@mojaloop/sdk-scheme-adapter 11.18.8
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/.env.example +140 -0
- package/.eslintignore +2 -0
- package/.eslintrc.json +30 -0
- package/.nvmrc +1 -0
- package/.versionrc +15 -0
- package/CHANGELOG.md +118 -0
- package/InboundServer/api.yaml +3594 -0
- package/InboundServer/api_template.yaml +69 -0
- package/InboundServer/handlers.js +940 -0
- package/InboundServer/index.js +205 -0
- package/InboundServer/middlewares.js +426 -0
- package/OAuthTestServer/index.js +66 -0
- package/OAuthTestServer/model.js +70 -0
- package/OutboundServer/api.yaml +2732 -0
- package/OutboundServer/api_interfaces/index.d.ts +117 -0
- package/OutboundServer/api_interfaces/openapi.d.ts +1475 -0
- package/OutboundServer/api_template/components/parameters/bulkQuoteId.yaml +9 -0
- package/OutboundServer/api_template/components/parameters/bulkTransferId.yaml +9 -0
- package/OutboundServer/api_template/components/parameters/requestToPayTransactionId.yaml +9 -0
- package/OutboundServer/api_template/components/parameters/transferId.yaml +9 -0
- package/OutboundServer/api_template/components/responses/accountsCreationCompleted.yaml +5 -0
- package/OutboundServer/api_template/components/responses/accountsCreationError.yaml +5 -0
- package/OutboundServer/api_template/components/responses/accountsCreationTimeout.yaml +5 -0
- package/OutboundServer/api_template/components/responses/authorizationPostSuccess.yaml +5 -0
- package/OutboundServer/api_template/components/responses/authorizationsServerError.yaml +5 -0
- package/OutboundServer/api_template/components/responses/bulkQuoteBadRequest.yaml +5 -0
- package/OutboundServer/api_template/components/responses/bulkQuoteServerError.yaml +5 -0
- package/OutboundServer/api_template/components/responses/bulkQuoteSuccess.yaml +5 -0
- package/OutboundServer/api_template/components/responses/bulkQuoteTimeout.yaml +5 -0
- package/OutboundServer/api_template/components/responses/bulkTransferBadRequest.yaml +5 -0
- package/OutboundServer/api_template/components/responses/bulkTransferServerError.yaml +5 -0
- package/OutboundServer/api_template/components/responses/bulkTransferSuccess.yaml +5 -0
- package/OutboundServer/api_template/components/responses/bulkTransferTimeout.yaml +5 -0
- package/OutboundServer/api_template/components/responses/partiesByIdError404.yaml +9 -0
- package/OutboundServer/api_template/components/responses/partiesByIdSuccess.yaml +5 -0
- package/OutboundServer/api_template/components/responses/quotesPostSuccess.yaml +5 -0
- package/OutboundServer/api_template/components/responses/quotesServerError.yaml +5 -0
- package/OutboundServer/api_template/components/responses/requestToPaySuccess.yaml +5 -0
- package/OutboundServer/api_template/components/responses/requestToPayTransferBadRequest.yaml +5 -0
- package/OutboundServer/api_template/components/responses/requestToPayTransferSuccess.yaml +5 -0
- package/OutboundServer/api_template/components/responses/simpleTransfersPostSuccess.yaml +5 -0
- package/OutboundServer/api_template/components/responses/simpleTransfersServerError.yaml +5 -0
- package/OutboundServer/api_template/components/responses/transferBadRequest.yaml +5 -0
- package/OutboundServer/api_template/components/responses/transferServerError.yaml +5 -0
- package/OutboundServer/api_template/components/responses/transferSuccess.yaml +5 -0
- package/OutboundServer/api_template/components/responses/transferTimeout.yaml +5 -0
- package/OutboundServer/api_template/components/schemas/accountCreationStatus.yaml +18 -0
- package/OutboundServer/api_template/components/schemas/accountsCreationState.yaml +4 -0
- package/OutboundServer/api_template/components/schemas/accountsRequest.yaml +20 -0
- package/OutboundServer/api_template/components/schemas/accountsResponse.yaml +15 -0
- package/OutboundServer/api_template/components/schemas/async2SyncCurrentState.yaml +5 -0
- package/OutboundServer/api_template/components/schemas/authorizationsPostRequest.yaml +15 -0
- package/OutboundServer/api_template/components/schemas/authorizationsPostResponse.yaml +19 -0
- package/OutboundServer/api_template/components/schemas/bulkQuoteErrorResponse.yaml +8 -0
- package/OutboundServer/api_template/components/schemas/bulkQuoteRequest.yaml +26 -0
- package/OutboundServer/api_template/components/schemas/bulkQuoteResponse.yaml +21 -0
- package/OutboundServer/api_template/components/schemas/bulkQuoteStatus.yaml +4 -0
- package/OutboundServer/api_template/components/schemas/bulkQuoteStatusResponse.yaml +17 -0
- package/OutboundServer/api_template/components/schemas/bulkTransferErrorResponse.yaml +8 -0
- package/OutboundServer/api_template/components/schemas/bulkTransferRequest.yaml +26 -0
- package/OutboundServer/api_template/components/schemas/bulkTransferResponse.yaml +16 -0
- package/OutboundServer/api_template/components/schemas/bulkTransferStatus.yaml +4 -0
- package/OutboundServer/api_template/components/schemas/bulkTransferStatusResponse.yaml +17 -0
- package/OutboundServer/api_template/components/schemas/errorAccountsResponse.yaml +8 -0
- package/OutboundServer/api_template/components/schemas/errorAuthorizationsResponse.yaml +3 -0
- package/OutboundServer/api_template/components/schemas/errorQuotesResponse.yaml +9 -0
- package/OutboundServer/api_template/components/schemas/errorResponse.yaml +8 -0
- package/OutboundServer/api_template/components/schemas/errorSimpleTransfersResponse.yaml +3 -0
- package/OutboundServer/api_template/components/schemas/errorTransferResponse.yaml +8 -0
- package/OutboundServer/api_template/components/schemas/extensionListEmptiable.yaml +6 -0
- package/OutboundServer/api_template/components/schemas/individualQuote.yaml +32 -0
- package/OutboundServer/api_template/components/schemas/individualQuoteResult.yaml +28 -0
- package/OutboundServer/api_template/components/schemas/individualTransfer.yaml +32 -0
- package/OutboundServer/api_template/components/schemas/individualTransferFulfilment.yaml +13 -0
- package/OutboundServer/api_template/components/schemas/individualTransferResult.yaml +41 -0
- package/OutboundServer/api_template/components/schemas/mojaloopError.yaml +5 -0
- package/OutboundServer/api_template/components/schemas/mojaloopTransactionRequestState.yaml +2 -0
- package/OutboundServer/api_template/components/schemas/partiesByIdResponse.yaml +13 -0
- package/OutboundServer/api_template/components/schemas/quote.yaml +3 -0
- package/OutboundServer/api_template/components/schemas/quoteError.yaml +16 -0
- package/OutboundServer/api_template/components/schemas/quotesPostRequest.yaml +13 -0
- package/OutboundServer/api_template/components/schemas/quotesPostResponse.yaml +48 -0
- package/OutboundServer/api_template/components/schemas/requestToPayRequest.yaml +39 -0
- package/OutboundServer/api_template/components/schemas/requestToPayResponse.yaml +41 -0
- package/OutboundServer/api_template/components/schemas/requestToPayTransferRequest.yaml +42 -0
- package/OutboundServer/api_template/components/schemas/requestToPayTransferResponse.yaml +58 -0
- package/OutboundServer/api_template/components/schemas/simpleTransferServerError.yaml +5 -0
- package/OutboundServer/api_template/components/schemas/simpleTransfersPostRequest.yaml +12 -0
- package/OutboundServer/api_template/components/schemas/simpleTransfersPostResponse.yaml +11 -0
- package/OutboundServer/api_template/components/schemas/transactionType.yaml +4 -0
- package/OutboundServer/api_template/components/schemas/transferContinuationAcceptOTP.yaml +9 -0
- package/OutboundServer/api_template/components/schemas/transferContinuationAcceptParty.yaml +8 -0
- package/OutboundServer/api_template/components/schemas/transferContinuationAcceptQuote.yaml +9 -0
- package/OutboundServer/api_template/components/schemas/transferError.yaml +16 -0
- package/OutboundServer/api_template/components/schemas/transferFulfilment.yaml +3 -0
- package/OutboundServer/api_template/components/schemas/transferParty.yaml +40 -0
- package/OutboundServer/api_template/components/schemas/transferRequest.yaml +37 -0
- package/OutboundServer/api_template/components/schemas/transferResponse.yaml +58 -0
- package/OutboundServer/api_template/components/schemas/transferStatus.yaml +6 -0
- package/OutboundServer/api_template/components/schemas/transferStatusResponse.yaml +13 -0
- package/OutboundServer/api_template/health.yaml +12 -0
- package/OutboundServer/api_template/openapi.yaml +55 -0
- package/OutboundServer/api_template/paths/accounts.yaml +26 -0
- package/OutboundServer/api_template/paths/authorizations.yaml +19 -0
- package/OutboundServer/api_template/paths/bulkQuotes.yaml +23 -0
- package/OutboundServer/api_template/paths/bulkQuotes_bulkQuoteId.yaml +24 -0
- package/OutboundServer/api_template/paths/bulkTransfers.yaml +23 -0
- package/OutboundServer/api_template/paths/bulkTransfers_bulkTransferId.yaml +24 -0
- package/OutboundServer/api_template/paths/parties_Type_ID.yaml +20 -0
- package/OutboundServer/api_template/paths/parties_Type_ID_SubId.yaml +22 -0
- package/OutboundServer/api_template/paths/quotes.yaml +20 -0
- package/OutboundServer/api_template/paths/requestToPay.yaml +22 -0
- package/OutboundServer/api_template/paths/requestToPayTransfer.yaml +57 -0
- package/OutboundServer/api_template/paths/requestToPayTransfer_requestToPayTransactionId.yaml +34 -0
- package/OutboundServer/api_template/paths/simpleTransfers.yaml +19 -0
- package/OutboundServer/api_template/paths/transfers.yaml +55 -0
- package/OutboundServer/api_template/paths/transfers_transferId.yaml +58 -0
- package/OutboundServer/handlers.js +622 -0
- package/OutboundServer/index.js +137 -0
- package/OutboundServer/middlewares.js +67 -0
- package/TestServer/api.yaml +62 -0
- package/TestServer/handlers.js +63 -0
- package/TestServer/index.js +215 -0
- package/audit-resolve.json +65 -0
- package/babel.config.js +3 -0
- package/config.js +158 -0
- package/index.d.ts +1 -0
- package/index.js +149 -0
- package/jest.config.js +15 -0
- package/lib/api/index.js +12 -0
- package/lib/cache.js +352 -0
- package/lib/check.js +25 -0
- package/lib/model/AccountsModel.js +396 -0
- package/lib/model/Async2SyncModel.js +283 -0
- package/lib/model/AuthorizationsModel.js +86 -0
- package/lib/model/InboundTransfersModel.js +730 -0
- package/lib/model/OutboundBulkQuotesModel.js +485 -0
- package/lib/model/OutboundBulkTransfersModel.js +479 -0
- package/lib/model/OutboundRequestToPayModel.js +517 -0
- package/lib/model/OutboundRequestToPayTransferModel.js +893 -0
- package/lib/model/OutboundTransfersModel.js +823 -0
- package/lib/model/PartiesModel.js +70 -0
- package/lib/model/ProxyModel/MatchRules/Expression.js +48 -0
- package/lib/model/ProxyModel/MatchRules/Headers.js +65 -0
- package/lib/model/ProxyModel/MatchRules/MatchRule.js +27 -0
- package/lib/model/ProxyModel/MatchRules/Path.js +36 -0
- package/lib/model/ProxyModel/MatchRules/Query.js +65 -0
- package/lib/model/ProxyModel/MatchRules/index.js +19 -0
- package/lib/model/ProxyModel/Route.js +82 -0
- package/lib/model/ProxyModel/configSchema.json +118 -0
- package/lib/model/ProxyModel/index.js +138 -0
- package/lib/model/QuotesModel.js +94 -0
- package/lib/model/TransfersModel.js +81 -0
- package/lib/model/common/BackendError.js +26 -0
- package/lib/model/common/PersistentStateMachine.js +93 -0
- package/lib/model/common/index.js +18 -0
- package/lib/model/index.js +43 -0
- package/lib/model/lib/deferredJob.js +113 -0
- package/lib/model/lib/index.js +9 -0
- package/lib/model/lib/requests/backendRequests.js +227 -0
- package/lib/model/lib/requests/common.js +76 -0
- package/lib/model/lib/requests/index.js +19 -0
- package/lib/model/lib/shared.js +468 -0
- package/lib/randomphrase/index.js +21 -0
- package/lib/randomphrase/words.json +3397 -0
- package/lib/router.js +28 -0
- package/lib/validate.js +205 -0
- package/package.json +102 -0
- package/test/__mocks__/@mojaloop/sdk-standard-components.js +152 -0
- package/test/__mocks__/javascript-state-machine.js +21 -0
- package/test/__mocks__/redis.js +49 -0
- package/test/__mocks__/uuidv4.js +16 -0
- package/test/config/integration.env +136 -0
- package/test/integration/lib/Outbound/authorizations.test.js +58 -0
- package/test/integration/lib/Outbound/data/authorizationsPostRequest.json +43 -0
- package/test/integration/lib/Outbound/data/quotesPostRequest.json +52 -0
- package/test/integration/lib/Outbound/data/transfersPostRequest.json +24 -0
- package/test/integration/lib/Outbound/parties.test.js +28 -0
- package/test/integration/lib/Outbound/quotes.test.js +58 -0
- package/test/integration/lib/Outbound/simpleTransfers.test.js +67 -0
- package/test/integration/lib/cache.test.js +80 -0
- package/test/integration/testEnv.js +7 -0
- package/test/unit/InboundServer.test.js +443 -0
- package/test/unit/TestServer.test.js +394 -0
- package/test/unit/api/accounts/accounts.test.js +128 -0
- package/test/unit/api/accounts/data/postAccountsBody.json +7 -0
- package/test/unit/api/accounts/data/postAccountsErrorMojaloopResponse.json +25 -0
- package/test/unit/api/accounts/data/postAccountsErrorTimeoutResponse.json +19 -0
- package/test/unit/api/accounts/data/postAccountsSuccessResponse.json +17 -0
- package/test/unit/api/accounts/data/postAccountsSuccessResponseWithError1.json +21 -0
- package/test/unit/api/accounts/data/postAccountsSuccessResponseWithError2.json +21 -0
- package/test/unit/api/accounts/utils.js +65 -0
- package/test/unit/api/proxy/data/proxyConfig.yaml +82 -0
- package/test/unit/api/proxy/data/requestBody.json +22 -0
- package/test/unit/api/proxy/data/requestHeaders.json +5 -0
- package/test/unit/api/proxy/data/requestQuery.json +6 -0
- package/test/unit/api/proxy/data/responseBody.json +21 -0
- package/test/unit/api/proxy/data/responseHeaders.json +5 -0
- package/test/unit/api/proxy/proxy.test.js +220 -0
- package/test/unit/api/proxy/utils.js +79 -0
- package/test/unit/api/transfers/data/getTransfersCommittedResponse.json +21 -0
- package/test/unit/api/transfers/data/getTransfersErrorNotFound.json +17 -0
- package/test/unit/api/transfers/data/postQuotesBody.json +52 -0
- package/test/unit/api/transfers/data/postTransfersBadBody.json +17 -0
- package/test/unit/api/transfers/data/postTransfersBody.json +24 -0
- package/test/unit/api/transfers/data/postTransfersErrorMojaloopResponse.json +53 -0
- package/test/unit/api/transfers/data/postTransfersErrorTimeoutResponse.json +47 -0
- package/test/unit/api/transfers/data/postTransfersSimpleBody.json +26 -0
- package/test/unit/api/transfers/data/postTransfersSuccessResponse.json +101 -0
- package/test/unit/api/transfers/data/putPartiesBody.json +20 -0
- package/test/unit/api/transfers/data/putQuotesBody.json +37 -0
- package/test/unit/api/transfers/data/putTransfersBody.json +17 -0
- package/test/unit/api/transfers/transfers.test.js +191 -0
- package/test/unit/api/transfers/utils.js +183 -0
- package/test/unit/api/utils.js +75 -0
- package/test/unit/config.test.js +119 -0
- package/test/unit/data/commonHttpHeaders.json +6 -0
- package/test/unit/data/defaultConfig.json +58 -0
- package/test/unit/data/postQuotesBody.json +52 -0
- package/test/unit/data/putParticipantsBody.json +12 -0
- package/test/unit/data/putPartiesBody.json +20 -0
- package/test/unit/data/testFile.json +29 -0
- package/test/unit/data/testFile.yaml +14 -0
- package/test/unit/inboundApi/data/mockArguments.json +117 -0
- package/test/unit/inboundApi/data/mockTransactionRequest.json +42 -0
- package/test/unit/inboundApi/handlers.test.js +799 -0
- package/test/unit/index.test.js +55 -0
- package/test/unit/lib/cache.test.js +146 -0
- package/test/unit/lib/model/AccountsModel.test.js +121 -0
- package/test/unit/lib/model/AuthorizationsModel.test.js +460 -0
- package/test/unit/lib/model/InboundTransfersModel.test.js +628 -0
- package/test/unit/lib/model/OutboundBulkQuotesModel.test.js +249 -0
- package/test/unit/lib/model/OutboundBulkTransfersModel.test.js +244 -0
- package/test/unit/lib/model/OutboundRequestToPayModel.test.js +166 -0
- package/test/unit/lib/model/OutboundRequestToPayTransferModel.test.js +245 -0
- package/test/unit/lib/model/OutboundTransfersModel.test.js +836 -0
- package/test/unit/lib/model/PartiesModel.test.js +468 -0
- package/test/unit/lib/model/QuotesModel.test.js +470 -0
- package/test/unit/lib/model/TransfersModel.test.js +474 -0
- package/test/unit/lib/model/common/PersistentStateMachine.test.js +179 -0
- package/test/unit/lib/model/data/authorizationsResponse.json +13 -0
- package/test/unit/lib/model/data/bulkQuoteRequest.json +27 -0
- package/test/unit/lib/model/data/bulkQuoteResponse.json +35 -0
- package/test/unit/lib/model/data/bulkTransferFulfil.json +13 -0
- package/test/unit/lib/model/data/bulkTransferRequest.json +29 -0
- package/test/unit/lib/model/data/defaultConfig.json +47 -0
- package/test/unit/lib/model/data/getBulkTransfersBackendResponse.json +42 -0
- package/test/unit/lib/model/data/getBulkTransfersMojaloopResponse.json +22 -0
- package/test/unit/lib/model/data/getTransfersBackendResponse.json +34 -0
- package/test/unit/lib/model/data/getTransfersMojaloopResponse.json +17 -0
- package/test/unit/lib/model/data/mockArguments.json +131 -0
- package/test/unit/lib/model/data/mockTxnRequestsArguments.json +63 -0
- package/test/unit/lib/model/data/notificationToPayee.json +10 -0
- package/test/unit/lib/model/data/payeeParty.json +16 -0
- package/test/unit/lib/model/data/putAuthorizationsResponse.json +10 -0
- package/test/unit/lib/model/data/putQuotesResponse.json +33 -0
- package/test/unit/lib/model/data/putTransfersResponse.json +5 -0
- package/test/unit/lib/model/data/quoteResponse.json +31 -0
- package/test/unit/lib/model/data/requestToPayRequest.json +20 -0
- package/test/unit/lib/model/data/requestToPayTransferRequest.json +27 -0
- package/test/unit/lib/model/data/transactionRequestResponse.json +18 -0
- package/test/unit/lib/model/data/transferFulfil.json +8 -0
- package/test/unit/lib/model/data/transferRequest.json +26 -0
- package/test/unit/lib/model/mockedLibRequests.js +74 -0
- package/test/unit/mockLogger.js +39 -0
- package/test/unit/outboundApi/data/bulkQuoteRequest.json +28 -0
- package/test/unit/outboundApi/data/bulkTransferRequest.json +28 -0
- package/test/unit/outboundApi/data/mockBulkQuoteError.json +45 -0
- package/test/unit/outboundApi/data/mockBulkTransferError.json +48 -0
- package/test/unit/outboundApi/data/mockError.json +41 -0
- package/test/unit/outboundApi/data/mockGetPartiesError.json +4 -0
- package/test/unit/outboundApi/data/mockRequestToPayError.json +32 -0
- package/test/unit/outboundApi/data/mockRequestToPayTransferError.json +39 -0
- package/test/unit/outboundApi/data/requestToPay.json +21 -0
- package/test/unit/outboundApi/data/requestToPayTransferRequest.json +20 -0
- package/test/unit/outboundApi/data/transferRequest.json +21 -0
- package/test/unit/outboundApi/handlers.test.js +986 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const axios = require('axios');
|
|
4
|
+
const { uuid } = require('uuidv4');
|
|
5
|
+
const env = require('../../testEnv');
|
|
6
|
+
const transfersPostRequest = require('./data/transfersPostRequest.json');
|
|
7
|
+
|
|
8
|
+
jest.dontMock('redis');
|
|
9
|
+
|
|
10
|
+
/*
|
|
11
|
+
"TRANSFERS_VALIDATION_WITH_PREVIOUS_QUOTES": false,
|
|
12
|
+
"TRANSFERS_VALIDATION_ILP_PACKET": false,
|
|
13
|
+
"TRANSFERS_VALIDATION_CONDITION": false,
|
|
14
|
+
|
|
15
|
+
Ensure these values in the TTK `user_config.json` file are set to false.
|
|
16
|
+
Since we are testing the /transfers endpoint in isolation without a prior
|
|
17
|
+
quote and a fake `ilpPacket` and `condition`.
|
|
18
|
+
*/
|
|
19
|
+
describe('/simpleTransfers', () => {
|
|
20
|
+
|
|
21
|
+
test('post - happy flow', async () => {
|
|
22
|
+
const postTransfersURI = `${env.OutboundHostURI}/simpleTransfers`;
|
|
23
|
+
const transferId = uuid();
|
|
24
|
+
const res = await axios({
|
|
25
|
+
method: 'POST',
|
|
26
|
+
url: postTransfersURI,
|
|
27
|
+
data: {
|
|
28
|
+
fspId: 'switch',
|
|
29
|
+
transfersPostRequest: {
|
|
30
|
+
...transfersPostRequest,
|
|
31
|
+
transferId
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
headers: {
|
|
35
|
+
'access-control-allow-origin': '*'
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
expect(res.status).toEqual(200);
|
|
40
|
+
expect(res.data.currentState).toEqual('COMPLETED');
|
|
41
|
+
expect(typeof res.data.transfer).toEqual('object');
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test('post - timeout', async () => {
|
|
45
|
+
const postTransfersURI = `${env.OutboundHostURI}/simpleTransfers`;
|
|
46
|
+
const transferId = uuid();
|
|
47
|
+
try {
|
|
48
|
+
await axios({
|
|
49
|
+
method: 'POST',
|
|
50
|
+
url: postTransfersURI,
|
|
51
|
+
data: {
|
|
52
|
+
fspId: 'timeout-fsp-id-transfer',
|
|
53
|
+
transfersPostRequest: {
|
|
54
|
+
...transfersPostRequest,
|
|
55
|
+
transferId
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
headers: {
|
|
59
|
+
'access-control-allow-origin': '*'
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
} catch (err) {
|
|
63
|
+
expect(err.response.status).toEqual(500);
|
|
64
|
+
expect(err.response.data.message).toEqual('Timeout');
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
});
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/*****
|
|
2
|
+
License
|
|
3
|
+
--------------
|
|
4
|
+
Copyright © 2017 Bill & Melinda Gates Foundation
|
|
5
|
+
The Mojaloop files are made available by the Bill & Melinda Gates Foundation under the Apache License, Version 2.0 (the 'License') and you may not use these files except in compliance with the License. You may obtain a copy of the License at
|
|
6
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
Unless required by applicable law or agreed to in writing, the Mojaloop files are distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
|
8
|
+
|
|
9
|
+
Initial contribution
|
|
10
|
+
--------------------
|
|
11
|
+
The initial functionality and code base was donated by the Mowali project working in conjunction with MTN and Orange as service provides.
|
|
12
|
+
* Project: Mowali
|
|
13
|
+
|
|
14
|
+
Contributors
|
|
15
|
+
--------------
|
|
16
|
+
This is the official list of the Mojaloop project contributors for this file.
|
|
17
|
+
Names of the original copyright holders (individuals or organizations)
|
|
18
|
+
should be listed with a '*' in the first column. People who have
|
|
19
|
+
contributed from an organization can be listed under the organization
|
|
20
|
+
that actually holds the copyright for their contributions (see the
|
|
21
|
+
Gates Foundation organization for an example). Those individuals should have
|
|
22
|
+
their names indented and be marked with a '-'. Email address can be added
|
|
23
|
+
optionally within square brackets <email>.
|
|
24
|
+
* Gates Foundation
|
|
25
|
+
- Name Surname <name.surname@gatesfoundation.com>
|
|
26
|
+
|
|
27
|
+
* Crosslake
|
|
28
|
+
- Lewis Daly <lewisd@crosslaketech.com>
|
|
29
|
+
--------------
|
|
30
|
+
******/
|
|
31
|
+
'use strict';
|
|
32
|
+
|
|
33
|
+
jest.dontMock('redis');
|
|
34
|
+
|
|
35
|
+
const Cache = require('../../../lib/cache');
|
|
36
|
+
const { Logger } = require('@mojaloop/sdk-standard-components');
|
|
37
|
+
const env = require('../testEnv');
|
|
38
|
+
|
|
39
|
+
const defaultCacheConfig = {
|
|
40
|
+
host: env.redis.host,
|
|
41
|
+
port: env.redis.port,
|
|
42
|
+
logger: null
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const createCache = async (config) => {
|
|
46
|
+
config.logger = new Logger.Logger({
|
|
47
|
+
context: {
|
|
48
|
+
app: 'mojaloop-sdk-inboundCache'
|
|
49
|
+
},
|
|
50
|
+
stringify: Logger.buildStringify({ space: 4 }),
|
|
51
|
+
});
|
|
52
|
+
const cache = new Cache(config);
|
|
53
|
+
await cache.connect();
|
|
54
|
+
|
|
55
|
+
return cache;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
describe('Cache', () => {
|
|
59
|
+
let cache;
|
|
60
|
+
|
|
61
|
+
beforeEach(async () => {
|
|
62
|
+
cache = await createCache(defaultCacheConfig);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
afterEach(async () => {
|
|
66
|
+
await cache.disconnect();
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test('Sets and retrieves an object in the cache', async () => {
|
|
70
|
+
// Arrange
|
|
71
|
+
const value = {test: true};
|
|
72
|
+
|
|
73
|
+
// Act
|
|
74
|
+
await cache.set('keyA', JSON.stringify(value));
|
|
75
|
+
const result = await cache.get('keyA');
|
|
76
|
+
|
|
77
|
+
// Assert
|
|
78
|
+
expect(result).toStrictEqual(value);
|
|
79
|
+
});
|
|
80
|
+
});
|
|
@@ -0,0 +1,443 @@
|
|
|
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({ ...serverConfig.cacheConfig, 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.0')
|
|
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({ ...serverConfig.cacheConfig, 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.0', 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.0',
|
|
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({ ...serverConfig.cacheConfig, 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.0')
|
|
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({ ...serverConfig.cacheConfig, 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.0', 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.0',
|
|
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({ ...serverConfig.cacheConfig, 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.0')
|
|
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({ ...serverConfig.cacheConfig, 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.0', 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.0',
|
|
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.mutualTLS.inboundRequests.enabled = enableTls;
|
|
338
|
+
const logger = new Logger.Logger({ stringify: () => '' });
|
|
339
|
+
const cache = new Cache({ ...defConfig.cacheConfig, 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({ ...serverConfig.cacheConfig, 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.rmdirSync(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
|
+
});
|