@mojaloop/sdk-scheme-adapter 18.0.0 → 18.0.2
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/.dockerignore +18 -0
- package/.eslintignore +2 -0
- package/.ncurc.yaml +7 -0
- package/CHANGELOG.md +20 -0
- package/CODEOWNERS +31 -1
- package/README.md +1 -0
- package/audit-resolve.json +35 -0
- package/package.json +13 -13
- package/test/__mocks__/@mojaloop/sdk-standard-components.js +0 -151
- package/test/__mocks__/javascript-state-machine.js +0 -21
- package/test/__mocks__/redis.js +0 -78
- package/test/__mocks__/uuidv4.js +0 -16
- package/test/config/integration.env +0 -146
- package/test/integration/lib/Outbound/data/quotesPostRequest.json +0 -52
- package/test/integration/lib/Outbound/data/transfersPostRequest.json +0 -24
- package/test/integration/lib/Outbound/parties.test.js +0 -31
- package/test/integration/lib/Outbound/quotes.test.js +0 -62
- package/test/integration/lib/Outbound/simpleTransfers.test.js +0 -70
- package/test/integration/lib/cache.test.js +0 -79
- package/test/integration/testEnv.js +0 -4
- package/test/unit/ControlClient.test.js +0 -69
- package/test/unit/ControlServer/events.js +0 -41
- package/test/unit/ControlServer/index.js +0 -227
- package/test/unit/ControlServer.test.js +0 -66
- package/test/unit/InboundServer.test.js +0 -443
- package/test/unit/TestServer.test.js +0 -392
- package/test/unit/api/accounts/accounts.test.js +0 -128
- package/test/unit/api/accounts/data/postAccountsBody.json +0 -7
- package/test/unit/api/accounts/data/postAccountsErrorMojaloopResponse.json +0 -33
- package/test/unit/api/accounts/data/postAccountsErrorTimeoutResponse.json +0 -19
- package/test/unit/api/accounts/data/postAccountsSuccessResponse.json +0 -31
- package/test/unit/api/accounts/data/postAccountsSuccessResponseWithError1.json +0 -34
- package/test/unit/api/accounts/data/postAccountsSuccessResponseWithError2.json +0 -39
- package/test/unit/api/accounts/utils.js +0 -79
- package/test/unit/api/proxy/data/proxyConfig.yaml +0 -82
- package/test/unit/api/proxy/data/requestBody.json +0 -22
- package/test/unit/api/proxy/data/requestHeaders.json +0 -5
- package/test/unit/api/proxy/data/requestQuery.json +0 -6
- package/test/unit/api/proxy/data/responseBody.json +0 -21
- package/test/unit/api/proxy/data/responseHeaders.json +0 -5
- package/test/unit/api/proxy/proxy.test.js +0 -220
- package/test/unit/api/proxy/utils.js +0 -79
- package/test/unit/api/transfers/data/getTransfersCommittedResponse.json +0 -24
- package/test/unit/api/transfers/data/getTransfersErrorNotFound.json +0 -18
- package/test/unit/api/transfers/data/postQuotesBody.json +0 -52
- package/test/unit/api/transfers/data/postTransfersBadBody.json +0 -17
- package/test/unit/api/transfers/data/postTransfersBody.json +0 -24
- package/test/unit/api/transfers/data/postTransfersErrorMojaloopResponse.json +0 -62
- package/test/unit/api/transfers/data/postTransfersErrorTimeoutResponse.json +0 -48
- package/test/unit/api/transfers/data/postTransfersSimpleBody.json +0 -26
- package/test/unit/api/transfers/data/postTransfersSuccessResponse.json +0 -128
- package/test/unit/api/transfers/data/putPartiesBody.json +0 -20
- package/test/unit/api/transfers/data/putQuotesBody.json +0 -37
- package/test/unit/api/transfers/data/putTransfersBody.json +0 -17
- package/test/unit/api/transfers/transfers.test.js +0 -191
- package/test/unit/api/transfers/utils.js +0 -264
- package/test/unit/api/utils.js +0 -86
- package/test/unit/config.test.js +0 -119
- package/test/unit/data/commonHttpHeaders.json +0 -7
- package/test/unit/data/defaultConfig.json +0 -70
- package/test/unit/data/postQuotesBody.json +0 -52
- package/test/unit/data/putParticipantsBody.json +0 -12
- package/test/unit/data/putPartiesBody.json +0 -20
- package/test/unit/data/testFile.json +0 -29
- package/test/unit/data/testFile.yaml +0 -14
- package/test/unit/inboundApi/data/mockArguments.json +0 -117
- package/test/unit/inboundApi/data/mockTransactionRequest.json +0 -42
- package/test/unit/inboundApi/handlers.test.js +0 -786
- package/test/unit/index.test.js +0 -88
- package/test/unit/lib/cache.test.js +0 -145
- package/test/unit/lib/model/AccountsModel.test.js +0 -124
- package/test/unit/lib/model/InboundTransfersModel.test.js +0 -889
- package/test/unit/lib/model/OutboundBulkQuotesModel.test.js +0 -253
- package/test/unit/lib/model/OutboundBulkTransfersModel.test.js +0 -247
- package/test/unit/lib/model/OutboundRequestToPayModel.test.js +0 -166
- package/test/unit/lib/model/OutboundRequestToPayTransferModel.test.js +0 -245
- package/test/unit/lib/model/OutboundTransfersModel.test.js +0 -1579
- package/test/unit/lib/model/PartiesModel.test.js +0 -478
- package/test/unit/lib/model/QuotesModel.test.js +0 -477
- package/test/unit/lib/model/TransfersModel.test.js +0 -481
- package/test/unit/lib/model/common/PersistentStateMachine.test.js +0 -178
- package/test/unit/lib/model/data/authorizationsResponse.json +0 -13
- package/test/unit/lib/model/data/bulkQuoteRequest.json +0 -27
- package/test/unit/lib/model/data/bulkQuoteResponse.json +0 -35
- package/test/unit/lib/model/data/bulkTransferFulfil.json +0 -13
- package/test/unit/lib/model/data/bulkTransferRequest.json +0 -29
- package/test/unit/lib/model/data/defaultConfig.json +0 -59
- package/test/unit/lib/model/data/getBulkTransfersBackendResponse.json +0 -42
- package/test/unit/lib/model/data/getBulkTransfersMojaloopResponse.json +0 -22
- package/test/unit/lib/model/data/getTransfersBackendResponse.json +0 -34
- package/test/unit/lib/model/data/getTransfersMojaloopResponse.json +0 -17
- package/test/unit/lib/model/data/mockArguments.json +0 -188
- package/test/unit/lib/model/data/mockTxnRequestsArguments.json +0 -63
- package/test/unit/lib/model/data/notificationAbortedToPayee.json +0 -10
- package/test/unit/lib/model/data/notificationReservedToPayee.json +0 -10
- package/test/unit/lib/model/data/notificationToPayee.json +0 -10
- package/test/unit/lib/model/data/payeeParty.json +0 -18
- package/test/unit/lib/model/data/putQuotesResponse.json +0 -33
- package/test/unit/lib/model/data/putTransfersResponse.json +0 -5
- package/test/unit/lib/model/data/quoteResponse.json +0 -42
- package/test/unit/lib/model/data/requestToPayRequest.json +0 -20
- package/test/unit/lib/model/data/requestToPayTransferRequest.json +0 -27
- package/test/unit/lib/model/data/transactionRequestResponse.json +0 -18
- package/test/unit/lib/model/data/transferFulfil.json +0 -10
- package/test/unit/lib/model/data/transferRequest.json +0 -26
- package/test/unit/lib/model/mockedLibRequests.js +0 -74
- package/test/unit/mockLogger.js +0 -39
- package/test/unit/outboundApi/data/bulkQuoteRequest.json +0 -28
- package/test/unit/outboundApi/data/bulkTransferRequest.json +0 -28
- package/test/unit/outboundApi/data/mockBulkQuoteError.json +0 -45
- package/test/unit/outboundApi/data/mockBulkTransferError.json +0 -48
- package/test/unit/outboundApi/data/mockError.json +0 -41
- package/test/unit/outboundApi/data/mockGetPartiesError.json +0 -4
- package/test/unit/outboundApi/data/mockRequestToPayError.json +0 -32
- package/test/unit/outboundApi/data/mockRequestToPayTransferError.json +0 -39
- package/test/unit/outboundApi/data/requestToPay.json +0 -21
- package/test/unit/outboundApi/data/requestToPayTransferRequest.json +0 -20
- package/test/unit/outboundApi/data/transferRequest.json +0 -21
- package/test/unit/outboundApi/handlers.test.js +0 -887
|
@@ -1,443 +0,0 @@
|
|
|
1
|
-
/**************************************************************************
|
|
2
|
-
* (C) Copyright ModusBox Inc. 2019 - All rights reserved. *
|
|
3
|
-
* *
|
|
4
|
-
* This file is made available under the terms of the license agreement *
|
|
5
|
-
* specified in the corresponding source code repository. *
|
|
6
|
-
* *
|
|
7
|
-
* ORIGINAL AUTHOR: *
|
|
8
|
-
* James Bush - james.bush@modusbox.com *
|
|
9
|
-
**************************************************************************/
|
|
10
|
-
|
|
11
|
-
'use strict';
|
|
12
|
-
|
|
13
|
-
const supertest = require('supertest');
|
|
14
|
-
|
|
15
|
-
const defaultConfig = require('./data/defaultConfig');
|
|
16
|
-
const putPartiesBody = require('./data/putPartiesBody');
|
|
17
|
-
const postQuotesBody = require('./data/postQuotesBody');
|
|
18
|
-
const putParticipantsBody = require('./data/putParticipantsBody');
|
|
19
|
-
const commonHttpHeaders = require('./data/commonHttpHeaders');
|
|
20
|
-
|
|
21
|
-
jest.mock('~/lib/cache');
|
|
22
|
-
jest.mock('@mojaloop/sdk-standard-components');
|
|
23
|
-
jest.mock('~/lib/model/lib/requests', () => require('./lib/model/mockedLibRequests'));
|
|
24
|
-
|
|
25
|
-
const Cache = require('~/lib/cache');
|
|
26
|
-
const { Jws, Logger } = require('@mojaloop/sdk-standard-components');
|
|
27
|
-
const path = require('path');
|
|
28
|
-
const fs = require('fs');
|
|
29
|
-
const os = require('os');
|
|
30
|
-
const http = require('http');
|
|
31
|
-
const https = require('https');
|
|
32
|
-
|
|
33
|
-
const InboundServer = require('~/InboundServer');
|
|
34
|
-
|
|
35
|
-
describe('Inbound Server', () => {
|
|
36
|
-
describe('PUT /parties', () => {
|
|
37
|
-
let serverConfig;
|
|
38
|
-
|
|
39
|
-
beforeEach(() => {
|
|
40
|
-
Jws.validator.__validate.mockClear();
|
|
41
|
-
serverConfig = JSON.parse(JSON.stringify(defaultConfig));
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
async function testPartiesJwsValidation(validateInboundJws, validateInboundPutPartiesJws, expectedValidationCalls) {
|
|
45
|
-
serverConfig.validateInboundJws = validateInboundJws;
|
|
46
|
-
serverConfig.validateInboundPutPartiesJws = validateInboundPutPartiesJws;
|
|
47
|
-
const logger = new Logger.Logger({ stringify: () => '' });
|
|
48
|
-
const cache = new Cache({ cacheUrl: serverConfig.cacheUrl, logger: logger.push({ component: 'cache' }) });
|
|
49
|
-
const svr = new InboundServer(serverConfig, logger, cache);
|
|
50
|
-
await svr.start();
|
|
51
|
-
await supertest(svr._server)
|
|
52
|
-
.put('/parties/MSISDN/123456789')
|
|
53
|
-
.send(putPartiesBody)
|
|
54
|
-
.set('content-type', 'application/vnd.interoperability.parties+json;version=1.1')
|
|
55
|
-
.set('fspiop-http-method', 'PUT')
|
|
56
|
-
.set('fspiop-uri', '/parties/MSISDN/123456789')
|
|
57
|
-
.set('date', new Date().toISOString());
|
|
58
|
-
await svr.stop();
|
|
59
|
-
expect(Jws.validator.__validate).toHaveBeenCalledTimes(expectedValidationCalls);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
async function testPartiesHeaderValidation(contentType, expectedStatusCode, expectedBody = null) {
|
|
63
|
-
const logger = new Logger.Logger({ stringify: () => '' });
|
|
64
|
-
const cache = new Cache({ cacheUrl: serverConfig.cacheUrl, logger: logger.push({ component: 'cache' }) });
|
|
65
|
-
const svr = new InboundServer(serverConfig, logger, cache);
|
|
66
|
-
await svr.start();
|
|
67
|
-
const result = await supertest(svr._server)
|
|
68
|
-
.put('/parties/MSISDN/123456789')
|
|
69
|
-
.send(putPartiesBody)
|
|
70
|
-
.set(commonHttpHeaders)
|
|
71
|
-
.set('content-type', contentType)
|
|
72
|
-
.set('fspiop-http-method', 'PUT')
|
|
73
|
-
.set('fspiop-uri', '/parties/MSISDN/123456789')
|
|
74
|
-
.set('date', new Date().toISOString());
|
|
75
|
-
await svr.stop();
|
|
76
|
-
expect(result.status).toEqual(expectedStatusCode);
|
|
77
|
-
|
|
78
|
-
if (expectedBody) {
|
|
79
|
-
expect(result.body).toEqual(expectedBody);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
test('validates incoming JWS when VALIDATE_INBOUND_JWS and VALIDATE_INBOUND_PUT_PARTIES_JWS is true', () =>
|
|
84
|
-
testPartiesJwsValidation(true, true, 1));
|
|
85
|
-
|
|
86
|
-
test('does not validate incoming JWS when VALIDATE_INBOUND_JWS is true and VALIDATE_INBOUND_PUT_PARTIES_JWS is false', () =>
|
|
87
|
-
testPartiesJwsValidation(true, false, 0));
|
|
88
|
-
|
|
89
|
-
test('does not validate incoming JWS when VALIDATE_INBOUND_JWS is false and VALIDATE_INBOUND_PUT_PARTIES_JWS is false', () =>
|
|
90
|
-
testPartiesJwsValidation(false, false, 0));
|
|
91
|
-
|
|
92
|
-
test('does not validate incoming JWS when VALIDATE_INBOUND_JWS is false and VALIDATE_INBOUND_PUT_PARTIES_JWS is true', () =>
|
|
93
|
-
testPartiesJwsValidation(false, true, 0));
|
|
94
|
-
|
|
95
|
-
test('processes parties request with valid content-type headers successfully', async () => {
|
|
96
|
-
await testPartiesHeaderValidation('application/vnd.interoperability.parties+json;version=1.1', 200);
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
test('returns error on invalid parties content-type headers', async () => {
|
|
100
|
-
await testPartiesHeaderValidation(
|
|
101
|
-
'application/json',
|
|
102
|
-
400,
|
|
103
|
-
{
|
|
104
|
-
'errorInformation': {
|
|
105
|
-
'errorCode': '3101',
|
|
106
|
-
'errorDescription': 'Malformed syntax'
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
);
|
|
110
|
-
await testPartiesHeaderValidation(
|
|
111
|
-
'application/vnd.interoperability.test+json;version=1.1',
|
|
112
|
-
400,
|
|
113
|
-
{
|
|
114
|
-
'errorInformation': {
|
|
115
|
-
'errorCode': '3101',
|
|
116
|
-
'errorDescription': 'Malformed syntax'
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
);
|
|
120
|
-
await testPartiesHeaderValidation(
|
|
121
|
-
'application/vnd.interoperability.parties+json;version=6.0',
|
|
122
|
-
406,
|
|
123
|
-
{
|
|
124
|
-
'errorInformation': {
|
|
125
|
-
'errorCode': '3001',
|
|
126
|
-
'errorDescription': 'Unacceptable version requested',
|
|
127
|
-
'extensionList': expect.any(Array)
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
);
|
|
131
|
-
});
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
describe('POST /quotes', () => {
|
|
135
|
-
let serverConfig;
|
|
136
|
-
beforeEach(() => {
|
|
137
|
-
Jws.validator.__validate.mockClear();
|
|
138
|
-
serverConfig = JSON.parse(JSON.stringify(defaultConfig));
|
|
139
|
-
});
|
|
140
|
-
async function testQuotesJwsValidation(validateInboundJws, validateInboundPutPartiesJws, expectedValidationCalls) {
|
|
141
|
-
serverConfig.validateInboundJws = validateInboundJws;
|
|
142
|
-
serverConfig.validateInboundPutPartiesJws = validateInboundPutPartiesJws;
|
|
143
|
-
const logger = new Logger.Logger({ stringify: () => '' });
|
|
144
|
-
const cache = new Cache({ cacheUrl: serverConfig.cacheUrl, logger: logger.push({ component: 'cache' }) });
|
|
145
|
-
const svr = new InboundServer(serverConfig, logger, cache);
|
|
146
|
-
await svr.start();
|
|
147
|
-
await supertest(svr._server)
|
|
148
|
-
.post('/quotes')
|
|
149
|
-
.send(postQuotesBody)
|
|
150
|
-
.set(commonHttpHeaders)
|
|
151
|
-
.set('content-type', 'application/vnd.interoperability.quotes+json;version=1.1')
|
|
152
|
-
.set('fspiop-http-method', 'POST')
|
|
153
|
-
.set('fspiop-uri', '/quotes')
|
|
154
|
-
.set('date', new Date().toISOString());
|
|
155
|
-
await svr.stop();
|
|
156
|
-
expect(Jws.validator.__validate).toHaveBeenCalledTimes(expectedValidationCalls);
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
async function testQuotesHeaderValidation(contentType, expectedStatusCode, expectedBody = null) {
|
|
160
|
-
const logger = new Logger.Logger({ stringify: () => '' });
|
|
161
|
-
const cache = new Cache({ cacheUrl: serverConfig.cacheUrl, logger: logger.push({ component: 'cache' }) });
|
|
162
|
-
const svr = new InboundServer(serverConfig, logger, cache);
|
|
163
|
-
await svr.start();
|
|
164
|
-
const result = await supertest(svr._server)
|
|
165
|
-
.post('/quotes')
|
|
166
|
-
.send(postQuotesBody)
|
|
167
|
-
.set(commonHttpHeaders)
|
|
168
|
-
.set('content-type', contentType)
|
|
169
|
-
.set('fspiop-http-method', 'POST')
|
|
170
|
-
.set('fspiop-uri', '/quotes')
|
|
171
|
-
.set('date', new Date().toISOString());
|
|
172
|
-
await svr.stop();
|
|
173
|
-
expect(result.status).toEqual(expectedStatusCode);
|
|
174
|
-
if (expectedBody) {
|
|
175
|
-
expect(result.body).toEqual(expectedBody);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
test('validates incoming JWS on other routes when VALIDATE_INBOUND_JWS is true and VALIDATE_INBOUND_PUT_PARTIES_JWS is false', () =>
|
|
180
|
-
testQuotesJwsValidation(true, false, 1));
|
|
181
|
-
|
|
182
|
-
test('validates incoming JWS on other routes when VALIDATE_INBOUND_JWS is true and VALIDATE_INBOUND_PUT_PARTIES_JWS is true', () =>
|
|
183
|
-
testQuotesJwsValidation(true, true, 1));
|
|
184
|
-
|
|
185
|
-
test('processes quotes request with valid content-type headers successfully', async () => {
|
|
186
|
-
await testQuotesHeaderValidation('application/vnd.interoperability.quotes+json;version=1.1', 202);
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
test('returns error on invalid quotes content-type headers', async () => {
|
|
190
|
-
await testQuotesHeaderValidation(
|
|
191
|
-
'application/json',
|
|
192
|
-
400,
|
|
193
|
-
{
|
|
194
|
-
'errorInformation': {
|
|
195
|
-
'errorCode': '3101',
|
|
196
|
-
'errorDescription': 'Malformed syntax'
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
);
|
|
200
|
-
await testQuotesHeaderValidation(
|
|
201
|
-
'application/vnd.interoperability.parties+json;version=1.1',
|
|
202
|
-
400,
|
|
203
|
-
{
|
|
204
|
-
'errorInformation': {
|
|
205
|
-
'errorCode': '3101',
|
|
206
|
-
'errorDescription': 'Malformed syntax'
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
);
|
|
210
|
-
await testQuotesHeaderValidation(
|
|
211
|
-
'application/vnd.interoperability.quotes+json;version=6.0',
|
|
212
|
-
406,
|
|
213
|
-
{
|
|
214
|
-
'errorInformation': {
|
|
215
|
-
'errorCode': '3001',
|
|
216
|
-
'errorDescription': 'Unacceptable version requested',
|
|
217
|
-
'extensionList': expect.any(Array)
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
);
|
|
221
|
-
});
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
describe('PUT /participants', () => {
|
|
225
|
-
let serverConfig;
|
|
226
|
-
beforeEach(() => {
|
|
227
|
-
Jws.validator.__validate.mockClear();
|
|
228
|
-
serverConfig = JSON.parse(JSON.stringify(defaultConfig));
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
async function testParticipantsJwsValidation(validateInboundJws, validateInboundPutPartiesJws, expectedValidationCalls) {
|
|
232
|
-
serverConfig.validateInboundJws = validateInboundJws;
|
|
233
|
-
serverConfig.validateInboundPutPartiesJws = validateInboundPutPartiesJws;
|
|
234
|
-
const logger = new Logger.Logger({ stringify: () => '' });
|
|
235
|
-
const cache = new Cache({ cacheUrl: serverConfig.cacheUrl, logger: logger.push({ component: 'cache' }) });
|
|
236
|
-
const svr = new InboundServer(serverConfig, logger, cache);
|
|
237
|
-
await svr.start();
|
|
238
|
-
await supertest(svr._server)
|
|
239
|
-
.put('/participants/00000000-0000-1000-a000-000000000002')
|
|
240
|
-
.send(putParticipantsBody)
|
|
241
|
-
.set(commonHttpHeaders)
|
|
242
|
-
.set('content-type', 'application/vnd.interoperability.participants+json;version=1.1')
|
|
243
|
-
.set('fspiop-http-method', 'PUT')
|
|
244
|
-
.set('fspiop-uri', '/participants/00000000-0000-1000-a000-000000000002')
|
|
245
|
-
.set('date', new Date().toISOString());
|
|
246
|
-
await svr.stop();
|
|
247
|
-
expect(Jws.validator.__validate).toHaveBeenCalledTimes(expectedValidationCalls);
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
async function testParticipantsHeaderValidation(contentType, expectedStatusCode, expectedBody = null) {
|
|
251
|
-
const logger = new Logger.Logger({ stringify: () => '' });
|
|
252
|
-
const cache = new Cache({ cacheUrl: serverConfig.cacheUrl, logger: logger.push({ component: 'cache' }) });
|
|
253
|
-
const svr = new InboundServer(serverConfig, logger, cache);
|
|
254
|
-
await svr.start();
|
|
255
|
-
const result = await supertest(svr._server)
|
|
256
|
-
.put('/participants/00000000-0000-1000-a000-000000000002')
|
|
257
|
-
.send(putParticipantsBody)
|
|
258
|
-
.set(commonHttpHeaders)
|
|
259
|
-
.set('content-type', contentType)
|
|
260
|
-
.set('fspiop-http-method', 'PUT')
|
|
261
|
-
.set('fspiop-uri', '/participants/00000000-0000-1000-a000-000000000002')
|
|
262
|
-
.set('date', new Date().toISOString());
|
|
263
|
-
await svr.stop();
|
|
264
|
-
expect(result.status).toEqual(expectedStatusCode);
|
|
265
|
-
if (expectedBody) {
|
|
266
|
-
expect(result.body).toEqual(expectedBody);
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
test('validates incoming JWS when VALIDATE_INBOUND_JWS is true', () =>
|
|
271
|
-
testParticipantsJwsValidation(true, true, 1));
|
|
272
|
-
|
|
273
|
-
test('does not validate incoming JWS when VALIDATE_INBOUND_JWS is false ', () =>
|
|
274
|
-
testParticipantsJwsValidation(false, false, 0));
|
|
275
|
-
|
|
276
|
-
test('processes participants request with valid content-type headers successfully', async () => {
|
|
277
|
-
await testParticipantsHeaderValidation('application/vnd.interoperability.participants+json;version=1.1', 200);
|
|
278
|
-
});
|
|
279
|
-
|
|
280
|
-
test('returns error on invalid participants content-type headers', async () => {
|
|
281
|
-
await testParticipantsHeaderValidation(
|
|
282
|
-
'application/json',
|
|
283
|
-
400,
|
|
284
|
-
{
|
|
285
|
-
'errorInformation': {
|
|
286
|
-
'errorCode': '3101',
|
|
287
|
-
'errorDescription': 'Malformed syntax'
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
);
|
|
291
|
-
await testParticipantsHeaderValidation(
|
|
292
|
-
'application/vnd.interoperability.parties+json;version=1.1',
|
|
293
|
-
400,
|
|
294
|
-
{
|
|
295
|
-
'errorInformation': {
|
|
296
|
-
'errorCode': '3101',
|
|
297
|
-
'errorDescription': 'Malformed syntax'
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
);
|
|
301
|
-
await testParticipantsHeaderValidation(
|
|
302
|
-
'application/vnd.interoperability.participants+json;version=6.0',
|
|
303
|
-
406,
|
|
304
|
-
{
|
|
305
|
-
'errorInformation': {
|
|
306
|
-
'errorCode': '3001',
|
|
307
|
-
'errorDescription': 'Unacceptable version requested',
|
|
308
|
-
'extensionList': expect.any(Array)
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
);
|
|
312
|
-
});
|
|
313
|
-
});
|
|
314
|
-
|
|
315
|
-
describe('mTLS test', () => {
|
|
316
|
-
let defConfig;
|
|
317
|
-
let httpServerSpy;
|
|
318
|
-
let httpsServerSpy;
|
|
319
|
-
|
|
320
|
-
beforeAll(() => {
|
|
321
|
-
httpServerSpy = jest.spyOn(http, 'createServer');
|
|
322
|
-
httpsServerSpy = jest.spyOn(https, 'createServer');
|
|
323
|
-
});
|
|
324
|
-
|
|
325
|
-
beforeEach(() => {
|
|
326
|
-
defConfig = JSON.parse(JSON.stringify(defaultConfig));
|
|
327
|
-
httpServerSpy.mockClear();
|
|
328
|
-
httpsServerSpy.mockClear();
|
|
329
|
-
});
|
|
330
|
-
|
|
331
|
-
afterAll(() => {
|
|
332
|
-
httpServerSpy.mockRestore();
|
|
333
|
-
httpsServerSpy.mockRestore();
|
|
334
|
-
});
|
|
335
|
-
|
|
336
|
-
async function testTlsServer(enableTls) {
|
|
337
|
-
defConfig.inbound.tls.mutualTLS.enabled = enableTls;
|
|
338
|
-
const logger = new Logger.Logger({ stringify: () => '' });
|
|
339
|
-
const cache = new Cache({ cacheUrl: defConfig.cacheUrl, logger: logger.push({ component: 'cache' }) });
|
|
340
|
-
const server = new InboundServer(defConfig, logger, cache);
|
|
341
|
-
await server.start();
|
|
342
|
-
if (enableTls) {
|
|
343
|
-
expect(httpsServerSpy).toHaveBeenCalled();
|
|
344
|
-
expect(httpServerSpy).not.toHaveBeenCalled();
|
|
345
|
-
} else {
|
|
346
|
-
expect(httpsServerSpy).not.toHaveBeenCalled();
|
|
347
|
-
expect(httpServerSpy).toHaveBeenCalled();
|
|
348
|
-
}
|
|
349
|
-
await server.stop();
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
test('Inbound server should use HTTPS if inbound mTLS enabled', () =>
|
|
353
|
-
testTlsServer(true));
|
|
354
|
-
|
|
355
|
-
test('Inbound server should use HTTP if inbound mTLS disabled', () =>
|
|
356
|
-
testTlsServer(false));
|
|
357
|
-
});
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
describe('JWS verification keys', () => {
|
|
361
|
-
let svr;
|
|
362
|
-
let keysDir;
|
|
363
|
-
|
|
364
|
-
beforeEach(async () => {
|
|
365
|
-
const serverConfig = JSON.parse(JSON.stringify(defaultConfig));
|
|
366
|
-
serverConfig.validateInboundJws = true;
|
|
367
|
-
keysDir = fs.mkdtempSync(path.join(os.tmpdir(), 'jest-'));
|
|
368
|
-
const mockFilePath = path.join(keysDir, 'mojaloop-sdk.pem');
|
|
369
|
-
fs.writeFileSync(mockFilePath, 'foo-key');
|
|
370
|
-
serverConfig.jwsVerificationKeysDirectory = keysDir;
|
|
371
|
-
const logger = new Logger.Logger({ stringify: () => '' });
|
|
372
|
-
const cache = new Cache({ cacheUrl: serverConfig.cacheUrl, logger: logger.push({ component: 'cache' }) });
|
|
373
|
-
svr = new InboundServer(serverConfig, logger, cache);
|
|
374
|
-
await svr.start();
|
|
375
|
-
});
|
|
376
|
-
|
|
377
|
-
afterEach(async () => {
|
|
378
|
-
await svr.stop();
|
|
379
|
-
fs.rmSync(keysDir, { recursive: true });
|
|
380
|
-
});
|
|
381
|
-
|
|
382
|
-
it('updates server configuration when a new JWS verification key '
|
|
383
|
-
+ 'is added to the target monitored folder.', async () => {
|
|
384
|
-
let keys;
|
|
385
|
-
|
|
386
|
-
keys = Object.keys(Jws.validator.__validationKeys);
|
|
387
|
-
expect(keys).toEqual(['mojaloop-sdk']);
|
|
388
|
-
|
|
389
|
-
const mockFilePath = path.join(keysDir, 'mock-jws.pem');
|
|
390
|
-
fs.writeFileSync(mockFilePath, 'foo-key');
|
|
391
|
-
|
|
392
|
-
await new Promise(resolve => setTimeout(() => resolve(), 1000));
|
|
393
|
-
|
|
394
|
-
keys = Object.keys(Jws.validator.__validationKeys);
|
|
395
|
-
expect(keys).toEqual(['mojaloop-sdk', 'mock-jws']);
|
|
396
|
-
});
|
|
397
|
-
|
|
398
|
-
it('updates server configuration when a new JWS verification key '
|
|
399
|
-
+ 'is removed from the target monitored folder.', async () => {
|
|
400
|
-
let keys;
|
|
401
|
-
|
|
402
|
-
keys = Object.keys(Jws.validator.__validationKeys);
|
|
403
|
-
expect(keys).toEqual(['mojaloop-sdk']);
|
|
404
|
-
|
|
405
|
-
const mockFilePath = path.join(keysDir, 'mock-jws.pem');
|
|
406
|
-
fs.writeFileSync(mockFilePath, 'foo-key');
|
|
407
|
-
|
|
408
|
-
await new Promise(resolve => setTimeout(() => resolve(), 1000));
|
|
409
|
-
|
|
410
|
-
keys = Object.keys(Jws.validator.__validationKeys);
|
|
411
|
-
expect(keys).toEqual(['mojaloop-sdk', 'mock-jws']);
|
|
412
|
-
|
|
413
|
-
fs.unlinkSync(mockFilePath);
|
|
414
|
-
|
|
415
|
-
await new Promise(resolve => setTimeout(() => resolve(), 1000));
|
|
416
|
-
|
|
417
|
-
keys = Object.keys(Jws.validator.__validationKeys);
|
|
418
|
-
expect(keys).toEqual(['mojaloop-sdk']);
|
|
419
|
-
});
|
|
420
|
-
|
|
421
|
-
it('updates server configuration when a new JWS verification key '
|
|
422
|
-
+ 'is changed in the target monitored folder.', async () => {
|
|
423
|
-
let keys;
|
|
424
|
-
|
|
425
|
-
keys = Object.keys(Jws.validator.__validationKeys);
|
|
426
|
-
expect(keys).toEqual(['mojaloop-sdk']);
|
|
427
|
-
|
|
428
|
-
const mockFilePath = path.join(keysDir, 'mock-jws.pem');
|
|
429
|
-
fs.writeFileSync(mockFilePath, 'foo-key');
|
|
430
|
-
|
|
431
|
-
await new Promise(resolve => setTimeout(() => resolve(), 1000));
|
|
432
|
-
|
|
433
|
-
keys = Object.keys(Jws.validator.__validationKeys);
|
|
434
|
-
expect(keys).toEqual(['mojaloop-sdk', 'mock-jws']);
|
|
435
|
-
|
|
436
|
-
fs.writeFileSync(mockFilePath, 'foo-key-updated');
|
|
437
|
-
|
|
438
|
-
await new Promise(resolve => setTimeout(() => resolve(), 1000));
|
|
439
|
-
|
|
440
|
-
expect(Jws.validator.__validationKeys['mock-jws'].toString()).toEqual('foo-key-updated');
|
|
441
|
-
});
|
|
442
|
-
});
|
|
443
|
-
});
|