@mojaloop/sdk-scheme-adapter 12.0.0 → 12.1.0
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/.circleci/config.yml +619 -0
- package/.env.example +13 -0
- package/.nvmrc +1 -1
- package/.versionrc +1 -0
- package/CHANGELOG.md +28 -2
- package/CODEOWNERS +2 -0
- package/Dockerfile +35 -0
- package/LICENSE.md +10 -0
- package/PROXY.md +84 -0
- package/README.md +228 -0
- package/SECURITY.md +18 -0
- package/audit-resolve.json +45 -0
- package/docker/ml-testing-toolkit/secrets/keygen.sh +5 -0
- package/docker/ml-testing-toolkit/secrets/privatekey.pem +27 -0
- package/docker/ml-testing-toolkit/secrets/publickey.cer +21 -0
- package/docker/ml-testing-toolkit/secrets/tls/createSecrets.sh +29 -0
- package/docker/ml-testing-toolkit/secrets/tls/hub_client.csr +28 -0
- package/docker/ml-testing-toolkit/secrets/tls/hub_client_cacert.pem +32 -0
- package/docker/ml-testing-toolkit/secrets/tls/hub_client_cakey.key +51 -0
- package/docker/ml-testing-toolkit/secrets/tls/hub_client_key.key +51 -0
- package/docker/ml-testing-toolkit/secrets/tls/hub_server.csr +28 -0
- package/docker/ml-testing-toolkit/secrets/tls/hub_server_cacert.pem +32 -0
- package/docker/ml-testing-toolkit/secrets/tls/hub_server_cacert.srl +1 -0
- package/docker/ml-testing-toolkit/secrets/tls/hub_server_cakey.key +51 -0
- package/docker/ml-testing-toolkit/secrets/tls/hub_server_cert.pem +33 -0
- package/docker/ml-testing-toolkit/secrets/tls/hub_server_key.key +51 -0
- package/docker/ml-testing-toolkit/secrets/tls/openssl.conf +17 -0
- package/docker/ml-testing-toolkit/spec_files/api_definitions/central_admin_9.3/api_spec.yaml +2450 -0
- package/docker/ml-testing-toolkit/spec_files/api_definitions/central_admin_9.3/response_map.json +96 -0
- package/docker/ml-testing-toolkit/spec_files/api_definitions/fspiop_1.0/api_spec.yaml +4187 -0
- package/docker/ml-testing-toolkit/spec_files/api_definitions/fspiop_1.0/callback_map.json +542 -0
- package/docker/ml-testing-toolkit/spec_files/api_definitions/fspiop_1.0/mockRef.json +83 -0
- package/docker/ml-testing-toolkit/spec_files/api_definitions/fspiop_1.0/trigger_templates/transaction_request_followup.json +125 -0
- package/docker/ml-testing-toolkit/spec_files/api_definitions/fspiop_1.1/api_spec.yaml +3703 -0
- package/docker/ml-testing-toolkit/spec_files/api_definitions/fspiop_1.1/callback_map.json +568 -0
- package/docker/ml-testing-toolkit/spec_files/api_definitions/fspiop_1.1/mockRef.json +83 -0
- package/docker/ml-testing-toolkit/spec_files/api_definitions/fspiop_1.1/trigger_templates/transaction_request_followup.json +125 -0
- package/docker/ml-testing-toolkit/spec_files/api_definitions/settlements_1.0/api_spec.yaml +983 -0
- package/docker/ml-testing-toolkit/spec_files/api_definitions/settlements_1.0/mockRef.json +38 -0
- package/docker/ml-testing-toolkit/spec_files/api_definitions/settlements_1.0/response_map.json +34 -0
- package/docker/ml-testing-toolkit/spec_files/reports/templates/newman/html_template.html +1074 -0
- package/docker/ml-testing-toolkit/spec_files/reports/templates/newman/pdf_template.html +765 -0
- package/docker/ml-testing-toolkit/spec_files/reports/templates/newman/script.js +98 -0
- package/docker/ml-testing-toolkit/spec_files/rules_callback/config.json +3 -0
- package/docker/ml-testing-toolkit/spec_files/rules_callback/default.json +426 -0
- package/docker/ml-testing-toolkit/spec_files/rules_response/config.json +3 -0
- package/docker/ml-testing-toolkit/spec_files/rules_response/default.json +1623 -0
- package/docker/ml-testing-toolkit/spec_files/rules_response/default_pisp_rules.json +161 -0
- package/docker/ml-testing-toolkit/spec_files/rules_validation/config.json +3 -0
- package/docker/ml-testing-toolkit/spec_files/rules_validation/default.json +672 -0
- package/docker/ml-testing-toolkit/spec_files/system_config.json +62 -0
- package/docker/ml-testing-toolkit/spec_files/user_config.json +45 -0
- package/docker/wait4/setup_hosts_file.sh +25 -0
- package/docker/wait4/wait4.config.js +71 -0
- package/docker/wait4/wait4.js +204 -0
- package/docker-compose.yml +67 -0
- package/docs/Mojaloop - Modusbox Onboarding functionality.pdf +0 -0
- package/docs/dfspInboundApi.yaml +1091 -0
- package/jest.config.js +4 -1
- package/package.json +17 -17
- package/secrets/jwsSigningKey.key +27 -0
- package/secrets/jwsVerificationKeys/mojaloop-sdk.pem +9 -0
- package/secrets/jwsVerificationKeys/switch.pem +9 -0
- package/sequences.puml +99 -0
- package/src/ControlAgent/index.js +221 -0
- package/{TestServer → src/ControlServer}/handlers.js +0 -0
- package/src/ControlServer/index.js +294 -0
- package/{InboundServer → src/InboundServer}/api.yaml +0 -0
- package/src/InboundServer/api_template.yaml +69 -0
- package/{InboundServer → src/InboundServer}/handlers.js +0 -0
- package/{InboundServer → src/InboundServer}/index.js +33 -1
- package/{InboundServer → src/InboundServer}/middlewares.js +0 -0
- package/src/OAuthTestServer/index.js +127 -0
- package/{OAuthTestServer → src/OAuthTestServer}/model.js +0 -0
- package/{OutboundServer → src/OutboundServer}/api.yaml +0 -0
- package/{OutboundServer → src/OutboundServer}/api_interfaces/index.d.ts +0 -0
- package/{OutboundServer → src/OutboundServer}/api_interfaces/openapi.d.ts +0 -0
- package/{OutboundServer → src/OutboundServer}/api_template/components/parameters/bulkQuoteId.yaml +1 -1
- package/{OutboundServer → src/OutboundServer}/api_template/components/parameters/bulkTransferId.yaml +1 -1
- package/{OutboundServer → src/OutboundServer}/api_template/components/parameters/requestToPayTransactionId.yaml +1 -1
- package/{OutboundServer → src/OutboundServer}/api_template/components/parameters/transferId.yaml +1 -1
- package/{OutboundServer → src/OutboundServer}/api_template/components/responses/accountsCreationCompleted.yaml +0 -0
- package/{OutboundServer → src/OutboundServer}/api_template/components/responses/accountsCreationError.yaml +0 -0
- package/{OutboundServer → src/OutboundServer}/api_template/components/responses/accountsCreationTimeout.yaml +0 -0
- package/{OutboundServer → src/OutboundServer}/api_template/components/responses/bulkQuoteBadRequest.yaml +0 -0
- package/{OutboundServer → src/OutboundServer}/api_template/components/responses/bulkQuoteServerError.yaml +0 -0
- package/{OutboundServer → src/OutboundServer}/api_template/components/responses/bulkQuoteSuccess.yaml +0 -0
- package/{OutboundServer → src/OutboundServer}/api_template/components/responses/bulkQuoteTimeout.yaml +0 -0
- package/{OutboundServer → src/OutboundServer}/api_template/components/responses/bulkTransferBadRequest.yaml +0 -0
- package/{OutboundServer → src/OutboundServer}/api_template/components/responses/bulkTransferServerError.yaml +0 -0
- package/{OutboundServer → src/OutboundServer}/api_template/components/responses/bulkTransferSuccess.yaml +0 -0
- package/{OutboundServer → src/OutboundServer}/api_template/components/responses/bulkTransferTimeout.yaml +0 -0
- package/{OutboundServer → src/OutboundServer}/api_template/components/responses/partiesByIdError404.yaml +1 -1
- package/{OutboundServer → src/OutboundServer}/api_template/components/responses/partiesByIdSuccess.yaml +0 -0
- package/{OutboundServer → src/OutboundServer}/api_template/components/responses/quotesPostSuccess.yaml +0 -0
- package/{OutboundServer → src/OutboundServer}/api_template/components/responses/quotesServerError.yaml +0 -0
- package/{OutboundServer → src/OutboundServer}/api_template/components/responses/requestToPaySuccess.yaml +0 -0
- package/{OutboundServer → src/OutboundServer}/api_template/components/responses/requestToPayTransferBadRequest.yaml +0 -0
- package/{OutboundServer → src/OutboundServer}/api_template/components/responses/requestToPayTransferSuccess.yaml +0 -0
- package/{OutboundServer → src/OutboundServer}/api_template/components/responses/simpleTransfersPostSuccess.yaml +0 -0
- package/{OutboundServer → src/OutboundServer}/api_template/components/responses/simpleTransfersServerError.yaml +0 -0
- package/{OutboundServer → src/OutboundServer}/api_template/components/responses/transferBadRequest.yaml +0 -0
- package/{OutboundServer → src/OutboundServer}/api_template/components/responses/transferServerError.yaml +0 -0
- package/{OutboundServer → src/OutboundServer}/api_template/components/responses/transferSuccess.yaml +0 -0
- package/{OutboundServer → src/OutboundServer}/api_template/components/responses/transferTimeout.yaml +0 -0
- package/src/OutboundServer/api_template/components/schemas/accountCreationStatus.yaml +18 -0
- package/{OutboundServer → src/OutboundServer}/api_template/components/schemas/accountsCreationState.yaml +0 -0
- package/src/OutboundServer/api_template/components/schemas/accountsRequest.yaml +20 -0
- package/{OutboundServer → src/OutboundServer}/api_template/components/schemas/accountsResponse.yaml +1 -1
- package/{OutboundServer → src/OutboundServer}/api_template/components/schemas/async2SyncCurrentState.yaml +0 -0
- package/{OutboundServer → src/OutboundServer}/api_template/components/schemas/bulkQuoteErrorResponse.yaml +0 -0
- package/{OutboundServer → src/OutboundServer}/api_template/components/schemas/bulkQuoteRequest.yaml +2 -2
- package/{OutboundServer → src/OutboundServer}/api_template/components/schemas/bulkQuoteResponse.yaml +1 -1
- package/{OutboundServer → src/OutboundServer}/api_template/components/schemas/bulkQuoteStatus.yaml +0 -0
- package/{OutboundServer → src/OutboundServer}/api_template/components/schemas/bulkQuoteStatusResponse.yaml +1 -1
- package/{OutboundServer → src/OutboundServer}/api_template/components/schemas/bulkTransferErrorResponse.yaml +0 -0
- package/{OutboundServer → src/OutboundServer}/api_template/components/schemas/bulkTransferRequest.yaml +2 -2
- package/{OutboundServer → src/OutboundServer}/api_template/components/schemas/bulkTransferResponse.yaml +1 -1
- package/{OutboundServer → src/OutboundServer}/api_template/components/schemas/bulkTransferStatus.yaml +0 -0
- package/{OutboundServer → src/OutboundServer}/api_template/components/schemas/bulkTransferStatusResponse.yaml +1 -1
- package/{OutboundServer → src/OutboundServer}/api_template/components/schemas/errorAccountsResponse.yaml +0 -0
- package/{OutboundServer → src/OutboundServer}/api_template/components/schemas/errorQuotesResponse.yaml +0 -0
- package/{OutboundServer → src/OutboundServer}/api_template/components/schemas/errorResponse.yaml +0 -0
- package/{OutboundServer → src/OutboundServer}/api_template/components/schemas/errorSimpleTransfersResponse.yaml +0 -0
- package/{OutboundServer → src/OutboundServer}/api_template/components/schemas/errorTransferResponse.yaml +0 -0
- package/src/OutboundServer/api_template/components/schemas/extensionListEmptiable.yaml +6 -0
- package/src/OutboundServer/api_template/components/schemas/individualQuote.yaml +32 -0
- package/{OutboundServer → src/OutboundServer}/api_template/components/schemas/individualQuoteResult.yaml +5 -5
- package/src/OutboundServer/api_template/components/schemas/individualTransfer.yaml +32 -0
- package/{OutboundServer → src/OutboundServer}/api_template/components/schemas/individualTransferFulfilment.yaml +2 -2
- package/{OutboundServer → src/OutboundServer}/api_template/components/schemas/individualTransferResult.yaml +6 -6
- package/src/OutboundServer/api_template/components/schemas/mojaloopError.yaml +5 -0
- package/src/OutboundServer/api_template/components/schemas/mojaloopTransactionRequestState.yaml +2 -0
- package/{OutboundServer → src/OutboundServer}/api_template/components/schemas/partiesByIdResponse.yaml +1 -1
- package/src/OutboundServer/api_template/components/schemas/quote.yaml +3 -0
- package/{OutboundServer → src/OutboundServer}/api_template/components/schemas/quoteError.yaml +0 -0
- package/src/OutboundServer/api_template/components/schemas/quotesPostRequest.yaml +13 -0
- package/src/OutboundServer/api_template/components/schemas/quotesPostResponse.yaml +48 -0
- package/src/OutboundServer/api_template/components/schemas/requestToPayRequest.yaml +39 -0
- package/src/OutboundServer/api_template/components/schemas/requestToPayResponse.yaml +41 -0
- package/src/OutboundServer/api_template/components/schemas/requestToPayTransferRequest.yaml +42 -0
- package/{OutboundServer → src/OutboundServer}/api_template/components/schemas/requestToPayTransferResponse.yaml +6 -6
- package/{OutboundServer → src/OutboundServer}/api_template/components/schemas/simpleTransferServerError.yaml +0 -0
- package/src/OutboundServer/api_template/components/schemas/simpleTransfersPostRequest.yaml +12 -0
- package/{OutboundServer → src/OutboundServer}/api_template/components/schemas/simpleTransfersPostResponse.yaml +1 -1
- package/{OutboundServer → src/OutboundServer}/api_template/components/schemas/transactionType.yaml +0 -0
- package/{OutboundServer → src/OutboundServer}/api_template/components/schemas/transferContinuationAcceptOTP.yaml +0 -0
- package/{OutboundServer → src/OutboundServer}/api_template/components/schemas/transferContinuationAcceptParty.yaml +0 -0
- package/{OutboundServer → src/OutboundServer}/api_template/components/schemas/transferContinuationAcceptQuote.yaml +0 -0
- package/{OutboundServer → src/OutboundServer}/api_template/components/schemas/transferError.yaml +0 -0
- package/src/OutboundServer/api_template/components/schemas/transferFulfilment.yaml +3 -0
- package/src/OutboundServer/api_template/components/schemas/transferParty.yaml +40 -0
- package/{OutboundServer → src/OutboundServer}/api_template/components/schemas/transferRequest.yaml +4 -4
- package/{OutboundServer → src/OutboundServer}/api_template/components/schemas/transferResponse.yaml +6 -6
- package/{OutboundServer → src/OutboundServer}/api_template/components/schemas/transferStatus.yaml +0 -0
- package/{OutboundServer → src/OutboundServer}/api_template/components/schemas/transferStatusResponse.yaml +1 -1
- package/{OutboundServer → src/OutboundServer}/api_template/health.yaml +0 -0
- package/{OutboundServer → src/OutboundServer}/api_template/openapi.yaml +0 -0
- package/{OutboundServer → src/OutboundServer}/api_template/paths/accounts.yaml +0 -0
- package/{OutboundServer → src/OutboundServer}/api_template/paths/bulkQuotes.yaml +0 -0
- package/{OutboundServer → src/OutboundServer}/api_template/paths/bulkQuotes_bulkQuoteId.yaml +0 -0
- package/{OutboundServer → src/OutboundServer}/api_template/paths/bulkTransfers.yaml +0 -0
- package/{OutboundServer → src/OutboundServer}/api_template/paths/bulkTransfers_bulkTransferId.yaml +0 -0
- package/{OutboundServer → src/OutboundServer}/api_template/paths/parties_Type_ID.yaml +2 -2
- package/{OutboundServer → src/OutboundServer}/api_template/paths/parties_Type_ID_SubId.yaml +3 -3
- package/{OutboundServer → src/OutboundServer}/api_template/paths/quotes.yaml +0 -0
- package/{OutboundServer → src/OutboundServer}/api_template/paths/requestToPay.yaml +0 -0
- package/{OutboundServer → src/OutboundServer}/api_template/paths/requestToPayTransfer.yaml +0 -0
- package/{OutboundServer → src/OutboundServer}/api_template/paths/requestToPayTransfer_requestToPayTransactionId.yaml +0 -0
- package/{OutboundServer → src/OutboundServer}/api_template/paths/simpleTransfers.yaml +0 -0
- package/{OutboundServer → src/OutboundServer}/api_template/paths/transfers.yaml +0 -0
- package/{OutboundServer → src/OutboundServer}/api_template/paths/transfers_transferId.yaml +0 -0
- package/{OutboundServer → src/OutboundServer}/handlers.js +0 -0
- package/{OutboundServer → src/OutboundServer}/index.js +15 -0
- package/{OutboundServer → src/OutboundServer}/middlewares.js +0 -0
- package/{TestServer → src/TestServer}/api.yaml +0 -0
- package/src/TestServer/handlers.js +63 -0
- package/{TestServer → src/TestServer}/index.js +31 -0
- package/{config.js → src/config.js} +6 -0
- package/{index.d.ts → src/index.d.ts} +0 -0
- package/{index.js → src/index.js} +0 -0
- package/{lib → src/lib}/api/index.js +0 -0
- package/{lib → src/lib}/cache.js +0 -0
- package/{lib → src/lib}/check.js +0 -0
- package/{lib → src/lib}/model/AccountsModel.js +0 -0
- package/{lib → src/lib}/model/Async2SyncModel.js +0 -0
- package/{lib → src/lib}/model/InboundTransfersModel.js +0 -0
- package/{lib → src/lib}/model/OutboundBulkQuotesModel.js +0 -0
- package/{lib → src/lib}/model/OutboundBulkTransfersModel.js +0 -0
- package/{lib → src/lib}/model/OutboundRequestToPayModel.js +0 -0
- package/{lib → src/lib}/model/OutboundRequestToPayTransferModel.js +0 -0
- package/{lib → src/lib}/model/OutboundTransfersModel.js +0 -0
- package/{lib → src/lib}/model/PartiesModel.js +0 -0
- package/{lib → src/lib}/model/ProxyModel/MatchRules/Expression.js +0 -0
- package/{lib → src/lib}/model/ProxyModel/MatchRules/Headers.js +0 -0
- package/{lib → src/lib}/model/ProxyModel/MatchRules/MatchRule.js +0 -0
- package/{lib → src/lib}/model/ProxyModel/MatchRules/Path.js +0 -0
- package/{lib → src/lib}/model/ProxyModel/MatchRules/Query.js +0 -0
- package/{lib → src/lib}/model/ProxyModel/MatchRules/index.js +0 -0
- package/{lib → src/lib}/model/ProxyModel/Route.js +0 -0
- package/{lib → src/lib}/model/ProxyModel/configSchema.json +0 -0
- package/{lib → src/lib}/model/ProxyModel/index.js +0 -0
- package/{lib → src/lib}/model/QuotesModel.js +0 -0
- package/{lib → src/lib}/model/TransfersModel.js +0 -0
- package/{lib → src/lib}/model/common/BackendError.js +0 -0
- package/{lib → src/lib}/model/common/PersistentStateMachine.js +0 -0
- package/{lib → src/lib}/model/common/index.js +0 -0
- package/{lib → src/lib}/model/index.js +0 -0
- package/{lib → src/lib}/model/lib/deferredJob.js +0 -0
- package/{lib → src/lib}/model/lib/index.js +0 -0
- package/{lib → src/lib}/model/lib/requests/backendRequests.js +0 -0
- package/{lib → src/lib}/model/lib/requests/common.js +0 -0
- package/{lib → src/lib}/model/lib/requests/index.js +0 -0
- package/{lib → src/lib}/model/lib/shared.js +0 -0
- package/{lib → src/lib}/randomphrase/index.js +0 -0
- package/{lib → src/lib}/randomphrase/words.json +0 -0
- package/{lib → src/lib}/router.js +0 -0
- package/{lib → src/lib}/validate.js +0 -0
- package/test/config/integration.env +9 -0
- package/test/integration/lib/cache.test.js +3 -3
- package/test/unit/ControlClient.test.js +113 -0
- package/test/unit/ControlServer/events.js +41 -0
- package/test/unit/ControlServer/index.js +231 -0
- package/test/unit/ControlServer.test.js +126 -0
- package/test/unit/InboundServer.test.js +5 -5
- package/test/unit/TestServer.test.js +5 -5
- package/test/unit/api/utils.js +5 -5
- package/test/unit/config.test.js +11 -10
- package/test/unit/inboundApi/handlers.test.js +6 -6
- package/test/unit/index.test.js +2 -1
- package/test/unit/lib/cache.test.js +1 -1
- package/test/unit/lib/model/AccountsModel.test.js +2 -2
- package/test/unit/lib/model/InboundTransfersModel.test.js +5 -5
- package/test/unit/lib/model/OutboundBulkQuotesModel.test.js +2 -2
- package/test/unit/lib/model/OutboundBulkTransfersModel.test.js +2 -2
- package/test/unit/lib/model/OutboundRequestToPayModel.test.js +3 -3
- package/test/unit/lib/model/OutboundRequestToPayTransferModel.test.js +2 -2
- package/test/unit/lib/model/OutboundTransfersModel.test.js +3 -3
- package/test/unit/lib/model/PartiesModel.test.js +28 -28
- package/test/unit/lib/model/QuotesModel.test.js +31 -31
- package/test/unit/lib/model/TransfersModel.test.js +3 -3
- package/test/unit/lib/model/common/PersistentStateMachine.test.js +13 -13
- package/test/unit/lib/model/mockedLibRequests.js +1 -1
- package/test/unit/outboundApi/handlers.test.js +3 -3
- package/.eslintignore +0 -2
- package/InboundServer/api_template.yaml +0 -69
- package/OAuthTestServer/index.js +0 -66
- package/OutboundServer/api_template/components/schemas/accountCreationStatus.yaml +0 -18
- package/OutboundServer/api_template/components/schemas/accountsRequest.yaml +0 -20
- package/OutboundServer/api_template/components/schemas/extensionListEmptiable.yaml +0 -6
- package/OutboundServer/api_template/components/schemas/individualQuote.yaml +0 -32
- package/OutboundServer/api_template/components/schemas/individualTransfer.yaml +0 -32
- package/OutboundServer/api_template/components/schemas/mojaloopError.yaml +0 -5
- package/OutboundServer/api_template/components/schemas/mojaloopTransactionRequestState.yaml +0 -2
- package/OutboundServer/api_template/components/schemas/quote.yaml +0 -3
- package/OutboundServer/api_template/components/schemas/quotesPostRequest.yaml +0 -13
- package/OutboundServer/api_template/components/schemas/quotesPostResponse.yaml +0 -48
- package/OutboundServer/api_template/components/schemas/requestToPayRequest.yaml +0 -39
- package/OutboundServer/api_template/components/schemas/requestToPayResponse.yaml +0 -41
- package/OutboundServer/api_template/components/schemas/requestToPayTransferRequest.yaml +0 -42
- package/OutboundServer/api_template/components/schemas/simpleTransfersPostRequest.yaml +0 -12
- package/OutboundServer/api_template/components/schemas/transferFulfilment.yaml +0 -3
- package/OutboundServer/api_template/components/schemas/transferParty.yaml +0 -40
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
/**************************************************************************
|
|
2
|
+
* (C) Copyright ModusBox Inc. 2020 - 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
|
+
* Matt Kingston - matt.kingston@modusbox.com *
|
|
9
|
+
**************************************************************************/
|
|
10
|
+
'use strict';
|
|
11
|
+
|
|
12
|
+
const ws = require('ws');
|
|
13
|
+
const jsonPatch = require('fast-json-patch');
|
|
14
|
+
const randomPhrase = require('~/lib/randomphrase');
|
|
15
|
+
const { getInternalEventEmitter, INTERNAL_EVENTS } = require('./events');
|
|
16
|
+
|
|
17
|
+
const ControlServerEventEmitter = getInternalEventEmitter();
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
/**************************************************************************
|
|
21
|
+
* The message protocol messages, verbs, and errors
|
|
22
|
+
*************************************************************************/
|
|
23
|
+
const MESSAGE = {
|
|
24
|
+
CONFIGURATION: 'CONFIGURATION',
|
|
25
|
+
ERROR: 'ERROR',
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const VERB = {
|
|
29
|
+
READ: 'READ',
|
|
30
|
+
NOTIFY: 'NOTIFY',
|
|
31
|
+
PATCH: 'PATCH'
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const ERROR = {
|
|
35
|
+
UNSUPPORTED_MESSAGE: 'UNSUPPORTED_MESSAGE',
|
|
36
|
+
UNSUPPORTED_VERB: 'UNSUPPORTED_VERB',
|
|
37
|
+
JSON_PARSE_ERROR: 'JSON_PARSE_ERROR',
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/**************************************************************************
|
|
41
|
+
* Private convenience functions
|
|
42
|
+
*************************************************************************/
|
|
43
|
+
const serialise = JSON.stringify;
|
|
44
|
+
const deserialise = (msg) => {
|
|
45
|
+
//reviver function
|
|
46
|
+
return JSON.parse(msg.toString(), (k, v) => {
|
|
47
|
+
if (
|
|
48
|
+
v !== null &&
|
|
49
|
+
typeof v === 'object' &&
|
|
50
|
+
'type' in v &&
|
|
51
|
+
v.type === 'Buffer' &&
|
|
52
|
+
'data' in v &&
|
|
53
|
+
Array.isArray(v.data)) {
|
|
54
|
+
return new Buffer(v.data);
|
|
55
|
+
}
|
|
56
|
+
return v;
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
const buildMsg = (verb, msg, data, id = randomPhrase()) => serialise({
|
|
62
|
+
verb,
|
|
63
|
+
msg,
|
|
64
|
+
data,
|
|
65
|
+
id,
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
const buildPatchConfiguration = (oldConf, newConf, id) => {
|
|
69
|
+
const patches = jsonPatch.compare(oldConf, newConf);
|
|
70
|
+
return buildMsg(VERB.PATCH, MESSAGE.CONFIGURATION, patches, id);
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
/**************************************************************************
|
|
74
|
+
* build
|
|
75
|
+
*
|
|
76
|
+
* Public object exposing an API to build valid protocol messages.
|
|
77
|
+
* It is not the only way to build valid messages within the protocol.
|
|
78
|
+
*************************************************************************/
|
|
79
|
+
const build = {
|
|
80
|
+
CONFIGURATION: {
|
|
81
|
+
PATCH: buildPatchConfiguration,
|
|
82
|
+
READ: (id) => buildMsg(VERB.READ, MESSAGE.CONFIGURATION, {}, id),
|
|
83
|
+
NOTIFY: (config, id) => buildMsg(VERB.NOTIFY, MESSAGE.CONFIGURATION, config, id),
|
|
84
|
+
},
|
|
85
|
+
ERROR: {
|
|
86
|
+
NOTIFY: {
|
|
87
|
+
UNSUPPORTED_MESSAGE: (id) => buildMsg(VERB.NOTIFY, MESSAGE.ERROR, ERROR.UNSUPPORTED_MESSAGE, id),
|
|
88
|
+
UNSUPPORTED_VERB: (id) => buildMsg(VERB.NOTIFY, MESSAGE.ERROR, ERROR.UNSUPPORTED_VERB, id),
|
|
89
|
+
JSON_PARSE_ERROR: (id) => buildMsg(VERB.NOTIFY, MESSAGE.ERROR, ERROR.JSON_PARSE_ERROR, id),
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
/**************************************************************************
|
|
95
|
+
* Server
|
|
96
|
+
*
|
|
97
|
+
* The Control Server. Exposes a websocket control API.
|
|
98
|
+
* Used to hot-restart the SDK.
|
|
99
|
+
*
|
|
100
|
+
* logger - Logger- see SDK logger used elsewhere
|
|
101
|
+
* port - HTTP port to host on
|
|
102
|
+
* appConfig - The configuration for the entire application- supplied here as this class uses it to
|
|
103
|
+
* validate reconfiguration requests- it is not used for configuration here, however
|
|
104
|
+
* server - optional HTTP/S server on which to serve the websocket
|
|
105
|
+
*************************************************************************/
|
|
106
|
+
class Server extends ws.Server {
|
|
107
|
+
constructor({ logger, appConfig = {} }) {
|
|
108
|
+
super({ clientTracking: true, port: appConfig.control.port });
|
|
109
|
+
|
|
110
|
+
this._logger = logger;
|
|
111
|
+
this._port = appConfig.control.port;
|
|
112
|
+
this._appConfig = appConfig;
|
|
113
|
+
this._clientData = new Map();
|
|
114
|
+
|
|
115
|
+
this.on('error', err => {
|
|
116
|
+
this._logger.push({ err })
|
|
117
|
+
.log('Unhandled websocket error occurred. Shutting down.');
|
|
118
|
+
process.exit(1);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
this.on('connection', (socket, req) => {
|
|
122
|
+
const logger = this._logger.push({
|
|
123
|
+
url: req.url,
|
|
124
|
+
ip: 'localhost',
|
|
125
|
+
remoteAddress: req.socket.remoteAddress,
|
|
126
|
+
});
|
|
127
|
+
logger.log('Websocket connection received');
|
|
128
|
+
this._clientData.set(socket, { ip: req.connection.remoteAddress, logger });
|
|
129
|
+
|
|
130
|
+
socket.on('close', (code, reason) => {
|
|
131
|
+
logger.push({ code, reason }).log('Websocket connection closed');
|
|
132
|
+
this._clientData.delete(socket);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
socket.on('message', this._handle(socket, logger));
|
|
136
|
+
});
|
|
137
|
+
this._logger.push(this.address()).log('running on');
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// Close the server then wait for all the client sockets to close
|
|
141
|
+
async stop() {
|
|
142
|
+
await new Promise(this.close.bind(this));
|
|
143
|
+
this._logger.log('Control server shutdown complete');
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
_handle(client, logger) {
|
|
147
|
+
return (data) => {
|
|
148
|
+
// TODO: json-schema validation of received message- should be pretty straight-forward
|
|
149
|
+
// and will allow better documentation of the API
|
|
150
|
+
let msg;
|
|
151
|
+
try {
|
|
152
|
+
msg = deserialise(data);
|
|
153
|
+
} catch (err) {
|
|
154
|
+
logger.push({ data }).log('Couldn\'t parse received message');
|
|
155
|
+
client.send(build.ERROR.NOTIFY.JSON_PARSE_ERROR());
|
|
156
|
+
}
|
|
157
|
+
logger.push({ msg }).log('Handling received message');
|
|
158
|
+
switch (msg.msg) {
|
|
159
|
+
case MESSAGE.CONFIGURATION:
|
|
160
|
+
switch (msg.verb) {
|
|
161
|
+
case VERB.READ:
|
|
162
|
+
(async () => {
|
|
163
|
+
const jwsCerts = await this.populateConfig();
|
|
164
|
+
client.send(build.CONFIGURATION.NOTIFY(jwsCerts, msg.id));
|
|
165
|
+
})();
|
|
166
|
+
break;
|
|
167
|
+
default:
|
|
168
|
+
client.send(build.ERROR.NOTIFY.UNSUPPORTED_VERB(msg.id));
|
|
169
|
+
break;
|
|
170
|
+
}
|
|
171
|
+
break;
|
|
172
|
+
default:
|
|
173
|
+
client.send(build.ERROR.NOTIFY.UNSUPPORTED_MESSAGE(msg.id));
|
|
174
|
+
break;
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
async populateConfig(){
|
|
180
|
+
return this._appConfig;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Register this server instance to receive internal server messages
|
|
186
|
+
* from other modules.
|
|
187
|
+
*/
|
|
188
|
+
registerInternalEvents() {
|
|
189
|
+
ControlServerEventEmitter.on(INTERNAL_EVENTS.SERVER.BROADCAST_CONFIG_CHANGE, (params) => {
|
|
190
|
+
this.broadcastConfigChange(params);
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Broadcast configuration change to all connected clients.
|
|
196
|
+
*
|
|
197
|
+
* @param {object} params Updated configuration
|
|
198
|
+
*/
|
|
199
|
+
async broadcastConfigChange(updatedConfig) {
|
|
200
|
+
const updateConfMsg = build.CONFIGURATION.PATCH({}, updatedConfig, randomPhrase());
|
|
201
|
+
const errorLogger = (socket, message) => (err) =>
|
|
202
|
+
this._logger
|
|
203
|
+
.push({ message, ip: this._clientData.get(socket).ip, err })
|
|
204
|
+
.log('Error sending JWS keys notification to client');
|
|
205
|
+
return await this.broadcast(updateConfMsg, errorLogger);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Broadcasts a protocol message to all connected clients.
|
|
210
|
+
*
|
|
211
|
+
* @param {string} msg
|
|
212
|
+
* @param {object} errorLogger
|
|
213
|
+
*/
|
|
214
|
+
async broadcast(msg, errorLogger) {
|
|
215
|
+
const sendToAllClients = (msg, errorLogger) => Promise.all(
|
|
216
|
+
[...this.clients.values()].map((socket) =>
|
|
217
|
+
(new Promise((resolve) => socket.send(msg, resolve))).catch(errorLogger(socket, msg))
|
|
218
|
+
)
|
|
219
|
+
);
|
|
220
|
+
return await sendToAllClients(msg, errorLogger);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
module.exports = {
|
|
226
|
+
Server,
|
|
227
|
+
build,
|
|
228
|
+
MESSAGE,
|
|
229
|
+
VERB,
|
|
230
|
+
ERROR,
|
|
231
|
+
};
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
|
|
2
|
+
const ControlServer = require('~/ControlServer');
|
|
3
|
+
const InboundServer = require('~/InboundServer');
|
|
4
|
+
const OutboundServer = require('~/OutboundServer');
|
|
5
|
+
const TestServer = require('~/TestServer');
|
|
6
|
+
const defaultConfig = require('./data/defaultConfig.json');
|
|
7
|
+
const { Logger } = require('@mojaloop/sdk-standard-components');
|
|
8
|
+
|
|
9
|
+
jest.mock('~/lib/cache');
|
|
10
|
+
const Cache = require('~/lib/cache');
|
|
11
|
+
|
|
12
|
+
// TODO:
|
|
13
|
+
// - diff against master to determine what else needs testing
|
|
14
|
+
// - especially look for assertions in the code
|
|
15
|
+
// - err.. grep the code for TODO
|
|
16
|
+
|
|
17
|
+
describe('ControlServer', () => {
|
|
18
|
+
it('exposes a valid message API', () => {
|
|
19
|
+
expect(Object.keys(ControlServer.build).sort()).toEqual(
|
|
20
|
+
Object.keys(ControlServer.MESSAGE).sort(),
|
|
21
|
+
'The API exposed by the builder object must contain as top-level keys all of the message types exposed in the MESSAGE constant. Check that ControlServer.MESSAGE has the same keys as ControlServer.build.'
|
|
22
|
+
);
|
|
23
|
+
Object.entries(ControlServer.build).forEach(([messageType, builders]) => {
|
|
24
|
+
expect(Object.keys(ControlServer.VERB)).toEqual(
|
|
25
|
+
expect.arrayContaining(Object.keys(builders)),
|
|
26
|
+
`For message type '${messageType}' every builder must correspond to a verb. Check that ControlServer.build.${messageType} has the same keys as ControlServer.VERB.`
|
|
27
|
+
);
|
|
28
|
+
});
|
|
29
|
+
expect(Object.keys(ControlServer.build.ERROR.NOTIFY).sort()).toEqual(
|
|
30
|
+
Object.keys(ControlServer.ERROR).sort(),
|
|
31
|
+
'ControlServer.ERROR.NOTIFY should contain the same keys as ControlServer.ERROR'
|
|
32
|
+
);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
describe('API', () => {
|
|
36
|
+
let server, logger, client;
|
|
37
|
+
const appConfig = { what: 'ever' };
|
|
38
|
+
const changedConfig = { ...appConfig, some: 'thing' };
|
|
39
|
+
|
|
40
|
+
beforeEach(async () => {
|
|
41
|
+
logger = new Logger.Logger({ stringify: () => '' });
|
|
42
|
+
server = new ControlServer.Server({ logger, appConfig });
|
|
43
|
+
client = await ControlServer.Client.Create({
|
|
44
|
+
address: 'localhost',
|
|
45
|
+
port: server.address().port,
|
|
46
|
+
logger
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
afterEach(async () => {
|
|
51
|
+
await server.stop();
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('supplies config when requested', async () => {
|
|
55
|
+
await client.send(ControlServer.build.CONFIGURATION.READ());
|
|
56
|
+
const response = await client.receive();
|
|
57
|
+
expect(response).toEqual({
|
|
58
|
+
...JSON.parse(ControlServer.build.CONFIGURATION.NOTIFY(appConfig, response.id)),
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('emits new config when received', async () => {
|
|
63
|
+
const newConfigEvent = new Promise(
|
|
64
|
+
(resolve) => server.on(ControlServer.EVENT.RECONFIGURE, resolve)
|
|
65
|
+
);
|
|
66
|
+
await client.send(ControlServer.build.CONFIGURATION.PATCH(appConfig, changedConfig));
|
|
67
|
+
const newConfEventData = await newConfigEvent;
|
|
68
|
+
expect(newConfEventData).toEqual(changedConfig);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('sends new config to clients when instructed', async () => {
|
|
72
|
+
const client2 = await ControlServer.Client.Create({
|
|
73
|
+
address: 'localhost',
|
|
74
|
+
port: server.address().port,
|
|
75
|
+
logger
|
|
76
|
+
});
|
|
77
|
+
const changedConfig = { ...appConfig, some: 'thing' };
|
|
78
|
+
await client.send(ControlServer.build.CONFIGURATION.PATCH(appConfig, changedConfig));
|
|
79
|
+
const restart = server.reconfigure({ appConfig: changedConfig });
|
|
80
|
+
restart();
|
|
81
|
+
await server.notifyClientsOfCurrentConfig();
|
|
82
|
+
const [notification, notification2] =
|
|
83
|
+
await Promise.all([client.receive(), client2.receive()]);
|
|
84
|
+
const expected = ControlServer.build.CONFIGURATION.NOTIFY(changedConfig, notification.id);
|
|
85
|
+
expect(JSON.stringify(notification)).toEqual(expected);
|
|
86
|
+
expect(JSON.stringify(notification2)).toEqual(expected);
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
describe('Server reconfigure methods', () => {
|
|
92
|
+
let conf, logger, cache;
|
|
93
|
+
|
|
94
|
+
const isPromise = (o) => Promise.resolve(o) === o;
|
|
95
|
+
|
|
96
|
+
beforeEach(() => {
|
|
97
|
+
conf = JSON.parse(JSON.stringify(defaultConfig));
|
|
98
|
+
logger = new Logger.Logger({ stringify: () => '' });
|
|
99
|
+
cache = new Cache({ ...conf.cacheConfig, logger: logger.push({ component: 'cache' }) });
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
test('InboundServer reconfigure method returns sync function', async () => {
|
|
103
|
+
const server = new InboundServer(conf, logger, cache);
|
|
104
|
+
const res = await server.reconfigure(conf, logger, cache);
|
|
105
|
+
expect(isPromise(res)).toEqual(false);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
test('OutboundServer reconfigure method returns sync function', async () => {
|
|
109
|
+
const server = new OutboundServer(conf, logger, cache);
|
|
110
|
+
const res = await server.reconfigure(conf, logger, cache);
|
|
111
|
+
expect(isPromise(res)).toEqual(false);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
test('TestServer reconfigure method returns sync function', async () => {
|
|
115
|
+
const server = new TestServer({ logger, cache });
|
|
116
|
+
const res = await server.reconfigure({ logger, cache });
|
|
117
|
+
expect(isPromise(res)).toEqual(false);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
test('ControlServer reconfigure method returns sync function', async () => {
|
|
121
|
+
const server = new ControlServer.Server({ logger, appConfig: {} });
|
|
122
|
+
const res = await server.reconfigure({ logger, appConfig: {} });
|
|
123
|
+
expect(isPromise(res)).toEqual(false);
|
|
124
|
+
await server.close();
|
|
125
|
+
});
|
|
126
|
+
});
|
|
@@ -18,11 +18,11 @@ const postQuotesBody = require('./data/postQuotesBody');
|
|
|
18
18
|
const putParticipantsBody = require('./data/putParticipantsBody');
|
|
19
19
|
const commonHttpHeaders = require('./data/commonHttpHeaders');
|
|
20
20
|
|
|
21
|
-
jest.mock('
|
|
21
|
+
jest.mock('~/lib/cache');
|
|
22
22
|
jest.mock('@mojaloop/sdk-standard-components');
|
|
23
|
-
jest.mock('
|
|
23
|
+
jest.mock('~/lib/model/lib/requests', () => require('./lib/model/mockedLibRequests'));
|
|
24
24
|
|
|
25
|
-
const Cache = require('
|
|
25
|
+
const Cache = require('~/lib/cache');
|
|
26
26
|
const { Jws, Logger } = require('@mojaloop/sdk-standard-components');
|
|
27
27
|
const path = require('path');
|
|
28
28
|
const fs = require('fs');
|
|
@@ -30,7 +30,7 @@ const os = require('os');
|
|
|
30
30
|
const http = require('http');
|
|
31
31
|
const https = require('https');
|
|
32
32
|
|
|
33
|
-
const InboundServer = require('
|
|
33
|
+
const InboundServer = require('~/InboundServer');
|
|
34
34
|
|
|
35
35
|
describe('Inbound Server', () => {
|
|
36
36
|
describe('PUT /parties', () => {
|
|
@@ -376,7 +376,7 @@ describe('Inbound Server', () => {
|
|
|
376
376
|
|
|
377
377
|
afterEach(async () => {
|
|
378
378
|
await svr.stop();
|
|
379
|
-
fs.
|
|
379
|
+
fs.rmSync(keysDir, { recursive: true });
|
|
380
380
|
});
|
|
381
381
|
|
|
382
382
|
it('updates server configuration when a new JWS verification key '
|
|
@@ -20,13 +20,13 @@ const commonHttpHeaders = require('./data/commonHttpHeaders');
|
|
|
20
20
|
const WebSocket = require('ws');
|
|
21
21
|
const { Logger } = require('@mojaloop/sdk-standard-components');
|
|
22
22
|
|
|
23
|
-
jest.mock('
|
|
23
|
+
jest.mock('~/lib/cache');
|
|
24
24
|
jest.mock('@mojaloop/sdk-standard-components');
|
|
25
|
-
jest.mock('
|
|
25
|
+
jest.mock('~/lib/model/lib/requests', () => require('./lib/model/mockedLibRequests'));
|
|
26
26
|
|
|
27
|
-
const Cache = require('
|
|
28
|
-
const InboundServer = require('
|
|
29
|
-
const TestServer = require('
|
|
27
|
+
const Cache = require('~/lib/cache');
|
|
28
|
+
const InboundServer = require('~/InboundServer');
|
|
29
|
+
const TestServer = require('~/TestServer');
|
|
30
30
|
|
|
31
31
|
const createWsClient = async (port, path) => {
|
|
32
32
|
const result = new WebSocket(`ws://127.0.0.1:${port}${path}`);
|
package/test/unit/api/utils.js
CHANGED
|
@@ -2,12 +2,12 @@ const fs = require('fs');
|
|
|
2
2
|
const path = require('path');
|
|
3
3
|
const yaml = require('js-yaml');
|
|
4
4
|
const supertest = require('supertest');
|
|
5
|
-
const Validate = require('
|
|
5
|
+
const Validate = require('~/lib/validate');
|
|
6
6
|
|
|
7
|
-
const InboundServer = require('
|
|
8
|
-
const OutboundServer = require('
|
|
7
|
+
const InboundServer = require('~/InboundServer');
|
|
8
|
+
const OutboundServer = require('~/OutboundServer');
|
|
9
9
|
const { Logger } = require('@mojaloop/sdk-standard-components');
|
|
10
|
-
const Cache = require('
|
|
10
|
+
const Cache = require('~/lib/cache');
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Get OpenAPI spec and Validator for specified server
|
|
@@ -15,7 +15,7 @@ const Cache = require('../../../lib/cache');
|
|
|
15
15
|
* @return {Promise<{apiSpecs: Object, validator: Validator}>}
|
|
16
16
|
*/
|
|
17
17
|
const readApiInfo = async (serverType) => {
|
|
18
|
-
const specPath = path.join(__dirname,
|
|
18
|
+
const specPath = path.join(__dirname, `../../../src/${serverType}/api.yaml`);
|
|
19
19
|
const apiSpecs = yaml.load(fs.readFileSync(specPath));
|
|
20
20
|
const validator = new Validate();
|
|
21
21
|
await validator.initialise(apiSpecs);
|
package/test/unit/config.test.js
CHANGED
|
@@ -28,36 +28,37 @@ describe('config', () => {
|
|
|
28
28
|
process.env.BACKEND_ENDPOINT = '172.17.0.5:4000';
|
|
29
29
|
process.env.CACHE_HOST = '172.17.0.2';
|
|
30
30
|
process.env.CACHE_PORT = '6379';
|
|
31
|
+
process.env.MGMT_API_WS_URL = '0.0.0.0';
|
|
31
32
|
certDir = fs.mkdtempSync(path.join(os.tmpdir(), 'jest-'));
|
|
32
33
|
});
|
|
33
34
|
|
|
34
35
|
afterEach(() => {
|
|
35
36
|
process.env = { ...env };
|
|
36
|
-
fs.
|
|
37
|
+
fs.rmSync(certDir, { recursive: true });
|
|
37
38
|
jest.resetModules();
|
|
38
39
|
});
|
|
39
40
|
|
|
40
41
|
it('correctly parses OUTBOUND_ERROR_STATUSCODE_EXTENSION_KEY when set', () => {
|
|
41
42
|
process.env.OUTBOUND_ERROR_STATUSCODE_EXTENSION_KEY = outErrorStatusKey;
|
|
42
|
-
const config = require('
|
|
43
|
+
const config = require('~/config');
|
|
43
44
|
expect(config.outboundErrorStatusCodeExtensionKey).toEqual(outErrorStatusKey);
|
|
44
45
|
});
|
|
45
46
|
|
|
46
47
|
it('correctly parses OUTBOUND_ERROR_STATUSCODE_EXTENSION_KEY when NOT set', () => {
|
|
47
48
|
delete process.env.OUTBOUND_ERROR_STATUSCODE_EXTENSION_KEY;
|
|
48
|
-
const config = require('
|
|
49
|
+
const config = require('~/config');
|
|
49
50
|
expect(config.outboundErrorStatusCodeExtensionKey).toBeUndefined();
|
|
50
51
|
});
|
|
51
52
|
|
|
52
53
|
it('correctly parses VALIDATE_INBOUND_PUT_PARTIES_JWS when NOT set', () => {
|
|
53
54
|
delete process.env.VALIDATE_INBOUND_PUT_PARTIES_JWS;
|
|
54
|
-
const config = require('
|
|
55
|
+
const config = require('~/config');
|
|
55
56
|
expect(config.validateInboundPutPartiesJws).toBeFalsy();
|
|
56
57
|
});
|
|
57
58
|
|
|
58
59
|
it('correctly parses VALIDATE_INBOUND_PUT_PARTIES_JWS when set', () => {
|
|
59
60
|
process.env.VALIDATE_INBOUND_PUT_PARTIES_JWS = 'true';
|
|
60
|
-
const config = require('
|
|
61
|
+
const config = require('~/config');
|
|
61
62
|
expect(config.validateInboundPutPartiesJws).toBeTruthy();
|
|
62
63
|
});
|
|
63
64
|
|
|
@@ -66,7 +67,7 @@ describe('config', () => {
|
|
|
66
67
|
const certContent = 'cert-data';
|
|
67
68
|
fs.writeFileSync(cert, certContent);
|
|
68
69
|
process.env.IN_SERVER_CERT_PATH = cert;
|
|
69
|
-
const config = require('
|
|
70
|
+
const config = require('~/config');
|
|
70
71
|
const content = config.mutualTLS.inboundRequests.creds.cert.toString();
|
|
71
72
|
expect(content).toBe(certContent);
|
|
72
73
|
});
|
|
@@ -82,14 +83,14 @@ describe('config', () => {
|
|
|
82
83
|
];
|
|
83
84
|
certs.forEach((cert, index) => fs.writeFileSync(cert, certContent[index]));
|
|
84
85
|
process.env.IN_CA_CERT_PATH = certs.join(',');
|
|
85
|
-
const config = require('
|
|
86
|
+
const config = require('~/config');
|
|
86
87
|
const content = config.mutualTLS.inboundRequests.creds.ca.map(ca => ca.toString());
|
|
87
88
|
expect(content).toStrictEqual(certContent);
|
|
88
89
|
});
|
|
89
90
|
|
|
90
91
|
it('should parse proxy config yaml file as json object', () => {
|
|
91
92
|
process.env.PROXY_CONFIG_PATH = path.join(__dirname, './data/testFile.yaml');
|
|
92
|
-
const config = require('
|
|
93
|
+
const config = require('~/config');
|
|
93
94
|
const proxyConfig = require('./data/testFile');
|
|
94
95
|
expect(config.proxyConfig).toEqual(proxyConfig);
|
|
95
96
|
});
|
|
@@ -107,12 +108,12 @@ describe('config', () => {
|
|
|
107
108
|
},
|
|
108
109
|
|
|
109
110
|
};
|
|
110
|
-
const parseResourceVersion = require('
|
|
111
|
+
const parseResourceVersion = require('~/config').__parseResourceVersion;
|
|
111
112
|
expect(parseResourceVersion('resourceOneName=1.0,resourceTwoName=1.1')).toEqual(resourceVersions);
|
|
112
113
|
});
|
|
113
114
|
|
|
114
115
|
it('should throw an err if the resource string is not correctly formed', () => {
|
|
115
|
-
const parseResourceVersion = require('
|
|
116
|
+
const parseResourceVersion = require('~/config').__parseResourceVersion;
|
|
116
117
|
expect(() => parseResourceVersion('resourceOneName=1.0;resourceTwoName=1.1')).toThrowError(new Error('Resource versions format should be in format: "resouceOneName=1.0,resourceTwoName=1.1"'));
|
|
117
118
|
});
|
|
118
119
|
|
|
@@ -10,13 +10,13 @@
|
|
|
10
10
|
|
|
11
11
|
'use strict';
|
|
12
12
|
|
|
13
|
-
jest.mock('
|
|
13
|
+
jest.mock('~/lib/model');
|
|
14
14
|
|
|
15
|
-
const handlers = require('
|
|
16
|
-
const Model = require('
|
|
17
|
-
const QuotesModel = require('
|
|
18
|
-
const PartiesModel = require('
|
|
19
|
-
const TransfersModel = require('
|
|
15
|
+
const handlers = require('~/InboundServer/handlers');
|
|
16
|
+
const Model = require('~/lib/model').InboundTransfersModel;
|
|
17
|
+
const QuotesModel = require('~/lib/model').QuotesModel;
|
|
18
|
+
const PartiesModel = require('~/lib/model').PartiesModel;
|
|
19
|
+
const TransfersModel = require('~/lib/model').TransfersModel;
|
|
20
20
|
|
|
21
21
|
const mockArguments = require('./data/mockArguments');
|
|
22
22
|
const mockTransactionRequestData = require('./data/mockTransactionRequest');
|
package/test/unit/index.test.js
CHANGED
|
@@ -21,8 +21,9 @@ process.env.PEER_ENDPOINT = '172.17.0.3:4000';
|
|
|
21
21
|
process.env.BACKEND_ENDPOINT = '172.17.0.5:4000';
|
|
22
22
|
process.env.CACHE_HOST = '172.17.0.2';
|
|
23
23
|
process.env.CACHE_PORT = '6379';
|
|
24
|
+
process.env.MGMT_API_WS_URL = '0.0.0.0';
|
|
24
25
|
|
|
25
|
-
const index = require('
|
|
26
|
+
const index = require('~/index.js');
|
|
26
27
|
|
|
27
28
|
describe('index.js', () => {
|
|
28
29
|
test('WSO2 error events in OutboundServer propagate to top-level server', () => {
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
jest.mock('@mojaloop/sdk-standard-components');
|
|
15
15
|
jest.mock('redis');
|
|
16
16
|
|
|
17
|
-
const Cache = require('
|
|
18
|
-
const { AccountsModel } = require('
|
|
17
|
+
const Cache = require('~/lib/cache');
|
|
18
|
+
const { AccountsModel } = require('~/lib/model');
|
|
19
19
|
|
|
20
20
|
const StateMachine = require('javascript-state-machine');
|
|
21
21
|
const { MojaloopRequests, Logger } = require('@mojaloop/sdk-standard-components');
|
|
@@ -12,16 +12,16 @@
|
|
|
12
12
|
// we use a mock standard components lib to intercept and mock certain funcs
|
|
13
13
|
jest.mock('@mojaloop/sdk-standard-components');
|
|
14
14
|
jest.mock('redis');
|
|
15
|
-
jest.mock('
|
|
15
|
+
jest.mock('~/lib/model/lib/requests',() => require('./mockedLibRequests'));
|
|
16
16
|
|
|
17
17
|
const defaultConfig = require('./data/defaultConfig');
|
|
18
|
-
const Model = require('
|
|
18
|
+
const Model = require('~/lib/model').InboundTransfersModel;
|
|
19
19
|
const mockArguments = require('./data/mockArguments');
|
|
20
20
|
const mockTxnReqquestsArguments = require('./data/mockTxnRequestsArguments');
|
|
21
21
|
const { MojaloopRequests, Ilp, Logger } = require('@mojaloop/sdk-standard-components');
|
|
22
|
-
const { BackendRequests, HTTPResponseError } = require('
|
|
23
|
-
const Cache = require('
|
|
24
|
-
const shared = require('
|
|
22
|
+
const { BackendRequests, HTTPResponseError } = require('~/lib/model/lib/requests');
|
|
23
|
+
const Cache = require('~/lib/cache');
|
|
24
|
+
const shared = require('~/lib/model/lib/shared');
|
|
25
25
|
|
|
26
26
|
const getTransfersBackendResponse = require('./data/getTransfersBackendResponse');
|
|
27
27
|
const getTransfersMojaloopResponse = require('./data/getTransfersMojaloopResponse');
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
jest.mock('@mojaloop/sdk-standard-components');
|
|
15
15
|
jest.mock('redis');
|
|
16
16
|
|
|
17
|
-
const Cache = require('
|
|
18
|
-
const Model = require('
|
|
17
|
+
const Cache = require('~/lib/cache');
|
|
18
|
+
const Model = require('~/lib/model').OutboundBulkQuotesModel;
|
|
19
19
|
|
|
20
20
|
const { MojaloopRequests, Logger } = require('@mojaloop/sdk-standard-components');
|
|
21
21
|
const StateMachine = require('javascript-state-machine');
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
jest.mock('@mojaloop/sdk-standard-components');
|
|
15
15
|
jest.mock('redis');
|
|
16
16
|
|
|
17
|
-
const Cache = require('
|
|
18
|
-
const Model = require('
|
|
17
|
+
const Cache = require('~/lib/cache');
|
|
18
|
+
const Model = require('~/lib/model').OutboundBulkTransfersModel;
|
|
19
19
|
|
|
20
20
|
const { MojaloopRequests, Logger } = require('@mojaloop/sdk-standard-components');
|
|
21
21
|
const StateMachine = require('javascript-state-machine');
|
|
@@ -14,9 +14,9 @@
|
|
|
14
14
|
jest.mock('@mojaloop/sdk-standard-components');
|
|
15
15
|
jest.mock('redis');
|
|
16
16
|
|
|
17
|
-
const Cache = require('
|
|
18
|
-
const Model = require('
|
|
19
|
-
const PartiesModel = require('
|
|
17
|
+
const Cache = require('~/lib/cache');
|
|
18
|
+
const Model = require('~/lib/model').OutboundRequestToPayModel;
|
|
19
|
+
const PartiesModel = require('~/lib/model').PartiesModel;
|
|
20
20
|
|
|
21
21
|
const { MojaloopRequests, Logger } = require('@mojaloop/sdk-standard-components');
|
|
22
22
|
const StateMachine = require('javascript-state-machine');
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
jest.mock('@mojaloop/sdk-standard-components');
|
|
15
15
|
jest.mock('redis');
|
|
16
16
|
|
|
17
|
-
const Cache = require('
|
|
18
|
-
const Model = require('
|
|
17
|
+
const Cache = require('~/lib/cache');
|
|
18
|
+
const Model = require('~/lib/model').OutboundRequestToPayTransferModel;
|
|
19
19
|
|
|
20
20
|
const { MojaloopRequests, Logger } = require('@mojaloop/sdk-standard-components');
|
|
21
21
|
const StateMachine = require('javascript-state-machine');
|
|
@@ -14,9 +14,9 @@
|
|
|
14
14
|
jest.mock('@mojaloop/sdk-standard-components');
|
|
15
15
|
jest.mock('redis');
|
|
16
16
|
|
|
17
|
-
const Cache = require('
|
|
18
|
-
const Model = require('
|
|
19
|
-
const PartiesModel = require('
|
|
17
|
+
const Cache = require('~/lib/cache');
|
|
18
|
+
const Model = require('~/lib/model').OutboundTransfersModel;
|
|
19
|
+
const PartiesModel = require('~/lib/model').PartiesModel;
|
|
20
20
|
|
|
21
21
|
const { MojaloopRequests, Logger } = require('@mojaloop/sdk-standard-components');
|
|
22
22
|
const StateMachine = require('javascript-state-machine');
|