basic-auth.test.ts
This file
Path
src/utils/basic-auth.test.ts
56 lines · 1.6 KiB · TypeScript
Last changed by
Not known.
History of this fileTake it
The walk stopped after 200 commits: lines older than 61bee9f point at it.
refactor(hono-base): remove unneeded processes and variables (#3649)EdamAmexbefore adoption61bee9f
lines 1–56why, one step back1import { auth } from './basic-auth'23describe('auth', () => {4 it('auth() - not include Authorization Header', () => {5 const res = auth(new Request('http://localhost/auth'))6 expect(res).toBeUndefined()7 })89 it('auth() - invalid Authorization Header format', () => {10 const res = auth(11 new Request('http://localhost/auth', {12 headers: { Authorization: 'InvalidAuthHeader' },13 })14 )15 expect(res).toBeUndefined()16 })1718 it('auth() - invalid Base64 string in Authorization Header', () => {19 const res = auth(20 new Request('http://localhost/auth', {21 headers: { Authorization: 'Basic InvalidBase64' },22 })23 )24 expect(res).toBeUndefined()25 })2627 it('auth() - valid Authorization Header', () => {28 const validBase64 = btoa('username:password')29 const res = auth(30 new Request('http://localhost/auth', {31 headers: { Authorization: `Basic ${validBase64}` },32 })33 )34 expect(res).toEqual({ username: 'username', password: 'password' })35 })3637 it('auth() - empty username', () => {38 const validBase64 = btoa(':password')39 const res = auth(40 new Request('http://localhost/auth', {41 headers: { Authorization: `Basic ${validBase64}` },42 })43 )44 expect(res).toEqual({ username: '', password: 'password' })45 })4647 it('auth() - empty password', () => {48 const validBase64 = btoa('username:')49 const res = auth(50 new Request('http://localhost/auth', {51 headers: { Authorization: `Basic ${validBase64}` },52 })53 )54 expect(res).toEqual({ username: 'username', password: '' })55 })56})