97 lines
4.3 KiB
JavaScript
97 lines
4.3 KiB
JavaScript
import { readFileSync } from "node:fs";
|
|
import { join } from "node:path";
|
|
import { describe, expect, it } from "vitest";
|
|
|
|
import {
|
|
inferEdgeGatewayErrorCode,
|
|
normalizeEdgeGatewayError,
|
|
redactEdgeGatewayDiagnostic,
|
|
redactEdgeGatewayUrl,
|
|
} from "@/features/edgeGateways/edgeGatewayErrors.js";
|
|
|
|
const managerSource = readFileSync(join(process.cwd(), "src/features/edgeGateways/EdgeGatewayManager.vue"), "utf8");
|
|
const tasksSource = readFileSync(join(process.cwd(), "src/features/edgeGateways/EdgeGatewayTasksPage.vue"), "utf8");
|
|
const manageSource = readFileSync(join(process.cwd(), "src/features/edgeGateways/EdgeGatewayManagePage.vue"), "utf8");
|
|
|
|
describe("edge gateway workflow helpers", () => {
|
|
it("exposes v2 tabs, terminal routing, and management actions", () => {
|
|
expect(managerSource).toContain('id: "overview"');
|
|
expect(managerSource).toContain('id: "inventory"');
|
|
expect(managerSource).toContain('id: "tasks"');
|
|
expect(managerSource).toContain('id: "logs"');
|
|
expect(managerSource).toContain('id: "statistics"');
|
|
expect(managerSource).toContain('id: "terminal"');
|
|
expect(managerSource).toContain('id: "settings"');
|
|
expect(managerSource).toContain("`gateway-tab-${tab.id}`");
|
|
expect(tasksSource).toContain('data-testid="gateway-tasks-page"');
|
|
expect(tasksSource).toContain('data-testid="gateway-operation-update"');
|
|
expect(tasksSource).toContain('data-testid="gateway-operation-uninstall"');
|
|
expect(tasksSource).toContain('data-testid="gateway-operation-cancel"');
|
|
expect(tasksSource).toContain('data-testid="gateway-operation-retry"');
|
|
expect(manageSource).toContain('data-testid="gateway-rotate-credentials"');
|
|
expect(managerSource).toContain("EdgeGatewayTerminalPage");
|
|
expect(managerSource).toContain("EdgeGatewayManagePage");
|
|
expect(managerSource).toContain('data-testid="edge-gateway-workspace"');
|
|
});
|
|
|
|
it("maps structured edge gateway errors into UI copy", () => {
|
|
expect(inferEdgeGatewayErrorCode({ response: { data: { data: { error_code: "EDGE_GATEWAY_CONFLICT" } } } })).toBe(
|
|
"EDGE_GATEWAY_CONFLICT"
|
|
);
|
|
|
|
const normalized = normalizeEdgeGatewayError({
|
|
response: {
|
|
data: {
|
|
data: {
|
|
error_code: "EDGE_GATEWAY_INVALID_TOKEN",
|
|
message: "Invalid edge gateway token",
|
|
},
|
|
},
|
|
},
|
|
});
|
|
|
|
expect(normalized.code).toBe("EDGE_GATEWAY_INVALID_TOKEN");
|
|
expect(normalized.title).toMatch(/legitimationsoplysninger/i);
|
|
expect(normalized.message).toContain("Invalid edge gateway token");
|
|
});
|
|
it("redacts broker diagnostic secrets before rendering technical details", () => {
|
|
expect(
|
|
redactEdgeGatewayUrl(
|
|
"https://brokerUser:brokerPass@broker.internal/socket?access_token=ACCESSSECRET&signature=SIGSECRET&token=BROKER_TOKEN"
|
|
)
|
|
).toBe("https://***:***@broker.internal/socket?access_token=***&signature=***&token=***");
|
|
|
|
expect(
|
|
redactEdgeGatewayDiagnostic(
|
|
"authorization=Bearer LASTERRSECRET url=https://u:p@broker.internal/?jwt=ERRJWT signed_url=https://host/path?signature=DISCSIG&key=DISCKEY"
|
|
)
|
|
).not.toMatch(/LASTERRSECRET|ERRJWT|DISCSIG|DISCKEY|u:p/);
|
|
|
|
const normalized = normalizeEdgeGatewayError({
|
|
response: {
|
|
data: {
|
|
data: {
|
|
diagnostics: {
|
|
broker_url:
|
|
"https://brokerUser:brokerPass@broker.internal/socket?access_token=ACCESSSECRET&signature=SIGSECRET&token=BROKER_TOKEN",
|
|
relay_url: "https://agentUser:agentPass@gw.internal/relay?token=RELAY_TOKEN&jwt=JWTSECRET",
|
|
broker_presence: {
|
|
last_error:
|
|
"poll failed authorization=Bearer LASTERRSECRET url=https://u:p@broker.internal/?jwt=ERRJWT",
|
|
disconnect_reason: "disconnect signed_url=https://host/path?signature=DISCSIG&key=DISCKEY",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
});
|
|
|
|
const details = normalized.details.join("\n");
|
|
expect(details).toContain("Broker URL: https://***:***@broker.internal/socket?access_token=***");
|
|
expect(details).toContain("Relay URL: https://***:***@gw.internal/relay?token=***&jwt=***");
|
|
expect(details).not.toMatch(
|
|
/brokerUser|brokerPass|ACCESSSECRET|SIGSECRET|BROKER_TOKEN|agentUser|agentPass|RELAY_TOKEN|JWTSECRET|LASTERRSECRET|ERRJWT|DISCSIG|DISCKEY|u:p/
|
|
);
|
|
});
|
|
});
|