2026-06-02 00:43:05 +03:00
|
|
|
import { describe, expect, test } from 'bun:test';
|
|
|
|
|
import { createRequestSecurityRuntime } from './request-security.js';
|
|
|
|
|
|
|
|
|
|
const createRuntime = () => createRequestSecurityRuntime({
|
|
|
|
|
readSettingsFromDiskMigrated: async () => ({}),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('request security runtime', () => {
|
2026-07-01 09:55:41 +03:00
|
|
|
test('allows packaged client origins for remote client transports', async () => {
|
2026-06-02 00:43:05 +03:00
|
|
|
const runtime = createRuntime();
|
|
|
|
|
|
|
|
|
|
await expect(runtime.isRequestOriginAllowed({
|
|
|
|
|
headers: {
|
|
|
|
|
origin: 'openchamber-ui://app',
|
|
|
|
|
host: '192.168.1.130:1202',
|
|
|
|
|
},
|
|
|
|
|
socket: {},
|
|
|
|
|
})).resolves.toBe(true);
|
2026-07-01 09:55:41 +03:00
|
|
|
|
|
|
|
|
await expect(runtime.isRequestOriginAllowed({
|
|
|
|
|
headers: {
|
|
|
|
|
origin: 'capacitor://localhost',
|
|
|
|
|
host: '192.168.1.130:1202',
|
|
|
|
|
},
|
|
|
|
|
socket: {},
|
|
|
|
|
})).resolves.toBe(true);
|
2026-07-04 02:48:07 +03:00
|
|
|
|
|
|
|
|
// Android Capacitor WebView (androidScheme 'https') reports this origin.
|
|
|
|
|
await expect(runtime.isRequestOriginAllowed({
|
|
|
|
|
headers: {
|
|
|
|
|
origin: 'https://localhost',
|
|
|
|
|
host: '192.168.1.130:1202',
|
|
|
|
|
},
|
|
|
|
|
socket: {},
|
|
|
|
|
})).resolves.toBe(true);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('rejects unknown origins', async () => {
|
|
|
|
|
const runtime = createRuntime();
|
|
|
|
|
|
|
|
|
|
await expect(runtime.isRequestOriginAllowed({
|
|
|
|
|
headers: {
|
|
|
|
|
origin: 'https://evil.example.com',
|
|
|
|
|
host: '192.168.1.130:1202',
|
|
|
|
|
},
|
|
|
|
|
socket: {},
|
|
|
|
|
})).resolves.toBe(false);
|
2026-06-02 00:43:05 +03:00
|
|
|
});
|
|
|
|
|
});
|