account-lookup-service 15.5.0-iso.0
Sign up to get free protection for your applications and to get access to all the features.
- package/.circleci/config.yml +11 -0
- package/.ncurc.yaml +6 -0
- package/.nvmrc +1 -0
- package/.nycrc.yml +20 -0
- package/.versionrc +15 -0
- package/CHANGELOG.md +330 -0
- package/CODEOWNERS +38 -0
- package/Dockerfile +45 -0
- package/LICENSE.md +10 -0
- package/README.md +252 -0
- package/audit-ci.jsonc +32 -0
- package/audit-resolve.json +161 -0
- package/config/default.json +109 -0
- package/config/knexfile.js +21 -0
- package/docker/account-lookup-service/default.json +106 -0
- package/docker/account-lookup-service/make-default-json.sh +5 -0
- package/docker/account-lookup-service/override.json +15 -0
- package/docker/central-ledger/default.json +458 -0
- package/docker/config-modifier/account-lookup-service.js +31 -0
- package/docker/kafka/consumer.properties +26 -0
- package/docker/kafka/producer.properties +45 -0
- package/docker/kafka/server.properties +143 -0
- package/docker/kafka/tools-log4j.properties +21 -0
- package/docker/mock-proxy/Dockerfile +15 -0
- package/docker/mock-proxy/package-lock.json +4986 -0
- package/docker/mock-proxy/package.json +24 -0
- package/docker/mock-proxy/src/config.ts +14 -0
- package/docker/mock-proxy/src/server.ts +94 -0
- package/docker/mock-proxy/src/utils.ts +29 -0
- package/docker/mock-proxy/tsconfig.json +24 -0
- package/docker/sql-init/01_permissions.sql +2 -0
- package/docker/sql-init-central-ledger/01_permissions.sql +2 -0
- package/docker/wait-for/wait-for-account-lookup-service.sh +10 -0
- package/docker/wait-for/wait-for-central-ledger.sh +11 -0
- package/docker/wait-for/wait-for-kafka.sh +7 -0
- package/docker/wait-for/wait-for-ml-api-adapter.sh +9 -0
- package/docker/wait-for/wait-for-mockserver.sh +20 -0
- package/docker/wait-for/wait-for-mysql-als.sh +14 -0
- package/docker/wait-for/wait-for-mysql-central-ledger.sh +11 -0
- package/docker/wait-for/wait-for-mysql.sh +11 -0
- package/docker/wait-for/wait-for-objstore.sh +12 -0
- package/docker/wait-for/wait-for.env +18 -0
- package/docker/wait-for/wait-for.sh +81 -0
- package/docker-compose.integration.yml +29 -0
- package/docker-compose.yml +243 -0
- package/jest-int.config.js +8 -0
- package/jest.config.js +16 -0
- package/jsdoc.json +38 -0
- package/migrations/01_currency.js +42 -0
- package/migrations/02_endpointType.js +43 -0
- package/migrations/03_endpointType-indexes.js +37 -0
- package/migrations/04_partyIdType.js +43 -0
- package/migrations/05_partyIdType-indexes.js +38 -0
- package/migrations/08_oracleEndpoint.js +51 -0
- package/migrations/09_oracleEndpoint-indexes.js +41 -0
- package/migrations/10_oracleEndpoint-remove-constraints.js +38 -0
- package/package.json +180 -0
- package/scripts/_wait4_all.js +143 -0
- package/scripts/test-functional.sh +76 -0
- package/secrets/jwsSigningKey.key +27 -0
- package/seeds/currency.js +765 -0
- package/seeds/endpointType.js +65 -0
- package/seeds/partyIdType.js +79 -0
- package/src/api/endpointcache.js +67 -0
- package/src/api/health.js +66 -0
- package/src/api/index.js +85 -0
- package/src/api/oracles/{ID}.js +100 -0
- package/src/api/oracles.js +96 -0
- package/src/api/participants/{ID}/error.js +44 -0
- package/src/api/participants/{ID}.js +44 -0
- package/src/api/participants/{Type}/{ID}/error.js +74 -0
- package/src/api/participants/{Type}/{ID}/{SubId}/error.js +68 -0
- package/src/api/participants/{Type}/{ID}/{SubId}.js +113 -0
- package/src/api/participants/{Type}/{ID}.js +133 -0
- package/src/api/participants.js +63 -0
- package/src/api/parties/{Type}/{ID}/error.js +66 -0
- package/src/api/parties/{Type}/{ID}/{SubId}/error.js +56 -0
- package/src/api/parties/{Type}/{ID}/{SubId}.js +77 -0
- package/src/api/parties/{Type}/{ID}.js +98 -0
- package/src/api/routes.js +294 -0
- package/src/constants.js +16 -0
- package/src/domain/oracle/index.js +33 -0
- package/src/domain/oracle/oracle.js +234 -0
- package/src/domain/participants/index.js +35 -0
- package/src/domain/participants/participants.js +560 -0
- package/src/domain/parties/getPartiesByTypeAndID.js +239 -0
- package/src/domain/parties/index.js +32 -0
- package/src/domain/parties/parties.js +215 -0
- package/src/domain/parties/utils.js +84 -0
- package/src/domain/timeout/dto.js +48 -0
- package/src/domain/timeout/index.js +104 -0
- package/src/handlers/TimeoutHandler.js +94 -0
- package/src/handlers/index.js +70 -0
- package/src/handlers/monitoring/index.js +51 -0
- package/src/handlers/monitoring/plugins/health.js +61 -0
- package/src/handlers/monitoring/plugins/metrics.js +48 -0
- package/src/handlers/register.js +102 -0
- package/src/index.js +66 -0
- package/src/interface/admin-swagger.yaml +804 -0
- package/src/interface/admin_swagger.json +959 -0
- package/src/interface/api-swagger-iso20022-parties.yaml +1734 -0
- package/src/interface/api-swagger.yaml +1733 -0
- package/src/interface/api_swagger.json +3046 -0
- package/src/interface/fspiop-rest-v2.0-ISO20022_parties.yaml +2256 -0
- package/src/interface/thirdparty/admin-swagger.yaml +808 -0
- package/src/interface/thirdparty/admin_swagger.json +961 -0
- package/src/interface/thirdparty/api-swagger.yaml +1739 -0
- package/src/interface/thirdparty/api_swagger.json +3142 -0
- package/src/lib/argv.js +39 -0
- package/src/lib/cache.js +126 -0
- package/src/lib/config.js +183 -0
- package/src/lib/db.js +26 -0
- package/src/lib/headers.js +53 -0
- package/src/lib/healthCheck/subServiceHealth.js +84 -0
- package/src/lib/index.js +11 -0
- package/src/lib/migrator.js +17 -0
- package/src/lib/requestLogger.js +54 -0
- package/src/lib/util.js +66 -0
- package/src/metrics/handler.js +33 -0
- package/src/metrics/plugin.js +52 -0
- package/src/metrics/routes.js +43 -0
- package/src/models/currency/currency.js +48 -0
- package/src/models/currency/index.js +32 -0
- package/src/models/endpointType/endpointType.js +48 -0
- package/src/models/endpointType/index.js +32 -0
- package/src/models/misc/migrationLock.js +49 -0
- package/src/models/oracle/facade.js +341 -0
- package/src/models/oracle/index.js +41 -0
- package/src/models/oracle/oracleEndpoint.js +192 -0
- package/src/models/oracle/oracleEndpointCached.js +108 -0
- package/src/models/participantEndpoint/facade.js +238 -0
- package/src/models/partyIdType/index.js +32 -0
- package/src/models/partyIdType/partyIdType.js +41 -0
- package/src/plugins.js +139 -0
- package/src/server.js +199 -0
- package/test/fixtures/index.js +131 -0
- package/test/fixtures/iso.js +110 -0
- package/test/integration/.env +8 -0
- package/test/integration/api/parties.test.js +137 -0
- package/test/integration/constants.js +20 -0
- package/test/integration/domain/oracle/index.test.js +324 -0
- package/test/integration/domain/timeout/index.test.js +75 -0
- package/test/integration/env.sh +15 -0
- package/test/integration/example.test.js +12 -0
- package/test/integration/models/currency/currency.test.js +68 -0
- package/test/integration/plugins.test.js +62 -0
- package/test/integration/prepareTestParticipants.js +30 -0
- package/test/integration/setup.js +5 -0
- package/test/integration-config.json +81 -0
- package/test/integration-runner.sh +108 -0
- package/test/unit/api/health.test.js +142 -0
- package/test/unit/api/oracles/{ID}.test.js +264 -0
- package/test/unit/api/oracles.test.js +173 -0
- package/test/unit/api/participants/participants.test.js +117 -0
- package/test/unit/api/participants/{Type}/{ID}/error.test.js +155 -0
- package/test/unit/api/participants/{Type}/{ID}/{SubId}/error.test.js +131 -0
- package/test/unit/api/participants/{Type}/{ID}/{SubId}.test.js +377 -0
- package/test/unit/api/participants/{Type}/{ID}.test.js +383 -0
- package/test/unit/api/participants.test.js +108 -0
- package/test/unit/api/parties/endpointcache.test.js +83 -0
- package/test/unit/api/parties/parties.test.js +102 -0
- package/test/unit/api/parties/{Type}/{ID}/error.test.js +145 -0
- package/test/unit/api/parties/{Type}/{ID}/{SubId}/error.test.js +141 -0
- package/test/unit/api/parties/{Type}/{ID}/{SubId}.test.js +241 -0
- package/test/unit/api/parties/{Type}/{ID}.test.js +240 -0
- package/test/unit/domain/oracle/oracle.test.js +505 -0
- package/test/unit/domain/participants/participants.test.js +1724 -0
- package/test/unit/domain/parties/parties.test.js +940 -0
- package/test/unit/domain/timeout/dto.test.js +28 -0
- package/test/unit/domain/timeout/index.test.js +81 -0
- package/test/unit/handlers/TimeoutHandler.test.js +125 -0
- package/test/unit/handlers/index.test.js +56 -0
- package/test/unit/handlers/register.test.js +90 -0
- package/test/unit/index.test.js +139 -0
- package/test/unit/iso20022/partiesValidation.test.js +129 -0
- package/test/unit/lib/TransformFacades.test.js +18 -0
- package/test/unit/lib/argv.test.js +40 -0
- package/test/unit/lib/cache.test.js +172 -0
- package/test/unit/lib/config.test.js +108 -0
- package/test/unit/lib/healthCheck/subServiceHealth.test.js +89 -0
- package/test/unit/lib/migrator.test.js +52 -0
- package/test/unit/lib/requestLogger.test.js +115 -0
- package/test/unit/lib/util.test.js +68 -0
- package/test/unit/mocks.js +66 -0
- package/test/unit/models/currency/currency.test.js +91 -0
- package/test/unit/models/endpointType/endpointType.test.js +69 -0
- package/test/unit/models/misc/migrationLock.test.js +96 -0
- package/test/unit/models/oracle/facade.test.js +546 -0
- package/test/unit/models/oracle/oracleEndpoint.test.js +409 -0
- package/test/unit/models/oracle/oracleEndpointCached.test.js +153 -0
- package/test/unit/models/participantEndpoint/facade.test.js +295 -0
- package/test/unit/models/partyIdType/partyIdType.test.js +88 -0
- package/test/unit/plugins.test.js +89 -0
- package/test/unit/setup.js +7 -0
- package/test/util/apiClients/AlsApiClient.js +44 -0
- package/test/util/apiClients/BasicApiClient.js +34 -0
- package/test/util/apiClients/ProxyApiClient.js +25 -0
- package/test/util/apiClients/index.js +7 -0
- package/test/util/helper.js +332 -0
- package/test/util/index.js +11 -0
- package/test/util/mockgen.js +43 -0
- package/test/util/onboarding.js +132 -0
- package/test/util/scripts/addAlsDb.sh +33 -0
- package/test/util/scripts/configureMockServer.sh +35 -0
- package/test/util/scripts/env.sh +19 -0
- package/test/util/scripts/populateTestData.sh +62 -0
- package/test/util/scripts/startMockCentralServer.sh +45 -0
- package/test/util/scripts/startMockOracleServer.sh +45 -0
- package/test/util/testConfig.js +44 -0
@@ -0,0 +1,332 @@
|
|
1
|
+
/*****
|
2
|
+
License
|
3
|
+
--------------
|
4
|
+
Copyright © 2017 Bill & Melinda Gates Foundation
|
5
|
+
The Mojaloop files are made available by the Bill & Melinda Gates Foundation under the Apache License, Version 2.0 (the "License") and you may not use these files except in compliance with the License. You may obtain a copy of the License at
|
6
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
7
|
+
Unless required by applicable law or agreed to in writing, the Mojaloop files are distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
8
|
+
Contributors
|
9
|
+
--------------
|
10
|
+
This is the official list of the Mojaloop project contributors for this file.
|
11
|
+
Names of the original copyright holders (individuals or organizations)
|
12
|
+
should be listed with a '*' in the first column. People who have
|
13
|
+
contributed from an organization can be listed under the organization
|
14
|
+
that actually holds the copyright for their contributions (see the
|
15
|
+
Gates Foundation organization for an example). Those individuals should have
|
16
|
+
their names indented and be marked with a '-'. Email address can be added
|
17
|
+
optionally within square brackets <email>.
|
18
|
+
* Gates Foundation
|
19
|
+
* - Name Surname <name.surname@gatesfoundation.com>
|
20
|
+
|
21
|
+
* - Rajiv Mothilal <rajiv.mothilal@modusbox.com>
|
22
|
+
* - Henk Kodde <henk.kodde@modusbox.com>
|
23
|
+
|
24
|
+
--------------
|
25
|
+
******/
|
26
|
+
'use strict'
|
27
|
+
|
28
|
+
const Mustache = require('mustache')
|
29
|
+
const Mockgen = require('./mockgen')
|
30
|
+
const Enums = require('@mojaloop/central-services-shared').Enum
|
31
|
+
const { API_TYPES } = require('@mojaloop/central-services-shared').Util.Hapi
|
32
|
+
const Config = require('../../src/lib/config')
|
33
|
+
|
34
|
+
const payerfsp = 'payerfsp'
|
35
|
+
const payeefsp = 'payeefsp'
|
36
|
+
const validatePayerFspUri = Mustache.render(Config.SWITCH_ENDPOINT + Enums.EndPoints.FspEndpointTemplates.PARTICIPANTS_GET, { fsp: payerfsp })
|
37
|
+
const validatePayeeFspUri = Mustache.render(Config.SWITCH_ENDPOINT + Enums.EndPoints.FspEndpointTemplates.PARTICIPANTS_GET, { fsp: payeefsp })
|
38
|
+
const defaultSwitchHeaders = defaultHeaders(Config.HUB_NAME, Enums.Http.HeaderResources.PARTICIPANTS, Config.HUB_NAME)
|
39
|
+
const defaultStandardHeaders = (resource = Enums.Http.HeaderResources.PARTICIPANTS) => defaultHeaders(payerfsp, resource, payeefsp)
|
40
|
+
const getPayerfspEndpointsUri = Mustache.render(Config.SWITCH_ENDPOINT + Enums.EndPoints.FspEndpointTemplates.PARTICIPANT_ENDPOINTS_GET, { fsp: payerfsp })
|
41
|
+
const getPayeefspEndpointsUri = Mustache.render(Config.SWITCH_ENDPOINT + Enums.EndPoints.FspEndpointTemplates.PARTICIPANT_ENDPOINTS_GET, { fsp: payeefsp })
|
42
|
+
|
43
|
+
/**
|
44
|
+
* @function generateMockRequest
|
45
|
+
*
|
46
|
+
* @description Uses MockGen to create a mock request given a URI and endpoint
|
47
|
+
*
|
48
|
+
* @example
|
49
|
+
* const mock = await Helper.generateMockRequest('/participants/{Type}/{ID}', 'get')
|
50
|
+
*
|
51
|
+
* @param {*} path - A URI Path. e.g. `/participants/{Type}/{ID}`
|
52
|
+
* @param {*} operation - A HTTP Method (lowercase). e.g. `get`
|
53
|
+
*/
|
54
|
+
|
55
|
+
const generateMockRequest = async (path, operation, isApi = true) => {
|
56
|
+
return new Promise((resolve, reject) => {
|
57
|
+
Mockgen(isApi).requests({
|
58
|
+
path,
|
59
|
+
operation
|
60
|
+
}, function (error, mock) {
|
61
|
+
return error ? reject(error) : resolve(mock)
|
62
|
+
})
|
63
|
+
})
|
64
|
+
}
|
65
|
+
|
66
|
+
/**
|
67
|
+
* @function defaultHeaders
|
68
|
+
*
|
69
|
+
* @description This returns a set of default headers used for requests
|
70
|
+
*
|
71
|
+
* see https://nodejs.org/dist/latest-v10.x/docs/api/http.html#http_message_headers
|
72
|
+
*
|
73
|
+
* @param {string} destination - to who the request is being sent
|
74
|
+
* @param {string} resource - the flow that is being requested i.e. participants
|
75
|
+
* @param {string} source - from who the request is made
|
76
|
+
* @param {string} version - the version for the accept and content-type headers
|
77
|
+
* @param {"fspiop"|"iso20022"} apiType - the type of API being called (FSPIP or ISO20022)
|
78
|
+
*
|
79
|
+
* @returns {object} Returns the default headers
|
80
|
+
*/
|
81
|
+
|
82
|
+
function defaultHeaders (destination, resource, source, version = '1.1', apiType = API_TYPES.fspiop) {
|
83
|
+
// TODO: See API section 3.2.1; what should we do about X-Forwarded-For? Also, should we
|
84
|
+
// add/append to this field in all 'queueResponse' calls?
|
85
|
+
const isoPart = apiType === API_TYPES.iso20022 ? '.iso20022' : ''
|
86
|
+
|
87
|
+
return {
|
88
|
+
accept: `application/vnd.interoperability${isoPart}.${resource}+json;version=${version}`,
|
89
|
+
'fspiop-destination': destination || '',
|
90
|
+
'content-type': `application/vnd.interoperability${isoPart}.${resource}+json;version=${version}`,
|
91
|
+
date: '2019-05-24 08:52:19',
|
92
|
+
'fspiop-source': source,
|
93
|
+
'fspiop-signature': '{"signature":"iU4GBXSfY8twZMj1zXX1CTe3LDO8Zvgui53icrriBxCUF_wltQmnjgWLWI4ZUEueVeOeTbDPBZazpBWYvBYpl5WJSUoXi14nVlangcsmu2vYkQUPmHtjOW-yb2ng6_aPfwd7oHLWrWzcsjTF-S4dW7GZRPHEbY_qCOhEwmmMOnE1FWF1OLvP0dM0r4y7FlnrZNhmuVIFhk_pMbEC44rtQmMFv4pm4EVGqmIm3eyXz0GkX8q_O1kGBoyIeV_P6RRcZ0nL6YUVMhPFSLJo6CIhL2zPm54Qdl2nVzDFWn_shVyV0Cl5vpcMJxJ--O_Zcbmpv6lxqDdygTC782Ob3CNMvg\\",\\"protectedHeader\\":\\"eyJhbGciOiJSUzI1NiIsIkZTUElPUC1VUkkiOiIvdHJhbnNmZXJzIiwiRlNQSU9QLUhUVFAtTWV0aG9kIjoiUE9TVCIsIkZTUElPUC1Tb3VyY2UiOiJPTUwiLCJGU1BJT1AtRGVzdGluYXRpb24iOiJNVE5Nb2JpbGVNb25leSIsIkRhdGUiOiIifQ"}'
|
94
|
+
}
|
95
|
+
}
|
96
|
+
|
97
|
+
const getOracleEndpointDatabaseResponse = [{
|
98
|
+
oracleEndpointId: 1,
|
99
|
+
endpointType: 'URL',
|
100
|
+
value: 'http://localhost:8444',
|
101
|
+
idType: 'MSISDN',
|
102
|
+
currency: 'USD',
|
103
|
+
isDefault: true
|
104
|
+
}]
|
105
|
+
|
106
|
+
const getByTypeIdRequest = {
|
107
|
+
query: {},
|
108
|
+
params: {
|
109
|
+
ID: '123456',
|
110
|
+
Type: 'MSISDN'
|
111
|
+
},
|
112
|
+
headers: {
|
113
|
+
accept: 'application/vnd.interoperability.participants+json;version=1',
|
114
|
+
'fspiop-destination': payeefsp,
|
115
|
+
'content-type': 'application/vnd.interoperability.participants+json;version=1.1',
|
116
|
+
date: '2019-05-24 08:52:19',
|
117
|
+
'fspiop-source': payerfsp
|
118
|
+
},
|
119
|
+
method: 'get'
|
120
|
+
}
|
121
|
+
|
122
|
+
const getByTypeIdRequestError = {
|
123
|
+
query: {},
|
124
|
+
params: {
|
125
|
+
ID: '',
|
126
|
+
Type: ''
|
127
|
+
},
|
128
|
+
headers: {
|
129
|
+
accept: 'application/vnd.interoperability.participants+json;version=1',
|
130
|
+
'fspiop-destination': payeefsp,
|
131
|
+
'content-type': 'application/vnd.interoperability.participants+json;version=1.1',
|
132
|
+
date: '2019-05-24 08:52:19',
|
133
|
+
'fspiop-source': payerfsp
|
134
|
+
},
|
135
|
+
method: 'get'
|
136
|
+
}
|
137
|
+
|
138
|
+
const putByTypeIdRequest = {
|
139
|
+
query: {},
|
140
|
+
params: {
|
141
|
+
ID: '123456',
|
142
|
+
Type: 'MSISDN'
|
143
|
+
},
|
144
|
+
headers: {
|
145
|
+
accept: 'application/vnd.interoperability.participants+json;version=1',
|
146
|
+
'fspiop-destination': payeefsp,
|
147
|
+
'content-type': 'application/vnd.interoperability.participants+json;version=1.1',
|
148
|
+
date: '2019-05-24 08:52:19',
|
149
|
+
'fspiop-source': payerfsp
|
150
|
+
},
|
151
|
+
method: 'put'
|
152
|
+
}
|
153
|
+
|
154
|
+
const getByTypeIdCurrencyRequest = {
|
155
|
+
query: {
|
156
|
+
currency: 'USD'
|
157
|
+
},
|
158
|
+
params: {
|
159
|
+
ID: '123456',
|
160
|
+
Type: 'MSISDN'
|
161
|
+
},
|
162
|
+
headers: {
|
163
|
+
accept: 'application/vnd.interoperability.participants+json;version=1',
|
164
|
+
'fspiop-destination': payeefsp,
|
165
|
+
'content-type': 'application/vnd.interoperability.participants+json;version=1.1',
|
166
|
+
date: '2019-05-24 08:52:19',
|
167
|
+
'fspiop-source': payerfsp
|
168
|
+
},
|
169
|
+
method: 'get'
|
170
|
+
}
|
171
|
+
|
172
|
+
const postByTypeIdCurrencyRequest = {
|
173
|
+
query: {
|
174
|
+
currency: 'USD'
|
175
|
+
},
|
176
|
+
params: {
|
177
|
+
ID: '123456',
|
178
|
+
Type: 'MSISDN'
|
179
|
+
},
|
180
|
+
headers: {
|
181
|
+
accept: 'application/vnd.interoperability.participants+json;version=1',
|
182
|
+
'fspiop-destination': payeefsp,
|
183
|
+
'content-type': 'application/vnd.interoperability.participants+json;version=1.1',
|
184
|
+
date: '2019-05-24 08:52:19',
|
185
|
+
'fspiop-source': payerfsp
|
186
|
+
},
|
187
|
+
method: 'post'
|
188
|
+
}
|
189
|
+
|
190
|
+
const oracleGetCurrencyUri = Mustache.render(getOracleEndpointDatabaseResponse[0].value + Enums.EndPoints.FspEndpointTemplates.ORACLE_PARTICIPANTS_TYPE_ID_CURRENCY, {
|
191
|
+
partyIdType: getByTypeIdCurrencyRequest.params.Type,
|
192
|
+
partyIdentifier: getByTypeIdCurrencyRequest.params.ID,
|
193
|
+
currency: getByTypeIdCurrencyRequest.query.currency
|
194
|
+
})
|
195
|
+
|
196
|
+
const oracleGetUri = Mustache.render(getOracleEndpointDatabaseResponse[0].value + Enums.EndPoints.FspEndpointTemplates.ORACLE_PARTICIPANTS_TYPE_ID, {
|
197
|
+
partyIdType: getByTypeIdRequest.params.Type,
|
198
|
+
partyIdentifier: getByTypeIdRequest.params.ID
|
199
|
+
})
|
200
|
+
|
201
|
+
const oracleGetPartiesUri = Mustache.render(getOracleEndpointDatabaseResponse[0].value + Enums.EndPoints.FspEndpointTemplates.PARTIES_GET, {
|
202
|
+
partyIdType: getByTypeIdRequest.params.Type,
|
203
|
+
partyIdentifier: getByTypeIdRequest.params.ID
|
204
|
+
})
|
205
|
+
|
206
|
+
const getOracleResponse = {
|
207
|
+
data: {
|
208
|
+
partyList: [{
|
209
|
+
fspId: payeefsp
|
210
|
+
}]
|
211
|
+
}
|
212
|
+
}
|
213
|
+
|
214
|
+
const getEndPointsResponse = {
|
215
|
+
data: [
|
216
|
+
{
|
217
|
+
type: Enums.EndPoints.FspEndpointTypes.FSPIOP_CALLBACK_URL_PARTICIPANT_PUT,
|
218
|
+
value: 'localhost:33350'
|
219
|
+
},
|
220
|
+
{
|
221
|
+
type: Enums.EndPoints.FspEndpointTypes.FSPIOP_CALLBACK_URL_PARTICIPANT_PUT_ERROR,
|
222
|
+
value: 'localhost:33351'
|
223
|
+
},
|
224
|
+
{
|
225
|
+
type: Enums.EndPoints.FspEndpointTypes.FSPIOP_CALLBACK_URL_PARTICIPANT_BATCH_PUT,
|
226
|
+
value: 'localhost:33352'
|
227
|
+
},
|
228
|
+
{
|
229
|
+
type: Enums.EndPoints.FspEndpointTypes.FSPIOP_CALLBACK_URL_PARTICIPANT_BATCH_PUT_ERROR,
|
230
|
+
value: 'localhost:33353'
|
231
|
+
},
|
232
|
+
{
|
233
|
+
type: Enums.EndPoints.FspEndpointTypes.FSPIOP_CALLBACK_URL_PARTIES_GET,
|
234
|
+
value: 'localhost:33354'
|
235
|
+
},
|
236
|
+
{
|
237
|
+
type: Enums.EndPoints.FspEndpointTypes.FSPIOP_CALLBACK_URL_PARTIES_PUT,
|
238
|
+
value: 'localhost:33355'
|
239
|
+
},
|
240
|
+
{
|
241
|
+
type: Enums.EndPoints.FspEndpointTypes.FSPIOP_CALLBACK_URL_PARTIES_PUT_ERROR,
|
242
|
+
value: 'localhost:33356'
|
243
|
+
}
|
244
|
+
]
|
245
|
+
}
|
246
|
+
|
247
|
+
const fspIdPayload = {
|
248
|
+
fspId: payeefsp
|
249
|
+
}
|
250
|
+
|
251
|
+
const participantPutEndpointOptions = {
|
252
|
+
partyIdType: getByTypeIdCurrencyRequest.params.Type,
|
253
|
+
partyIdentifier: getByTypeIdCurrencyRequest.params.ID
|
254
|
+
}
|
255
|
+
|
256
|
+
function defaultAdminHeaders () {
|
257
|
+
return {
|
258
|
+
Accept: 'application/vnd.interoperability.oracles+json;version=1',
|
259
|
+
'Content-Type': 'application/vnd.interoperability.oracles+json;version=1.1',
|
260
|
+
Date: (new Date()).toUTCString()
|
261
|
+
}
|
262
|
+
}
|
263
|
+
|
264
|
+
/**
|
265
|
+
* Mock Span
|
266
|
+
*/
|
267
|
+
class Span {
|
268
|
+
constructor () {
|
269
|
+
this.isFinished = false
|
270
|
+
}
|
271
|
+
|
272
|
+
audit () {
|
273
|
+
return jest.fn()
|
274
|
+
}
|
275
|
+
|
276
|
+
error () {
|
277
|
+
return jest.fn()
|
278
|
+
}
|
279
|
+
|
280
|
+
finish () {
|
281
|
+
return jest.fn()
|
282
|
+
}
|
283
|
+
|
284
|
+
debug () {
|
285
|
+
return jest.fn()
|
286
|
+
}
|
287
|
+
|
288
|
+
info () {
|
289
|
+
return jest.fn()
|
290
|
+
}
|
291
|
+
|
292
|
+
getChild () {
|
293
|
+
return new Span()
|
294
|
+
}
|
295
|
+
}
|
296
|
+
|
297
|
+
const mockSpan = () => {
|
298
|
+
return new Span()
|
299
|
+
}
|
300
|
+
|
301
|
+
const partiesHeadersDto = ({
|
302
|
+
source = 'sourceFsp',
|
303
|
+
destination = 'destinationFsp',
|
304
|
+
version = '2.0',
|
305
|
+
apiType
|
306
|
+
} = {}) => defaultHeaders(destination, 'parties', source, version, apiType)
|
307
|
+
|
308
|
+
module.exports = {
|
309
|
+
defaultAdminHeaders,
|
310
|
+
validatePayerFspUri,
|
311
|
+
validatePayeeFspUri,
|
312
|
+
defaultSwitchHeaders,
|
313
|
+
defaultStandardHeaders,
|
314
|
+
generateMockRequest,
|
315
|
+
getPayerfspEndpointsUri,
|
316
|
+
getPayeefspEndpointsUri,
|
317
|
+
getOracleEndpointDatabaseResponse,
|
318
|
+
oracleGetCurrencyUri,
|
319
|
+
oracleGetUri,
|
320
|
+
oracleGetPartiesUri,
|
321
|
+
getByTypeIdRequest,
|
322
|
+
putByTypeIdRequest,
|
323
|
+
getByTypeIdRequestError,
|
324
|
+
getByTypeIdCurrencyRequest,
|
325
|
+
getOracleResponse,
|
326
|
+
getEndPointsResponse,
|
327
|
+
fspIdPayload,
|
328
|
+
partiesHeadersDto,
|
329
|
+
participantPutEndpointOptions,
|
330
|
+
postByTypeIdCurrencyRequest,
|
331
|
+
mockSpan
|
332
|
+
}
|
@@ -0,0 +1,43 @@
|
|
1
|
+
/*****
|
2
|
+
License
|
3
|
+
--------------
|
4
|
+
Copyright © 2017 Bill & Melinda Gates Foundation
|
5
|
+
The Mojaloop files are made available by the Bill & Melinda Gates Foundation under the Apache License, Version 2.0 (the "License") and you may not use these files except in compliance with the License. You may obtain a copy of the License at
|
6
|
+
|
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
|
+
Gates Foundation organization 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
|
+
* Gates Foundation
|
23
|
+
- Name Surname <name.surname@gatesfoundation.com>
|
24
|
+
|
25
|
+
* Rajiv Mothilal <rajiv.mothilal@modusbox.com>
|
26
|
+
|
27
|
+
--------------
|
28
|
+
******/
|
29
|
+
|
30
|
+
'use strict'
|
31
|
+
const SwagMock = require('swagmock')
|
32
|
+
const { pathForInterface } = require('../../src/lib/util')
|
33
|
+
const apiPath = pathForInterface({ isAdmin: false, isMockInterface: true })
|
34
|
+
const adminPath = pathForInterface({ isAdmin: true, isMockInterface: true })
|
35
|
+
let mockGen
|
36
|
+
|
37
|
+
module.exports = function (isApi = true) {
|
38
|
+
/**
|
39
|
+
* Cached mock generator
|
40
|
+
*/
|
41
|
+
mockGen = mockGen || SwagMock(isApi ? apiPath : adminPath)
|
42
|
+
return mockGen
|
43
|
+
}
|
@@ -0,0 +1,132 @@
|
|
1
|
+
const axios = require('axios')
|
2
|
+
const axiosRetry = require('axios-retry').default
|
3
|
+
const { FspEndpointTypes } = require('@mojaloop/central-services-shared').Enum.EndPoints
|
4
|
+
const Logger = require('@mojaloop/central-services-logger')
|
5
|
+
const config = require('../../src/lib/config')
|
6
|
+
const fixtures = require('../fixtures')
|
7
|
+
const { CL_PORT, PROXY_HOST, PROXY_PORT, PARTY_ID_TYPE } = require('../integration/constants')
|
8
|
+
|
9
|
+
axiosRetry(axios, {
|
10
|
+
retries: 5,
|
11
|
+
retryDelay: retryCount => retryCount * 1000
|
12
|
+
})
|
13
|
+
|
14
|
+
const alsAdminUrl = `http://localhost:${config.ADMIN_PORT}`
|
15
|
+
const clUrl = `http://localhost:${CL_PORT}`
|
16
|
+
const proxyUrl = `http://${PROXY_HOST}:${PROXY_PORT}`
|
17
|
+
|
18
|
+
const headers = {
|
19
|
+
'Cache-Control': 'no-cache',
|
20
|
+
'Content-Type': 'application/json',
|
21
|
+
'FSPIOP-Source': 'util.createTestParticipant'
|
22
|
+
}
|
23
|
+
|
24
|
+
const pause = async (ms = 1000) => new Promise(resolve => setTimeout(resolve, ms))
|
25
|
+
|
26
|
+
const createHubAccounts = async ({
|
27
|
+
currency = 'EUR',
|
28
|
+
hubName = config.HUB_NAME
|
29
|
+
} = {}) => {
|
30
|
+
const opts = { headers }
|
31
|
+
|
32
|
+
const accTypes = ['HUB_RECONCILIATION', 'HUB_MULTILATERAL_SETTLEMENT']
|
33
|
+
const accCreating = accTypes.map(type => axios.post(`${clUrl}/participants/${hubName}/accounts`, {
|
34
|
+
currency, type
|
35
|
+
}, opts))
|
36
|
+
const accounts = await Promise.all(accCreating)
|
37
|
+
|
38
|
+
const settlModel = await axios.post(`${clUrl}/settlementModels`, {
|
39
|
+
name: 'DEFERREDNET',
|
40
|
+
settlementGranularity: 'NET',
|
41
|
+
settlementInterchange: 'MULTILATERAL',
|
42
|
+
settlementDelay: 'DEFERRED',
|
43
|
+
requireLiquidityCheck: true,
|
44
|
+
ledgerAccountType: 'POSITION',
|
45
|
+
autoPositionReset: true,
|
46
|
+
currency,
|
47
|
+
settlementAccountType: 'SETTLEMENT'
|
48
|
+
}, opts)
|
49
|
+
|
50
|
+
Logger.info('createHubAccounts is finished')
|
51
|
+
return {
|
52
|
+
accounts,
|
53
|
+
settlModel
|
54
|
+
}
|
55
|
+
}
|
56
|
+
|
57
|
+
const endpoints = [
|
58
|
+
{
|
59
|
+
type: FspEndpointTypes.FSPIOP_CALLBACK_URL_PARTICIPANT_PUT,
|
60
|
+
value: `${proxyUrl}/participants/{{partyIdType}}/{{partyIdentifier}}`
|
61
|
+
},
|
62
|
+
{
|
63
|
+
type: FspEndpointTypes.FSPIOP_CALLBACK_URL_PARTICIPANT_PUT_ERROR,
|
64
|
+
value: `${proxyUrl}/participants/{{partyIdType}}/{{partyIdentifier}}/error`
|
65
|
+
},
|
66
|
+
{
|
67
|
+
type: FspEndpointTypes.FSPIOP_CALLBACK_URL_PARTIES_GET,
|
68
|
+
value: `${proxyUrl}/parties/{{partyIdType}}/{{partyIdentifier}}`
|
69
|
+
},
|
70
|
+
{
|
71
|
+
type: FspEndpointTypes.FSPIOP_CALLBACK_URL_PARTIES_PUT,
|
72
|
+
value: `${proxyUrl}/parties/{{partyIdType}}/{{partyIdentifier}}`
|
73
|
+
},
|
74
|
+
{
|
75
|
+
type: FspEndpointTypes.FSPIOP_CALLBACK_URL_PARTIES_PUT_ERROR,
|
76
|
+
value: `${proxyUrl}/parties/{{partyIdType}}/{{partyIdentifier}}/error`
|
77
|
+
}
|
78
|
+
]
|
79
|
+
|
80
|
+
const createTestParticipant = async ({
|
81
|
+
name = `testDfsp-${Date.now()}`,
|
82
|
+
currency = 'EUR',
|
83
|
+
isProxy = false
|
84
|
+
} = {}) => {
|
85
|
+
const opts = { headers }
|
86
|
+
|
87
|
+
const participantCreated = await axios.post(`${clUrl}/participants`, {
|
88
|
+
name, currency, isProxy
|
89
|
+
}, opts)
|
90
|
+
await pause()
|
91
|
+
|
92
|
+
const createEpUrl = `${clUrl}/participants/${name}/endpoints`
|
93
|
+
const addedEPs = []
|
94
|
+
|
95
|
+
for (const ep of endpoints) {
|
96
|
+
addedEPs.push(await axios.post(createEpUrl, ep, opts))
|
97
|
+
}
|
98
|
+
|
99
|
+
Logger.info(`createTestParticipant ${name} is finished`)
|
100
|
+
return {
|
101
|
+
participantCreated,
|
102
|
+
addedEPs
|
103
|
+
}
|
104
|
+
}
|
105
|
+
|
106
|
+
const createOracle = async ({
|
107
|
+
oracleIdType = PARTY_ID_TYPE,
|
108
|
+
currency = 'EUR',
|
109
|
+
endpointValue = `${proxyUrl}/oracle`,
|
110
|
+
isDefault = true
|
111
|
+
} = {}) => {
|
112
|
+
const headers = fixtures.participantsCallHeadersDto()
|
113
|
+
const body = {
|
114
|
+
oracleIdType,
|
115
|
+
endpoint: {
|
116
|
+
value: endpointValue,
|
117
|
+
endpointType: 'URL'
|
118
|
+
},
|
119
|
+
currency,
|
120
|
+
isDefault
|
121
|
+
}
|
122
|
+
const oracle = await axios.post(`${alsAdminUrl}/oracles`, body, { headers })
|
123
|
+
|
124
|
+
Logger.info('createOracle is finished')
|
125
|
+
return oracle
|
126
|
+
}
|
127
|
+
|
128
|
+
module.exports = {
|
129
|
+
createHubAccounts,
|
130
|
+
createTestParticipant,
|
131
|
+
createOracle
|
132
|
+
}
|
@@ -0,0 +1,33 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
echo "---------------------------------------------------------------------"
|
3
|
+
echo " Adding ALS database and user to existing ${DB_ID} Instance"
|
4
|
+
echo "---------------------------------------------------------------------"
|
5
|
+
|
6
|
+
CWD="${0%/*}"
|
7
|
+
|
8
|
+
if [[ "$CWD" =~ ^(.*)\.sh$ ]];
|
9
|
+
then
|
10
|
+
CWD="."
|
11
|
+
fi
|
12
|
+
|
13
|
+
echo "Loading env vars..."
|
14
|
+
source $CWD/env.sh
|
15
|
+
|
16
|
+
docker stop $DB_ID
|
17
|
+
echo "Starting container ${DB_ID}"
|
18
|
+
docker start $DB_ID
|
19
|
+
exit_code=$?
|
20
|
+
|
21
|
+
if [ "$exit_code" = "0" ]
|
22
|
+
then
|
23
|
+
docker exec -it ${DB_ID} mysql -uroot -e "DROP SCHEMA IF EXISTS account_lookup;"
|
24
|
+
docker exec -it ${DB_ID} mysql -uroot -e "CREATE SCHEMA account_lookup;"
|
25
|
+
docker exec -it ${DB_ID} mysql -uroot -e "DROP USER IF EXISTS account_lookup@'%';"
|
26
|
+
docker exec -it ${DB_ID} mysql -uroot -e "CREATE USER account_lookup@'%' IDENTIFIED WITH mysql_native_password BY '$DBPASS';"
|
27
|
+
docker exec -it ${DB_ID} mysql -uroot -e "GRANT ALL PRIVILEGES ON account_lookup.* TO 'account_lookup'@'%';"
|
28
|
+
docker exec -it ${DB_ID} mysql -uroot -e "FLUSH PRIVILEGES;"
|
29
|
+
else
|
30
|
+
>&2 echo "{$DB_ID} container does not exist "
|
31
|
+
fi
|
32
|
+
|
33
|
+
echo "${DB_ID} ALS database ready to accept requests..."
|
@@ -0,0 +1,35 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
echo "---------------------------------------------------------------------"
|
3
|
+
echo "Checking if MockServer is available Script..."
|
4
|
+
echo "---------------------------------------------------------------------"
|
5
|
+
echo
|
6
|
+
|
7
|
+
CWD="${0%/*}"
|
8
|
+
|
9
|
+
if [[ "$CWD" =~ ^(.*)\.sh$ ]];
|
10
|
+
then
|
11
|
+
CWD="."
|
12
|
+
fi
|
13
|
+
|
14
|
+
echo "Loading env vars..."
|
15
|
+
source $CWD/env.sh
|
16
|
+
|
17
|
+
echo
|
18
|
+
echo "---------------------------------------------------------------------"
|
19
|
+
echo " Configuring MockServer Instance"
|
20
|
+
echo "---------------------------------------------------------------------"
|
21
|
+
|
22
|
+
is_service_up() {
|
23
|
+
docker run --rm --network host byrnedo/alpine-curl -s -X PUT 'http://localhost:1080/status' -d '{"method": "*", "path": "*"}'
|
24
|
+
}
|
25
|
+
|
26
|
+
echo "Waiting for mockserver to start"
|
27
|
+
until is_service_up; do
|
28
|
+
printf "."
|
29
|
+
sleep $SLEEP_FACTOR_IN_SECONDS
|
30
|
+
done
|
31
|
+
|
32
|
+
echo
|
33
|
+
echo "Configuring expectation for mockserver"
|
34
|
+
docker run --rm --network host byrnedo/alpine-curl -X PUT "http://localhost:1080/expectation" -d '{ "httpRequest": { "method": ".*", "path": "/.*parties.*" }, "times" : { "remainingTimes" : 0, "unlimited" : true }, "timeToLive" : { "unlimited" : true }, "httpResponse": { "statusCode": 200, "body": "{}" } }';
|
35
|
+
docker run --rm --network host byrnedo/alpine-curl -X PUT "http://localhost:1080/expectation" -d '{ "httpRequest": { "method": ".*", "path": "/.*participants.*" }, "times" : { "remainingTimes" : 0, "unlimited" : true }, "timeToLive" : { "unlimited" : true }, "httpResponse": { "statusCode": 200, "body": "{}" } }';
|
@@ -0,0 +1,19 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
export MOCKSERVER_ID=mockserver
|
3
|
+
export SLEEP_FACTOR_IN_SECONDS=5
|
4
|
+
export DB_ID=mysql
|
5
|
+
export DBPASS=password
|
6
|
+
|
7
|
+
# Admin API
|
8
|
+
export ACCOUNT_LOOKUP_ADMIN_URI_PREFIX=http
|
9
|
+
export ACCOUNT_LOOKUP_ADMIN_HOST=localhost
|
10
|
+
export ACCOUNT_LOOKUP_ADMIN_PORT=4001
|
11
|
+
export ACCOUNT_LOOKUP_ADMIN_BASE=/
|
12
|
+
|
13
|
+
# FSPIOP API
|
14
|
+
export ACCOUNT_LOOKUP_FSPIOP_URI_PREFIX=http
|
15
|
+
export ACCOUNT_LOOKUP_FSPIOP_HOST=localhost
|
16
|
+
export ACCOUNT_LOOKUP_FSPIOP_PORT=4002
|
17
|
+
export ACCOUNT_LOOKUP_FSPIOP_BASE=/
|
18
|
+
|
19
|
+
export PAYEE_PARTICIPANT_LIST=("27713803912")
|
@@ -0,0 +1,62 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
echo "---------------------------------------------------------------------"
|
3
|
+
echo "Starting script to populate test data.."
|
4
|
+
echo "---------------------------------------------------------------------"
|
5
|
+
echo
|
6
|
+
|
7
|
+
CWD="${0%/*}"
|
8
|
+
|
9
|
+
if [[ "$CWD" =~ ^(.*)\.sh$ ]];
|
10
|
+
then
|
11
|
+
CWD="."
|
12
|
+
fi
|
13
|
+
|
14
|
+
echo "Loading env vars..."
|
15
|
+
source $CWD/env.sh
|
16
|
+
|
17
|
+
echo "---------------------------------------------------------------------"
|
18
|
+
echo "Registering Oracles for MSISDNs."
|
19
|
+
echo "---------------------------------------------------------------------"
|
20
|
+
curl --location ${ACCOUNT_LOOKUP_ADMIN_URI_PREFIX}://${ACCOUNT_LOOKUP_ADMIN_HOST}:${ACCOUNT_LOOKUP_ADMIN_PORT}${ACCOUNT_LOOKUP_ADMIN_BASE}oracles \
|
21
|
+
--header 'Cache-Control: no-cache' \
|
22
|
+
--header 'Content-Type: application/json' \
|
23
|
+
--header 'cache-control: no-cache' \
|
24
|
+
--header 'FSPIOP-Source: populateTestData.sh' \
|
25
|
+
--header 'Date: Thu, 24 Jan 2019 10:22:12 GMT' \
|
26
|
+
--data-raw '{
|
27
|
+
"oracleIdType": "MSISDN",
|
28
|
+
"endpoint": {
|
29
|
+
"value": "http://localhost:8444/oracle",
|
30
|
+
"endpointType": "URL"
|
31
|
+
},
|
32
|
+
"currency": "USD",
|
33
|
+
"isDefault": true
|
34
|
+
}'
|
35
|
+
|
36
|
+
echo
|
37
|
+
echo "---------------------------------------------------------------------"
|
38
|
+
echo " Creating TestData for $FSPList"
|
39
|
+
echo "---------------------------------------------------------------------"
|
40
|
+
echo " Prerequisites for Central-Ledger:"
|
41
|
+
echo " 1. Ensure you run 'npm run migrate'"
|
42
|
+
echo " 2. The below requests only work for the 'ADMIN' API"
|
43
|
+
|
44
|
+
for PAYEE_PARTICIPANT in "${PAYEE_PARTICIPANT_LIST[@]}"
|
45
|
+
do
|
46
|
+
echo ''
|
47
|
+
echo "*********************************************************************"
|
48
|
+
echo ''
|
49
|
+
echo
|
50
|
+
echo "Creating participants '$PAYEE_PARTICIPANT'"
|
51
|
+
echo "---------------------------------------------------------------------"
|
52
|
+
curl --location ${ACCOUNT_LOOKUP_FSPIOP_URI_PREFIX}://${ACCOUNT_LOOKUP_FSPIOP_HOST}:${ACCOUNT_LOOKUP_FSPIOP_PORT}${ACCOUNT_LOOKUP_FSPIOP_BASE}participants/MSISDN/${PAYEE_PARTICIPANT} \
|
53
|
+
--header 'Cache-Control: no-cache' \
|
54
|
+
--header 'Content-Type: application/vnd.interoperability.participants+json;version=1.1' \
|
55
|
+
--header 'Date: Thu, 24 Jan 2019 10:22:12 GMT' \
|
56
|
+
--header 'FSPIOP-Source: payeefsp' \
|
57
|
+
--header 'Accept: application/vnd.interoperability.participants+json;version=1.1' \
|
58
|
+
--data-binary '{
|
59
|
+
"fspId": "payeefsp",
|
60
|
+
"currency": "USD"
|
61
|
+
}'
|
62
|
+
done
|