feat(device-core): expose safe project control views
This commit is contained in:
@@ -59,9 +59,26 @@ test("project workspace returns only masked identity projections", async () => {
|
||||
assert.equal(workspace.devices[0].identifier.masked, "***********0001");
|
||||
assert.equal(workspace.discoveries[0].identifier.masked, "***********0001");
|
||||
assert.equal(workspace.enrollments[0].expectedIdentifier.masked, "***********0001");
|
||||
assert.equal(
|
||||
workspace.enrollments[0].enrollmentIntentRef,
|
||||
"enrollment-intent:77777777-7777-4777-8777-777777777777",
|
||||
);
|
||||
assert.equal(workspace.adapterPackages[0].packageKey, "generic-tracker");
|
||||
assert.equal(workspace.modelProfiles[0].modelProfileRef, "vendor.model.v1");
|
||||
assert.equal(workspace.routes[0].activeSessionCount, 1);
|
||||
assert.equal(workspace.sessions[0].frameCount, 12);
|
||||
assert.equal(workspace.bindings[0].lifecycleState, "pending_external_approval");
|
||||
assert.equal(workspace.configurationRevisions[0].revisionNumber, 1);
|
||||
assert.equal(workspace.commands[0].lifecycleState, "acknowledged");
|
||||
assert.equal(workspace.auditEvents[0].eventType, "device.observed");
|
||||
assert.equal(workspace.grants[0].principalRef, "user:device-admin");
|
||||
assert.equal(workspace.policies.commandTransport, "disabled");
|
||||
const serialized = JSON.stringify(workspace);
|
||||
assert.equal(serialized.includes("hmac-sha256"), false);
|
||||
assert.equal(serialized.includes("ndc-credref"), false);
|
||||
assert.equal(serialized.includes("transport-message-secret"), false);
|
||||
assert.equal(serialized.includes("external-approval-proof"), false);
|
||||
assert.equal(serialized.includes("raw-audit-payload"), false);
|
||||
});
|
||||
|
||||
test("project read source never selects identifier digests or credential refs", async () => {
|
||||
@@ -71,8 +88,9 @@ test("project read source never selects identifier digests or credential refs",
|
||||
);
|
||||
assert.doesNotMatch(
|
||||
source,
|
||||
/\b(?:identifier_digest|expected_identifier_digest|credential_ref)\b/,
|
||||
/\b(?:identifier_digest|expected_identifier_digest|credential_ref|parameters_digest|parameters_projection|transport_message_ref|external_approval_ref|external_approval_digest)\b/,
|
||||
);
|
||||
assert.doesNotMatch(source, /\b(?:dae\.payload|dcr\.configuration)\b/);
|
||||
});
|
||||
|
||||
function workspaceClient() {
|
||||
@@ -86,7 +104,174 @@ function workspaceClient() {
|
||||
grantReads += 1;
|
||||
return { rows: [storedGrantRow()] };
|
||||
}
|
||||
if (/from device_instances di/.test(sql)) {
|
||||
if (/from device_adapter_packages ap/.test(sql)) {
|
||||
return { rows: [{
|
||||
id: "99999999-9999-4999-8999-999999999999",
|
||||
package_key: "generic-tracker",
|
||||
display_name: "Generic tracker",
|
||||
publisher_ref: "publisher:nodedc",
|
||||
lifecycle_state: "active",
|
||||
created_at: timestamp,
|
||||
updated_at: timestamp,
|
||||
}] };
|
||||
}
|
||||
if (/from device_adapter_versions av/.test(sql)) {
|
||||
return { rows: [{
|
||||
id: "aaaaaaaa-aaaa-4aaa-8aaa-aaaaaaaaaaaa",
|
||||
adapter_package_id: "99999999-9999-4999-8999-999999999999",
|
||||
version: "1.0.0",
|
||||
runtime_package_ref: "artifact:generic-tracker:1.0.0",
|
||||
content_digest: `sha256:${"a".repeat(64)}`,
|
||||
contract_version: "device-adapter.v1",
|
||||
capabilities: ["telemetry"],
|
||||
lifecycle_state: "active",
|
||||
created_at: timestamp,
|
||||
updated_at: timestamp,
|
||||
}] };
|
||||
}
|
||||
if (/from device_model_profiles dmp/.test(sql)) {
|
||||
return { rows: [{
|
||||
profile_ref: "vendor.model.v1",
|
||||
adapter_version_id: "aaaaaaaa-aaaa-4aaa-8aaa-aaaaaaaaaaaa",
|
||||
schema_version: "1.0.0",
|
||||
vendor: "Vendor",
|
||||
model: "Model",
|
||||
device_type: "tracker",
|
||||
protocol: "INTERNAL",
|
||||
schema_artifact_ref: "schema:vendor.model.v1",
|
||||
profile_digest: `sha256:${"b".repeat(64)}`,
|
||||
capabilities: ["telemetry"],
|
||||
lifecycle_state: "active",
|
||||
created_at: timestamp,
|
||||
updated_at: timestamp,
|
||||
}] };
|
||||
}
|
||||
if (/from device_edges de/.test(sql)) {
|
||||
return { rows: [{
|
||||
id: "bbbbbbbb-bbbb-4bbb-8bbb-bbbbbbbbbbbb",
|
||||
edge_key: "edge-one",
|
||||
display_name: "Edge one",
|
||||
deployment_ref: "deployment:edge-one",
|
||||
lifecycle_state: "active",
|
||||
created_at: timestamp,
|
||||
updated_at: timestamp,
|
||||
}] };
|
||||
}
|
||||
if (/from device_routes dr/.test(sql)) {
|
||||
return { rows: [{
|
||||
id: "cccccccc-cccc-4ccc-8ccc-cccccccccccc",
|
||||
route_key: "route-one",
|
||||
display_name: "Route one",
|
||||
edge_id: "bbbbbbbb-bbbb-4bbb-8bbb-bbbbbbbbbbbb",
|
||||
edge_name: "Edge one",
|
||||
model_profile_ref: "vendor.model.v1",
|
||||
profile_vendor: "Vendor",
|
||||
profile_model: "Model",
|
||||
listener_ref: "listener:generic",
|
||||
protocol: "INTERNAL",
|
||||
direction: "bidirectional",
|
||||
lifecycle_state: "active",
|
||||
session_count: "1",
|
||||
active_session_count: "1",
|
||||
created_at: timestamp,
|
||||
updated_at: timestamp,
|
||||
}] };
|
||||
}
|
||||
if (/select ds\.id, ds\.route_id, dr\.display_name/.test(sql)) {
|
||||
return { rows: [{
|
||||
id: "dddddddd-dddd-4ddd-8ddd-dddddddddddd",
|
||||
route_id: "cccccccc-cccc-4ccc-8ccc-cccccccccccc",
|
||||
route_name: "Route one",
|
||||
device_id: "44444444-4444-4444-8444-444444444444",
|
||||
device_name: "Pilot device",
|
||||
protocol: "INTERNAL",
|
||||
lifecycle_state: "online",
|
||||
connected_at: timestamp,
|
||||
last_seen_at: timestamp,
|
||||
disconnected_at: null,
|
||||
close_reason_code: null,
|
||||
frame_count: "12",
|
||||
byte_count: "1024",
|
||||
}] };
|
||||
}
|
||||
if (/from device_resource_bindings drb/.test(sql)) {
|
||||
return { rows: [{
|
||||
id: "eeeeeeee-eeee-4eee-8eee-eeeeeeeeeeee",
|
||||
binding_key: "foundry-map",
|
||||
display_name: "Foundry map",
|
||||
source_kind: "collection",
|
||||
device_id: null,
|
||||
collection_id: "55555555-5555-4555-8555-555555555555",
|
||||
source_name: "Pilot fleet",
|
||||
target_kind: "foundry.application",
|
||||
target_ref: "application:pilot-map",
|
||||
capabilities: ["observe"],
|
||||
lifecycle_state: "pending_external_approval",
|
||||
source_approved_at: timestamp,
|
||||
external_approval_ref: "external-approval-proof",
|
||||
created_at: timestamp,
|
||||
updated_at: timestamp,
|
||||
}] };
|
||||
}
|
||||
if (/from device_configuration_revisions dcr/.test(sql)) {
|
||||
return { rows: [{
|
||||
id: "ffffffff-ffff-4fff-8fff-ffffffffffff",
|
||||
device_id: "44444444-4444-4444-8444-444444444444",
|
||||
device_name: "Pilot device",
|
||||
revision_number: "1",
|
||||
model_profile_ref: "vendor.model.v1",
|
||||
schema_artifact_ref: "schema:vendor.model.v1",
|
||||
configuration_digest: `sha256:${"c".repeat(64)}`,
|
||||
configuration: { raw: "must-not-leak" },
|
||||
change_summary: "Pilot configuration",
|
||||
created_at: timestamp,
|
||||
}] };
|
||||
}
|
||||
if (/from device_configuration_state dcs/.test(sql)) {
|
||||
return { rows: [{
|
||||
device_id: "44444444-4444-4444-8444-444444444444",
|
||||
device_name: "Pilot device",
|
||||
desired_revision_id: "ffffffff-ffff-4fff-8fff-ffffffffffff",
|
||||
applied_revision_id: null,
|
||||
applied_at: null,
|
||||
updated_at: timestamp,
|
||||
}] };
|
||||
}
|
||||
if (/from device_commands dc/.test(sql)) {
|
||||
return { rows: [{
|
||||
id: "12121212-1212-4121-8121-121212121212",
|
||||
device_id: "44444444-4444-4444-8444-444444444444",
|
||||
device_name: "Pilot device",
|
||||
command_key: "safe-ping",
|
||||
command_catalog_ref: "catalog:safe-ping:v1",
|
||||
command_type: "device.ping",
|
||||
risk_class: "low",
|
||||
lifecycle_state: "acknowledged",
|
||||
planned_at: timestamp,
|
||||
expires_at: "2026-08-11T00:00:00.000Z",
|
||||
confirmed_at: timestamp,
|
||||
dispatched_at: timestamp,
|
||||
acknowledged_at: timestamp,
|
||||
terminal_at: null,
|
||||
terminal_reason_code: null,
|
||||
transport_message_ref: "transport-message-secret",
|
||||
parameters_projection: { raw: "must-not-leak" },
|
||||
created_at: timestamp,
|
||||
updated_at: timestamp,
|
||||
}] };
|
||||
}
|
||||
if (/from device_audit_events dae/.test(sql)) {
|
||||
return { rows: [{
|
||||
id: "13131313-1313-4131-8131-131313131313",
|
||||
event_type: "device.observed",
|
||||
actor_ref: "user:device-admin",
|
||||
device_id: "44444444-4444-4444-8444-444444444444",
|
||||
discovery_id: "66666666-6666-4666-8666-666666666666",
|
||||
occurred_at: timestamp,
|
||||
payload: { raw: "raw-audit-payload" },
|
||||
}] };
|
||||
}
|
||||
if (/from device_instances di\n left join lateral/.test(sql)) {
|
||||
return { rows: [{
|
||||
id: "44444444-4444-4444-8444-444444444444",
|
||||
device_key: "pilot-device",
|
||||
|
||||
Reference in New Issue
Block a user