Complete ARNavi VPS onboarding and contextual key controls
Device Core qualification / qualify (push) Successful in 6m45s

This commit is contained in:
DCCONSTRUCTIONS
2026-09-30 23:57:17 +03:00
parent 19aa5e2796
commit 53dbd7483e
11 changed files with 312 additions and 64 deletions
@@ -264,3 +264,42 @@ test('tracker settings keep project and contour authority across remote calls',
await assert.rejects(service.execute(actor,input), /b2_access_denied/);
assert.equal(calls.length,2);
});
test('VPS onboarding rejects invalid or application-only credentials without creating a host', async () => {
for (const input of ['bad-json', JSON.stringify({ ...pkg, authority: 'contours' }), JSON.stringify(pkg)]) {
const repo = repository(); let secrets = 0;
const service = new B2Infrastructure({ pool: repo.pool,
secrets: { save: async () => { secrets += 1; return 'private-ref'; } },
clientFactory: () => ({ call: async (path) => path === '/v2/identity' ? { host_id: input === JSON.stringify(pkg) ? 'foreign-host' : pkg.host_id } : { items: [] } }) });
await assert.rejects(service.execute(actor, { action: 'register-host', projectRef: `project:${projectId}`, name: 'VPS', connection: input }, 'a'.repeat(32)));
assert.equal(secrets, 0); assert.deepEqual(repo.writes, []);
}
});
test('VPS onboarding reuses the project host and audits no credential material', async () => {
const queries = []; let existing = false;
const base = repository(); const db = await base.pool.connect(); const original = db.query.bind(db);
db.query = async (sql, values) => {
queries.push({ sql, values });
if (sql.includes('pg_advisory_xact_lock')) return { rows: [] };
if (sql.startsWith('insert into device_b2_hosts')) return { rows: [{ id: source.id }] };
if (sql.startsWith('select h.host_key')) return { rows: existing ? [{ host_key: 'b2-existing-project-view' }] : [] };
if (sql.startsWith('insert into device_infrastructure_hosts')) return { rows: [{ id: hostId, host_key: values[3],
display_name: values[4], project_id: projectId, owner_scope_id: ownerId, lifecycle_state: 'active', created: !existing }] };
if (sql.startsWith('insert into device_b2_host_views')) { existing = true; return { rows: [] }; }
return original(sql, values);
};
const service = new B2Infrastructure({ pool: base.pool, secrets: { save: async () => 'private-ref' },
clientFactory: () => ({ call: async () => ({ host_id: pkg.host_id }) }) });
const input = { action: 'register-host', projectRef: `project:${projectId}`, name: 'VPS', connection: JSON.stringify(pkg) };
const first = await service.execute(actor, input, 'a'.repeat(32));
const second = await service.execute(actor, input, 'b'.repeat(32));
assert.equal(first.hostRef, second.hostRef);
assert.equal(queries.filter((q) => q.sql === 'commit').length, 2);
const hosts = queries.filter((q) => q.sql.startsWith('insert into device_infrastructure_hosts'));
assert.equal(hosts[0].values[3], `b2-${source.id}`);
assert.equal(hosts[1].values[3], 'b2-existing-project-view');
const audit = queries.filter((q) => q.sql.includes('insert into device_audit_events'));
assert.ok(audit.length > 0);
assert.ok(!JSON.stringify(audit).includes(pkg.client_secret));
});