fix(web): the app opens over plain HTTP on a home network instead of showing a blank page
Browsers offer crypto.randomUUID only on HTTPS pages and localhost. The player's client id called it at startup, so opening Minstrel at http://<host>:4533, as the README's quick start says to, threw before anything rendered. The id now falls back to crypto.getRandomValues, which every page has. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,13 +1,18 @@
|
||||
import { afterEach, beforeEach, describe, expect, test } from 'vitest';
|
||||
import { getOrCreateClientId } from './clientId';
|
||||
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest';
|
||||
import { getOrCreateClientId, randomUUID } from './clientId';
|
||||
|
||||
const UUID_V4 = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
|
||||
|
||||
beforeEach(() => sessionStorage.clear());
|
||||
afterEach(() => sessionStorage.clear());
|
||||
afterEach(() => {
|
||||
sessionStorage.clear();
|
||||
vi.unstubAllGlobals();
|
||||
});
|
||||
|
||||
describe('getOrCreateClientId', () => {
|
||||
test('generates a UUID on first call and persists it in sessionStorage', () => {
|
||||
const id = getOrCreateClientId();
|
||||
expect(id).toMatch(/^[0-9a-f-]{36}$/);
|
||||
expect(id).toMatch(UUID_V4);
|
||||
expect(sessionStorage.getItem('minstrel.client_id')).toBe(id);
|
||||
});
|
||||
|
||||
@@ -17,3 +22,15 @@ describe('getOrCreateClientId', () => {
|
||||
expect(a).toBe(b);
|
||||
});
|
||||
});
|
||||
|
||||
describe('randomUUID', () => {
|
||||
test('still makes an id on a plain-HTTP page, where crypto.randomUUID is missing', () => {
|
||||
const real = globalThis.crypto;
|
||||
vi.stubGlobal('crypto', { getRandomValues: real.getRandomValues.bind(real) });
|
||||
const a = randomUUID();
|
||||
const b = randomUUID();
|
||||
expect(a).toMatch(UUID_V4);
|
||||
expect(b).toMatch(UUID_V4);
|
||||
expect(a).not.toBe(b);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user