Skip to content

Commit

Permalink
feat: await signature verification, test improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
njlie committed Dec 12, 2024
1 parent 4e17260 commit f4ffb75
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/backend/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ export class App {

koa.use(
async (ctx: TenantedHttpSigContext, next: Koa.Next): Promise<void> => {
if (!verifyTenantOrOperatorApiSignature(ctx, this.config)) {
if (!(await verifyTenantOrOperatorApiSignature(ctx, this.config))) {
ctx.throw(401, 'Unauthorized')
}
return next()
Expand Down
3 changes: 3 additions & 0 deletions packages/backend/src/shared/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -441,8 +441,11 @@ describe('utils', (): void => {

ctx.request.body = requestBody

const tenantService = await deps.use('tenantService')
const getSpy = jest.spyOn(tenantService, 'get')
const result = await verifyTenantOrOperatorApiSignature(ctx, config)
expect(result).toEqual(false)
expect(getSpy).toHaveBeenCalled()
expect(ctx.tenant).toBeUndefined()
expect(ctx.isOperator).toEqual(false)
})
Expand Down
3 changes: 1 addition & 2 deletions packages/backend/src/shared/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,7 @@ export async function verifyTenantOrOperatorApiSignature(

if (!tenant) return false

if (!(await canApiSignatureBeProcessed(signature as string, ctx, config)))
return false
if (!(await canApiSignatureBeProcessed(signature, ctx, config))) return false

// First, try validating with the tenant api secret
if (
Expand Down

0 comments on commit f4ffb75

Please sign in to comment.