mirror of
https://github.com/misenhower/splatoon2.ink.git
synced 2026-09-30 21:26:51 -05:00
Improve readability of test setup and assertions
This commit is contained in:
@@ -9,6 +9,7 @@ const env = {
|
||||
ACCESS_TEAM_DOMAIN: 'example.cloudflareaccess.com',
|
||||
ACCESS_AUD: 'admin-audience',
|
||||
};
|
||||
|
||||
async function token({
|
||||
audience = env.ACCESS_AUD,
|
||||
issuer = 'https://' + env.ACCESS_TEAM_DOMAIN,
|
||||
@@ -22,6 +23,7 @@ async function token({
|
||||
.setExpirationTime(expires)
|
||||
.sign(privateKey);
|
||||
}
|
||||
|
||||
function request(jwt, host = env.ADMIN_HOSTNAME) {
|
||||
return new Request(`https://${host}/admin/`, {
|
||||
headers: jwt ? { 'Cf-Access-Jwt-Assertion': jwt } : {},
|
||||
@@ -32,17 +34,18 @@ test('validates Access signature, issuer, audience, expiration and configured ho
|
||||
assert.deepEqual(await verifyAccess(request(await token()), env, publicKey), {
|
||||
email: 'admin@example.test',
|
||||
});
|
||||
|
||||
for (const options of [
|
||||
{ audience: 'different-app' },
|
||||
{ issuer: 'https://other.cloudflareaccess.com' },
|
||||
{ expires: '0s' },
|
||||
])
|
||||
assert.equal(await verifyAccess(request(await token(options)), env, publicKey), null);
|
||||
assert.equal(
|
||||
await verifyAccess(request(await token(), 'other.workers.dev'), env, publicKey),
|
||||
null,
|
||||
);
|
||||
|
||||
assert.equal(await verifyAccess(request(await token(), 'other.workers.dev'), env, publicKey), null);
|
||||
|
||||
const wrong = await generateKeyPair('RS256');
|
||||
|
||||
assert.equal(await verifyAccess(request(await token()), env, wrong.publicKey), null);
|
||||
});
|
||||
|
||||
|
||||
@@ -4,12 +4,16 @@ import { RunLog, logMessage } from '../../src/app/log.js';
|
||||
|
||||
test('bounds retained logs, redacts secrets, and preserves normal console output', async () => {
|
||||
const consoleLog = mock.method(console, 'info', () => {});
|
||||
|
||||
try {
|
||||
const capture = new RunLog(['secret-value']);
|
||||
await capture.run(async () => {
|
||||
for (let i = 0; i < 205; i++) logMessage('info', `line ${i}`);
|
||||
for (let i = 0; i < 205; i++)
|
||||
logMessage('info', `line ${i}`);
|
||||
|
||||
logMessage('info', 'secret-value Bearer sensitive-token');
|
||||
});
|
||||
|
||||
assert.equal(capture.snapshot.lines.length, 200);
|
||||
assert.equal(capture.snapshot.omitted, 6);
|
||||
assert.equal(capture.snapshot.lines.at(-1).text, '[redacted] Bearer [redacted]');
|
||||
@@ -20,9 +24,11 @@ test('bounds retained logs, redacts secrets, and preserves normal console output
|
||||
});
|
||||
test('concurrent run contexts do not capture each other or unrelated messages', async () => {
|
||||
mock.method(console, 'info', () => {});
|
||||
|
||||
try {
|
||||
const a = new RunLog(),
|
||||
b = new RunLog();
|
||||
|
||||
await Promise.all([
|
||||
a.run(async () => {
|
||||
await Promise.resolve();
|
||||
@@ -33,12 +39,13 @@ test('concurrent run contexts do not capture each other or unrelated messages',
|
||||
}),
|
||||
]);
|
||||
logMessage('info', 'outside');
|
||||
|
||||
assert.deepEqual(
|
||||
a.snapshot.lines.map((l) => l.text),
|
||||
a.snapshot.lines.map(l => l.text),
|
||||
['a'],
|
||||
);
|
||||
assert.deepEqual(
|
||||
b.snapshot.lines.map((l) => l.text),
|
||||
b.snapshot.lines.map(l => l.text),
|
||||
['b'],
|
||||
);
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user