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.
Files changed (319) hide show
  1. package/.dockerignore +10 -0
  2. package/.grype.yaml +16 -0
  3. package/.ncurc.yaml +9 -0
  4. package/.nvmrc +1 -0
  5. package/.versionrc.js +16 -0
  6. package/CHANGELOG.md +504 -0
  7. package/CODEOWNERS +30 -0
  8. package/Dockerfile +42 -0
  9. package/Dockerfile-newman +13 -0
  10. package/LICENSE.md +9 -0
  11. package/README.md +119 -0
  12. package/assets/diagrams/architectural/architectural-diagram.svg +3 -0
  13. package/assets/diagrams/flow/flow-diagram.svg +3 -0
  14. package/assets/images/Sample-Response-Failure.png +0 -0
  15. package/assets/images/Screenshot 2020-04-16 at 22.58.04.png +0 -0
  16. package/assets/images/TLS-Enabled-on-Environment.png +0 -0
  17. package/assets/images/adapter-mutual-tls-enabled.png +0 -0
  18. package/assets/images/add-additional-input-values.png +0 -0
  19. package/assets/images/add-condition-button.png +0 -0
  20. package/assets/images/add-new-assertion.png +0 -0
  21. package/assets/images/add-new-input-value.png +0 -0
  22. package/assets/images/add-new-input-variable.png +0 -0
  23. package/assets/images/additional-transfers.png +0 -0
  24. package/assets/images/api-provisioning-add-new-api-confirmation.png +0 -0
  25. package/assets/images/api-provisioning-file-input-window.png +0 -0
  26. package/assets/images/api-provisioning-list-apis-view.png +0 -0
  27. package/assets/images/api-provisioning-menu-item.png +0 -0
  28. package/assets/images/apply_and_restart.jpg +0 -0
  29. package/assets/images/assess-request-or-response.png +0 -0
  30. package/assets/images/assess-response-equation-save.png +0 -0
  31. package/assets/images/assess-response-equation.png +0 -0
  32. package/assets/images/assess-response-status.png +0 -0
  33. package/assets/images/building-new-rules-file.png +0 -0
  34. package/assets/images/callback-rules-screen.png +0 -0
  35. package/assets/images/configurable-parameter-assertion.png +0 -0
  36. package/assets/images/configurable-parameter-currency.png +0 -0
  37. package/assets/images/configurable-parameter.png +0 -0
  38. package/assets/images/connection-manager-ui-opening.png +0 -0
  39. package/assets/images/create-inbound-user-simulator.png +0 -0
  40. package/assets/images/creating-new-rule-file.png +0 -0
  41. package/assets/images/dfsp-client-cacert.png +0 -0
  42. package/assets/images/dfsp-client-submit.png +0 -0
  43. package/assets/images/dfsp-client.png +0 -0
  44. package/assets/images/dfsp-p2p-happy-path.png +0 -0
  45. package/assets/images/dfsp-server-cacert.png +0 -0
  46. package/assets/images/dfsp-server-cert.png +0 -0
  47. package/assets/images/download-report.png +0 -0
  48. package/assets/images/drive_have_not_been_shared.jpg +0 -0
  49. package/assets/images/event-response-options.png +0 -0
  50. package/assets/images/expand-monitoring-messages.png +0 -0
  51. package/assets/images/fixed-response-sample.png +0 -0
  52. package/assets/images/header-selection.png +0 -0
  53. package/assets/images/heap_error_windows.jpg +0 -0
  54. package/assets/images/hosted-mode-docker-compose-intro.png +0 -0
  55. package/assets/images/hub-client-cert.png +0 -0
  56. package/assets/images/import-template.png +0 -0
  57. package/assets/images/inbound-requests-environment.png +0 -0
  58. package/assets/images/inbound-requests-scripts.png +0 -0
  59. package/assets/images/jws-certificate-submit.png +0 -0
  60. package/assets/images/jws-certificate.png +0 -0
  61. package/assets/images/jws-certs-keys.png +0 -0
  62. package/assets/images/jws-hub-certs-keys.png +0 -0
  63. package/assets/images/local-enable-jws-publickey.png +0 -0
  64. package/assets/images/local-mutual-tls-enabled.png +0 -0
  65. package/assets/images/local_drives_to_be_available.jpg +0 -0
  66. package/assets/images/mcm-environment-opening.png +0 -0
  67. package/assets/images/menu-items.png +0 -0
  68. package/assets/images/mock-response-sample.png +0 -0
  69. package/assets/images/monitoring-initial-state.png +0 -0
  70. package/assets/images/monitoring-messages.png +0 -0
  71. package/assets/images/new-empty-assertion.png +0 -0
  72. package/assets/images/opened-imported-template.png +0 -0
  73. package/assets/images/opening-default-settings.png +0 -0
  74. package/assets/images/opening-sync-response-rules.png +0 -0
  75. package/assets/images/opening-view.png +0 -0
  76. package/assets/images/outbound-display-opening-hub.png +0 -0
  77. package/assets/images/outbound-display-opening.png +0 -0
  78. package/assets/images/override-with-environment-variable.png +0 -0
  79. package/assets/images/populate-with-sample-body.png +0 -0
  80. package/assets/images/resource-selection.png +0 -0
  81. package/assets/images/rule-builder-select-api.png +0 -0
  82. package/assets/images/sample-condition-add-configurable-params.png +0 -0
  83. package/assets/images/sample-condition.png +0 -0
  84. package/assets/images/sample-editor.png +0 -0
  85. package/assets/images/sample-request.png +0 -0
  86. package/assets/images/sample-test-assertion.png +0 -0
  87. package/assets/images/send-transfer.png +0 -0
  88. package/assets/images/sending-single-test-case-1.png +0 -0
  89. package/assets/images/sending-single-test-case-2.png +0 -0
  90. package/assets/images/sending-test-cases.png +0 -0
  91. package/assets/images/server-certificates-submitted.png +0 -0
  92. package/assets/images/simulator-response.png +0 -0
  93. package/assets/images/simulator-scheme-adapter-endpoint.png +0 -0
  94. package/assets/images/summarized-view-of-rule.png +0 -0
  95. package/assets/images/template-window.png +0 -0
  96. package/assets/images/test-case-editor-console-log.png +0 -0
  97. package/assets/images/test-case-editor-environment-state.png +0 -0
  98. package/assets/images/test-case-editor-scripts.png +0 -0
  99. package/assets/images/test-case-editor.png +0 -0
  100. package/assets/images/testcase-definition-download.png +0 -0
  101. package/assets/images/testcase-definition-edit-meta-info.png +0 -0
  102. package/assets/images/testing-toolkit-mojaloop-testing-toolkit-endpoint.png +0 -0
  103. package/assets/images/tls-hub-certs-keys.png +0 -0
  104. package/assets/images/tls-jws-enabled-on-environment.png +0 -0
  105. package/assets/images/updated-sample-body-data.png +0 -0
  106. package/assets/images/using-configurable-parameter.png +0 -0
  107. package/assets/images/validation-rules-screen.png +0 -0
  108. package/assets/images/view-response.png +0 -0
  109. package/audit-ci.jsonc +7 -0
  110. package/connection-manager/docker-compose.yml +55 -0
  111. package/database/docker-compose.yml +16 -0
  112. package/docker/hosted-mode/docker-compose.yaml +107 -0
  113. package/docker/hosted-mode/keycloak/keycloak-realm.json +2298 -0
  114. package/docker/hosted-mode/mongo-init.sh +1 -0
  115. package/docker/hosted-mode-tls/docker-compose.yaml +171 -0
  116. package/docker/hosted-mode-tls/keycloak/keycloak-realm.json +2298 -0
  117. package/docker/hosted-mode-tls/mongo-init.sh +1 -0
  118. package/docker-compose.yml +62 -0
  119. package/documents/Mojaloop-Testing-Toolkit.md +296 -0
  120. package/documents/RULES_ENGINE.md +403 -0
  121. package/documents/User-Guide-API-Provisioning.md +121 -0
  122. package/documents/User-Guide-CLI.md +218 -0
  123. package/documents/User-Guide-Connection-Manager.md +282 -0
  124. package/documents/User-Guide-Frequently-Asked-Questions.md +39 -0
  125. package/documents/User-Guide-Hosted-Mode-Docker-Compose.md +110 -0
  126. package/documents/User-Guide-Installation.md +163 -0
  127. package/documents/User-Guide-Mojaloop-Testing-Toolkit.md +642 -0
  128. package/documents/User-Guide-OAuth-Server-Deployment.md +283 -0
  129. package/documents/User-Guide-Onboarding-DFSP.md +197 -0
  130. package/documents/User-Guide-Onboarding-HUB.md +191 -0
  131. package/documents/User-Guide.md +53 -0
  132. package/examples/collections/dfsp/p2p_failed_tests.json +7161 -0
  133. package/examples/collections/dfsp/p2p_fx_happy_path.json +502 -0
  134. package/examples/collections/dfsp/p2p_happy_path.json +350 -0
  135. package/examples/collections/dfsp/p2p_happy_path_extended.json +6106 -0
  136. package/examples/collections/dfsp/p2p_happy_path_jws.json +511 -0
  137. package/examples/collections/dfsp/p2p_payee_assertions_websocket.json +441 -0
  138. package/examples/collections/dfsp/sample.json +5029 -0
  139. package/examples/collections/dfsp/transaction_request_service.json +240 -0
  140. package/examples/collections/fxp/FXP.json +264 -0
  141. package/examples/collections/fxp/SDK_backend.json +98 -0
  142. package/examples/collections/fxp/SDK_outbound.json +163 -0
  143. package/examples/collections/hub/hub_01_p2p_happy_path/hub_p2p_receive_quote.json +400 -0
  144. package/examples/collections/hub/hub_01_p2p_happy_path/hub_p2p_send_quote.json +395 -0
  145. package/examples/collections/hub/hub_02_block_transfer/hub_block_transfer.json +393 -0
  146. package/examples/collections/hub/hub_03_funds_in_out/hub_funds_in.json +224 -0
  147. package/examples/collections/hub/hub_03_funds_in_out/hub_funds_out.json +780 -0
  148. package/examples/collections/hub/hub_04_settlements/hub_settlements.json +3138 -0
  149. package/examples/collections/hub/hub_05_transfer_negative_scenarios/hub_transfer_negative_payee_abort.json +475 -0
  150. package/examples/collections/hub/hub_05_transfer_negative_scenarios/hub_transfer_negative_payee_invalid_fulfillment.json +370 -0
  151. package/examples/collections/hub/hub_05_transfer_negative_scenarios/hub_transfer_negative_transfer_timeout.json +262 -0
  152. package/examples/collections/hub/hub_06_transaction_requests_service/hub_trs_authorizations.json +117 -0
  153. package/examples/collections/hub/hub_06_transaction_requests_service/hub_trs_error_framework.json +591 -0
  154. package/examples/collections/hub/hub_06_transaction_requests_service/hub_trs_received_state.json +379 -0
  155. package/examples/collections/hub/hub_06_transaction_requests_service/hub_trs_reject_state.json +361 -0
  156. package/examples/collections/hub/hub_07_quoting_service.json +525 -0
  157. package/examples/collections/hub/hub_08_participant_inactive_stop_transfers.json +706 -0
  158. package/examples/collections/hub/hub_09_duplicate_handling_transfers.json +1377 -0
  159. package/examples/collections/hub/hub_10_on_us_transfers.json +245 -0
  160. package/examples/collections/hub/hub_11_accented_and_spl_chars.json +629 -0
  161. package/examples/collections/hub/hub_12_fspiop_version_1.1.json +646 -0
  162. package/examples/collections/hub/hub_13_bulk_transfers.json +1857 -0
  163. package/examples/collections/iso20022/self_referencing_iso20022.json +926 -0
  164. package/examples/collections/provisioning/testingtoolkitdfsp.json +904 -0
  165. package/examples/environments/dfsp_local_environment.json +46 -0
  166. package/examples/environments/hub_local_environment.json +57 -0
  167. package/jest.config.js +17 -0
  168. package/package.json +199 -0
  169. package/sbom-v18.12.4.csv +1553 -0
  170. package/secrets/keygen.sh +5 -0
  171. package/secrets/privatekey.pem +27 -0
  172. package/secrets/publickey.cer +21 -0
  173. package/secrets/tls/01.pem +132 -0
  174. package/secrets/tls/createSecrets.sh +20 -0
  175. package/secrets/tls/hub_client.csr +32 -0
  176. package/secrets/tls/hub_client_cacert.pem +35 -0
  177. package/secrets/tls/hub_client_cakey.pem +52 -0
  178. package/secrets/tls/hub_client_key.key +52 -0
  179. package/secrets/tls/hub_server.csr +31 -0
  180. package/secrets/tls/hub_server_cacert.pem +35 -0
  181. package/secrets/tls/hub_server_cakey.pem +52 -0
  182. package/secrets/tls/hub_server_cert.pem +132 -0
  183. package/secrets/tls/hub_server_key.key +52 -0
  184. package/secrets/tls/index.txt +1 -0
  185. package/secrets/tls/index.txt.attr +1 -0
  186. package/secrets/tls/openssl-client.cnf +36 -0
  187. package/secrets/tls/openssl-clientca.cnf +71 -0
  188. package/secrets/tls/openssl-server.cnf +39 -0
  189. package/secrets/tls/openssl-serverca.cnf +71 -0
  190. package/secrets/tls/serial.txt +1 -0
  191. package/spec_files/api_definitions/als_admin_1.1/api_spec.yaml +804 -0
  192. package/spec_files/api_definitions/central_admin_1.0/api_spec.yaml +1850 -0
  193. package/spec_files/api_definitions/central_admin_1.0/response_map.json +96 -0
  194. package/spec_files/api_definitions/central_admin_old_9.3/api_spec.yaml +2467 -0
  195. package/spec_files/api_definitions/central_admin_old_9.3/response_map.json +96 -0
  196. package/spec_files/api_definitions/fspiop_1.0/api_spec.yaml +4187 -0
  197. package/spec_files/api_definitions/fspiop_1.0/callback_map.json +568 -0
  198. package/spec_files/api_definitions/fspiop_1.0/mockRef.json +79 -0
  199. package/spec_files/api_definitions/fspiop_1.0/trigger_templates/transaction_request_followup.json +126 -0
  200. package/spec_files/api_definitions/fspiop_1.0/trigger_templates/transaction_request_followup_quotes_only.json +97 -0
  201. package/spec_files/api_definitions/fspiop_1.1/api_spec.yaml +3778 -0
  202. package/spec_files/api_definitions/fspiop_1.1/callback_map.json +568 -0
  203. package/spec_files/api_definitions/fspiop_1.1/mockRef.json +79 -0
  204. package/spec_files/api_definitions/fspiop_1.1/trigger_templates/transaction_request_followup.json +125 -0
  205. package/spec_files/api_definitions/fspiop_2.0/api_spec.yaml +4839 -0
  206. package/spec_files/api_definitions/fspiop_2.0/callback_map.json +716 -0
  207. package/spec_files/api_definitions/fspiop_2.0/mockRef.json +79 -0
  208. package/spec_files/api_definitions/fspiop_2.0/trigger_templates/transaction_request_followup.json +125 -0
  209. package/spec_files/api_definitions/fspiop_2.0_iso20022/api_spec.yaml +8331 -0
  210. package/spec_files/api_definitions/fspiop_2.0_iso20022/callback_map.json +508 -0
  211. package/spec_files/api_definitions/fspiop_2.0_iso20022/mockRef.json +66 -0
  212. package/spec_files/api_definitions/fx-api_2.0/api_spec.yaml +1768 -0
  213. package/spec_files/api_definitions/fx-api_2.0/callback_map.json +188 -0
  214. package/spec_files/api_definitions/fx-api_2.0/mockRef.json +83 -0
  215. package/spec_files/api_definitions/mojaloop_sdk_outbound_scheme_adapter_1.0/api_spec.yaml +2612 -0
  216. package/spec_files/api_definitions/mojaloop_sdk_outbound_scheme_adapter_1.0/mockRef.json +22 -0
  217. package/spec_files/api_definitions/mojaloop_sdk_outbound_scheme_adapter_1.0/response_map.json +35 -0
  218. package/spec_files/api_definitions/mojaloop_simulator_0.1/api_spec.yaml +225 -0
  219. package/spec_files/api_definitions/mojaloop_simulator_sim_1.4/api_spec.yaml +1087 -0
  220. package/spec_files/api_definitions/mojaloop_simulator_sim_1.4/mockRef.json +75 -0
  221. package/spec_files/api_definitions/mojaloop_simulator_sim_1.4/response_map.json +55 -0
  222. package/spec_files/api_definitions/payment_manager_1.4/api_spec.yaml +1389 -0
  223. package/spec_files/api_definitions/sdk-scheme-adapter-backend-v2_1_0-openapi3-snippets_2.1/api_spec.yaml +2834 -0
  224. package/spec_files/api_definitions/sdk-scheme-adapter-outbound-v2_1_0-openapi3-snippets_2.1/api_spec.yaml +3449 -0
  225. package/spec_files/api_definitions/settlements_1.0/api_spec.yaml +983 -0
  226. package/spec_files/api_definitions/settlements_1.0/mockRef.json +38 -0
  227. package/spec_files/api_definitions/settlements_1.0/response_map.json +34 -0
  228. package/spec_files/api_definitions/settlements_2.0/api_spec.yaml +1001 -0
  229. package/spec_files/api_definitions/settlements_2.0/mockRef.json +38 -0
  230. package/spec_files/api_definitions/settlements_2.0/response_map.json +34 -0
  231. package/spec_files/api_definitions/thirdparty_sdk_outbound_0.1/api_spec.yaml +2139 -0
  232. package/spec_files/reports/templates/newman/html_template.html +1202 -0
  233. package/spec_files/reports/templates/newman/pdf_template.html +790 -0
  234. package/spec_files/reports/templates/testcase_definition/table_view.html +1602 -0
  235. package/spec_files/rules_callback/config.json +3 -0
  236. package/spec_files/rules_callback/default.json +2698 -0
  237. package/spec_files/rules_callback/p2p-limit.json +129 -0
  238. package/spec_files/rules_forward/config.json +3 -0
  239. package/spec_files/rules_forward/default.json +482 -0
  240. package/spec_files/rules_response/config.json +3 -0
  241. package/spec_files/rules_response/default.json +295 -0
  242. package/spec_files/rules_validation/config.json +3 -0
  243. package/spec_files/rules_validation/default.json +1 -0
  244. package/spec_files/rules_validation/p2p-limit.json +55 -0
  245. package/spec_files/system_config.json +175 -0
  246. package/spec_files/user_config.json +109 -0
  247. package/src/index.js +67 -0
  248. package/src/lib/MyEventEmitter.js +54 -0
  249. package/src/lib/api-management.js +143 -0
  250. package/src/lib/api-routes/config.js +83 -0
  251. package/src/lib/api-routes/history.js +139 -0
  252. package/src/lib/api-routes/keycloak.js +54 -0
  253. package/src/lib/api-routes/longpolling.js +70 -0
  254. package/src/lib/api-routes/oauth2.js +149 -0
  255. package/src/lib/api-routes/objectstore.js +53 -0
  256. package/src/lib/api-routes/openapi.js +224 -0
  257. package/src/lib/api-routes/outbound.js +134 -0
  258. package/src/lib/api-routes/reports.js +72 -0
  259. package/src/lib/api-routes/rules.js +356 -0
  260. package/src/lib/api-routes/samples.js +92 -0
  261. package/src/lib/api-routes/server-logs.js +44 -0
  262. package/src/lib/api-routes/settings.js +71 -0
  263. package/src/lib/api-server.js +135 -0
  264. package/src/lib/arrayStore.js +101 -0
  265. package/src/lib/callbackHandler.js +201 -0
  266. package/src/lib/config.js +177 -0
  267. package/src/lib/configuration-providers/mb-connection-manager.js +625 -0
  268. package/src/lib/db/adapters/dbAdapter.js +184 -0
  269. package/src/lib/db/dfspMockUsers.js +64 -0
  270. package/src/lib/db/models/mongoDBWrapper.js +78 -0
  271. package/src/lib/eventListenerClient/inboundEventListener.js +176 -0
  272. package/src/lib/fileAdapter.js +57 -0
  273. package/src/lib/httpAgentStore.js +135 -0
  274. package/src/lib/importExport.js +186 -0
  275. package/src/lib/jws/JwsSigning.js +141 -0
  276. package/src/lib/loadSamples.js +128 -0
  277. package/src/lib/logger.js +20 -0
  278. package/src/lib/longpollingEmitter.js +56 -0
  279. package/src/lib/metrics.js +51 -0
  280. package/src/lib/mocking/custom-functions/generic.js +57 -0
  281. package/src/lib/mocking/middleware-functions/ilpModel.js +238 -0
  282. package/src/lib/mocking/middleware-functions/quotesAssociation.js +75 -0
  283. package/src/lib/mocking/middleware-functions/transactionRequestsService.js +78 -0
  284. package/src/lib/mocking/openApiDefinitionsModel.js +64 -0
  285. package/src/lib/mocking/openApiMockHandler.js +466 -0
  286. package/src/lib/mocking/openApiRulesEngine.js +492 -0
  287. package/src/lib/mocking/openApiVersionTools.js +136 -0
  288. package/src/lib/mocking/transformers/fspiopToISO20022.js +230 -0
  289. package/src/lib/mocking/transformers/index.js +41 -0
  290. package/src/lib/notificationEmitter.js +64 -0
  291. package/src/lib/oauth/KeycloakHelper.js +220 -0
  292. package/src/lib/oauth/LoginService.js +133 -0
  293. package/src/lib/oauth/OAuthHelper.js +181 -0
  294. package/src/lib/oauth/OAuthValidator.js +118 -0
  295. package/src/lib/oauth/Wso2Client.js +64 -0
  296. package/src/lib/objectStore/inMemoryImpl.js +50 -0
  297. package/src/lib/objectStore/objectStoreInterface.js +51 -0
  298. package/src/lib/objectStore.js +122 -0
  299. package/src/lib/report-generator/generator.js +126 -0
  300. package/src/lib/report-generator/helpers.js +154 -0
  301. package/src/lib/requestLogger.js +190 -0
  302. package/src/lib/resources/wso2carbon-publickey.cert +20 -0
  303. package/src/lib/rulesEngine.js +95 -0
  304. package/src/lib/rulesEngineModel.js +463 -0
  305. package/src/lib/scripting-engines/postman-sandbox.js +142 -0
  306. package/src/lib/scripting-engines/vm-javascript-sandbox.js +294 -0
  307. package/src/lib/server-logs/adapters/elastic-search.js +102 -0
  308. package/src/lib/server-logs/adapters/grafana.js +0 -0
  309. package/src/lib/server-logs/index.js +75 -0
  310. package/src/lib/socket-server.js +55 -0
  311. package/src/lib/storageAdapter.js +109 -0
  312. package/src/lib/test-outbound/TestCaseRunner.js +173 -0
  313. package/src/lib/test-outbound/getTracing.js +19 -0
  314. package/src/lib/test-outbound/outbound-initiator.js +1107 -0
  315. package/src/lib/uniqueIdGenerator.js +35 -0
  316. package/src/lib/utils.js +89 -0
  317. package/src/lib/utilsInternal.js +56 -0
  318. package/src/lib/webSocketClient/WebSocketClientManager.js +197 -0
  319. package/src/server.js +218 -0
