Skip to content

Commit

Permalink
test(backend): quote create access control
Browse files Browse the repository at this point in the history
  • Loading branch information
BlairCurrey committed Oct 31, 2024
1 parent 08d9668 commit b404d12
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
35 changes: 35 additions & 0 deletions packages/backend/src/graphql/resolvers/quote.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,41 @@ describe('Quote Resolvers', (): void => {
}
expect(createSpy).toHaveBeenCalledWith({ ...input, method: 'ilp' })
})

test('cannot access', async (): Promise<void> => {
const spy = jest
.spyOn(walletAddressService, 'canAccess')
.mockImplementation(async () => false)

expect.assertions(3)
try {
await appContainer.apolloClient
.query({
query: gql`
mutation CreateQuote($input: CreateQuoteInput!) {
createQuote(input: $input) {
quote {
id
}
}
}
`,
variables: { input }
})
.then((query): QuoteResponse => query.data?.createQuote)
} catch (error) {
expect(error).toBeInstanceOf(ApolloError)
expect((error as ApolloError).graphQLErrors).toContainEqual(
expect.objectContaining({
message: 'Unknown wallet address id input',
extensions: expect.objectContaining({
code: GraphQLErrorCode.BadUserInput
})
})
)
}
expect(spy).toHaveBeenCalled()
})
})

describe('Wallet address quotes', (): void => {
Expand Down
4 changes: 1 addition & 3 deletions packages/backend/src/graphql/resolvers/quote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,8 @@ export const getQuote: QueryResolvers<ApolloContext>['quote'] = async (

export const createQuote: MutationResolvers<ApolloContext>['createQuote'] =
async (parent, args, ctx): Promise<ResolversTypes['QuoteResponse']> => {
// ACCESS CONTROL CASE: Creates. If operator, OK. Else, get associated wallet address
// tenantId and compare to requestor's tenantId before creating.
const walletAddressService = await ctx.container.use('walletAddressService')
const canAccess = walletAddressService.canAccess(
const canAccess = await walletAddressService.canAccess(
ctx.isOperator,
ctx.tenantId,
args.input.walletAddressId
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/graphql/resolvers/wallet_address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export const updateWalletAddress: MutationResolvers<ApolloContext>['updateWallet
}

// TODO: access control? operator only, anyone, or tenanted?
// Perhaps operator only? if tenanted will maybe need to fn
// Perhaps operator only? if tenanted will maybe need fn
// like existing processNextWalletAddresses that filters by tenant
export const triggerWalletAddressEvents: MutationResolvers<ApolloContext>['triggerWalletAddressEvents'] =
async (
Expand Down

0 comments on commit b404d12

Please sign in to comment.