fix(webui): make listener exposure explicit

Use a local-only default while preserving saved operator choices and keeping broader network access available from the settings panel.

Treat enabled encrypted transport as a startup requirement and present a dismissible notice when remote browser access is not protected.
This commit is contained in:
DrSmoothl committed 2026-08-01 16:50:08 +08:00
1 parent e4179ffb47
commit ea841d929e
12 files changed
+193 -36

No files matched your search

+18 -1
View File
@@ -2,7 +2,7 @@ import { describe, it, expect, beforeEach, afterEach } from 'vitest';
import fs from 'fs';
import os from 'os';
import path from 'path';
import { validateTlsPair, resolveTlsContext } from '../src/webui/tls';
import { requireTlsContext, validateTlsPair, resolveTlsContext } from '../src/webui/tls';
// A throwaway self-signed pair (openssl, CN=snowluma-test). createSecureContext
// only parses — expiry is irrelevant — so this stays valid for the test forever.
@@ -99,4 +99,21 @@ describe('resolveTlsContext', () => {
expect(r.ok).toBe(false);
expect(r.reason).toBeTruthy();
});
it('refuses to start an enabled TLS listener with an unusable certificate pair', () => {
expect(() => requireTlsContext(dir)).toThrow(/TLS.*missing/i);
fs.writeFileSync(path.join(dir, 'cert.pem'), 'garbage');
fs.writeFileSync(path.join(dir, 'key.pem'), 'garbage');
expect(() => requireTlsContext(dir)).toThrow(/TLS.*invalid/i);
});
it('returns a validated certificate pair for an enabled TLS listener', () => {
fs.writeFileSync(path.join(dir, 'cert.pem'), CERT);
fs.writeFileSync(path.join(dir, 'key.pem'), KEY);
const tls = requireTlsContext(dir);
expect(tls.cert.toString()).toContain('BEGIN CERTIFICATE');
expect(tls.key.toString()).toContain('PRIVATE KEY');
});
});