@villedemontreal/jwt-validator 5.9.2 → 5.10.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.
Files changed (48) hide show
  1. package/dist/scripts/showCoverage.js.map +1 -1
  2. package/dist/scripts/testUnits.js.map +1 -1
  3. package/dist/scripts/watch.js.map +1 -1
  4. package/dist/src/config/configs.d.ts +15 -0
  5. package/dist/src/config/configs.js +11 -0
  6. package/dist/src/config/configs.js.map +1 -1
  7. package/dist/src/config/init.js +2 -3
  8. package/dist/src/config/init.js.map +1 -1
  9. package/dist/src/jwtValidator.js.map +1 -1
  10. package/dist/src/jwtValidator.test.js.map +1 -1
  11. package/dist/src/middleware/jwtMiddleware.js.map +1 -1
  12. package/dist/src/middleware/tokenTransformationMiddleware.js +13 -1
  13. package/dist/src/middleware/tokenTransformationMiddleware.js.map +1 -1
  14. package/dist/src/models/accessToken.d.ts +32 -0
  15. package/dist/src/models/accessToken.js +3 -0
  16. package/dist/src/models/accessToken.js.map +1 -0
  17. package/dist/src/models/customError.js +2 -3
  18. package/dist/src/models/customError.js.map +1 -1
  19. package/dist/src/models/gluuUserType.js +1 -1
  20. package/dist/src/models/gluuUserType.js.map +1 -1
  21. package/dist/src/models/identities.d.ts +523 -0
  22. package/dist/src/models/identities.js +57 -0
  23. package/dist/src/models/identities.js.map +1 -0
  24. package/dist/src/models/publicKey.d.ts +0 -1
  25. package/dist/src/models/publicKey.js +1 -1
  26. package/dist/src/models/publicKey.js.map +1 -1
  27. package/dist/src/repositories/cachedPublicKeyRepository.js.map +1 -1
  28. package/dist/src/repositories/publicKeyRepository.js.map +1 -1
  29. package/dist/src/userValidator.js.map +1 -1
  30. package/dist/src/userValidator.test.js.map +1 -1
  31. package/dist/src/utils/createIdentityFromJwt.d.ts +39 -0
  32. package/dist/src/utils/createIdentityFromJwt.js +464 -0
  33. package/dist/src/utils/createIdentityFromJwt.js.map +1 -0
  34. package/dist/src/utils/createIdentityFromJwt.test.d.ts +1 -0
  35. package/dist/src/utils/createIdentityFromJwt.test.js +1433 -0
  36. package/dist/src/utils/createIdentityFromJwt.test.js.map +1 -0
  37. package/dist/src/utils/jwtMock.js.map +1 -1
  38. package/dist/src/utils/logger.js +2 -3
  39. package/dist/src/utils/logger.js.map +1 -1
  40. package/dist/src/utils/testingConfigurations.js +1 -2
  41. package/dist/src/utils/testingConfigurations.js.map +1 -1
  42. package/package.json +30 -30
  43. package/src/config/configs.ts +21 -0
  44. package/src/middleware/tokenTransformationMiddleware.ts +16 -1
  45. package/src/models/accessToken.ts +35 -0
  46. package/src/models/identities.ts +621 -0
  47. package/src/utils/createIdentityFromJwt.test.ts +1595 -0
  48. package/src/utils/createIdentityFromJwt.ts +540 -0
