deno.land / x / oauth4webapi@v1.2.2 / test / www_authenticate.test.ts
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190import test from 'ava'import { getResponse } from './_setup.js'import * as lib from '../src/index.js'
function response(headers: Headers) { return getResponse('', { status: 401, headers })}
const name = 'www-authenticate'
test('parseWwwAuthenticateChallenges()', (t) => { { const headers = new Headers() t.deepEqual(lib.parseWwwAuthenticateChallenges(response(headers)), undefined) }
{ const headers = new Headers() headers.append(name, 'invalid=true') t.deepEqual(lib.parseWwwAuthenticateChallenges(response(headers)), undefined) }
{ const headers = new Headers() headers.append(name, 'Basic realm="Access to the staging site", charset="UTF-8"') t.deepEqual(lib.parseWwwAuthenticateChallenges(response(headers)), [ { scheme: 'basic', parameters: { charset: 'UTF-8', realm: 'Access to the staging site' } }, ]) }
{ const headers = new Headers() headers.append(name, 'Basic') t.deepEqual(lib.parseWwwAuthenticateChallenges(response(headers)), [ { scheme: 'basic', parameters: {} }, ]) }
{ const headers = new Headers() headers.append(name, 'Basic realm=realm') t.deepEqual(lib.parseWwwAuthenticateChallenges(response(headers)), [ { scheme: 'basic', parameters: { realm: 'realm' } }, ]) }
{ const headers = new Headers() headers.append(name, 'BASIC REALM=realM') t.deepEqual(lib.parseWwwAuthenticateChallenges(response(headers)), [ { scheme: 'basic', parameters: { realm: 'realM' } }, ]) }
{ const headers = new Headers() headers.append(name, 'Basic realm="realm"') t.deepEqual(lib.parseWwwAuthenticateChallenges(response(headers)), [ { scheme: 'basic', parameters: { realm: 'realm' } }, ]) }
{ const headers = new Headers() headers.append(name, 'Basic auth-param1="value"') t.deepEqual(lib.parseWwwAuthenticateChallenges(response(headers)), [ { scheme: 'basic', parameters: { 'auth-param1': 'value' } }, ]) }
{ const headers = new Headers() headers.append( name, 'Digest realm="http-auth@example.org", qop="auth, auth-int", algorithm=SHA-256, nonce="7ypf/xlj9XXwfDPEoM4URrv/xwf94BcCAzFZH4GiTo0v", opaque="FQhe/qaU925kfnzjCev0ciny7QMkPqMAFRtzCUYo5tdS"', ) headers.append( name, 'Digest realm="http-auth@example.org", qop="auth, auth-int", algorithm=MD5, nonce="7ypf/xlj9XXwfDPEoM4URrv/xwf94BcCAzFZH4GiTo0v", opaque="FQhe/qaU925kfnzjCev0ciny7QMkPqMAFRtzCUYo5tdS"', )
t.deepEqual(lib.parseWwwAuthenticateChallenges(response(headers)), [ { scheme: 'digest', parameters: { realm: 'http-auth@example.org', qop: 'auth, auth-int', algorithm: 'SHA-256', nonce: '7ypf/xlj9XXwfDPEoM4URrv/xwf94BcCAzFZH4GiTo0v', opaque: 'FQhe/qaU925kfnzjCev0ciny7QMkPqMAFRtzCUYo5tdS', }, }, { scheme: 'digest', parameters: { realm: 'http-auth@example.org', qop: 'auth, auth-int', algorithm: 'MD5', nonce: '7ypf/xlj9XXwfDPEoM4URrv/xwf94BcCAzFZH4GiTo0v', opaque: 'FQhe/qaU925kfnzjCev0ciny7QMkPqMAFRtzCUYo5tdS', }, }, ]) }
{ const headers = new Headers() headers.append( name, 'Newauth realm="apps", type=1, title="Login to "apps"", Basic realm="simple"', ) t.deepEqual(lib.parseWwwAuthenticateChallenges(response(headers)), [ { scheme: 'newauth', parameters: { realm: 'apps', type: '1', title: 'Login to "apps"', }, }, { scheme: 'basic', parameters: { realm: 'simple', }, }, ]) }
{ const headers = new Headers() headers.append(name, 'Basic') headers.append(name, 'DPoP') t.deepEqual(lib.parseWwwAuthenticateChallenges(response(headers)), [ { scheme: 'basic', parameters: {} }, { scheme: 'dpop', parameters: {} }, ]) }
{ const headers = new Headers() headers.append(name, 'Newauth realm="apps", type=1, title="Login to "apps","') headers.append(name, 'Newauth realm="apps", type=1, title="Login to "apps"') t.deepEqual(lib.parseWwwAuthenticateChallenges(response(headers)), [ { scheme: 'newauth', parameters: { realm: 'apps', type: '1', title: 'Login to "apps",' } }, { scheme: 'newauth', parameters: { realm: 'apps', type: '1', title: 'Login to "apps' } }, ]) }
{ const headers = new Headers() headers.append(name, 'Newauth realm="apps", type=1, title="Login to "apps",",') t.deepEqual(lib.parseWwwAuthenticateChallenges(response(headers)), [ { scheme: 'newauth', parameters: { realm: 'apps', type: '1', title: 'Login to "apps",' } }, ]) }
{ const headers = new Headers() headers.append(name, 'Newauth realm="apps", type=1, title="Login to "apps",') t.deepEqual(lib.parseWwwAuthenticateChallenges(response(headers)), [ { scheme: 'newauth', parameters: { realm: 'apps', type: '1', title: 'Login to "apps' } }, ]) }
{ const headers = new Headers() headers.append(name, 'Newauth realm="apps", type=1, title="Login to "apps","') t.deepEqual(lib.parseWwwAuthenticateChallenges(response(headers)), [ { scheme: 'newauth', parameters: { realm: 'apps', type: '1', title: 'Login to "apps",' } }, ]) }
{ const headers = new Headers() headers.append(name, 'Newauth realm="apps", type=1, title="Login to apps=asd"') t.deepEqual(lib.parseWwwAuthenticateChallenges(response(headers)), [ { scheme: 'newauth', parameters: { realm: 'apps', type: '1', title: 'Login to apps=asd' } }, ]) }
{ const headers = new Headers() headers.append(name, 'Newauth realm="apps", title="Login to, apps=asd", type=1') t.deepEqual(lib.parseWwwAuthenticateChallenges(response(headers)), [ { scheme: 'newauth', parameters: { realm: 'apps', type: '1', title: 'Login to, apps=asd' } }, ]) }})
Version Info