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,40 @@
|
|
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
|
+
* Crosslake
|
22
|
+
- Lewis Daly <lewisd@crosslaketech.com>
|
23
|
+
|
24
|
+
--------------
|
25
|
+
******/
|
26
|
+
|
27
|
+
'use strict'
|
28
|
+
|
29
|
+
const Argv = require('../../../src/lib/argv')
|
30
|
+
|
31
|
+
describe('Argv', () => {
|
32
|
+
it('getArgs returns the args', async () => {
|
33
|
+
// Arrange
|
34
|
+
// Act
|
35
|
+
const result = Argv.getArgs()
|
36
|
+
|
37
|
+
// Assert
|
38
|
+
expect(result.length > 0).toBe(true)
|
39
|
+
})
|
40
|
+
})
|
@@ -0,0 +1,172 @@
|
|
1
|
+
'use strict'
|
2
|
+
|
3
|
+
const Sinon = require('sinon')
|
4
|
+
const Config = require('../../../src/lib/config')
|
5
|
+
const Cache = require('../../../src/lib/cache')
|
6
|
+
|
7
|
+
describe('Config tests', () => {
|
8
|
+
let sandbox
|
9
|
+
beforeEach(() => {
|
10
|
+
sandbox = Sinon.createSandbox()
|
11
|
+
Cache.registerCacheClient({
|
12
|
+
id: 'testCacheClient',
|
13
|
+
preloadCache: async () => sandbox.stub()
|
14
|
+
})
|
15
|
+
})
|
16
|
+
|
17
|
+
afterEach(() => {
|
18
|
+
sandbox.restore()
|
19
|
+
})
|
20
|
+
|
21
|
+
describe('Cache should', () => {
|
22
|
+
it('call constructor of CatboxMemory', async () => {
|
23
|
+
sandbox.stub(Cache.CatboxMemory.Engine)
|
24
|
+
const catboxMemoryConstructorSpy = sandbox.spy(Cache.CatboxMemory, 'Engine')
|
25
|
+
await Cache.initCache()
|
26
|
+
expect(catboxMemoryConstructorSpy.calledOnce).toBeTruthy()
|
27
|
+
await Cache.destroyCache()
|
28
|
+
})
|
29
|
+
|
30
|
+
it('init+start and then stop CatboxMemory', async () => {
|
31
|
+
sandbox.spy(Cache.CatboxMemory.Engine.prototype, 'start')
|
32
|
+
sandbox.spy(Cache.CatboxMemory.Engine.prototype, 'stop')
|
33
|
+
await Cache.initCache()
|
34
|
+
expect(Cache.CatboxMemory.Engine.prototype.start.calledOnce).toBeTruthy()
|
35
|
+
expect(Cache.CatboxMemory.Engine.prototype.stop.calledOnce).toBeFalsy()
|
36
|
+
await Cache.destroyCache()
|
37
|
+
expect(Cache.CatboxMemory.Engine.prototype.start.calledOnce).toBeTruthy()
|
38
|
+
expect(Cache.CatboxMemory.Engine.prototype.stop.calledOnce).toBeTruthy()
|
39
|
+
})
|
40
|
+
})
|
41
|
+
|
42
|
+
describe('Cache client', () => {
|
43
|
+
it('preload should be called once during Cache.initCache()', async () => {
|
44
|
+
let preloadCacheCalledCnt = 0
|
45
|
+
Cache.registerCacheClient({
|
46
|
+
id: 'testCacheClient',
|
47
|
+
preloadCache: async () => {
|
48
|
+
preloadCacheCalledCnt++
|
49
|
+
}
|
50
|
+
})
|
51
|
+
|
52
|
+
// Test participant-getAll gets called during cache init
|
53
|
+
expect(preloadCacheCalledCnt === 0).toBeTruthy()
|
54
|
+
await Cache.initCache()
|
55
|
+
expect(preloadCacheCalledCnt === 1).toBeTruthy()
|
56
|
+
|
57
|
+
// end
|
58
|
+
await Cache.destroyCache()
|
59
|
+
})
|
60
|
+
|
61
|
+
it('get() should call Catbox Memory get()', async () => {
|
62
|
+
Config.GENERAL_CACHE_CONFIG.CACHE_ENABLED = true
|
63
|
+
const getSpy = sandbox.spy(Cache.CatboxMemory.Engine.prototype, 'get')
|
64
|
+
|
65
|
+
const cacheClient = Cache.registerCacheClient({
|
66
|
+
id: 'testCacheClient',
|
67
|
+
preloadCache: async () => {}
|
68
|
+
})
|
69
|
+
|
70
|
+
// Test get()
|
71
|
+
expect(getSpy.called).toBeFalsy()
|
72
|
+
await Cache.initCache()
|
73
|
+
getSpy.resetHistory()
|
74
|
+
await cacheClient.get('')
|
75
|
+
expect(getSpy.called).toBeTruthy()
|
76
|
+
|
77
|
+
// end
|
78
|
+
await Cache.destroyCache()
|
79
|
+
})
|
80
|
+
|
81
|
+
it('get() should NOT call Catbox Memory get() when cache is disabled', async () => {
|
82
|
+
Config.GENERAL_CACHE_CONFIG.CACHE_ENABLED = false
|
83
|
+
const getSpy = sandbox.spy(Cache.CatboxMemory.Engine.prototype, 'get')
|
84
|
+
|
85
|
+
const cacheClient = Cache.registerCacheClient({
|
86
|
+
id: 'testCacheClient',
|
87
|
+
preloadCache: async () => {}
|
88
|
+
})
|
89
|
+
|
90
|
+
// Test get()
|
91
|
+
expect(getSpy.called).toBeFalsy()
|
92
|
+
await Cache.initCache()
|
93
|
+
getSpy.resetHistory()
|
94
|
+
await cacheClient.get('')
|
95
|
+
expect(getSpy.called).toBeFalsy()
|
96
|
+
|
97
|
+
// end
|
98
|
+
await Cache.destroyCache()
|
99
|
+
})
|
100
|
+
|
101
|
+
it('set() should call Catbox Memory set() and should work', async () => {
|
102
|
+
Config.GENERAL_CACHE_CONFIG.CACHE_ENABLED = true
|
103
|
+
const getSpy = sandbox.spy(Cache.CatboxMemory.Engine.prototype, 'get')
|
104
|
+
const setSpy = sandbox.spy(Cache.CatboxMemory.Engine.prototype, 'set')
|
105
|
+
const cacheClient = Cache.registerCacheClient({
|
106
|
+
id: 'testCacheClient',
|
107
|
+
preloadCache: async () => {}
|
108
|
+
})
|
109
|
+
const testKey = cacheClient.createKey('testKeyName')
|
110
|
+
const valueToCache = { a: 'some random value', b: 10 }
|
111
|
+
|
112
|
+
// Init cache
|
113
|
+
expect(setSpy.called).toBeFalsy()
|
114
|
+
await Cache.initCache()
|
115
|
+
setSpy.resetHistory()
|
116
|
+
getSpy.resetHistory()
|
117
|
+
|
118
|
+
// Test set()
|
119
|
+
await cacheClient.set(testKey, valueToCache)
|
120
|
+
expect(setSpy.called).toBeTruthy()
|
121
|
+
|
122
|
+
// Verify the value with get()
|
123
|
+
const valueFromCache = await cacheClient.get(testKey)
|
124
|
+
expect(getSpy.called).toBeTruthy()
|
125
|
+
expect(valueFromCache.item).toEqual(valueToCache)
|
126
|
+
|
127
|
+
// end
|
128
|
+
await Cache.destroyCache()
|
129
|
+
})
|
130
|
+
|
131
|
+
it('drop() works', async () => {
|
132
|
+
Config.GENERAL_CACHE_CONFIG.CACHE_ENABLED = true
|
133
|
+
const getSpy = sandbox.spy(Cache.CatboxMemory.Engine.prototype, 'get')
|
134
|
+
const setSpy = sandbox.spy(Cache.CatboxMemory.Engine.prototype, 'set')
|
135
|
+
const dropSpy = sandbox.spy(Cache.CatboxMemory.Engine.prototype, 'drop')
|
136
|
+
const cacheClient = Cache.registerCacheClient({
|
137
|
+
id: 'testCacheClient',
|
138
|
+
preloadCache: async () => {}
|
139
|
+
})
|
140
|
+
const testKey = cacheClient.createKey('testKeyName')
|
141
|
+
const valueToCache = { a: 'some random value', b: 10 }
|
142
|
+
|
143
|
+
// Init cache
|
144
|
+
expect(dropSpy.called).toBeFalsy()
|
145
|
+
expect(getSpy.called).toBeFalsy()
|
146
|
+
await Cache.initCache()
|
147
|
+
setSpy.resetHistory()
|
148
|
+
getSpy.resetHistory()
|
149
|
+
|
150
|
+
// Test set()
|
151
|
+
await cacheClient.set(testKey, valueToCache)
|
152
|
+
expect(setSpy.called).toBeTruthy()
|
153
|
+
|
154
|
+
// Verify the value with get()
|
155
|
+
const valueFromCache = await cacheClient.get(testKey)
|
156
|
+
expect(getSpy.called).toBeTruthy()
|
157
|
+
expect(valueFromCache.item).toEqual(valueToCache)
|
158
|
+
|
159
|
+
// Test drop()
|
160
|
+
await cacheClient.drop(testKey)
|
161
|
+
expect(setSpy.called).toBeTruthy()
|
162
|
+
|
163
|
+
// Verify the value doesn't exist in cache with get()
|
164
|
+
const valueFromCacheAfterDrop = await cacheClient.get(testKey)
|
165
|
+
expect(getSpy.called).toBeTruthy()
|
166
|
+
expect(valueFromCacheAfterDrop).toBeNull()
|
167
|
+
|
168
|
+
// end
|
169
|
+
await Cache.destroyCache()
|
170
|
+
})
|
171
|
+
})
|
172
|
+
})
|
@@ -0,0 +1,108 @@
|
|
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
|
+
* Shashikant Hirugade <shashikant.hirugade@modusbox.com>
|
22
|
+
--------------
|
23
|
+
******/
|
24
|
+
'use strict'
|
25
|
+
|
26
|
+
const src = '../../../src/'
|
27
|
+
|
28
|
+
const configImport = `${src}/lib/config`
|
29
|
+
jest.mock(configImport)
|
30
|
+
|
31
|
+
describe('Config tests', () => {
|
32
|
+
beforeEach(() => {
|
33
|
+
jest.resetModules()
|
34
|
+
})
|
35
|
+
|
36
|
+
afterEach(() => {
|
37
|
+
jest.clearAllMocks()
|
38
|
+
})
|
39
|
+
|
40
|
+
it('should load successfully', async () => {
|
41
|
+
// Setup
|
42
|
+
let Config = null
|
43
|
+
let isSuccess
|
44
|
+
// set env var
|
45
|
+
process.env.ALS_ENDPOINT_SECURITY__JWS__JWS_SIGN = true
|
46
|
+
|
47
|
+
// Act
|
48
|
+
try {
|
49
|
+
Config = jest.requireActual(configImport)
|
50
|
+
isSuccess = true
|
51
|
+
} catch (e) {
|
52
|
+
isSuccess = false
|
53
|
+
}
|
54
|
+
|
55
|
+
// Assert
|
56
|
+
expect(Config != null).toBe(true)
|
57
|
+
expect(isSuccess).toBe(true)
|
58
|
+
})
|
59
|
+
|
60
|
+
it('should parse ENV var ALS_PROTOCOL_VERSIONS__ACCEPT__VALIDATELIST as a string', async () => {
|
61
|
+
// Setup
|
62
|
+
let Config = null
|
63
|
+
let isSuccess
|
64
|
+
const validateList = ['1']
|
65
|
+
// set env var
|
66
|
+
process.env.ALS_PROTOCOL_VERSIONS__CONTENT__VALIDATELIST = JSON.stringify(validateList)
|
67
|
+
process.env.ALS_PROTOCOL_VERSIONS__ACCEPT__VALIDATELIST = JSON.stringify(validateList)
|
68
|
+
|
69
|
+
// Act
|
70
|
+
try {
|
71
|
+
Config = jest.requireActual(configImport)
|
72
|
+
isSuccess = true
|
73
|
+
} catch (e) {
|
74
|
+
isSuccess = false
|
75
|
+
}
|
76
|
+
|
77
|
+
// Assert
|
78
|
+
expect(Config != null).toBe(true)
|
79
|
+
expect(isSuccess).toBe(true)
|
80
|
+
expect(Config.PROTOCOL_VERSIONS.CONTENT.VALIDATELIST).toMatchObject(validateList)
|
81
|
+
expect(Config.PROTOCOL_VERSIONS.ACCEPT.VALIDATELIST).toMatchObject(validateList)
|
82
|
+
})
|
83
|
+
|
84
|
+
it('should should throw error when file not found', async () => {
|
85
|
+
// Setup
|
86
|
+
let Config = null
|
87
|
+
let error = null
|
88
|
+
let isSuccess
|
89
|
+
|
90
|
+
// set env var
|
91
|
+
process.env.ALS_ENDPOINT_SECURITY__JWS__JWS_SIGN = true
|
92
|
+
process.env.ALS_ENDPOINT_SECURITY__JWS__JWS_SIGNING_KEY_PATH = '/fake/path'
|
93
|
+
|
94
|
+
// Act
|
95
|
+
try {
|
96
|
+
Config = jest.requireActual(configImport)
|
97
|
+
isSuccess = true
|
98
|
+
} catch (e) {
|
99
|
+
isSuccess = false
|
100
|
+
error = e
|
101
|
+
}
|
102
|
+
|
103
|
+
// Assert
|
104
|
+
expect(Config).toBeDefined()
|
105
|
+
expect(isSuccess).toBe(false)
|
106
|
+
expect(error.message).toBe('File doesn\'t exist')
|
107
|
+
})
|
108
|
+
})
|
@@ -0,0 +1,89 @@
|
|
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
|
+
* Lewis Daly <lewis@vesselstech.com>
|
26
|
+
* Steven Oderayi <steven.oderayi@modusbox.com>
|
27
|
+
|
28
|
+
--------------
|
29
|
+
******/
|
30
|
+
|
31
|
+
'use strict'
|
32
|
+
|
33
|
+
const Sinon = require('sinon')
|
34
|
+
const { statusEnum, serviceName } = require('@mojaloop/central-services-shared').HealthCheck.HealthCheckEnums
|
35
|
+
const MigrationLockModel = require('../../../../src/models/misc/migrationLock')
|
36
|
+
const { getSubServiceHealthDatastore } = require('../../../../src/lib/healthCheck/subServiceHealth.js')
|
37
|
+
|
38
|
+
describe('SubServiceHealth test', () => {
|
39
|
+
let sandbox
|
40
|
+
|
41
|
+
beforeEach(() => {
|
42
|
+
sandbox = Sinon.createSandbox()
|
43
|
+
})
|
44
|
+
|
45
|
+
afterEach(() => {
|
46
|
+
sandbox.restore()
|
47
|
+
})
|
48
|
+
|
49
|
+
describe('getSubServiceHealthDatastore', () => {
|
50
|
+
it('datastore test passes when the database is not migration locked', async () => {
|
51
|
+
// Arrange
|
52
|
+
sandbox.stub(MigrationLockModel, 'getIsMigrationLocked').returns(false)
|
53
|
+
const expected = { name: serviceName.datastore, status: statusEnum.OK }
|
54
|
+
|
55
|
+
// Act
|
56
|
+
const result = await getSubServiceHealthDatastore()
|
57
|
+
|
58
|
+
// Assert
|
59
|
+
expect(result).toEqual(expected)
|
60
|
+
expect(MigrationLockModel.getIsMigrationLocked.called).toBe(true)
|
61
|
+
})
|
62
|
+
|
63
|
+
it('datastore test fails when the database is migration locked', async () => {
|
64
|
+
// Arrange
|
65
|
+
sandbox.stub(MigrationLockModel, 'getIsMigrationLocked').returns(true)
|
66
|
+
const expected = { name: serviceName.datastore, status: statusEnum.DOWN }
|
67
|
+
|
68
|
+
// Act
|
69
|
+
const result = await getSubServiceHealthDatastore()
|
70
|
+
|
71
|
+
// Assert
|
72
|
+
expect(result).toEqual(expected)
|
73
|
+
expect(MigrationLockModel.getIsMigrationLocked.called).toBe(true)
|
74
|
+
})
|
75
|
+
|
76
|
+
it('datastore test fails when getIsMigrationLocked throws', async () => {
|
77
|
+
// Arrange
|
78
|
+
sandbox.stub(MigrationLockModel, 'getIsMigrationLocked').throws(new Error('Error connecting to db'))
|
79
|
+
const expected = { name: serviceName.datastore, status: statusEnum.DOWN }
|
80
|
+
|
81
|
+
// Act
|
82
|
+
const result = await getSubServiceHealthDatastore()
|
83
|
+
|
84
|
+
// Assert
|
85
|
+
expect(result).toEqual(expected)
|
86
|
+
expect(MigrationLockModel.getIsMigrationLocked.called).toBe(true)
|
87
|
+
})
|
88
|
+
})
|
89
|
+
})
|
@@ -0,0 +1,52 @@
|
|
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
|
+
* Crosslake
|
22
|
+
- Lewis Daly <lewisd@crosslaketech.com>
|
23
|
+
|
24
|
+
* ModusBox
|
25
|
+
- Georgi Georgiev <georgi.georgiev@modusbox.com>
|
26
|
+
--------------
|
27
|
+
******/
|
28
|
+
'use strict'
|
29
|
+
|
30
|
+
const Migrations = require('@mojaloop/database-lib').Migrations
|
31
|
+
const Migrator = require('../../../src/lib/migrator')
|
32
|
+
|
33
|
+
describe('Migrator', () => {
|
34
|
+
beforeEach(() => {
|
35
|
+
const migrationsMethods = Object.getOwnPropertyNames(Migrations)
|
36
|
+
migrationsMethods.forEach((methodName) => {
|
37
|
+
jest.spyOn(Migrations, methodName).mockImplementation(() => {})
|
38
|
+
})
|
39
|
+
})
|
40
|
+
|
41
|
+
afterEach(() => {
|
42
|
+
jest.clearAllMocks()
|
43
|
+
})
|
44
|
+
|
45
|
+
it('runs the migration from the knexfile', async () => {
|
46
|
+
// Act
|
47
|
+
Migrator.migrate()
|
48
|
+
|
49
|
+
// Assert
|
50
|
+
expect(Migrations.migrate).toHaveBeenCalledTimes(1)
|
51
|
+
})
|
52
|
+
})
|
@@ -0,0 +1,115 @@
|
|
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
|
+
* Crosslake
|
22
|
+
- Lewis Daly <lewisd@crosslaketech.com>
|
23
|
+
|
24
|
+
--------------
|
25
|
+
******/
|
26
|
+
|
27
|
+
'use strict'
|
28
|
+
|
29
|
+
const Sinon = require('sinon')
|
30
|
+
const ErrorHandler = require('@mojaloop/central-services-error-handling')
|
31
|
+
|
32
|
+
const requestLogger = require('../../../src/lib/requestLogger')
|
33
|
+
const { logger } = require('../../../src/lib')
|
34
|
+
const fixtures = require('../../fixtures')
|
35
|
+
|
36
|
+
let sandbox
|
37
|
+
|
38
|
+
describe('requestLogger', () => {
|
39
|
+
beforeEach(() => {
|
40
|
+
sandbox = Sinon.createSandbox()
|
41
|
+
})
|
42
|
+
|
43
|
+
afterEach(() => {
|
44
|
+
sandbox.restore()
|
45
|
+
})
|
46
|
+
|
47
|
+
describe('logRequest', () => {
|
48
|
+
it('prints the request.payload if it exists', async () => {
|
49
|
+
// Arrange
|
50
|
+
const infoSpy = sandbox.spy(logger.mlLogger, 'info')
|
51
|
+
const req = {
|
52
|
+
...fixtures.mockHapiRequestDto(),
|
53
|
+
url: {
|
54
|
+
path: '/123/456'
|
55
|
+
},
|
56
|
+
query: {},
|
57
|
+
payload: {
|
58
|
+
itemA: 123,
|
59
|
+
itemB: 456
|
60
|
+
}
|
61
|
+
}
|
62
|
+
|
63
|
+
// Act
|
64
|
+
requestLogger.logRequest(req)
|
65
|
+
|
66
|
+
// Assert
|
67
|
+
expect(infoSpy.calledOnce).toBe(true)
|
68
|
+
const logLine = infoSpy.firstCall.args[0]
|
69
|
+
expect(logLine).toContain(JSON.stringify(req.headers))
|
70
|
+
expect(logLine).toContain(JSON.stringify(req.query))
|
71
|
+
expect(logLine).toContain(JSON.stringify(req.payload))
|
72
|
+
})
|
73
|
+
})
|
74
|
+
|
75
|
+
describe('logResponse', () => {
|
76
|
+
it('should log response statusCode', async () => {
|
77
|
+
// Arrange
|
78
|
+
const infoSpy = sandbox.spy(logger.mlLogger, 'info')
|
79
|
+
const req = {
|
80
|
+
...fixtures.mockHapiRequestDto(),
|
81
|
+
response: {
|
82
|
+
statusCode: 500
|
83
|
+
}
|
84
|
+
}
|
85
|
+
|
86
|
+
// Act
|
87
|
+
requestLogger.logResponse(req)
|
88
|
+
|
89
|
+
// Assert
|
90
|
+
const logLine = infoSpy.firstCall.args[0]
|
91
|
+
expect(logLine).toContain(JSON.stringify(req.response.statusCode))
|
92
|
+
})
|
93
|
+
|
94
|
+
it('handles valid json error response', async () => {
|
95
|
+
// Arrange
|
96
|
+
const infoSpy = sandbox.spy(logger.mlLogger, 'info')
|
97
|
+
const response = ErrorHandler.Factory.createFSPIOPError(ErrorHandler.Enums.FSPIOPErrorCodes.VALIDATION_ERROR, 'Invalid currency code')
|
98
|
+
const statusCode = 123
|
99
|
+
response.output = {
|
100
|
+
statusCode
|
101
|
+
}
|
102
|
+
const req = {
|
103
|
+
...fixtures.mockHapiRequestDto(),
|
104
|
+
response
|
105
|
+
}
|
106
|
+
|
107
|
+
// Act
|
108
|
+
requestLogger.logResponse(req)
|
109
|
+
|
110
|
+
// Assert
|
111
|
+
const logLine = infoSpy.firstCall.args[0]
|
112
|
+
expect(logLine).toContain(JSON.stringify(statusCode))
|
113
|
+
})
|
114
|
+
})
|
115
|
+
})
|
@@ -0,0 +1,68 @@
|
|
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
|
+
- Kevin Leyow <kevin.leyow@modusbox.com>
|
22
|
+
|
23
|
+
--------------
|
24
|
+
******/
|
25
|
+
|
26
|
+
'use strict'
|
27
|
+
|
28
|
+
const Util = require('../../../src/lib/util')
|
29
|
+
const Config = require('../../../src/lib/config')
|
30
|
+
const path = require('path')
|
31
|
+
|
32
|
+
describe('Util', () => {
|
33
|
+
it('pathForInterface should return correct path', async () => {
|
34
|
+
const apiPath = Util.pathForInterface({ isAdmin: false, isMockInterface: false })
|
35
|
+
const expectedAPIpathResult = path.join('interface', 'api-swagger.yaml')
|
36
|
+
expect(apiPath).toContain(expectedAPIpathResult)
|
37
|
+
|
38
|
+
const apiAdminPath = Util.pathForInterface({ isAdmin: true, isMockInterface: false })
|
39
|
+
const expectedApiAdminPath = path.join('interface', 'admin-swagger.yaml')
|
40
|
+
expect(apiAdminPath).toContain(expectedApiAdminPath)
|
41
|
+
|
42
|
+
const apiMockPath = Util.pathForInterface({ isAdmin: false, isMockInterface: true })
|
43
|
+
const expectedApiMockPath = path.join('interface', 'api_swagger.json')
|
44
|
+
expect(apiMockPath).toContain(expectedApiMockPath)
|
45
|
+
|
46
|
+
const apiAdminMockPath = Util.pathForInterface({ isAdmin: true, isMockInterface: true })
|
47
|
+
const expectedApiAdminMockPath = path.join('interface', 'admin_swagger.json')
|
48
|
+
expect(apiAdminMockPath).toContain(expectedApiAdminMockPath)
|
49
|
+
|
50
|
+
Config.FEATURE_ENABLE_EXTENDED_PARTY_ID_TYPE = true
|
51
|
+
|
52
|
+
const apiExtendedPath = Util.pathForInterface({ isAdmin: false, isMockInterface: false })
|
53
|
+
const expectedApiExtendedPath = path.join('interface', 'thirdparty', 'api-swagger.yaml')
|
54
|
+
expect(apiExtendedPath).toContain(expectedApiExtendedPath)
|
55
|
+
|
56
|
+
const apiExtendedAdminPath = Util.pathForInterface({ isAdmin: true, isMockInterface: false })
|
57
|
+
const expectedApiExtendedAdminPath = path.join('interface', 'thirdparty', 'admin-swagger.yaml')
|
58
|
+
expect(apiExtendedAdminPath).toContain(expectedApiExtendedAdminPath)
|
59
|
+
|
60
|
+
const apiExtendedMockPath = Util.pathForInterface({ isAdmin: false, isMockInterface: true })
|
61
|
+
const expectedApiExtendedMockPath = path.join('interface', 'thirdparty', 'api_swagger.json')
|
62
|
+
expect(apiExtendedMockPath).toContain(expectedApiExtendedMockPath)
|
63
|
+
|
64
|
+
const apiExtendedAdminMockPath = Util.pathForInterface({ isAdmin: true, isMockInterface: true })
|
65
|
+
const expectedApiExtendedAdminMockPath = path.join('interface', 'thirdparty', 'admin_swagger.json')
|
66
|
+
expect(apiExtendedAdminMockPath).toContain(expectedApiExtendedAdminMockPath)
|
67
|
+
})
|
68
|
+
})
|