import { expect, test } from 'vitest'; import { resolveWhiteLabel } from './white-label'; // The sign-in wiring, as a gate. // // Four Lux surfaces once had four sign-ins: two hand-rolled the IAM client, one // built an authorize URL with no PKCE, and one read the issuer out of an env // var — brand per DEPLOYMENT. `resolveWhiteLabel` is the single answer, and // these are the three facts every surface depends on: // // issuer from the HOST, never an env var and never a per-app table // clientId from the HOST, `-` per the fleet naming scheme // total an unknown host resolves rather than throws // // Each pair below was checked against the live authorize endpoint: these answer // 302 where an unregistered pair answers 400. That is why a wrong value here is // a sign-in outage rather than a cosmetic slip, and why the pairs are written // down instead of derived a second time in the assertion. const at = (host: string) => { const w = resolveWhiteLabel(host); return { issuer: w.issuer, clientId: w.clientId }; }; test('the issuer and the client id come from the hostname', () => { expect(at('lux.cloud')).toEqual({ issuer: 'https://lux.id', clientId: 'lux-cloud' }); expect(at('mpc.lux.network')).toEqual({ issuer: 'https://lux.id', clientId: 'lux-mpc' }); expect(at('web3.hanzo.ai')).toEqual({ issuer: 'https://hanzo.id', clientId: 'hanzo-web3' }); }); test("Zoo's issuer is zoolabs.id, which is the row every hand-rolled map gets wrong", () => { // `id.zoo.network` answers, which is why it keeps being copied around, but // its own discovery document advertises `https://zoolabs.id` — so a client // pinned to the alias validates `iss` against a string the IdP never emits // and rejects every token it is handed. expect(at('zoo.cloud')).toEqual({ issuer: 'https://zoolabs.id', clientId: 'zoo-cloud' }); expect(at('zoo.ngo').issuer).toBe('https://zoolabs.id'); }); test('a pinned slug is a registration, not a guess', () => { // One client for the whole brand, so the derivation that works everywhere // else — leftmost label — would ask for a client id that does not exist. expect(at('bootno.de')).toEqual({ issuer: 'https://id.bootno.de', clientId: 'bootnode-platform' }); expect(at('console.bootno.de').clientId).toBe('bootnode-platform'); expect(at('cloud.pars.network').clientId).toBe('pars-app'); }); test('an apex takes the service label, and www is chrome rather than an app', () => { expect(at('lux.network').clientId).toBe('lux-network'); expect(at('www.lux.network').clientId).toBe('lux-network'); expect(at('ui.lux.finance').clientId).toBe('lux-ui'); }); test('a host nobody registered still resolves', () => { // A preview URL and a health probe reach this. Throwing here blanks the UI // on a page that has nothing to do with signing in. expect(at('nope.example')).toEqual({ issuer: 'https://lux.id', clientId: 'lux-app' }); expect(at('')).toEqual({ issuer: 'https://lux.id', clientId: 'lux-app' }); expect(at('localhost').clientId).toBe('lux-local'); }); test('a domain is matched on a label boundary, not as a substring', () => { // `notlux.cloud` is not Lux's. Matched as a suffix it would be, and one // registrable domain away is somebody else's sign-in. expect(resolveWhiteLabel('notlux.cloud').org).toBe('lux'); expect(at('notlux.cloud').clientId).toBe('lux-app'); });