fix(ui): preserve Attack Paths context scope

This commit is contained in:
alejandrobailo
2026-07-21 18:13:10 +02:00
parent 1725391b84
commit 94f52a2593
3 changed files with 16 additions and 2 deletions
@@ -412,6 +412,7 @@ export default function AttackPathsPage() {
>;
const lighthouseContext = scanId
? buildAttackPathContext({
pathname,
scanId,
queryId: queryBuilder.selectedQuery,
queryLabel: queryBuilder.selectedQueryData?.attributes.name,
@@ -144,6 +144,7 @@ describe("Lighthouse page contributions", () => {
it("builds an attack-path snapshot and excludes unsafe query parameters", () => {
expect(
buildAttackPathContext({
pathname: "/attack-paths/query-builder",
scanId: "scan-1",
queryId: "internet-exposed",
queryLabel: "Internet exposed resources",
@@ -162,7 +163,7 @@ describe("Lighthouse page contributions", () => {
kind: "attack_path",
id: "current-query",
source: "automatic",
scopeKey: "attack-paths:/attack-paths",
scopeKey: "attack-paths:/attack-paths/query-builder",
label: "Internet exposed resources",
scanId: "scan-1",
queryId: "internet-exposed",
@@ -178,6 +179,17 @@ describe("Lighthouse page contributions", () => {
});
});
it("builds an attack-path scope from the current route", () => {
// Given / When
const context = buildAttackPathContext({
pathname: "/attack-paths",
scanId: "scan-1",
});
// Then
expect(context.scopeKey).toBe("attack-paths:/attack-paths");
});
it("builds scan summary and selected scan snapshots", () => {
expect(buildScanSummaryContext(9, "completed")).toEqual({
kind: "scan",
+2 -1
View File
@@ -64,6 +64,7 @@ interface ComplianceContextInput {
}
interface AttackPathContextInput {
pathname: string;
scanId: string;
queryId?: string | null;
queryLabel?: string;
@@ -211,7 +212,7 @@ export function buildAttackPathContext(
kind: LIGHTHOUSE_CONTEXT_KIND.ATTACK_PATH,
id: input.queryId ? "current-query" : "current-scan",
source: LIGHTHOUSE_CONTEXT_SOURCE.AUTOMATIC,
scopeKey: getLighthouseScopeKey("/attack-paths"),
scopeKey: getLighthouseScopeKey(input.pathname),
label: toBoundedString(input.queryLabel || "Selected attack-path scan"),
scanId: toBoundedString(input.scanId),
queryId: optionalBoundedString(input.queryId ?? undefined),