@verii/server-mockvendor 1.0.0-pre.1752076816

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 (82) hide show
  1. package/.localdev.env +15 -0
  2. package/.standalone.env +5 -0
  3. package/LICENSE +201 -0
  4. package/docker/compose.yml +25 -0
  5. package/jest.config.js +20 -0
  6. package/multilingual-string.schema.json +40 -0
  7. package/package.json +70 -0
  8. package/src/config/config.js +55 -0
  9. package/src/controllers/api/accepted-offers/controller.js +9 -0
  10. package/src/controllers/api/accepted-offers/repo.js +25 -0
  11. package/src/controllers/api/applicants/controller.js +9 -0
  12. package/src/controllers/api/applicants/repo.js +30 -0
  13. package/src/controllers/api/create_did_key/controller.js +29 -0
  14. package/src/controllers/api/create_did_key/schemas/index.js +4 -0
  15. package/src/controllers/api/create_did_key/schemas/jwk-did-request.schema.js +20 -0
  16. package/src/controllers/api/create_did_key/schemas/jwk-did-response.schema.js +41 -0
  17. package/src/controllers/api/create_jwk/controller.js +35 -0
  18. package/src/controllers/api/create_jwk/schemas/index.js +3 -0
  19. package/src/controllers/api/create_jwk/schemas/jwk-response.schema.js +33 -0
  20. package/src/controllers/api/credential-submissions/controller.js +59 -0
  21. package/src/controllers/api/credential-submissions/repo.js +16 -0
  22. package/src/controllers/api/identifications/controller.js +67 -0
  23. package/src/controllers/api/identifications/repo.js +22 -0
  24. package/src/controllers/api/issuing-exchanges/controller.js +218 -0
  25. package/src/controllers/api/issuing-exchanges/fetchers.js +45 -0
  26. package/src/controllers/api/issuing-exchanges/repo.js +27 -0
  27. package/src/controllers/api/jwt/controller.js +69 -0
  28. package/src/controllers/api/jwt/schemas/index.js +6 -0
  29. package/src/controllers/api/jwt/schemas/jwt-request.schema.js +40 -0
  30. package/src/controllers/api/jwt/schemas/jwt-response.schema.js +14 -0
  31. package/src/controllers/api/jwt/schemas/jwt-verify-request.schema.js +17 -0
  32. package/src/controllers/api/jwt/schemas/jwt-verify-response.schema.js +17 -0
  33. package/src/controllers/api/offers/autohooks.js +5 -0
  34. package/src/controllers/api/offers/controller.js +87 -0
  35. package/src/controllers/api/offers/new-mockvendor-offer.schema.js +22 -0
  36. package/src/controllers/api/offers/repo.js +33 -0
  37. package/src/controllers/api/users/controller.js +20 -0
  38. package/src/controllers/api/users/repo.js +29 -0
  39. package/src/controllers/autohooks.js +22 -0
  40. package/src/controllers/inspection/controller.js +39 -0
  41. package/src/controllers/issuing/controller.js +158 -0
  42. package/src/controllers/registrar/controller.js +67 -0
  43. package/src/controllers/registrar/repo.js +24 -0
  44. package/src/controllers/root/controller.js +15 -0
  45. package/src/controllers/schemas/index.js +21 -0
  46. package/src/controllers/schemas/issuer-data.schema.json +26 -0
  47. package/src/entities/index.js +4 -0
  48. package/src/entities/key-pairs/index.js +3 -0
  49. package/src/entities/key-pairs/key-pairs.js +73 -0
  50. package/src/entities/offers/index.js +3 -0
  51. package/src/entities/offers/schemas/generate-offers.schema.js +30 -0
  52. package/src/entities/offers/schemas/index.js +3 -0
  53. package/src/index.js +19 -0
  54. package/src/init-server.js +34 -0
  55. package/src/main.js +18 -0
  56. package/src/standalone.js +8 -0
  57. package/src/start-app-server.js +32 -0
  58. package/test/accepted-offers.test.js +47 -0
  59. package/test/api-users.test.js +170 -0
  60. package/test/create_did_key-controller.test.js +94 -0
  61. package/test/create_jwk-controller.test.js +86 -0
  62. package/test/credential-submissions.test.js +331 -0
  63. package/test/factories/accepted-offers.factory.js +16 -0
  64. package/test/factories/delayed-offer.factory.js +17 -0
  65. package/test/factories/identifications.factory.js +33 -0
  66. package/test/factories/offers.factory.js +64 -0
  67. package/test/factories/users.factory.js +24 -0
  68. package/test/helpers/PastEmploymentPosition-2007-2009-Junior-Project-Manager.json +26 -0
  69. package/test/helpers/PastEmploymentPosition-2009-2015-Project-Manager.json +26 -0
  70. package/test/helpers/helpers/PastEmploymentPosition-2009-2015-Project-Manager.json +26 -0
  71. package/test/helpers/latest-Adam-Smith.json +49 -0
  72. package/test/helpers/legacy-Adam-Smith.json +33 -0
  73. package/test/helpers/mockvendor-build-fastify.js +16 -0
  74. package/test/helpers/tools/verifgen/templates/PastEmploymentPosition-2009-2015-Project-Manager.json +26 -0
  75. package/test/identifications.test.js +56 -0
  76. package/test/issuing-exchanges.test.js +335 -0
  77. package/test/issuing-identify.test.js +137 -0
  78. package/test/jwt-controller.test.js +320 -0
  79. package/test/offers.test.js +682 -0
  80. package/test/registrar.test.js +276 -0
  81. package/test/root.test.js +25 -0
  82. package/test/swagger.test.js +21 -0
