@velocitycareerlabs/server-webwallet 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.
- package/.localdev.env +57 -0
- package/.standalone.env +22 -0
- package/LICENSE +248 -0
- package/README.md +11 -0
- package/jest.config.js +20 -0
- package/migrate-mongo.config.js +23 -0
- package/package.json +72 -0
- package/src/config/config.js +74 -0
- package/src/controllers/accounts/autohooks.js +28 -0
- package/src/controllers/accounts/controller.js +209 -0
- package/src/controllers/accounts/schemas/index.js +6 -0
- package/src/controllers/accounts/schemas/webwallet-accounts-request.schema.js +25 -0
- package/src/controllers/accounts/schemas/webwallet-accounts-response.schema.js +72 -0
- package/src/controllers/accounts/schemas/webwallet-accounts-update-request.schema.js +23 -0
- package/src/controllers/accounts/schemas/webwallet-test-personas-response.schema.js +110 -0
- package/src/controllers/consent/autohooks.js +14 -0
- package/src/controllers/consent/controller.js +91 -0
- package/src/controllers/consent/schemas/index.js +3 -0
- package/src/controllers/consent/schemas/webwallet-consent-response.schema.js +23 -0
- package/src/controllers/credentials/autohooks.js +36 -0
- package/src/controllers/credentials/controller.js +92 -0
- package/src/controllers/credentials/schemas/index.js +4 -0
- package/src/controllers/credentials/schemas/webwallet-credential-categories-response.schema.js +21 -0
- package/src/controllers/credentials/schemas/webwallet-credentials-response.schema.js +29 -0
- package/src/controllers/disclosures/autohooks.js +21 -0
- package/src/controllers/disclosures/controller.js +168 -0
- package/src/controllers/disclosures/schemas/index.js +7 -0
- package/src/controllers/disclosures/schemas/webwallet-accept-presentation-request-body.schema.js +28 -0
- package/src/controllers/disclosures/schemas/webwallet-accept-presentation-response.schema.js +16 -0
- package/src/controllers/disclosures/schemas/webwallet-get-disclosures-response.schema.js +18 -0
- package/src/controllers/disclosures/schemas/webwallet-get-presentation-request-query.schema.js +21 -0
- package/src/controllers/disclosures/schemas/webwallet-get-presentation-request-response.schema.js +16 -0
- package/src/controllers/feedback/autohooks.js +11 -0
- package/src/controllers/feedback/controller.js +48 -0
- package/src/controllers/issuing/common-schemas/index.js +10 -0
- package/src/controllers/issuing/common-schemas/webwallet-get-credential-manifest-query.schema.js +27 -0
- package/src/controllers/issuing/common-schemas/webwallet-get-credential-manifest-response.schema.js +31 -0
- package/src/controllers/issuing/deep-link/autohooks.js +51 -0
- package/src/controllers/issuing/deep-link/controller.js +192 -0
- package/src/controllers/issuing/deep-link/schemas/index.js +6 -0
- package/src/controllers/issuing/deep-link/schemas/webwallet-deep-link-accept-offers-request.schema.js +30 -0
- package/src/controllers/issuing/deep-link/schemas/webwallet-deep-link-accept-offers-response.schema.js +36 -0
- package/src/controllers/issuing/deep-link/schemas/webwallet-deep-link-offers-request.schema.js +28 -0
- package/src/controllers/issuing/deep-link/schemas/webwallet-deep-link-offers-response.schema.js +48 -0
- package/src/controllers/issuing/identity-credentials/autohooks.js +42 -0
- package/src/controllers/issuing/identity-credentials/controller.js +188 -0
- package/src/controllers/issuing/identity-credentials/schemas/index.js +6 -0
- package/src/controllers/issuing/identity-credentials/schemas/webwallet-identity-credentials-confirm-body.schema.js +20 -0
- package/src/controllers/issuing/identity-credentials/schemas/webwallet-identity-credentials-confirm-response.schema.js +37 -0
- package/src/controllers/issuing/identity-credentials/schemas/webwallet-identity-credentials-request-code-body.schema.js +14 -0
- package/src/controllers/issuing/identity-credentials/schemas/webwallet-identity-credentials-request-code-params.schema.js +19 -0
- package/src/controllers/linkedin/autohooks.js +16 -0
- package/src/controllers/linkedin/controller.js +276 -0
- package/src/controllers/linkedin/schemas/index.js +3 -0
- package/src/controllers/linkedin/schemas/webwallet-linkedin-me-response.schema.js +14 -0
- package/src/controllers/root/controller.js +29 -0
- package/src/entities/.gitkeep +0 -0
- package/src/entities/accounts/constants.js +5 -0
- package/src/entities/accounts/domains/extract-auth0-id-token-or-access-token.js +22 -0
- package/src/entities/accounts/domains/index.js +5 -0
- package/src/entities/accounts/domains/validate-account-permissions.js +36 -0
- package/src/entities/accounts/domains/validate-logo-size.js +25 -0
- package/src/entities/accounts/index.js +5 -0
- package/src/entities/accounts/repos/accounts.repo.js +63 -0
- package/src/entities/credentials/domains/index.js +3 -0
- package/src/entities/credentials/domains/offer-to-credential-mongo-dto.js +43 -0
- package/src/entities/credentials/index.js +6 -0
- package/src/entities/credentials/orchestrators/index.js +3 -0
- package/src/entities/credentials/orchestrators/load-additional-render-info.js +65 -0
- package/src/entities/credentials/repos/credentials.repo.js +132 -0
- package/src/entities/credentials/schemas/index.js +4 -0
- package/src/entities/credentials/schemas/webwallet-credential-response.schema.js +138 -0
- package/src/entities/credentials/schemas/webwallet-credentials-response.schemas.js +95 -0
- package/src/entities/credentials/schemas/webwallet-display-descriptor-response.schema.js +106 -0
- package/src/entities/disclosures/index.js +4 -0
- package/src/entities/disclosures/repos/disclosures.repo.js +31 -0
- package/src/entities/disclosures/schemas/index.js +10 -0
- package/src/entities/disclosures/schemas/webwallet-disclosure.schema.js +39 -0
- package/src/entities/disclosures/schemas/webwallet-presentation-request-field.schema.js +45 -0
- package/src/entities/disclosures/schemas/webwallet-presentation-request-filter.schema.js +30 -0
- package/src/entities/disclosures/schemas/webwallet-presentation-request-format.schema.js +36 -0
- package/src/entities/disclosures/schemas/webwallet-presentation-request-input-descriptors.schema.js +111 -0
- package/src/entities/disclosures/schemas/webwallet-presentation-request-schema.schema.js +14 -0
- package/src/entities/disclosures/schemas/webwallet-presentation-request-submission-requirements.schema.js +37 -0
- package/src/entities/disclosures/schemas/webwallet-presentation-request.schema.js +79 -0
- package/src/entities/index.js +6 -0
- package/src/entities/issuing/domain/constants.js +8 -0
- package/src/entities/issuing/domain/does-user-have-fresh-pending-verification.js +26 -0
- package/src/entities/issuing/domain/get-credentials-from-offers.js +18 -0
- package/src/entities/issuing/domain/index.js +5 -0
- package/src/entities/issuing/index.js +5 -0
- package/src/entities/issuing/orchestrators/build-issuing-input-credentials.js +35 -0
- package/src/entities/issuing/orchestrators/generate-offers-by-deep-link.js +74 -0
- package/src/entities/issuing/orchestrators/get-identity-issuer.js +35 -0
- package/src/entities/issuing/orchestrators/get-identity-offers-by-deeplink.js +74 -0
- package/src/entities/issuing/orchestrators/index.js +6 -0
- package/src/entities/issuing/schemas/index.js +9 -0
- package/src/entities/issuing/schemas/webwallet-credential-manifest.schema.js +198 -0
- package/src/errors/error-codes.js +12 -0
- package/src/fetchers/career-wallet/create-account-fetcher.js +7 -0
- package/src/fetchers/career-wallet/create-did-fetcher.js +17 -0
- package/src/fetchers/career-wallet/get-app-config.js +11 -0
- package/src/fetchers/career-wallet/get-consents.js +13 -0
- package/src/fetchers/career-wallet/get-credential-categories.js +7 -0
- package/src/fetchers/career-wallet/get-personas.js +7 -0
- package/src/fetchers/career-wallet/index.js +12 -0
- package/src/fetchers/career-wallet/post-consent.js +9 -0
- package/src/fetchers/career-wallet/send-feedback.js +14 -0
- package/src/fetchers/career-wallet/sign-fetcher.js +14 -0
- package/src/fetchers/career-wallet/verify-id-credential-confirm-code.js +19 -0
- package/src/fetchers/career-wallet/verify-id-credential-request-code.js +20 -0
- package/src/fetchers/index.js +4 -0
- package/src/fetchers/lib-api/get-credential-display-schema.js +12 -0
- package/src/fetchers/lib-api/index.js +3 -0
- package/src/fetchers/linkedin/create-linkedin-post.js +45 -0
- package/src/fetchers/linkedin/get-access-token.js +26 -0
- package/src/fetchers/linkedin/get-linkedin-user-email.js +13 -0
- package/src/fetchers/linkedin/get-linkedin-user-id.js +16 -0
- package/src/fetchers/linkedin/index.js +9 -0
- package/src/fetchers/linkedin/register-image-to-upload.js +30 -0
- package/src/fetchers/linkedin/revoke-linkedin-access.js +20 -0
- package/src/fetchers/linkedin/upload-image-to-linkedin.js +16 -0
- package/src/index.js +15 -0
- package/src/init-server.js +108 -0
- package/src/plugins/crypto-services/index.js +5 -0
- package/src/plugins/crypto-services/jwt-sign-service-impl.js +72 -0
- package/src/plugins/crypto-services/jwt-verify-service-impl.js +21 -0
- package/src/plugins/crypto-services/key-service-impl.js +28 -0
- package/src/plugins/fetch-errors-handler-plugin.js +64 -0
- package/src/plugins/index.js +4 -0
- package/src/plugins/vnf-sdk-plugin.js +53 -0
- package/src/standalone.js +8 -0
- package/test/accounts-controller.test.js +618 -0
- package/test/consent-controller.test.js +185 -0
- package/test/credentials-controller.test.js +307 -0
- package/test/crypro-services/jwt-sign-service-impl.test.js +83 -0
- package/test/crypro-services/jwt-verify-service-impl.test.js +27 -0
- package/test/crypro-services/key-service-impl.test.js +76 -0
- package/test/crypro-services/mocks/index.js +4 -0
- package/test/crypro-services/mocks/jwt-mock.js +15 -0
- package/test/crypro-services/mocks/public-jwk.js +14 -0
- package/test/disclosures-controller/disclosure-credentials.test.js +428 -0
- package/test/disclosures-controller/get-disclosures.test.js +169 -0
- package/test/disclosures-controller/mocks/get-credential-manifest.js +20 -0
- package/test/disclosures-controller/mocks/index.js +6 -0
- package/test/disclosures-controller/mocks/presentation-request.js +32 -0
- package/test/disclosures-controller/mocks/presentation-submission.js +21 -0
- package/test/disclosures-controller/mocks/submission-result.js +19 -0
- package/test/factories/accounts.js +25 -0
- package/test/factories/credentials.js +66 -0
- package/test/factories/disclosures.js +106 -0
- package/test/feedback-controller.test.js +125 -0
- package/test/fetch-errors-handler-plugin.test.js +97 -0
- package/test/filter-deleted-credentials-extension.test.js +82 -0
- package/test/helpers/.env.test +10 -0
- package/test/helpers/nock-consent-add.js +16 -0
- package/test/helpers/nock-consents-get.js +15 -0
- package/test/helpers/nock-feedback.js +9 -0
- package/test/helpers/nock-linkedin-access-token.js +9 -0
- package/test/helpers/nock-linkedin-email.js +15 -0
- package/test/helpers/nock-linkedin-image-register.js +28 -0
- package/test/helpers/nock-linkedin-me.js +13 -0
- package/test/helpers/nock-linkedin-post.js +37 -0
- package/test/helpers/nock-linkedin-revoke.js +9 -0
- package/test/helpers/nock-test-personas.js +13 -0
- package/test/helpers/webwallet-build-fastify.js +17 -0
- package/test/issuing-controller/issuing-by-deeplink-empty-offers.test.js +142 -0
- package/test/issuing-controller/issuing-by-deeplink-failed-offers.test.js +142 -0
- package/test/issuing-controller/issuing-by-deeplink.test.js +492 -0
- package/test/issuing-controller/issuing-identity-credentials.test.js +377 -0
- package/test/issuing-controller/mocks/accept-offers-response.js +90 -0
- package/test/issuing-controller/mocks/accepted-credentials.js +47 -0
- package/test/issuing-controller/mocks/credential-manifest-presentation.js +72 -0
- package/test/issuing-controller/mocks/credential-manifest.js +45 -0
- package/test/issuing-controller/mocks/identity-issuing/accept-offers.js +22 -0
- package/test/issuing-controller/mocks/identity-issuing/confirm-verification-code.js +5 -0
- package/test/issuing-controller/mocks/identity-issuing/get-app-config.js +52 -0
- package/test/issuing-controller/mocks/identity-issuing/get-organization.js +118 -0
- package/test/issuing-controller/mocks/identity-issuing/index.js +6 -0
- package/test/issuing-controller/mocks/index.js +6 -0
- package/test/issuing-controller/mocks/issuers.js +126 -0
- package/test/issuing-controller/mocks/offers.js +48 -0
- package/test/issuing-controller/mocks/schema.js +107 -0
- package/test/linkedin-controller.test.js +452 -0
- package/test/mocks/credential-categories.js +115 -0
- package/test/mocks/credentials.js +15 -0
- package/test/mocks/didjwk.js +25 -0
- package/test/mocks/index.js +7 -0
- package/test/mocks/issuers.js +88 -0
- package/test/mocks/jwk.js +53 -0
- package/test/mocks/schema.js +107 -0
- package/test/root.test.js +42 -0
- package/test/vcl-sdk-plugin.test.js +86 -0
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
const { mongoDb } = require('@spencejs/spence-mongo-repos');
|
|
2
|
+
const nock = require('nock');
|
|
3
|
+
// const newError = require('http-errors');
|
|
4
|
+
|
|
5
|
+
const buildFastify = require('./helpers/webwallet-build-fastify');
|
|
6
|
+
|
|
7
|
+
const initAccountsFactory = require('./factories/accounts');
|
|
8
|
+
const { nockConsentAdd } = require('./helpers/nock-consent-add');
|
|
9
|
+
const { nockConsentGetLatest } = require('./helpers/nock-consents-get');
|
|
10
|
+
|
|
11
|
+
const auth0Token =
|
|
12
|
+
// eslint-disable-next-line max-len
|
|
13
|
+
'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IktFWSJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWUsImlzcyI6Imh0dHBzOi8vbG9jYWxob3N0LyIsImF1ZCI6ImZvbyIsInNjb3BlIjoicmVhZDp1c2VycyJ9.VwIIUqx9T-AxqbfL_FyNRAeOxTwiC2JpcwtrqnEWN3DdF07ijUkF1WYy8Ahfr_p4R3KnoPbiefZnIbVANCt-lt0ej32rfil2yHhQEsvFxSOjcrx6ARmPp0YAfWlN-5Sotzkxy29jaOZMEDkmRFZg3jkdC7wosPW_S6M-olC4g3HHfylpZI8O3Jdd87Qr9wD_QtUzANwnPbl2Q-9NEyxVjAZIWg_HWK9JAAaf_2IY5VwHBvyp0oeQSEHKi4hogcM59EOc4FxdR5WH45B_PenVa6W4mHFBkH8sAXxt2Zs9s2efujkfWYfyXvgL_lN7vT-TEADlAPP2L6CpWpDISOMsQWUSgGHcN_KwRh_E7qJwahR6mv4QHY6ReEoyjkmSS3swrD1l74jNs7QLAdsMywvzCMDsHabs7DYcEMGQBdP14PJ_ucLFnkivZeBDAc6sS445ocbyrpyO40XMaMorD5khRd9ej89SxR7d_v0W6Ne2Nn4XgW3pAZzu5Rdc4JvqfzLFxkp95jxy1MTAddjWISPmNOYYyXHM9SSqSpqVECOFS0f4z2zycHRqXUcOytWrvED6VGo9x7-IVCgu8vFzj0zToIWQmsDs3UoH9RnV12z0PMwGXQzca1lT_zGwJxBF3e4zJjmcJ05OMF2JgZ2_G48O3M4Dtb0jlgWbKLd0kWlIFzQ;';
|
|
14
|
+
|
|
15
|
+
const auth0userId = '1234567890';
|
|
16
|
+
const usersDid = 'did:example:123';
|
|
17
|
+
|
|
18
|
+
jest.mock('@velocitycareerlabs/vnf-nodejs-wallet-sdk', () => {
|
|
19
|
+
const originalModule = jest.requireActual(
|
|
20
|
+
'@velocitycareerlabs/vnf-nodejs-wallet-sdk'
|
|
21
|
+
);
|
|
22
|
+
return {
|
|
23
|
+
...originalModule,
|
|
24
|
+
VCLProvider: {
|
|
25
|
+
getInstance: jest.fn().mockReturnValue({
|
|
26
|
+
initialize: jest.fn().mockResolvedValue(null),
|
|
27
|
+
}),
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
describe('consent-controller', () => {
|
|
33
|
+
let fastify;
|
|
34
|
+
let persistAccounts;
|
|
35
|
+
|
|
36
|
+
beforeAll(async () => {
|
|
37
|
+
fastify = buildFastify();
|
|
38
|
+
nock('https://localhost/')
|
|
39
|
+
.persist()
|
|
40
|
+
.get('/.well-known/jwks.json')
|
|
41
|
+
.reply(200, jwks);
|
|
42
|
+
await fastify.ready();
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
afterEach(async () => {
|
|
46
|
+
nock.cleanAll();
|
|
47
|
+
await mongoDb().collection('accounts').deleteMany({});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
afterAll(async () => {
|
|
51
|
+
nock.restore();
|
|
52
|
+
await fastify.close();
|
|
53
|
+
});
|
|
54
|
+
describe('consent', () => {
|
|
55
|
+
it('should return 200 and create a consent', async () => {
|
|
56
|
+
({ persistAccounts } = initAccountsFactory(fastify));
|
|
57
|
+
|
|
58
|
+
await persistAccounts({
|
|
59
|
+
auth0userId,
|
|
60
|
+
usersDid,
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
const nockInstance = nock(fastify.config.careerWalletUrl);
|
|
64
|
+
nockConsentAdd(nockInstance);
|
|
65
|
+
|
|
66
|
+
const consent = {
|
|
67
|
+
version: '1.0',
|
|
68
|
+
accountId: 'mocked-user-id',
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const response = await fastify.inject({
|
|
72
|
+
method: 'POST',
|
|
73
|
+
url: '/consent',
|
|
74
|
+
headers: {
|
|
75
|
+
authorization: `Bearer ${auth0Token}`,
|
|
76
|
+
},
|
|
77
|
+
body: consent,
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
expect(response.statusCode).toBe(200);
|
|
81
|
+
expect(response.json()).toEqual({
|
|
82
|
+
consent: {
|
|
83
|
+
version: '1.0',
|
|
84
|
+
accountId: 'mocked-user-id',
|
|
85
|
+
createdAt: expect.any(String),
|
|
86
|
+
id: expect.any(String),
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('should retrive consent latest', async () => {
|
|
92
|
+
({ persistAccounts } = initAccountsFactory(fastify));
|
|
93
|
+
|
|
94
|
+
await persistAccounts({
|
|
95
|
+
auth0userId,
|
|
96
|
+
usersDid,
|
|
97
|
+
careerWalletAccountId: '1111',
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
const nockInstance = nock(fastify.config.careerWalletUrl);
|
|
101
|
+
nockConsentGetLatest(nockInstance);
|
|
102
|
+
|
|
103
|
+
const consents = {
|
|
104
|
+
consent: {
|
|
105
|
+
id: '1',
|
|
106
|
+
version: '1.0',
|
|
107
|
+
accountId: '1111',
|
|
108
|
+
createdAt: expect.any(String),
|
|
109
|
+
},
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
const response = await fastify.inject({
|
|
113
|
+
method: 'GET',
|
|
114
|
+
url: '/consent',
|
|
115
|
+
headers: {
|
|
116
|
+
authorization: `Bearer ${auth0Token}`,
|
|
117
|
+
},
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
expect(response.statusCode).toBe(200);
|
|
121
|
+
expect(response.json()).toEqual(consents);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it('should throw an error no account', async () => {
|
|
125
|
+
const response = await fastify.inject({
|
|
126
|
+
method: 'GET',
|
|
127
|
+
url: '/consent',
|
|
128
|
+
headers: {
|
|
129
|
+
authorization: `Bearer ${auth0Token}`,
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
expect(response.statusCode).toBe(404);
|
|
134
|
+
expect(response.json()).toMatchObject({
|
|
135
|
+
// errorCode: 'web_wallet_server_error',
|
|
136
|
+
message: 'Account not found',
|
|
137
|
+
error: 'Not Found',
|
|
138
|
+
statusCode: 404,
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
const jwks = {
|
|
145
|
+
keys: [
|
|
146
|
+
{
|
|
147
|
+
alg: 'RS512',
|
|
148
|
+
kid: 'KEY',
|
|
149
|
+
x5c: ['UNUSED'],
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
alg: 'RS256',
|
|
153
|
+
kid: 'KEY',
|
|
154
|
+
x5c: [
|
|
155
|
+
`
|
|
156
|
+
MIIEnjCCAoYCCQDmnGII6qzGlTANBgkqhkiG9w0BAQsFADARMQ8wDQYDVQQDDAZ1
|
|
157
|
+
bnVzZWQwHhcNMjEwOTE5MDcxODQ2WhcNMjExMDE5MDcxODQ2WjARMQ8wDQYDVQQD
|
|
158
|
+
DAZ1bnVzZWQwggIiMA0GCSqGSIb3DQEBAQUAA4ICDwAwggIKAoICAQDY2acJ8JAH
|
|
159
|
+
XjK8j3sAXOokSWwvaEg65UJS0C7KdnfbLTeaeYFHBRY0v9Jkk/PJSXv9hMWw1aD3
|
|
160
|
+
n7NrhVwXeRXi/7VZuW/S4ek+hK+IMDvpKqzn+XeCpaMoRpAgloADeNY0qhYKxpr2
|
|
161
|
+
L0SmRQDwVy1r/g31ECewD2WpEiRSmXsQ2Q2uYT3V60BmbhUw31KGEr4SLXL9pzmb
|
|
162
|
+
arOH/5Rhqg+YFMywNY6i01S3UdOlUtAyWT/mVRAkVTsUEou9tBw61zputPdMrl7p
|
|
163
|
+
d4InmlfCmXNTPFh9EDczPQiAVPq8MDyEdRGP134+HM9+YgQUZjy+WsxmGEvplJIf
|
|
164
|
+
KrYtlWe11//oAXC3690LUYtvg49lNY4+H0/nngjnCDXkZo6f+PEvnBZfYl596VTV
|
|
165
|
+
Fx4FGNOqLwg4bAyE5j5jXtEGW1oKo1pxBg7Oe3MteQUDwMrONB3CbxdxDiN3YH94
|
|
166
|
+
2nWGW9Le+CeA1QUhfjQqSoZRJURGYGoztVuIXOElnkrgwcJreX4b8y+Uo5kpp2By
|
|
167
|
+
6UUaD/mMj9XQ+Ygp/J8DlJlqDXOIp6JUJ75aSK5ZIjRtWq/Go5RUjW9IW0ldEehh
|
|
168
|
+
/4j0ZWC0vR1/le2UmAE6tXhkH4sdx9JM84V+qRzjiGqQx3Wn00uwMiHHhte17t41
|
|
169
|
+
vk+b75wuHbfiq9R8irL6wqWeeuzvCC37NwIDAQABMA0GCSqGSIb3DQEBCwUAA4IC
|
|
170
|
+
AQCZOT6S5HLUp0gBtWK6Fxyzb9lWPE+AJipjJ80lS3OnaOIyVtyJexJ2BjTKWldJ
|
|
171
|
+
48zkzLNIRsTEGEipNS6NkrkElfmoaNBpdbDch2WBkME3UYlFIR9GgbXPMlACQlwJ
|
|
172
|
+
f4qT3iIZ9zjpVMP8F63TzRRr7KEYW2PGHEtVQktMPprGEfU4Sz0OIa9RRV+BLsfh
|
|
173
|
+
x8he2pimJEzoEaWPgyJXV1S+tLUif8A/CEkZVRZ2vADA7WMGl2ZTdbmsTjXh4bf2
|
|
174
|
+
A4l4Zec+jwOjUPiEk5lLJwv1KeYos9wuUczAk7ku8wRzyZbrjwgRam9VQA5qmRzJ
|
|
175
|
+
PegEQwJaKMRu8PPK0L4KFN4v3ma7Ux6D719nko8mZ0kA2oUs6phsFmoWQfsbRbsD
|
|
176
|
+
CdUGnM2fPp6V285r9w9Y6+1nVdtJpbAPFJR3SxIpfYVfx3tI6C3BR9bIMr8uCf81
|
|
177
|
+
G+Ebvo4qTuY6Cg/mTpPLZ4cKpwSvB6cE+xeSHvKIRYm6QUYEReRxQ3b4aUKBSNwl
|
|
178
|
+
FEQufVGhGzeblNC3fjP+mMtqbyC8c1zkHc6tjJYO5yesKf8bjO71by2jgSced7nN
|
|
179
|
+
5JvJawfEcabgHJ1aAFLj0tlPMrViFzu6y8/A5aZLc5UMISXAZXfB4wIEdyUUXJh4
|
|
180
|
+
rJKE/ZCb2+W8g29N5cv2P6nhahT3mYatMiQ0U/gfaIrA0A==
|
|
181
|
+
`.trim(),
|
|
182
|
+
],
|
|
183
|
+
},
|
|
184
|
+
],
|
|
185
|
+
};
|
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
const { mongoDb } = require('@spencejs/spence-mongo-repos');
|
|
2
|
+
const { omit } = require('lodash/fp');
|
|
3
|
+
const nock = require('nock');
|
|
4
|
+
const {
|
|
5
|
+
VCLOrganizationsSearchDescriptor,
|
|
6
|
+
VCLFilter,
|
|
7
|
+
VCLProvider,
|
|
8
|
+
} = require('@velocitycareerlabs/vnf-nodejs-wallet-sdk');
|
|
9
|
+
|
|
10
|
+
const { ObjectId } = require('mongodb');
|
|
11
|
+
const { mongoify } = require('@velocitycareerlabs/tests-helpers');
|
|
12
|
+
const {
|
|
13
|
+
errorResponseMatcher,
|
|
14
|
+
} = require('@velocitycareerlabs/tests-helpers/src/error-matchers');
|
|
15
|
+
const buildFastify = require('./helpers/webwallet-build-fastify');
|
|
16
|
+
const { mockSchema, mockedCredentialCategories } = require('./mocks');
|
|
17
|
+
const initCredentialsFactory = require('./factories/credentials');
|
|
18
|
+
const { WebWalletServerError } = require('../src/errors/error-codes');
|
|
19
|
+
|
|
20
|
+
const auth0Token =
|
|
21
|
+
// eslint-disable-next-line max-len
|
|
22
|
+
'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IktFWSJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWUsImlzcyI6Imh0dHBzOi8vbG9jYWxob3N0LyIsImF1ZCI6ImZvbyIsInNjb3BlIjoicmVhZDp1c2VycyJ9.VwIIUqx9T-AxqbfL_FyNRAeOxTwiC2JpcwtrqnEWN3DdF07ijUkF1WYy8Ahfr_p4R3KnoPbiefZnIbVANCt-lt0ej32rfil2yHhQEsvFxSOjcrx6ARmPp0YAfWlN-5Sotzkxy29jaOZMEDkmRFZg3jkdC7wosPW_S6M-olC4g3HHfylpZI8O3Jdd87Qr9wD_QtUzANwnPbl2Q-9NEyxVjAZIWg_HWK9JAAaf_2IY5VwHBvyp0oeQSEHKi4hogcM59EOc4FxdR5WH45B_PenVa6W4mHFBkH8sAXxt2Zs9s2efujkfWYfyXvgL_lN7vT-TEADlAPP2L6CpWpDISOMsQWUSgGHcN_KwRh_E7qJwahR6mv4QHY6ReEoyjkmSS3swrD1l74jNs7QLAdsMywvzCMDsHabs7DYcEMGQBdP14PJ_ucLFnkivZeBDAc6sS445ocbyrpyO40XMaMorD5khRd9ej89SxR7d_v0W6Ne2Nn4XgW3pAZzu5Rdc4JvqfzLFxkp95jxy1MTAddjWISPmNOYYyXHM9SSqSpqVECOFS0f4z2zycHRqXUcOytWrvED6VGo9x7-IVCgu8vFzj0zToIWQmsDs3UoH9RnV12z0PMwGXQzca1lT_zGwJxBF3e4zJjmcJ05OMF2JgZ2_G48O3M4Dtb0jlgWbKLd0kWlIFzQ;';
|
|
23
|
+
|
|
24
|
+
jest.mock('@velocitycareerlabs/vnf-nodejs-wallet-sdk', () => {
|
|
25
|
+
const { mockIssuers } = require('./mocks');
|
|
26
|
+
const originalModule = jest.requireActual(
|
|
27
|
+
'@velocitycareerlabs/vnf-nodejs-wallet-sdk'
|
|
28
|
+
);
|
|
29
|
+
return {
|
|
30
|
+
...originalModule,
|
|
31
|
+
VCLProvider: {
|
|
32
|
+
getInstance: jest.fn().mockReturnValue({
|
|
33
|
+
initialize: jest.fn().mockResolvedValue(null),
|
|
34
|
+
searchForOrganizations: jest.fn().mockResolvedValue(mockIssuers),
|
|
35
|
+
}),
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
const vclSdk = VCLProvider.getInstance();
|
|
41
|
+
|
|
42
|
+
describe('Test credentials controller', () => {
|
|
43
|
+
let fastify;
|
|
44
|
+
let schemaNock;
|
|
45
|
+
let persistCredentials;
|
|
46
|
+
|
|
47
|
+
beforeAll(async () => {
|
|
48
|
+
fastify = buildFastify();
|
|
49
|
+
|
|
50
|
+
nock('https://localhost/').get('/.well-known/jwks.json').reply(200, jwks);
|
|
51
|
+
schemaNock = nockSchemaRequest(fastify);
|
|
52
|
+
|
|
53
|
+
await fastify.ready();
|
|
54
|
+
({ persistCredentials } = initCredentialsFactory(fastify));
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
beforeEach(async () => {
|
|
58
|
+
await mongoDb().collection('credentials').deleteMany({});
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
afterEach(async () => {
|
|
62
|
+
nock.cleanAll();
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
afterAll(async () => {
|
|
66
|
+
nock.restore();
|
|
67
|
+
await fastify.close();
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
describe('GET /credentials - get list of credentials for current user', () => {
|
|
71
|
+
it('should return all credentials for current user Id', async () => {
|
|
72
|
+
const [currentUserCredential] = await Promise.all([
|
|
73
|
+
persistCredentials(),
|
|
74
|
+
persistCredentials({
|
|
75
|
+
auth0UserId: 'testUserId2',
|
|
76
|
+
did: 'did:test:2',
|
|
77
|
+
}),
|
|
78
|
+
]);
|
|
79
|
+
|
|
80
|
+
const response = await fastify.injectJson({
|
|
81
|
+
method: 'GET',
|
|
82
|
+
url: '/credentials',
|
|
83
|
+
headers: {
|
|
84
|
+
authorization: `Bearer ${auth0Token}`,
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
expect(response.statusCode).toBe(200);
|
|
89
|
+
|
|
90
|
+
expect(vclSdk.searchForOrganizations).toBeCalledTimes(1);
|
|
91
|
+
expect(vclSdk.searchForOrganizations).toBeCalledWith(
|
|
92
|
+
new VCLOrganizationsSearchDescriptor(
|
|
93
|
+
new VCLFilter(currentUserCredential.issuer.id)
|
|
94
|
+
)
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
expect(schemaNock.isDone()).toBe(true);
|
|
98
|
+
|
|
99
|
+
expect(response.json).toEqual({
|
|
100
|
+
credentials: [
|
|
101
|
+
{
|
|
102
|
+
...omit(['_id'], currentUserCredential),
|
|
103
|
+
id: expect.any(String),
|
|
104
|
+
createdAt: expect.any(String),
|
|
105
|
+
updatedAt: expect.any(String),
|
|
106
|
+
},
|
|
107
|
+
],
|
|
108
|
+
issuers: { [currentUserCredential.issuer.id]: expect.anything() },
|
|
109
|
+
displayDescriptors: {
|
|
110
|
+
[currentUserCredential.type[0]]: expect.anything(),
|
|
111
|
+
},
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it('should return empty array of credentials if there are no items in DB for user Id', async () => {
|
|
116
|
+
await Promise.all([
|
|
117
|
+
persistCredentials({
|
|
118
|
+
auth0UserId: 'testUserId1',
|
|
119
|
+
did: 'did:test:1',
|
|
120
|
+
}),
|
|
121
|
+
persistCredentials({
|
|
122
|
+
auth0UserId: 'testUserId2',
|
|
123
|
+
did: 'did:test:2',
|
|
124
|
+
}),
|
|
125
|
+
]);
|
|
126
|
+
|
|
127
|
+
const response = await fastify.injectJson({
|
|
128
|
+
method: 'GET',
|
|
129
|
+
url: '/credentials',
|
|
130
|
+
headers: {
|
|
131
|
+
authorization: `Bearer ${auth0Token}`,
|
|
132
|
+
},
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
expect(response.statusCode).toBe(200);
|
|
136
|
+
|
|
137
|
+
expect(response.json).toEqual({
|
|
138
|
+
credentials: [],
|
|
139
|
+
issuers: {},
|
|
140
|
+
displayDescriptors: {},
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it('should return error 401 if there is incorrect token', async () => {
|
|
145
|
+
const response = await fastify.injectJson({
|
|
146
|
+
method: 'GET',
|
|
147
|
+
url: '/credentials',
|
|
148
|
+
headers: {
|
|
149
|
+
authorization: 'Bearer randomIncorrectToken',
|
|
150
|
+
},
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
expect(response.statusCode).toBe(401);
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
describe('GET /credentials/categories - get list of credential categories', () => {
|
|
158
|
+
it('should return all credential categories', async () => {
|
|
159
|
+
const nockedRequest = nock(fastify.config.careerWalletUrl)
|
|
160
|
+
.get('/api/v0.6/credential-categories')
|
|
161
|
+
.reply(200, mockedCredentialCategories);
|
|
162
|
+
|
|
163
|
+
const response = await fastify.injectJson({
|
|
164
|
+
method: 'GET',
|
|
165
|
+
url: '/credentials/categories',
|
|
166
|
+
headers: {
|
|
167
|
+
authorization: `Bearer ${auth0Token}`,
|
|
168
|
+
},
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
expect(response.statusCode).toBe(200);
|
|
172
|
+
|
|
173
|
+
expect(response.json).toEqual(mockedCredentialCategories);
|
|
174
|
+
|
|
175
|
+
expect(nockedRequest.isDone()).toBe(true);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it('should return error 401 when getting credential categories with incorrect token', async () => {
|
|
179
|
+
const response = await fastify.injectJson({
|
|
180
|
+
method: 'GET',
|
|
181
|
+
url: '/credentials/categories',
|
|
182
|
+
headers: {
|
|
183
|
+
authorization: 'Bearer randomIncorrectToken',
|
|
184
|
+
},
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
expect(response.statusCode).toBe(401);
|
|
188
|
+
});
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
describe('DELETE /credential/credentialId - delete User`s credential', () => {
|
|
192
|
+
it('Should delete User`s credential softly (add deletedAt field)', async () => {
|
|
193
|
+
const [credential] = await Promise.all([
|
|
194
|
+
persistCredentials(),
|
|
195
|
+
persistCredentials(),
|
|
196
|
+
]);
|
|
197
|
+
|
|
198
|
+
const response = await fastify.injectJson({
|
|
199
|
+
method: 'DELETE',
|
|
200
|
+
url: `/credentials/${credential._id}`,
|
|
201
|
+
headers: {
|
|
202
|
+
authorization: `Bearer ${auth0Token}`,
|
|
203
|
+
},
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
expect(response.statusCode).toBe(204);
|
|
207
|
+
|
|
208
|
+
expect(
|
|
209
|
+
await mongoDb()
|
|
210
|
+
.collection('credentials')
|
|
211
|
+
.findOne({
|
|
212
|
+
_id: new ObjectId(credential._id),
|
|
213
|
+
})
|
|
214
|
+
).toEqual(
|
|
215
|
+
mongoify({
|
|
216
|
+
...credential,
|
|
217
|
+
updatedAt: expect.any(Date),
|
|
218
|
+
deletedAt: expect.any(Date),
|
|
219
|
+
})
|
|
220
|
+
);
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
it('Sould return 404 if credential belong to anoter user or doesn`t exist', async () => {
|
|
224
|
+
const credential = await persistCredentials({
|
|
225
|
+
auth0UserId: '1234567',
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
const response = await fastify.injectJson({
|
|
229
|
+
method: 'DELETE',
|
|
230
|
+
url: `/credentials/${credential._id}`,
|
|
231
|
+
headers: {
|
|
232
|
+
authorization: `Bearer ${auth0Token}`,
|
|
233
|
+
},
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
expect(response.statusCode).toBe(404);
|
|
237
|
+
|
|
238
|
+
expect(response.json).toEqual(
|
|
239
|
+
errorResponseMatcher({
|
|
240
|
+
error: 'Not Found',
|
|
241
|
+
errorCode: WebWalletServerError,
|
|
242
|
+
message: `Credential ${credential._id} not found`,
|
|
243
|
+
statusCode: 404,
|
|
244
|
+
})
|
|
245
|
+
);
|
|
246
|
+
});
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
it('Should return 401 if no access token is passed', async () => {
|
|
250
|
+
const response = await fastify.injectJson({
|
|
251
|
+
method: 'DELETE',
|
|
252
|
+
url: '/credentials/test_cred_id',
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
expect(response.statusCode).toBe(401);
|
|
256
|
+
});
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
const nockSchemaRequest = (fastify) => {
|
|
260
|
+
return nock(fastify.config.libUrl)
|
|
261
|
+
.get('/display-descriptors/open-badge-v2.0.descriptor.json')
|
|
262
|
+
.once()
|
|
263
|
+
.reply(200, mockSchema);
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
const jwks = {
|
|
267
|
+
keys: [
|
|
268
|
+
{
|
|
269
|
+
alg: 'RS512',
|
|
270
|
+
kid: 'KEY',
|
|
271
|
+
x5c: ['UNUSED'],
|
|
272
|
+
},
|
|
273
|
+
{
|
|
274
|
+
alg: 'RS256',
|
|
275
|
+
kid: 'KEY',
|
|
276
|
+
x5c: [
|
|
277
|
+
`
|
|
278
|
+
MIIEnjCCAoYCCQDmnGII6qzGlTANBgkqhkiG9w0BAQsFADARMQ8wDQYDVQQDDAZ1
|
|
279
|
+
bnVzZWQwHhcNMjEwOTE5MDcxODQ2WhcNMjExMDE5MDcxODQ2WjARMQ8wDQYDVQQD
|
|
280
|
+
DAZ1bnVzZWQwggIiMA0GCSqGSIb3DQEBAQUAA4ICDwAwggIKAoICAQDY2acJ8JAH
|
|
281
|
+
XjK8j3sAXOokSWwvaEg65UJS0C7KdnfbLTeaeYFHBRY0v9Jkk/PJSXv9hMWw1aD3
|
|
282
|
+
n7NrhVwXeRXi/7VZuW/S4ek+hK+IMDvpKqzn+XeCpaMoRpAgloADeNY0qhYKxpr2
|
|
283
|
+
L0SmRQDwVy1r/g31ECewD2WpEiRSmXsQ2Q2uYT3V60BmbhUw31KGEr4SLXL9pzmb
|
|
284
|
+
arOH/5Rhqg+YFMywNY6i01S3UdOlUtAyWT/mVRAkVTsUEou9tBw61zputPdMrl7p
|
|
285
|
+
d4InmlfCmXNTPFh9EDczPQiAVPq8MDyEdRGP134+HM9+YgQUZjy+WsxmGEvplJIf
|
|
286
|
+
KrYtlWe11//oAXC3690LUYtvg49lNY4+H0/nngjnCDXkZo6f+PEvnBZfYl596VTV
|
|
287
|
+
Fx4FGNOqLwg4bAyE5j5jXtEGW1oKo1pxBg7Oe3MteQUDwMrONB3CbxdxDiN3YH94
|
|
288
|
+
2nWGW9Le+CeA1QUhfjQqSoZRJURGYGoztVuIXOElnkrgwcJreX4b8y+Uo5kpp2By
|
|
289
|
+
6UUaD/mMj9XQ+Ygp/J8DlJlqDXOIp6JUJ75aSK5ZIjRtWq/Go5RUjW9IW0ldEehh
|
|
290
|
+
/4j0ZWC0vR1/le2UmAE6tXhkH4sdx9JM84V+qRzjiGqQx3Wn00uwMiHHhte17t41
|
|
291
|
+
vk+b75wuHbfiq9R8irL6wqWeeuzvCC37NwIDAQABMA0GCSqGSIb3DQEBCwUAA4IC
|
|
292
|
+
AQCZOT6S5HLUp0gBtWK6Fxyzb9lWPE+AJipjJ80lS3OnaOIyVtyJexJ2BjTKWldJ
|
|
293
|
+
48zkzLNIRsTEGEipNS6NkrkElfmoaNBpdbDch2WBkME3UYlFIR9GgbXPMlACQlwJ
|
|
294
|
+
f4qT3iIZ9zjpVMP8F63TzRRr7KEYW2PGHEtVQktMPprGEfU4Sz0OIa9RRV+BLsfh
|
|
295
|
+
x8he2pimJEzoEaWPgyJXV1S+tLUif8A/CEkZVRZ2vADA7WMGl2ZTdbmsTjXh4bf2
|
|
296
|
+
A4l4Zec+jwOjUPiEk5lLJwv1KeYos9wuUczAk7ku8wRzyZbrjwgRam9VQA5qmRzJ
|
|
297
|
+
PegEQwJaKMRu8PPK0L4KFN4v3ma7Ux6D719nko8mZ0kA2oUs6phsFmoWQfsbRbsD
|
|
298
|
+
CdUGnM2fPp6V285r9w9Y6+1nVdtJpbAPFJR3SxIpfYVfx3tI6C3BR9bIMr8uCf81
|
|
299
|
+
G+Ebvo4qTuY6Cg/mTpPLZ4cKpwSvB6cE+xeSHvKIRYm6QUYEReRxQ3b4aUKBSNwl
|
|
300
|
+
FEQufVGhGzeblNC3fjP+mMtqbyC8c1zkHc6tjJYO5yesKf8bjO71by2jgSced7nN
|
|
301
|
+
5JvJawfEcabgHJ1aAFLj0tlPMrViFzu6y8/A5aZLc5UMISXAZXfB4wIEdyUUXJh4
|
|
302
|
+
rJKE/ZCb2+W8g29N5cv2P6nhahT3mYatMiQ0U/gfaIrA0A==
|
|
303
|
+
`.trim(),
|
|
304
|
+
],
|
|
305
|
+
},
|
|
306
|
+
],
|
|
307
|
+
};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
const nock = require('nock');
|
|
2
|
+
const {
|
|
3
|
+
VCLJwtDescriptor,
|
|
4
|
+
} = require('@velocitycareerlabs/vnf-nodejs-wallet-sdk');
|
|
5
|
+
const buildFastify = require('../helpers/webwallet-build-fastify');
|
|
6
|
+
const {
|
|
7
|
+
JwtResponseMock,
|
|
8
|
+
JwtMock,
|
|
9
|
+
OriginalPayload,
|
|
10
|
+
} = require('./mocks/jwt-mock');
|
|
11
|
+
const {
|
|
12
|
+
JwtSignServiceImpl,
|
|
13
|
+
} = require('../../src/plugins/crypto-services/jwt-sign-service-impl');
|
|
14
|
+
const { DidJwkMocks } = require('../mocks/didjwk');
|
|
15
|
+
|
|
16
|
+
jest.mock('@velocitycareerlabs/vnf-nodejs-wallet-sdk', () => {
|
|
17
|
+
const originalModule = jest.requireActual(
|
|
18
|
+
'@velocitycareerlabs/vnf-nodejs-wallet-sdk'
|
|
19
|
+
);
|
|
20
|
+
return {
|
|
21
|
+
...originalModule,
|
|
22
|
+
VCLProvider: {
|
|
23
|
+
getInstance: jest.fn().mockReturnValue({
|
|
24
|
+
initialize: jest.fn().mockResolvedValue(null),
|
|
25
|
+
}),
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
describe('sign service implementation test', () => {
|
|
31
|
+
let subject;
|
|
32
|
+
|
|
33
|
+
let fastify;
|
|
34
|
+
|
|
35
|
+
beforeAll(async () => {
|
|
36
|
+
fastify = buildFastify();
|
|
37
|
+
await fastify.ready();
|
|
38
|
+
|
|
39
|
+
subject = JwtSignServiceImpl(fastify);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('should sign payload successfully', async () => {
|
|
43
|
+
const nockedRequest = nock(fastify.config.careerWalletUrl)
|
|
44
|
+
.post('/api/v0.6/jwt/sign')
|
|
45
|
+
.reply(200, JwtResponseMock);
|
|
46
|
+
|
|
47
|
+
const jwt = await subject.sign(
|
|
48
|
+
new VCLJwtDescriptor(OriginalPayload, 'jti123', 'iss123', 'aud123'),
|
|
49
|
+
DidJwkMocks.DidJwk,
|
|
50
|
+
'nonce123',
|
|
51
|
+
null
|
|
52
|
+
);
|
|
53
|
+
expect(nockedRequest.isDone()).toBe(true);
|
|
54
|
+
|
|
55
|
+
expect(jwt).toStrictEqual(JwtMock);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('should fail while signing payload', async () => {
|
|
59
|
+
nock(fastify.config.careerWalletUrl)
|
|
60
|
+
.post('/api/v0.6/jwt/sign')
|
|
61
|
+
.reply(500, {});
|
|
62
|
+
|
|
63
|
+
try {
|
|
64
|
+
await subject.sign(
|
|
65
|
+
new VCLJwtDescriptor(OriginalPayload, 'jti123', 'iss123', 'aud123'),
|
|
66
|
+
DidJwkMocks.DidJwk,
|
|
67
|
+
'nonce123',
|
|
68
|
+
null
|
|
69
|
+
);
|
|
70
|
+
} catch (error) {
|
|
71
|
+
expect(error).not.toBeNull();
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
afterEach(async () => {
|
|
76
|
+
nock.cleanAll();
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
afterAll(async () => {
|
|
80
|
+
nock.restore();
|
|
81
|
+
await fastify.close();
|
|
82
|
+
});
|
|
83
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const {
|
|
2
|
+
JwtVerifyServiceImpl,
|
|
3
|
+
} = require('../../src/plugins/crypto-services/jwt-verify-service-impl');
|
|
4
|
+
const { JwtMock, PublicJwk } = require('./mocks/index');
|
|
5
|
+
const { DidJwkMocks } = require('../mocks/didjwk');
|
|
6
|
+
|
|
7
|
+
describe('sign service implementation test', () => {
|
|
8
|
+
let subject;
|
|
9
|
+
|
|
10
|
+
beforeAll(async () => {
|
|
11
|
+
subject = JwtVerifyServiceImpl();
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it('should verify jwt successfully', async () => {
|
|
15
|
+
const isVerified = await subject.verify(JwtMock, PublicJwk);
|
|
16
|
+
|
|
17
|
+
expect(isVerified).toBeTruthy();
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('should fail with error while verifying jwt', async () => {
|
|
21
|
+
try {
|
|
22
|
+
await subject.verify(JwtMock, DidJwkMocks.DidJwk.publicJwk);
|
|
23
|
+
} catch (e) {
|
|
24
|
+
expect(e).not.toBeNull();
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
});
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
const {
|
|
2
|
+
VCLDidJwkDescriptor,
|
|
3
|
+
VCLSignatureAlgorithm,
|
|
4
|
+
} = require('@velocitycareerlabs/vnf-nodejs-wallet-sdk');
|
|
5
|
+
const nock = require('nock');
|
|
6
|
+
const {
|
|
7
|
+
KeyServiceImpl,
|
|
8
|
+
} = require('../../src/plugins/crypto-services/key-service-impl');
|
|
9
|
+
const { DidJwkMocks } = require('../mocks/didjwk');
|
|
10
|
+
const buildFastify = require('../helpers/webwallet-build-fastify');
|
|
11
|
+
|
|
12
|
+
jest.mock('@velocitycareerlabs/vnf-nodejs-wallet-sdk', () => {
|
|
13
|
+
const originalModule = jest.requireActual(
|
|
14
|
+
'@velocitycareerlabs/vnf-nodejs-wallet-sdk'
|
|
15
|
+
);
|
|
16
|
+
return {
|
|
17
|
+
...originalModule,
|
|
18
|
+
VCLProvider: {
|
|
19
|
+
getInstance: jest.fn().mockReturnValue({
|
|
20
|
+
initialize: jest.fn().mockResolvedValue(null),
|
|
21
|
+
}),
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
describe('key service implementation test', () => {
|
|
27
|
+
let subject;
|
|
28
|
+
|
|
29
|
+
let fastify;
|
|
30
|
+
|
|
31
|
+
beforeAll(async () => {
|
|
32
|
+
fastify = buildFastify();
|
|
33
|
+
await fastify.ready();
|
|
34
|
+
|
|
35
|
+
subject = KeyServiceImpl(fastify);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('should generate a did:jwk successfully', async () => {
|
|
39
|
+
const nockedRequest = nock(fastify.config.careerWalletUrl)
|
|
40
|
+
.post('/api/v0.6/create_did_key')
|
|
41
|
+
.reply(200, DidJwkMocks.DidJwk.payload);
|
|
42
|
+
|
|
43
|
+
const didJwk = await subject.generateDidJwk(
|
|
44
|
+
new VCLDidJwkDescriptor(VCLSignatureAlgorithm.ES256, null)
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
expect(nockedRequest.isDone()).toBe(true);
|
|
48
|
+
|
|
49
|
+
expect(didJwk).toStrictEqual(DidJwkMocks.DidJwk);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('should fail while generating a did:jwk', async () => {
|
|
53
|
+
nock(fastify.config.careerWalletUrl)
|
|
54
|
+
.post('/api/v0.6/create_did_key')
|
|
55
|
+
.reply(500);
|
|
56
|
+
|
|
57
|
+
const didJwkDescriptor = new VCLDidJwkDescriptor(
|
|
58
|
+
VCLSignatureAlgorithm.ES256,
|
|
59
|
+
null
|
|
60
|
+
);
|
|
61
|
+
try {
|
|
62
|
+
await subject.generateDidJwk(didJwkDescriptor);
|
|
63
|
+
} catch (error) {
|
|
64
|
+
expect(error).not.toBeNull();
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
afterEach(async () => {
|
|
69
|
+
nock.cleanAll();
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
afterAll(async () => {
|
|
73
|
+
nock.restore();
|
|
74
|
+
await fastify.close();
|
|
75
|
+
});
|
|
76
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const { VCLJwt } = require('@velocitycareerlabs/vnf-nodejs-wallet-sdk');
|
|
2
|
+
|
|
3
|
+
const OriginalPayload = { p1: 'v1', p2: 'v12' };
|
|
4
|
+
const JwtStrMock =
|
|
5
|
+
// eslint-disable-next-line max-len
|
|
6
|
+
'eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NksiLCJqd2siOnsia3R5IjoiRUMiLCJjcnYiOiJzZWNwMjU2azEiLCJ4IjoiQ1JFNzc0WV8ydkctdTZka2UwSmQzYVhrd1R4WkE2TV96cDZ2TkR0Vmt5NCIsInkiOiJZLWhIdS1FSXlHSGFRRTdmamxZVVlBZ2lVanFqZFc2VXlIaHI2OVFZTS04IiwidXNlIjoic2lnIn19.eyJwMSI6InYxIiwicDIiOiJ2MTIiLCJuYmYiOjE2OTQ0MzUyMjAsImp0aSI6Ijk4YTc4MGFmLTIyZGYtNGU3ZC1iYTZjLTBmYjE0Njk2Zjg0NSIsImlzcyI6ImlzczEyMyIsInN1YiI6IlpHNXQwT1ZrT08iLCJpYXQiOjE2OTQ0MzUyMjB9.kaEGDsRFjFylIAQ1DDX0GQyWBD1y5rG7WNpFZbrL1DFPrfFgDrydXXOCaBbr8TN81kPrbkscsHUuioY-tGCxMw';
|
|
7
|
+
const JwtResponseMock = { compactJwt: JwtStrMock };
|
|
8
|
+
const JwtMock = VCLJwt.fromEncodedJwt(JwtStrMock);
|
|
9
|
+
|
|
10
|
+
module.exports = {
|
|
11
|
+
JwtMock,
|
|
12
|
+
JwtStrMock,
|
|
13
|
+
JwtResponseMock,
|
|
14
|
+
OriginalPayload,
|
|
15
|
+
};
|