@@ -0,0 +1,403 @@
1
+ Rules Engine
2
+ ============
3
+
4
+ Table of Contents
5
+ =================
6
+
7
+ - [Json Rules Engine:](#json-rules-engine)
8
+ - [Implementation in Self Testing Toolkit](#implementation-in-self-testing-toolkit)
9
+ - [Rules File](#rules-file)
10
+ - [Defining Conditions](#defining-conditions)
11
+ - [Events](#events)
12
+ - [FIXED_ERROR_CALLBACK and FIXED_CALLBACK](#fixed_error_callback-and-fixed_callback)
13
+ - [Configurable parameters](#configurable-parameters)
14
+ - [MOCK_ERROR_CALLBACK and MOCK_CALLBACK](#mock_error_callback-and-mock_callback)
15
+ - [Priority of rules](#priority-of-rules)
16
+
17
+ This Self Testing Toolkit implemented "Rules Engine" by taking advantage of ***Json Rules Engine***.
18
+
19
+ ## Json Rules Engine:
20
+ *"Json Rules Engine"* is a powerful, lightweight rules engine. Rules are composed of simple json structures, making them human readable and easy to persist.
21
+
22
+ Rules are composed of two components: conditions and events. Conditions are a set of requirements that must be met to trigger the rule's event.
23
+
24
+ You can refer https://www.npmjs.com/package/json-rules-engine for further information on JRE.
25
+
26
+ ## Implementation in Self Testing Toolkit
27
+
28
+ The rules in self testing toolkit are implemented at two levels.
29
+ * One for validating the incoming request and send error callback if the validation rule matches.
30
+ * Another for generating callbacks if the callback rule matches.
31
+
32
+ In both cases the conditions syntax is same as per the Json Rules Engine, where as the event types will be different for the two levels.
33
+
34
+ ### Rules File
35
+ The rules file is a json file with an array of individual rules.
36
+
37
+ A typical validation rule file syntax is like below.
38
+ ```
39
+ [
40
+ {
41
+ "ruleId": 1,
42
+ "description": "If the transfer amount is equal to 2 USD, send a fixed error callback",
43
+ "conditions": {
44
+ "all": [
45
+ {
46
+ "fact": "path",
47
+ "operator": "equal",
48
+ "value": "/transfers"
49
+ },
50
+ {
51
+ "fact": "method",
52
+ "operator": "equal",
53
+ "value": "post"
54
+ },
55
+ {
56
+ "fact": "body",
57
+ "operator": "equal",
58
+ "value": "2",
59
+ "path": "amount.amount"
60
+ }
61
+ ]
62
+ },
63
+ "event": {
64
+ "type": "FIXED_ERROR_CALLBACK",
65
+ "params": {
66
+ "path": "/transfers/{$request.body.transferId}/error",
67
+ "method": "put",
68
+ "headers": {},
69
+ "delay": 100,
70
+ "body": {
71
+ "errorInformation": {
72
+ "errorCode": "5001",
73
+ "errorDescription": "The amount is less than the required amount"
74
+ }
75
+ }
76
+ }
77
+ }
78
+ }
79
+ ]
80
+ ```
81
+
82
+ ### Defining Conditions
83
+
84
+ Conditions can be defined with either "all" or "any" type of arrays. In each array there are objects containing three basic properties "fact", "operator" and "value".
85
+
86
+ * Fact - facts are the variable names that can be one of the following
87
+ * path - The request path
88
+
89
+ Example: /transfers, /parties/MSISDN/9876543210 ... etc
90
+
91
+ * method - The http method of the request in lowercase
92
+
93
+ Example: get, post ... etc
94
+
95
+ * body - The request body object. The properties of the body can be specified using a *condition helper* called **"path"**.
96
+
97
+ Example: amount.amount from the body '{ "amount": { "amount": 20, "type": "USD" } }' can be compared with the following condition
98
+ ```
99
+ {
100
+ "fact": "body",
101
+ "operator": "equal",
102
+ "value": "100",
103
+ "path": "amount.amount"
104
+ }
105
+ ```
106
+
107
+ * pathParams - By using this the path parameter values from the request can be compared.
108
+
109
+ Example: Type & ID of pathParams from the get request /parties/{Type}/{ID}
110
+
111
+ * queryParams - By using this the query parameter values from the request can be compared.
112
+
113
+ Example: 'state' of queryParams from the get request /settlementWindows?state=OPEN
114
+
115
+ * operationPath - This is used for matching the path syntax from open API file
116
+
117
+ Example: operationPath contains the value /parties/{Type}/{ID} instead of /parties/MSISDN/9876543210 which can actually be found in the fact 'path'.
118
+
119
+ * Operator - The ```operator``` compares the value returned by the ```fact``` to what is stored in the ```value``` property. If the result is truthy, the condition passes.
120
+ There are number of operators available to compare the values
121
+
122
+ * String and Numeric operators:
123
+
124
+ ```equal``` - _fact_ must equal _value_
125
+
126
+ ```notEqual``` - _fact_ must not equal _value_
127
+
128
+ _these operators use strict equality (===) and inequality (!==)_
129
+
130
+ * Numeric operators:
131
+
132
+ ```lessThan``` - _fact_ must be less than _value_
133
+
134
+ ```lessThanInclusive```- _fact_ must be less than or equal to _value_
135
+
136
+ ```greaterThan``` - _fact_ must be greater than _value_
137
+
138
+ ```greaterThanInclusive```- _fact_ must be greater than or equal to _value_
139
+
140
+ * String Numeric operators:
141
+
142
+ *(These operators can be used if the type fo the property is string, but we want to parse it to integer and compare)*
143
+
144
+ ```numericEqual``` - _fact_ must equal _value_
145
+ ```numericNotEqual``` - _fact_ must not equal _value_
146
+ ```numericLessThan``` - _fact_ must be less than _value_
147
+
148
+ ```numericLessThanInclusive```- _fact_ must be less than or equal to _value_
149
+
150
+ ```numericGreaterThan``` - _fact_ must be greater than _value_
151
+
152
+ ```numericGreaterThanInclusive```- _fact_ must be greater than or equal to _value_
153
+
154
+ * Array operators:
155
+
156
+ ```in``` - _fact_ must be included in _value_ (an array)
157
+
158
+ ```notIn``` - _fact_ must not be included in _value_ (an array)
159
+
160
+ ```contains``` - _fact_ (an array) must include _value_
161
+
162
+ ```doesNotContain``` - _fact_ (an array) must not include _value_
163
+ * Value - The actual value to compare
164
+
165
+ Following are the examples of conditions
166
+
167
+ ```
168
+ "all": [
169
+ {
170
+ "fact": "path",
171
+ "operator": "equal",
172
+ "value": "/transfers"
173
+ },
174
+ {
175
+ "fact": "method",
176
+ "operator": "equal",
177
+ "value": "post"
178
+ }
179
+ ]
180
+ ```
181
+
182
+ ```
183
+ "any": [
184
+ {
185
+ "fact": "body",
186
+ "path": "amount.type",
187
+ "operator": "equal",
188
+ "value": "GBP"
189
+ },
190
+ {
191
+ "fact": "body",
192
+ "path": "amount.type",
193
+ "operator": "equal",
194
+ "value": "USD"
195
+ }
196
+ ]
197
+ ```
198
+
199
+ ### Events
200
+
201
+ And event can be defined with "type" and "params" properties.
202
+
203
+ There are different type of events based on the rules engine level.
204
+
205
+ * Validation Rules Engine
206
+ * FIXED_ERROR_CALLBACK
207
+ * MOCK_ERROR_CALLBACK
208
+ * NO_CALLBACK
209
+ * Callbacks Rules Engine
210
+ * FIXED_CALLBACK
211
+ * MOCK_CALLBACK
212
+ * NO_CALLBACK
213
+ * Synchronous Response Rules Engine
214
+ * FIXED_RESPONSE
215
+ * MOCK_RESPONSE
216
+
217
+ #### FIXED_ERROR_CALLBACK and FIXED_CALLBACK
218
+
219
+ For FIXED_ERROR_CALLBACK & FIXED_CALLBACK, we need to supply every detail for sending callback like path, method, headers & body
220
+ Let's look at an example of an event type *FIXED_ERROR_CALLBACK*
221
+ ```
222
+ "event": {
223
+ "type": "FIXED_ERROR_CALLBACK",
224
+ "params": {
225
+ "path": "/parties/{$request.params.Type}/{$request.params.ID}/error",
226
+ "method": "put",
227
+ "headers": {},
228
+ "delay": 100,
229
+ "body": {
230
+ "errorInformation": {
231
+ "errorCode": "5001",
232
+ "errorDescription": "The party {$request.params.ID} is not found"
233
+ }
234
+ }
235
+ }
236
+ }
237
+ ```
238
+
239
+ #### Configurable parameters
240
+
241
+ You can observe the configurable parameters '\{\$request.params.Type\}' and '\{\$request.params.ID\}'. These values will be replaced with the values from the request in run time.
242
+
243
+ The following is the list of configurable parameters that you can define anywhere in path, headers & body values.
244
+ * $request.params - Parameters in the request path
245
+ * $request.body - Request body
246
+ * $request.path - Entire request path
247
+ * $request.query - Query parameters of the request
248
+ * $request.headers - Http headers of the request
249
+ * $config.<param_name> - Configuration parameter value from environment or local.env file
250
+ * $session.negotiatedContentType - Negotiated content type. Can be sent to callbacks and error callbacks
251
+ * $session.uniqueId - UniqueID for the request session
252
+
253
+
254
+ **Advanced parameters for developers:**
255
+
256
+ There are some advanced parameters type *$function* is implemented for advanced users / developers. The syntax is like below
257
+
258
+ * $function.sample.getSampleText (For development purpose)
259
+
260
+ The above parameter calls the function 'getSampleText' in 'sample.js' file located at 'lib/mocking/custom-functions' folder. An argument will be passed to this function from which the developer can get the request parameters to process like 'arg1.request.body.quoteId', 'arg1.request.headers.date' ...etc
261
+
262
+ Please be noted that these javascript files can not be change in runtime and need compilation for the changes.
263
+
264
+
265
+ #### MOCK_ERROR_CALLBACK and MOCK_CALLBACK
266
+
267
+ For MOCK_ERROR_CALLBACK & MOCK_CALLBACK, we don't need to supply the details like path, method, headers & body. The toolkit will generate the callback based on the openAPI definition file.
268
+
269
+ Let's look at an example of an event type *MOCK_ERROR_CALLBACK*
270
+ ```
271
+ "event": {
272
+ "type": "MOCK_ERROR_CALLBACK",
273
+ "params": {
274
+ }
275
+ }
276
+ ```
277
+
278
+ That's it, the self testing toolkit can be able to generate a mock callback based on the open API file with random values.
279
+
280
+ **Also you can define the params like in fixed callbacks to override a particular value.**
281
+
282
+ See the following example in which the generated values of the firstName & name will be replaced accordingly
283
+
284
+ ```
285
+ "event": {
286
+ "type": "MOCK_CALLBACK",
287
+ "params": {
288
+ "body": {
289
+ "party": {
290
+ "personalInfo": {
291
+ "complexName": {
292
+ "firstName": "A fixed value",
293
+ }
294
+ }
295
+ "name": "The party with phone number ${request.params.ID}"
296
+ }
297
+ }
298
+ }
299
+ }
300
+
301
+ ```
302
+
303
+ #### NO_CALLBACK
304
+
305
+ For NO_CALLBACK, there are some test cases where the requirements dictate that there is no follow up callback.
306
+
307
+ ```
308
+ "event": {
309
+ "type": "NO_CALLBACK",
310
+ }
311
+ ```
312
+
313
+ #### MOCK_RESPONSE and FIXED_RESPONSE
314
+
315
+ These event types are used for defining events for synchronous response rules.
316
+
317
+ These are same like callback event types, but the only difference is we need to provide the statusCode for FIXED_RESPONSE type. MOCK_RESPONSE automatically picks up the success response code from api specification file.
318
+
319
+ Let's look at an example of an event type *FIXED_RESPONSE*
320
+ ```
321
+ "event": {
322
+ "type": "FIXED_RESPONSE",
323
+ "params": {
324
+ "body": [
325
+ {
326
+ "createdDate": "2020-02-10",
327
+ "id": 123,
328
+ "state": "{$request.query.state}",
329
+ "reason": "string",
330
+ "changedDate": "2020-02-10"
331
+ }
332
+ ],
333
+ "statusCode": "200"
334
+ }
335
+ }
336
+ ```
337
+
338
+ ### Priority of rules
339
+
340
+ The 'priority' property in a rule dictates when rule should be run, relative to other rules. Higher priority rules are run before lower priority rules. Rules with the same priority are run in parallel. Priority must be a positive, non-zero integer.
341
+
342
+ **Example:**
343
+
344
+ Consider the following example, observe the priority values. So rule which compares the amount value will be executed first and then the other rule will be executed. So if the amount is equal to 50, then we will get FIXED_CALLBACK event in first place, and in other cases we get MOCK_CALLBACK.
345
+
346
+ ```
347
+ [
348
+ {
349
+ "ruleId": 1,
350
+ "priority": 2,
351
+ "description": "If the transfer amount is equal to 50 USD, send a fixed callback",
352
+ "conditions": {
353
+ "all": [
354
+ {
355
+ "fact": "path",
356
+ "operator": "equal",
357
+ "value": "/transfers"
358
+ },
359
+ {
360
+ "fact": "method",
361
+ "operator": "equal",
362
+ "value": "post"
363
+ },
364
+ {
365
+ "fact": "body",
366
+ "operator": "equal",
367
+ "value": "50",
368
+ "path": "amount.amount"
369
+ }
370
+ ]
371
+ },
372
+ "event": {
373
+ "type": "FIXED_CALLBACK",
374
+ "params": {
375
+ ...Some fixed callback
376
+ }
377
+ }
378
+ },
379
+ {
380
+ "ruleId": 2,
381
+ "priority": 1,
382
+ "description": "Send a mock callback for all the remaining transfer requests",
383
+ "conditions": {
384
+ "all": [
385
+ {
386
+ "fact": "path",
387
+ "operator": "equal",
388
+ "value": "/transfers"
389
+ },
390
+ {
391
+ "fact": "method",
392
+ "operator": "equal",
393
+ "value": "post"
394
+ }
395
+ ]
396
+ },
397
+ "event": {
398
+ "type": "MOCK_CALLBACK",
399
+ "params": {
400
+ }
401
+ }
402
+ },
403
+ ```
@@ -0,0 +1,121 @@
1
+ # Mojaloop Testing Toolkit
2
+
3
+ ## _API Provisioning_
4
+
5
+ **Table of Contents**
6
+
7
+ 1. [Overview](#1-overview)
8
+
9
+ 2. [Synchronous API](#2-synchronous-api)
10
+
11
+ 3. [Asynchronous API](#3-asynchronous-api)
12
+
13
+ 4. [Provisioning through UI](#4-api-provisioning-through-ui)
14
+
15
+ 5. [Prefix and Hostnames](#5-prefix-and-hostnames)
16
+
17
+
18
+ ## 1. Overview
19
+
20
+ The Testing Toolkit is highly configurable and any API can be provisioned into TTK easily.
21
+ TTK supports two kinds of APIs
22
+
23
+ * Synchronous API
24
+ * Asynchronous API
25
+
26
+ ## 2. Synchronous API
27
+
28
+ You just need to provide the **Swagger / OpenAPI** specification file of your synchronous API to the TTK.
29
+
30
+ - Please copy the specification file in yaml format into the following folder
31
+ ```
32
+ spec_files/<your-api-folder-name>/api_spec.yaml
33
+ ```
34
+ - Add a new entry to the property **API_DEFINITIONS** in _spec_files/system_config.json_
35
+ ```
36
+ {
37
+ "type": "<your-api-name>",
38
+ "version": "<major_version.minor_version",
39
+ "folderPath": "<your-api-folder-name>"
40
+ }
41
+ ```
42
+ - Restart the testing toolkit service and that's it. You are all set.
43
+
44
+ You should be able to send your API requests to TTK and the TTK will validate them against the specification. You can monitor them in the TTK UI.
45
+
46
+ And also you can go ahead to create your own response rules to get customized responses from TTK through TTK UI.
47
+
48
+ ## 3. Asynchronous API
49
+
50
+ You should follow the same procedure as Synchronous API and some additional steps are there to provision an Asynchronous API.
51
+
52
+ - Please copy the specification file in yaml format into the following file
53
+ ```
54
+ spec_files/<your-api-folder-name>/api_spec.yaml
55
+ ```
56
+ - Add a new entry to the property **API_DEFINITIONS** in _spec_files/system_config.json_. Please observe the additional _asynchronous_ flag here.
57
+ ```
58
+ {
59
+ "type": "<your-api-name>",
60
+ "version": "<major_version.minor_version",
61
+ "folderPath": "<your-api-folder-name>",
62
+ "asynchronous": true
63
+ }
64
+ ```
65
+ - Additionally you should provide some information about callback mappings to associate the asynchronous callbacks to the respective requests. You can add that information into the following file. You can refer the sample files provided for FSPIOP api in the repository.
66
+ ```
67
+ spec_files/<your-api-folder-name>/callback_map.json
68
+ ```
69
+ - Restart the testing toolkit service and that's it. You are all set.
70
+
71
+ You should be able to send your API requests to TTK and the TTK will validate them against the specification. You can monitor them in the TTK UI.
72
+
73
+ And also you can go ahead to create your own validation rules, callback rules and response rules to get customized / mock callbacks and responses from TTK through TTK UI.
74
+
75
+ ## 4. Provisioning through UI
76
+
77
+ ![Opening API Management](/assets/images/api-provisioning-menu-item.png)
78
+
79
+ - You can go to _**API Management**_ navigation tab. Below is the default view of this API Management page.
80
+
81
+ ![API Management Default View](/assets/images/api-provisioning-list-apis-view.png)
82
+
83
+ - Click on **Add new API** button, a popup window will be opened and you should drag / select your API specification yaml file there.
84
+
85
+ ![API Management File Input Window](/assets/images/api-provisioning-file-input-window.png)
86
+
87
+ - After your file is been processed and validated by TTK, you can find the information about your API in the window. You can verify the details and change the name and other details populated there.
88
+
89
+ ![API Management Add New API Confirmation](/assets/images/api-provisioning-add-new-api-confirmation.png)
90
+
91
+ ## 5. Prefix and Hostnames
92
+
93
+ We can also add a `prefix` to a provisioned API. For example if the API consists of a resource called `/pets`, we can configure a prefix for the pets api like `prefix: "/api"` in `system_config.json` file.
94
+ Then the TTK accepts inbound requests on `/api/pets` instead of `/pets`.
95
+
96
+ This is useful when two provisioned APIs have a common resource. Then we can clearly specify how TTK should work for the inbound requests on that common resource.
97
+
98
+ **Note:** Prefix should always start with `/`
99
+
100
+ In the same way we can also specify `hostnames` for an API. Then TTK selects the API based on the matching `hostname` of the inbound request. For example you can configure the hostname `127.0.0.1` for an API, then all that API will be selected only when the hostname of the inbound request in `127.0.0.1`. It doesn't match the inbound requests with the hostname `localhost`.
101
+
102
+ Example configuration section of `system_config.json` file.
103
+ ```
104
+ "API_DEFINITIONS": [
105
+ {
106
+ "type": "example-api-1",
107
+ "version": "1.0",
108
+ "folderPath": "example-api-1",
109
+ "hostnames": [],
110
+ "prefix": "/api1"
111
+ },
112
+ {
113
+ "type": "example-api-2",
114
+ "version": "1.0",
115
+ "folderPath": "example-api-2",
116
+ "hostnames": [
117
+ "example2.localhost.localdomain"
118
+ ]
119
+ }
120
+ }
121
+ ```