@@ -0,0 +1,276 @@
1
+ const { mongoDb } = require('@spencejs/spence-mongo-repos');
2
+ const { signAndEncodeBase64 } = require('@verii/crypto');
3
+ const { ObjectId } = require('mongodb');
4
+ const canonicalize = require('canonicalize');
5
+ const buildFastify = require('./helpers/mockvendor-build-fastify');
6
+
7
+ describe('Registrar messages controller tests', () => {
8
+ const vnfHeaderSignatureSigningKey =
9
+ 'fc48dafb3d36ef0b5bb7663fb7fd571c950e0578016ef4cccba4d5e34c2aa15b';
10
+ let fastify;
11
+ let messagesCollection;
12
+
13
+ beforeAll(async () => {
14
+ fastify = buildFastify();
15
+ await fastify.ready();
16
+ messagesCollection = mongoDb().collection('messages');
17
+ });
18
+
19
+ beforeEach(async () => {
20
+ await messagesCollection.deleteMany({});
21
+ });
22
+
23
+ afterAll(async () => {
24
+ await fastify.close();
25
+ });
26
+ describe('Registrar webhook test suite', () => {
27
+ it('should receive secure messaging from api', async () => {
28
+ jest.spyOn(Date, 'now').mockImplementation(() => 1234567890);
29
+ const payload = {
30
+ messageType: 'create_tenant',
31
+ messageId: '123',
32
+ payload: {
33
+ caoDid: 'did:123',
34
+ caoService: {
35
+ id: 'did:velocity:12',
36
+ type: 'VlcIdDocumentIssuer_v1',
37
+ serviceEndpoint: 'https://devagent.velocitycareerlabs.io',
38
+ },
39
+ create_tenant: {
40
+ did: 'did:321',
41
+ serviceIds: ['1', '2'],
42
+ keys: [
43
+ {
44
+ kidFragment: '#-a-123',
45
+ purposes: ['DLT'],
46
+ key: '123',
47
+ publicKey: '345',
48
+ algorithm: 'SECP256K1',
49
+ encoding: 'hex',
50
+ },
51
+ ],
52
+ },
53
+ },
54
+ };
55
+ const signature = signAndEncodeBase64(
56
+ `${Date.now()}.${canonicalize(payload)}`,
57
+ vnfHeaderSignatureSigningKey
58
+ );
59
+ const response = await fastify.injectJson({
60
+ method: 'POST',
61
+ url: '/registrar/registrar-webhook/',
62
+ payload,
63
+ headers: {
64
+ 'x-vnf-signature': `t=${Date.now()},v1=${signature}`,
65
+ },
66
+ });
67
+ expect(response.json).toEqual({
68
+ messageId: '123',
69
+ messageType: 'ack',
70
+ });
71
+ const messageReceived = await messagesCollection.findOne({
72
+ messageId: '123',
73
+ });
74
+ expect(messageReceived).toEqual({
75
+ _id: expect.any(ObjectId),
76
+ createdAt: expect.any(Date),
77
+ messageId: '123',
78
+ messageType: 'create_tenant',
79
+ payload: {
80
+ caoDid: 'did:123',
81
+ caoService: {
82
+ id: 'did:velocity:12',
83
+ type: 'VlcIdDocumentIssuer_v1',
84
+ serviceEndpoint: 'https://devagent.velocitycareerlabs.io',
85
+ },
86
+ create_tenant: {
87
+ did: 'did:321',
88
+ serviceIds: ['1', '2'],
89
+ keys: [
90
+ {
91
+ kidFragment: '#-a-123',
92
+ purposes: ['DLT'],
93
+ key: '123',
94
+ publicKey: '345',
95
+ algorithm: 'SECP256K1',
96
+ encoding: 'hex',
97
+ },
98
+ ],
99
+ },
100
+ },
101
+ updatedAt: expect.any(Date),
102
+ vnfSignatureVerified: true,
103
+ });
104
+ });
105
+ it('should receive secure messaging from api with bad signature', async () => {
106
+ jest.spyOn(Date, 'now').mockImplementation(() => 1234567890);
107
+ const payload = {
108
+ messageType: 'create_tenant',
109
+ messageId: '123',
110
+ payload: {
111
+ caoDid: 'did:123',
112
+ caoService: {
113
+ id: 'did:velocity:12',
114
+ type: 'VlcIdDocumentIssuer_v1',
115
+ serviceEndpoint: 'https://devagent.velocitycareerlabs.io',
116
+ },
117
+ create_tenant: {
118
+ did: 'did:321',
119
+ serviceIds: ['1', '2'],
120
+ keys: [
121
+ {
122
+ kidFragment: '#-a-123',
123
+ purposes: ['DLT'],
124
+ key: '123',
125
+ publicKey: '345',
126
+ algorithm: 'SECP256K1',
127
+ encoding: 'hex',
128
+ },
129
+ ],
130
+ },
131
+ },
132
+ };
133
+ const signature = signAndEncodeBase64(
134
+ `${Date.now()}.${canonicalize(payload)}`,
135
+ vnfHeaderSignatureSigningKey
136
+ );
137
+ const response = await fastify.injectJson({
138
+ method: 'POST',
139
+ url: '/registrar/registrar-webhook/',
140
+ payload: {
141
+ ...payload,
142
+ messageId: '456',
143
+ },
144
+ headers: {
145
+ 'x-vnf-signature': `t=${Date.now()},v1=${signature}`,
146
+ },
147
+ });
148
+ expect(response.json).toEqual({
149
+ messageId: '456',
150
+ messageType: 'ack',
151
+ });
152
+ const messageReceived = await messagesCollection.findOne({
153
+ messageId: '456',
154
+ });
155
+ expect(messageReceived).toEqual({
156
+ _id: expect.any(ObjectId),
157
+ createdAt: expect.any(Date),
158
+ messageId: '456',
159
+ messageType: 'create_tenant',
160
+ payload: {
161
+ caoDid: 'did:123',
162
+ caoService: {
163
+ id: 'did:velocity:12',
164
+ type: 'VlcIdDocumentIssuer_v1',
165
+ serviceEndpoint: 'https://devagent.velocitycareerlabs.io',
166
+ },
167
+ create_tenant: {
168
+ did: 'did:321',
169
+ serviceIds: ['1', '2'],
170
+ keys: [
171
+ {
172
+ kidFragment: '#-a-123',
173
+ purposes: ['DLT'],
174
+ key: '123',
175
+ publicKey: '345',
176
+ algorithm: 'SECP256K1',
177
+ encoding: 'hex',
178
+ },
179
+ ],
180
+ },
181
+ },
182
+ updatedAt: expect.any(Date),
183
+ vnfSignatureVerified: false,
184
+ });
185
+ });
186
+ it('should return 400 with incorrect payload', async () => {
187
+ const response = await fastify.injectJson({
188
+ method: 'POST',
189
+ url: '/registrar/registrar-webhook/',
190
+ payload: { messageType: 'bla', messageId: '123' },
191
+ });
192
+ expect(response.json).toEqual({
193
+ code: 'FST_ERR_VALIDATION',
194
+ error: 'Bad Request',
195
+ message: 'body/messageType must be equal to one of the allowed values',
196
+ statusCode: 400,
197
+ });
198
+ });
199
+ });
200
+ describe('Registrar webhook delay test suite', () => {
201
+ it('should receive secure messaging from api with 30 second delay', async () => {
202
+ jest.spyOn(Date, 'now').mockImplementation(() => 1234567890);
203
+ const payload = { messageType: 'test', messageId: '123' };
204
+ const signature = signAndEncodeBase64(
205
+ `${Date.now()}.${canonicalize(payload)}`,
206
+ vnfHeaderSignatureSigningKey
207
+ );
208
+ const response = await fastify.injectJson({
209
+ method: 'POST',
210
+ url: '/registrar/registrar-webhook-delay/',
211
+ payload,
212
+ headers: {
213
+ 'x-vnf-signature': `t=${Date.now()},v1=${signature}`,
214
+ },
215
+ });
216
+ expect(response.json).toEqual({ messageId: '123', messageType: 'ack' });
217
+ const messageReceived = await messagesCollection.findOne({
218
+ messageId: '123',
219
+ });
220
+ expect(messageReceived).toEqual({
221
+ _id: expect.any(ObjectId),
222
+ createdAt: expect.any(Date),
223
+ messageId: '123',
224
+ messageType: 'test',
225
+ updatedAt: expect.any(Date),
226
+ vnfSignatureVerified: true,
227
+ });
228
+ }, 40000);
229
+
230
+ it('should return 400 with incorrect payload delay', async () => {
231
+ const response = await fastify.injectJson({
232
+ method: 'POST',
233
+ url: '/registrar/registrar-webhook-delay/',
234
+ payload: { messageType: 'bla', messageId: '123' },
235
+ });
236
+ expect(response.json).toEqual({
237
+ code: 'FST_ERR_VALIDATION',
238
+ error: 'Bad Request',
239
+ message: 'body/messageType must be equal to one of the allowed values',
240
+ statusCode: 400,
241
+ });
242
+ }, 40000);
243
+ });
244
+ describe('Registrar webhook bad protocal test suite', () => {
245
+ it('should return foo with bad endpoint protocol', async () => {
246
+ jest.spyOn(Date, 'now').mockImplementation(() => 1234567890);
247
+ const payload = { messageType: 'create_tenant', messageId: '123' };
248
+ const signature = signAndEncodeBase64(
249
+ `${Date.now()}.${canonicalize(payload)}`,
250
+ vnfHeaderSignatureSigningKey
251
+ );
252
+ const response = await fastify.injectJson({
253
+ method: 'POST',
254
+ url: '/registrar/registrar-webhook-bad-protocol/',
255
+ payload,
256
+ headers: {
257
+ 'x-vnf-signature': `t=${Date.now()},v1=${signature}`,
258
+ },
259
+ });
260
+ expect(response.json).toEqual({ foo: 'foo' });
261
+ });
262
+ it('should return 400 with bad payload protocol', async () => {
263
+ const response = await fastify.injectJson({
264
+ method: 'POST',
265
+ url: '/registrar/registrar-webhook-bad-protocol/',
266
+ payload: { messageType: 'bla', messageId: '123' },
267
+ });
268
+ expect(response.json).toEqual({
269
+ code: 'FST_ERR_VALIDATION',
270
+ error: 'Bad Request',
271
+ message: 'body/messageType must be equal to one of the allowed values',
272
+ statusCode: 400,
273
+ });
274
+ });
275
+ });
276
+ });
@@ -0,0 +1,25 @@
1
+ const buildFastify = require('./helpers/mockvendor-build-fastify');
2
+
3
+ describe('Root routes', () => {
4
+ let fastify;
5
+
6
+ beforeAll(async () => {
7
+ fastify = buildFastify();
8
+ await fastify.ready();
9
+ });
10
+
11
+ afterAll(async () => {
12
+ await fastify.close();
13
+ });
14
+
15
+ it('should respond to /test-integration', async () => {
16
+ const response = await fastify.injectJson({
17
+ method: 'POST',
18
+ url: '/test-integration',
19
+ payload: { message: 'Hi' },
20
+ });
21
+
22
+ expect(response.statusCode).toEqual(200);
23
+ expect(response.json).toEqual({ messageReceived: 'Hi' });
24
+ });
25
+ });
@@ -0,0 +1,21 @@
1
+ const buildFastify = require('./helpers/mockvendor-build-fastify');
2
+
3
+ describe('swagger json', () => {
4
+ let fastify;
5
+ beforeAll(async () => {
6
+ fastify = buildFastify();
7
+ });
8
+
9
+ afterAll(async () => {
10
+ await fastify.close();
11
+ });
12
+
13
+ it('should generate json', async () => {
14
+ const result = await fastify.injectJson({
15
+ method: 'GET',
16
+ url: 'documentation/json',
17
+ });
18
+ expect(result.statusCode).toEqual(200);
19
+ expect(result.json).not.toBe(null);
20
+ });
21
+ });