26 lines
1023 B
TypeScript
26 lines
1023 B
TypeScript
import assert from 'node:assert/strict';
|
|
import { test } from 'node:test';
|
|
import { accessToken } from '../src/accounts/access-token.ts';
|
|
|
|
test('Access JWT can fall back to the browser authorization cookie', async () => {
|
|
const request = new Request('https://edgessh.example.workers.dev/api/auth/me', {
|
|
headers: { Cookie: 'unrelated=value; CF_Authorization=not-a-jwt; another=value' },
|
|
});
|
|
assert.equal(accessToken(request), 'not-a-jwt');
|
|
});
|
|
|
|
test('missing Access header and cookie is reported as unauthenticated', async () => {
|
|
const request = new Request('https://edgessh.example.workers.dev/api/auth/me');
|
|
assert.equal(accessToken(request), null);
|
|
});
|
|
|
|
test('Access assertion header takes precedence over the browser cookie', async () => {
|
|
const request = new Request('https://edgessh.example.workers.dev/api/auth/me', {
|
|
headers: {
|
|
'Cf-Access-Jwt-Assertion': 'header-token',
|
|
Cookie: 'CF_Authorization=cookie-token',
|
|
},
|
|
});
|
|
assert.equal(accessToken(request), 'header-token');
|
|
});
|