Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
darianm authored and darianm committed Nov 4, 2024
1 parent fa0d4b1 commit 150a26e
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions packages/backend/src/open_payments/auth/middleware.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,7 @@ describe('Auth Middleware', (): void => {
ctx.request.headers.authorization = ''

await expect(middleware(ctx, next)).resolves.toBeUndefined()
expect(ctx.response.get('WWW-Authenticate')).toBe(
`GNAP as_uri=${Config.authServerGrantUrl}`
)
expect(ctx.response.get('WWW-Authenticate')).toBe('')
expect(next).toHaveBeenCalled()
})

Expand Down Expand Up @@ -555,12 +553,25 @@ describe('authenticatedStatusMiddleware', (): void => {
await appContainer.shutdown()
})

test('sets ctx.authenticated to false if http signature is invalid', async (): Promise<void> => {
test('sets ctx.authenticated to false if http signature is invalid and missing auth header', async (): Promise<void> => {
const ctx = createContext<HttpSigWithAuthenticatedStatusContext>({
headers: { 'signature-input': '' }
})

expect(authenticatedStatusMiddleware(ctx, next)).resolves.toBeUndefined()
expect(next).toHaveBeenCalled()
expect(ctx.authenticated).toBe(false)
})

test('sets ctx.authenticated to false if http signature is invalid and existing auth header', async (): Promise<void> => {
const ctx = createContext<HttpSigWithAuthenticatedStatusContext>({
headers: { 'signature-input': '', authorization: 'GNAP token' }
})

expect(authenticatedStatusMiddleware(ctx, next)).rejects.toMatchObject({
status: 401,
message: 'Signature validation error: missing keyId in signature input'
})
expect(next).not.toHaveBeenCalled()
expect(ctx.authenticated).toBe(false)
})
Expand Down

0 comments on commit 150a26e

Please sign in to comment.