mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-20 18:22:25 +00:00
fix(cctv): keep main's HLS leases and test them through the middleware
Drop the per-peer lease budget and the lease-to-address binding. Main's keyless same-site gate already refuses cross-site media requests, while the budget capped a shared address (Docker gateway, reverse proxy, NAT) at 8 leases across both sessions and still let one address hold both. A lease now keeps working when its viewer reconnects from a new address. Add a middleware test that drives the HLS playlist, segment and DELETE for viewers on one shared address, on distinct addresses and after an address change, and fold the media cases (segment read, DELETE, no catalog request) into the cross-site table test. Remove the redundant puppeteer flag, the CURRENT-STATE paragraph and the changelog fragment, which no longer describe a change.
This commit is contained in:
1 parent
90e464eb5a
commit
0699876e4e
8 files changed
+212
-162
No files matched your search
@@ -155,9 +155,9 @@ function mount(t, respond) {
|
||||
});
|
||||
assert.ok(handler, 'the CCTV provider must mount a middleware');
|
||||
|
||||
const call = async (path, headers = {}) => {
|
||||
const call = async (path, headers = {}, method = 'GET') => {
|
||||
const { res, done } = recordingResponse();
|
||||
await handler({ url: path, headers, method: 'GET', on() {} }, res);
|
||||
await handler({ url: path, headers, method, on() {} }, res);
|
||||
await done;
|
||||
return res;
|
||||
};
|
||||
@@ -401,24 +401,35 @@ test('every CCTV route refuses cross-site requests and admits the app itself', a
|
||||
}),
|
||||
);
|
||||
const host = 'localhost:5173';
|
||||
const paths = [
|
||||
'/sources',
|
||||
'/health',
|
||||
`/stream/${STILL.id}`,
|
||||
`/frame/${STILL.id}`,
|
||||
`/media/${VIDEO.id}`,
|
||||
const lease = '00000000-0000-4000-8000-000000000000';
|
||||
const routes = [
|
||||
['GET', '/sources'],
|
||||
['GET', '/health'],
|
||||
['GET', `/stream/${STILL.id}`],
|
||||
['GET', `/frame/${STILL.id}`],
|
||||
['GET', `/media/${VIDEO.id}`],
|
||||
['GET', `/media/${VIDEO.id}/seg_0.ts?lease=${lease}`],
|
||||
['DELETE', `/media/${VIDEO.id}?lease=${lease}`],
|
||||
];
|
||||
// A catalog refresh would fetch the live packs: a refused request must not
|
||||
// start one.
|
||||
process.env.CCTV_FORCE_AUSTIN = '1';
|
||||
for (const headers of [
|
||||
{ host, 'sec-fetch-site': 'cross-site' },
|
||||
{ host, 'sec-fetch-site': 'same-site' },
|
||||
{ host, origin: 'https://elsewhere.example' },
|
||||
{ host, origin: 'null' },
|
||||
])
|
||||
for (const path of paths) {
|
||||
const res = await app.call(path, headers);
|
||||
assert.equal(res.statusCode, 403, `${path} ${JSON.stringify(headers)}`);
|
||||
for (const [method, path] of routes) {
|
||||
const res = await app.call(path, headers, method);
|
||||
assert.equal(
|
||||
res.statusCode,
|
||||
403,
|
||||
`${method} ${path} ${JSON.stringify(headers)}`,
|
||||
);
|
||||
}
|
||||
assert.deepEqual(app.requests, [], 'a refused request reached an upstream');
|
||||
process.env.CCTV_FORCE_AUSTIN = '0';
|
||||
for (const headers of [
|
||||
{ host, 'sec-fetch-site': 'same-origin' },
|
||||
{ host, origin: `http://${host}` },
|
||||
@@ -528,46 +539,3 @@ test('a forwarded same-origin request reaches every CCTV route but not the Stree
|
||||
assert.equal(direct.body, 'street-view');
|
||||
assert.equal(streetViewCalls(), 1);
|
||||
});
|
||||
|
||||
test('cross-site media creation, segment reads and release fail before any catalog or media fetch', async (t) => {
|
||||
let handler;
|
||||
const originalFetch = globalThis.fetch;
|
||||
let calls = 0;
|
||||
globalThis.fetch = async () => {
|
||||
calls++;
|
||||
throw new Error('must not fetch');
|
||||
};
|
||||
t.after(() => {
|
||||
globalThis.fetch = originalFetch;
|
||||
});
|
||||
cctvProxy().configureServer({
|
||||
middlewares: {
|
||||
use: (_path, fn) => {
|
||||
handler = fn;
|
||||
},
|
||||
},
|
||||
});
|
||||
for (const headers of [
|
||||
{ origin: 'https://foreign.example' },
|
||||
{ origin: 'null' },
|
||||
{ 'sec-fetch-site': 'cross-site' },
|
||||
{ 'sec-fetch-site': 'same-site' },
|
||||
]) {
|
||||
for (const [method, url] of [
|
||||
['GET', '/media/camera?lease=test'],
|
||||
['DELETE', '/media/camera?lease=test'],
|
||||
['GET', '/media/camera/seg_0.ts?lease=test'],
|
||||
]) {
|
||||
const { res } = recordingResponse();
|
||||
res.setHeader = (name, value) => {
|
||||
res.headers[name] = value;
|
||||
};
|
||||
await handler(
|
||||
{ method, url, headers: { host: 'localhost:4173', ...headers } },
|
||||
res,
|
||||
);
|
||||
assert.equal(res.statusCode, 403);
|
||||
}
|
||||
}
|
||||
assert.equal(calls, 0);
|
||||
});
|
||||
Reference in new issue
Block a user