@proconnect-gouv/proconnect.identite 14.0.0 → 16.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -0
- package/dist/connectors/index.d.ts +2 -7
- package/dist/connectors/index.d.ts.map +1 -1
- package/dist/connectors/index.js +3 -3
- package/dist/managers/certification/certification-score.d.ts +16 -0
- package/dist/managers/certification/certification-score.d.ts.map +1 -1
- package/dist/managers/certification/certification-score.js +65 -41
- package/dist/repositories/authenticator/delete-all-authenticators-by-user-id.d.ts +3 -0
- package/dist/repositories/authenticator/delete-all-authenticators-by-user-id.d.ts.map +1 -0
- package/dist/repositories/authenticator/delete-all-authenticators-by-user-id.js +12 -0
- package/dist/repositories/authenticator/index.d.ts +1 -0
- package/dist/repositories/authenticator/index.d.ts.map +1 -1
- package/dist/repositories/authenticator/index.js +1 -0
- package/dist/repositories/oidc-client/upsert-authorization-request.d.ts +1 -1
- package/dist/repositories/oidc-client/upsert-authorization-request.d.ts.map +1 -1
- package/dist/repositories/oidc-client/upsert-authorization-request.js +6 -4
- package/dist/repositories/organization/find-by-user-id.d.ts +0 -1
- package/dist/repositories/organization/find-by-user-id.d.ts.map +1 -1
- package/dist/repositories/organization/find-by-user-id.js +1 -2
- package/dist/repositories/organization/index.d.ts +0 -1
- package/dist/repositories/organization/index.d.ts.map +1 -1
- package/dist/repositories/organization/index.js +0 -1
- package/dist/repositories/user_organisation/find-user-organization.d.ts +0 -1
- package/dist/repositories/user_organisation/find-user-organization.d.ts.map +1 -1
- package/dist/repositories/user_organisation/find-user-organization.js +1 -2
- package/dist/repositories/user_organisation/get-user-organization.d.ts +0 -1
- package/dist/repositories/user_organisation/get-user-organization.d.ts.map +1 -1
- package/dist/services/organization/get-membership-changes-by-domain-verification.d.ts +18 -0
- package/dist/services/organization/get-membership-changes-by-domain-verification.d.ts.map +1 -0
- package/dist/services/organization/get-membership-changes-by-domain-verification.js +21 -0
- package/dist/services/organization/index.d.ts +1 -1
- package/dist/services/organization/index.d.ts.map +1 -1
- package/dist/services/organization/index.js +1 -1
- package/dist/types/authorization-request.d.ts +2 -0
- package/dist/types/authorization-request.d.ts.map +1 -1
- package/dist/types/authorization-request.js +4 -1
- package/dist/types/user-organization-link.d.ts +0 -2
- package/dist/types/user-organization-link.d.ts.map +1 -1
- package/dist/types/user-organization-link.js +0 -1
- package/package.json +1 -1
- package/src/connectors/index.ts +2 -2
- package/src/managers/certification/certification-score.test.ts +64 -1
- package/src/managers/certification/certification-score.ts +84 -50
- package/src/repositories/authenticator/delete-all-authenticators-by-user-id.test.ts +51 -0
- package/src/repositories/authenticator/delete-all-authenticators-by-user-id.ts +22 -0
- package/src/repositories/authenticator/index.ts +1 -0
- package/src/repositories/oidc-client/upsert-authorization-request.test.ts +18 -5
- package/src/repositories/oidc-client/upsert-authorization-request.ts +6 -3
- package/src/repositories/organization/find-by-user-id.test.ts +5 -5
- package/src/repositories/organization/find-by-user-id.test.ts.snapshot +3 -6
- package/src/repositories/organization/find-by-user-id.ts +1 -2
- package/src/repositories/organization/index.ts +0 -1
- package/src/repositories/user_organisation/find-user-organization.ts +1 -2
- package/src/repositories/user_organisation/get-user-organization.test.ts +0 -1
- package/src/services/organization/get-membership-changes-by-domain-verification.test.ts +91 -0
- package/src/services/organization/get-membership-changes-by-domain-verification.ts +46 -0
- package/src/services/organization/index.ts +1 -1
- package/src/types/authorization-request.ts +5 -1
- package/src/types/user-organization-link.ts +0 -1
- package/dist/repositories/organization/find-by-verified-email-domain.d.ts +0 -6
- package/dist/repositories/organization/find-by-verified-email-domain.d.ts.map +0 -1
- package/dist/repositories/organization/find-by-verified-email-domain.js +0 -21
- package/dist/services/organization/get-member-ids-promoted-by-domain.d.ts +0 -9
- package/dist/services/organization/get-member-ids-promoted-by-domain.d.ts.map +0 -1
- package/dist/services/organization/get-member-ids-promoted-by-domain.js +0 -11
- package/src/repositories/organization/find-by-verified-email-domain.test.ts +0 -46
- package/src/repositories/organization/find-by-verified-email-domain.ts +0 -33
- package/src/services/organization/get-member-ids-promoted-by-domain.test.ts +0 -100
- package/src/services/organization/get-member-ids-promoted-by-domain.ts +0 -27
package/src/connectors/index.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
4
|
createAuthenticatorFactory,
|
|
5
|
+
deleteAllAuthenticatorsByUserIdFactory,
|
|
5
6
|
deleteAuthenticatorFactory,
|
|
6
7
|
findAuthenticatorFactory,
|
|
7
8
|
findAuthenticatorsByUserIdFactory,
|
|
@@ -33,7 +34,6 @@ import {
|
|
|
33
34
|
import {
|
|
34
35
|
findBySiretFactory,
|
|
35
36
|
findByUserIdFactory,
|
|
36
|
-
findByVerifiedEmailDomainFactory,
|
|
37
37
|
findOrganizationByIdFactory,
|
|
38
38
|
findPendingByUserIdFactory,
|
|
39
39
|
getOrganizationByIdFactory,
|
|
@@ -85,6 +85,7 @@ export function createContext({
|
|
|
85
85
|
authenticators: {
|
|
86
86
|
create: createAuthenticatorFactory({ pg }),
|
|
87
87
|
delete: deleteAuthenticatorFactory({ pg }),
|
|
88
|
+
deleteAllByUserId: deleteAllAuthenticatorsByUserIdFactory({ pg }),
|
|
88
89
|
find: findAuthenticatorFactory({ pg }),
|
|
89
90
|
findByUserId: findAuthenticatorsByUserIdFactory({ pg }),
|
|
90
91
|
update: updateAuthenticatorFactory({ pg }),
|
|
@@ -119,7 +120,6 @@ export function createContext({
|
|
|
119
120
|
findById: findOrganizationByIdFactory({ pg }),
|
|
120
121
|
findBySiret: findBySiretFactory({ pg }),
|
|
121
122
|
findByUserId: findByUserIdFactory({ pg }),
|
|
122
|
-
findByVerifiedEmailDomain: findByVerifiedEmailDomainFactory({ pg }),
|
|
123
123
|
findPendingByUserId: findPendingByUserIdFactory({ pg }),
|
|
124
124
|
getById: getOrganizationByIdFactory({ pg }),
|
|
125
125
|
upsert: upsertFactory({ pg }),
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import assert from "node:assert/strict";
|
|
4
4
|
import { describe, it } from "node:test";
|
|
5
|
-
import { certificationScore } from "./certification-score.js";
|
|
5
|
+
import { certificationScore, compareCriteria } from "./certification-score.js";
|
|
6
6
|
|
|
7
7
|
//
|
|
8
8
|
|
|
@@ -343,3 +343,66 @@ describe("certification scoring", () => {
|
|
|
343
343
|
);
|
|
344
344
|
});
|
|
345
345
|
});
|
|
346
|
+
|
|
347
|
+
describe("compareCriteria", () => {
|
|
348
|
+
it("keeps the received and the compared value of each side", () => {
|
|
349
|
+
assert.deepStrictEqual(
|
|
350
|
+
compareCriteria(
|
|
351
|
+
{
|
|
352
|
+
birthcountry: "99100",
|
|
353
|
+
birthdate: new Date("1946-08-17"),
|
|
354
|
+
birthplace: "47019",
|
|
355
|
+
family_name: "Bernard",
|
|
356
|
+
gender: "male",
|
|
357
|
+
given_name: "Jean-Pierre Paul",
|
|
358
|
+
},
|
|
359
|
+
{
|
|
360
|
+
birthcountry: null,
|
|
361
|
+
birthdate: new Date("1946-08-18"),
|
|
362
|
+
birthplace: "47209",
|
|
363
|
+
family_name: "BERNARD",
|
|
364
|
+
gender: null,
|
|
365
|
+
given_name: "Jean Pierre",
|
|
366
|
+
},
|
|
367
|
+
),
|
|
368
|
+
[
|
|
369
|
+
{
|
|
370
|
+
criterion: "family_name",
|
|
371
|
+
franceconnect: { compared: "BERNARD", raw: "Bernard" },
|
|
372
|
+
matched: true,
|
|
373
|
+
source: { compared: "BERNARD", raw: "BERNARD" },
|
|
374
|
+
},
|
|
375
|
+
{
|
|
376
|
+
criterion: "first_name",
|
|
377
|
+
franceconnect: { compared: "JEAN", raw: "Jean-Pierre Paul" },
|
|
378
|
+
matched: true,
|
|
379
|
+
source: { compared: "JEAN", raw: "Jean Pierre" },
|
|
380
|
+
},
|
|
381
|
+
{
|
|
382
|
+
criterion: "gender",
|
|
383
|
+
franceconnect: { compared: "male", raw: "male" },
|
|
384
|
+
matched: true,
|
|
385
|
+
source: { compared: null, raw: null },
|
|
386
|
+
},
|
|
387
|
+
{
|
|
388
|
+
criterion: "birth_date",
|
|
389
|
+
franceconnect: {
|
|
390
|
+
compared: "1946-08-17T00:00:00.000Z",
|
|
391
|
+
raw: "1946-08-17T00:00:00.000Z",
|
|
392
|
+
},
|
|
393
|
+
matched: false,
|
|
394
|
+
source: {
|
|
395
|
+
compared: "1946-08-18T00:00:00.000Z",
|
|
396
|
+
raw: "1946-08-18T00:00:00.000Z",
|
|
397
|
+
},
|
|
398
|
+
},
|
|
399
|
+
{
|
|
400
|
+
criterion: "birth_place",
|
|
401
|
+
franceconnect: { compared: "47209", raw: "47019" },
|
|
402
|
+
matched: true,
|
|
403
|
+
source: { compared: "47209", raw: "47209" },
|
|
404
|
+
},
|
|
405
|
+
],
|
|
406
|
+
);
|
|
407
|
+
});
|
|
408
|
+
});
|
|
@@ -40,69 +40,103 @@ export function certificationScore(
|
|
|
40
40
|
identitePivot: IdentityVector,
|
|
41
41
|
sourceDirigeant: IdentityVector,
|
|
42
42
|
) {
|
|
43
|
-
|
|
43
|
+
return new Set(
|
|
44
|
+
compareCriteria(identitePivot, sourceDirigeant)
|
|
45
|
+
.filter(({ matched }) => matched)
|
|
46
|
+
.map(({ criterion }) => criterion),
|
|
47
|
+
);
|
|
48
|
+
}
|
|
44
49
|
|
|
50
|
+
/**
|
|
51
|
+
* Compares each evaluated criterion and keeps, for both sides, the value as
|
|
52
|
+
* received (`raw`) and the value actually compared (`compared`).
|
|
53
|
+
*/
|
|
54
|
+
export function compareCriteria(
|
|
55
|
+
identitePivot: IdentityVector,
|
|
56
|
+
sourceDirigeant: IdentityVector,
|
|
57
|
+
) {
|
|
45
58
|
// 1. Family name match (after normalization)
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
) {
|
|
54
|
-
matches.add(MatchCriteria.enum.family_name);
|
|
55
|
-
}
|
|
59
|
+
const family_name = compare({
|
|
60
|
+
criterion: MatchCriteria.enum.family_name,
|
|
61
|
+
franceconnect: identitePivot.family_name,
|
|
62
|
+
match: bothPresentAndEqual,
|
|
63
|
+
normalize: normalizeText,
|
|
64
|
+
source: sourceDirigeant.family_name,
|
|
65
|
+
});
|
|
56
66
|
|
|
57
67
|
// 2. First name match (first name only, after normalization)
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
68
|
+
const first_name = compare({
|
|
69
|
+
criterion: MatchCriteria.enum.first_name,
|
|
70
|
+
franceconnect: identitePivot.given_name,
|
|
71
|
+
match: bothPresentAndEqual,
|
|
72
|
+
normalize: extractFirstName,
|
|
73
|
+
source: sourceDirigeant.given_name,
|
|
74
|
+
});
|
|
64
75
|
|
|
65
76
|
// 3. Gender match (match or absent in source)
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
identitePivot.gender
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}
|
|
77
|
+
const gender = compare({
|
|
78
|
+
criterion: MatchCriteria.enum.gender,
|
|
79
|
+
franceconnect: identitePivot.gender,
|
|
80
|
+
match: (pivot, source) => !source || pivot === source,
|
|
81
|
+
source: sourceDirigeant.gender,
|
|
82
|
+
});
|
|
72
83
|
|
|
73
84
|
// 4. Birth date match (exact match)
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}
|
|
85
|
+
const birth_date = compare({
|
|
86
|
+
criterion: MatchCriteria.enum.birth_date,
|
|
87
|
+
franceconnect: identitePivot.birthdate?.toISOString() ?? null,
|
|
88
|
+
match: bothPresentAndEqual,
|
|
89
|
+
source: sourceDirigeant.birthdate?.toISOString() ?? null,
|
|
90
|
+
});
|
|
81
91
|
|
|
82
92
|
// 5. Birth place match (different logic for French vs foreigners)
|
|
83
93
|
const isFrench =
|
|
84
94
|
!identitePivot.birthcountry || identitePivot.birthcountry === "99100";
|
|
95
|
+
const birth = isFrench
|
|
96
|
+
? // For French: commune code (with conversion), match if source has none
|
|
97
|
+
compare({
|
|
98
|
+
criterion: MatchCriteria.enum.birth_place,
|
|
99
|
+
franceconnect: identitePivot.birthplace,
|
|
100
|
+
match: (pivot, source) => !source || (!!pivot && pivot === source),
|
|
101
|
+
normalize: convertCommuneCode,
|
|
102
|
+
source: sourceDirigeant.birthplace,
|
|
103
|
+
})
|
|
104
|
+
: // For foreigners: country code (COG 99XXX), match if either side has none
|
|
105
|
+
compare({
|
|
106
|
+
criterion: MatchCriteria.enum.birth_country,
|
|
107
|
+
franceconnect: identitePivot.birthcountry,
|
|
108
|
+
match: (pivot, source) =>
|
|
109
|
+
pivot === null || source === null || pivot === source,
|
|
110
|
+
source: sourceDirigeant.birthcountry,
|
|
111
|
+
});
|
|
85
112
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
113
|
+
return [family_name, first_name, gender, birth_date, birth];
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function bothPresentAndEqual(pivot: string | null, source: string | null) {
|
|
117
|
+
return !!pivot && !!source && pivot === source;
|
|
118
|
+
}
|
|
90
119
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
120
|
+
function compare({
|
|
121
|
+
criterion,
|
|
122
|
+
franceconnect,
|
|
123
|
+
match,
|
|
124
|
+
normalize = (value) => value,
|
|
125
|
+
source,
|
|
126
|
+
}: {
|
|
127
|
+
criterion: MatchCriteria;
|
|
128
|
+
franceconnect: string | null;
|
|
129
|
+
match: (pivot: string | null, source: string | null) => boolean;
|
|
130
|
+
normalize?: (value: string | null) => string | null;
|
|
131
|
+
source: string | null;
|
|
132
|
+
}) {
|
|
133
|
+
const compared_franceconnect = normalize(franceconnect);
|
|
134
|
+
const compared_source = normalize(source);
|
|
106
135
|
|
|
107
|
-
return
|
|
136
|
+
return {
|
|
137
|
+
criterion,
|
|
138
|
+
franceconnect: { compared: compared_franceconnect, raw: franceconnect },
|
|
139
|
+
matched: match(compared_franceconnect, compared_source),
|
|
140
|
+
source: { compared: compared_source, raw: source },
|
|
141
|
+
};
|
|
108
142
|
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
//
|
|
2
|
+
|
|
3
|
+
import { emptyDatabase, migrate, pg } from "#testing";
|
|
4
|
+
import assert from "node:assert/strict";
|
|
5
|
+
import { before, beforeEach, suite, test } from "node:test";
|
|
6
|
+
import { deleteAllAuthenticatorsByUserIdFactory } from "./delete-all-authenticators-by-user-id.js";
|
|
7
|
+
|
|
8
|
+
//
|
|
9
|
+
|
|
10
|
+
const deleteAllAuthenticatorsByUserId = deleteAllAuthenticatorsByUserIdFactory({
|
|
11
|
+
pg: pg as any,
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
suite("deleteAllAuthenticatorsByUserIdFactory", () => {
|
|
15
|
+
before(migrate);
|
|
16
|
+
beforeEach(emptyDatabase);
|
|
17
|
+
|
|
18
|
+
test("should delete all the authenticators of the user only", async () => {
|
|
19
|
+
await pg.sql`
|
|
20
|
+
INSERT INTO users
|
|
21
|
+
(id, email, created_at, updated_at, given_name, family_name, phone_number, job)
|
|
22
|
+
VALUES
|
|
23
|
+
(1, 'lion.eljonson@darkangels.world', '4444-04-04', '4444-04-04', 'lion', 'el''jonson', 'i', 'primarque'),
|
|
24
|
+
(2, 'rogal.dorn@imperialfists.world', '4444-04-04', '4444-04-04', 'rogal', 'dorn', 'i', 'primarque')
|
|
25
|
+
;
|
|
26
|
+
`;
|
|
27
|
+
await pg.sql`
|
|
28
|
+
INSERT INTO authenticators
|
|
29
|
+
(credential_id, credential_public_key, counter, credential_backed_up, user_id, usage_count, user_verified)
|
|
30
|
+
VALUES
|
|
31
|
+
('CRED1', '\\x00', 0, false, 1, 0, true),
|
|
32
|
+
('CRED2', '\\x00', 0, false, 1, 0, true),
|
|
33
|
+
('CRED3', '\\x00', 0, false, 2, 0, true)
|
|
34
|
+
;
|
|
35
|
+
`;
|
|
36
|
+
|
|
37
|
+
const result = await deleteAllAuthenticatorsByUserId(1);
|
|
38
|
+
|
|
39
|
+
assert.equal(result, true);
|
|
40
|
+
const { rows } = await pg.query(
|
|
41
|
+
"SELECT credential_id FROM authenticators ORDER BY credential_id",
|
|
42
|
+
);
|
|
43
|
+
assert.deepEqual(rows, [{ credential_id: "CRED3" }]);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test("should return false when the user has no authenticator", async () => {
|
|
47
|
+
const result = await deleteAllAuthenticatorsByUserId(1);
|
|
48
|
+
|
|
49
|
+
assert.equal(result, false);
|
|
50
|
+
});
|
|
51
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
//
|
|
2
|
+
|
|
3
|
+
import type { DatabaseContext } from "#src/types";
|
|
4
|
+
import { type QueryResult } from "pg";
|
|
5
|
+
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
export function deleteAllAuthenticatorsByUserIdFactory({
|
|
9
|
+
pg,
|
|
10
|
+
}: DatabaseContext) {
|
|
11
|
+
return async function deleteAllAuthenticatorsByUserId(user_id: number) {
|
|
12
|
+
const { rowCount, affectedRows } = (await pg.query(
|
|
13
|
+
`
|
|
14
|
+
DELETE FROM authenticators
|
|
15
|
+
WHERE user_id = $1
|
|
16
|
+
RETURNING *`,
|
|
17
|
+
[user_id],
|
|
18
|
+
)) as QueryResult & { affectedRows?: number };
|
|
19
|
+
|
|
20
|
+
return (affectedRows ?? rowCount ?? 0) > 0;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
@@ -40,12 +40,14 @@ suite("upsertAuthorizationRequestFactory", () => {
|
|
|
40
40
|
user_ip_address: "127.0.0.1",
|
|
41
41
|
interaction_cid: "Rex5_Tq4tBqqwz0xPTJyd",
|
|
42
42
|
outcome: "succeeded",
|
|
43
|
+
sid: "ulthwe",
|
|
43
44
|
});
|
|
44
45
|
|
|
45
46
|
assert.equal(authorizationRequest.user_id, 1);
|
|
46
47
|
assert.equal(authorizationRequest.oidc_client_id, 1);
|
|
47
48
|
assert.equal(authorizationRequest.interaction_cid, "Rex5_Tq4tBqqwz0xPTJyd");
|
|
48
49
|
assert.equal(authorizationRequest.outcome, "succeeded");
|
|
50
|
+
assert.equal(authorizationRequest.sid, "ulthwe");
|
|
49
51
|
});
|
|
50
52
|
|
|
51
53
|
test("should update the authorization request of the same interaction", async () => {
|
|
@@ -60,36 +62,47 @@ suite("upsertAuthorizationRequestFactory", () => {
|
|
|
60
62
|
...request,
|
|
61
63
|
interaction_cid: "caliban",
|
|
62
64
|
outcome: null,
|
|
65
|
+
sid: null,
|
|
63
66
|
});
|
|
64
67
|
await upsertAuthorizationRequest({
|
|
65
68
|
...request,
|
|
66
69
|
interaction_cid: "fallen",
|
|
67
70
|
outcome: null,
|
|
71
|
+
sid: "rock",
|
|
68
72
|
});
|
|
69
73
|
await upsertAuthorizationRequest({
|
|
70
74
|
...request,
|
|
71
75
|
interaction_cid: "caliban",
|
|
72
76
|
outcome: "succeeded",
|
|
77
|
+
sid: "rock",
|
|
78
|
+
});
|
|
79
|
+
await upsertAuthorizationRequest({
|
|
80
|
+
...request,
|
|
81
|
+
interaction_cid: "fallen",
|
|
82
|
+
outcome: null,
|
|
83
|
+
sid: null,
|
|
73
84
|
});
|
|
74
85
|
await upsertAuthorizationRequest({
|
|
75
86
|
...request,
|
|
76
87
|
interaction_cid: null,
|
|
77
88
|
outcome: "succeeded",
|
|
89
|
+
sid: "rock",
|
|
78
90
|
});
|
|
79
91
|
await upsertAuthorizationRequest({
|
|
80
92
|
...request,
|
|
81
93
|
interaction_cid: null,
|
|
82
94
|
outcome: "succeeded",
|
|
95
|
+
sid: "rock",
|
|
83
96
|
});
|
|
84
97
|
|
|
85
98
|
const { rows } = await pg.query(
|
|
86
|
-
"SELECT interaction_cid, outcome FROM users_oidc_clients ORDER BY id",
|
|
99
|
+
"SELECT interaction_cid, outcome, sid FROM users_oidc_clients ORDER BY id",
|
|
87
100
|
);
|
|
88
101
|
assert.deepEqual(rows, [
|
|
89
|
-
{ interaction_cid: "caliban", outcome: "succeeded" },
|
|
90
|
-
{ interaction_cid: "fallen", outcome: null },
|
|
91
|
-
{ interaction_cid: null, outcome: "succeeded" },
|
|
92
|
-
{ interaction_cid: null, outcome: "succeeded" },
|
|
102
|
+
{ interaction_cid: "caliban", outcome: "succeeded", sid: "rock" },
|
|
103
|
+
{ interaction_cid: "fallen", outcome: null, sid: "rock" },
|
|
104
|
+
{ interaction_cid: null, outcome: "succeeded", sid: "rock" },
|
|
105
|
+
{ interaction_cid: null, outcome: "succeeded", sid: "rock" },
|
|
93
106
|
]);
|
|
94
107
|
});
|
|
95
108
|
});
|
|
@@ -18,19 +18,21 @@ export function upsertAuthorizationRequestFactory({ pg }: DatabaseContext) {
|
|
|
18
18
|
user_ip_address,
|
|
19
19
|
interaction_cid,
|
|
20
20
|
outcome,
|
|
21
|
+
sid,
|
|
21
22
|
}: BaseAuthorizationRequest) {
|
|
22
23
|
const { rows }: QueryResult<AuthorizationRequest> = await pg.query(
|
|
23
24
|
`
|
|
24
25
|
INSERT INTO users_oidc_clients
|
|
25
|
-
(user_id, oidc_client_id, organization_id, sp_name, user_ip_address, created_at, updated_at, interaction_cid, outcome)
|
|
26
|
-
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)
|
|
26
|
+
(user_id, oidc_client_id, organization_id, sp_name, user_ip_address, created_at, updated_at, interaction_cid, outcome, sid)
|
|
27
|
+
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
|
|
27
28
|
ON CONFLICT (interaction_cid) WHERE interaction_cid IS NOT NULL
|
|
28
29
|
DO UPDATE SET
|
|
29
30
|
organization_id = EXCLUDED.organization_id,
|
|
30
31
|
outcome = EXCLUDED.outcome,
|
|
32
|
+
sid = COALESCE(EXCLUDED.sid, users_oidc_clients.sid),
|
|
31
33
|
updated_at = EXCLUDED.updated_at,
|
|
32
34
|
user_id = EXCLUDED.user_id
|
|
33
|
-
RETURNING user_id, oidc_client_id, organization_id, sp_name, user_ip_address, created_at, updated_at, id, interaction_cid, outcome;
|
|
35
|
+
RETURNING user_id, oidc_client_id, organization_id, sp_name, user_ip_address, created_at, updated_at, id, interaction_cid, outcome, sid;
|
|
34
36
|
`,
|
|
35
37
|
[
|
|
36
38
|
user_id,
|
|
@@ -42,6 +44,7 @@ RETURNING user_id, oidc_client_id, organization_id, sp_name, user_ip_address, cr
|
|
|
42
44
|
new Date(),
|
|
43
45
|
interaction_cid,
|
|
44
46
|
outcome,
|
|
47
|
+
sid,
|
|
45
48
|
],
|
|
46
49
|
);
|
|
47
50
|
|
|
@@ -59,11 +59,11 @@ async function seed() {
|
|
|
59
59
|
|
|
60
60
|
await pg.sql`
|
|
61
61
|
INSERT INTO users_organizations
|
|
62
|
-
(user_id, organization_id, created_at, updated_at, is_external, verification_type
|
|
63
|
-
VALUES (1, 1, '2023-01-25', '2024-02-20', false, 'necron'
|
|
64
|
-
(1, 3, '2023-04-01', '2024-05-05', true, 'alliance'
|
|
65
|
-
(2, 2, '2023-03-01', '2024-04-01', false, 'necron'
|
|
66
|
-
(6, 5, '2023-07-05', '2024-08-15', false, 'imperial'
|
|
62
|
+
(user_id, organization_id, created_at, updated_at, is_external, verification_type)
|
|
63
|
+
VALUES (1, 1, '2023-01-25', '2024-02-20', false, 'necron'),
|
|
64
|
+
(1, 3, '2023-04-01', '2024-05-05', true, 'alliance'),
|
|
65
|
+
(2, 2, '2023-03-01', '2024-04-01', false, 'necron'),
|
|
66
|
+
(6, 5, '2023-07-05', '2024-08-15', false, 'imperial')
|
|
67
67
|
;
|
|
68
68
|
`;
|
|
69
69
|
}
|
|
@@ -27,8 +27,7 @@ exports[`findByUserIdFactory > should return multiple organizations when user ha
|
|
|
27
27
|
"cached_denomination_usuelle_etablissement_principal": null,
|
|
28
28
|
"is_external": false,
|
|
29
29
|
"verification_type": "necron",
|
|
30
|
-
"verified_at": null
|
|
31
|
-
"has_been_greeted": true
|
|
30
|
+
"verified_at": null
|
|
32
31
|
},
|
|
33
32
|
{
|
|
34
33
|
"id": 3,
|
|
@@ -57,8 +56,7 @@ exports[`findByUserIdFactory > should return multiple organizations when user ha
|
|
|
57
56
|
"cached_denomination_usuelle_etablissement_principal": null,
|
|
58
57
|
"is_external": true,
|
|
59
58
|
"verification_type": "alliance",
|
|
60
|
-
"verified_at": null
|
|
61
|
-
"has_been_greeted": false
|
|
59
|
+
"verified_at": null
|
|
62
60
|
}
|
|
63
61
|
]
|
|
64
62
|
`;
|
|
@@ -92,8 +90,7 @@ exports[`findByUserIdFactory > should return single organization when user has o
|
|
|
92
90
|
"cached_denomination_usuelle_etablissement_principal": null,
|
|
93
91
|
"is_external": false,
|
|
94
92
|
"verification_type": "imperial",
|
|
95
|
-
"verified_at": null
|
|
96
|
-
"has_been_greeted": true
|
|
93
|
+
"verified_at": null
|
|
97
94
|
}
|
|
98
95
|
]
|
|
99
96
|
`;
|
|
@@ -17,8 +17,7 @@ export function findByUserIdFactory({ pg }: DatabaseContext) {
|
|
|
17
17
|
SELECT o.*,
|
|
18
18
|
uo.is_external,
|
|
19
19
|
uo.verification_type,
|
|
20
|
-
uo.verified_at
|
|
21
|
-
uo.has_been_greeted
|
|
20
|
+
uo.verified_at
|
|
22
21
|
FROM organizations o
|
|
23
22
|
INNER JOIN users_organizations uo ON uo.organization_id = o.id
|
|
24
23
|
WHERE uo.user_id = $1
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
export * from "./find-by-siret.js";
|
|
4
4
|
export * from "./find-by-user-id.js";
|
|
5
|
-
export * from "./find-by-verified-email-domain.js";
|
|
6
5
|
export * from "./find-organization-by-id.js";
|
|
7
6
|
export * from "./find-pending-by-user-id.js";
|
|
8
7
|
export * from "./get-organization-by-id.js";
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
//
|
|
2
|
+
|
|
3
|
+
import { getMembershipChangesByDomainVerification } from "#src/services/organization";
|
|
4
|
+
import assert from "node:assert/strict";
|
|
5
|
+
import { describe, it } from "node:test";
|
|
6
|
+
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
const unverified_darkangels = [
|
|
10
|
+
{
|
|
11
|
+
email: "lion.eljonson@darkangels.world",
|
|
12
|
+
verification_type: "no_validation_means_available",
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
email: "cat.eljonson@darkangels.world",
|
|
16
|
+
verification_type: "no_verification_means_for_entreprise_unipersonnelle",
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
email: "tiger.eljonson@darkangels.world",
|
|
20
|
+
verification_type: "no_verification_means_for_small_association",
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
email: "wolf.eljonson@darkangels.world",
|
|
24
|
+
verification_type: "no_verification_means_for_small_organization",
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
email: "mouse.eljonson@darkangels.world",
|
|
28
|
+
verification_type: "domain_not_verified_yet",
|
|
29
|
+
},
|
|
30
|
+
];
|
|
31
|
+
|
|
32
|
+
const verified_darkangels = [
|
|
33
|
+
{
|
|
34
|
+
email: "luther@darkangels.world",
|
|
35
|
+
verification_type: "organization_dirigeant",
|
|
36
|
+
},
|
|
37
|
+
{ email: "azrael@darkangels.world", verification_type: "domain" },
|
|
38
|
+
{
|
|
39
|
+
email: "belial@darkangels.world",
|
|
40
|
+
verification_type: "official_contact_email",
|
|
41
|
+
},
|
|
42
|
+
];
|
|
43
|
+
|
|
44
|
+
const other_domains = [
|
|
45
|
+
{
|
|
46
|
+
email: "leman.russ@spacewolves.world",
|
|
47
|
+
verification_type: "no_validation_means_available",
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
email: "cypher@fallen.darkangels.world",
|
|
51
|
+
verification_type: "no_validation_means_available",
|
|
52
|
+
},
|
|
53
|
+
];
|
|
54
|
+
|
|
55
|
+
const members = [
|
|
56
|
+
...unverified_darkangels,
|
|
57
|
+
...verified_darkangels,
|
|
58
|
+
...other_domains,
|
|
59
|
+
];
|
|
60
|
+
|
|
61
|
+
describe("getMembershipChangesByDomainVerification", () => {
|
|
62
|
+
it("should promote the unverified and super weak members of an approved domain", () => {
|
|
63
|
+
assert.deepEqual(
|
|
64
|
+
getMembershipChangesByDomainVerification({
|
|
65
|
+
domain: "darkangels.world",
|
|
66
|
+
members,
|
|
67
|
+
verification_type: "verified",
|
|
68
|
+
}),
|
|
69
|
+
{
|
|
70
|
+
kind: "domain_approved",
|
|
71
|
+
promoted_members: unverified_darkangels,
|
|
72
|
+
verification_type: "verified",
|
|
73
|
+
},
|
|
74
|
+
);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("should remove every member of a refused domain, whatever their link", () => {
|
|
78
|
+
assert.deepEqual(
|
|
79
|
+
getMembershipChangesByDomainVerification({
|
|
80
|
+
domain: "darkangels.world",
|
|
81
|
+
members,
|
|
82
|
+
verification_type: "refused",
|
|
83
|
+
}),
|
|
84
|
+
{
|
|
85
|
+
kind: "domain_refused",
|
|
86
|
+
removed_members: [...unverified_darkangels, ...verified_darkangels],
|
|
87
|
+
verification_type: "refused",
|
|
88
|
+
},
|
|
89
|
+
);
|
|
90
|
+
});
|
|
91
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
//
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
EmailDomainApprovedVerificationValues,
|
|
5
|
+
EmailDomainRejectedVerificationValues,
|
|
6
|
+
SuperWeakLinkEnum,
|
|
7
|
+
UnverifiedLinkEnum,
|
|
8
|
+
type EmailDomainNoPendingVerificationType,
|
|
9
|
+
} from "#src/types";
|
|
10
|
+
import { getEmailDomain } from "@proconnect-gouv/proconnect.core/services/email";
|
|
11
|
+
import { match } from "ts-pattern";
|
|
12
|
+
|
|
13
|
+
//
|
|
14
|
+
|
|
15
|
+
export function getMembershipChangesByDomainVerification<
|
|
16
|
+
Member extends { email: string; verification_type: string },
|
|
17
|
+
>({
|
|
18
|
+
domain,
|
|
19
|
+
members,
|
|
20
|
+
verification_type,
|
|
21
|
+
}: {
|
|
22
|
+
domain: string;
|
|
23
|
+
members: ReadonlyArray<Member>;
|
|
24
|
+
verification_type: EmailDomainNoPendingVerificationType;
|
|
25
|
+
}) {
|
|
26
|
+
const domain_members = members.filter(
|
|
27
|
+
({ email }) => getEmailDomain(email) === domain,
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
return match(verification_type)
|
|
31
|
+
.with(...EmailDomainApprovedVerificationValues, (verification_type) => ({
|
|
32
|
+
kind: "domain_approved" as const,
|
|
33
|
+
promoted_members: domain_members.filter(
|
|
34
|
+
({ verification_type }) =>
|
|
35
|
+
UnverifiedLinkEnum.safeParse(verification_type).success ||
|
|
36
|
+
SuperWeakLinkEnum.safeParse(verification_type).success,
|
|
37
|
+
),
|
|
38
|
+
verification_type,
|
|
39
|
+
}))
|
|
40
|
+
.with(...EmailDomainRejectedVerificationValues, (verification_type) => ({
|
|
41
|
+
kind: "domain_refused" as const,
|
|
42
|
+
removed_members: domain_members,
|
|
43
|
+
verification_type,
|
|
44
|
+
}))
|
|
45
|
+
.exhaustive();
|
|
46
|
+
}
|