@velocitycareerlabs/server-careerwallet 1.25.0-dev-build.12642c864

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 (252) hide show
  1. package/.localdev.env +47 -0
  2. package/.standalone.env +13 -0
  3. package/LICENSE +248 -0
  4. package/jest.config.js +20 -0
  5. package/migrate-mongo.config.js +25 -0
  6. package/migrations/20211017180227-create-personas.js +478 -0
  7. package/migrations/20211026185916-create-vanessa.js +79 -0
  8. package/migrations/20211026185917-update-personas.js +30 -0
  9. package/migrations/20211108124410-remove-surplus-personas.js +33 -0
  10. package/migrations/20211108132353-fix-vanessa-and-sheila.js +25 -0
  11. package/migrations/20220222123110-add-career-wallet-app-config.js +6 -0
  12. package/migrations/20220411104157-add-min-app-versions.js +15 -0
  13. package/migrations/20220419131726-create-nicole-flores-persona.js +63 -0
  14. package/migrations/20220515114034-update-persona-id-credentials.js +628 -0
  15. package/migrations/20220608093743-disable-mainnet-holderapp-id-verification.js +21 -0
  16. package/migrations/20220609063708-enable-mainnet-holderapp-id-verification.js +21 -0
  17. package/migrations/20220623091507-add-push-url.js +43 -0
  18. package/migrations/20220624133205-set-min-app-versions-to-11.js +16 -0
  19. package/migrations/20220710125326-set-min-app-version-to-0.10.7.js +16 -0
  20. package/migrations/20220811103500-add-verification-service-disclosure-deeplink.js +45 -0
  21. package/migrations/20220811123751-add-holderapp-dids-to-config.js +74 -0
  22. package/migrations/20220818072306-add-holderapp-endpoints-to-config.js +21 -0
  23. package/migrations/20220825090656-update-deeplink.js +46 -0
  24. package/migrations/20221003151823-app-config-add-public-verification-api.js +18 -0
  25. package/migrations/20221116085242-add-holderapp-sdk-to-config.js +15 -0
  26. package/migrations/20221121091030-update-holderapp-deeplink.js +19 -0
  27. package/migrations/20221128103425-update-holderapp-presentation-template.js +19 -0
  28. package/migrations/20221221091436-app-config-add-oauth.js +13 -0
  29. package/migrations/20221226205900-app-config-add-presentation-extension-api.js +18 -0
  30. package/migrations/20230120113141-update-holderapp-cashSiquence.js +15 -0
  31. package/migrations/20230123084103-update-holderapp-cacheSequence.js +15 -0
  32. package/migrations/20230214083430-update-holderapp-cache-Sequence.js +15 -0
  33. package/migrations/20230225173335-set-min-app-version-1.5.1.js +30 -0
  34. package/migrations/20230323120629-add-sunil-singh-persona.js +87 -0
  35. package/migrations/20230329081529-add-personas-by-env.js +294 -0
  36. package/migrations/20230329103219-remove-unused-personas.js +14 -0
  37. package/migrations/20230504090208-disable-yoti-migration.js +21 -0
  38. package/migrations/20230504123425-set-min-app-version-1.8.1.js +38 -0
  39. package/migrations/20230504185047-enable-yoti-migration.js +21 -0
  40. package/migrations/20230524053203-add-devices-index.js +16 -0
  41. package/migrations/20230704000002-add-common-holder-endpoints-to-config.js +16 -0
  42. package/migrations/20230704000003-add-linkedin-holder-endpoints-to-config.js +18 -0
  43. package/migrations/20230704104055-update-push-url-and-yoti-url.js +18 -0
  44. package/migrations/20230705000001-add-liburl-to-holderapp-config.js +20 -0
  45. package/migrations/20230814113134-app-config-add-oauth-client-id.js +18 -0
  46. package/migrations/20230821154136-yoti-new-session-url-fix.js +19 -0
  47. package/migrations/20230907134442-update-holderapp-cache-Sequence.js +15 -0
  48. package/migrations/20230919180000-set-holderapp-min-app-versions-1.15.0.js +16 -0
  49. package/migrations/20231011083137-update-holderapp-cache-sequence-6.js +15 -0
  50. package/migrations/20231102083252-set-holderapp-min-app-versions-1.14.0.js +16 -0
  51. package/migrations/20231108202229-set-holderapp-min-app-versions-1.15.0.js +16 -0
  52. package/migrations/20231115143332-holderapp-isDirectIssuerCheckOn-true.js +16 -0
  53. package/migrations/20231120100020-insert-didKeyMetadatum-for-old-accounts.js +59 -0
  54. package/migrations/20231207142742-remove-devices-from-accounts.js +46 -0
  55. package/migrations/20231226090805-app-config-set-direct-issuer-check.js +13 -0
  56. package/migrations/202312271524-set-holderapp-app-version-1.15.1.js +16 -0
  57. package/migrations/20232211171700-app-config-update-base-urls.js +18 -0
  58. package/migrations/20240102093506-holderapp-revert-version-1.15.0.js +16 -0
  59. package/migrations/202401041618111-holderapp-isDebugOn-false.js +17 -0
  60. package/migrations/20240131095122-test-personas-add-did.js +102 -0
  61. package/migrations/202402051547000-update-sdk.js +18 -0
  62. package/migrations/20240206101448-update-personas-vc-to-v2.js +137 -0
  63. package/migrations/202402061233000-set-xVnfProtocolVersion-2.js +13 -0
  64. package/migrations/202402081240000-set-xVnfProtocolVersion-1.js +13 -0
  65. package/migrations/202402131319-set-holderapp-min-versions-1.17.js +16 -0
  66. package/migrations/202402141152-set-holderapp-min-version-1.16.js +16 -0
  67. package/migrations/20240221123501-transform-account-keys-to-stringified-jwk.js +81 -0
  68. package/migrations/202402290955-update-holderapp-to-verifyMyCreds.js +36 -0
  69. package/migrations/20240311134223-update-keyid-persona.js +66 -0
  70. package/migrations/20240312141618-vl-7409-persona-update-maria-williams.js +82 -0
  71. package/migrations/202403181733000-remove-devices-from-all-accounts.js +27 -0
  72. package/migrations/20240401091041-set-holderapp-min-version-1.18.1.js +16 -0
  73. package/migrations/202404071847-app-config-update-yoti-url.js +19 -0
  74. package/migrations/20240724063405-vl-3827-new-yoti-session-url.js +19 -0
  75. package/migrations/20240731112302-vl-8160-add-persona-keys.js +101 -0
  76. package/migrations/20240911115206-vanessa-lin-id-credentials.js +57 -0
  77. package/migrations/202409201219-add-isWalletAvailable-field.js +13 -0
  78. package/migrations/202409221012-set-isWalletAvailable-true.js +13 -0
  79. package/migrations/20240922114643-holderapp-isWalletAvailable-refactor.js +36 -0
  80. package/migrations/20240923132213-update-android-ios-app-config.js +36 -0
  81. package/migrations/20240926061732-inc-cacheSequence-to-7.js +15 -0
  82. package/migrations/20240926073339-inc-cacheSequence-to-7-fix.js +18 -0
  83. package/migrations/202410081217-adam-smith-id-credntials.js +57 -0
  84. package/migrations/202410101243-adam_smith-id-credential.js +57 -0
  85. package/migrations/20241015124307-persona-key-id-type-fix.js +26 -0
  86. package/migrations/202501291027000-set-holderapp-did-web.js +37 -0
  87. package/migrations/environments/dev.env +34 -0
  88. package/migrations/environments/localdev.env +22 -0
  89. package/migrations/environments/prod.env +18 -0
  90. package/migrations/environments/qa.env +54 -0
  91. package/migrations/environments/staging.env +31 -0
  92. package/migrations/environments/test.env +18 -0
  93. package/package.json +84 -0
  94. package/src/assets/category-icons/assessment.png +0 -0
  95. package/src/assets/category-icons/badge.png +0 -0
  96. package/src/assets/category-icons/certification.png +0 -0
  97. package/src/assets/category-icons/education.png +0 -0
  98. package/src/assets/category-icons/employment.png +0 -0
  99. package/src/assets/category-icons/gig.png +0 -0
  100. package/src/assets/category-icons/identity.png +0 -0
  101. package/src/assets/category-icons/pharmacy.png +0 -0
  102. package/src/assets/category-icons/training.png +0 -0
  103. package/src/assets/credentialCategories.json +119 -0
  104. package/src/config/config.js +156 -0
  105. package/src/controllers/api/v0.6/accounts/autohooks.js +36 -0
  106. package/src/controllers/api/v0.6/accounts/controller.js +288 -0
  107. package/src/controllers/api/v0.6/accounts/schemas/careerwallet-accounts-didkeymetadatum-response.schema.js +41 -0
  108. package/src/controllers/api/v0.6/accounts/schemas/careerwallet-accounts-request.schema.js +49 -0
  109. package/src/controllers/api/v0.6/accounts/schemas/careerwallet-accounts-response.schema.js +74 -0
  110. package/src/controllers/api/v0.6/accounts/schemas/careerwallet-get-account-response.schema.js +72 -0
  111. package/src/controllers/api/v0.6/accounts/schemas/index.js +6 -0
  112. package/src/controllers/api/v0.6/careerwallet/appconfig/controller.js +25 -0
  113. package/src/controllers/api/v0.6/careerwallet/appconfig/repo.js +40 -0
  114. package/src/controllers/api/v0.6/careerwallet/autohooks.js +5 -0
  115. package/src/controllers/api/v0.6/careerwallet/consents/controller.js +66 -0
  116. package/src/controllers/api/v0.6/careerwallet/consents/latest/autohooks.js +7 -0
  117. package/src/controllers/api/v0.6/careerwallet/consents/latest/controller.js +76 -0
  118. package/src/controllers/api/v0.6/careerwallet/consents/repo.js +24 -0
  119. package/src/controllers/api/v0.6/careerwallet/consents/schemas/careerwallet-consent-response.schema.js +23 -0
  120. package/src/controllers/api/v0.6/careerwallet/consents/schemas/index.js +3 -0
  121. package/src/controllers/api/v0.6/create_did_key/autohooks.js +10 -0
  122. package/src/controllers/api/v0.6/create_did_key/controller.js +84 -0
  123. package/src/controllers/api/v0.6/create_did_key/schemas/index.js +4 -0
  124. package/src/controllers/api/v0.6/create_did_key/schemas/jwk-did-request.schema.js +20 -0
  125. package/src/controllers/api/v0.6/create_did_key/schemas/jwk-did-response.schema.js +41 -0
  126. package/src/controllers/api/v0.6/create_jwk/autohooks.js +10 -0
  127. package/src/controllers/api/v0.6/create_jwk/controller.js +46 -0
  128. package/src/controllers/api/v0.6/create_jwk/schemas/index.js +3 -0
  129. package/src/controllers/api/v0.6/create_jwk/schemas/jwk-response.schema.js +33 -0
  130. package/src/controllers/api/v0.6/credential-categories/controller.js +35 -0
  131. package/src/controllers/api/v0.6/devices/autohooks.js +11 -0
  132. package/src/controllers/api/v0.6/devices/controller.js +323 -0
  133. package/src/controllers/api/v0.6/devices/repo.js +27 -0
  134. package/src/controllers/api/v0.6/devices/schemas/device.schema.json +43 -0
  135. package/src/controllers/api/v0.6/devices/schemas/index.js +3 -0
  136. package/src/controllers/api/v0.6/feedback/controller.js +24 -0
  137. package/src/controllers/api/v0.6/feedback/schemas/index.js +3 -0
  138. package/src/controllers/api/v0.6/feedback/schemas/new-feedback.schema.js +47 -0
  139. package/src/controllers/api/v0.6/jwt/autohooks.js +10 -0
  140. package/src/controllers/api/v0.6/jwt/controller.js +44 -0
  141. package/src/controllers/api/v0.6/jwt/schemas/index.js +4 -0
  142. package/src/controllers/api/v0.6/jwt/schemas/jwt-request.schema.js +40 -0
  143. package/src/controllers/api/v0.6/jwt/schemas/jwt-response.schema.js +14 -0
  144. package/src/controllers/api/v0.6/oauth/controller.js +131 -0
  145. package/src/controllers/api/v0.6/push/controller.js +296 -0
  146. package/src/controllers/api/v0.6/push/firebase-initializer.js +21 -0
  147. package/src/controllers/api/v0.6/push/notification-types.js +37 -0
  148. package/src/controllers/api/v0.6/push/push-gateway-auth.js +123 -0
  149. package/src/controllers/api/v0.6/push/repo.js +24 -0
  150. package/src/controllers/api/v0.6/verification-offers/repo.js +25 -0
  151. package/src/controllers/api/v0.6/verify/autohooks.js +15 -0
  152. package/src/controllers/api/v0.6/verify/controller.js +348 -0
  153. package/src/controllers/api/v0.6/verify/repo.js +23 -0
  154. package/src/controllers/api/v0.6/verify/verification-credential-types.js +6 -0
  155. package/src/controllers/jwt/autohooks.js +10 -0
  156. package/src/controllers/jwt/controller.js +106 -0
  157. package/src/controllers/jwt/schemas/index.js +31 -0
  158. package/src/controllers/jwt/schemas/jwt-decode.response.200.schema.json +20 -0
  159. package/src/controllers/jwt/schemas/jwt-decode.schema.json +15 -0
  160. package/src/controllers/jwt/schemas/jwt-sign.response.200.schema.json +14 -0
  161. package/src/controllers/jwt/schemas/jwt-sign.schema.json +40 -0
  162. package/src/controllers/jwt/schemas/jwt-verify.response.200.schema.json +17 -0
  163. package/src/controllers/jwt/schemas/jwt-verify.schema.json +19 -0
  164. package/src/controllers/reference/autohooks.js +5 -0
  165. package/src/controllers/reference/countries/controller.js +81 -0
  166. package/src/controllers/reference/personas/controller.js +91 -0
  167. package/src/controllers/reference/personas/repo.js +29 -0
  168. package/src/controllers/reference/personas/schemas/index.js +3 -0
  169. package/src/controllers/reference/personas/schemas/persona.schema.json +108 -0
  170. package/src/controllers/root/controller.js +27 -0
  171. package/src/entities/accounts/constants.js +18 -0
  172. package/src/entities/accounts/domain/index.js +3 -0
  173. package/src/entities/accounts/domain/merge-scopes.js +9 -0
  174. package/src/entities/accounts/index.js +5 -0
  175. package/src/entities/accounts/repos/accounts.repo.js +64 -0
  176. package/src/entities/accounts/repos/id-token-claims-extension.js +31 -0
  177. package/src/entities/accounts/repos/index.js +3 -0
  178. package/src/entities/devices/constants.js +7 -0
  179. package/src/entities/devices/index.js +3 -0
  180. package/src/entities/feedback/domain/generate-feedback-email.js +23 -0
  181. package/src/entities/feedback/domain/index.js +3 -0
  182. package/src/entities/feedback/index.js +3 -0
  183. package/src/entities/index.js +9 -0
  184. package/src/entities/key-pairs/index.js +4 -0
  185. package/src/entities/key-pairs/orchestrators/generate-jwk.js +28 -0
  186. package/src/entities/key-pairs/orchestrators/get-key-pair.js +58 -0
  187. package/src/entities/key-pairs/orchestrators/index.js +4 -0
  188. package/src/entities/key-pairs/repos/index.js +3 -0
  189. package/src/entities/key-pairs/repos/key-pairs.repo.js +23 -0
  190. package/src/entities/oauth/constants.js +13 -0
  191. package/src/entities/oauth/domain/build-access-token.js +14 -0
  192. package/src/entities/oauth/domain/index.js +10 -0
  193. package/src/entities/oauth/domain/validate-audience.js +13 -0
  194. package/src/entities/oauth/domain/validate-client-id.js +13 -0
  195. package/src/entities/oauth/domain/validate-credential.js +16 -0
  196. package/src/entities/oauth/domain/validate-presentation.js +17 -0
  197. package/src/entities/oauth/domain/validate-refresh-token.js +17 -0
  198. package/src/entities/oauth/domain/validate-scope.js +30 -0
  199. package/src/entities/oauth/domain/verify-presentation.js +24 -0
  200. package/src/entities/oauth/index.js +4 -0
  201. package/src/entities/pushes/domains/errors.js +11 -0
  202. package/src/entities/pushes/domains/index.js +3 -0
  203. package/src/entities/pushes/index.js +3 -0
  204. package/src/entities/verification-code-attempts/index.js +3 -0
  205. package/src/entities/verification-code-attempts/orchestrators/index.js +3 -0
  206. package/src/entities/verification-code-attempts/orchestrators/validate-verification-code-attempts.js +79 -0
  207. package/src/entities/verification-code-attempts/repo.js +99 -0
  208. package/src/entities/verifications/constants.js +8 -0
  209. package/src/entities/verifications/index.js +3 -0
  210. package/src/helpers/caching-constants.js +6 -0
  211. package/src/helpers/index.js +3 -0
  212. package/src/index.js +15 -0
  213. package/src/init-server.js +88 -0
  214. package/src/plugins/index.js +4 -0
  215. package/src/plugins/vcl-verification-version-plugin.js +10 -0
  216. package/src/plugins/verify-access-token-plugin.js +116 -0
  217. package/src/standalone.js +8 -0
  218. package/test/accounts-controller.test.js +893 -0
  219. package/test/accounts-repo.test.js +92 -0
  220. package/test/careerwallet-config-controller.test.js +142 -0
  221. package/test/careerwallet-consents-controller.test.js +409 -0
  222. package/test/create_did_key-controller.test.js +397 -0
  223. package/test/create_jwk-controller.test.js +188 -0
  224. package/test/credential-categories-controller.test.js +29 -0
  225. package/test/credential-icons-controller.test.js +36 -0
  226. package/test/devices-controller.test.js +1025 -0
  227. package/test/factories/accounts-factory.js +15 -0
  228. package/test/factories/career-wallet-config-factory.js +60 -0
  229. package/test/factories/consents-career-wallet-factory.js +21 -0
  230. package/test/factories/devices-factory.js +16 -0
  231. package/test/factories/key-pairs-factory.js +18 -0
  232. package/test/factories/notifications-factory.js +16 -0
  233. package/test/factories/persona-factory.js +17 -0
  234. package/test/factories/refresh-tokens-factory.js +14 -0
  235. package/test/factories/verification-code-attempts-factory.js +17 -0
  236. package/test/factories/verification-factory.js +15 -0
  237. package/test/factories/verification-offer-factory.js +20 -0
  238. package/test/feedback-controller.test.js +225 -0
  239. package/test/helpers/.env.test +39 -0
  240. package/test/helpers/access-token.js +59 -0
  241. package/test/helpers/careerwallet-build-fastify.js +20 -0
  242. package/test/helpers/yoti.js +96 -0
  243. package/test/id-verification-controller.test.js +27 -0
  244. package/test/jwt-controller.test.js +1519 -0
  245. package/test/oauth-controller.test.js +639 -0
  246. package/test/push-controller.test.js +733 -0
  247. package/test/push-gateway-auth.test.js +208 -0
  248. package/test/reference-countries-controller.test.js +45 -0
  249. package/test/reference-personas-controller.test.js +179 -0
  250. package/test/root.test.js +21 -0
  251. package/test/swagger.test.js +21 -0
  252. package/test/verification-controller.test.js +1372 -0
