Skip to content

Commit

Permalink
fix: invalid tokens were not being rejected
Browse files Browse the repository at this point in the history
  • Loading branch information
menduz committed Apr 26, 2021
1 parent 4d21ff4 commit 71e410b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export async function createMetricsComponent<K extends string, V extends object
if (!header) return { status: 401 }
const [_, value] = header.split(" ")
if (value != bearerToken) {
if (!header) return { status: 401 }
return { status: 401 }
}
}

Expand Down
6 changes: 6 additions & 0 deletions test/authentication.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,10 @@ describeTestE2E("Authenticated tests", ({ getComponents, run }) => {
const res = await fetch.fetch("/a/metrics", { headers: { authorization: "Bearer asd" } })
expect(res.status).toEqual(200)
})

it("responds the /a/metrics endpoint with 401 with invalid token", async () => {
const { fetch } = getComponents()
const res = await fetch.fetch("/a/metrics", { headers: { authorization: "Bearer xxxxxxxxx" } })
expect(res.status).toEqual(401)
})
})

0 comments on commit 71e410b

Please sign in to comment.