Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(csi-241): fixed unit-tests #483

Merged
merged 7 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 13 additions & 75 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@
"@mojaloop/central-services-health": "15.0.0",
"@mojaloop/central-services-logger": "11.3.1",
"@mojaloop/central-services-metrics": "12.0.8",
"@mojaloop/central-services-shared": "18.4.0",
"@mojaloop/central-services-shared": "^18.5.1",
"@mojaloop/central-services-stream": "11.3.1",
"@mojaloop/database-lib": "11.0.5",
"@mojaloop/database-lib": "11.0.6",
"@mojaloop/event-sdk": "14.1.1",
"@mojaloop/sdk-standard-components": "18.1.0",
"@now-ims/hapi-now-auth": "2.1.0",
Expand Down Expand Up @@ -122,12 +122,15 @@
"yargs-parser": "13.1.2",
"markdown-it": "12.3.2"
},
"yargs": {
"yargs-parser": "^21.1.1"
},
"jsonwebtoken": "9.0.0",
"jsonpointer": "5.0.0"
},
"devDependencies": {
"@types/jest": "29.5.12",
"audit-ci": "^7.0.1",
"audit-ci": "^7.1.0",
"axios": "1.7.2",
"docdash": "2.0.2",
"get-port": "5.1.1",
Expand Down
2 changes: 1 addition & 1 deletion src/handlers/endpointcache.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ module.exports = {
}, EventSdk.AuditEventAction.start)
try {
await ParticipantEndpointCache.stopCache()
await ParticipantEndpointCache.initializeCache(Config.CENTRAL_SHARED_ENDPOINT_CACHE_CONFIG)
await ParticipantEndpointCache.initializeCache(Config.CENTRAL_SHARED_ENDPOINT_CACHE_CONFIG, LibUtil.hubNameConfig)
histTimerEnd({ success: true })
} catch (err) {
histTimerEnd({ success: false })
Expand Down
7 changes: 6 additions & 1 deletion src/lib/util.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const util = require('util')
const Path = require('path')
const Enum = require('@mojaloop/central-services-shared').Enum
const { HeaderValidation } = require('@mojaloop/central-services-shared').Util
const Config = require('../lib/config')

const getSpanTags = ({ headers }, transactionType, transactionAction) => {
Expand Down Expand Up @@ -55,5 +56,9 @@ function getStackOrInspect (err) {
module.exports = {
getSpanTags,
pathForInterface,
getStackOrInspect
getStackOrInspect,
hubNameConfig: {
hubName: Config.HUB_NAME,
hubNameRegex: HeaderValidation.getHubNameRegex(Config.HUB_NAME)
}
}
37 changes: 24 additions & 13 deletions src/models/oracle/facade.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const ErrorHandler = require('@mojaloop/central-services-error-handling')
const Config = require('../../lib/config')
const Metrics = require('@mojaloop/central-services-metrics')
const cachedOracleEndpoint = require('../oracle/oracleEndpointCached')
const hubNameRegex = require('../../lib/util').hubNameConfig.hubNameRegex

/**
* @function oracleRequest
Expand Down Expand Up @@ -79,14 +80,15 @@ exports.oracleRequest = async (headers, method, params = {}, query = {}, payload
let cachedOracleFspResponse
cachedOracleFspResponse = cache && cache.get(cache.createKey(`oracleSendRequest_${url}`))
if (!cachedOracleFspResponse) {
cachedOracleFspResponse = await request.sendRequest(
cachedOracleFspResponse = await request.sendRequest({
url,
headers,
headers[Enums.Http.Headers.FSPIOP.SOURCE],
headers[Enums.Http.Headers.FSPIOP.DESTINATION] || Config.HUB_NAME,
method.toUpperCase(),
payload || undefined
)
source: headers[Enums.Http.Headers.FSPIOP.SOURCE],
destination: headers[Enums.Http.Headers.FSPIOP.DESTINATION] || Config.HUB_NAME,
method: method.toUpperCase(),
payload,
hubNameRegex
})
// Trying to cache the whole response object will fail because it contains circular references
// so we'll just cache the data property of the response.
cachedOracleFspResponse = {
Expand All @@ -106,14 +108,15 @@ exports.oracleRequest = async (headers, method, params = {}, query = {}, payload
return cachedOracleFspResponse
}

return await request.sendRequest(
return await request.sendRequest({
url,
headers,
headers[Enums.Http.Headers.FSPIOP.SOURCE],
headers[Enums.Http.Headers.FSPIOP.DESTINATION] || Config.HUB_NAME,
method.toUpperCase(),
payload || undefined
)
source: headers[Enums.Http.Headers.FSPIOP.SOURCE],
destination: headers[Enums.Http.Headers.FSPIOP.DESTINATION] || Config.HUB_NAME,
method: method.toUpperCase(),
payload,
hubNameRegex
})
} catch (err) {
histTimerEnd({ success: false, hit: false })
Logger.isErrorEnabled && Logger.error(err)
Expand Down Expand Up @@ -318,7 +321,15 @@ exports.oracleBatchRequest = async (headers, method, requestPayload, type, paylo
url = oracleEndpointModel[0].value + Enums.EndPoints.FspEndpointTemplates.ORACLE_PARTICIPANTS_BATCH
}
Logger.isDebugEnabled && Logger.debug(`Oracle endpoints: ${url}`)
return await request.sendRequest(url, headers, headers[Enums.Http.Headers.FSPIOP.SOURCE], headers[Enums.Http.Headers.FSPIOP.DESTINATION] || Config.HUB_NAME, method, payload || undefined)
return await request.sendRequest({
url,
headers,
source: headers[Enums.Http.Headers.FSPIOP.SOURCE],
destination: headers[Enums.Http.Headers.FSPIOP.DESTINATION] || Config.HUB_NAME,
method,
payload,
hubNameRegex
})
} else {
Logger.isErrorEnabled && Logger.error(`Oracle type:${type} not found`)
throw ErrorHandler.Factory.createFSPIOPError(ErrorHandler.Enums.FSPIOPErrorCodes.ADD_PARTY_INFO_ERROR, `Oracle type:${type} not found`)
Expand Down
16 changes: 14 additions & 2 deletions src/models/participantEndpoint/facade.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const ErrorHandler = require('@mojaloop/central-services-error-handling')
const JwsSigner = require('@mojaloop/sdk-standard-components').Jws.signer
const Metrics = require('@mojaloop/central-services-metrics')
const Config = require('../../lib/config')
const hubNameRegex = require('../../lib/util').hubNameConfig.hubNameRegex
const uriRegex = /(?:^.*)(\/(participants|parties|quotes|transfers)(\/.*)*)$/

/**
Expand Down Expand Up @@ -103,8 +104,19 @@ exports.sendRequest = async (headers, requestedParticipant, endpointType, method
}
const jwsSigner = defineJwsSigner(Config, headers, requestedEndpoint)

const resp = await Util.Request.sendRequest(requestedEndpoint, headers, headers[Enums.Http.Headers.FSPIOP.SOURCE],
headers[Enums.Http.Headers.FSPIOP.DESTINATION], method, payload, Enums.Http.ResponseTypes.JSON, span, jwsSigner, protocolVersions)
const resp = await Util.Request.sendRequest({
url: requestedEndpoint,
headers,
source: headers[Enums.Http.Headers.FSPIOP.SOURCE],
destination: headers[Enums.Http.Headers.FSPIOP.DESTINATION],
method,
payload,
responseType: Enums.Http.ResponseTypes.JSON,
span,
jwsSigner,
protocolVersions,
hubNameRegex
})
histTimerEndSendRequestToParticipant({ success: true, endpointType, participantName: requestedParticipant })
return resp
} catch (err) {
Expand Down
4 changes: 2 additions & 2 deletions src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ const initializeApi = async (port = Config.API_PORT) => {
const api = await OpenapiBackend.initialise(OpenAPISpecPath, Handlers.ApiHandlers)
const server = await createServer(port, api, Routes.APIRoutes(api), false)
Logger.isInfoEnabled && Logger.info(`Server running on ${server.info.host}:${server.info.port}`)
await ParticipantEndpointCache.initializeCache(Config.CENTRAL_SHARED_ENDPOINT_CACHE_CONFIG)
await ParticipantCache.initializeCache(Config.CENTRAL_SHARED_PARTICIPANT_CACHE_CONFIG)
await ParticipantEndpointCache.initializeCache(Config.CENTRAL_SHARED_ENDPOINT_CACHE_CONFIG, Util.hubNameConfig)
await ParticipantCache.initializeCache(Config.CENTRAL_SHARED_PARTICIPANT_CACHE_CONFIG, Util.hubNameConfig)
await OracleEndpointCache.initialize()
await Cache.initCache()
return server
Expand Down
Loading