@@ -0,0 +1,92 @@
1
+ const { mongoDb } = require('@spencejs/spence-mongo-repos');
2
+ const { ObjectId } = require('mongodb');
3
+ const { hashAndEncodeHex } = require('@velocitycareerlabs/crypto');
4
+ const { accountsRepoPlugin } = require('../src/entities/accounts/repos');
5
+ const buildFastify = require('./helpers/careerwallet-build-fastify');
6
+ const initAccountsFactory = require('./factories/accounts-factory');
7
+
8
+ const testDID = 'test-did';
9
+
10
+ const testDidKeyMetadatum = {
11
+ publicJwk: {
12
+ crv: 'secp256k1',
13
+ kty: 'EC',
14
+ use: 'sig',
15
+ x: 'Lm972sWcSp9dMzkbsXvbUZ7-E24mreaZRIXAR9rIG94',
16
+ y: 'jbSpGUpx0g4ZrNS2heAuwDqmr-F2JIWvK29l-6vJBKA',
17
+ },
18
+ keyId: 'keyId',
19
+ kid: `${testDID}#0`,
20
+ did: testDID,
21
+ };
22
+
23
+ const refreshToken = 'test-refresh-token';
24
+ const newRefreshToken = 'new-refresh-token';
25
+
26
+ describe('test suite for accounts repo', () => {
27
+ let accountsRepo;
28
+ let fastify;
29
+ let persistAccounts;
30
+
31
+ beforeAll(async () => {
32
+ fastify = buildFastify();
33
+ await fastify.ready();
34
+
35
+ accountsRepo = await accountsRepoPlugin(fastify)({
36
+ log: fastify.log,
37
+ config: fastify.config,
38
+ });
39
+
40
+ ({ persistAccounts } = initAccountsFactory(fastify));
41
+ });
42
+
43
+ afterAll(async () => {
44
+ await fastify.close();
45
+ });
46
+
47
+ beforeEach(async () => {
48
+ await mongoDb().collection('accounts').deleteMany({});
49
+
50
+ persistAccounts({
51
+ did: testDID,
52
+ refreshToken,
53
+ didKeyMetadatum: [testDidKeyMetadatum],
54
+ });
55
+ });
56
+
57
+ it('findAccountAndSetRefreshToken method should return account for correct did', async () => {
58
+ expect(
59
+ await accountsRepo.findAccountAndSetRefreshToken(
60
+ { 'didKeyMetadatum.did': testDID },
61
+ newRefreshToken
62
+ )
63
+ ).toEqual({
64
+ _id: expect.any(ObjectId),
65
+ did: testDID,
66
+ accountType: 'temp',
67
+ refreshToken: hashAndEncodeHex(newRefreshToken),
68
+ createdAt: expect.any(Date),
69
+ updatedAt: expect.any(Date),
70
+ scope: expect.any(Array),
71
+ didKeyMetadatum: [testDidKeyMetadatum],
72
+ });
73
+ });
74
+
75
+ it('findAccountAndSetRefreshToken method should return account for correct refreshToken', async () => {
76
+ expect(
77
+ await accountsRepo.findAccountAndSetRefreshToken(
78
+ { refreshToken },
79
+ newRefreshToken
80
+ )
81
+ ).toEqual({
82
+ _id: expect.any(ObjectId),
83
+ did: testDID,
84
+ accountType: 'temp',
85
+ refreshToken: hashAndEncodeHex(newRefreshToken),
86
+ createdAt: expect.any(Date),
87
+ updatedAt: expect.any(Date),
88
+ scope: expect.any(Array),
89
+ didKeyMetadatum: [testDidKeyMetadatum],
90
+ });
91
+ });
92
+ });
@@ -0,0 +1,142 @@
1
+ const { mongoDb } = require('@spencejs/spence-mongo-repos');
2
+
3
+ const initCareerWalletConfigFactory = require('./factories/career-wallet-config-factory');
4
+ const buildFastify = require('./helpers/careerwallet-build-fastify');
5
+
6
+ const baseUrl = '/api/v0.6/careerwallet/appconfig';
7
+
8
+ describe('Career Wallet Config Test Suite', () => {
9
+ let fastify;
10
+ let persistCareerWalletConfig;
11
+
12
+ beforeAll(async () => {
13
+ fastify = buildFastify();
14
+ await fastify.ready();
15
+
16
+ ({ persistCareerWalletConfig } = initCareerWalletConfigFactory(fastify));
17
+ });
18
+
19
+ beforeEach(async () => {
20
+ await mongoDb().collection('careerWalletConfigs').deleteMany({});
21
+ });
22
+
23
+ afterAll(async () => {
24
+ await fastify.close();
25
+ });
26
+
27
+ it('Should 200 when yotiIDV is true', async () => {
28
+ await persistCareerWalletConfig();
29
+
30
+ const response = await fastify.injectJson({
31
+ method: 'GET',
32
+ url: `${baseUrl}`,
33
+ });
34
+
35
+ expect(response.statusCode).toEqual(200);
36
+ expect(response.json).toEqual({
37
+ ios: {
38
+ isWalletAvailable: true,
39
+ },
40
+ android: {
41
+ isWalletAvailable: true,
42
+ },
43
+ yotiIDV: true,
44
+ latestAndroidVersion: '0.10.5',
45
+ latestIOSVersion: '0.10.5',
46
+ minAndroidVersion: '0.10.5',
47
+ minIOSVersion: '0.10.5',
48
+ pushUrl: 'https://example.com/push',
49
+ baseUrls: {
50
+ walletApi: 'https://example.walletapi.com',
51
+ verificationApi: 'https://example.verificationApi.com',
52
+ verificationServiceActionBaseUrl:
53
+ 'https://example.publicVerificationApi.com',
54
+ presentationExtensionPeriodURL: 'https://example.get-extension-period',
55
+ libVnfUrl: 'https://example.lib.com',
56
+ },
57
+ sdk: {
58
+ cacheSequence: 1,
59
+ },
60
+ oauth: {
61
+ oauthAudience: 'testOauthAudience',
62
+ clientId: 'testOauthClientId',
63
+ },
64
+ idVerifierDid: 'idVerifierDid',
65
+ emailVerifierDid: 'emailVerifierDid',
66
+ phoneVerifierDid: 'phoneVerifierDid',
67
+ yotiNewSessionUrl: 'https://yoti.com',
68
+ verificationServiceDeepLink:
69
+ 'https://example.verificationServiceDeepLink',
70
+ verificationServicePresentationLinkTemplate:
71
+ 'https://example.verificationServicePresentationLinkTemplate',
72
+ commonUrls: {
73
+ supportLink: 'https://www.velocitycareerlabs.com/faq',
74
+ termsAndConditionsLink: 'https://app.prove.bio/privacy-policy',
75
+ },
76
+ linkedinEndpoints: {
77
+ authUrl: 'https://www.linkedin.com/oauth/v2',
78
+ apiUrl: 'https://api.linkedin.com/v2',
79
+ addToProfileUrl: 'https://www.linkedin.com/profile/add',
80
+ addToFeed: 'https://www.linkedin.com/feed/update',
81
+ },
82
+ });
83
+ });
84
+
85
+ it('Should 200 when yotiIDV is false', async () => {
86
+ await persistCareerWalletConfig({ yotiIDV: false });
87
+
88
+ const response = await fastify.injectJson({
89
+ method: 'GET',
90
+ url: `${baseUrl}`,
91
+ });
92
+
93
+ expect(response.statusCode).toEqual(200);
94
+ expect(response.json).toEqual({
95
+ ios: {
96
+ isWalletAvailable: true,
97
+ },
98
+ android: {
99
+ isWalletAvailable: true,
100
+ },
101
+ yotiIDV: false,
102
+ latestAndroidVersion: '0.10.5',
103
+ latestIOSVersion: '0.10.5',
104
+ minAndroidVersion: '0.10.5',
105
+ minIOSVersion: '0.10.5',
106
+ pushUrl: 'https://example.com/push',
107
+ baseUrls: {
108
+ walletApi: 'https://example.walletapi.com',
109
+ verificationApi: 'https://example.verificationApi.com',
110
+ verificationServiceActionBaseUrl:
111
+ 'https://example.publicVerificationApi.com',
112
+ presentationExtensionPeriodURL: 'https://example.get-extension-period',
113
+ libVnfUrl: 'https://example.lib.com',
114
+ },
115
+ sdk: {
116
+ cacheSequence: 1,
117
+ },
118
+ oauth: {
119
+ oauthAudience: 'testOauthAudience',
120
+ clientId: 'testOauthClientId',
121
+ },
122
+ idVerifierDid: 'idVerifierDid',
123
+ emailVerifierDid: 'emailVerifierDid',
124
+ phoneVerifierDid: 'phoneVerifierDid',
125
+ yotiNewSessionUrl: 'https://yoti.com',
126
+ verificationServiceDeepLink:
127
+ 'https://example.verificationServiceDeepLink',
128
+ verificationServicePresentationLinkTemplate:
129
+ 'https://example.verificationServicePresentationLinkTemplate',
130
+ commonUrls: {
131
+ supportLink: 'https://www.velocitycareerlabs.com/faq',
132
+ termsAndConditionsLink: 'https://app.prove.bio/privacy-policy',
133
+ },
134
+ linkedinEndpoints: {
135
+ authUrl: 'https://www.linkedin.com/oauth/v2',
136
+ apiUrl: 'https://api.linkedin.com/v2',
137
+ addToProfileUrl: 'https://www.linkedin.com/profile/add',
138
+ addToFeed: 'https://www.linkedin.com/feed/update',
139
+ },
140
+ });
141
+ });
142
+ });
@@ -0,0 +1,409 @@
1
+ const { mongoDb } = require('@spencejs/spence-mongo-repos');
2
+ const { hexFromJwk } = require('@velocitycareerlabs/jwt');
3
+ const { errorResponseMatcher } = require('@velocitycareerlabs/tests-helpers');
4
+ const { generateKeyPair } = require('@velocitycareerlabs/crypto');
5
+ const initConsentCareerWalletFactory = require('./factories/consents-career-wallet-factory');
6
+ const buildFastify = require('./helpers/careerwallet-build-fastify');
7
+ const consentsRepoPlugin = require('../src/controllers/api/v0.6/careerwallet/consents/repo');
8
+ const { createAccessToken } = require('./helpers/access-token');
9
+ const { accountScopes, adminScopes } = require('../src/entities');
10
+
11
+ describe('Consents career wallet controller tests', () => {
12
+ let fastify;
13
+ const baseUrl = 'api/v0.6/careerwallet';
14
+ let persistConsentsCareerWallet;
15
+ let consentsRepo;
16
+ let publicKey;
17
+ let privateKey;
18
+ let clientAccessToken;
19
+ let serverClientAccessToken;
20
+
21
+ beforeAll(async () => {
22
+ ({ publicKey, privateKey } = generateKeyPair({ format: 'jwk' }));
23
+
24
+ fastify = buildFastify({
25
+ holderAppServerAccessTokenPublicKey: publicKey,
26
+ holderAppServerAccessTokenSigningKey: hexFromJwk(privateKey),
27
+ });
28
+ await fastify.ready();
29
+
30
+ ({ persistConsentsCareerWallet } = initConsentCareerWalletFactory(fastify));
31
+
32
+ clientAccessToken = await createAccessToken(
33
+ accountScopes.account,
34
+ privateKey,
35
+ 'mocked-user-id'
36
+ );
37
+
38
+ serverClientAccessToken = await createAccessToken(
39
+ adminScopes.adminClient,
40
+ privateKey,
41
+ 'https://webwallet.velocitycareerlabs.com/'
42
+ );
43
+
44
+ consentsRepo = await consentsRepoPlugin(fastify)({
45
+ log: fastify.log,
46
+ config: fastify.config,
47
+ });
48
+ });
49
+
50
+ beforeEach(async () => {
51
+ await mongoDb().collection('organizations').deleteMany({});
52
+ await mongoDb().collection('groups').deleteMany({});
53
+ await mongoDb().collection('consentsCareerWallet').deleteMany({});
54
+ });
55
+
56
+ afterAll(async () => {
57
+ await fastify.close();
58
+ });
59
+
60
+ describe('Add consents tests', () => {
61
+ it('should 400 if version does not exist in body', async () => {
62
+ const response = await fastify.injectJson({
63
+ method: 'POST',
64
+ url: `${baseUrl}/consents/add`,
65
+ payload: {},
66
+ });
67
+ expect(response.statusCode).toBe(400);
68
+ expect(response.json).toStrictEqual(
69
+ errorResponseMatcher({
70
+ error: 'Bad Request',
71
+ errorCode: 'request_validation_failed',
72
+ message: "body must have required property 'version'",
73
+ statusCode: 400,
74
+ })
75
+ );
76
+ });
77
+
78
+ it('should 400 if version is empty string', async () => {
79
+ const response = await fastify.injectJson({
80
+ method: 'POST',
81
+ url: `${baseUrl}/consents/add`,
82
+ payload: {
83
+ version: '',
84
+ accountId: 'mocked-user-id',
85
+ },
86
+ });
87
+ expect(response.statusCode).toBe(400);
88
+ expect(response.json).toStrictEqual(
89
+ errorResponseMatcher({
90
+ error: 'Bad Request',
91
+ errorCode: 'request_validation_failed',
92
+ message: 'body/version must match pattern "[0-9]+.[0-9]+"',
93
+ statusCode: 400,
94
+ })
95
+ );
96
+ });
97
+
98
+ it('should 400 if version does not match pattern', async () => {
99
+ const response = await fastify.injectJson({
100
+ method: 'POST',
101
+ url: `${baseUrl}/consents/add`,
102
+ payload: {
103
+ version: 'abc',
104
+ accountId: 'mocked-user-id',
105
+ },
106
+ });
107
+ expect(response.statusCode).toBe(400);
108
+ expect(response.json).toStrictEqual(
109
+ errorResponseMatcher({
110
+ error: 'Bad Request',
111
+ errorCode: 'request_validation_failed',
112
+ message: 'body/version must match pattern "[0-9]+.[0-9]+"',
113
+ statusCode: 400,
114
+ })
115
+ );
116
+ });
117
+
118
+ it('should 400 if accountId does not exist in body', async () => {
119
+ const response = await fastify.injectJson({
120
+ method: 'POST',
121
+ url: `${baseUrl}/consents/add`,
122
+ payload: {
123
+ version: '1.0',
124
+ },
125
+ });
126
+ expect(response.statusCode).toBe(400);
127
+ expect(response.json).toStrictEqual(
128
+ errorResponseMatcher({
129
+ error: 'Bad Request',
130
+ errorCode: 'request_validation_failed',
131
+ message: "body must have required property 'accountId'",
132
+ statusCode: 400,
133
+ })
134
+ );
135
+ });
136
+
137
+ it('should create consent for authorized user', async () => {
138
+ const response = await fastify.injectJson({
139
+ method: 'POST',
140
+ url: `${baseUrl}/consents/add`,
141
+ payload: {
142
+ version: '1.0',
143
+ accountId: 'mocked-user-id',
144
+ },
145
+ });
146
+
147
+ const consent = await consentsRepo.findOne({
148
+ filter: {
149
+ accountId: 'mocked-user-id',
150
+ },
151
+ });
152
+
153
+ expect(response.statusCode).toStrictEqual(201);
154
+ expect(response.json.consent).toStrictEqual({
155
+ createdAt: expect.any(String),
156
+ id: expect.any(String),
157
+ accountId: 'mocked-user-id',
158
+ version: '1.0',
159
+ });
160
+ expect({
161
+ createdAt: consent.createdAt.toISOString(),
162
+ id: consent._id.toString(),
163
+ accountId: consent.accountId,
164
+ version: consent.version,
165
+ }).toStrictEqual(response.json.consent);
166
+ });
167
+
168
+ it('should create new one consent version if user already has consent', async () => {
169
+ const consent = await persistConsentsCareerWallet();
170
+
171
+ const response = await fastify.injectJson({
172
+ method: 'POST',
173
+ url: `${baseUrl}/consents/add`,
174
+ payload: {
175
+ version: '2.2',
176
+ accountId: 'mocked-user-id',
177
+ },
178
+ });
179
+
180
+ const consents = await consentsRepo.find({
181
+ filter: {
182
+ accountId: 'mocked-user-id',
183
+ },
184
+ });
185
+
186
+ expect(consents.length).toBe(2);
187
+ expect(response.statusCode).toStrictEqual(201);
188
+ expect([
189
+ {
190
+ createdAt: consents[0].createdAt.toISOString(),
191
+ id: consents[0]._id.toString(),
192
+ accountId: consents[0].accountId,
193
+ version: consents[0].version,
194
+ },
195
+ {
196
+ createdAt: consents[1].createdAt.toISOString(),
197
+ id: consents[1]._id.toString(),
198
+ accountId: consents[1].accountId,
199
+ version: consents[1].version,
200
+ },
201
+ ]).toStrictEqual([
202
+ response.json.consent,
203
+ {
204
+ createdAt: consent.createdAt,
205
+ id: consent._id.toString(),
206
+ accountId: consent.accountId,
207
+ version: consent.version,
208
+ },
209
+ ]);
210
+ });
211
+
212
+ it('should not create new one consent if version already exist', async () => {
213
+ const consent = await persistConsentsCareerWallet({
214
+ version: '2.2',
215
+ });
216
+
217
+ const response = await fastify.injectJson({
218
+ method: 'POST',
219
+ url: `${baseUrl}/consents/add`,
220
+ payload: {
221
+ version: '2.2',
222
+ accountId: 'mocked-user-id',
223
+ },
224
+ });
225
+
226
+ const consents = await consentsRepo.find({
227
+ filter: {
228
+ accountId: 'mocked-user-id',
229
+ },
230
+ });
231
+
232
+ expect(consents.length).toBe(1);
233
+ expect(response.statusCode).toEqual(201);
234
+ expect([
235
+ {
236
+ createdAt: consents[0].createdAt.toISOString(),
237
+ id: consents[0]._id.toString(),
238
+ accountId: consents[0].accountId,
239
+ version: consents[0].version,
240
+ },
241
+ ]).toEqual([response.json.consent]);
242
+ expect([
243
+ {
244
+ createdAt: consents[0].createdAt.toISOString(),
245
+ id: consents[0]._id.toString(),
246
+ accountId: consents[0].accountId,
247
+ version: consents[0].version,
248
+ },
249
+ ]).toStrictEqual([
250
+ {
251
+ createdAt: consent.createdAt,
252
+ id: consent._id.toString(),
253
+ accountId: consent.accountId,
254
+ version: consent.version,
255
+ },
256
+ ]);
257
+ });
258
+ });
259
+
260
+ describe('Get consents tests', () => {
261
+ it('should get latest consent', async () => {
262
+ await persistConsentsCareerWallet();
263
+ const consent = await persistConsentsCareerWallet({
264
+ version: '1.1',
265
+ });
266
+ const response = await fastify.injectJson({
267
+ method: 'GET',
268
+ url: `${baseUrl}/consents/latest`,
269
+ headers: {
270
+ authorization: `Bearer ${clientAccessToken}`,
271
+ },
272
+ });
273
+
274
+ expect(response.statusCode).toEqual(200);
275
+ expect(response.json).toEqual({
276
+ consent: {
277
+ createdAt: expect.any(String),
278
+ id: consent._id.toString(),
279
+ accountId: 'mocked-user-id',
280
+ version: '1.1',
281
+ },
282
+ });
283
+ });
284
+
285
+ it('should get 400 if consents not found', async () => {
286
+ const response = await fastify.injectJson({
287
+ method: 'GET',
288
+ url: `${baseUrl}/consents/latest`,
289
+ headers: {
290
+ authorization: `Bearer ${clientAccessToken}`,
291
+ },
292
+ });
293
+
294
+ expect(response.statusCode).toEqual(400);
295
+ expect(response.json).toEqual(
296
+ errorResponseMatcher({
297
+ error: 'Bad Request',
298
+ message: 'Consents not found',
299
+ errorCode: 'missing_error_code',
300
+ statusCode: 400,
301
+ })
302
+ );
303
+ });
304
+
305
+ it('should get 400 if token invalid', async () => {
306
+ const response = await fastify.injectJson({
307
+ method: 'GET',
308
+ url: `${baseUrl}/consents/latest`,
309
+ headers: {
310
+ authorization: `Bearer qwe${clientAccessToken}`,
311
+ },
312
+ });
313
+
314
+ expect(response.statusCode).toEqual(401);
315
+ expect(response.json).toEqual(
316
+ errorResponseMatcher({
317
+ error: 'Unauthorized',
318
+ message: 'invalid authorization header',
319
+ errorCode: 'missing_error_code',
320
+ statusCode: 401,
321
+ })
322
+ );
323
+ });
324
+
325
+ it('Should 401 if jwt token not set', async () => {
326
+ const response = await fastify.injectJson({
327
+ method: 'GET',
328
+ url: `${baseUrl}/consents/latest`,
329
+ headers: {
330
+ authorization: '',
331
+ },
332
+ });
333
+
334
+ expect(response.statusCode).toEqual(401);
335
+ expect(response.json).toEqual(
336
+ errorResponseMatcher({
337
+ error: 'Unauthorized',
338
+ message: 'missing authorization header',
339
+ errorCode: 'missing_error_code',
340
+ statusCode: 401,
341
+ })
342
+ );
343
+ });
344
+ });
345
+
346
+ it('should return latest consent if requested by the server client with valid M2M token', async () => {
347
+ await persistConsentsCareerWallet();
348
+ const consent = await persistConsentsCareerWallet({
349
+ version: '1.1',
350
+ });
351
+ const response = await fastify.injectJson({
352
+ method: 'GET',
353
+ url: `${baseUrl}/consents/latest?accountId=mocked-user-id`,
354
+ headers: {
355
+ authorization: `Bearer ${serverClientAccessToken}`,
356
+ },
357
+ });
358
+
359
+ expect(response.statusCode).toEqual(200);
360
+ expect(response.json).toEqual({
361
+ consent: {
362
+ createdAt: expect.any(String),
363
+ id: consent._id.toString(),
364
+ accountId: 'mocked-user-id',
365
+ version: '1.1',
366
+ },
367
+ });
368
+ });
369
+
370
+ it('should return 400 if requested by the server client with valid M2M token but accountId is not set', async () => {
371
+ const response = await fastify.injectJson({
372
+ method: 'GET',
373
+ url: `${baseUrl}/consents/latest`,
374
+ headers: {
375
+ authorization: `Bearer ${serverClientAccessToken}`,
376
+ },
377
+ });
378
+
379
+ expect(response.statusCode).toEqual(400);
380
+ expect(response.json).toEqual(
381
+ errorResponseMatcher({
382
+ error: 'Bad Request',
383
+ message: 'AccountId query param is missed',
384
+ errorCode: 'missing_error_code',
385
+ statusCode: 400,
386
+ })
387
+ );
388
+ });
389
+
390
+ it('should return 400 if requested by the regular client but accountId and sub are different', async () => {
391
+ const response = await fastify.injectJson({
392
+ method: 'GET',
393
+ url: `${baseUrl}/consents/latest?accountId=mocked-user-id-mismatched`,
394
+ headers: {
395
+ authorization: `Bearer ${clientAccessToken}`,
396
+ },
397
+ });
398
+
399
+ expect(response.statusCode).toEqual(400);
400
+ expect(response.json).toEqual(
401
+ errorResponseMatcher({
402
+ error: 'Bad Request',
403
+ message: 'Param accountId and sub mismatch',
404
+ errorCode: 'missing_error_code',
405
+ statusCode: 400,
406
+ })
407
+ );
408
+ });
409
+ });