Manage shared ARNavi VPS contours and application keys from infrastructure

This commit is contained in:
DCCONSTRUCTIONS
2026-09-30 15:34:39 +03:00
parent 6ca6738bab
commit 1828a05332
22 changed files with 1099 additions and 2 deletions
@@ -207,3 +207,29 @@ async function postJson(url, body, headers = {}) {
assert.equal(payload.ok, true);
return payload;
}
test('B2 key management rejects cross-origin requests and never caches returned credentials', async (t) => {
const auth = createDeviceManagerAuth({ env: { NODEDC_DEVICE_MANAGER_AUTH_REQUIRED: 'false' } });
const calls = [];
const coreClient = { ...createLocalPreviewDeviceCore(), async b2Infrastructure(actor, body, id) {
calls.push({ actor, body, id }); return { connection: { client_secret: 'synthetic-once-only' } };
} };
const server = createDeviceManagerServer({ auth, coreClient });
await new Promise((resolve, reject) => { server.once('error', reject); server.listen(0, '127.0.0.1', resolve); });
t.after(() => new Promise((resolve) => server.close(resolve)));
const origin = `http://127.0.0.1:${server.address().port}`;
const headers = { 'content-type': 'application/json', 'idempotency-key': 'a'.repeat(32) };
const body = JSON.stringify({ action: 'key-issue', projectRef: 'project:synthetic', hostRef: 'host:synthetic' });
for (const supplied of [undefined, 'https://attacker.invalid']) {
const denied = await fetch(origin + '/api/device-manager/b2/infrastructure', { method: 'POST', headers: { ...headers, ...(supplied ? { origin: supplied } : {}) }, body });
assert.equal(denied.status, 403);
}
assert.equal(calls.length, 0);
const response = await fetch(origin + '/api/device-manager/b2/infrastructure', { method: 'POST',
headers: { ...headers, origin, 'X-NODEDC-User-Ref': 'user:spoofed' }, body });
assert.equal(response.status, 200);
assert.match(response.headers.get('cache-control'), /no-store/);
assert.equal((await response.json()).result.connection.client_secret, 'synthetic-once-only');
assert.equal(calls.length, 1);
assert.equal(calls[0].actor.userRef, 'user:local-device-admin');
});