ml-testing-toolkit 18.13.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/.dockerignore +10 -0
- package/.grype.yaml +16 -0
- package/.ncurc.yaml +9 -0
- package/.nvmrc +1 -0
- package/.versionrc.js +16 -0
- package/CHANGELOG.md +504 -0
- package/CODEOWNERS +30 -0
- package/Dockerfile +42 -0
- package/Dockerfile-newman +13 -0
- package/LICENSE.md +9 -0
- package/README.md +119 -0
- package/assets/diagrams/architectural/architectural-diagram.svg +3 -0
- package/assets/diagrams/flow/flow-diagram.svg +3 -0
- package/assets/images/Sample-Response-Failure.png +0 -0
- package/assets/images/Screenshot 2020-04-16 at 22.58.04.png +0 -0
- package/assets/images/TLS-Enabled-on-Environment.png +0 -0
- package/assets/images/adapter-mutual-tls-enabled.png +0 -0
- package/assets/images/add-additional-input-values.png +0 -0
- package/assets/images/add-condition-button.png +0 -0
- package/assets/images/add-new-assertion.png +0 -0
- package/assets/images/add-new-input-value.png +0 -0
- package/assets/images/add-new-input-variable.png +0 -0
- package/assets/images/additional-transfers.png +0 -0
- package/assets/images/api-provisioning-add-new-api-confirmation.png +0 -0
- package/assets/images/api-provisioning-file-input-window.png +0 -0
- package/assets/images/api-provisioning-list-apis-view.png +0 -0
- package/assets/images/api-provisioning-menu-item.png +0 -0
- package/assets/images/apply_and_restart.jpg +0 -0
- package/assets/images/assess-request-or-response.png +0 -0
- package/assets/images/assess-response-equation-save.png +0 -0
- package/assets/images/assess-response-equation.png +0 -0
- package/assets/images/assess-response-status.png +0 -0
- package/assets/images/building-new-rules-file.png +0 -0
- package/assets/images/callback-rules-screen.png +0 -0
- package/assets/images/configurable-parameter-assertion.png +0 -0
- package/assets/images/configurable-parameter-currency.png +0 -0
- package/assets/images/configurable-parameter.png +0 -0
- package/assets/images/connection-manager-ui-opening.png +0 -0
- package/assets/images/create-inbound-user-simulator.png +0 -0
- package/assets/images/creating-new-rule-file.png +0 -0
- package/assets/images/dfsp-client-cacert.png +0 -0
- package/assets/images/dfsp-client-submit.png +0 -0
- package/assets/images/dfsp-client.png +0 -0
- package/assets/images/dfsp-p2p-happy-path.png +0 -0
- package/assets/images/dfsp-server-cacert.png +0 -0
- package/assets/images/dfsp-server-cert.png +0 -0
- package/assets/images/download-report.png +0 -0
- package/assets/images/drive_have_not_been_shared.jpg +0 -0
- package/assets/images/event-response-options.png +0 -0
- package/assets/images/expand-monitoring-messages.png +0 -0
- package/assets/images/fixed-response-sample.png +0 -0
- package/assets/images/header-selection.png +0 -0
- package/assets/images/heap_error_windows.jpg +0 -0
- package/assets/images/hosted-mode-docker-compose-intro.png +0 -0
- package/assets/images/hub-client-cert.png +0 -0
- package/assets/images/import-template.png +0 -0
- package/assets/images/inbound-requests-environment.png +0 -0
- package/assets/images/inbound-requests-scripts.png +0 -0
- package/assets/images/jws-certificate-submit.png +0 -0
- package/assets/images/jws-certificate.png +0 -0
- package/assets/images/jws-certs-keys.png +0 -0
- package/assets/images/jws-hub-certs-keys.png +0 -0
- package/assets/images/local-enable-jws-publickey.png +0 -0
- package/assets/images/local-mutual-tls-enabled.png +0 -0
- package/assets/images/local_drives_to_be_available.jpg +0 -0
- package/assets/images/mcm-environment-opening.png +0 -0
- package/assets/images/menu-items.png +0 -0
- package/assets/images/mock-response-sample.png +0 -0
- package/assets/images/monitoring-initial-state.png +0 -0
- package/assets/images/monitoring-messages.png +0 -0
- package/assets/images/new-empty-assertion.png +0 -0
- package/assets/images/opened-imported-template.png +0 -0
- package/assets/images/opening-default-settings.png +0 -0
- package/assets/images/opening-sync-response-rules.png +0 -0
- package/assets/images/opening-view.png +0 -0
- package/assets/images/outbound-display-opening-hub.png +0 -0
- package/assets/images/outbound-display-opening.png +0 -0
- package/assets/images/override-with-environment-variable.png +0 -0
- package/assets/images/populate-with-sample-body.png +0 -0
- package/assets/images/resource-selection.png +0 -0
- package/assets/images/rule-builder-select-api.png +0 -0
- package/assets/images/sample-condition-add-configurable-params.png +0 -0
- package/assets/images/sample-condition.png +0 -0
- package/assets/images/sample-editor.png +0 -0
- package/assets/images/sample-request.png +0 -0
- package/assets/images/sample-test-assertion.png +0 -0
- package/assets/images/send-transfer.png +0 -0
- package/assets/images/sending-single-test-case-1.png +0 -0
- package/assets/images/sending-single-test-case-2.png +0 -0
- package/assets/images/sending-test-cases.png +0 -0
- package/assets/images/server-certificates-submitted.png +0 -0
- package/assets/images/simulator-response.png +0 -0
- package/assets/images/simulator-scheme-adapter-endpoint.png +0 -0
- package/assets/images/summarized-view-of-rule.png +0 -0
- package/assets/images/template-window.png +0 -0
- package/assets/images/test-case-editor-console-log.png +0 -0
- package/assets/images/test-case-editor-environment-state.png +0 -0
- package/assets/images/test-case-editor-scripts.png +0 -0
- package/assets/images/test-case-editor.png +0 -0
- package/assets/images/testcase-definition-download.png +0 -0
- package/assets/images/testcase-definition-edit-meta-info.png +0 -0
- package/assets/images/testing-toolkit-mojaloop-testing-toolkit-endpoint.png +0 -0
- package/assets/images/tls-hub-certs-keys.png +0 -0
- package/assets/images/tls-jws-enabled-on-environment.png +0 -0
- package/assets/images/updated-sample-body-data.png +0 -0
- package/assets/images/using-configurable-parameter.png +0 -0
- package/assets/images/validation-rules-screen.png +0 -0
- package/assets/images/view-response.png +0 -0
- package/audit-ci.jsonc +7 -0
- package/connection-manager/docker-compose.yml +55 -0
- package/database/docker-compose.yml +16 -0
- package/docker/hosted-mode/docker-compose.yaml +107 -0
- package/docker/hosted-mode/keycloak/keycloak-realm.json +2298 -0
- package/docker/hosted-mode/mongo-init.sh +1 -0
- package/docker/hosted-mode-tls/docker-compose.yaml +171 -0
- package/docker/hosted-mode-tls/keycloak/keycloak-realm.json +2298 -0
- package/docker/hosted-mode-tls/mongo-init.sh +1 -0
- package/docker-compose.yml +62 -0
- package/documents/Mojaloop-Testing-Toolkit.md +296 -0
- package/documents/RULES_ENGINE.md +403 -0
- package/documents/User-Guide-API-Provisioning.md +121 -0
- package/documents/User-Guide-CLI.md +218 -0
- package/documents/User-Guide-Connection-Manager.md +282 -0
- package/documents/User-Guide-Frequently-Asked-Questions.md +39 -0
- package/documents/User-Guide-Hosted-Mode-Docker-Compose.md +110 -0
- package/documents/User-Guide-Installation.md +163 -0
- package/documents/User-Guide-Mojaloop-Testing-Toolkit.md +642 -0
- package/documents/User-Guide-OAuth-Server-Deployment.md +283 -0
- package/documents/User-Guide-Onboarding-DFSP.md +197 -0
- package/documents/User-Guide-Onboarding-HUB.md +191 -0
- package/documents/User-Guide.md +53 -0
- package/examples/collections/dfsp/p2p_failed_tests.json +7161 -0
- package/examples/collections/dfsp/p2p_fx_happy_path.json +502 -0
- package/examples/collections/dfsp/p2p_happy_path.json +350 -0
- package/examples/collections/dfsp/p2p_happy_path_extended.json +6106 -0
- package/examples/collections/dfsp/p2p_happy_path_jws.json +511 -0
- package/examples/collections/dfsp/p2p_payee_assertions_websocket.json +441 -0
- package/examples/collections/dfsp/sample.json +5029 -0
- package/examples/collections/dfsp/transaction_request_service.json +240 -0
- package/examples/collections/fxp/FXP.json +264 -0
- package/examples/collections/fxp/SDK_backend.json +98 -0
- package/examples/collections/fxp/SDK_outbound.json +163 -0
- package/examples/collections/hub/hub_01_p2p_happy_path/hub_p2p_receive_quote.json +400 -0
- package/examples/collections/hub/hub_01_p2p_happy_path/hub_p2p_send_quote.json +395 -0
- package/examples/collections/hub/hub_02_block_transfer/hub_block_transfer.json +393 -0
- package/examples/collections/hub/hub_03_funds_in_out/hub_funds_in.json +224 -0
- package/examples/collections/hub/hub_03_funds_in_out/hub_funds_out.json +780 -0
- package/examples/collections/hub/hub_04_settlements/hub_settlements.json +3138 -0
- package/examples/collections/hub/hub_05_transfer_negative_scenarios/hub_transfer_negative_payee_abort.json +475 -0
- package/examples/collections/hub/hub_05_transfer_negative_scenarios/hub_transfer_negative_payee_invalid_fulfillment.json +370 -0
- package/examples/collections/hub/hub_05_transfer_negative_scenarios/hub_transfer_negative_transfer_timeout.json +262 -0
- package/examples/collections/hub/hub_06_transaction_requests_service/hub_trs_authorizations.json +117 -0
- package/examples/collections/hub/hub_06_transaction_requests_service/hub_trs_error_framework.json +591 -0
- package/examples/collections/hub/hub_06_transaction_requests_service/hub_trs_received_state.json +379 -0
- package/examples/collections/hub/hub_06_transaction_requests_service/hub_trs_reject_state.json +361 -0
- package/examples/collections/hub/hub_07_quoting_service.json +525 -0
- package/examples/collections/hub/hub_08_participant_inactive_stop_transfers.json +706 -0
- package/examples/collections/hub/hub_09_duplicate_handling_transfers.json +1377 -0
- package/examples/collections/hub/hub_10_on_us_transfers.json +245 -0
- package/examples/collections/hub/hub_11_accented_and_spl_chars.json +629 -0
- package/examples/collections/hub/hub_12_fspiop_version_1.1.json +646 -0
- package/examples/collections/hub/hub_13_bulk_transfers.json +1857 -0
- package/examples/collections/iso20022/self_referencing_iso20022.json +926 -0
- package/examples/collections/provisioning/testingtoolkitdfsp.json +904 -0
- package/examples/environments/dfsp_local_environment.json +46 -0
- package/examples/environments/hub_local_environment.json +57 -0
- package/jest.config.js +17 -0
- package/package.json +199 -0
- package/sbom-v18.12.4.csv +1553 -0
- package/secrets/keygen.sh +5 -0
- package/secrets/privatekey.pem +27 -0
- package/secrets/publickey.cer +21 -0
- package/secrets/tls/01.pem +132 -0
- package/secrets/tls/createSecrets.sh +20 -0
- package/secrets/tls/hub_client.csr +32 -0
- package/secrets/tls/hub_client_cacert.pem +35 -0
- package/secrets/tls/hub_client_cakey.pem +52 -0
- package/secrets/tls/hub_client_key.key +52 -0
- package/secrets/tls/hub_server.csr +31 -0
- package/secrets/tls/hub_server_cacert.pem +35 -0
- package/secrets/tls/hub_server_cakey.pem +52 -0
- package/secrets/tls/hub_server_cert.pem +132 -0
- package/secrets/tls/hub_server_key.key +52 -0
- package/secrets/tls/index.txt +1 -0
- package/secrets/tls/index.txt.attr +1 -0
- package/secrets/tls/openssl-client.cnf +36 -0
- package/secrets/tls/openssl-clientca.cnf +71 -0
- package/secrets/tls/openssl-server.cnf +39 -0
- package/secrets/tls/openssl-serverca.cnf +71 -0
- package/secrets/tls/serial.txt +1 -0
- package/spec_files/api_definitions/als_admin_1.1/api_spec.yaml +804 -0
- package/spec_files/api_definitions/central_admin_1.0/api_spec.yaml +1850 -0
- package/spec_files/api_definitions/central_admin_1.0/response_map.json +96 -0
- package/spec_files/api_definitions/central_admin_old_9.3/api_spec.yaml +2467 -0
- package/spec_files/api_definitions/central_admin_old_9.3/response_map.json +96 -0
- package/spec_files/api_definitions/fspiop_1.0/api_spec.yaml +4187 -0
- package/spec_files/api_definitions/fspiop_1.0/callback_map.json +568 -0
- package/spec_files/api_definitions/fspiop_1.0/mockRef.json +79 -0
- package/spec_files/api_definitions/fspiop_1.0/trigger_templates/transaction_request_followup.json +126 -0
- package/spec_files/api_definitions/fspiop_1.0/trigger_templates/transaction_request_followup_quotes_only.json +97 -0
- package/spec_files/api_definitions/fspiop_1.1/api_spec.yaml +3778 -0
- package/spec_files/api_definitions/fspiop_1.1/callback_map.json +568 -0
- package/spec_files/api_definitions/fspiop_1.1/mockRef.json +79 -0
- package/spec_files/api_definitions/fspiop_1.1/trigger_templates/transaction_request_followup.json +125 -0
- package/spec_files/api_definitions/fspiop_2.0/api_spec.yaml +4839 -0
- package/spec_files/api_definitions/fspiop_2.0/callback_map.json +716 -0
- package/spec_files/api_definitions/fspiop_2.0/mockRef.json +79 -0
- package/spec_files/api_definitions/fspiop_2.0/trigger_templates/transaction_request_followup.json +125 -0
- package/spec_files/api_definitions/fspiop_2.0_iso20022/api_spec.yaml +8331 -0
- package/spec_files/api_definitions/fspiop_2.0_iso20022/callback_map.json +508 -0
- package/spec_files/api_definitions/fspiop_2.0_iso20022/mockRef.json +66 -0
- package/spec_files/api_definitions/fx-api_2.0/api_spec.yaml +1768 -0
- package/spec_files/api_definitions/fx-api_2.0/callback_map.json +188 -0
- package/spec_files/api_definitions/fx-api_2.0/mockRef.json +83 -0
- package/spec_files/api_definitions/mojaloop_sdk_outbound_scheme_adapter_1.0/api_spec.yaml +2612 -0
- package/spec_files/api_definitions/mojaloop_sdk_outbound_scheme_adapter_1.0/mockRef.json +22 -0
- package/spec_files/api_definitions/mojaloop_sdk_outbound_scheme_adapter_1.0/response_map.json +35 -0
- package/spec_files/api_definitions/mojaloop_simulator_0.1/api_spec.yaml +225 -0
- package/spec_files/api_definitions/mojaloop_simulator_sim_1.4/api_spec.yaml +1087 -0
- package/spec_files/api_definitions/mojaloop_simulator_sim_1.4/mockRef.json +75 -0
- package/spec_files/api_definitions/mojaloop_simulator_sim_1.4/response_map.json +55 -0
- package/spec_files/api_definitions/payment_manager_1.4/api_spec.yaml +1389 -0
- package/spec_files/api_definitions/sdk-scheme-adapter-backend-v2_1_0-openapi3-snippets_2.1/api_spec.yaml +2834 -0
- package/spec_files/api_definitions/sdk-scheme-adapter-outbound-v2_1_0-openapi3-snippets_2.1/api_spec.yaml +3449 -0
- package/spec_files/api_definitions/settlements_1.0/api_spec.yaml +983 -0
- package/spec_files/api_definitions/settlements_1.0/mockRef.json +38 -0
- package/spec_files/api_definitions/settlements_1.0/response_map.json +34 -0
- package/spec_files/api_definitions/settlements_2.0/api_spec.yaml +1001 -0
- package/spec_files/api_definitions/settlements_2.0/mockRef.json +38 -0
- package/spec_files/api_definitions/settlements_2.0/response_map.json +34 -0
- package/spec_files/api_definitions/thirdparty_sdk_outbound_0.1/api_spec.yaml +2139 -0
- package/spec_files/reports/templates/newman/html_template.html +1202 -0
- package/spec_files/reports/templates/newman/pdf_template.html +790 -0
- package/spec_files/reports/templates/testcase_definition/table_view.html +1602 -0
- package/spec_files/rules_callback/config.json +3 -0
- package/spec_files/rules_callback/default.json +2698 -0
- package/spec_files/rules_callback/p2p-limit.json +129 -0
- package/spec_files/rules_forward/config.json +3 -0
- package/spec_files/rules_forward/default.json +482 -0
- package/spec_files/rules_response/config.json +3 -0
- package/spec_files/rules_response/default.json +295 -0
- package/spec_files/rules_validation/config.json +3 -0
- package/spec_files/rules_validation/default.json +1 -0
- package/spec_files/rules_validation/p2p-limit.json +55 -0
- package/spec_files/system_config.json +175 -0
- package/spec_files/user_config.json +109 -0
- package/src/index.js +67 -0
- package/src/lib/MyEventEmitter.js +54 -0
- package/src/lib/api-management.js +143 -0
- package/src/lib/api-routes/config.js +83 -0
- package/src/lib/api-routes/history.js +139 -0
- package/src/lib/api-routes/keycloak.js +54 -0
- package/src/lib/api-routes/longpolling.js +70 -0
- package/src/lib/api-routes/oauth2.js +149 -0
- package/src/lib/api-routes/objectstore.js +53 -0
- package/src/lib/api-routes/openapi.js +224 -0
- package/src/lib/api-routes/outbound.js +134 -0
- package/src/lib/api-routes/reports.js +72 -0
- package/src/lib/api-routes/rules.js +356 -0
- package/src/lib/api-routes/samples.js +92 -0
- package/src/lib/api-routes/server-logs.js +44 -0
- package/src/lib/api-routes/settings.js +71 -0
- package/src/lib/api-server.js +135 -0
- package/src/lib/arrayStore.js +101 -0
- package/src/lib/callbackHandler.js +201 -0
- package/src/lib/config.js +177 -0
- package/src/lib/configuration-providers/mb-connection-manager.js +625 -0
- package/src/lib/db/adapters/dbAdapter.js +184 -0
- package/src/lib/db/dfspMockUsers.js +64 -0
- package/src/lib/db/models/mongoDBWrapper.js +78 -0
- package/src/lib/eventListenerClient/inboundEventListener.js +176 -0
- package/src/lib/fileAdapter.js +57 -0
- package/src/lib/httpAgentStore.js +135 -0
- package/src/lib/importExport.js +186 -0
- package/src/lib/jws/JwsSigning.js +141 -0
- package/src/lib/loadSamples.js +128 -0
- package/src/lib/logger.js +20 -0
- package/src/lib/longpollingEmitter.js +56 -0
- package/src/lib/metrics.js +51 -0
- package/src/lib/mocking/custom-functions/generic.js +57 -0
- package/src/lib/mocking/middleware-functions/ilpModel.js +238 -0
- package/src/lib/mocking/middleware-functions/quotesAssociation.js +75 -0
- package/src/lib/mocking/middleware-functions/transactionRequestsService.js +78 -0
- package/src/lib/mocking/openApiDefinitionsModel.js +64 -0
- package/src/lib/mocking/openApiMockHandler.js +466 -0
- package/src/lib/mocking/openApiRulesEngine.js +492 -0
- package/src/lib/mocking/openApiVersionTools.js +136 -0
- package/src/lib/mocking/transformers/fspiopToISO20022.js +230 -0
- package/src/lib/mocking/transformers/index.js +41 -0
- package/src/lib/notificationEmitter.js +64 -0
- package/src/lib/oauth/KeycloakHelper.js +220 -0
- package/src/lib/oauth/LoginService.js +133 -0
- package/src/lib/oauth/OAuthHelper.js +181 -0
- package/src/lib/oauth/OAuthValidator.js +118 -0
- package/src/lib/oauth/Wso2Client.js +64 -0
- package/src/lib/objectStore/inMemoryImpl.js +50 -0
- package/src/lib/objectStore/objectStoreInterface.js +51 -0
- package/src/lib/objectStore.js +122 -0
- package/src/lib/report-generator/generator.js +126 -0
- package/src/lib/report-generator/helpers.js +154 -0
- package/src/lib/requestLogger.js +190 -0
- package/src/lib/resources/wso2carbon-publickey.cert +20 -0
- package/src/lib/rulesEngine.js +95 -0
- package/src/lib/rulesEngineModel.js +463 -0
- package/src/lib/scripting-engines/postman-sandbox.js +142 -0
- package/src/lib/scripting-engines/vm-javascript-sandbox.js +294 -0
- package/src/lib/server-logs/adapters/elastic-search.js +102 -0
- package/src/lib/server-logs/adapters/grafana.js +0 -0
- package/src/lib/server-logs/index.js +75 -0
- package/src/lib/socket-server.js +55 -0
- package/src/lib/storageAdapter.js +109 -0
- package/src/lib/test-outbound/TestCaseRunner.js +173 -0
- package/src/lib/test-outbound/getTracing.js +19 -0
- package/src/lib/test-outbound/outbound-initiator.js +1107 -0
- package/src/lib/uniqueIdGenerator.js +35 -0
- package/src/lib/utils.js +89 -0
- package/src/lib/utilsInternal.js +56 -0
- package/src/lib/webSocketClient/WebSocketClientManager.js +197 -0
- package/src/server.js +218 -0
|
@@ -0,0 +1,625 @@
|
|
|
1
|
+
/*****
|
|
2
|
+
License
|
|
3
|
+
--------------
|
|
4
|
+
Copyright © 2020-2025 Mojaloop Foundation
|
|
5
|
+
The Mojaloop files are made available by the Mojaloop 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
|
+
|
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
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.
|
|
10
|
+
|
|
11
|
+
Contributors
|
|
12
|
+
--------------
|
|
13
|
+
This is the official list of the Mojaloop project contributors for this file.
|
|
14
|
+
Names of the original copyright holders (individuals or organizations)
|
|
15
|
+
should be listed with a '*' in the first column. People who have
|
|
16
|
+
contributed from an organization can be listed under the organization
|
|
17
|
+
that actually holds the copyright for their contributions (see the
|
|
18
|
+
Mojaloop Foundation for an example). Those individuals should have
|
|
19
|
+
their names indented and be marked with a '-'. Email address can be added
|
|
20
|
+
optionally within square brackets <email>.
|
|
21
|
+
|
|
22
|
+
* Mojaloop Foundation
|
|
23
|
+
- Name Surname <name.surname@mojaloop.io>
|
|
24
|
+
|
|
25
|
+
* ModusBox
|
|
26
|
+
* Vijaya Kumar Guthi <vijaya.guthi@modusbox.com> (Original Author)
|
|
27
|
+
--------------
|
|
28
|
+
******/
|
|
29
|
+
|
|
30
|
+
const Config = require('../config')
|
|
31
|
+
const axios = require('axios').default
|
|
32
|
+
const fs = require('fs')
|
|
33
|
+
const _ = require('lodash')
|
|
34
|
+
const { promisify } = require('util')
|
|
35
|
+
const querystring = require('querystring')
|
|
36
|
+
const readFileAsync = promisify(fs.readFile)
|
|
37
|
+
const objectStore = require('../objectStore/objectStoreInterface')
|
|
38
|
+
const dfspDB = require('../db/dfspMockUsers')
|
|
39
|
+
const customLogger = require('../requestLogger')
|
|
40
|
+
|
|
41
|
+
const DEFAULT_ENVIRONMENT_NAME = 'TESTING-TOOLKIT'
|
|
42
|
+
const DEFAULT_TESTING_TOOLKIT_FSPID = 'testingtoolkitdfsp'
|
|
43
|
+
const CM_CHECK_INTERVAL = 10000
|
|
44
|
+
let CONNECTION_MANAGER = {}
|
|
45
|
+
|
|
46
|
+
let currentCookies = [null]
|
|
47
|
+
let currentEnvironment = null
|
|
48
|
+
// var currentTestingToolkitDFSP = null
|
|
49
|
+
// var currentUserDFSP = null
|
|
50
|
+
|
|
51
|
+
const currentJWSConfig = {
|
|
52
|
+
dfsps: {}
|
|
53
|
+
}
|
|
54
|
+
const currentTlsConfig = {
|
|
55
|
+
dfsps: {}
|
|
56
|
+
}
|
|
57
|
+
const currentEndpoints = {}
|
|
58
|
+
|
|
59
|
+
const initEnvironment = async () => {
|
|
60
|
+
// Check whether an environment exists with the name testing-toolkit
|
|
61
|
+
try {
|
|
62
|
+
const environmentsResult = await axios.get(CONNECTION_MANAGER.API_URL + '/api/environments', { headers: { Cookie: currentCookies[0], 'Content-Type': 'application/json' } })
|
|
63
|
+
if (environmentsResult.status === 200) {
|
|
64
|
+
const environments = environmentsResult.data
|
|
65
|
+
if (environments.length > 0) {
|
|
66
|
+
const testingToolkitEnv = environments.find(item => item.name === DEFAULT_ENVIRONMENT_NAME)
|
|
67
|
+
currentEnvironment = testingToolkitEnv || null
|
|
68
|
+
} else {
|
|
69
|
+
currentEnvironment = null
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
} catch (err) {}
|
|
73
|
+
|
|
74
|
+
// Create if not exists
|
|
75
|
+
if (!currentEnvironment) {
|
|
76
|
+
try {
|
|
77
|
+
const environmentData = {
|
|
78
|
+
name: DEFAULT_ENVIRONMENT_NAME,
|
|
79
|
+
defaultDN: {
|
|
80
|
+
CN: 'tes1.centralhub.modusbox.live',
|
|
81
|
+
O: 'Modusbox',
|
|
82
|
+
OU: 'MCM'
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
const createEnvResponse = await axios.post(CONNECTION_MANAGER.API_URL + '/api/environments', environmentData, { headers: { Cookie: currentCookies[0], 'Content-Type': 'application/json' } })
|
|
86
|
+
if (createEnvResponse.status === 200) {
|
|
87
|
+
currentEnvironment = createEnvResponse.data
|
|
88
|
+
} else {
|
|
89
|
+
throw new Error('Some error creating environment - ' + JSON.stringify(createEnvResponse))
|
|
90
|
+
}
|
|
91
|
+
} catch (err) {
|
|
92
|
+
throw new Error('Some error creating environment - ' + err.message)
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const initDFSP = async (environmentId, dfspId, dfspName) => {
|
|
98
|
+
if (!currentJWSConfig.dfsps[dfspId]) {
|
|
99
|
+
currentJWSConfig.dfsps[dfspId] = {}
|
|
100
|
+
}
|
|
101
|
+
if (!currentTlsConfig.dfsps[dfspId]) {
|
|
102
|
+
currentTlsConfig.dfsps[dfspId] = {}
|
|
103
|
+
}
|
|
104
|
+
// Check whether a dfspId exists
|
|
105
|
+
try {
|
|
106
|
+
const dfspResult = await axios.get(CONNECTION_MANAGER.API_URL + '/api/environments/' + environmentId + '/dfsps', { headers: { Cookie: currentCookies[0], 'Content-Type': 'application/json' } })
|
|
107
|
+
if (dfspResult.status === 200 && dfspResult.data.length > 0) {
|
|
108
|
+
const dfspItem = dfspResult.data.find(item => item.id === dfspId)
|
|
109
|
+
if (dfspItem) {
|
|
110
|
+
return dfspItem
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
} catch (err) {}
|
|
114
|
+
|
|
115
|
+
// Create if not exists
|
|
116
|
+
try {
|
|
117
|
+
const dfspData = {
|
|
118
|
+
dfspId,
|
|
119
|
+
name: dfspName,
|
|
120
|
+
monetaryZoneId: 'EUR'
|
|
121
|
+
}
|
|
122
|
+
const dfspCreateResponse = await axios.post(CONNECTION_MANAGER.API_URL + '/api/environments/' + environmentId + '/dfsps', dfspData, { headers: { Cookie: currentCookies[0], 'Content-Type': 'application/json' } })
|
|
123
|
+
if (dfspCreateResponse.status === 200) {
|
|
124
|
+
return dfspCreateResponse.data
|
|
125
|
+
} else {
|
|
126
|
+
customLogger.logMessage('error', 'Some error creating DFSP', { notification: false })
|
|
127
|
+
}
|
|
128
|
+
} catch (err) {
|
|
129
|
+
customLogger.logMessage('error', 'Some error creating DFSP', { additionalData: err.response ? err.response.data : err, notification: false })
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const initJWSCertificate = async (environmentId, dfspId, jwsCertificate, intermediateCertificate) => {
|
|
134
|
+
const rootCertificate = null
|
|
135
|
+
let certExists = false
|
|
136
|
+
let certResult = null
|
|
137
|
+
// Check whether a jws certificate exists for the dfspId testing-toolkit
|
|
138
|
+
try {
|
|
139
|
+
certResult = await axios.get(CONNECTION_MANAGER.API_URL + '/api/environments/' + environmentId + '/dfsps/' + dfspId + '/jwscerts', { headers: { Cookie: currentCookies[0], 'Content-Type': 'application/json' } })
|
|
140
|
+
if (certResult.status === 200) {
|
|
141
|
+
certExists = (certResult.data && certResult.data.id)
|
|
142
|
+
}
|
|
143
|
+
} catch (err) {}
|
|
144
|
+
|
|
145
|
+
if (certExists && (rootCertificate === certResult.data.rootCertificate && intermediateCertificate === certResult.data.intermediateChain && jwsCertificate === certResult.data.jwsCertificate)) {
|
|
146
|
+
return certResult
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// Create if not exists or update if exists
|
|
150
|
+
try {
|
|
151
|
+
const jwsData = {
|
|
152
|
+
rootCertificate,
|
|
153
|
+
intermediateChain: intermediateCertificate,
|
|
154
|
+
jwsCertificate
|
|
155
|
+
}
|
|
156
|
+
let jwsCertResponse = null
|
|
157
|
+
if (certExists) {
|
|
158
|
+
jwsCertResponse = await axios.put(CONNECTION_MANAGER.API_URL + '/api/environments/' + environmentId + '/dfsps/' + dfspId + '/jwscerts', jwsData, { headers: { Cookie: currentCookies[0], 'Content-Type': 'application/json' } })
|
|
159
|
+
} else {
|
|
160
|
+
jwsCertResponse = await axios.post(CONNECTION_MANAGER.API_URL + '/api/environments/' + environmentId + '/dfsps/' + dfspId + '/jwscerts', jwsData, { headers: { Cookie: currentCookies[0], 'Content-Type': 'application/json' } })
|
|
161
|
+
}
|
|
162
|
+
if (jwsCertResponse.status === 200) {
|
|
163
|
+
return jwsCertResponse.data
|
|
164
|
+
} else {
|
|
165
|
+
customLogger.logMessage('error', 'Some error creating / updating JWS cert for DFSP', { notification: false })
|
|
166
|
+
}
|
|
167
|
+
} catch (err) {
|
|
168
|
+
customLogger.logMessage('error', 'Some error creating / updating JWS cert for DFSP', { additionalData: err.response ? err.response.data : err, notification: false })
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const fetchUserDFSPJwsCerts = async (environmentId, dfspId) => {
|
|
173
|
+
// Check whether an environment exists with the name testing-toolkit
|
|
174
|
+
try {
|
|
175
|
+
const certResult = await axios.get(CONNECTION_MANAGER.API_URL + '/api/environments/' + environmentId + '/dfsps/' + dfspId + '/jwscerts', { headers: { Cookie: currentCookies[0], 'Content-Type': 'application/json' } })
|
|
176
|
+
if (certResult.status === 200 && (certResult.data && certResult.data.id)) {
|
|
177
|
+
const fetchedJwsCerts = certResult.data
|
|
178
|
+
if (!_.isEqual(fetchedJwsCerts, currentJWSConfig.dfsps[dfspId])) {
|
|
179
|
+
currentJWSConfig.dfsps[dfspId] = fetchedJwsCerts
|
|
180
|
+
await setJWSConfig()
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
} catch (err) {}
|
|
184
|
+
return currentJWSConfig.dfsps[dfspId]
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// TLS Related
|
|
188
|
+
|
|
189
|
+
const initHubCa = async (environmentId) => {
|
|
190
|
+
let certResult = null
|
|
191
|
+
// Check whether a jws certificate exists for the dfspId testing-toolkit
|
|
192
|
+
try {
|
|
193
|
+
certResult = await axios.get(CONNECTION_MANAGER.API_URL + '/api/environments/' + environmentId + '/ca/rootCert', { headers: { Cookie: currentCookies[0], 'Content-Type': 'application/json' } })
|
|
194
|
+
if (certResult.status === 200 && (certResult.data && certResult.data.certificate)) {
|
|
195
|
+
return certResult.data.certificate
|
|
196
|
+
}
|
|
197
|
+
} catch (err) {}
|
|
198
|
+
|
|
199
|
+
// Create if not exists
|
|
200
|
+
try {
|
|
201
|
+
const casData = {
|
|
202
|
+
default: {
|
|
203
|
+
expiry: '87600h',
|
|
204
|
+
usages: [
|
|
205
|
+
'signing'
|
|
206
|
+
],
|
|
207
|
+
signature_algorithm: 'SHA256WithRSA'
|
|
208
|
+
},
|
|
209
|
+
csr: {
|
|
210
|
+
hosts: [
|
|
211
|
+
'string'
|
|
212
|
+
],
|
|
213
|
+
names: [
|
|
214
|
+
{
|
|
215
|
+
CN: 'testingtoolkithubca',
|
|
216
|
+
O: 'Testing Toolkit Hub CA',
|
|
217
|
+
OU: 'Payments',
|
|
218
|
+
C: 'US',
|
|
219
|
+
ST: 'NY',
|
|
220
|
+
L: 'NY'
|
|
221
|
+
}
|
|
222
|
+
],
|
|
223
|
+
key: {
|
|
224
|
+
size: 4096,
|
|
225
|
+
algo: 'rsa'
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
let hubCaCertResponse = null
|
|
230
|
+
|
|
231
|
+
hubCaCertResponse = await axios.post(CONNECTION_MANAGER.API_URL + '/api/environments/' + environmentId + '/cas', casData, { headers: { Cookie: currentCookies[0], 'Content-Type': 'application/json' } })
|
|
232
|
+
|
|
233
|
+
if (hubCaCertResponse.status === 200) {
|
|
234
|
+
return hubCaCertResponse.data.certificate
|
|
235
|
+
} else {
|
|
236
|
+
customLogger.logMessage('error', 'Some error creating Hub CA Certificate', { notification: false })
|
|
237
|
+
}
|
|
238
|
+
} catch (err) {
|
|
239
|
+
customLogger.logMessage('error', 'Some error creating Hub CA Certificate', { additionalData: err.response ? err.response.data : err, notification: false })
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
const checkDfspCa = async (environmentId, dfspId) => {
|
|
244
|
+
// Check for any new CSRs those need to be signed
|
|
245
|
+
try {
|
|
246
|
+
const dfspCaResult = await axios.get(CONNECTION_MANAGER.API_URL + '/api/environments/' + environmentId + '/dfsps/' + dfspId + '/ca', { headers: { Cookie: currentCookies[0], 'Content-Type': 'application/json' } })
|
|
247
|
+
if (dfspCaResult.status === 200 && dfspCaResult.data.rootCertificate && dfspCaResult.data.validationState === 'VALID') {
|
|
248
|
+
if (currentTlsConfig.dfsps[dfspId].dfspCaRootCert !== dfspCaResult.data.rootCertificate) {
|
|
249
|
+
currentTlsConfig.dfsps[dfspId].dfspCaRootCert = dfspCaResult.data.rootCertificate
|
|
250
|
+
await setTLSConfig()
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
} catch (err) {}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
const checkDfspCsrs = async (environmentId, dfspId) => {
|
|
257
|
+
// Check for any new CSRs those need to be signed
|
|
258
|
+
let dfspPendingCsrs = []
|
|
259
|
+
try {
|
|
260
|
+
const dfspCsrsResult = await axios.get(CONNECTION_MANAGER.API_URL + '/api/environments/' + environmentId + '/dfsps/' + dfspId + '/enrollments/inbound', { headers: { Cookie: currentCookies[0], 'Content-Type': 'application/json' } })
|
|
261
|
+
if (dfspCsrsResult.status === 200) {
|
|
262
|
+
dfspPendingCsrs = dfspCsrsResult.data.filter(item => item.state === 'CSR_LOADED' && item.validationState === 'VALID')
|
|
263
|
+
}
|
|
264
|
+
} catch (err) {}
|
|
265
|
+
|
|
266
|
+
// Iterate through pending CSRs and sign
|
|
267
|
+
for (let i = 0; i < dfspPendingCsrs.length; i++) {
|
|
268
|
+
// Sign the CSR
|
|
269
|
+
try {
|
|
270
|
+
const signResponse = await axios.post(CONNECTION_MANAGER.API_URL + '/api/environments/' + environmentId + '/dfsps/' + dfspId + '/enrollments/inbound/' + dfspPendingCsrs[i].id + '/sign', {}, { headers: { Cookie: currentCookies[0], 'Content-Type': 'application/json' } })
|
|
271
|
+
|
|
272
|
+
if (signResponse.status === 200) {
|
|
273
|
+
if (signResponse.data.certificate) {
|
|
274
|
+
customLogger.logMessage('info', 'CSR signed for ' + dfspId, { notification: false })
|
|
275
|
+
}
|
|
276
|
+
} else {
|
|
277
|
+
customLogger.logMessage('error', 'Some error signing DFSP CSR', { notification: false })
|
|
278
|
+
}
|
|
279
|
+
} catch (err) {
|
|
280
|
+
customLogger.logMessage('error', 'Some error signing DFSP CSR', { additionalData: err.response ? err.response.data : err, notification: false })
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
const checkHubCsrs = async (environmentId, dfspId) => {
|
|
286
|
+
// Check for any new CSRs those need to be signed
|
|
287
|
+
let hubCsrs = []
|
|
288
|
+
try {
|
|
289
|
+
const hubCsrsResult = await axios.get(CONNECTION_MANAGER.API_URL + '/api/environments/' + environmentId + '/dfsps/' + dfspId + '/enrollments/outbound', { headers: { Cookie: currentCookies[0], 'Content-Type': 'application/json' } })
|
|
290
|
+
if (hubCsrsResult.status === 200) {
|
|
291
|
+
hubCsrs = hubCsrsResult.data.filter(item => item.validationState === 'VALID')
|
|
292
|
+
}
|
|
293
|
+
} catch (err) {}
|
|
294
|
+
|
|
295
|
+
// Store if any signed CSRs found or create a CSR if no CSR found
|
|
296
|
+
if (hubCsrs.length > 0) {
|
|
297
|
+
const hubSignedCsrs = hubCsrs.filter(item => (item.validationState === 'VALID' && item.state === 'CERT_SIGNED' && item.certificate !== null))
|
|
298
|
+
if (hubSignedCsrs.length > 0 && currentTlsConfig.dfsps[dfspId] && currentTlsConfig.dfsps[dfspId].hubClientCert !== hubSignedCsrs[0].certificate) {
|
|
299
|
+
customLogger.logMessage('info', 'New Signed Hub client CERT Found: ' + dfspId, { notification: false })
|
|
300
|
+
currentTlsConfig.dfsps[dfspId].hubClientCert = hubSignedCsrs[0].certificate
|
|
301
|
+
await setTLSConfig()
|
|
302
|
+
}
|
|
303
|
+
} else {
|
|
304
|
+
try {
|
|
305
|
+
const hubClientCsrData = await readFileAsync('secrets/tls/hub_client.csr')
|
|
306
|
+
const hubCsrData = {
|
|
307
|
+
hubCSR: hubClientCsrData.toString()
|
|
308
|
+
}
|
|
309
|
+
let hubCsrCreateResponse = null
|
|
310
|
+
hubCsrCreateResponse = await axios.post(CONNECTION_MANAGER.API_URL + '/api/environments/' + environmentId + '/dfsps/' + dfspId + '/enrollments/outbound', hubCsrData, { headers: { Cookie: currentCookies[0], 'Content-Type': 'application/json' } })
|
|
311
|
+
customLogger.logMessage('info', hubCsrCreateResponse.status === 200 ? 'Hub CSR Uploaded' : 'Some error uploading Hub CSR', { notification: false })
|
|
312
|
+
} catch (err) {
|
|
313
|
+
customLogger.logMessage('error', 'Some error uploading Hub CSR', { additionalData: err.response ? err.response.data : err, notification: false })
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
const uploadHubServerCerts = async (environmentId, rootCert, intermediateChain, serverCert) => {
|
|
319
|
+
// Check for any hub server certs
|
|
320
|
+
let hubServerCerts = null
|
|
321
|
+
try {
|
|
322
|
+
const hubServerCertsResult = await axios.get(CONNECTION_MANAGER.API_URL + '/api/environments/' + environmentId + '/hub/servercerts', { headers: { Cookie: currentCookies[0], 'Content-Type': 'application/json' } })
|
|
323
|
+
if (hubServerCertsResult.status === 200) {
|
|
324
|
+
hubServerCerts = hubServerCertsResult.data
|
|
325
|
+
}
|
|
326
|
+
} catch (err) {}
|
|
327
|
+
|
|
328
|
+
const newHubServerCerts = {
|
|
329
|
+
rootCertificate: rootCert,
|
|
330
|
+
intermediateChain,
|
|
331
|
+
serverCertificate: serverCert
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
// Update if the certificates are not same
|
|
335
|
+
if (hubServerCerts) {
|
|
336
|
+
if (hubServerCerts.rootCertificate !== rootCert || hubServerCerts.intermediateChain !== intermediateChain || hubServerCerts.serverCertificate !== serverCert) {
|
|
337
|
+
try {
|
|
338
|
+
const hubServerCertsUpdateResponse = await axios.put(CONNECTION_MANAGER.API_URL + '/api/environments/' + environmentId + '/hub/servercerts', newHubServerCerts, { headers: { Cookie: currentCookies[0], 'Content-Type': 'application/json' } })
|
|
339
|
+
if (hubServerCertsUpdateResponse.status === 200) {
|
|
340
|
+
customLogger.logMessage('info', 'Hub Server certs updated', { notification: false })
|
|
341
|
+
} else {
|
|
342
|
+
customLogger.logMessage('error', 'Some error updating Hub server certs', { notification: false })
|
|
343
|
+
}
|
|
344
|
+
} catch (err) {
|
|
345
|
+
customLogger.logMessage('error', 'Some error updating Hub server certs', { additionalData: err, notification: false })
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
} else {
|
|
349
|
+
try {
|
|
350
|
+
const hubServerCertsCreateResponse = await axios.post(CONNECTION_MANAGER.API_URL + '/api/environments/' + environmentId + '/hub/servercerts', newHubServerCerts, { headers: { Cookie: currentCookies[0], 'Content-Type': 'application/json' } })
|
|
351
|
+
if (hubServerCertsCreateResponse.status === 200) {
|
|
352
|
+
customLogger.logMessage('info', 'Hub Server certs created', { notification: false })
|
|
353
|
+
} else {
|
|
354
|
+
customLogger.logMessage('error', 'Some error creating Hub server certs', { notification: false })
|
|
355
|
+
}
|
|
356
|
+
} catch (err) {
|
|
357
|
+
customLogger.logMessage('error', 'Some error creating Hub server certs', { additionalData: err, notification: false })
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
const checkDfspServerCerts = async (environmentId, dfspId) => {
|
|
363
|
+
// Check for any new CSRs those need to be signed
|
|
364
|
+
try {
|
|
365
|
+
const dfspServerCertsResult = await axios.get(CONNECTION_MANAGER.API_URL + '/api/environments/' + environmentId + '/dfsps/' + dfspId + '/servercerts', { headers: { Cookie: currentCookies[0], 'Content-Type': 'application/json' } })
|
|
366
|
+
if (dfspServerCertsResult.status === 200 && dfspServerCertsResult.data.validationState === 'VALID') {
|
|
367
|
+
currentTlsConfig.dfsps[dfspId].dfspServerCaRootCert = dfspServerCertsResult.data.rootCertificate
|
|
368
|
+
currentTlsConfig.dfsps[dfspId].dfspServerCaIntermediateCert = dfspServerCertsResult.data.intermediateChain
|
|
369
|
+
currentTlsConfig.dfsps[dfspId].dfspServerCert = dfspServerCertsResult.data.serverCertificate
|
|
370
|
+
await setTLSConfig()
|
|
371
|
+
}
|
|
372
|
+
} catch (err) {}
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
const tlsLoadHubServerCertificates = async () => {
|
|
376
|
+
// Read Hub Server root CA
|
|
377
|
+
const tmpHubServerCaRootCert = await readFileAsync('secrets/tls/hub_server_cacert.pem')
|
|
378
|
+
currentTlsConfig.hubServerCaRootCert = tmpHubServerCaRootCert.toString()
|
|
379
|
+
// Read Hub server cert
|
|
380
|
+
const tmpHubServerCert = await readFileAsync('secrets/tls/hub_server_cert.pem')
|
|
381
|
+
currentTlsConfig.hubServerCert = tmpHubServerCert.toString()
|
|
382
|
+
// Read Hub server key
|
|
383
|
+
const tmpHubServerKey = await readFileAsync('secrets/tls/hub_server_key.key')
|
|
384
|
+
currentTlsConfig.hubServerKey = tmpHubServerKey.toString()
|
|
385
|
+
|
|
386
|
+
await setTLSConfig()
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
const tlsChecker = async () => {
|
|
390
|
+
// Initialize HUB CA
|
|
391
|
+
currentTlsConfig.hubCaCert = await initHubCa(currentEnvironment.id)
|
|
392
|
+
|
|
393
|
+
const dfspList = await dfspDB.getDFSPList(DEFAULT_TESTING_TOOLKIT_FSPID)
|
|
394
|
+
for (let i = 0; i < dfspList.length; i++) {
|
|
395
|
+
// TODO: Download DFSP CA and place it in trusted store
|
|
396
|
+
await checkDfspCa(currentEnvironment.id, dfspList[i].id)
|
|
397
|
+
|
|
398
|
+
// Check for DFSP CSRs
|
|
399
|
+
await checkDfspCsrs(currentEnvironment.id, dfspList[i].id)
|
|
400
|
+
|
|
401
|
+
// Upload HUB CSRs and also Check for Signed HUB CSRs and get outbound certificate
|
|
402
|
+
await checkHubCsrs(currentEnvironment.id, dfspList[i].id)
|
|
403
|
+
|
|
404
|
+
// Check for DFSP Server root CA and server cert
|
|
405
|
+
await checkDfspServerCerts(currentEnvironment.id, dfspList[i].id)
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
// Read Hub Server Certificates
|
|
409
|
+
await tlsLoadHubServerCertificates()
|
|
410
|
+
|
|
411
|
+
// Upload Hub Server root CA and Hub Server cert
|
|
412
|
+
await uploadHubServerCerts(currentEnvironment.id, currentTlsConfig.hubServerCaRootCert, null, currentTlsConfig.hubServerCert)
|
|
413
|
+
|
|
414
|
+
// Read Hub Client Key
|
|
415
|
+
const hubClientKeyData = await readFileAsync('secrets/tls/hub_client_key.key')
|
|
416
|
+
currentTlsConfig.hubClientKey = hubClientKeyData.toString()
|
|
417
|
+
await setTLSConfig()
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
const endpointChecker = async () => {
|
|
421
|
+
// Check whether an environment exists with the name testing-toolkit
|
|
422
|
+
try {
|
|
423
|
+
const dfspsResult = await axios.get(CONNECTION_MANAGER.API_URL + '/api/environments/' + currentEnvironment.id + '/dfsps', { headers: { Cookie: currentCookies[0], 'Content-Type': 'application/json' } })
|
|
424
|
+
if (dfspsResult.status === 200) {
|
|
425
|
+
const dfspList = dfspsResult.data
|
|
426
|
+
const tempEndpoints = {}
|
|
427
|
+
// Iterate through all dfsps and get the endpoints
|
|
428
|
+
for (let i = 0; i < dfspList.length; i++) {
|
|
429
|
+
const dfspId = dfspList[i].id
|
|
430
|
+
const endpointResult = await axios.get(CONNECTION_MANAGER.API_URL + '/api/environments/' + currentEnvironment.id + '/dfsps/' + dfspId + '/endpoints', { headers: { Cookie: currentCookies[0], 'Content-Type': 'application/json' } })
|
|
431
|
+
if (endpointResult.status === 200) {
|
|
432
|
+
const fetchedEndpoints = endpointResult.data
|
|
433
|
+
for (let j = 0; j < fetchedEndpoints.length; j++) {
|
|
434
|
+
if (fetchedEndpoints[j].state === 'NEW') {
|
|
435
|
+
// Confirm endpoint
|
|
436
|
+
await axios.post(CONNECTION_MANAGER.API_URL + '/api/environments/' + currentEnvironment.id + '/dfsps/' + dfspId + '/endpoints/' + fetchedEndpoints[j].id + '/confirmation', null, { headers: { Cookie: currentCookies[0], 'Content-Type': 'application/json' } })
|
|
437
|
+
}
|
|
438
|
+
if (fetchedEndpoints[j].direction === 'INGRESS' && fetchedEndpoints[j].type === 'URL') {
|
|
439
|
+
// Store the URL for this DFSP
|
|
440
|
+
tempEndpoints[dfspId] = fetchedEndpoints[j].value.url
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
if (!_.isEqual(tempEndpoints, currentEndpoints.dfspEndpoints)) {
|
|
446
|
+
currentEndpoints.dfspEndpoints = tempEndpoints
|
|
447
|
+
await setEndpointsConfig()
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
} catch (err) {}
|
|
451
|
+
return currentEndpoints
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
const checkConnectionManager = async () => {
|
|
455
|
+
const user = {
|
|
456
|
+
dfspId: DEFAULT_TESTING_TOOLKIT_FSPID
|
|
457
|
+
}
|
|
458
|
+
const userConfig = await Config.getUserConfig(user)
|
|
459
|
+
const systemConfig = Config.getSystemConfig()
|
|
460
|
+
CONNECTION_MANAGER = systemConfig.CONNECTION_MANAGER
|
|
461
|
+
if (CONNECTION_MANAGER.AUTH_ENABLED) {
|
|
462
|
+
// Get the cookies from object store
|
|
463
|
+
currentCookies = await auth(user)
|
|
464
|
+
}
|
|
465
|
+
if (userConfig.JWS_SIGN || userConfig.VALIDATE_INBOUND_JWS) {
|
|
466
|
+
try {
|
|
467
|
+
// Get private key for signing
|
|
468
|
+
currentJWSConfig.testingToolkitDfspPrivateKey = await readFileAsync('secrets/privatekey.pem')
|
|
469
|
+
await setJWSConfig()
|
|
470
|
+
// Initialize HUB environment
|
|
471
|
+
await initDFSPHelper()
|
|
472
|
+
// Initialize JWS certificate for testing toolkit dfsp
|
|
473
|
+
const certData = await readFileAsync('secrets/publickey.cer')
|
|
474
|
+
currentJWSConfig.testingToolkitDfspCerts = await initJWSCertificate(currentEnvironment.id, DEFAULT_TESTING_TOOLKIT_FSPID, certData.toString(), null)
|
|
475
|
+
await setJWSConfig()
|
|
476
|
+
// Fetch the user DFSP Jws certs once and then periodically check
|
|
477
|
+
const dfspList = await dfspDB.getDFSPList(DEFAULT_TESTING_TOOLKIT_FSPID)
|
|
478
|
+
for (let i = 0; i < dfspList.length; i++) {
|
|
479
|
+
await fetchUserDFSPJwsCerts(currentEnvironment.id, dfspList[i].id)
|
|
480
|
+
}
|
|
481
|
+
} catch (err) {
|
|
482
|
+
customLogger.logMessage('error', err.message, { additionalData: err, notification: false })
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
if (Config.getSystemConfig().OUTBOUND_MUTUAL_TLS_ENABLED || Config.getSystemConfig().INBOUND_MUTUAL_TLS_ENABLED) {
|
|
487
|
+
try {
|
|
488
|
+
await initDFSPHelper()
|
|
489
|
+
await tlsChecker()
|
|
490
|
+
} catch (err) {
|
|
491
|
+
customLogger.logMessage('error', err.message, { additionalData: err, notification: false })
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
if (Config.getSystemConfig().HOSTING_ENABLED) {
|
|
496
|
+
try {
|
|
497
|
+
await initDFSPHelper()
|
|
498
|
+
await endpointChecker()
|
|
499
|
+
} catch (err) {
|
|
500
|
+
customLogger.logMessage('error', err.message, { additionalData: err, notification: false })
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
const initDFSPHelper = async () => {
|
|
506
|
+
// Initialize HUB environment
|
|
507
|
+
await initEnvironment()
|
|
508
|
+
// Initialize the DFSPs
|
|
509
|
+
await initDFSP(currentEnvironment.id, DEFAULT_TESTING_TOOLKIT_FSPID, 'Testing Toolkit DFSP')
|
|
510
|
+
const dfspList = await dfspDB.getDFSPList(DEFAULT_TESTING_TOOLKIT_FSPID)
|
|
511
|
+
for (let i = 0; i < dfspList.length; i++) {
|
|
512
|
+
await initDFSP(currentEnvironment.id, dfspList[i].id, dfspList[i].name)
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
const auth = async () => {
|
|
517
|
+
const loginFormData = {
|
|
518
|
+
username: CONNECTION_MANAGER.HUB_USERNAME,
|
|
519
|
+
password: CONNECTION_MANAGER.HUB_PASSWORD
|
|
520
|
+
}
|
|
521
|
+
let cookies = await objectStore.get('CONNECTION_MANAGER_COOKIES')
|
|
522
|
+
if (Object.keys(cookies).length !== 0) {
|
|
523
|
+
const cookieIsValid = Object.values(cookies).some(cookie => {
|
|
524
|
+
const token = {}
|
|
525
|
+
const cookieItems = cookie.split(';').map(item => item.trim())
|
|
526
|
+
cookieItems.forEach(cookieItem => {
|
|
527
|
+
const cookieElements = cookieItem.split('=').map(item => item.trim())
|
|
528
|
+
if (cookieElements[0] === 'MCM-API_ACCESS_TOKEN') {
|
|
529
|
+
token.accessToken = cookieElements[1]
|
|
530
|
+
} else if (cookieElements[0] === 'expires') {
|
|
531
|
+
token.expires = Date.parse(cookieElements[1])
|
|
532
|
+
}
|
|
533
|
+
})
|
|
534
|
+
if (token.accessToken && token.expires) {
|
|
535
|
+
return (Date.now() < token.expires - (60 * 1000))
|
|
536
|
+
}
|
|
537
|
+
return false
|
|
538
|
+
})
|
|
539
|
+
if (cookieIsValid) {
|
|
540
|
+
return cookies
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
const loginResp = await axios.post(CONNECTION_MANAGER.API_URL + '/api/login', querystring.stringify(loginFormData), { headers: { 'Content-Type': 'application/x-www-form-urlencoded' } })
|
|
544
|
+
if (loginResp.status === 200) {
|
|
545
|
+
if (loginResp.headers['set-cookie']) {
|
|
546
|
+
await objectStore.set('CONNECTION_MANAGER_COOKIES', loginResp.headers['set-cookie'])
|
|
547
|
+
cookies = await objectStore.get('CONNECTION_MANAGER_COOKIES')
|
|
548
|
+
}
|
|
549
|
+
} else {
|
|
550
|
+
throw new Error('Some error while login to the MCM as hub')
|
|
551
|
+
}
|
|
552
|
+
return cookies
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
const startLoop = async () => {
|
|
556
|
+
try {
|
|
557
|
+
await checkConnectionManager()
|
|
558
|
+
} catch (err) {
|
|
559
|
+
console.log('Error connection manager: ' + err.message)
|
|
560
|
+
}
|
|
561
|
+
setTimeout(startLoop, CM_CHECK_INTERVAL)
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
const initialize = async () => {
|
|
565
|
+
await objectStore.init()
|
|
566
|
+
startLoop()
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
const waitForTlsHubCerts = async (interval = 2) => {
|
|
570
|
+
for (let i = 0; i < 10; i++) {
|
|
571
|
+
if (currentTlsConfig.hubCaCert && currentTlsConfig.hubServerCert && currentTlsConfig.hubServerKey) {
|
|
572
|
+
return true
|
|
573
|
+
}
|
|
574
|
+
await new Promise(resolve => setTimeout(resolve, interval * 1000))
|
|
575
|
+
}
|
|
576
|
+
throw new Error('Timeout Hub Init')
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
const getTestingToolkitDfspJWSCerts = async () => {
|
|
580
|
+
const jwsConfig = await objectStore.get('jwsConfig')
|
|
581
|
+
return jwsConfig.testingToolkitDfspCerts ? jwsConfig.testingToolkitDfspCerts.jwsCertificate : null
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
const getTestingToolkitDfspJWSPrivateKey = async () => {
|
|
585
|
+
const jwsConfig = await objectStore.get('jwsConfig')
|
|
586
|
+
return jwsConfig.testingToolkitDfspPrivateKey
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
const getUserDfspJWSCerts = async (dfspId) => {
|
|
590
|
+
const jwsConfig = await objectStore.get('jwsConfig')
|
|
591
|
+
return jwsConfig.dfsps[dfspId] ? jwsConfig.dfsps[dfspId].jwsCertificate : null
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
const getTlsConfig = async () => {
|
|
595
|
+
const config = await objectStore.get('tlsConfig')
|
|
596
|
+
return config
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
const getEndpointsConfig = async () => {
|
|
600
|
+
const config = await objectStore.get('endpointsConfig')
|
|
601
|
+
return config
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
const setJWSConfig = async () => {
|
|
605
|
+
await objectStore.set('jwsConfig', currentJWSConfig)
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
const setTLSConfig = async () => {
|
|
609
|
+
await objectStore.set('tlsConfig', currentTlsConfig)
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
const setEndpointsConfig = async () => {
|
|
613
|
+
await objectStore.set('endpointsConfig', currentEndpoints)
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
module.exports = {
|
|
617
|
+
initialize,
|
|
618
|
+
checkConnectionManager,
|
|
619
|
+
getTestingToolkitDfspJWSCerts,
|
|
620
|
+
getUserDfspJWSCerts,
|
|
621
|
+
getTestingToolkitDfspJWSPrivateKey,
|
|
622
|
+
getTlsConfig,
|
|
623
|
+
getEndpointsConfig,
|
|
624
|
+
waitForTlsHubCerts
|
|
625
|
+
}
|