Skip to content

Commit

Permalink
Merge branch 'feat/og-gen-mw-vite-plugin' of github.com:dac09/redwood…
Browse files Browse the repository at this point in the history
… 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
dac09 committed Apr 12, 2024
2 parents b1d32fe + fd99c88 commit 9a39cc1
Show file tree
Hide file tree
Showing 6 changed files with 419 additions and 316 deletions.
2 changes: 2 additions & 0 deletions .changesets/10442.md
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.
15 changes: 11 additions & 4 deletions docs/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8250,6 +8250,13 @@ __metadata:
languageName: node
linkType: hard

"minipass@npm:^5.0.0":
version: 5.0.0
resolution: "minipass@npm:5.0.0"
checksum: 10c0/a91d8043f691796a8ac88df039da19933ef0f633e3d7f0d35dcd5373af49131cf2399bfc355f41515dc495e3990369c3858cd319e5c2722b4753c90bf3152462
languageName: node
linkType: hard

"minizlib@npm:^2.1.1, minizlib@npm:^2.1.2":
version: 2.1.2
resolution: "minizlib@npm:2.1.2"
Expand Down Expand Up @@ -10808,16 +10815,16 @@ __metadata:
linkType: hard

"tar@npm:^6.0.2, tar@npm:^6.1.2":
version: 6.1.11
resolution: "tar@npm:6.1.11"
version: 6.2.1
resolution: "tar@npm:6.2.1"
dependencies:
chownr: "npm:^2.0.0"
fs-minipass: "npm:^2.0.0"
minipass: "npm:^3.0.0"
minipass: "npm:^5.0.0"
minizlib: "npm:^2.1.1"
mkdirp: "npm:^1.0.3"
yallist: "npm:^4.0.0"
checksum: 10c0/5a016f5330f43815420797b87ade578e2ea60affd47439c988a3fc8f7bb6b36450d627c31ba6a839346fae248b4c8c12bb06bb0716211f37476838c7eff91f05
checksum: 10c0/a5eca3eb50bc11552d453488344e6507156b9193efd7635e98e867fab275d527af53d8866e2370cd09dfe74378a18111622ace35af6a608e5223a7d27fe99537
languageName: node
linkType: hard

Expand Down
70 changes: 70 additions & 0 deletions packages/api/src/auth/__tests__/parseAuthorizationHeader.test.ts
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',
})
})
})
2 changes: 1 addition & 1 deletion packages/api/src/auth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export interface AuthorizationHeader {
export const parseAuthorizationHeader = (
event: APIGatewayProxyEvent | Request,
): AuthorizationHeader => {
const parts = getEventHeader(event, 'authorization')?.split(' ')
const parts = getEventHeader(event, 'Authorization')?.split(' ')
if (parts?.length !== 2) {
throw new Error('The `Authorization` header is not valid.')
}
Expand Down
4 changes: 2 additions & 2 deletions packages/auth-providers/firebase/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@
"@babel/cli": "7.24.1",
"@babel/core": "^7.22.20",
"@types/react": "^18.2.55",
"firebase": "10.9.0",
"firebase": "10.11.0",
"jest": "29.7.0",
"jest-environment-jsdom": "29.7.0",
"react": "18.3.0-canary-a870b2d54-20240314",
"typescript": "5.4.3"
},
"peerDependencies": {
"firebase": "10.9.0"
"firebase": "10.11.0"
},
"gitHead": "3905ed045508b861b495f8d5630d76c7a157d8f1"
}
Loading

0 comments on commit 9a39cc1

Please sign in to comment.