account-lookup-service 17.12.3 → 17.12.5-snapshot.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/package.json +4 -4
- package/{sbom-v17.12.2.csv → sbom-v17.12.4.csv} +249 -219
- package/src/domain/parties/services/BasePartiesService.js +9 -3
- package/src/domain/parties/services/PutPartiesErrorService.js +2 -1
- package/src/lib/config.js +2 -1
- package/src/models/oracle/facade.js +4 -1
- package/src/models/participantEndpoint/facade.js +7 -2
- package/test/unit/domain/parties/parties.test.js +29 -11
- package/test/unit/domain/parties/services/BasePartiesService.test.js +1 -0
- package/test/unit/domain/parties/services/PutPartiesErrorService.test.js +16 -15
- package/test/unit/domain/parties/services/PutPartiesService.test.js +117 -0
- package/test/unit/models/participantEndpoint/facade.test.js +20 -0
@@ -107,9 +107,13 @@ class BasePartiesService {
|
|
107
107
|
try {
|
108
108
|
log.error('error in processing parties request: ', error)
|
109
109
|
const fspiopError = ErrorHandler.Factory.reformatFSPIOPError(error)
|
110
|
+
|
110
111
|
const callbackHeaders = BasePartiesService.createErrorCallbackHeaders(this.inputs.headers, params)
|
111
112
|
const errorInfo = await this.deps.partiesUtils.makePutPartiesErrorPayload(this.deps.config, fspiopError, callbackHeaders, params)
|
112
113
|
|
114
|
+
this.state.destination = callbackHeaders[Headers.FSPIOP.DESTINATION]
|
115
|
+
await this.identifyDestinationForCallback()
|
116
|
+
|
113
117
|
await this.sendErrorCallback({
|
114
118
|
errorInfo,
|
115
119
|
headers: callbackHeaders,
|
@@ -127,7 +131,7 @@ class BasePartiesService {
|
|
127
131
|
async validateParticipant (participantId) {
|
128
132
|
try {
|
129
133
|
this.stepInProgress('validateParticipant')
|
130
|
-
return this.deps.participant.validateParticipant(participantId)
|
134
|
+
return await this.deps.participant.validateParticipant(participantId)
|
131
135
|
} catch (err) {
|
132
136
|
this.log.warn(`error in validateParticipant ${participantId}: `, err)
|
133
137
|
return null
|
@@ -157,7 +161,7 @@ class BasePartiesService {
|
|
157
161
|
|
158
162
|
async sendErrorCallback ({ errorInfo, headers, params }) {
|
159
163
|
this.stepInProgress('sendErrorCallback')
|
160
|
-
const sendTo = this.state.requester || headers[Headers.FSPIOP.DESTINATION]
|
164
|
+
const sendTo = this.state.requester || headers[Headers.FSPIOP.DESTINATION]
|
161
165
|
const endpointType = this.deps.partiesUtils.errorPartyCbType(params.SubId)
|
162
166
|
|
163
167
|
await this.deps.participant.sendErrorToParticipant(
|
@@ -168,7 +172,9 @@ class BasePartiesService {
|
|
168
172
|
|
169
173
|
async sendDeleteOracleRequest (headers, params) {
|
170
174
|
this.stepInProgress('sendDeleteOracleRequest')
|
171
|
-
|
175
|
+
const result = await this.deps.oracle.oracleRequest(headers, RestMethods.DELETE, params, null, null, this.deps.cache)
|
176
|
+
this.log.verbose('sendDeleteOracleRequest is done', { params })
|
177
|
+
return result
|
172
178
|
}
|
173
179
|
|
174
180
|
async removeProxyGetPartiesTimeoutCache (alsReq) {
|
@@ -42,7 +42,7 @@ class PutPartiesErrorService extends BasePartiesService {
|
|
42
42
|
}
|
43
43
|
} else {
|
44
44
|
const schemeParticipant = await this.validateParticipant(this.state.destination)
|
45
|
-
if (schemeParticipant) {
|
45
|
+
if (!schemeParticipant) {
|
46
46
|
this.log.info('Need to cleanup oracle and forward SERVICE_CURRENTLY_UNAVAILABLE error')
|
47
47
|
await this.cleanupOracle()
|
48
48
|
await this.removeProxyGetPartiesTimeoutCache(alsReq)
|
@@ -86,6 +86,7 @@ class PutPartiesErrorService extends BasePartiesService {
|
|
86
86
|
const callbackHeaders = BasePartiesService.createErrorCallbackHeaders(headers, params, this.state.destination)
|
87
87
|
const errorInfo = await this.deps.partiesUtils.makePutPartiesErrorPayload(this.deps.config, error, callbackHeaders, params)
|
88
88
|
|
89
|
+
await this.identifyDestinationForCallback()
|
89
90
|
await super.sendErrorCallback({
|
90
91
|
errorInfo,
|
91
92
|
headers: callbackHeaders,
|
package/src/lib/config.js
CHANGED
@@ -175,7 +175,8 @@ const config = {
|
|
175
175
|
FEATURE_ENABLE_EXTENDED_PARTY_ID_TYPE: RC.FEATURE_ENABLE_EXTENDED_PARTY_ID_TYPE || false,
|
176
176
|
PROTOCOL_VERSIONS: getProtocolVersions(DEFAULT_PROTOCOL_VERSION, RC.PROTOCOL_VERSIONS),
|
177
177
|
PROXY_CACHE_CONFIG: RC.PROXY_CACHE,
|
178
|
-
DELETE_PARTICIPANT_VALIDATION_ENABLED: RC.DELETE_PARTICIPANT_VALIDATION_ENABLED || false
|
178
|
+
DELETE_PARTICIPANT_VALIDATION_ENABLED: RC.DELETE_PARTICIPANT_VALIDATION_ENABLED || false,
|
179
|
+
HTTP_REQUEST_TIMEOUT_MS: RC.HTTP_REQUEST_TIMEOUT_MS ?? 20_000
|
179
180
|
}
|
180
181
|
|
181
182
|
if (config.JWS_SIGN) {
|
@@ -43,7 +43,10 @@ const { Headers, RestMethods, ReturnCodes } = Enums.Http
|
|
43
43
|
const sendHttpRequest = ({ method, ...restArgs }) => request.sendRequest({
|
44
44
|
...restArgs,
|
45
45
|
method: method.toUpperCase(),
|
46
|
-
hubNameRegex
|
46
|
+
hubNameRegex,
|
47
|
+
axiosRequestOptionsOverride: {
|
48
|
+
timeout: Config.HTTP_REQUEST_TIMEOUT_MS
|
49
|
+
}
|
47
50
|
})
|
48
51
|
|
49
52
|
/**
|
@@ -37,6 +37,9 @@ const { logger } = require('../../lib')
|
|
37
37
|
const { hubNameRegex } = require('../../lib/util').hubNameConfig
|
38
38
|
|
39
39
|
const uriRegex = /(?:^.*)(\/(participants|parties|quotes|transfers)(\/.*)*)$/
|
40
|
+
const axiosRequestOptionsOverride = {
|
41
|
+
timeout: Config.HTTP_REQUEST_TIMEOUT_MS
|
42
|
+
}
|
40
43
|
|
41
44
|
/**
|
42
45
|
* @module src/models/participantEndpoint/facade
|
@@ -115,7 +118,8 @@ exports.sendRequest = async (headers, requestedParticipant, endpointType, method
|
|
115
118
|
span,
|
116
119
|
protocolVersions,
|
117
120
|
hubNameRegex,
|
118
|
-
apiType: Config.API_TYPE
|
121
|
+
apiType: Config.API_TYPE,
|
122
|
+
axiosRequestOptionsOverride
|
119
123
|
}
|
120
124
|
logger.debug('participant - sendRequest params:', { params })
|
121
125
|
params.jwsSigner = defineJwsSigner(Config, headers, requestedEndpoint)
|
@@ -252,7 +256,8 @@ exports.sendErrorToParticipant = async (participantName, endpointType, errorInfo
|
|
252
256
|
hubNameRegex,
|
253
257
|
span,
|
254
258
|
protocolVersions,
|
255
|
-
apiType: Config.API_TYPE
|
259
|
+
apiType: Config.API_TYPE,
|
260
|
+
axiosRequestOptionsOverride
|
256
261
|
}
|
257
262
|
logger.debug('participant - sendErrorToParticipant params: ', { params })
|
258
263
|
params.jwsSigner = defineJwsSigner(Config, clonedHeaders, requesterErrorEndpoint)
|
@@ -240,7 +240,9 @@ describe('Parties Tests', () => {
|
|
240
240
|
it('handles error when sourceDfsp cannot be found (no fspiop-proxy in headers)', async () => {
|
241
241
|
expect.hasAssertions()
|
242
242
|
// Arrange
|
243
|
-
participant.validateParticipant = sandbox.stub()
|
243
|
+
participant.validateParticipant = sandbox.stub()
|
244
|
+
.resolves(null)
|
245
|
+
.onSecondCall().resolves({})
|
244
246
|
participant.sendErrorToParticipant = sandbox.stub().resolves(null)
|
245
247
|
const loggerStub = sandbox.stub(logger.mlLogger, 'error')
|
246
248
|
|
@@ -258,7 +260,11 @@ describe('Parties Tests', () => {
|
|
258
260
|
|
259
261
|
it('should send error callback, if proxy-header is present, but no proxy in the scheme', async () => {
|
260
262
|
Config.PROXY_CACHE_CONFIG.enabled = true
|
261
|
-
participant.validateParticipant = sandbox.stub()
|
263
|
+
participant.validateParticipant = sandbox.stub()
|
264
|
+
.resolves(null) // source
|
265
|
+
.onSecondCall().resolves(null) // proxy
|
266
|
+
.onThirdCall().resolves({}) // destination of callback
|
267
|
+
// !! Need to review the whole test: coz it's not clear where to send callback if no proxy and external source
|
262
268
|
participant.sendErrorToParticipant = sandbox.stub().resolves()
|
263
269
|
participant.sendRequest = sandbox.stub().resolves()
|
264
270
|
const proxy = `proxy-${Date.now()}`
|
@@ -483,6 +489,7 @@ describe('Parties Tests', () => {
|
|
483
489
|
participant.validateParticipant = sandbox.stub()
|
484
490
|
.onFirstCall().resolves(null) // source
|
485
491
|
.onSecondCall().resolves(null) // oracle dfsp
|
492
|
+
.onThirdCall().resolves({})
|
486
493
|
participant.sendRequest = sandbox.stub().resolves()
|
487
494
|
participant.sendErrorToParticipant = sandbox.stub().resolves()
|
488
495
|
|
@@ -631,6 +638,9 @@ describe('Parties Tests', () => {
|
|
631
638
|
// Arrange
|
632
639
|
const loggerStub = sandbox.stub(logger.constructor.prototype, 'error')
|
633
640
|
participant.sendErrorToParticipant = sandbox.stub().resolves()
|
641
|
+
participant.validateParticipant = sandbox.stub()
|
642
|
+
.resolves(null)
|
643
|
+
.onSecondCall().resolves({})
|
634
644
|
|
635
645
|
const payload = JSON.stringify({ testPayload: true })
|
636
646
|
const dataUri = encodePayload(payload, 'application/json')
|
@@ -755,7 +765,7 @@ describe('Parties Tests', () => {
|
|
755
765
|
await partiesDomain.putPartiesByTypeAndID(Helper.putByTypeIdRequest.headers, Helper.putByTypeIdRequest.params, 'put', payload, dataUri, null, proxyCache)
|
756
766
|
|
757
767
|
// Assert
|
758
|
-
expect(participant.validateParticipant.callCount).toBe(
|
768
|
+
expect(participant.validateParticipant.callCount).toBe(3)
|
759
769
|
expect(participant.sendErrorToParticipant.callCount).toBe(1)
|
760
770
|
participant.validateParticipant.reset()
|
761
771
|
participant.sendErrorToParticipant.reset()
|
@@ -784,7 +794,7 @@ describe('Parties Tests', () => {
|
|
784
794
|
await partiesDomain.putPartiesByTypeAndID(Helper.putByTypeIdRequest.headers, params, 'put', payload, dataUri, null, proxyCache)
|
785
795
|
|
786
796
|
// Assert
|
787
|
-
expect(participant.validateParticipant.callCount).toBe(
|
797
|
+
expect(participant.validateParticipant.callCount).toBe(3)
|
788
798
|
expect(participant.sendErrorToParticipant.callCount).toBe(1)
|
789
799
|
const firstCallArgs = participant.sendErrorToParticipant.getCall(0).args
|
790
800
|
expect(firstCallArgs[1]).toBe(expectedErrorCallbackEnpointType)
|
@@ -850,7 +860,9 @@ describe('Parties Tests', () => {
|
|
850
860
|
it('sends error to the participant when there is no destination participant', async () => {
|
851
861
|
expect.hasAssertions()
|
852
862
|
// Arrange
|
853
|
-
participant.validateParticipant = sandbox.stub()
|
863
|
+
participant.validateParticipant = sandbox.stub()
|
864
|
+
.resolves(null)
|
865
|
+
.onSecondCall().resolves({})
|
854
866
|
participant.sendErrorToParticipant = sandbox.stub().throws(new Error('Unknown error'))
|
855
867
|
const payload = JSON.stringify({ errorPayload: true })
|
856
868
|
const dataUri = encodePayload(payload, 'application/json')
|
@@ -884,14 +896,16 @@ describe('Parties Tests', () => {
|
|
884
896
|
// Assert
|
885
897
|
expect(participant.sendErrorToParticipant.callCount).toBe(1)
|
886
898
|
const sendErrorCallArgs = participant.sendErrorToParticipant.getCall(0).args
|
887
|
-
expect(sendErrorCallArgs[0]).toStrictEqual(headers['fspiop-
|
899
|
+
expect(sendErrorCallArgs[0]).toStrictEqual(headers['fspiop-source'])
|
888
900
|
})
|
889
901
|
|
890
902
|
it('handles error when `validateParticipant()` fails', async () => {
|
891
903
|
expect.hasAssertions()
|
892
904
|
// Arrange)
|
893
905
|
const loggerStub = sandbox.stub(logger.constructor.prototype, 'error')
|
894
|
-
participant.validateParticipant = sandbox.stub()
|
906
|
+
participant.validateParticipant = sandbox.stub()
|
907
|
+
.onFirstCall().throws(new Error('Validation fails'))
|
908
|
+
.onSecondCall().resolves({})
|
895
909
|
participant.sendErrorToParticipant = sandbox.stub().resolves({})
|
896
910
|
const payload = JSON.stringify({ errorPayload: true })
|
897
911
|
const expectedCallbackEnpointType = Enum.EndPoints.FspEndpointTypes.FSPIOP_CALLBACK_URL_PARTIES_PUT_ERROR
|
@@ -911,7 +925,9 @@ describe('Parties Tests', () => {
|
|
911
925
|
// Arrange
|
912
926
|
|
913
927
|
const loggerStub = sandbox.stub(logger.constructor.prototype, 'error')
|
914
|
-
participant.validateParticipant = sandbox.stub()
|
928
|
+
participant.validateParticipant = sandbox.stub()
|
929
|
+
.throws(new Error('Validation fails'))
|
930
|
+
.onSecondCall().resolves({})
|
915
931
|
participant.sendErrorToParticipant = sandbox.stub().resolves({})
|
916
932
|
const payload = JSON.stringify({ errorPayload: true })
|
917
933
|
const params = { ...Helper.putByTypeIdRequest.params, SubId: 'SubId' }
|
@@ -935,9 +951,10 @@ describe('Parties Tests', () => {
|
|
935
951
|
const proxy = `proxy-${Date.now()}`
|
936
952
|
const headers = fixtures.partiesCallHeadersDto({ destination, proxy })
|
937
953
|
const { params } = Helper.putByTypeIdRequest
|
938
|
-
participant.validateParticipant = sandbox.stub().resolves(
|
954
|
+
participant.validateParticipant = sandbox.stub().resolves(null) // external participant
|
939
955
|
participant.sendRequest = sandbox.stub().resolves()
|
940
956
|
participant.sendErrorToParticipant = sandbox.stub().resolves()
|
957
|
+
proxyCache.lookupProxyByDfspId = sandbox.stub().resolves(proxy)
|
941
958
|
oracleEndpointCached.getOracleEndpointByType = sandbox.stub().resolves([
|
942
959
|
{ value: 'http://oracle.endpoint' }
|
943
960
|
])
|
@@ -950,8 +967,9 @@ describe('Parties Tests', () => {
|
|
950
967
|
expect(participant.sendRequest.callCount).toBe(0)
|
951
968
|
expect(participant.sendErrorToParticipant.callCount).toBe(1)
|
952
969
|
// eslint-disable-next-line no-unused-vars
|
953
|
-
const [sentTo, _, data] = participant.sendErrorToParticipant.lastCall.args
|
954
|
-
expect(sentTo).toBe(
|
970
|
+
const [sentTo, _, data, cbHeaders] = participant.sendErrorToParticipant.lastCall.args
|
971
|
+
expect(sentTo).toBe(proxy)
|
972
|
+
expect(cbHeaders[Headers.FSPIOP.DESTINATION]).toBe(destination)
|
955
973
|
expect(data.errorInformation.errorCode).toBe('2003')
|
956
974
|
})
|
957
975
|
})
|
@@ -38,6 +38,7 @@ describe('BasePartiesService Tests -->', () => {
|
|
38
38
|
})
|
39
39
|
|
40
40
|
test('should send error party callback in ISO20022 format', async () => {
|
41
|
+
participantMock.validateParticipant = jest.fn().mockResolvedValue({})
|
41
42
|
const deps = {
|
42
43
|
...createMockDeps(),
|
43
44
|
config: { ...config, API_TYPE: API_TYPES.iso20022 }
|
@@ -30,7 +30,7 @@ const { createMockDeps, oracleMock, participantMock } = require('./deps')
|
|
30
30
|
const { PutPartiesErrorService } = require('#src/domain/parties/services/index')
|
31
31
|
const fixtures = require('#test/fixtures/index')
|
32
32
|
|
33
|
-
const { RestMethods } = PutPartiesErrorService.enums()
|
33
|
+
const { RestMethods, Headers } = PutPartiesErrorService.enums()
|
34
34
|
|
35
35
|
describe('PutPartiesErrorService Tests -->', () => {
|
36
36
|
beforeEach(() => {
|
@@ -38,33 +38,34 @@ describe('PutPartiesErrorService Tests -->', () => {
|
|
38
38
|
})
|
39
39
|
|
40
40
|
test('should cleanup oracle and forward SERVICE_CURRENTLY_UNAVAILABLE error for party from external dfsp', async () => {
|
41
|
-
participantMock.validateParticipant = jest.fn().
|
42
|
-
const destination = '
|
41
|
+
participantMock.validateParticipant = jest.fn().mockRejectedValue(new Error('No participant found')) // external participant
|
42
|
+
const destination = 'externalDfsp'
|
43
|
+
const proxyDest = 'proxyDest'
|
44
|
+
const deps = createMockDeps()
|
45
|
+
deps.proxyCache.lookupProxyByDfspId = jest.fn().mockResolvedValue(proxyDest)
|
46
|
+
|
43
47
|
const headers = fixtures.partiesCallHeadersDto({ destination, proxy: 'proxyA' })
|
44
48
|
const params = fixtures.partiesParamsDto()
|
45
49
|
const dataUri = fixtures.dataUriDto()
|
46
|
-
const service = new PutPartiesErrorService(
|
50
|
+
const service = new PutPartiesErrorService(deps, { headers, params, dataUri })
|
47
51
|
|
48
52
|
await service.handleRequest()
|
49
53
|
expect(oracleMock.oracleRequest).toHaveBeenCalledTimes(1)
|
50
54
|
expect(oracleMock.oracleRequest.mock.lastCall[1]).toBe(RestMethods.DELETE)
|
51
55
|
expect(participantMock.sendErrorToParticipant).toHaveBeenCalledTimes(1)
|
52
56
|
// eslint-disable-next-line no-unused-vars
|
53
|
-
const [sentTo, _, payload] = participantMock.sendErrorToParticipant.mock.lastCall
|
54
|
-
expect(sentTo).toBe(
|
57
|
+
const [sentTo, _, payload, cbHeaders] = participantMock.sendErrorToParticipant.mock.lastCall
|
58
|
+
expect(sentTo).toBe(proxyDest)
|
59
|
+
expect(cbHeaders[Headers.FSPIOP.DESTINATION]).toBe(destination)
|
55
60
|
expect(payload.errorInformation.errorCode).toBe('2003')
|
56
61
|
})
|
57
62
|
|
58
|
-
test('should NOT cleanup oracle if destination is
|
59
|
-
const destination = '
|
60
|
-
const proxyDest = 'proxyDest'
|
63
|
+
test('should NOT cleanup oracle if destination is local', async () => {
|
64
|
+
const destination = 'localDfsp'
|
61
65
|
const deps = createMockDeps()
|
62
|
-
deps.participant.validateParticipant = jest.fn().mockResolvedValue(
|
63
|
-
deps.proxyCache.lookupProxyByDfspId = jest.fn().mockResolvedValue(proxyDest)
|
66
|
+
deps.participant.validateParticipant = jest.fn().mockResolvedValue({})
|
64
67
|
|
65
|
-
const headers = fixtures.partiesCallHeadersDto({
|
66
|
-
destination, proxy: 'proxyA'
|
67
|
-
})
|
68
|
+
const headers = fixtures.partiesCallHeadersDto({ destination })
|
68
69
|
const params = fixtures.partiesParamsDto()
|
69
70
|
const dataUri = fixtures.dataUriDto()
|
70
71
|
const service = new PutPartiesErrorService(deps, { headers, params, dataUri })
|
@@ -72,6 +73,6 @@ describe('PutPartiesErrorService Tests -->', () => {
|
|
72
73
|
await service.handleRequest()
|
73
74
|
expect(oracleMock.oracleRequest).not.toHaveBeenCalled()
|
74
75
|
expect(participantMock.sendErrorToParticipant).toHaveBeenCalledTimes(1)
|
75
|
-
expect(participantMock.sendErrorToParticipant.mock.lastCall[0]).toBe(
|
76
|
+
expect(participantMock.sendErrorToParticipant.mock.lastCall[0]).toBe(destination)
|
76
77
|
})
|
77
78
|
})
|
@@ -0,0 +1,117 @@
|
|
1
|
+
/*****
|
2
|
+
License
|
3
|
+
--------------
|
4
|
+
Copyright © 2020-2025 Mojaloop Foundation
|
5
|
+
The Mojaloop files are made available by the Mojaloop Foundation under the Apache License, Version 2.0 (the "License") and you may not use these files except in compliance with the License. You may obtain a copy of the License at
|
6
|
+
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
|
9
|
+
Unless required by applicable law or agreed to in writing, the Mojaloop files are distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
10
|
+
|
11
|
+
Contributors
|
12
|
+
--------------
|
13
|
+
This is the official list of the Mojaloop project contributors for this file.
|
14
|
+
Names of the original copyright holders (individuals or organizations)
|
15
|
+
should be listed with a '*' in the first column. People who have
|
16
|
+
contributed from an organization can be listed under the organization
|
17
|
+
that actually holds the copyright for their contributions (see the
|
18
|
+
Mojaloop Foundation for an example). Those individuals should have
|
19
|
+
their names indented and be marked with a '-'. Email address can be added
|
20
|
+
optionally within square brackets <email>.
|
21
|
+
|
22
|
+
* Mojaloop Foundation
|
23
|
+
* Eugen Klymniuk <eugen.klymniuk@infitx.com>
|
24
|
+
|
25
|
+
--------------
|
26
|
+
******/
|
27
|
+
|
28
|
+
const { createMockDeps, participantMock } = require('./deps')
|
29
|
+
// ↑ should be first require to mock external deps ↑
|
30
|
+
const { PutPartiesService } = require('#src/domain/parties/services/index')
|
31
|
+
const config = require('#src/lib/config')
|
32
|
+
const fixtures = require('#test/fixtures/index')
|
33
|
+
|
34
|
+
const { Headers } = PutPartiesService.enums()
|
35
|
+
|
36
|
+
describe('PutPartiesService Tests -->', () => {
|
37
|
+
beforeEach(() => {
|
38
|
+
jest.clearAllMocks()
|
39
|
+
})
|
40
|
+
|
41
|
+
test('should send error callback to source in case of error on forwarding request to destination (buffer scheme)', async () => {
|
42
|
+
const errMessage = 'Test Http Error'
|
43
|
+
participantMock.sendRequest = jest.fn().mockRejectedValue(new Error(errMessage))
|
44
|
+
participantMock.validateParticipant = jest.fn().mockResolvedValue({})
|
45
|
+
const source = 'mwk-dfsp'
|
46
|
+
const destination = 'zmk-dfsp'
|
47
|
+
const headers = fixtures.partiesCallHeadersDto({ source, destination, proxy: '' })
|
48
|
+
const params = fixtures.partiesParamsDto()
|
49
|
+
const dataUri = fixtures.dataUriDto()
|
50
|
+
const service = new PutPartiesService(createMockDeps(), { headers, params, dataUri })
|
51
|
+
|
52
|
+
await service.handleRequest()
|
53
|
+
.catch(err => service.handleError(err))
|
54
|
+
|
55
|
+
expect(participantMock.sendErrorToParticipant).toHaveBeenCalledTimes(1)
|
56
|
+
// eslint-disable-next-line no-unused-vars
|
57
|
+
const [sentTo, _, payload, cbHeaders] = participantMock.sendErrorToParticipant.mock.lastCall
|
58
|
+
expect(sentTo).toBe(source)
|
59
|
+
expect(payload.errorInformation.errorCode).toBe('2001')
|
60
|
+
expect(payload.errorInformation.errorDescription.endsWith(errMessage)).toBe(true)
|
61
|
+
expect(cbHeaders[Headers.FSPIOP.SOURCE]).toBe(config.HUB_NAME)
|
62
|
+
expect(cbHeaders[Headers.FSPIOP.DESTINATION]).toBe(source)
|
63
|
+
})
|
64
|
+
|
65
|
+
test('should send error callback to source proxy in case of error on forwarding request to destination proxy (region scheme)', async () => {
|
66
|
+
const errMessage = 'Test Http Error'
|
67
|
+
participantMock.sendRequest = jest.fn().mockRejectedValue(new Error(errMessage))
|
68
|
+
participantMock.validateParticipant = jest.fn().mockResolvedValue(null)
|
69
|
+
|
70
|
+
const source = 'zmk-dfsp'
|
71
|
+
const proxy = 'proxy-zmk'
|
72
|
+
const destination = 'mwk-dfsp'
|
73
|
+
const proxyDest = 'proxy-mwk'
|
74
|
+
|
75
|
+
const deps = createMockDeps()
|
76
|
+
deps.proxyCache.lookupProxyByDfspId = jest.fn(async (dfsp) => {
|
77
|
+
if (dfsp === source) return proxy
|
78
|
+
if (dfsp === destination) return proxyDest
|
79
|
+
return null
|
80
|
+
})
|
81
|
+
|
82
|
+
const headers = fixtures.partiesCallHeadersDto({ source, destination, proxy })
|
83
|
+
const params = fixtures.partiesParamsDto()
|
84
|
+
const dataUri = fixtures.dataUriDto()
|
85
|
+
const service = new PutPartiesService(deps, { headers, params, dataUri })
|
86
|
+
|
87
|
+
await service.handleRequest()
|
88
|
+
.catch(err => service.handleError(err))
|
89
|
+
|
90
|
+
expect(participantMock.sendErrorToParticipant).toHaveBeenCalledTimes(1)
|
91
|
+
// eslint-disable-next-line no-unused-vars
|
92
|
+
const [sentTo, _, payload, cbHeaders] = participantMock.sendErrorToParticipant.mock.lastCall
|
93
|
+
expect(sentTo).toBe(proxy)
|
94
|
+
expect(payload.errorInformation.errorCode).toBe('2001')
|
95
|
+
expect(payload.errorInformation.errorDescription.endsWith(errMessage)).toBe(true)
|
96
|
+
expect(cbHeaders[Headers.FSPIOP.SOURCE]).toBe(config.HUB_NAME)
|
97
|
+
expect(cbHeaders[Headers.FSPIOP.DESTINATION]).toBe(source)
|
98
|
+
})
|
99
|
+
|
100
|
+
test('should just log error in case handleError failed', async () => {
|
101
|
+
const headers = fixtures.partiesCallHeadersDto()
|
102
|
+
const params = fixtures.partiesParamsDto()
|
103
|
+
const dataUri = fixtures.dataUriDto()
|
104
|
+
const service = new PutPartiesService(createMockDeps(), { headers, params, dataUri })
|
105
|
+
|
106
|
+
service.handleRequest = jest.fn().mockRejectedValue(new Error('handleRequest failed'))
|
107
|
+
service.identifyDestinationForCallback = jest.fn()
|
108
|
+
service.sendErrorCallback = jest.fn().mockRejectedValue(new Error('sendErrorCallback failed'))
|
109
|
+
const logSpy = jest.spyOn(service.log.mlLogger, 'error')
|
110
|
+
|
111
|
+
const result = await service.handleRequest()
|
112
|
+
.catch(err => service.handleError(err))
|
113
|
+
|
114
|
+
expect(result).toBeUndefined()
|
115
|
+
expect(logSpy.mock.lastCall[0]).toBe('failed to handleError. No further processing! ')
|
116
|
+
})
|
117
|
+
})
|
@@ -188,6 +188,26 @@ describe('participantEndpoint Facade', () => {
|
|
188
188
|
|
189
189
|
expect(mockSendRequest.mock.lastCall[0].jwsSigner).toBeTruthy()
|
190
190
|
})
|
191
|
+
|
192
|
+
it('should add default timeout to sendRequest', async () => {
|
193
|
+
const mockedConfig = {
|
194
|
+
JWS_SIGN: false,
|
195
|
+
FSPIOP_SOURCE_TO_SIGN: mockHubName,
|
196
|
+
PROTOCOL_VERSIONS: fixtures.protocolVersionsDto(),
|
197
|
+
HTTP_REQUEST_TIMEOUT_MS: 1000
|
198
|
+
}
|
199
|
+
jest.mock('../../../../src/lib/config', () => (mockedConfig))
|
200
|
+
mockGetEndpoint.mockImplementation(() => 'https://example.com/12345')
|
201
|
+
mockSendRequest.mockImplementation(async () => true)
|
202
|
+
const ParticipantFacade = require(`${src}/models/participantEndpoint/facade`)
|
203
|
+
|
204
|
+
const headers = {}
|
205
|
+
const requestedParticipant = {}
|
206
|
+
const endpointType = 'URL'
|
207
|
+
|
208
|
+
await ParticipantFacade.sendRequest(headers, requestedParticipant, endpointType)
|
209
|
+
expect(mockSendRequest.mock.calls[0][0].axiosRequestOptionsOverride.timeout).toBe(mockedConfig.HTTP_REQUEST_TIMEOUT_MS)
|
210
|
+
})
|
191
211
|
})
|
192
212
|
|
193
213
|
describe('validateParticipant', () => {
|