Skip to content

Commit

Permalink
fix: restore proxied quotes validation
Browse files Browse the repository at this point in the history
  • Loading branch information
oderayi committed Aug 21, 2024
1 parent a2cae31 commit 225b9d4
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
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
21 changes: 21 additions & 0 deletions test/unit/model/quotes.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,27 @@ 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

0 comments on commit 225b9d4

Please sign in to comment.