Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
enedis_sge_konnector
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
web-et-numerique
Factory
LLLE_Project
enedis_sge_konnector
Commits
bdeb7441
Commit
bdeb7441
authored
2 years ago
by
Bastien DUMONT
Browse files
Options
Downloads
Patches
Plain Diff
test verifyUserIdentity
parent
0840e453
No related branches found
Branches containing commit
No related tags found
2 merge requests
!12
Feat/donnes tech debut contrat
,
!10
Feat/rechercher point
Pipeline
#39769
failed
2 years ago
Stage: test
Stage: build
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
__tests__/verifyUserIdentity.spec.js
+47
-24
47 additions, 24 deletions
__tests__/verifyUserIdentity.spec.js
src/findUserPdl.js
+45
-0
45 additions, 0 deletions
src/findUserPdl.js
src/index.js
+3
-77
3 additions, 77 deletions
src/index.js
src/verifyUserIdentity.js
+40
-0
40 additions, 0 deletions
src/verifyUserIdentity.js
with
135 additions
and
101 deletions
__tests__/verifyUserIdentity.spec.js
+
47
−
24
View file @
bdeb7441
const
{
errors
}
=
require
(
'
cozy-konnector-libs
'
)
const
{
verifyUserIdentity
}
=
require
(
'
../src/
index
'
)
const
{
verifyUserIdentity
}
=
require
(
'
../src/
verifyUserIdentity
'
)
jest
.
mock
(
'
../src/requests/insee
'
,
()
=>
({
getInseeCode
:
jest
.
fn
().
mockResolvedValueOnce
(
69
),
getInseeCode
:
jest
.
fn
().
mockResolvedValue
(
69
),
}))
// This mock doenst work somehow
jest
.
mock
(
'
../src/findUserPdl
'
,
()
=>
({
findUserPdl
:
jest
.
fn
().
mockResolvedValue
(
'
12345
'
),
}))
describe
(
'
verifyUserIdentity
'
,
()
=>
{
// mock insee code
// mock find User Pdl
// const mockGetInseeCode = jest.fn()
// const mockFindUserPdl = jest.fn()
it
(
'
should throw LOGIN_FAILED when pdl give and recieved are not matching
'
,
async
()
=>
{
const
result
=
await
verifyUserIdentity
(
{
name
:
'
John
'
,
address
:
'
1 street
'
,
pointId
:
987654321
,
postalCode
:
'
69069
'
,
},
'
baseUrl
'
,
'
apiKey
'
,
'
login@user.com
'
)
// jest
// .mock(verifyUserIdentity(), 'getInseeCode')
// .mockResolvedValueOnce(696969)
// jest.spyOn(verifyUserIdentity, 'findUserPdl').mockResolvedValueOnce(696969)
jest
.
mock
(
'
../src/index
'
,
()
=>
({
start
:
jest
.
fn
(),
}))
describe
(
'
verifyUserIdentity
'
,
()
=>
{
it
(
'
should throw LOGIN_FAILED when pdl give and recieved are NOT matching 🚫
'
,
async
()
=>
{
try
{
await
verifyUserIdentity
(
{
name
:
'
John
'
,
address
:
'
1 street
'
,
pointId
:
987654321
,
postalCode
:
'
69069
'
,
},
'
azertyuiop
'
,
'
apiKey
'
,
'
login@user.com
'
)
expect
(
true
).
toBe
(
false
)
}
catch
(
error
)
{
expect
(
error
).
toBe
(
errors
.
LOGIN_FAILED
)
}
})
expect
(
result
).
toBe
(
errors
.
LOGIN_FAILED
)
it
(
'
should return true when pdl give and recieved are matching ✅
'
,
async
()
=>
{
try
{
const
response
=
await
verifyUserIdentity
(
{
name
:
'
John
'
,
address
:
'
1 street
'
,
pointId
:
'
12345
'
,
postalCode
:
'
69069
'
,
},
'
azertyuiop
'
,
'
apiKey
'
,
'
login@user.com
'
)
expect
(
response
).
toBe
(
true
)
}
catch
(
error
)
{
expect
(
true
).
toBe
(
false
)
}
})
})
This diff is collapsed.
Click to expand it.
src/findUserPdl.js
0 → 100644
+
45
−
0
View file @
bdeb7441
// @ts-check
const
{
log
,
errors
}
=
require
(
'
cozy-konnector-libs
'
)
const
soapRequest
=
require
(
'
easy-soap-request
'
)
const
{
parseUserPdl
,
parseTags
,
parseValue
}
=
require
(
'
./parsing
'
)
const
{
rechercherPoint
}
=
require
(
'
./requests/sge
'
)
const
xml2js
=
require
(
'
xml2js
'
)
/**
* @return {Promise<string>} User Pdl
*/
async
function
findUserPdl
(
url
,
apiAuthKey
,
appLogin
,
name
,
address
,
postalCode
,
inseeCode
)
{
log
(
'
info
'
,
'
Fetching user data
'
)
const
sgeHeaders
=
{
'
Content-Type
'
:
'
text/xml;charset=UTF-8
'
,
apikey
:
apiAuthKey
,
}
const
{
response
}
=
await
soapRequest
({
url
:
url
,
headers
:
sgeHeaders
,
xml
:
rechercherPoint
(
appLogin
,
name
,
postalCode
,
inseeCode
,
address
),
}).
catch
(
err
=>
{
log
(
'
error
'
,
'
rechercherPointResponse
'
)
log
(
'
error
'
,
err
)
throw
errors
.
LOGIN_FAILED
})
const
parsedReply
=
await
xml2js
.
parseStringPromise
(
response
.
body
,
{
tagNameProcessors
:
[
parseTags
],
valueProcessors
:
[
parseValue
],
explicitArray
:
false
,
})
//TODO: handle errors
return
parseUserPdl
(
parsedReply
)
}
module
.
exports
=
{
findUserPdl
}
This diff is collapsed.
Click to expand it.
src/index.js
+
3
−
77
View file @
bdeb7441
...
...
@@ -17,13 +17,12 @@ const {
formateDataForDoctype
,
parseTags
,
parseValue
,
parseUserPdl
,
}
=
require
(
'
./parsing
'
)
const
{
consulterDonneesTechniquesContractuelles
,
consultationMesuresDetailleesMaxPower
,
consultationMesuresDetaillees
,
rechercherPoint
,
commanderCollectePublicationMesures
,
commanderArretServiceSouscritMesures
,
}
=
require
(
'
./requests/sge
'
)
...
...
@@ -33,7 +32,8 @@ const {
getBoConsent
,
deleteBoConsent
,
}
=
require
(
'
./requests/bo
'
)
const
{
getInseeCode
}
=
require
(
'
./requests/insee
'
)
const
verifyUserIdentity
=
require
(
'
./verifyUserIdentity
'
)
moment
.
locale
(
'
fr
'
)
// set the language
moment
.
tz
.
setDefault
(
'
Europe/Paris
'
)
// set the timezone
...
...
@@ -110,38 +110,6 @@ async function start(fields, cozyParameters) {
await
gatherData
(
baseUrl
,
apiAuthKey
,
loginUtilisateur
,
fields
.
pointId
)
}
/**
* Verify user identity
* @param {object} fields
* @param {string} baseUrl
* @param {string} apiAuthKey
* @param {string} loginUtilisateur
*/
async
function
verifyUserIdentity
(
fields
,
baseUrl
,
apiAuthKey
,
loginUtilisateur
)
{
const
inseeCode
=
await
getInseeCode
(
fields
.
postalCode
)
const
pdl
=
await
findUserPdl
(
`
${
baseUrl
}
/enedis_SDE_recherche-point/1.0`
,
apiAuthKey
,
loginUtilisateur
,
fields
.
name
,
fields
.
address
,
fields
.
postalCode
,
inseeCode
)
if
(
fields
.
pointId
!=
pdl
)
{
log
(
'
error
'
,
'
PointId does not match
'
)
throw
errors
.
LOGIN_FAILED
}
return
true
}
/**
* Main method for gathering data
* @param {string} baseUrl
...
...
@@ -476,45 +444,3 @@ function isFirstStart() {
//TODO: Implement
return
true
}
/**
* @return {Promise<string>} User Pdl
*/
async
function
findUserPdl
(
url
,
apiAuthKey
,
appLogin
,
name
,
address
,
postalCode
,
inseeCode
)
{
log
(
'
info
'
,
'
Fetching user data
'
)
const
sgeHeaders
=
{
'
Content-Type
'
:
'
text/xml;charset=UTF-8
'
,
apikey
:
apiAuthKey
,
}
const
{
response
}
=
await
soapRequest
({
url
:
url
,
headers
:
sgeHeaders
,
xml
:
rechercherPoint
(
appLogin
,
name
,
postalCode
,
inseeCode
,
address
),
}).
catch
(
err
=>
{
log
(
'
error
'
,
'
rechercherPointResponse
'
)
log
(
'
error
'
,
err
)
throw
errors
.
LOGIN_FAILED
})
const
parsedReply
=
await
xml2js
.
parseStringPromise
(
response
.
body
,
{
tagNameProcessors
:
[
parseTags
],
valueProcessors
:
[
parseValue
],
explicitArray
:
false
,
})
//TODO: handle errors
return
parseUserPdl
(
parsedReply
)
}
module
.
exports
=
{
verifyUserIdentity
,
findUserPdl
,
}
This diff is collapsed.
Click to expand it.
src/verifyUserIdentity.js
0 → 100644
+
40
−
0
View file @
bdeb7441
// @ts-check
const
{
log
,
errors
}
=
require
(
'
cozy-konnector-libs
'
)
const
{
findUserPdl
}
=
require
(
'
./findUserPdl
'
)
const
{
getInseeCode
}
=
require
(
'
./requests/insee
'
)
/**
* Verify user identity
* @param {object} fields
* @param {string} baseUrl
* @param {string} apiAuthKey
* @param {string} loginUtilisateur
*/
async
function
verifyUserIdentity
(
fields
,
baseUrl
,
apiAuthKey
,
loginUtilisateur
)
{
const
inseeCode
=
await
getInseeCode
(
fields
.
postalCode
)
const
pdl
=
await
findUserPdl
(
`
${
baseUrl
}
/enedis_SDE_recherche-point/1.0`
,
apiAuthKey
,
loginUtilisateur
,
fields
.
name
,
fields
.
address
,
fields
.
postalCode
,
inseeCode
)
console
.
log
(
pdl
)
console
.
log
(
fields
.
pointId
)
if
(
fields
.
pointId
!=
pdl
)
{
log
(
'
error
'
,
'
PointId does not match
'
)
throw
errors
.
LOGIN_FAILED
}
return
true
}
module
.
exports
=
{
verifyUserIdentity
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment