forked from redwoodjs/redwood
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feat/og-gen-mw-vite-plugin' of github.com:dac09/redwood…
… into feat/og-gen-mw-vite-plugin * 'feat/og-gen-mw-vite-plugin' of github.com:dac09/redwood: chore(deps): bump browserify-sign from 4.2.1 to 4.2.3 (redwoodjs#10446) chore(deps): bump tar from 6.1.11 to 6.2.1 in /docs (redwoodjs#10438) chore(deps): update dependency firebase to v10.11.0 (redwoodjs#10366) fix(auth): Handle when authorization header is lowercased (redwoodjs#10442)
- Loading branch information
Showing
6 changed files
with
419 additions
and
316 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
- fix(auth): Handle when authorization header is lowercased (#10442) by @dac09 | ||
Handles when 'authorization' header is lowercased, and adds some extra tests. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
packages/api/src/auth/__tests__/parseAuthorizationHeader.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import type { APIGatewayProxyEvent } from 'aws-lambda' | ||
import { test, expect, describe } from 'vitest' | ||
|
||
import { parseAuthorizationHeader } from '../index' | ||
|
||
describe('parseAuthorizationHeader', () => { | ||
test('throws error if Authorization header is not valid', () => { | ||
const invalidHeaders = [ | ||
undefined, | ||
null, | ||
'', | ||
'Bearer', | ||
'Bearer ', | ||
'Bearer token with spaces', | ||
'Token', | ||
'Token ', | ||
'Token token with spaces', | ||
] | ||
|
||
invalidHeaders.forEach((header) => { | ||
expect(() => | ||
// @ts-expect-error That's what we're testing | ||
parseAuthorizationHeader({ headers: { Authorization: header } }), | ||
).toThrowError('The `Authorization` header is not valid.') | ||
}) | ||
}) | ||
|
||
test('returns the schema and token from valid Authorization header', () => { | ||
const validHeaders = [ | ||
'Bearer token', | ||
'Bearer 12345', | ||
'Token token', | ||
'Token 12345', | ||
] | ||
|
||
validHeaders.forEach((header) => { | ||
// We only care about the headers in the event | ||
const result = parseAuthorizationHeader({ | ||
headers: { Authorization: header }, | ||
} as unknown as APIGatewayProxyEvent) | ||
|
||
expect(result).toEqual({ | ||
schema: header.split(' ')[0], | ||
token: header.split(' ')[1], | ||
}) | ||
}) | ||
}) | ||
|
||
test('Handles different lower-casing of the authorization header', () => { | ||
const result = parseAuthorizationHeader({ | ||
headers: { authorization: 'Bearer bazinga' }, | ||
} as unknown as APIGatewayProxyEvent) | ||
|
||
expect(result).toEqual({ | ||
schema: 'Bearer', | ||
token: 'bazinga', | ||
}) | ||
}) | ||
|
||
test('Handles different capital-casing of the Authorization header', () => { | ||
const result = parseAuthorizationHeader({ | ||
headers: { Authorization: 'Bearer bazinga' }, | ||
} as unknown as APIGatewayProxyEvent) | ||
|
||
expect(result).toEqual({ | ||
schema: 'Bearer', | ||
token: 'bazinga', | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.