Add direct B2 device enrollment and consolidate VPS controls
Device Core qualification / qualify (push) Successful in 8m6s
Device Core qualification / qualify (push) Successful in 8m6s
This commit is contained in:
@@ -318,3 +318,45 @@ test('application deletion requires company and credential authority and forward
|
||||
assert.deepEqual(calls, [{ path: '/v2/management/applications/delete', body: { integration_id: input.integrationId } }]);
|
||||
assert.equal(repo.writes.at(-1).values[1], 'b2.application-delete');
|
||||
});
|
||||
|
||||
test('enrollment options reveal only managed contours linked to the current active project', async () => {
|
||||
const own = 'a'.repeat(32), foreign = 'b'.repeat(32); const repo = repository();
|
||||
const db = await repo.pool.connect(), original = db.query; let released = false;
|
||||
db.release = () => { released = true; };
|
||||
db.query = async (sql, values) => {
|
||||
if (sql.includes('from device_b2_hosts')) {
|
||||
assert.match(sql, /l.project_id=v.project_id/); assert.match(sql, /h.lifecycle_state='active'/);
|
||||
assert.deepEqual(values, [projectId]); return { rows: [{ ...source, host_id: hostId, display_name: 'VPS', contour_ids: [own] }] };
|
||||
}
|
||||
return original(sql, values);
|
||||
};
|
||||
const service = new B2Infrastructure({ pool: repo.pool, secrets: { read: async () => pkg }, clientFactory: () => ({ async call(path) {
|
||||
assert.ok(released);
|
||||
return path === '/v2/identity' ? { host_id: pkg.host_id } : { items: [{ id: own, name: 'Own', access: 'manage' }, { id: foreign, name: 'Foreign', access: 'manage' }] };
|
||||
} }) });
|
||||
const result = await service.execute(actor, { projectRef: `project:${projectId}`, action: 'enrollment-options' });
|
||||
assert.deepEqual(result.hosts[0].contours, [{ id: own, name: 'Own' }]); assert.ok(!JSON.stringify(result).includes('Foreign'));
|
||||
});
|
||||
|
||||
test('enrollment validates project capability, active host and contour before forwarding USB', async () => {
|
||||
const own = 'a'.repeat(32), foreign = 'b'.repeat(32); const repo = repository();
|
||||
const db = await repo.pool.connect(), original = db.query; const calls = [];
|
||||
db.query = async (sql, values) => {
|
||||
if (sql.includes('from device_b2_hosts')) {
|
||||
assert.match(sql, /l.project_id=v.project_id/); assert.match(sql, /h.lifecycle_state='active'/);
|
||||
return { rows: values[0] === hostId && values[1] === projectId && values[2] === own ? [source] : [] };
|
||||
}
|
||||
return original(sql, values);
|
||||
};
|
||||
const service = new B2Infrastructure({ pool: repo.pool, secrets: { read: async () => pkg }, clientFactory: () => ({ async call(path, body) {
|
||||
calls.push(path); return path === '/v2/identity' ? { host_id: pkg.host_id } : { accepted: body.action };
|
||||
} }) });
|
||||
const input = { projectRef: `project:${projectId}`, hostRef: `host:${hostId}`, action: 'enrollment', contourId: own, request: { action: 'register', name: 'B2', imei: '323456789012345', number: 300 } };
|
||||
await assert.rejects(service.execute(actor, { ...input, contourId: foreign }), /b2_access_denied/);
|
||||
assert.deepEqual(calls, []);
|
||||
assert.deepEqual(await service.execute(actor, input), { accepted: 'register' });
|
||||
assert.deepEqual(calls, ['/v2/identity', `/v2/contours/${own}/enrollment`]);
|
||||
const denied = new B2Infrastructure({ pool: repository({ role: 'viewer' }).pool, secrets: { read: async () => assert.fail('no credentials') } });
|
||||
await assert.rejects(denied.execute({ ...actor, hubRole: 'member' }, input));
|
||||
await assert.rejects(denied.execute({ ...actor, hubRole: 'member' }, { projectRef: input.projectRef, action: 'enrollment-options' }));
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user