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,28 @@
|
|
1
|
+
const { API_TYPES } = require('@mojaloop/central-services-shared').Util.Hapi
|
2
|
+
const { timeoutCallbackDto } = require('../../../../src/domain/timeout/dto')
|
3
|
+
const config = require('../../../../src/lib/config')
|
4
|
+
|
5
|
+
const realApiType = config.API_TYPE
|
6
|
+
|
7
|
+
describe('timeoutCallbackDto Tests -->', () => {
|
8
|
+
// test('dummy', () => {
|
9
|
+
// expect(1).toBe(1)
|
10
|
+
// })
|
11
|
+
|
12
|
+
afterAll(() => {
|
13
|
+
config.API_TYPE = realApiType
|
14
|
+
})
|
15
|
+
|
16
|
+
test('should produce ISO payload', async () => {
|
17
|
+
config.API_TYPE = API_TYPES.iso20022
|
18
|
+
const destination = 'D1'
|
19
|
+
const partyId = 'P1'
|
20
|
+
const partyType = 'XXX'
|
21
|
+
const dto = await timeoutCallbackDto({ destination, partyId, partyType })
|
22
|
+
expect(dto.errorInformation).toBeTruthy()
|
23
|
+
|
24
|
+
const { Assgnr, Assgne } = dto.errorInformation.Assgnmt
|
25
|
+
expect(Assgnr.Agt.FinInstnId.Othr.Id).toBe(config.HUB_NAME)
|
26
|
+
expect(Assgne.Agt.FinInstnId.Othr.Id).toBe(destination)
|
27
|
+
})
|
28
|
+
})
|
@@ -0,0 +1,81 @@
|
|
1
|
+
/*****
|
2
|
+
License
|
3
|
+
--------------
|
4
|
+
Copyright © 2020-2024 Mojaloop Foundation
|
5
|
+
|
6
|
+
The Mojaloop files are made available by the Mojaloop Foundation under the Apache License, Version 2.0
|
7
|
+
(the "License") and you may not use these files except in compliance with the [License](http://www.apache.org/licenses/LICENSE-2.0).
|
8
|
+
|
9
|
+
You may obtain a copy of the License at [http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0)
|
10
|
+
|
11
|
+
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](http://www.apache.org/licenses/LICENSE-2.0).
|
12
|
+
|
13
|
+
Contributors
|
14
|
+
--------------
|
15
|
+
This is the official list of the Mojaloop project contributors for this file.
|
16
|
+
Names of the original copyright holders (individuals or organizations)
|
17
|
+
should be listed with a '*' in the first column. People who have
|
18
|
+
contributed from an organization can be listed under the organization
|
19
|
+
that actually holds the copyright for their contributions (see the
|
20
|
+
Gates Foundation organization for an example). Those individuals should have
|
21
|
+
their names indented and be marked with a '-'. Email address can be added
|
22
|
+
optionally within square brackets <email>.
|
23
|
+
|
24
|
+
* Gates Foundation
|
25
|
+
- Name Surname <name.surname@gatesfoundation.com>
|
26
|
+
|
27
|
+
* INFITX
|
28
|
+
- Steven Oderayi <steven.oderayi@infitx.com>
|
29
|
+
--------------
|
30
|
+
******/
|
31
|
+
|
32
|
+
'use strict'
|
33
|
+
|
34
|
+
const Participant = require('../../../../src/models/participantEndpoint/facade')
|
35
|
+
const TimeoutDomain = require('../../../../src/domain/timeout')
|
36
|
+
|
37
|
+
describe('Timeout Domain', () => {
|
38
|
+
beforeEach(() => {
|
39
|
+
jest.clearAllMocks()
|
40
|
+
jest.spyOn(Participant, 'validateParticipant').mockResolvedValue({})
|
41
|
+
jest.spyOn(Participant, 'sendErrorToParticipant').mockResolvedValue({})
|
42
|
+
})
|
43
|
+
|
44
|
+
afterEach(() => {
|
45
|
+
jest.restoreAllMocks()
|
46
|
+
})
|
47
|
+
|
48
|
+
describe('timeoutInterschemePartiesLookups', () => {
|
49
|
+
describe('timeoutInterschemePartiesLookups', () => {
|
50
|
+
it('should process expired ALS keys', async () => {
|
51
|
+
const mockCache = { processExpiredAlsKeys: jest.fn() }
|
52
|
+
await TimeoutDomain.timeoutInterschemePartiesLookups({ proxyCache: mockCache, batchSize: 10 })
|
53
|
+
expect(mockCache.processExpiredAlsKeys).toHaveBeenCalledWith(TimeoutDomain.sendTimeoutCallback, 10)
|
54
|
+
})
|
55
|
+
})
|
56
|
+
|
57
|
+
describe('sendTimeoutCallback', () => {
|
58
|
+
it('should send error to participant', async () => {
|
59
|
+
jest.spyOn(Participant, 'validateParticipant').mockResolvedValue({ fspId: 'sourceId' })
|
60
|
+
|
61
|
+
const cacheKey = 'als:sourceId:2:3:expiresAt'
|
62
|
+
const [, destination] = cacheKey.split(':')
|
63
|
+
|
64
|
+
await TimeoutDomain.sendTimeoutCallback(cacheKey)
|
65
|
+
|
66
|
+
expect(Participant.validateParticipant).toHaveBeenCalledWith('sourceId')
|
67
|
+
expect(Participant.sendErrorToParticipant).toHaveBeenCalledWith(
|
68
|
+
destination,
|
69
|
+
'FSPIOP_CALLBACK_URL_PARTIES_PUT_ERROR',
|
70
|
+
{ errorInformation: { errorCode: '3300', errorDescription: 'Generic expired error' } },
|
71
|
+
expect.any(Object), expect.any(Object), undefined, expect.any(Object)
|
72
|
+
)
|
73
|
+
})
|
74
|
+
|
75
|
+
it('should throw error if participant validation fails', async () => {
|
76
|
+
Participant.validateParticipant.mockResolvedValue(null)
|
77
|
+
await expect(TimeoutDomain.sendTimeoutCallback('als:sourceId:2:3:expiresAt')).rejects.toThrow()
|
78
|
+
})
|
79
|
+
})
|
80
|
+
})
|
81
|
+
})
|
@@ -0,0 +1,125 @@
|
|
1
|
+
/*****
|
2
|
+
License
|
3
|
+
--------------
|
4
|
+
Copyright © 2020-2024 Mojaloop Foundation
|
5
|
+
|
6
|
+
The Mojaloop files are made available by the Mojaloop Foundation under the Apache License, Version 2.0
|
7
|
+
(the "License") and you may not use these files except in compliance with the [License](http://www.apache.org/licenses/LICENSE-2.0).
|
8
|
+
|
9
|
+
You may obtain a copy of the License at [http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0)
|
10
|
+
|
11
|
+
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](http://www.apache.org/licenses/LICENSE-2.0).
|
12
|
+
|
13
|
+
Contributors
|
14
|
+
--------------
|
15
|
+
This is the official list of the Mojaloop project contributors for this file.
|
16
|
+
Names of the original copyright holders (individuals or organizations)
|
17
|
+
should be listed with a '*' in the first column. People who have
|
18
|
+
contributed from an organization can be listed under the organization
|
19
|
+
that actually holds the copyright for their contributions (see the
|
20
|
+
Gates Foundation organization for an example). Those individuals should have
|
21
|
+
their names indented and be marked with a '-'. Email address can be added
|
22
|
+
optionally within square brackets <email>.
|
23
|
+
|
24
|
+
* Gates Foundation
|
25
|
+
- Name Surname <name.surname@gatesfoundation.com>
|
26
|
+
|
27
|
+
* INFITX
|
28
|
+
- Steven Oderayi <steven.oderayi@infitx.com>
|
29
|
+
--------------
|
30
|
+
******/
|
31
|
+
|
32
|
+
'use strict'
|
33
|
+
|
34
|
+
const CronJob = require('cron').CronJob
|
35
|
+
const TimeoutHandler = require('../../../src/handlers/TimeoutHandler')
|
36
|
+
const TimeoutService = require('../../../src/domain/timeout')
|
37
|
+
const Config = require('../../../src/lib/config')
|
38
|
+
const { logger } = require('../../../src/lib')
|
39
|
+
const DefaultConfig = { ...Config }
|
40
|
+
|
41
|
+
const wait = (ms) => new Promise(resolve => setTimeout(resolve, ms))
|
42
|
+
|
43
|
+
describe('TimeoutHandler', () => {
|
44
|
+
let mockOptions
|
45
|
+
|
46
|
+
beforeEach(() => {
|
47
|
+
jest.spyOn(CronJob, 'from').mockReturnValue({
|
48
|
+
start: jest.fn(),
|
49
|
+
stop: jest.fn()
|
50
|
+
})
|
51
|
+
const mockProxyCache = { processExpiredAlsKeys: jest.fn() }
|
52
|
+
mockOptions = { proxyCache: mockProxyCache, batchSize: 10, logger }
|
53
|
+
})
|
54
|
+
|
55
|
+
afterEach(async () => {
|
56
|
+
jest.clearAllMocks()
|
57
|
+
})
|
58
|
+
|
59
|
+
describe('timeout', () => {
|
60
|
+
it('should execute timout service', async () => {
|
61
|
+
jest.spyOn(TimeoutService, 'timeoutInterschemePartiesLookups').mockResolvedValue()
|
62
|
+
await expect(TimeoutHandler.timeout(mockOptions)).resolves.toBeUndefined()
|
63
|
+
expect(TimeoutService.timeoutInterschemePartiesLookups).toHaveBeenCalled()
|
64
|
+
})
|
65
|
+
|
66
|
+
it('should not run if isRunning is true', async () => {
|
67
|
+
jest.spyOn(TimeoutService, 'timeoutInterschemePartiesLookups').mockImplementation(async () => {
|
68
|
+
await wait(1000)
|
69
|
+
})
|
70
|
+
await Promise.all([
|
71
|
+
TimeoutHandler.timeout(mockOptions),
|
72
|
+
TimeoutHandler.timeout(mockOptions)
|
73
|
+
])
|
74
|
+
expect(TimeoutService.timeoutInterschemePartiesLookups).toHaveBeenCalledTimes(1)
|
75
|
+
})
|
76
|
+
})
|
77
|
+
|
78
|
+
describe('register', () => {
|
79
|
+
it('should register handler', async () => {
|
80
|
+
jest.spyOn(TimeoutHandler, 'stop')
|
81
|
+
const result = await TimeoutHandler.register(mockOptions)
|
82
|
+
|
83
|
+
expect(result).toBe(true)
|
84
|
+
expect(TimeoutHandler.stop).not.toHaveBeenCalled()
|
85
|
+
expect(CronJob.from).toHaveBeenCalledWith({
|
86
|
+
start: false,
|
87
|
+
onTick: expect.any(Function),
|
88
|
+
cronTime: Config.HANDLERS_TIMEOUT_TIMEXP,
|
89
|
+
timeZone: Config.HANDLERS_TIMEOUT_TIMEZONE
|
90
|
+
})
|
91
|
+
expect(CronJob.from().start).toHaveBeenCalled()
|
92
|
+
|
93
|
+
await TimeoutHandler.stop()
|
94
|
+
})
|
95
|
+
|
96
|
+
it('should not register handler if HANDLERS_TIMEOUT_DISABLED is true', async () => {
|
97
|
+
Config.HANDLERS_TIMEOUT_DISABLED = true
|
98
|
+
|
99
|
+
const result = await TimeoutHandler.register(mockOptions)
|
100
|
+
|
101
|
+
expect(result).toBe(false)
|
102
|
+
expect(CronJob.from).not.toHaveBeenCalled()
|
103
|
+
Config.HANDLERS_TIMEOUT_DISABLED = DefaultConfig.HANDLERS_TIMEOUT_DISABLED
|
104
|
+
})
|
105
|
+
})
|
106
|
+
|
107
|
+
describe('stop', () => {
|
108
|
+
it('should stop handler', async () => {
|
109
|
+
jest.spyOn(TimeoutHandler, 'register')
|
110
|
+
await TimeoutHandler.register(mockOptions)
|
111
|
+
await TimeoutHandler.stop()
|
112
|
+
|
113
|
+
expect(CronJob.from().stop).toHaveBeenCalled()
|
114
|
+
expect(TimeoutHandler.register).toHaveBeenCalled()
|
115
|
+
})
|
116
|
+
|
117
|
+
it('should not stop if not registered', async () => {
|
118
|
+
jest.spyOn(TimeoutHandler, 'register')
|
119
|
+
await TimeoutHandler.stop()
|
120
|
+
|
121
|
+
expect(CronJob.from().stop).not.toHaveBeenCalled()
|
122
|
+
expect(TimeoutHandler.register).not.toHaveBeenCalled()
|
123
|
+
})
|
124
|
+
})
|
125
|
+
})
|
@@ -0,0 +1,56 @@
|
|
1
|
+
/*****
|
2
|
+
License
|
3
|
+
--------------
|
4
|
+
Copyright © 2020-2024 Mojaloop Foundation
|
5
|
+
|
6
|
+
The Mojaloop files are made available by the Mojaloop Foundation under the Apache License, Version 2.0
|
7
|
+
(the "License") and you may not use these files except in compliance with the [License](http://www.apache.org/licenses/LICENSE-2.0).
|
8
|
+
|
9
|
+
You may obtain a copy of the License at [http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0)
|
10
|
+
|
11
|
+
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](http://www.apache.org/licenses/LICENSE-2.0).
|
12
|
+
|
13
|
+
Contributors
|
14
|
+
--------------
|
15
|
+
This is the official list of the Mojaloop project contributors for this file.
|
16
|
+
Names of the original copyright holders (individuals or organizations)
|
17
|
+
should be listed with a '*' in the first column. People who have
|
18
|
+
contributed from an organization can be listed under the organization
|
19
|
+
that actually holds the copyright for their contributions (see the
|
20
|
+
Gates Foundation organization for an example). Those individuals should have
|
21
|
+
their names indented and be marked with a '-'. Email address can be added
|
22
|
+
optionally within square brackets <email>.
|
23
|
+
|
24
|
+
* Gates Foundation
|
25
|
+
- Name Surname <name.surname@gatesfoundation.com>
|
26
|
+
|
27
|
+
* INFITX
|
28
|
+
- Steven Oderayi <steven.oderayi@infitx.com>
|
29
|
+
--------------
|
30
|
+
******/
|
31
|
+
|
32
|
+
'use strict'
|
33
|
+
|
34
|
+
const Server = require('../../../src/server')
|
35
|
+
const { HANDLER_TYPES } = require('../../../src/constants')
|
36
|
+
const Config = require('../../../src/lib/config')
|
37
|
+
|
38
|
+
describe('Handlers Index', () => {
|
39
|
+
beforeEach(() => {
|
40
|
+
jest.clearAllMocks()
|
41
|
+
jest.spyOn(Server, 'initializeHandlers').mockImplementation(() => {})
|
42
|
+
})
|
43
|
+
|
44
|
+
it('should start specified handlers in args', async () => {
|
45
|
+
process.argv = ['node', 'index.js', 'handlers', '--timeout']
|
46
|
+
require('../../../src/handlers/index')
|
47
|
+
const expectedLogger = { info: expect.any(Function), error: expect.any(Function) }
|
48
|
+
expect(Server.initializeHandlers).toHaveBeenCalledWith([HANDLER_TYPES.TIMEOUT], Config, expect.objectContaining(expectedLogger))
|
49
|
+
})
|
50
|
+
|
51
|
+
it('should not start any handlers if none are specified', async () => {
|
52
|
+
process.argv = ['node', 'index.js', 'handlers']
|
53
|
+
require('../../../src/handlers/index')
|
54
|
+
expect(Server.initializeHandlers).not.toHaveBeenCalled()
|
55
|
+
})
|
56
|
+
})
|
@@ -0,0 +1,90 @@
|
|
1
|
+
/*****
|
2
|
+
License
|
3
|
+
--------------
|
4
|
+
Copyright © 2020-2024 Mojaloop Foundation
|
5
|
+
|
6
|
+
The Mojaloop files are made available by the Mojaloop Foundation under the Apache License, Version 2.0
|
7
|
+
(the "License") and you may not use these files except in compliance with the [License](http://www.apache.org/licenses/LICENSE-2.0).
|
8
|
+
|
9
|
+
You may obtain a copy of the License at [http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0)
|
10
|
+
|
11
|
+
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](http://www.apache.org/licenses/LICENSE-2.0).
|
12
|
+
|
13
|
+
Contributors
|
14
|
+
--------------
|
15
|
+
This is the official list of the Mojaloop project contributors for this file.
|
16
|
+
Names of the original copyright holders (individuals or organizations)
|
17
|
+
should be listed with a '*' in the first column. People who have
|
18
|
+
contributed from an organization can be listed under the organization
|
19
|
+
that actually holds the copyright for their contributions (see the
|
20
|
+
Gates Foundation organization for an example). Those individuals should have
|
21
|
+
their names indented and be marked with a '-'. Email address can be added
|
22
|
+
optionally within square brackets <email>.
|
23
|
+
|
24
|
+
* Gates Foundation
|
25
|
+
- Name Surname <name.surname@gatesfoundation.com>
|
26
|
+
|
27
|
+
* INFITX
|
28
|
+
- Steven Oderayi <steven.oderayi@infitx.com>
|
29
|
+
--------------
|
30
|
+
******/
|
31
|
+
|
32
|
+
'use strict'
|
33
|
+
|
34
|
+
const TimeoutHandler = require('../../../src/handlers/TimeoutHandler')
|
35
|
+
const { HANDLER_TYPES } = require('../../../src/constants')
|
36
|
+
const { registerHandlers, registerAllHandlers, stopAllHandlers } = require('../../../src/handlers/register')
|
37
|
+
const Monitoring = require('../../../src/handlers/monitoring')
|
38
|
+
const { logger } = require('../../../src/lib')
|
39
|
+
|
40
|
+
describe('RegisterHandlers', () => {
|
41
|
+
let mockOptions
|
42
|
+
|
43
|
+
beforeEach(() => {
|
44
|
+
jest.clearAllMocks()
|
45
|
+
jest.spyOn(logger, 'debug')
|
46
|
+
jest.spyOn(logger, 'warn')
|
47
|
+
TimeoutHandler.register = jest.fn()
|
48
|
+
Monitoring.start = jest.fn()
|
49
|
+
Monitoring.stop = jest.fn()
|
50
|
+
const mockProxyCache = { processExpiredAlsKeys: jest.fn() }
|
51
|
+
mockOptions = { proxyCache: mockProxyCache, batchSize: 10, logger }
|
52
|
+
})
|
53
|
+
|
54
|
+
describe('registerHandlers', () => {
|
55
|
+
it('should register all handlers', async () => {
|
56
|
+
const handlers = [HANDLER_TYPES.TIMEOUT]
|
57
|
+
await registerHandlers(handlers, mockOptions)
|
58
|
+
|
59
|
+
expect(logger.debug).toHaveBeenCalledWith('Registering Timeout Handler')
|
60
|
+
expect(TimeoutHandler.register).toHaveBeenCalled()
|
61
|
+
})
|
62
|
+
|
63
|
+
it('should not register unknown handlers', async () => {
|
64
|
+
const handlers = ['unknown']
|
65
|
+
await registerHandlers(handlers, mockOptions)
|
66
|
+
|
67
|
+
expect(logger.warn).toHaveBeenCalledWith('Handler unknown not found')
|
68
|
+
})
|
69
|
+
})
|
70
|
+
|
71
|
+
describe('registerAllHandlers', () => {
|
72
|
+
it('should register all handlers', async () => {
|
73
|
+
await registerAllHandlers(mockOptions)
|
74
|
+
|
75
|
+
expect(logger.debug).toHaveBeenCalledWith('Registering all handlers')
|
76
|
+
expect(TimeoutHandler.register).toHaveBeenCalled()
|
77
|
+
})
|
78
|
+
})
|
79
|
+
|
80
|
+
describe('stopAllHandlers', () => {
|
81
|
+
it('should stop all handlers', async () => {
|
82
|
+
jest.spyOn(TimeoutHandler, 'stop')
|
83
|
+
|
84
|
+
await stopAllHandlers({ logger })
|
85
|
+
|
86
|
+
expect(logger.debug).toHaveBeenCalledWith('Stopping all handlers')
|
87
|
+
expect(TimeoutHandler.stop).toHaveBeenCalled()
|
88
|
+
})
|
89
|
+
})
|
90
|
+
})
|
@@ -0,0 +1,139 @@
|
|
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
|
+
* ModusBox
|
22
|
+
- Rajiv Mothilal <rajiv.mothilal@modusbox.com>
|
23
|
+
|
24
|
+
* Crosslake
|
25
|
+
- Lewis Daly <lewisd@crosslaketech.com>
|
26
|
+
|
27
|
+
--------------
|
28
|
+
******/
|
29
|
+
|
30
|
+
/*
|
31
|
+
For testing the server imports, we need to use jest.resetModules() between tests
|
32
|
+
This means specifying future imports here and actually doing the importing in `beforeEach`
|
33
|
+
*/
|
34
|
+
let Sinon
|
35
|
+
let Command
|
36
|
+
let sandbox
|
37
|
+
const Config = require('../../src/lib/config')
|
38
|
+
|
39
|
+
describe('Base Tests', () => {
|
40
|
+
beforeEach(() => {
|
41
|
+
jest.resetModules()
|
42
|
+
|
43
|
+
Sinon = require('sinon')
|
44
|
+
Command = require('commander').Command
|
45
|
+
|
46
|
+
sandbox = Sinon.createSandbox()
|
47
|
+
})
|
48
|
+
|
49
|
+
afterEach(() => {
|
50
|
+
jest.restoreAllMocks()
|
51
|
+
})
|
52
|
+
|
53
|
+
it('should display help if called with no args', () => {
|
54
|
+
// Arrange
|
55
|
+
const sandbox = Sinon.createSandbox()
|
56
|
+
const mockInitStub = sandbox.stub()
|
57
|
+
const helpStub = sandbox.stub(Command.prototype, 'help').returns(true)
|
58
|
+
|
59
|
+
jest.mock('../../src/server.js', () => ({ initializeApi: mockInitStub, initializeAdmin: mockInitStub }))
|
60
|
+
jest.mock('../../src/lib/argv.js', () => ({
|
61
|
+
getArgs: () => []
|
62
|
+
}))
|
63
|
+
|
64
|
+
// Act
|
65
|
+
require('../../src/index')
|
66
|
+
// Assert
|
67
|
+
// When starting with help, the help() method gets called
|
68
|
+
expect(helpStub.callCount).toBe(1)
|
69
|
+
})
|
70
|
+
|
71
|
+
it('should start the server with the default config', () => {
|
72
|
+
// Arrange
|
73
|
+
const mockInitStub = sandbox.stub()
|
74
|
+
const mockArgs = [
|
75
|
+
'node',
|
76
|
+
'src/index.js',
|
77
|
+
'server'
|
78
|
+
]
|
79
|
+
jest.mock('../../src/server.js', () => ({ initializeApi: mockInitStub, initializeAdmin: mockInitStub }))
|
80
|
+
jest.mock('../../src/lib/argv.js', () => ({
|
81
|
+
getArgs: () => mockArgs
|
82
|
+
}))
|
83
|
+
|
84
|
+
// Act
|
85
|
+
require('../../src/index.js')
|
86
|
+
|
87
|
+
// Assert
|
88
|
+
// When starting with default args, both the admin and api servers get startec
|
89
|
+
expect(mockInitStub.calledTwice).toBe(true)
|
90
|
+
})
|
91
|
+
|
92
|
+
it('should start the server with the --api config', () => {
|
93
|
+
// Arrange
|
94
|
+
const mockInitStub = sandbox.stub()
|
95
|
+
const mockArgs = [
|
96
|
+
'node',
|
97
|
+
'src/index.js',
|
98
|
+
'server',
|
99
|
+
'--api'
|
100
|
+
]
|
101
|
+
jest.mock('../../src/server.js', () => ({ initializeApi: mockInitStub }))
|
102
|
+
jest.mock('../../src/lib/argv.js', () => ({
|
103
|
+
getArgs: () => mockArgs
|
104
|
+
}))
|
105
|
+
|
106
|
+
// Act
|
107
|
+
require('../../src/index.js')
|
108
|
+
|
109
|
+
// Assert
|
110
|
+
// When starting with default args, both the admin and api servers get startec
|
111
|
+
expect(mockInitStub.callCount).toBe(1)
|
112
|
+
const initStubArgs = mockInitStub.getCall(0).args
|
113
|
+
expect(initStubArgs[0]).toStrictEqual(Config)
|
114
|
+
})
|
115
|
+
|
116
|
+
it('should start the server with the --admin config', () => {
|
117
|
+
// Arrange
|
118
|
+
const mockInitStub = sandbox.stub()
|
119
|
+
const mockArgs = [
|
120
|
+
'node',
|
121
|
+
'src/index.js',
|
122
|
+
'server',
|
123
|
+
'--admin'
|
124
|
+
]
|
125
|
+
jest.mock('../../src/server.js', () => ({ initializeAdmin: mockInitStub }))
|
126
|
+
jest.mock('../../src/lib/argv.js', () => ({
|
127
|
+
getArgs: () => mockArgs
|
128
|
+
}))
|
129
|
+
|
130
|
+
// Act
|
131
|
+
require('../../src/index.js')
|
132
|
+
|
133
|
+
// Assert
|
134
|
+
// When starting with default args, both the admin and api servers get startec
|
135
|
+
expect(mockInitStub.callCount).toBe(1)
|
136
|
+
const initStubArgs = mockInitStub.getCall(0).args
|
137
|
+
expect(initStubArgs[0]).toStrictEqual(Config)
|
138
|
+
})
|
139
|
+
})
|
@@ -0,0 +1,129 @@
|
|
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
|
+
|
9
|
+
Contributors
|
10
|
+
--------------
|
11
|
+
This is the official list of the Mojaloop project contributors for this file.
|
12
|
+
Names of the original copyright holders (individuals or organizations)
|
13
|
+
should be listed with a '*' in the first column. People who have
|
14
|
+
contributed from an organization can be listed under the organization
|
15
|
+
that actually holds the copyright for their contributions (see the
|
16
|
+
Gates Foundation organization for an example). Those individuals should have
|
17
|
+
their names indented and be marked with a '-'. Email address can be added
|
18
|
+
optionally within square brackets <email>.
|
19
|
+
* Gates Foundation
|
20
|
+
- Name Surname <name.surname@gatesfoundation.com>
|
21
|
+
|
22
|
+
* Eugen Klymniuk <eugen.klymniuk@infitx.com>
|
23
|
+
--------------
|
24
|
+
**********/
|
25
|
+
|
26
|
+
const { setTimeout: sleep } = require('node:timers/promises')
|
27
|
+
const Sinon = require('sinon')
|
28
|
+
const getPort = require('get-port')
|
29
|
+
const { API_TYPES } = require('@mojaloop/central-services-shared').Util.Hapi
|
30
|
+
|
31
|
+
const { initializeApi } = require('../../../src/server')
|
32
|
+
const participant = require('../../../src/models/participantEndpoint/facade')
|
33
|
+
const config = require('../../../src/lib/config')
|
34
|
+
const db = require('../../../src/lib/db')
|
35
|
+
|
36
|
+
const { partiesHeadersDto } = require('../../util/helper')
|
37
|
+
const { isoPartiesPutPayloadDto } = require('../../fixtures')
|
38
|
+
|
39
|
+
describe('ISO20022 PUT /parties endpoints validation Tests -->', () => {
|
40
|
+
let server
|
41
|
+
let sandbox
|
42
|
+
|
43
|
+
beforeAll(async () => {
|
44
|
+
sandbox = Sinon.createSandbox()
|
45
|
+
sandbox.stub(db, 'connect').resolves({})
|
46
|
+
config.API_PORT = await getPort()
|
47
|
+
config.API_TYPE = API_TYPES.iso20022
|
48
|
+
server = await initializeApi(config)
|
49
|
+
})
|
50
|
+
|
51
|
+
beforeEach(() => {
|
52
|
+
sandbox.stub(participant)
|
53
|
+
})
|
54
|
+
|
55
|
+
afterEach(() => {
|
56
|
+
sandbox.restore()
|
57
|
+
})
|
58
|
+
|
59
|
+
afterAll(async () => {
|
60
|
+
await server.stop()
|
61
|
+
})
|
62
|
+
|
63
|
+
test('should return 400 if fspiop headers were sent in case of API_TYPE=iso20022', async () => {
|
64
|
+
const headers = partiesHeadersDto({ apiType: API_TYPES.fspiop })
|
65
|
+
const request = {
|
66
|
+
method: 'PUT',
|
67
|
+
url: '/parties/MSISDN/123456789',
|
68
|
+
headers,
|
69
|
+
payload: {}
|
70
|
+
}
|
71
|
+
const { statusCode, result } = await server.inject(request)
|
72
|
+
|
73
|
+
expect(statusCode).toBe(400)
|
74
|
+
expect(result.errorInformation.errorDescription).toBe('Malformed syntax - Invalid accept header')
|
75
|
+
})
|
76
|
+
|
77
|
+
test('should pass headers validation, and fail due to incorrect payload', async () => {
|
78
|
+
const headers = partiesHeadersDto({ apiType: API_TYPES.iso20022 })
|
79
|
+
const request = {
|
80
|
+
method: 'PUT',
|
81
|
+
url: '/parties/MSISDN/123456789',
|
82
|
+
headers,
|
83
|
+
payload: {}
|
84
|
+
}
|
85
|
+
const { statusCode, result } = await server.inject(request)
|
86
|
+
|
87
|
+
expect(statusCode).toBe(400)
|
88
|
+
expect(result.errorInformation.errorDescription).toBe("Missing mandatory element - /requestBody must have required property 'Assgnmt'")
|
89
|
+
})
|
90
|
+
|
91
|
+
test('should return 200 from PUT /parties/{Type}/{ID} with proper ISO payload', async () => {
|
92
|
+
const headers = partiesHeadersDto({ apiType: API_TYPES.iso20022 })
|
93
|
+
const payload = isoPartiesPutPayloadDto()
|
94
|
+
const request = {
|
95
|
+
method: 'PUT',
|
96
|
+
url: '/parties/MSISDN/123456789',
|
97
|
+
headers,
|
98
|
+
payload
|
99
|
+
}
|
100
|
+
const response = await server.inject(request)
|
101
|
+
expect(response.statusCode).toBe(200)
|
102
|
+
})
|
103
|
+
|
104
|
+
test('should forward PUT /parties/{Type}/{ID} callback payload (ISO format)', async () => {
|
105
|
+
const headers = partiesHeadersDto({ apiType: API_TYPES.iso20022 })
|
106
|
+
const payload = isoPartiesPutPayloadDto()
|
107
|
+
const request = {
|
108
|
+
method: 'PUT',
|
109
|
+
url: '/parties/MSISDN/123456789',
|
110
|
+
headers,
|
111
|
+
payload
|
112
|
+
}
|
113
|
+
participant.validateParticipant = sandbox.stub().resolves({})
|
114
|
+
|
115
|
+
const { statusCode } = await server.inject(request)
|
116
|
+
expect(statusCode).toBe(200)
|
117
|
+
await sleep(1000)
|
118
|
+
|
119
|
+
expect(participant.validateParticipant.callCount).toBe(2)
|
120
|
+
expect(participant.sendRequest.callCount).toBe(1)
|
121
|
+
|
122
|
+
const { args } = participant.sendRequest.getCalls()[0]
|
123
|
+
const contentType = args[0]['content-type']
|
124
|
+
expect(contentType).toContain('iso20022')
|
125
|
+
|
126
|
+
const sentPayload = JSON.parse(args[4])
|
127
|
+
expect(sentPayload).toEqual(payload)
|
128
|
+
})
|
129
|
+
})
|
@@ -0,0 +1,18 @@
|
|
1
|
+
const { TransformFacades } = require('../../../src/lib')
|
2
|
+
const { errorCallbackResponseDto, partiesCallHeadersDto } = require('../../fixtures')
|
3
|
+
|
4
|
+
describe('TransformFacades Tests -->', () => {
|
5
|
+
// test('dummy', () => {
|
6
|
+
// expect(1).toBe(1)
|
7
|
+
// })
|
8
|
+
test('should transform PUT /parties error callback payload to ISO format', async () => {
|
9
|
+
const body = errorCallbackResponseDto()
|
10
|
+
const headers = partiesCallHeadersDto()
|
11
|
+
const isoPayload = await TransformFacades.FSPIOP.parties.putError({ body, headers })
|
12
|
+
expect(isoPayload.body).toBeTruthy()
|
13
|
+
expect(isoPayload.body.Assgnmt).toBeTruthy()
|
14
|
+
expect(isoPayload.body.Assgnmt.Assgnr).toBeTruthy()
|
15
|
+
expect(isoPayload.body.Assgnmt.Assgne).toBeTruthy()
|
16
|
+
expect(isoPayload.body.Rpt).toBeTruthy()
|
17
|
+
})
|
18
|
+
})
|