Skip to content
Myr

fix(basic-auth): handle passing invalid value to `atob()` (#1122)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* fix(basic-auth): handle passing invalid value to `atob()` * chore: denoify

authored by Yusuke Wada · committed by GitHub · parent 1c44c6e · Browse files · 3 files+21 added−5 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+21 added−5 removed

  • tests:+11 added−3 removed
  • other:+10 added−2 removed

3 files+21 added−5 removed

modified:deno_dist/middleware/basic-auth/index.ts+5 added-1 removed
modified:runtime_tests/deno/middleware.test.tsx+11 added-3 removed
8 unmodified lines
910Deno.test('Basic Auth Middleware', async () => {11 const app = new Hono()1213 const username = 'hono-user-a'14 const password = 'hono-password-a'13 const username = 'hono'14 const password = 'acoolproject'1516 app.use(17 '/auth/*',18 basicAuth({
7 unmodified lines
26 const res = await app.request('http://localhost/auth/a')27 assertEquals(res.status, 401)28 assertEquals(await res.text(), 'Unauthorized')2930 const credential = 'aG9uby11c2VyLWE6aG9uby1wYXNzd29yZC1h'30 const credential = 'aG9ubzphY29vbHByb2plY3Q='3132 const req = new Request('http://localhost/auth/a')33 req.headers.set('Authorization', `Basic ${credential}`)34 const resOK = await app.request(req)35 assertEquals(resOK.status, 200)36 assertEquals(await resOK.text(), 'auth')3738 const invalidCredential = 'G9ubzphY29vbHByb2plY3Q='3940 const req2 = new Request('http://localhost/auth/a')41 req2.headers.set('Authorization', `Basic ${invalidCredential}`)42 const resNG = await app.request(req2)43 assertEquals(resNG.status, 401)44 assertEquals(await resNG.text(), 'Unauthorized')45})4647Deno.test('JSX middleware', async () => {48 const app = new Hono()
90 unmodified lines
modified:src/middleware/basic-auth/index.ts+5 added-1 removed