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(mojaloop/#3817): restore proxied source validation #349

Merged
merged 2 commits into from
Aug 21, 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
10 changes: 8 additions & 2 deletions src/model/quotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,11 @@ class QuotesModel {

// In fspiop api spec 2.0, to support FX, `supportedCurrencies` can be optionally passed in via the payer property.
// If `supportedCurrencies` is present, then payer FSP must have position accounts for all those currencies.
if (quoteRequest.payer.supportedCurrencies && quoteRequest.payer.supportedCurrencies.length > 0) {
if (quoteRequest.payer.supportedCurrencies &&
quoteRequest.payer.supportedCurrencies.length > 0 &&
// if the payer dfsp has a proxy cache entry, we do not validate the dfsp here
!(await this.proxyClient?.lookupProxyByDfspId(fspiopSource))
) {
await Promise.all(quoteRequest.payer.supportedCurrencies.map(currency =>
this.db.getParticipant(fspiopSource, LOCAL_ENUM.PAYER_DFSP, currency, ENUM.Accounts.LedgerAccountType.POSITION)
))
Expand All @@ -192,7 +196,9 @@ class QuotesModel {
// Lets make sure the optional fspId exists in the payer's partyIdInfo before we validate it
if (
quoteRequest.payer?.partyIdInfo?.fspId &&
quoteRequest.payer.partyIdInfo.fspId !== fspiopSource
quoteRequest.payer.partyIdInfo.fspId !== fspiopSource &&
// if the payer dfsp has a proxy cache entry, we do not validate the dfsp here
!(await this.proxyClient?.lookupProxyByDfspId(quoteRequest.payer.partyIdInfo.fspId))
) {
await this.db.getParticipant(quoteRequest.payer.partyIdInfo.fspId, LOCAL_ENUM.PAYER_DFSP, quoteRequest.amount.currency, ENUM.Accounts.LedgerAccountType.POSITION)
}
Expand Down
4 changes: 2 additions & 2 deletions test/integration/putCallback.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ describe('PUT callback Tests --> ', () => {
expect(protectedHeader).toBeTruthy()
})

test('should pass validation for PUT /quotes/{ID} request if request transferAmount/payeeReceiveAmount currency is registered (position account exists) for the payee pariticpant', async () => {
test('should pass validation for PUT /quotes/{ID} request if request transferAmount/payeeReceiveAmount currency is registered (position account exists) for the payee participant', async () => {
// create test quote to prevent db (row reference) error on PUT request
const quoteCreated = await createQuote()
await wait(WAIT_TIMEOUT)
Expand Down Expand Up @@ -194,7 +194,7 @@ describe('PUT callback Tests --> ', () => {
}
})

test('should fail validation for PUT /quotes/{ID} request if request transferAmount/payeeReceiveAmount currency is not registered (position account does not exist) for the payee pariticpant', async () => {
test('should fail validation for PUT /quotes/{ID} request if request transferAmount/payeeReceiveAmount currency is not registered (position account does not exist) for the payee participant', async () => {
// test the same scenario with only transferAmount set
// create test quote to prevent db (row reference) error on PUT request
const quoteCreated = await createQuote()
Expand Down
20 changes: 20 additions & 0 deletions test/unit/model/quotes.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,26 @@ describe('QuotesModel', () => {
expect(quotesModel.db.getParticipant).toHaveBeenCalledWith(fspiopSource, 'PAYER_DFSP', 'ZMW', Enum.Accounts.LedgerAccountType.POSITION)
expect(quotesModel.db.getParticipant).toHaveBeenCalledWith(fspiopSource, 'PAYER_DFSP', 'TZS', Enum.Accounts.LedgerAccountType.POSITION)
})

it('should skip validating source if source is a proxied participant', async () => {
const fspiopSource = 'dfsp1'
const fspiopDestination = 'dfsp2'
const request = mockData.quoteRequest
request.payer.supportedCurrencies = ['ZMW', 'TZS']
quotesModel.proxyClient = {
isConnected: false,
connect: jest.fn().mockResolvedValue(true),
lookupProxyByDfspId: jest.fn().mockImplementation(fspid => {
return fspid === fspiopSource ? 'proxyId' : undefined
})
}

await expect(quotesModel.validateQuoteRequest(fspiopSource, fspiopDestination, request)).resolves.toBeUndefined()

quotesModel.db.getParticipant.mock.calls.forEach(call => {
expect(call[0]).not.toBe(fspiopSource)
})
})
})
describe('validateQuoteUpdate', () => {
beforeEach(() => {
Expand Down