65 lines
2.2 KiB
JavaScript
65 lines
2.2 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
|
|
import { AUDIT_FIELD_NAMES } from "../audit/index.mjs";
|
|
import { ERROR_CODES, validateResponse } from "../protocol/index.mjs";
|
|
import { handleJsonRpcRequest } from "./json-rpc.mjs";
|
|
|
|
test("unknown JSON-RPC method returns an error envelope with audit fields", async () => {
|
|
const response = await handleJsonRpcRequest({
|
|
jsonrpc: "2.0",
|
|
id: "req_01J00000000000000000000000",
|
|
method: "hardware.operation.cancel",
|
|
params: {
|
|
operationId: "op_01J00000000000000000000000"
|
|
},
|
|
meta: {
|
|
traceId: "trc_01J00000000000000000000000",
|
|
actorId: "usr_01J00000000000000000000000",
|
|
serviceId: "hwlab-cloud-web",
|
|
environment: "dev"
|
|
}
|
|
});
|
|
|
|
validateResponse(response);
|
|
assert.equal(response.error.code, ERROR_CODES.methodNotFound);
|
|
assert.equal(Object.hasOwn(response, "result"), false);
|
|
|
|
const audit = response.error.data.audit;
|
|
for (const field of AUDIT_FIELD_NAMES) {
|
|
assert.ok(Object.hasOwn(audit, field), `expected audit.${field}`);
|
|
}
|
|
assert.equal(audit.requestId, "req_01J00000000000000000000000");
|
|
assert.equal(audit.actor.id, "usr_01J00000000000000000000000");
|
|
assert.equal(audit.operation, "hardware.operation.cancel");
|
|
assert.equal(audit.target.type, "rpc_method");
|
|
assert.equal(audit.result, "rejected");
|
|
});
|
|
|
|
test("hardware.operation.request is a non-dispatching skeleton with visible audit fields", async () => {
|
|
const response = await handleJsonRpcRequest({
|
|
jsonrpc: "2.0",
|
|
id: "req_01J00000000000000000000001",
|
|
method: "hardware.operation.request",
|
|
params: {
|
|
projectId: "prj_01J00000000000000000000000"
|
|
},
|
|
meta: {
|
|
traceId: "trc_01J00000000000000000000001",
|
|
actorId: "usr_01J00000000000000000000000",
|
|
serviceId: "hwlab-cloud-web",
|
|
environment: "dev"
|
|
}
|
|
});
|
|
|
|
validateResponse(response);
|
|
assert.equal(response.result.accepted, false);
|
|
assert.equal(response.result.status, "skeleton");
|
|
|
|
for (const field of AUDIT_FIELD_NAMES) {
|
|
assert.ok(Object.hasOwn(response.result.audit, field), `expected audit.${field}`);
|
|
}
|
|
assert.equal(response.result.audit.operation, "hardware.operation.request");
|
|
assert.equal(response.result.audit.target.id, "prj_01J00000000000000000000000");
|
|
});
|