mirror of
https://github.com/ruvnet/RuView.git
synced 2026-09-01 04:55:54 +00:00
feat(metaharness): add guarded Cognitum Spaces OAuth (#1644)
This commit is contained in:
@@ -67,6 +67,17 @@ test('homecore guidance exposes requested capabilities and honest boundaries', (
|
||||
);
|
||||
});
|
||||
|
||||
test('integration guidance exposes the Cognitum OAuth surface and authority boundary', () => {
|
||||
const result = getGuidance(
|
||||
{ topic: 'integrations', query: 'Cognitum Spaces OAuth' },
|
||||
{ repoRoot: REPO_ROOT },
|
||||
);
|
||||
assert.equal(result.ok, true, JSON.stringify(result.sourceCheck));
|
||||
assert.equal(result.capabilities[0].id, 'cognitum-spaces-oauth');
|
||||
assert.match(result.capabilities[0].limitations.join(' '), /no write|read-only/i);
|
||||
assert.match(result.capabilities[0].limitations.join(' '), /credential-use/i);
|
||||
});
|
||||
|
||||
test('query ranks the matching capability and searches reviewed knowledge', () => {
|
||||
const result = getGuidance(
|
||||
{ topic: 'homecore', query: 'Wasmtime plugin', limit: 3 },
|
||||
|
||||
@@ -47,14 +47,21 @@ test('MCP handshake: initialize reports the package.json version; list endpoints
|
||||
s.send({ jsonrpc: '2.0', id: 1, method: 'initialize', params: {} });
|
||||
const init = await s.next(1);
|
||||
assert.equal(init.result.serverInfo.version, pkg.version, 'ADR-263 O6: version must match package.json');
|
||||
assert.match(init.result.instructions, /credential-use/);
|
||||
|
||||
s.send({ jsonrpc: '2.0', id: 2, method: 'tools/list' });
|
||||
const tools = (await s.next(2)).result.tools;
|
||||
assert.equal(tools.length, 8);
|
||||
assert.equal(tools.length, 9);
|
||||
for (const t of tools) assert.match(t.name, /^[a-zA-Z0-9_-]{1,64}$/, `advertised name not host-safe: ${t.name}`);
|
||||
const guidance = tools.find((tool) => tool.name === 'ruview_guidance');
|
||||
assert.ok(guidance);
|
||||
assert.equal(guidance.annotations.readOnlyHint, true);
|
||||
const spaces = tools.find((tool) => tool.name === 'ruview_spaces_list');
|
||||
assert.ok(spaces);
|
||||
assert.equal(spaces.annotations.readOnlyHint, false, 'OAuth refresh can update the local credential file');
|
||||
assert.equal(spaces.annotations.idempotentHint, false);
|
||||
assert.equal(spaces.annotations.destructiveHint, false);
|
||||
assert.equal(spaces.annotations.openWorldHint, true);
|
||||
|
||||
s.send({ jsonrpc: '2.0', id: 3, method: 'resources/list' });
|
||||
assert.deepEqual((await s.next(3)).result, { resources: [] });
|
||||
@@ -71,6 +78,11 @@ test('MCP handshake: initialize reports the package.json version; list endpoints
|
||||
assert.equal(guided.ok, true);
|
||||
assert.equal(guided.topic, 'homecore');
|
||||
assert.ok(guided.capabilities.some(({ id }) => id === 'homecore-runtime-restore'));
|
||||
|
||||
s.send({ jsonrpc: '2.0', id: 7, method: 'tools/call', params: { name: 'ruview_spaces_list', arguments: {} } });
|
||||
const deniedSpaces = JSON.parse((await s.next(7)).result.content[0].text);
|
||||
assert.equal(deniedSpaces.reason, 'authority_denied');
|
||||
assert.equal(deniedSpaces.requiredGrant, 'credential-use');
|
||||
} finally {
|
||||
s.close();
|
||||
}
|
||||
|
||||
@@ -21,3 +21,25 @@ test('read-only tools remain available with no mutation grants', () => {
|
||||
assert.equal(authorizeTool('ruview_guidance', {}, { source: 'mcp', grants: [] }).ok, true);
|
||||
assert.deepEqual(validateArguments({ type: 'object', properties: {} }, {}), []);
|
||||
});
|
||||
|
||||
test('credentialed external reads require an explicit MCP grant', () => {
|
||||
const denied = authorizeTool('ruview_spaces_list', {}, { source: 'mcp', grants: [] });
|
||||
assert.equal(denied.reason, 'authority_denied');
|
||||
assert.equal(denied.requiredGrant, 'credential-use');
|
||||
assert.equal(authorizeTool('ruview_spaces_list', {}, { source: 'mcp', grants: ['credential-use'] }).ok, true);
|
||||
assert.equal(authorizeTool('ruview_spaces_list', {}, { source: 'cli', grants: [] }).ok, true);
|
||||
});
|
||||
|
||||
test('Spaces schema never accepts raw credentials', async () => {
|
||||
for (const credential of [
|
||||
{ token: 'secret' },
|
||||
{ access_token: 'secret' },
|
||||
{ api_key: 'cog_secret' },
|
||||
{ authorization: 'Bearer secret' },
|
||||
{ base_url: 'https://attacker.example' },
|
||||
]) {
|
||||
const result = await runTool('ruview_spaces_list', credential);
|
||||
assert.equal(result.ok, false);
|
||||
assert.equal(result.reason, 'invalid_arguments');
|
||||
}
|
||||
});
|
||||
|
||||
112
harness/ruview/test/spaces.test.mjs
Normal file
112
harness/ruview/test/spaces.test.mjs
Normal file
@@ -0,0 +1,112 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { listCognitumSpaces, parseSpacesOutput } from '../src/spaces.js';
|
||||
import { runTool } from '../src/tools.js';
|
||||
|
||||
function validResponse() {
|
||||
return {
|
||||
object: 'list',
|
||||
data: [{
|
||||
id: 'room-1', tenantId: 'tenant-1', workspaceId: 'workspace-1', siteId: 'site-1', name: 'Room',
|
||||
version: 1, privacy: 'P2', status: 'live', connection: 'connected',
|
||||
state: { occupancy: 1, confidence: 0.9, observedAt: null, freshnessMs: 5, classification: 'P2', uncertainty: null, evidence: [] },
|
||||
provenance: {}, hardware: {}, dataBoundary: {}, observedAt: null, expiresAt: null,
|
||||
}],
|
||||
boundary: {
|
||||
authoritativeState: 'HomeCore Edge',
|
||||
cloudRole: 'tenant-scoped semantic synchronization',
|
||||
excluded: ['raw_csi', 'cir', 'rf_tensors', 'recordings', 'pose_frames', 'vital_waveforms', 'identity_observations'],
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
test('Spaces adapter invokes OAuth-only CLI args in a scrubbed environment', async () => {
|
||||
const credentialPath = 'C:/private/ruview-credentials.json';
|
||||
const secretApiKey = 'cog_DO_NOT_FORWARD';
|
||||
let observed;
|
||||
const result = await listCognitumSpaces(
|
||||
{ credentials_path: credentialPath },
|
||||
{
|
||||
source: 'cli',
|
||||
binary: 'wifi-densepose-test-double',
|
||||
env: { PATH: 'test-path', COGNITUM_SPACES_API: secretApiKey, RUVIEW_CREDENTIALS_PATH: credentialPath },
|
||||
execute: async (command, args, options) => {
|
||||
observed = { command, args, options };
|
||||
return { stdout: JSON.stringify(validResponse()), stderr: '', code: 0 };
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
assert.equal(result.ok, true);
|
||||
assert.equal(result.authentication, 'oauth');
|
||||
assert.equal(result.count, 1);
|
||||
assert.equal(observed.command, 'wifi-densepose-test-double');
|
||||
assert.deepEqual(observed.args, [
|
||||
'spaces', '--json', '--base-url', 'https://api.cognitum.one', '--credentials-path', credentialPath,
|
||||
]);
|
||||
assert.ok(observed.options.envAllowlist.includes('RUVIEW_CREDENTIALS_PATH'));
|
||||
assert.ok(!observed.options.envAllowlist.includes('COGNITUM_SPACES_API'));
|
||||
assert.ok(!observed.args.join(' ').includes(secretApiKey));
|
||||
});
|
||||
|
||||
test('MCP cannot select an arbitrary credential path even with a credential-use grant', async () => {
|
||||
const result = await runTool(
|
||||
'ruview_spaces_list',
|
||||
{ credentials_path: 'C:/private/credentials.json' },
|
||||
{ source: 'mcp', grants: ['credential-use'] },
|
||||
);
|
||||
assert.equal(result.ok, false);
|
||||
assert.equal(result.reason, 'credentials_path_not_allowed');
|
||||
});
|
||||
|
||||
test('MCP denies a Spaces read before touching local credentials or the network', async () => {
|
||||
const result = await runTool('ruview_spaces_list', {}, { source: 'mcp', grants: [] });
|
||||
assert.equal(result.ok, false);
|
||||
assert.equal(result.reason, 'authority_denied');
|
||||
assert.equal(result.requiredGrant, 'credential-use');
|
||||
});
|
||||
|
||||
test('metaharness rejects forbidden raw fields from a child process', () => {
|
||||
const response = validResponse();
|
||||
response.data[0].state.raw_csi = [1, 2, 3];
|
||||
assert.throws(() => parseSpacesOutput(JSON.stringify(response)), /forbidden raw field/i);
|
||||
});
|
||||
|
||||
test('metaharness rejects incomplete privacy boundaries and invalid confidence', () => {
|
||||
const incomplete = validResponse();
|
||||
incomplete.boundary.excluded = ['raw_csi'];
|
||||
assert.throws(() => parseSpacesOutput(JSON.stringify(incomplete)), /incomplete edge privacy boundary/i);
|
||||
|
||||
const invalid = validResponse();
|
||||
invalid.data[0].state.confidence = 2;
|
||||
assert.throws(() => parseSpacesOutput(JSON.stringify(invalid)), /invalid confidence/i);
|
||||
});
|
||||
|
||||
test('command failures redact API keys and JWT-shaped tokens', async () => {
|
||||
const secret = 'cog_SUPER_SECRET_VALUE';
|
||||
const jwt = 'eyJhbGciOiJFUzI1NiJ9.eyJzdWIiOiJ1c2VyLTEifQ.signature-material';
|
||||
const result = await listCognitumSpaces({}, {
|
||||
source: 'cli',
|
||||
binary: 'wifi-densepose-test-double',
|
||||
env: { PATH: 'test-path', COGNITUM_SPACES_API: secret },
|
||||
execute: async () => { throw new Error(`failed token=${jwt} api_key=${secret}`); },
|
||||
});
|
||||
assert.equal(result.ok, false);
|
||||
assert.ok(!result.detail.includes(secret));
|
||||
assert.ok(!result.detail.includes(jwt));
|
||||
assert.match(result.detail, /REDACTED/);
|
||||
});
|
||||
|
||||
test('credentialed calls never fall back to Cargo build scripts', async () => {
|
||||
let executed = false;
|
||||
const result = await listCognitumSpaces({}, {
|
||||
source: 'cli',
|
||||
cargo: 'cargo',
|
||||
repoRoot: 'C:/trusted/ruview',
|
||||
execute: async () => { executed = true; },
|
||||
});
|
||||
assert.equal(result.ok, false);
|
||||
assert.equal(result.reason, 'cli_missing');
|
||||
assert.equal(executed, false);
|
||||
});
|
||||
@@ -93,7 +93,7 @@ test('summarize gives PASS/finding text', () => {
|
||||
|
||||
test('registry exposes the documented tools with schemas (underscore-canonical)', () => {
|
||||
const names = Object.keys(TOOLS);
|
||||
for (const n of ['ruview_onboard', 'ruview_claim_check', 'ruview_verify', 'ruview_node_monitor', 'ruview_calibrate', 'ruview_node_flash', 'ruview_guidance', 'ruview_memory_search']) {
|
||||
for (const n of ['ruview_onboard', 'ruview_claim_check', 'ruview_verify', 'ruview_node_monitor', 'ruview_calibrate', 'ruview_node_flash', 'ruview_guidance', 'ruview_spaces_list', 'ruview_memory_search']) {
|
||||
assert.ok(names.includes(n), `missing ${n}`);
|
||||
assert.equal(TOOLS[n].inputSchema.type, 'object');
|
||||
assert.match(n, /^[a-zA-Z0-9_-]{1,64}$/, 'canonical names must satisfy host tool-name regexes');
|
||||
|
||||
Reference in New Issue
Block a user