@@ -0,0 +1,1595 @@
1
+ import { expect } from 'chai';
2
+ import { describe, it } from 'mocha';
3
+ import { createIdentityFromJwt } from './createIdentityFromJwt';
4
+
5
+ describe('createIdentityFromJwt', () => {
6
+ it('should recognize an employee', () => {
7
+ const jwt: any = {
8
+ iss: 'security-identity-token-api',
9
+ exp: 1721783045,
10
+ iat: 1721777736,
11
+ keyId: 6,
12
+ displayName: 'infra-auth-auth-playground-dev',
13
+ aud: 'e5dd632b-cb97-48d7-a310-5147be717cde',
14
+ name: 'John DOE',
15
+ sub: 'uuUOZLMFfuURgumF2hE2Z0ZIrVLqLoDy85AeicCJSHQ',
16
+ userName: 'udoejo3',
17
+ givenName: 'John',
18
+ familyName: 'DOE',
19
+ userType: 'employee',
20
+ employeeNumber: '100674051',
21
+ department: '421408000000',
22
+ phoneMobileNumber: '5141111111',
23
+ oid: '0b64042a-9cce-42dc-b645-cd721cbbc179',
24
+ realm: 'employees',
25
+ env: 'dev',
26
+ accessTokenIssuer:
27
+ 'https://login.microsoftonline.com/9f15d2dc-8753-4f83-aac2-a58288d3a4bc/v2.0',
28
+ email: 'john.doe@montreal.ca',
29
+ };
30
+ const identity = createIdentityFromJwt(jwt);
31
+ // console.log(identity);
32
+
33
+ expect(identity.toString()).to.equal(
34
+ 'user:employee:udoejo3:John DOE:john.doe@montreal.ca:100674051:421408000000:vdm'
35
+ );
36
+ expect(`${identity}`).to.equal(
37
+ 'user:employee:udoejo3:John DOE:john.doe@montreal.ca:100674051:421408000000:vdm'
38
+ );
39
+ if (identity.type === 'user') {
40
+ // we test that the registration is optional when you don't know the type of user
41
+ if (identity.attributes.registrationNumber) {
42
+ expect(identity.attributes.registrationNumber).to.eql('100674051');
43
+ } else {
44
+ expect.fail('expected to find the registration number');
45
+ }
46
+ if (identity.attributes.type === 'employee') {
47
+ // we test that the registrationNumber is not optional when type is employee
48
+ expect(identity.attributes.registrationNumber.substring(0, 4)).to.eql('1006');
49
+ } else {
50
+ expect.fail('expected employee');
51
+ }
52
+ } else {
53
+ expect.fail('expected user identity');
54
+ }
55
+ delete identity.toString;
56
+ expect(identity).to.eql({
57
+ type: 'user',
58
+ id: 'udoejo3',
59
+ displayName: 'John DOE',
60
+ attributes: {
61
+ type: 'employee',
62
+ email: 'john.doe@montreal.ca',
63
+ username: 'udoejo3',
64
+ registrationNumber: '100674051',
65
+ department: '421408000000',
66
+ firstName: 'John',
67
+ lastName: 'DOE',
68
+ accountProfile: 'vdm',
69
+ },
70
+ source: {
71
+ issuer: 'security-identity-token-api',
72
+ accessTokenIssuer:
73
+ 'https://login.microsoftonline.com/9f15d2dc-8753-4f83-aac2-a58288d3a4bc/v2.0',
74
+ aud: 'e5dd632b-cb97-48d7-a310-5147be717cde',
75
+ env: 'dev',
76
+ realm: 'employees',
77
+ claim: 'userName',
78
+ internalId: '0b64042a-9cce-42dc-b645-cd721cbbc179',
79
+ },
80
+ });
81
+ // console.log(JSON.stringify(identity));
82
+ expect(JSON.stringify(identity)).to.eql(
83
+ `{"type":"user","id":"udoejo3","displayName":"John DOE","attributes":{"type":"employee","email":"john.doe@montreal.ca","username":"udoejo3","registrationNumber":"100674051","department":"421408000000","firstName":"John","lastName":"DOE","accountProfile":"vdm"},"source":{"aud":"e5dd632b-cb97-48d7-a310-5147be717cde","issuer":"security-identity-token-api","accessTokenIssuer":"https://login.microsoftonline.com/9f15d2dc-8753-4f83-aac2-a58288d3a4bc/v2.0","env":"dev","realm":"employees","claim":"userName","internalId":"0b64042a-9cce-42dc-b645-cd721cbbc179"}}`
84
+ );
85
+ });
86
+
87
+ it('should recognize an employee of SPVM', () => {
88
+ const jwt: any = {
89
+ iss: 'security-identity-token-api',
90
+ exp: 1721783045,
91
+ iat: 1721777736,
92
+ keyId: 6,
93
+ displayName: 'infra-auth-auth-playground-dev',
94
+ aud: 'e5dd632b-cb97-48d7-a310-5147be717cde',
95
+ name: 'John DOE',
96
+ sub: 'uuUOZLMFfuURgumF2hE2Z0ZIrVLqLoDy85AeicCJSHQ',
97
+ userName: 'udoejo3',
98
+ givenName: 'John',
99
+ familyName: 'DOE',
100
+ userType: 'employee',
101
+ employeeNumber: '100674051',
102
+ department: 'PDQ 11',
103
+ phoneMobileNumber: '5141111111',
104
+ oid: '0b64042a-9cce-42dc-b645-cd721cbbc179',
105
+ realm: 'employees',
106
+ env: 'dev',
107
+ accessTokenIssuer:
108
+ 'https://login.microsoftonline.com/9f15d2dc-8753-4f83-aac2-a58288d3a4bc/v2.0',
109
+ email: 'john.doe@spvm.qc.ca',
110
+ };
111
+ const identity = createIdentityFromJwt(jwt);
112
+ // console.log(identity);
113
+
114
+ expect(identity.toString()).to.equal(
115
+ 'user:employee:udoejo3:John DOE:john.doe@spvm.qc.ca:100674051:PDQ 11:spvm'
116
+ );
117
+ delete identity.toString;
118
+ expect(identity).to.eql({
119
+ type: 'user',
120
+ id: 'udoejo3',
121
+ displayName: 'John DOE',
122
+ attributes: {
123
+ type: 'employee',
124
+ email: 'john.doe@spvm.qc.ca',
125
+ username: 'udoejo3',
126
+ registrationNumber: '100674051',
127
+ department: 'PDQ 11',
128
+ firstName: 'John',
129
+ lastName: 'DOE',
130
+ accountProfile: 'spvm',
131
+ },
132
+ source: {
133
+ issuer: 'security-identity-token-api',
134
+ accessTokenIssuer:
135
+ 'https://login.microsoftonline.com/9f15d2dc-8753-4f83-aac2-a58288d3a4bc/v2.0',
136
+ aud: 'e5dd632b-cb97-48d7-a310-5147be717cde',
137
+ env: 'dev',
138
+ realm: 'employees',
139
+ claim: 'userName',
140
+ internalId: '0b64042a-9cce-42dc-b645-cd721cbbc179',
141
+ },
142
+ });
143
+ // console.log(JSON.stringify(identity));
144
+ });
145
+
146
+ it('should recognize an employee using his admin profile (Prod)', () => {
147
+ const jwt: any = {
148
+ iss: 'security-identity-token-api',
149
+ exp: 1721783045,
150
+ iat: 1721777736,
151
+ keyId: 6,
152
+ displayName: 'infra-auth-auth-playground-dev',
153
+ aud: 'e5dd632b-cb97-48d7-a310-5147be717cde',
154
+ name: 'John DOE',
155
+ sub: 'uuUOZLMFfuURgumF2hE2Z0ZIrVLqLoDy85AeicCJSHQ',
156
+ userName: 'udoejo3',
157
+ givenName: 'John',
158
+ familyName: 'DOE',
159
+ userType: 'employee',
160
+ employeeNumber: '100674051',
161
+ department: '421408000000',
162
+ phoneMobileNumber: '5141111111',
163
+ oid: '0b64042a-9cce-42dc-b645-cd721cbbc179',
164
+ realm: 'employees',
165
+ env: 'dev',
166
+ accessTokenIssuer:
167
+ 'https://login.microsoftonline.com/9f15d2dc-8753-4f83-aac2-a58288d3a4bc/v2.0',
168
+ email: 'john.doe.adm@lavilledemontreal.omnicrosoft.com',
169
+ };
170
+ const identity = createIdentityFromJwt(jwt);
171
+ // console.log(identity);
172
+
173
+ expect(identity.toString()).to.equal(
174
+ 'user:employee:udoejo3:John DOE:john.doe.adm@lavilledemontreal.omnicrosoft.com:100674051:421408000000:vdm-admin'
175
+ );
176
+ delete identity.toString;
177
+ expect(identity).to.eql({
178
+ type: 'user',
179
+ id: 'udoejo3',
180
+ displayName: 'John DOE',
181
+ attributes: {
182
+ type: 'employee',
183
+ email: 'john.doe.adm@lavilledemontreal.omnicrosoft.com',
184
+ username: 'udoejo3',
185
+ registrationNumber: '100674051',
186
+ department: '421408000000',
187
+ firstName: 'John',
188
+ lastName: 'DOE',
189
+ accountProfile: 'vdm-admin',
190
+ },
191
+ source: {
192
+ issuer: 'security-identity-token-api',
193
+ accessTokenIssuer:
194
+ 'https://login.microsoftonline.com/9f15d2dc-8753-4f83-aac2-a58288d3a4bc/v2.0',
195
+ aud: 'e5dd632b-cb97-48d7-a310-5147be717cde',
196
+ env: 'dev',
197
+ realm: 'employees',
198
+ claim: 'userName',
199
+ internalId: '0b64042a-9cce-42dc-b645-cd721cbbc179',
200
+ },
201
+ });
202
+ // console.log(JSON.stringify(identity));
203
+ });
204
+ it('should recognize an employee using his admin profile (LAB)', () => {
205
+ const jwt: any = {
206
+ iss: 'security-identity-token-api',
207
+ exp: 1721783045,
208
+ iat: 1721777736,
209
+ keyId: 6,
210
+ displayName: 'infra-auth-auth-playground-dev',
211
+ aud: 'e5dd632b-cb97-48d7-a310-5147be717cde',
212
+ name: 'John DOE',
213
+ sub: 'uuUOZLMFfuURgumF2hE2Z0ZIrVLqLoDy85AeicCJSHQ',
214
+ userName: 'udoejo3',
215
+ givenName: 'John',
216
+ familyName: 'DOE',
217
+ userType: 'employee',
218
+ employeeNumber: '100674051',
219
+ department: '421408000000',
220
+ phoneMobileNumber: '5141111111',
221
+ oid: '0b64042a-9cce-42dc-b645-cd721cbbc179',
222
+ realm: 'employees',
223
+ env: 'dev',
224
+ accessTokenIssuer:
225
+ 'https://login.microsoftonline.com/9f15d2dc-8753-4f83-aac2-a58288d3a4bc/v2.0',
226
+ email: 'john.doe.adm@montrealville.omnicrosoft.com',
227
+ };
228
+ const identity = createIdentityFromJwt(jwt);
229
+ // console.log(identity);
230
+
231
+ expect(identity.toString()).to.equal(
232
+ 'user:employee:udoejo3:John DOE:john.doe.adm@montrealville.omnicrosoft.com:100674051:421408000000:vdm-admin'
233
+ );
234
+ delete identity.toString;
235
+ expect(identity).to.eql({
236
+ type: 'user',
237
+ id: 'udoejo3',
238
+ displayName: 'John DOE',
239
+ attributes: {
240
+ type: 'employee',
241
+ email: 'john.doe.adm@montrealville.omnicrosoft.com',
242
+ username: 'udoejo3',
243
+ registrationNumber: '100674051',
244
+ department: '421408000000',
245
+ firstName: 'John',
246
+ lastName: 'DOE',
247
+ accountProfile: 'vdm-admin',
248
+ },
249
+ source: {
250
+ issuer: 'security-identity-token-api',
251
+ accessTokenIssuer:
252
+ 'https://login.microsoftonline.com/9f15d2dc-8753-4f83-aac2-a58288d3a4bc/v2.0',
253
+ aud: 'e5dd632b-cb97-48d7-a310-5147be717cde',
254
+ env: 'dev',
255
+ realm: 'employees',
256
+ claim: 'userName',
257
+ internalId: '0b64042a-9cce-42dc-b645-cd721cbbc179',
258
+ },
259
+ });
260
+ // console.log(JSON.stringify(identity));
261
+ });
262
+ it('should recognize an external user by its username (codeX)', () => {
263
+ const jwt: any = {
264
+ iss: 'security-identity-token-api',
265
+ exp: 1721783045,
266
+ iat: 1721777736,
267
+ keyId: 6,
268
+ displayName: 'infra-auth-auth-playground-dev',
269
+ aud: 'e5dd632b-cb97-48d7-a310-5147be717cde',
270
+ name: 'John DOE',
271
+ sub: 'uuUOZLMFfuURgumF2hE2Z0ZIrVLqLoDy85AeicCJSHQ',
272
+ userName: 'xdoejo3',
273
+ givenName: 'John',
274
+ familyName: 'DOE',
275
+ userType: 'employee',
276
+ phoneMobileNumber: '5141111111',
277
+ oid: '0b64042a-9cce-42dc-b645-cd721cbbc179',
278
+ realm: 'employees',
279
+ env: 'dev',
280
+ accessTokenIssuer:
281
+ 'https://login.microsoftonline.com/9f15d2dc-8753-4f83-aac2-a58288d3a4bc/v2.0',
282
+ email: 'john.doe@montreal.ca',
283
+ };
284
+ const identity = createIdentityFromJwt(jwt);
285
+ // console.log(identity);
286
+
287
+ expect(identity.toString()).to.equal(
288
+ 'user:external:xdoejo3:John DOE:john.doe@montreal.ca::vdm'
289
+ );
290
+
291
+ delete identity.toString;
292
+ expect(identity).to.eql({
293
+ type: 'user',
294
+ id: 'xdoejo3',
295
+ displayName: 'John DOE',
296
+ attributes: {
297
+ type: 'external',
298
+ email: 'john.doe@montreal.ca',
299
+ username: 'xdoejo3',
300
+ department: undefined,
301
+ firstName: 'John',
302
+ lastName: 'DOE',
303
+ accountProfile: 'vdm',
304
+ },
305
+ source: {
306
+ issuer: 'security-identity-token-api',
307
+ accessTokenIssuer:
308
+ 'https://login.microsoftonline.com/9f15d2dc-8753-4f83-aac2-a58288d3a4bc/v2.0',
309
+ aud: 'e5dd632b-cb97-48d7-a310-5147be717cde',
310
+ env: 'dev',
311
+ realm: 'employees',
312
+ claim: 'userName',
313
+ internalId: '0b64042a-9cce-42dc-b645-cd721cbbc179',
314
+ },
315
+ });
316
+ });
317
+ it('should recognize an external user by its email (.ext)', () => {
318
+ const jwt: any = {
319
+ iss: 'security-identity-token-api',
320
+ exp: 1721783045,
321
+ iat: 1721777736,
322
+ keyId: 6,
323
+ displayName: 'infra-auth-auth-playground-dev',
324
+ aud: 'e5dd632b-cb97-48d7-a310-5147be717cde',
325
+ name: 'John DOE',
326
+ sub: 'uuUOZLMFfuURgumF2hE2Z0ZIrVLqLoDy85AeicCJSHQ',
327
+ userName: 'foobar',
328
+ givenName: 'John',
329
+ familyName: 'DOE',
330
+ userType: 'employee',
331
+ phoneMobileNumber: '5141111111',
332
+ oid: '0b64042a-9cce-42dc-b645-cd721cbbc179',
333
+ realm: 'employees',
334
+ env: 'dev',
335
+ accessTokenIssuer:
336
+ 'https://login.microsoftonline.com/9f15d2dc-8753-4f83-aac2-a58288d3a4bc/v2.0',
337
+ email: 'john.doe.ext@montreal.ca',
338
+ };
339
+ const identity = createIdentityFromJwt(jwt);
340
+ // console.log(identity);
341
+
342
+ expect(identity.toString()).to.equal(
343
+ 'user:external:foobar:John DOE:john.doe.ext@montreal.ca::vdm'
344
+ );
345
+
346
+ delete identity.toString;
347
+ expect(identity).to.eql({
348
+ type: 'user',
349
+ id: 'foobar',
350
+ displayName: 'John DOE',
351
+ attributes: {
352
+ type: 'external',
353
+ email: 'john.doe.ext@montreal.ca',
354
+ username: 'foobar',
355
+ department: undefined,
356
+ firstName: 'John',
357
+ lastName: 'DOE',
358
+ accountProfile: 'vdm',
359
+ },
360
+ source: {
361
+ issuer: 'security-identity-token-api',
362
+ accessTokenIssuer:
363
+ 'https://login.microsoftonline.com/9f15d2dc-8753-4f83-aac2-a58288d3a4bc/v2.0',
364
+ aud: 'e5dd632b-cb97-48d7-a310-5147be717cde',
365
+ env: 'dev',
366
+ realm: 'employees',
367
+ claim: 'userName',
368
+ internalId: '0b64042a-9cce-42dc-b645-cd721cbbc179',
369
+ },
370
+ });
371
+ });
372
+ it('should recognize a generic user', () => {
373
+ const jwt: any = {
374
+ iss: 'security-identity-token-api',
375
+ exp: 1722376780,
376
+ iat: 1722371805,
377
+ keyId: 6,
378
+ displayName: 'infra-auth-auth-playground-dev',
379
+ aud: 'e5dd632b-cb97-48d7-a310-5147be717cde',
380
+ name: 'C.Generique dsec developpeur2',
381
+ sub: 'mlKfaYaESpCXWGoHE3ej-kCaUBwfsQzqayvRvXXQHJo',
382
+ userName: 'cgdsecdev2',
383
+ givenName: 'C.Generique',
384
+ familyName: 'dsec developpeur2',
385
+ userType: 'employee',
386
+ department: '4211',
387
+ oid: '74096b4e-c090-4a97-af04-bbe25dc4f7d6',
388
+ isGenericAccount: true,
389
+ realm: 'employees',
390
+ env: 'dev',
391
+ accessTokenIssuer:
392
+ 'https://login.microsoftonline.com/9f15d2dc-8753-4f83-aac2-a58288d3a4bc/v2.0',
393
+ };
394
+ const identity = createIdentityFromJwt(jwt);
395
+ // console.log(identity);
396
+
397
+ expect(identity.toString()).to.equal(
398
+ 'user:generic:cgdsecdev2:C.Generique dsec developpeur2::4211:vdm'
399
+ );
400
+
401
+ delete identity.toString;
402
+ expect(identity).to.eql({
403
+ type: 'user',
404
+ id: 'cgdsecdev2',
405
+ displayName: 'C.Generique dsec developpeur2',
406
+ attributes: {
407
+ type: 'generic',
408
+ username: 'cgdsecdev2',
409
+ email: undefined,
410
+ department: '4211',
411
+ firstName: 'C.Generique',
412
+ lastName: 'dsec developpeur2',
413
+ accountProfile: 'vdm',
414
+ },
415
+ source: {
416
+ issuer: 'security-identity-token-api',
417
+ accessTokenIssuer:
418
+ 'https://login.microsoftonline.com/9f15d2dc-8753-4f83-aac2-a58288d3a4bc/v2.0',
419
+ aud: 'e5dd632b-cb97-48d7-a310-5147be717cde',
420
+ env: 'dev',
421
+ realm: 'employees',
422
+ claim: 'userName',
423
+ internalId: '74096b4e-c090-4a97-af04-bbe25dc4f7d6',
424
+ },
425
+ });
426
+ });
427
+
428
+ it('should recognize a guest user', () => {
429
+ const jwt: any = {
430
+ iss: 'security-identity-token-api',
431
+ exp: 1722376780,
432
+ iat: 1722371805,
433
+ keyId: 6,
434
+ displayName: 'infra-auth-auth-playground-dev',
435
+ aud: 'e5dd632b-cb97-48d7-a310-5147be717cde',
436
+ name: 'doe.daniel@hydro.qc.ca',
437
+ sub: 'mlKfaYaGoHEESpCXW3ej-kCaUBwfsQzqayvRvXXQHJo',
438
+ userName: 'doe.daniel_hydro.qc.ca#EXT#@lavilledemontreal.omnicrosoft.com',
439
+ userType: 'employee',
440
+ oid: '74096b4e-90c0-974a-af04-bbe25dc4f7d6',
441
+ realm: 'employees',
442
+ env: 'dev',
443
+ accessTokenIssuer:
444
+ 'https://login.microsoftonline.com/9f15d2dc-8753-4f83-aac2-a58288d3a4bc/v2.0',
445
+ email: 'doe.daniel@hydro.qc.ca',
446
+ };
447
+ const identity = createIdentityFromJwt(jwt);
448
+ // console.log(identity);
449
+
450
+ expect(identity.toString()).to.equal(
451
+ 'user:guest:employees:doe.daniel_hydro.qc.ca#EXT#@lavilledemontreal.omnicrosoft.com:doe.daniel@hydro.qc.ca:doe.daniel@hydro.qc.ca'
452
+ );
453
+
454
+ delete identity.toString;
455
+ expect(identity).to.eql({
456
+ type: 'user',
457
+ id: 'doe.daniel_hydro.qc.ca#EXT#@lavilledemontreal.omnicrosoft.com',
458
+ displayName: 'doe.daniel@hydro.qc.ca',
459
+ attributes: {
460
+ type: 'guest',
461
+ email: 'doe.daniel@hydro.qc.ca',
462
+ username: 'doe.daniel_hydro.qc.ca#EXT#@lavilledemontreal.omnicrosoft.com',
463
+ department: undefined,
464
+ firstName: undefined,
465
+ lastName: undefined,
466
+ accountProfile: 'vdm',
467
+ },
468
+ source: {
469
+ issuer: 'security-identity-token-api',
470
+ accessTokenIssuer:
471
+ 'https://login.microsoftonline.com/9f15d2dc-8753-4f83-aac2-a58288d3a4bc/v2.0',
472
+ aud: 'e5dd632b-cb97-48d7-a310-5147be717cde',
473
+ env: 'dev',
474
+ realm: 'employees',
475
+ claim: 'userName',
476
+ internalId: '74096b4e-90c0-974a-af04-bbe25dc4f7d6',
477
+ },
478
+ });
479
+ });
480
+
481
+ it('should recognize an anonymous user', () => {
482
+ const jwt: any = {
483
+ iss: 'security-identity-token-api',
484
+ exp: 1722377045,
485
+ iat: 1722373445,
486
+ keyId: 6,
487
+ displayName: 'Account Identity Managment',
488
+ aud: '@!4025.CA62.9BB6.16C5!0001!2212.0010!0008!2212.0010',
489
+ name: 'srvAcc Anonymous',
490
+ sub: '@!4025.CA62.9BB6.16C5!0001!2212.0010!0000!0000.1111.0020',
491
+ inum: '@!4025.CA62.9BB6.16C5!0001!2212.0010!0000!0000.1111.0020',
492
+ userName: 'srvAccAnonymous',
493
+ givenName: 'srvAcc',
494
+ familyName: 'Anonymous',
495
+ userType: 'anonymous',
496
+ realm: 'anonymous',
497
+ env: 'dev',
498
+ accessTokenIssuer: 'security-identity-anonymous-token-api',
499
+ };
500
+ const identity = createIdentityFromJwt(jwt);
501
+ // console.log(identity);
502
+
503
+ expect(identity.toString()).to.equal('anonymous:srvAccAnonymous:srvAcc Anonymous');
504
+
505
+ delete identity.toString;
506
+ expect(identity).to.eql({
507
+ type: 'anonymous',
508
+ id: 'srvAccAnonymous',
509
+ displayName: 'srvAcc Anonymous',
510
+ attributes: {
511
+ type: 'anonymous',
512
+ username: 'srvAccAnonymous',
513
+ },
514
+ source: {
515
+ issuer: 'security-identity-token-api',
516
+ accessTokenIssuer: 'security-identity-anonymous-token-api',
517
+ aud: '@!4025.CA62.9BB6.16C5!0001!2212.0010!0008!2212.0010',
518
+ env: 'dev',
519
+ realm: 'anonymous',
520
+ claim: 'userName',
521
+ internalId: '@!4025.CA62.9BB6.16C5!0001!2212.0010!0000!0000.1111.0020',
522
+ },
523
+ });
524
+ });
525
+
526
+ it('should recognize a client service account', () => {
527
+ const jwt: any = {
528
+ iss: 'security-identity-token-api',
529
+ exp: 1721782408,
530
+ iat: 1721778508,
531
+ keyId: 6,
532
+ displayName: 'infra-auth-auth-playground-dev',
533
+ aud: 'e5dd632b-cb97-48d7-a310-cde5147be717',
534
+ sub: 'e5dd632b-cb97-48d7-a310-cde5147be717',
535
+ userType: 'client',
536
+ oid: '18e8a9b0-876f-4a78-9934-ce3774903c2a',
537
+ realm: 'employees',
538
+ env: 'dev',
539
+ accessTokenIssuer:
540
+ 'https://login.microsoftonline.com/9f15d2dc-8753-4f83-aac2-a58288d3a4bc/v2.0',
541
+ };
542
+ const identity = createIdentityFromJwt(jwt);
543
+ // console.log(identity);
544
+
545
+ expect(identity.toString()).to.equal(
546
+ 'service-account:client:e5dd632b-cb97-48d7-a310-cde5147be717:infra-auth-auth-playground-dev'
547
+ );
548
+
549
+ delete identity.toString;
550
+ expect(identity).to.eql({
551
+ type: 'service-account',
552
+ id: 'e5dd632b-cb97-48d7-a310-cde5147be717',
553
+ displayName: 'infra-auth-auth-playground-dev',
554
+ attributes: {
555
+ type: 'client',
556
+ },
557
+ source: {
558
+ issuer: 'security-identity-token-api',
559
+ accessTokenIssuer:
560
+ 'https://login.microsoftonline.com/9f15d2dc-8753-4f83-aac2-a58288d3a4bc/v2.0',
561
+ aud: 'e5dd632b-cb97-48d7-a310-cde5147be717',
562
+ env: 'dev',
563
+ realm: 'employees',
564
+ claim: 'aud',
565
+ internalId: '18e8a9b0-876f-4a78-9934-ce3774903c2a',
566
+ },
567
+ });
568
+ });
569
+
570
+ it('should recognize a user service account', () => {
571
+ const jwt: any = {
572
+ iss: 'security-identity-token-api',
573
+ exp: 1722375517,
574
+ iat: 1722373717,
575
+ keyId: 6,
576
+ displayName: 'DiagnosticsCanary',
577
+ aud: '@!4025.CA62.9BB6.16C5!0001!2212.0010!0008!2212.0130',
578
+ name: 'srvAcc Diagnostics Canary',
579
+ sub: '@!4025.CA62.9BB6.16C5!0001!2212.0010!0000!0000.2222.0080',
580
+ inum: '@!4025.CA62.9BB6.16C5!0001!2212.0010!0000!0000.2222.0080',
581
+ userName: 'srvAccDiagCanary',
582
+ givenName: 'srvAcc',
583
+ familyName: 'srvAccDiagCanary',
584
+ userType: 'serviceAccount',
585
+ realm: 'citizens',
586
+ env: 'dev',
587
+ accessTokenIssuer: 'https://auth.dev.interne.montreal.ca',
588
+ };
589
+ const identity = createIdentityFromJwt(jwt);
590
+ // console.log(identity);
591
+
592
+ expect(identity.toString()).to.equal(
593
+ 'service-account:user:srvAccDiagCanary:srvAcc Diagnostics Canary'
594
+ );
595
+
596
+ delete identity.toString;
597
+ expect(identity).to.eql({
598
+ type: 'service-account',
599
+ id: 'srvAccDiagCanary',
600
+ displayName: 'srvAcc Diagnostics Canary',
601
+ attributes: {
602
+ type: 'user',
603
+ username: 'srvAccDiagCanary',
604
+ },
605
+ source: {
606
+ issuer: 'security-identity-token-api',
607
+ accessTokenIssuer: 'https://auth.dev.interne.montreal.ca',
608
+ aud: '@!4025.CA62.9BB6.16C5!0001!2212.0010!0008!2212.0130',
609
+ env: 'dev',
610
+ realm: 'citizens',
611
+ claim: 'userName',
612
+ internalId: '@!4025.CA62.9BB6.16C5!0001!2212.0010!0000!0000.2222.0080',
613
+ },
614
+ });
615
+ });
616
+
617
+ it('should recognize a citizen', () => {
618
+ const jwt: any = {
619
+ iss: 'security-identity-token-api',
620
+ exp: 1722377562,
621
+ iat: 1722373962,
622
+ keyId: 6,
623
+ displayName: 'infra-auth-auth-playground',
624
+ aud: 'a496befa-db7d-45a6-ac7a-11471816b8f1',
625
+ name: 'John Doe',
626
+ sub: '@!4025.CA62.9BB6.16C5!0001!2212.0010!0000!3F39.BEDB.4ADB.F74D',
627
+ inum: '@!4025.CA62.9BB6.16C5!0001!2212.0010!0000!3F39.BEDB.4ADB.F74D',
628
+ userName: 'john.doe@mailinator.com',
629
+ givenName: 'John',
630
+ familyName: 'Doe',
631
+ oid: '7d69384b-dcf4-4972-ebb3-d546551c700f',
632
+ realm: 'citizens',
633
+ env: 'dev',
634
+ accessTokenIssuer:
635
+ 'https://connexion.dev.montreal.ca/1543b575-116b-4325-a0bf-3ccdd7925321/v2.0/',
636
+ mtlIdentityId: '@!4025.CA62.9BB6.16C5!0001!2212.0010!0000!3F39.BEDB.4ADB.F74D',
637
+ email: 'john.doe@mailinator.com',
638
+ };
639
+ const identity = createIdentityFromJwt(jwt);
640
+ // console.log(identity);
641
+
642
+ expect(identity.toString()).to.equal(
643
+ 'user:citizen:@!4025.CA62.9BB6.16C5!0001!2212.0010!0000!3F39.BEDB.4ADB.F74D:John Doe:john.doe@mailinator.com'
644
+ );
645
+
646
+ delete identity.toString;
647
+ expect(identity).to.eql({
648
+ type: 'user',
649
+ id: '@!4025.CA62.9BB6.16C5!0001!2212.0010!0000!3F39.BEDB.4ADB.F74D',
650
+ displayName: 'John Doe',
651
+ attributes: {
652
+ type: 'citizen',
653
+ username: 'john.doe@mailinator.com',
654
+ email: 'john.doe@mailinator.com',
655
+ firstName: 'John',
656
+ lastName: 'Doe',
657
+ },
658
+ source: {
659
+ issuer: 'security-identity-token-api',
660
+ accessTokenIssuer:
661
+ 'https://connexion.dev.montreal.ca/1543b575-116b-4325-a0bf-3ccdd7925321/v2.0/',
662
+ aud: 'a496befa-db7d-45a6-ac7a-11471816b8f1',
663
+ env: 'dev',
664
+ realm: 'citizens',
665
+ claim: 'mtlIdentityId',
666
+ internalId: '7d69384b-dcf4-4972-ebb3-d546551c700f',
667
+ },
668
+ });
669
+ });
670
+
671
+ it('should default to unknown user identity', () => {
672
+ const jwt: any = {
673
+ iss: 'security-identity-token-api',
674
+ exp: 1722377562,
675
+ iat: 1722373962,
676
+ keyId: 6,
677
+ displayName: 'infra-auth-auth-playground',
678
+ aud: 'a496befa-db7d-45a6-ac7a-11471816b8f1',
679
+ name: 'John Doe',
680
+ sub: '12345',
681
+ userName: 'john.doe',
682
+ userType: 'SomeUnknownType',
683
+ givenName: 'John',
684
+ familyName: 'Doe',
685
+ realm: 'employees',
686
+ env: 'dev',
687
+ accessTokenIssuer:
688
+ 'https://login.microsoftonline.com/9f15d2dc-8753-4f83-aac2-a58288d3a4bc/v2.0',
689
+ email: 'john.doe@mailinator.com',
690
+ };
691
+ const identity = createIdentityFromJwt(jwt);
692
+ // console.log(identity);
693
+
694
+ expect(identity.toString()).to.equal(
695
+ 'user:unknown:john.doe:John Doe:john.doe@mailinator.com:::vdm'
696
+ );
697
+
698
+ delete identity.toString;
699
+ expect(identity).to.eql({
700
+ type: 'user',
701
+ id: 'john.doe',
702
+ displayName: 'John Doe',
703
+ attributes: {
704
+ type: 'unknown',
705
+ email: 'john.doe@mailinator.com',
706
+ username: 'john.doe',
707
+ registrationNumber: undefined,
708
+ department: undefined,
709
+ firstName: 'John',
710
+ lastName: 'Doe',
711
+ accountProfile: 'vdm',
712
+ },
713
+ source: {
714
+ issuer: 'security-identity-token-api',
715
+ accessTokenIssuer:
716
+ 'https://login.microsoftonline.com/9f15d2dc-8753-4f83-aac2-a58288d3a4bc/v2.0',
717
+ aud: 'a496befa-db7d-45a6-ac7a-11471816b8f1',
718
+ env: 'dev',
719
+ realm: 'employees',
720
+ claim: 'userName',
721
+ internalId: '12345',
722
+ },
723
+ });
724
+ });
725
+
726
+ it('should default to unknown identity, with name', () => {
727
+ const jwt: any = {
728
+ iss: 'security-identity-token-api',
729
+ exp: 1722377562,
730
+ iat: 1722373962,
731
+ keyId: 6,
732
+ displayName: 'infra-auth-auth-playground',
733
+ aud: 'a496befa-db7d-45a6-ac7a-11471816b8f1',
734
+ name: 'John Doe',
735
+ sub: '12345',
736
+ userType: 'SomeUnknownType',
737
+ realm: 'employees',
738
+ env: 'dev',
739
+ accessTokenIssuer:
740
+ 'https://login.microsoftonline.com/9f15d2dc-8753-4f83-aac2-a58288d3a4bc/v2.0',
741
+ };
742
+ const identity = createIdentityFromJwt(jwt);
743
+ // console.log(identity);
744
+
745
+ expect(identity.toString()).to.equal('unknown:12345:John Doe');
746
+
747
+ delete identity.toString;
748
+ expect(identity).to.eql({
749
+ type: 'unknown',
750
+ id: '12345',
751
+ displayName: 'John Doe',
752
+ attributes: {
753
+ type: 'unknown',
754
+ },
755
+ source: {
756
+ issuer: 'security-identity-token-api',
757
+ accessTokenIssuer:
758
+ 'https://login.microsoftonline.com/9f15d2dc-8753-4f83-aac2-a58288d3a4bc/v2.0',
759
+ aud: 'a496befa-db7d-45a6-ac7a-11471816b8f1',
760
+ env: 'dev',
761
+ realm: 'employees',
762
+ claim: 'sub',
763
+ internalId: '12345',
764
+ },
765
+ });
766
+ });
767
+
768
+ it('should default to unknown identity, without name', () => {
769
+ const jwt: any = {
770
+ iss: 'security-identity-token-api',
771
+ exp: 1722377562,
772
+ iat: 1722373962,
773
+ keyId: 6,
774
+ displayName: 'infra-auth-auth-playground',
775
+ aud: 'a496befa-db7d-45a6-ac7a-11471816b8f1',
776
+ // name: 'John Doe',
777
+ sub: '12345',
778
+ userType: 'SomeUnknownType',
779
+ realm: 'employees',
780
+ env: 'dev',
781
+ accessTokenIssuer:
782
+ 'https://login.microsoftonline.com/9f15d2dc-8753-4f83-aac2-a58288d3a4bc/v2.0',
783
+ };
784
+ const identity = createIdentityFromJwt(jwt);
785
+ // console.log(identity);
786
+
787
+ expect(identity.toString()).to.equal('unknown:12345:unknown');
788
+
789
+ delete identity.toString;
790
+ expect(identity).to.eql({
791
+ type: 'unknown',
792
+ id: '12345',
793
+ displayName: 'unknown',
794
+ attributes: {
795
+ type: 'unknown',
796
+ },
797
+ source: {
798
+ issuer: 'security-identity-token-api',
799
+ accessTokenIssuer:
800
+ 'https://login.microsoftonline.com/9f15d2dc-8753-4f83-aac2-a58288d3a4bc/v2.0',
801
+ aud: 'a496befa-db7d-45a6-ac7a-11471816b8f1',
802
+ env: 'dev',
803
+ realm: 'employees',
804
+ claim: 'sub',
805
+ internalId: '12345',
806
+ },
807
+ });
808
+ });
809
+
810
+ describe('should not recognize an employee when some required attributes are missing', () => {
811
+ it('no registration number', () => {
812
+ const jwt: any = {
813
+ iss: 'security-identity-token-api',
814
+ exp: 1721783045,
815
+ iat: 1721777736,
816
+ keyId: 6,
817
+ displayName: 'infra-auth-auth-playground-dev',
818
+ aud: 'e5dd632b-cb97-48d7-a310-5147be717cde',
819
+ name: 'John DOE',
820
+ sub: 'uuUOZLMFfuURgumF2hE2Z0ZIrVLqLoDy85AeicCJSHQ',
821
+ userName: 'udoejo3',
822
+ givenName: 'John',
823
+ familyName: 'DOE',
824
+ userType: 'employee',
825
+ // employeeNumber: '100674051',
826
+ department: '421408000000',
827
+ phoneMobileNumber: '5141111111',
828
+ oid: '0b64042a-9cce-42dc-b645-cd721cbbc179',
829
+ realm: 'employees',
830
+ env: 'dev',
831
+ accessTokenIssuer:
832
+ 'https://login.microsoftonline.com/9f15d2dc-8753-4f83-aac2-a58288d3a4bc/v2.0',
833
+ email: 'john.doe@montreal.ca',
834
+ };
835
+ const identity = createIdentityFromJwt(jwt);
836
+ // console.log(identity);
837
+
838
+ expect(identity.toString()).to.equal(
839
+ 'user:unknown:udoejo3:John DOE:john.doe@montreal.ca::421408000000:vdm'
840
+ );
841
+ delete identity.toString;
842
+ expect(identity).to.eql({
843
+ type: 'user',
844
+ id: 'udoejo3',
845
+ displayName: 'John DOE',
846
+ attributes: {
847
+ type: 'unknown',
848
+ email: 'john.doe@montreal.ca',
849
+ username: 'udoejo3',
850
+ registrationNumber: undefined,
851
+ department: '421408000000',
852
+ firstName: 'John',
853
+ lastName: 'DOE',
854
+ accountProfile: 'vdm',
855
+ },
856
+ source: {
857
+ issuer: 'security-identity-token-api',
858
+ accessTokenIssuer:
859
+ 'https://login.microsoftonline.com/9f15d2dc-8753-4f83-aac2-a58288d3a4bc/v2.0',
860
+ aud: 'e5dd632b-cb97-48d7-a310-5147be717cde',
861
+ env: 'dev',
862
+ realm: 'employees',
863
+ claim: 'userName',
864
+ internalId: '0b64042a-9cce-42dc-b645-cd721cbbc179',
865
+ },
866
+ });
867
+ // console.log(JSON.stringify(identity));
868
+ });
869
+
870
+ it('no department', () => {
871
+ const jwt: any = {
872
+ iss: 'security-identity-token-api',
873
+ exp: 1721783045,
874
+ iat: 1721777736,
875
+ keyId: 6,
876
+ displayName: 'infra-auth-auth-playground-dev',
877
+ aud: 'e5dd632b-cb97-48d7-a310-5147be717cde',
878
+ name: 'John DOE',
879
+ sub: 'uuUOZLMFfuURgumF2hE2Z0ZIrVLqLoDy85AeicCJSHQ',
880
+ userName: 'udoejo3',
881
+ givenName: 'John',
882
+ familyName: 'DOE',
883
+ userType: 'employee',
884
+ employeeNumber: '100674051',
885
+ // department: '421408000000',
886
+ phoneMobileNumber: '5141111111',
887
+ oid: '0b64042a-9cce-42dc-b645-cd721cbbc179',
888
+ realm: 'employees',
889
+ env: 'dev',
890
+ accessTokenIssuer:
891
+ 'https://login.microsoftonline.com/9f15d2dc-8753-4f83-aac2-a58288d3a4bc/v2.0',
892
+ email: 'john.doe@montreal.ca',
893
+ };
894
+ const identity = createIdentityFromJwt(jwt);
895
+ // console.log(identity);
896
+
897
+ expect(identity.toString()).to.equal(
898
+ 'user:unknown:udoejo3:John DOE:john.doe@montreal.ca:100674051::vdm'
899
+ );
900
+ delete identity.toString;
901
+ expect(identity).to.eql({
902
+ type: 'user',
903
+ id: 'udoejo3',
904
+ displayName: 'John DOE',
905
+ attributes: {
906
+ type: 'unknown',
907
+ email: 'john.doe@montreal.ca',
908
+ username: 'udoejo3',
909
+ registrationNumber: '100674051',
910
+ department: undefined,
911
+ firstName: 'John',
912
+ lastName: 'DOE',
913
+ accountProfile: 'vdm',
914
+ },
915
+ source: {
916
+ issuer: 'security-identity-token-api',
917
+ accessTokenIssuer:
918
+ 'https://login.microsoftonline.com/9f15d2dc-8753-4f83-aac2-a58288d3a4bc/v2.0',
919
+ aud: 'e5dd632b-cb97-48d7-a310-5147be717cde',
920
+ env: 'dev',
921
+ realm: 'employees',
922
+ claim: 'userName',
923
+ internalId: '0b64042a-9cce-42dc-b645-cd721cbbc179',
924
+ },
925
+ });
926
+ // console.log(JSON.stringify(identity));
927
+ });
928
+
929
+ it('no valid codeU', () => {
930
+ const jwt: any = {
931
+ iss: 'security-identity-token-api',
932
+ exp: 1721783045,
933
+ iat: 1721777736,
934
+ keyId: 6,
935
+ displayName: 'infra-auth-auth-playground-dev',
936
+ aud: 'e5dd632b-cb97-48d7-a310-5147be717cde',
937
+ name: 'John DOE',
938
+ sub: 'uuUOZLMFfuURgumF2hE2Z0ZIrVLqLoDy85AeicCJSHQ',
939
+ userName: 'usr_foo33',
940
+ givenName: 'John',
941
+ familyName: 'DOE',
942
+ userType: 'employee',
943
+ employeeNumber: '100674051',
944
+ department: '421408000000',
945
+ phoneMobileNumber: '5141111111',
946
+ oid: '0b64042a-9cce-42dc-b645-cd721cbbc179',
947
+ realm: 'employees',
948
+ env: 'dev',
949
+ accessTokenIssuer:
950
+ 'https://login.microsoftonline.com/9f15d2dc-8753-4f83-aac2-a58288d3a4bc/v2.0',
951
+ email: 'john.doe@montreal.ca',
952
+ };
953
+ const identity = createIdentityFromJwt(jwt);
954
+ // console.log(identity);
955
+
956
+ expect(identity.toString()).to.equal(
957
+ 'user:unknown:usr_foo33:John DOE:john.doe@montreal.ca:100674051:421408000000:vdm'
958
+ );
959
+ delete identity.toString;
960
+ expect(identity).to.eql({
961
+ type: 'user',
962
+ id: 'usr_foo33',
963
+ displayName: 'John DOE',
964
+ attributes: {
965
+ type: 'unknown',
966
+ email: 'john.doe@montreal.ca',
967
+ username: 'usr_foo33',
968
+ registrationNumber: '100674051',
969
+ department: '421408000000',
970
+ firstName: 'John',
971
+ lastName: 'DOE',
972
+ accountProfile: 'vdm',
973
+ },
974
+ source: {
975
+ issuer: 'security-identity-token-api',
976
+ accessTokenIssuer:
977
+ 'https://login.microsoftonline.com/9f15d2dc-8753-4f83-aac2-a58288d3a4bc/v2.0',
978
+ aud: 'e5dd632b-cb97-48d7-a310-5147be717cde',
979
+ env: 'dev',
980
+ realm: 'employees',
981
+ claim: 'userName',
982
+ internalId: '0b64042a-9cce-42dc-b645-cd721cbbc179',
983
+ },
984
+ });
985
+ // console.log(JSON.stringify(identity));
986
+ });
987
+ it('no username', () => {
988
+ const jwt: any = {
989
+ iss: 'security-identity-token-api',
990
+ exp: 1721783045,
991
+ iat: 1721777736,
992
+ keyId: 6,
993
+ displayName: 'infra-auth-auth-playground-dev',
994
+ aud: 'e5dd632b-cb97-48d7-a310-5147be717cde',
995
+ name: 'John DOE',
996
+ sub: 'uuUOZLMFfuURgumF2hE2Z0ZIrVLqLoDy85AeicCJSHQ',
997
+ // userName: 'usr_foo33',
998
+ givenName: 'John',
999
+ familyName: 'DOE',
1000
+ userType: 'employee',
1001
+ employeeNumber: '100674051',
1002
+ department: '421408000000',
1003
+ phoneMobileNumber: '5141111111',
1004
+ oid: '0b64042a-9cce-42dc-b645-cd721cbbc179',
1005
+ realm: 'employees',
1006
+ env: 'dev',
1007
+ accessTokenIssuer:
1008
+ 'https://login.microsoftonline.com/9f15d2dc-8753-4f83-aac2-a58288d3a4bc/v2.0',
1009
+ email: 'john.doe@montreal.ca',
1010
+ };
1011
+ const identity = createIdentityFromJwt(jwt);
1012
+ // console.log(identity);
1013
+
1014
+ expect(identity.toString()).to.equal(
1015
+ 'user:unknown:john.doe@montreal.ca:John DOE:john.doe@montreal.ca:100674051:421408000000:vdm'
1016
+ );
1017
+ delete identity.toString;
1018
+ expect(identity).to.eql({
1019
+ type: 'user',
1020
+ id: 'john.doe@montreal.ca',
1021
+ displayName: 'John DOE',
1022
+ attributes: {
1023
+ type: 'unknown',
1024
+ email: 'john.doe@montreal.ca',
1025
+ username: undefined,
1026
+ registrationNumber: '100674051',
1027
+ department: '421408000000',
1028
+ firstName: 'John',
1029
+ lastName: 'DOE',
1030
+ accountProfile: 'vdm',
1031
+ },
1032
+ source: {
1033
+ issuer: 'security-identity-token-api',
1034
+ accessTokenIssuer:
1035
+ 'https://login.microsoftonline.com/9f15d2dc-8753-4f83-aac2-a58288d3a4bc/v2.0',
1036
+ aud: 'e5dd632b-cb97-48d7-a310-5147be717cde',
1037
+ env: 'dev',
1038
+ realm: 'employees',
1039
+ claim: 'email',
1040
+ internalId: '0b64042a-9cce-42dc-b645-cd721cbbc179',
1041
+ },
1042
+ });
1043
+ // console.log(JSON.stringify(identity));
1044
+ });
1045
+ it('no name', () => {
1046
+ const jwt: any = {
1047
+ iss: 'security-identity-token-api',
1048
+ exp: 1721783045,
1049
+ iat: 1721777736,
1050
+ keyId: 6,
1051
+ displayName: 'infra-auth-auth-playground-dev',
1052
+ aud: 'e5dd632b-cb97-48d7-a310-5147be717cde',
1053
+ // name: 'John DOE',
1054
+ sub: 'uuUOZLMFfuURgumF2hE2Z0ZIrVLqLoDy85AeicCJSHQ',
1055
+ userName: 'udoejo3',
1056
+ givenName: 'John',
1057
+ familyName: 'DOE',
1058
+ userType: 'employee',
1059
+ employeeNumber: '100674051',
1060
+ department: '421408000000',
1061
+ phoneMobileNumber: '5141111111',
1062
+ oid: '0b64042a-9cce-42dc-b645-cd721cbbc179',
1063
+ realm: 'employees',
1064
+ env: 'dev',
1065
+ accessTokenIssuer:
1066
+ 'https://login.microsoftonline.com/9f15d2dc-8753-4f83-aac2-a58288d3a4bc/v2.0',
1067
+ email: 'john.doe@montreal.ca',
1068
+ };
1069
+ const identity = createIdentityFromJwt(jwt);
1070
+ // console.log(identity);
1071
+
1072
+ expect(identity.toString()).to.equal(
1073
+ 'user:unknown:udoejo3:john.doe@montreal.ca:john.doe@montreal.ca:100674051:421408000000:vdm'
1074
+ );
1075
+ delete identity.toString;
1076
+ expect(identity).to.eql({
1077
+ type: 'user',
1078
+ id: 'udoejo3',
1079
+ displayName: 'john.doe@montreal.ca',
1080
+ attributes: {
1081
+ type: 'unknown',
1082
+ email: 'john.doe@montreal.ca',
1083
+ username: 'udoejo3',
1084
+ registrationNumber: '100674051',
1085
+ department: '421408000000',
1086
+ firstName: 'John',
1087
+ lastName: 'DOE',
1088
+ accountProfile: 'vdm',
1089
+ },
1090
+ source: {
1091
+ issuer: 'security-identity-token-api',
1092
+ accessTokenIssuer:
1093
+ 'https://login.microsoftonline.com/9f15d2dc-8753-4f83-aac2-a58288d3a4bc/v2.0',
1094
+ aud: 'e5dd632b-cb97-48d7-a310-5147be717cde',
1095
+ env: 'dev',
1096
+ realm: 'employees',
1097
+ claim: 'userName',
1098
+ internalId: '0b64042a-9cce-42dc-b645-cd721cbbc179',
1099
+ },
1100
+ });
1101
+ // console.log(JSON.stringify(identity));
1102
+ });
1103
+ it('no name and no email', () => {
1104
+ const jwt: any = {
1105
+ iss: 'security-identity-token-api',
1106
+ exp: 1721783045,
1107
+ iat: 1721777736,
1108
+ keyId: 6,
1109
+ displayName: 'infra-auth-auth-playground-dev',
1110
+ aud: 'e5dd632b-cb97-48d7-a310-5147be717cde',
1111
+ // name: 'John DOE',
1112
+ sub: 'uuUOZLMFfuURgumF2hE2Z0ZIrVLqLoDy85AeicCJSHQ',
1113
+ userName: 'udoejo3',
1114
+ givenName: 'John',
1115
+ familyName: 'DOE',
1116
+ userType: 'employee',
1117
+ employeeNumber: '100674051',
1118
+ department: '421408000000',
1119
+ phoneMobileNumber: '5141111111',
1120
+ oid: '0b64042a-9cce-42dc-b645-cd721cbbc179',
1121
+ realm: 'employees',
1122
+ env: 'dev',
1123
+ accessTokenIssuer:
1124
+ 'https://login.microsoftonline.com/9f15d2dc-8753-4f83-aac2-a58288d3a4bc/v2.0',
1125
+ // email: 'john.doe@montreal.ca',
1126
+ };
1127
+ const identity = createIdentityFromJwt(jwt);
1128
+ // console.log(identity);
1129
+
1130
+ expect(identity.toString()).to.equal(
1131
+ 'user:unknown:udoejo3:udoejo3::100674051:421408000000:vdm'
1132
+ );
1133
+ delete identity.toString;
1134
+ expect(identity).to.eql({
1135
+ type: 'user',
1136
+ id: 'udoejo3',
1137
+ displayName: 'udoejo3',
1138
+ attributes: {
1139
+ type: 'unknown',
1140
+ email: undefined,
1141
+ username: 'udoejo3',
1142
+ registrationNumber: '100674051',
1143
+ department: '421408000000',
1144
+ firstName: 'John',
1145
+ lastName: 'DOE',
1146
+ accountProfile: 'vdm',
1147
+ },
1148
+ source: {
1149
+ issuer: 'security-identity-token-api',
1150
+ accessTokenIssuer:
1151
+ 'https://login.microsoftonline.com/9f15d2dc-8753-4f83-aac2-a58288d3a4bc/v2.0',
1152
+ aud: 'e5dd632b-cb97-48d7-a310-5147be717cde',
1153
+ env: 'dev',
1154
+ realm: 'employees',
1155
+ claim: 'userName',
1156
+ internalId: '0b64042a-9cce-42dc-b645-cd721cbbc179',
1157
+ },
1158
+ });
1159
+ // console.log(JSON.stringify(identity));
1160
+ });
1161
+ it('no first name', () => {
1162
+ const jwt: any = {
1163
+ iss: 'security-identity-token-api',
1164
+ exp: 1721783045,
1165
+ iat: 1721777736,
1166
+ keyId: 6,
1167
+ displayName: 'infra-auth-auth-playground-dev',
1168
+ aud: 'e5dd632b-cb97-48d7-a310-5147be717cde',
1169
+ name: 'John DOE',
1170
+ sub: 'uuUOZLMFfuURgumF2hE2Z0ZIrVLqLoDy85AeicCJSHQ',
1171
+ userName: 'udoejo3',
1172
+ // givenName: 'John',
1173
+ familyName: 'DOE',
1174
+ userType: 'employee',
1175
+ employeeNumber: '100674051',
1176
+ department: '421408000000',
1177
+ phoneMobileNumber: '5141111111',
1178
+ oid: '0b64042a-9cce-42dc-b645-cd721cbbc179',
1179
+ realm: 'employees',
1180
+ env: 'dev',
1181
+ accessTokenIssuer:
1182
+ 'https://login.microsoftonline.com/9f15d2dc-8753-4f83-aac2-a58288d3a4bc/v2.0',
1183
+ email: 'john.doe@montreal.ca',
1184
+ };
1185
+ const identity = createIdentityFromJwt(jwt);
1186
+ // console.log(identity);
1187
+
1188
+ expect(identity.toString()).to.equal(
1189
+ 'user:unknown:udoejo3:John DOE:john.doe@montreal.ca:100674051:421408000000:vdm'
1190
+ );
1191
+ delete identity.toString;
1192
+ expect(identity).to.eql({
1193
+ type: 'user',
1194
+ id: 'udoejo3',
1195
+ displayName: 'John DOE',
1196
+ attributes: {
1197
+ type: 'unknown',
1198
+ email: 'john.doe@montreal.ca',
1199
+ username: 'udoejo3',
1200
+ registrationNumber: '100674051',
1201
+ department: '421408000000',
1202
+ firstName: undefined,
1203
+ lastName: 'DOE',
1204
+ accountProfile: 'vdm',
1205
+ },
1206
+ source: {
1207
+ issuer: 'security-identity-token-api',
1208
+ accessTokenIssuer:
1209
+ 'https://login.microsoftonline.com/9f15d2dc-8753-4f83-aac2-a58288d3a4bc/v2.0',
1210
+ aud: 'e5dd632b-cb97-48d7-a310-5147be717cde',
1211
+ env: 'dev',
1212
+ realm: 'employees',
1213
+ claim: 'userName',
1214
+ internalId: '0b64042a-9cce-42dc-b645-cd721cbbc179',
1215
+ },
1216
+ });
1217
+ // console.log(JSON.stringify(identity));
1218
+ });
1219
+ it('no last name', () => {
1220
+ const jwt: any = {
1221
+ iss: 'security-identity-token-api',
1222
+ exp: 1721783045,
1223
+ iat: 1721777736,
1224
+ keyId: 6,
1225
+ displayName: 'infra-auth-auth-playground-dev',
1226
+ aud: 'e5dd632b-cb97-48d7-a310-5147be717cde',
1227
+ name: 'John DOE',
1228
+ sub: 'uuUOZLMFfuURgumF2hE2Z0ZIrVLqLoDy85AeicCJSHQ',
1229
+ userName: 'udoejo3',
1230
+ givenName: 'John',
1231
+ // familyName: 'DOE',
1232
+ userType: 'employee',
1233
+ employeeNumber: '100674051',
1234
+ department: '421408000000',
1235
+ phoneMobileNumber: '5141111111',
1236
+ oid: '0b64042a-9cce-42dc-b645-cd721cbbc179',
1237
+ realm: 'employees',
1238
+ env: 'dev',
1239
+ accessTokenIssuer:
1240
+ 'https://login.microsoftonline.com/9f15d2dc-8753-4f83-aac2-a58288d3a4bc/v2.0',
1241
+ email: 'john.doe@montreal.ca',
1242
+ };
1243
+ const identity = createIdentityFromJwt(jwt);
1244
+ // console.log(identity);
1245
+
1246
+ expect(identity.toString()).to.equal(
1247
+ 'user:unknown:udoejo3:John DOE:john.doe@montreal.ca:100674051:421408000000:vdm'
1248
+ );
1249
+ delete identity.toString;
1250
+ expect(identity).to.eql({
1251
+ type: 'user',
1252
+ id: 'udoejo3',
1253
+ displayName: 'John DOE',
1254
+ attributes: {
1255
+ type: 'unknown',
1256
+ email: 'john.doe@montreal.ca',
1257
+ username: 'udoejo3',
1258
+ registrationNumber: '100674051',
1259
+ department: '421408000000',
1260
+ firstName: 'John',
1261
+ lastName: undefined,
1262
+ accountProfile: 'vdm',
1263
+ },
1264
+ source: {
1265
+ issuer: 'security-identity-token-api',
1266
+ accessTokenIssuer:
1267
+ 'https://login.microsoftonline.com/9f15d2dc-8753-4f83-aac2-a58288d3a4bc/v2.0',
1268
+ aud: 'e5dd632b-cb97-48d7-a310-5147be717cde',
1269
+ env: 'dev',
1270
+ realm: 'employees',
1271
+ claim: 'userName',
1272
+ internalId: '0b64042a-9cce-42dc-b645-cd721cbbc179',
1273
+ },
1274
+ });
1275
+ // console.log(JSON.stringify(identity));
1276
+ });
1277
+ });
1278
+ describe('should not recognize an external user when some required attributes are missing', () => {
1279
+ it('invalid codeX', () => {
1280
+ const jwt: any = {
1281
+ iss: 'security-identity-token-api',
1282
+ exp: 1721783045,
1283
+ iat: 1721777736,
1284
+ keyId: 6,
1285
+ displayName: 'infra-auth-auth-playground-dev',
1286
+ aud: 'e5dd632b-cb97-48d7-a310-5147be717cde',
1287
+ name: 'John DOE',
1288
+ sub: 'uuUOZLMFfuURgumF2hE2Z0ZIrVLqLoDy85AeicCJSHQ',
1289
+ userName: 'xdr_foo',
1290
+ givenName: 'John',
1291
+ familyName: 'DOE',
1292
+ userType: 'employee',
1293
+ phoneMobileNumber: '5141111111',
1294
+ oid: '0b64042a-9cce-42dc-b645-cd721cbbc179',
1295
+ realm: 'employees',
1296
+ env: 'dev',
1297
+ accessTokenIssuer:
1298
+ 'https://login.microsoftonline.com/9f15d2dc-8753-4f83-aac2-a58288d3a4bc/v2.0',
1299
+ email: 'john.doe@montreal.ca',
1300
+ };
1301
+ const identity = createIdentityFromJwt(jwt);
1302
+ // console.log(identity);
1303
+
1304
+ expect(identity.toString()).to.equal(
1305
+ 'user:unknown:xdr_foo:John DOE:john.doe@montreal.ca:::vdm'
1306
+ );
1307
+
1308
+ delete identity.toString;
1309
+ expect(identity).to.eql({
1310
+ type: 'user',
1311
+ id: 'xdr_foo',
1312
+ displayName: 'John DOE',
1313
+ attributes: {
1314
+ type: 'unknown',
1315
+ email: 'john.doe@montreal.ca',
1316
+ username: 'xdr_foo',
1317
+ registrationNumber: undefined,
1318
+ department: undefined,
1319
+ firstName: 'John',
1320
+ lastName: 'DOE',
1321
+ accountProfile: 'vdm',
1322
+ },
1323
+ source: {
1324
+ issuer: 'security-identity-token-api',
1325
+ accessTokenIssuer:
1326
+ 'https://login.microsoftonline.com/9f15d2dc-8753-4f83-aac2-a58288d3a4bc/v2.0',
1327
+ aud: 'e5dd632b-cb97-48d7-a310-5147be717cde',
1328
+ env: 'dev',
1329
+ realm: 'employees',
1330
+ claim: 'userName',
1331
+ internalId: '0b64042a-9cce-42dc-b645-cd721cbbc179',
1332
+ },
1333
+ });
1334
+ });
1335
+ it('no name', () => {
1336
+ const jwt: any = {
1337
+ iss: 'security-identity-token-api',
1338
+ exp: 1721783045,
1339
+ iat: 1721777736,
1340
+ keyId: 6,
1341
+ displayName: 'infra-auth-auth-playground-dev',
1342
+ aud: 'e5dd632b-cb97-48d7-a310-5147be717cde',
1343
+ // name: 'John DOE',
1344
+ sub: 'uuUOZLMFfuURgumF2hE2Z0ZIrVLqLoDy85AeicCJSHQ',
1345
+ userName: 'xdoejo3',
1346
+ givenName: 'John',
1347
+ familyName: 'DOE',
1348
+ userType: 'employee',
1349
+ phoneMobileNumber: '5141111111',
1350
+ oid: '0b64042a-9cce-42dc-b645-cd721cbbc179',
1351
+ realm: 'employees',
1352
+ env: 'dev',
1353
+ accessTokenIssuer:
1354
+ 'https://login.microsoftonline.com/9f15d2dc-8753-4f83-aac2-a58288d3a4bc/v2.0',
1355
+ email: 'john.doe@montreal.ca',
1356
+ };
1357
+ const identity = createIdentityFromJwt(jwt);
1358
+ // console.log(identity);
1359
+
1360
+ expect(identity.toString()).to.equal(
1361
+ 'user:unknown:xdoejo3:john.doe@montreal.ca:john.doe@montreal.ca:::vdm'
1362
+ );
1363
+
1364
+ delete identity.toString;
1365
+ expect(identity).to.eql({
1366
+ type: 'user',
1367
+ id: 'xdoejo3',
1368
+ displayName: 'john.doe@montreal.ca',
1369
+ attributes: {
1370
+ type: 'unknown',
1371
+ email: 'john.doe@montreal.ca',
1372
+ username: 'xdoejo3',
1373
+ registrationNumber: undefined,
1374
+ department: undefined,
1375
+ firstName: 'John',
1376
+ lastName: 'DOE',
1377
+ accountProfile: 'vdm',
1378
+ },
1379
+ source: {
1380
+ issuer: 'security-identity-token-api',
1381
+ accessTokenIssuer:
1382
+ 'https://login.microsoftonline.com/9f15d2dc-8753-4f83-aac2-a58288d3a4bc/v2.0',
1383
+ aud: 'e5dd632b-cb97-48d7-a310-5147be717cde',
1384
+ env: 'dev',
1385
+ realm: 'employees',
1386
+ claim: 'userName',
1387
+ internalId: '0b64042a-9cce-42dc-b645-cd721cbbc179',
1388
+ },
1389
+ });
1390
+ });
1391
+ });
1392
+ describe('Exceptions', () => {
1393
+ it('the jwt parameter is mandatory', () => {
1394
+ expect(() => createIdentityFromJwt(null)).throws('"jwt" parameter is required');
1395
+ });
1396
+ it('the jwt MUST have a sub', () => {
1397
+ const jwt: any = {
1398
+ iss: 'security-identity-token-api',
1399
+ exp: 1721783045,
1400
+ iat: 1721777736,
1401
+ keyId: 6,
1402
+ displayName: 'infra-auth-auth-playground-dev',
1403
+ aud: 'e5dd632b-cb97-48d7-a310-5147be717cde',
1404
+ name: 'John DOE',
1405
+ // sub: 'uuUOZLMFfuURgumF2hE2Z0ZIrVLqLoDy85AeicCJSHQ',
1406
+ userName: 'xdoejo3',
1407
+ givenName: 'John',
1408
+ familyName: 'DOE',
1409
+ userType: 'employee',
1410
+ phoneMobileNumber: '5141111111',
1411
+ oid: '0b64042a-9cce-42dc-b645-cd721cbbc179',
1412
+ realm: 'employees',
1413
+ env: 'dev',
1414
+ accessTokenIssuer:
1415
+ 'https://login.microsoftonline.com/9f15d2dc-8753-4f83-aac2-a58288d3a4bc/v2.0',
1416
+ email: 'john.doe@montreal.ca',
1417
+ };
1418
+ expect(() => createIdentityFromJwt(jwt)).throws(
1419
+ 'expected to find the "sub" claim in the JWT'
1420
+ );
1421
+ });
1422
+ it('optional string claim should be a string and not a number', () => {
1423
+ const jwt: any = {
1424
+ iss: 'security-identity-token-api',
1425
+ exp: 1721783045,
1426
+ iat: 1721777736,
1427
+ keyId: 6,
1428
+ displayName: 'infra-auth-auth-playground-dev',
1429
+ aud: 'e5dd632b-cb97-48d7-a310-5147be717cde',
1430
+ name: 'John DOE',
1431
+ sub: 'uuUOZLMFfuURgumF2hE2Z0ZIrVLqLoDy85AeicCJSHQ',
1432
+ userName: 'xdoejo3',
1433
+ givenName: 'John',
1434
+ familyName: 'DOE',
1435
+ userType: 'employee',
1436
+ phoneMobileNumber: '5141111111',
1437
+ oid: 1234,
1438
+ realm: 'employees',
1439
+ env: 'dev',
1440
+ accessTokenIssuer:
1441
+ 'https://login.microsoftonline.com/9f15d2dc-8753-4f83-aac2-a58288d3a4bc/v2.0',
1442
+ email: 'john.doe@montreal.ca',
1443
+ };
1444
+ expect(() => createIdentityFromJwt(jwt)).throws(
1445
+ `claim 'oid' to contain a string but received: 1234`
1446
+ );
1447
+ });
1448
+ it('external users should belong to the employees realm', () => {
1449
+ const jwt: any = {
1450
+ iss: 'security-identity-token-api',
1451
+ exp: 1721783045,
1452
+ iat: 1721777736,
1453
+ keyId: 6,
1454
+ displayName: 'infra-auth-auth-playground-dev',
1455
+ aud: 'e5dd632b-cb97-48d7-a310-5147be717cde',
1456
+ name: 'John DOE',
1457
+ sub: 'uuUOZLMFfuURgumF2hE2Z0ZIrVLqLoDy85AeicCJSHQ',
1458
+ userName: 'xdoejo3',
1459
+ givenName: 'John',
1460
+ familyName: 'DOE',
1461
+ userType: 'employee',
1462
+ phoneMobileNumber: '5141111111',
1463
+ oid: '0b64042a-9cce-42dc-b645-cd721cbbc179',
1464
+ realm: 'citizens',
1465
+ env: 'dev',
1466
+ accessTokenIssuer:
1467
+ 'https://login.microsoftonline.com/9f15d2dc-8753-4f83-aac2-a58288d3a4bc/v2.0',
1468
+ email: 'john.doe@montreal.ca',
1469
+ };
1470
+ expect(() => createIdentityFromJwt(jwt)).throws(
1471
+ 'expected token to belong to the "employees" realm'
1472
+ );
1473
+ });
1474
+ it('anonymous users should belong to the anonymous realm', () => {
1475
+ const jwt: any = {
1476
+ iss: 'security-identity-token-api',
1477
+ exp: 1722377045,
1478
+ iat: 1722373445,
1479
+ keyId: 6,
1480
+ displayName: 'Account Identity Managment',
1481
+ aud: '@!4025.CA62.9BB6.16C5!0001!2212.0010!0008!2212.0010',
1482
+ name: 'srvAcc Anonymous',
1483
+ sub: '@!4025.CA62.9BB6.16C5!0001!2212.0010!0000!0000.1111.0020',
1484
+ inum: '@!4025.CA62.9BB6.16C5!0001!2212.0010!0000!0000.1111.0020',
1485
+ userName: 'srvAccAnonymous',
1486
+ givenName: 'srvAcc',
1487
+ familyName: 'Anonymous',
1488
+ userType: 'anonymous',
1489
+ realm: 'employees',
1490
+ env: 'dev',
1491
+ accessTokenIssuer: 'security-identity-anonymous-token-api',
1492
+ };
1493
+ expect(() => createIdentityFromJwt(jwt)).throws(
1494
+ 'anonymous: expected token to belong to the "anonymous" realm'
1495
+ );
1496
+ });
1497
+ it('citizen users should belong to the citizens realm', () => {
1498
+ const jwt: any = {
1499
+ iss: 'security-identity-token-api',
1500
+ exp: 1722377562,
1501
+ iat: 1722373962,
1502
+ keyId: 6,
1503
+ displayName: 'infra-auth-auth-playground',
1504
+ aud: 'a496befa-db7d-45a6-ac7a-11471816b8f1',
1505
+ name: 'John Doe',
1506
+ sub: '@!4025.CA62.9BB6.16C5!0001!2212.0010!0000!3F39.BEDB.4ADB.F74D',
1507
+ inum: '@!4025.CA62.9BB6.16C5!0001!2212.0010!0000!3F39.BEDB.4ADB.F74D',
1508
+ userName: 'john.doe@mailinator.com',
1509
+ givenName: 'John',
1510
+ familyName: 'Doe',
1511
+ oid: '7d69384b-dcf4-4972-ebb3-d546551c700f',
1512
+ realm: 'employees',
1513
+ env: 'dev',
1514
+ accessTokenIssuer:
1515
+ 'https://connexion.dev.montreal.ca/1543b575-116b-4325-a0bf-3ccdd7925321/v2.0/',
1516
+ mtlIdentityId: '@!4025.CA62.9BB6.16C5!0001!2212.0010!0000!3F39.BEDB.4ADB.F74D',
1517
+ email: 'john.doe@mailinator.com',
1518
+ };
1519
+ expect(() => createIdentityFromJwt(jwt)).throws(
1520
+ 'user:citizen: expected token to belong to the "citizens" realm'
1521
+ );
1522
+ });
1523
+ it('employee users should belong to the employees realm', () => {
1524
+ const jwt: any = {
1525
+ iss: 'security-identity-token-api',
1526
+ exp: 1721783045,
1527
+ iat: 1721777736,
1528
+ keyId: 6,
1529
+ displayName: 'infra-auth-auth-playground-dev',
1530
+ aud: 'e5dd632b-cb97-48d7-a310-5147be717cde',
1531
+ name: 'John DOE',
1532
+ sub: 'uuUOZLMFfuURgumF2hE2Z0ZIrVLqLoDy85AeicCJSHQ',
1533
+ userName: 'udoejo3',
1534
+ givenName: 'John',
1535
+ familyName: 'DOE',
1536
+ userType: 'employee',
1537
+ employeeNumber: '100674051',
1538
+ department: '421408000000',
1539
+ phoneMobileNumber: '5141111111',
1540
+ oid: '0b64042a-9cce-42dc-b645-cd721cbbc179',
1541
+ realm: 'citizens',
1542
+ env: 'dev',
1543
+ accessTokenIssuer:
1544
+ 'https://login.microsoftonline.com/9f15d2dc-8753-4f83-aac2-a58288d3a4bc/v2.0',
1545
+ email: 'john.doe@montreal.ca',
1546
+ };
1547
+ expect(() => createIdentityFromJwt(jwt)).throws(
1548
+ 'user:employee: expected token to belong to the "employees" realm'
1549
+ );
1550
+ });
1551
+ it('getStringClaim with identityType error', () => {
1552
+ const jwt: any = {
1553
+ iss: 'security-identity-token-api',
1554
+ exp: 1722377045,
1555
+ iat: 1722373445,
1556
+ keyId: 6,
1557
+ displayName: 'Account Identity Managment',
1558
+ aud: '@!4025.CA62.9BB6.16C5!0001!2212.0010!0008!2212.0010',
1559
+ name: 'srvAcc Anonymous',
1560
+ sub: '@!4025.CA62.9BB6.16C5!0001!2212.0010!0000!0000.1111.0020',
1561
+ inum: '@!4025.CA62.9BB6.16C5!0001!2212.0010!0000!0000.1111.0020',
1562
+ // userName: 'srvAccAnonymous',
1563
+ givenName: 'srvAcc',
1564
+ familyName: 'Anonymous',
1565
+ userType: 'anonymous',
1566
+ realm: 'anonymous',
1567
+ env: 'dev',
1568
+ accessTokenIssuer: 'security-identity-anonymous-token-api',
1569
+ };
1570
+ expect(() => createIdentityFromJwt(jwt)).throws(
1571
+ 'anonymous: expected to find the "userName" claim in the JWT'
1572
+ );
1573
+ });
1574
+ it('getStringClaim with identityType and subType error', () => {
1575
+ const jwt: any = {
1576
+ iss: 'security-identity-token-api',
1577
+ exp: 1721782408,
1578
+ iat: 1721778508,
1579
+ keyId: 6,
1580
+ // displayName: 'infra-auth-auth-playground-dev',
1581
+ aud: 'e5dd632b-cb97-48d7-a310-cde5147be717',
1582
+ sub: 'e5dd632b-cb97-48d7-a310-cde5147be717',
1583
+ userType: 'client',
1584
+ oid: '18e8a9b0-876f-4a78-9934-ce3774903c2a',
1585
+ realm: 'employees',
1586
+ env: 'dev',
1587
+ accessTokenIssuer:
1588
+ 'https://login.microsoftonline.com/9f15d2dc-8753-4f83-aac2-a58288d3a4bc/v2.0',
1589
+ };
1590
+ expect(() => createIdentityFromJwt(jwt)).throws(
1591
+ 'service-account: client: expected to find the "displayName" claim in the JWT'
1592
+ );
1593
+ });
1594
+ });
1595
+ });