chadtmiller.com/hud
A remote MCP server that shows atproto records as interactive UI inside MCP Apps hosts
place.hud.hudkit 0.3.1 Latest 5 packages
0
0
// `npm run unit` in web/ (`just check` runs it).
import { strict as assert } from 'node:assert';
import { test } from 'node:test';
import { backPath, wentOn } from './back.ts';
const ORIGIN = 'https://next.grain.social';
test('a path of the app comes back as it is', () => {
assert.equal(backPath('/profile/me?tab=1#top', ORIGIN), '/profile/me?tab=1#top');
assert.equal(backPath('/', ORIGIN), '/');
});
test('nothing, or anything off the origin, comes back home', () => {
for (const back of [null, '', '//evil.example', '/\\evil.example', '/\t/evil.example', '/\n/evil.example', '\t//evil.example', 'https://evil.example/', 'javascript:alert(1)', 'http://next.grain.social/']) {
assert.equal(backPath(back, ORIGIN), '/', JSON.stringify(back));
}
});
const AUTHORIZE = 'https://hud.place/oauth/authorize?client_id=x&login_hint=alice.test';
const CALLBACK = 'https://next.grain.social/auth/callback';
const redirect = (location: string | null) => ({ status: 303, location });
test('where HUD goes straight on, the browser goes there', () => {
assert.deepEqual(wentOn(redirect('https://pds.test/oauth/authorize?request_uri=urn:1'), AUTHORIZE, CALLBACK), { to: 'https://pds.test/oauth/authorize?request_uri=urn:1' });
assert.deepEqual(wentOn(redirect('/oauth/other'), AUTHORIZE, CALLBACK), { to: 'https://hud.place/oauth/other' });
});
test('sent back refused, why is said for the screen', () => {
assert.deepEqual(wentOn(redirect(`${CALLBACK}?error=access_denied&error_description=nobody.test+does+not+resolve+to+an+account&state=s`), AUTHORIZE, CALLBACK), { error: 'nobody.test does not resolve to an account' });
assert.deepEqual(wentOn(redirect(`${CALLBACK}?error=invalid_request`), AUTHORIZE, CALLBACK), { error: 'invalid_request' });
assert.deepEqual(wentOn(redirect(`${CALLBACK}?state=s`), AUTHORIZE, CALLBACK), { error: 'Signing in was refused.' });
});
test("where HUD answers its own page, the browser goes there; where it cannot start, or is not reached, why", () => {
assert.deepEqual(wentOn({ status: 200, location: null }, AUTHORIZE, CALLBACK), { to: AUTHORIZE });
assert.deepEqual(wentOn({ status: 400, location: null }, AUTHORIZE, CALLBACK), { error: 'Signing in could not start (HTTP 400); try again.' });
assert.deepEqual(wentOn(redirect(null), AUTHORIZE, CALLBACK), { error: 'Signing in could not start (HTTP 303); try again.' });
assert.deepEqual(wentOn(null, AUTHORIZE, CALLBACK), { error: 'Signing in could not reach the server; try again.' });
});