@dataparade/cli 0.0.35 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/package.json +4 -4
- package/dist/src/ai-enrichment/pii-signal-rules.d.ts +5 -0
- package/dist/src/ai-enrichment/pii-signal-rules.js +2 -3
- package/dist/src/ai-enrichment/provider-prompt.js +1 -0
- package/dist/src/ai-enrichment/providers/provider-contract.js +2 -44
- package/dist/src/ai-enrichment/third-party-data-flow.js +5 -4
- package/dist/src/cli.js +9 -3
- package/dist/src/discoveries/contract/ocsf-discovery-record.d.ts +4 -1
- package/dist/src/discoveries/contract/ocsf-discovery-record.js +1 -1
- package/dist/src/discoveries/contract/ontology-pins.d.ts +6 -4
- package/dist/src/discoveries/contract/ontology-pins.js +7 -5
- package/dist/src/facts/build-facts.d.ts +2 -0
- package/dist/src/facts/build-facts.js +18 -0
- package/dist/src/facts/layout.d.ts +4 -0
- package/dist/src/facts/layout.js +5 -1
- package/dist/src/facts/scan-stamps.d.ts +7 -0
- package/dist/src/facts/scan-stamps.js +30 -0
- package/dist/src/facts/schema.d.ts +178 -0
- package/dist/src/facts/schema.js +37 -1
- package/dist/src/kb/data-category-catalog.generated.d.ts +34 -0
- package/dist/src/kb/data-category-catalog.generated.js +962 -0
- package/dist/src/kb/kb-store.js +4 -1
- package/dist/src/kb/migrate.js +4 -2
- package/dist/src/kb/slot-shapes.d.ts +3 -2
- package/dist/src/kb/slot-shapes.js +13 -8
- package/dist/src/kb/taxonomy.d.ts +12 -6
- package/dist/src/kb/taxonomy.js +13 -18
- package/dist/src/output/scan-output-excludes.js +2 -0
- package/dist/src/output/write-scan-knowledge.d.ts +5 -1
- package/dist/src/output/write-scan-knowledge.js +21 -0
- package/dist/src/threat-model/build-threat-model.d.ts +3 -0
- package/dist/src/threat-model/build-threat-model.js +71 -0
- package/dist/src/threat-model/carry-forward-person-set-statuses.d.ts +8 -0
- package/dist/src/threat-model/carry-forward-person-set-statuses.js +87 -0
- package/dist/src/threat-model/io.d.ts +19 -0
- package/dist/src/threat-model/io.js +63 -0
- package/dist/src/threat-model/schema.d.ts +214 -0
- package/dist/src/threat-model/schema.js +75 -0
- package/dist/src/ui/scan-progress-renderer.d.ts +8 -1
- package/dist/src/ui/scan-progress-renderer.js +20 -1
- package/dist/src/upload/collect-scan-sidecars.d.ts +2 -1
- package/dist/src/upload/collect-scan-sidecars.js +3 -1
- package/dist/tests/cli/cli.spec.js +10 -1
- package/dist/tests/helpers/facts-fixture.js +16 -16
- package/dist/tests/schema/scan-result.schema.spec.js +1 -1
- package/dist/tests/unit/ai-enrichment/provider-contract.spec.js +1 -1
- package/dist/tests/unit/ai-enrichment/third-party-data-flow.spec.js +5 -5
- package/dist/tests/unit/core/graph-mapping.spec.js +4 -3
- package/dist/tests/unit/discoveries/write-ocsf-discoveries-long-ids.spec.js +3 -3
- package/dist/tests/unit/export/export-ocsf.spec.js +4 -4
- package/dist/tests/unit/facts/apply-answers.spec.js +20 -20
- package/dist/tests/unit/facts/build-facts.spec.js +143 -45
- package/dist/tests/unit/facts/identity.spec.js +13 -0
- package/dist/tests/unit/facts/scan-stamps.spec.js +32 -0
- package/dist/tests/unit/facts/slug.spec.js +2 -0
- package/dist/tests/unit/kb/answer-fingerprint.spec.js +9 -9
- package/dist/tests/unit/kb/data-category-catalog.spec.d.ts +1 -0
- package/dist/tests/unit/kb/data-category-catalog.spec.js +65 -0
- package/dist/tests/unit/kb/kb-interview-loop.spec.js +8 -7
- package/dist/tests/unit/kb/migrate.spec.js +2 -2
- package/dist/tests/unit/output/scan-output-excludes.spec.js +1 -1
- package/dist/tests/unit/threat-model/build-threat-model.spec.d.ts +1 -0
- package/dist/tests/unit/threat-model/build-threat-model.spec.js +189 -0
- package/dist/tests/unit/threat-model/carry-forward-person-set-statuses.spec.d.ts +1 -0
- package/dist/tests/unit/threat-model/carry-forward-person-set-statuses.spec.js +163 -0
- package/dist/tests/unit/threat-model/io.spec.d.ts +1 -0
- package/dist/tests/unit/threat-model/io.spec.js +103 -0
- package/dist/tests/unit/threat-model/schema.spec.d.ts +1 -0
- package/dist/tests/unit/threat-model/schema.spec.js +42 -0
- package/dist/tests/unit/ui/scan-progress-renderer.spec.js +58 -0
- package/dist/tests/unit/upload/collect-scan-sidecars.spec.js +8 -5
- package/dist/vendor/scanner/dist/src/analyze/code-navigator.d.ts +1 -1
- package/dist/vendor/scanner/dist/src/analyze/code-navigator.js +4 -0
- package/dist/vendor/scanner/dist/src/analyze/column-catalog.d.ts +1 -1
- package/dist/vendor/scanner/dist/src/analyze/column-catalog.js +2 -2
- package/dist/vendor/scanner/dist/src/analyze/concept-profile.d.ts +2 -2
- package/dist/vendor/scanner/dist/src/analyze/concept-profile.js +5 -3
- package/dist/vendor/scanner/dist/src/core/pipeline/build-scan-personal-data-layers.js +1 -1
- package/dist/vendor/scanner/dist/src/core/pipeline/deterministic-scan.js +43 -0
- package/dist/vendor/scanner/dist/src/core/pipeline/graph-mapping.js +23 -2
- package/dist/vendor/scanner/dist/src/core/pipeline/mixed-app-terraform-scan.js +1 -0
- package/dist/vendor/scanner/dist/src/core/pipeline/orchestrator-result.d.ts +2 -2
- package/dist/vendor/scanner/dist/src/core/pipeline/terraform-minimal-services.js +1 -0
- package/dist/vendor/scanner/dist/src/core/schema/scan-result.schema.d.ts +160 -2
- package/dist/vendor/scanner/dist/src/core/schema/scan-result.schema.js +24 -0
- package/dist/vendor/scanner/dist/src/core/types/data-flow.d.ts +48 -0
- package/dist/vendor/scanner/dist/src/core/types/data-flow.js +53 -0
- package/dist/vendor/scanner/dist/src/data-flow/detect.js +1 -0
- package/dist/vendor/scanner/dist/src/data-flow/ensure-hub-linked-assets.js +1 -0
- package/dist/vendor/scanner/dist/src/data-flow/ensure-manifest-declared-flows.js +1 -0
- package/dist/vendor/scanner/dist/src/data-flow/flow-authentication.d.ts +30 -0
- package/dist/vendor/scanner/dist/src/data-flow/flow-authentication.js +277 -0
- package/dist/vendor/scanner/dist/src/data-flow/flow-builder.js +6 -0
- package/dist/vendor/scanner/dist/src/data-flow/flow-controls.d.ts +24 -0
- package/dist/vendor/scanner/dist/src/data-flow/flow-controls.js +238 -0
- package/dist/vendor/scanner/dist/src/data-flow/flow-data-categories.d.ts +22 -0
- package/dist/vendor/scanner/dist/src/data-flow/flow-data-categories.js +69 -0
- package/dist/vendor/scanner/dist/src/data-flow/flow-interaction-description.d.ts +13 -0
- package/dist/vendor/scanner/dist/src/data-flow/flow-interaction-description.js +263 -0
- package/dist/vendor/scanner/dist/src/data-flow/hub-link-policy.d.ts +2 -1
- package/dist/vendor/scanner/dist/src/data-flow/hub-link-policy.js +3 -0
- package/dist/vendor/scanner/dist/src/data-flow/human-interaction-channels.d.ts +37 -0
- package/dist/vendor/scanner/dist/src/data-flow/human-interaction-channels.js +483 -0
- package/dist/vendor/scanner/dist/src/data-flow/intra-component-lineage.d.ts +3 -0
- package/dist/vendor/scanner/dist/src/data-flow/intra-component-lineage.js +12 -17
- package/dist/vendor/scanner/dist/src/data-flow/terraform-flows.js +5 -1
- package/dist/vendor/scanner/dist/src/data-flow/transformation-patterns.d.ts +5 -1
- package/dist/vendor/scanner/dist/src/data-flow/transformation-patterns.js +17 -37
- package/dist/vendor/scanner/dist/src/eval/canonical/concept-map.d.ts +36 -5
- package/dist/vendor/scanner/dist/src/eval/canonical/concept-map.js +53 -60
- package/dist/vendor/scanner/dist/src/eval/canonical/graph/endpoints.js +2 -9
- package/dist/vendor/scanner/dist/src/eval/canonical/scanner/personal-data.js +10 -7
- package/dist/vendor/scanner/dist/src/graph/build-dataparade-graph.js +3 -1
- package/dist/vendor/scanner/dist/src/index.d.ts +6 -0
- package/dist/vendor/scanner/dist/src/index.js +16 -1
- package/dist/vendor/scanner/dist/src/patterns/engine.js +1 -0
- package/dist/vendor/scanner/dist/src/pii-signals/match-pii-signals.d.ts +1 -1
- package/dist/vendor/scanner/dist/src/pii-signals/match-pii-signals.js +2 -2
- package/dist/vendor/scanner/dist/src/pii-signals/occurrence-group.d.ts +3 -3
- package/dist/vendor/scanner/dist/src/pii-signals/occurrence-group.js +12 -11
- package/dist/vendor/scanner/dist/src/pii-signals/personal-data-taxonomy.d.ts +44 -0
- package/dist/vendor/scanner/dist/src/pii-signals/personal-data-taxonomy.js +167 -0
- package/dist/vendor/scanner/dist/src/pii-signals/pii-signal-aliases.js +43 -43
- package/dist/vendor/scanner/dist/src/pii-signals/pii-signal-rules.d.ts +12 -1
- package/dist/vendor/scanner/dist/src/pii-signals/pii-signal-rules.js +28 -7
- package/dist/vendor/scanner/dist/src/pii-signals/signal-token.js +1 -1
- package/dist/vendor/scanner/dist/src/threats/stride.d.ts +98 -0
- package/dist/vendor/scanner/dist/src/threats/stride.js +179 -0
- package/dist/vendor/scanner/package.json +2 -2
- package/dist/vendor/scanner/patterns/concept-profiles.yaml +2 -2
- package/dist/vendor/scanner/patterns/flow-authentication.rules.yaml +75 -0
- package/dist/vendor/scanner/patterns/flow-controls.rules.yaml +68 -0
- package/dist/vendor/scanner/patterns/personal-data-taxonomy.yaml +155 -0
- package/dist/vendor/scanner/patterns/pii-signals.rules.yaml +38 -49
- package/dist/vendor/scanner/patterns/stride.rules.yaml +86 -0
- package/package.json +4 -4
- package/dist/vendor/scanner/dist/src/eval/canonical/concept-map.validate.d.ts +0 -17
- package/dist/vendor/scanner/dist/src/eval/canonical/concept-map.validate.js +0 -108
- package/dist/vendor/scanner/patterns/personal-data-concept-map.yaml +0 -76
|
@@ -42,16 +42,16 @@ describe("applyAnswers", () => {
|
|
|
42
42
|
});
|
|
43
43
|
it("sets a data item in facts.json and in its file, and a group in both", () => {
|
|
44
44
|
const state = (0, apply_answers_1.applyAnswers)(facts, files, [
|
|
45
|
-
answer({ factId: "data_item:
|
|
46
|
-
answer({ factId: "group:
|
|
45
|
+
answer({ factId: "data_item:pd:EmailAddress", action: "set", property: "labels", value: ["contact", "pii"] }),
|
|
46
|
+
answer({ factId: "group:pd:EmailAddress:staff", action: "set", property: "label", value: "employees" }),
|
|
47
47
|
]);
|
|
48
48
|
expect(state.facts.dataItems[0].labels).toEqual(["contact", "pii"]);
|
|
49
49
|
expect(state.dataItemFiles[0].labels).toEqual(["contact", "pii"]);
|
|
50
|
-
expect(state.facts.dataItems[0].groups.find((g) => g.id === "group:
|
|
51
|
-
expect(state.dataItemFiles[0].groups.find((g) => g.id === "group:
|
|
50
|
+
expect(state.facts.dataItems[0].groups.find((g) => g.id === "group:pd:EmailAddress:staff")?.label).toBe("employees");
|
|
51
|
+
expect(state.dataItemFiles[0].groups.find((g) => g.id === "group:pd:EmailAddress:staff")?.label).toBe("employees");
|
|
52
52
|
});
|
|
53
53
|
it("sets a property of an occurrence", () => {
|
|
54
|
-
const state = (0, apply_answers_1.applyAnswers)(facts, files, [answer({ factId: "occurrence:
|
|
54
|
+
const state = (0, apply_answers_1.applyAnswers)(facts, files, [answer({ factId: "occurrence:pd:EmailAddress:src/a.ts:3", action: "set", property: "labels", value: ["verified"] })]);
|
|
55
55
|
expect(state.dataItemFiles[0].occurrences[0].labels).toEqual(["verified"]);
|
|
56
56
|
});
|
|
57
57
|
it("keeps answers about the system apart from Facts", () => {
|
|
@@ -80,35 +80,35 @@ describe("applyAnswers", () => {
|
|
|
80
80
|
const state = (0, apply_answers_1.applyAnswers)(facts, files, [answer({ factId: "cmp_mail", action: "remove" })]);
|
|
81
81
|
expect(state.facts.components.map((c) => c.id)).toEqual(["cmp_api", "cmp_user"]);
|
|
82
82
|
expect(state.facts.dataFlows.map((f) => f.id)).toEqual(["flow_login"]);
|
|
83
|
-
const staff = state.facts.dataItems[0].groups.find((g) => g.id === "group:
|
|
83
|
+
const staff = state.facts.dataItems[0].groups.find((g) => g.id === "group:pd:EmailAddress:staff");
|
|
84
84
|
expect(staff?.handledBy).toEqual(["cmp_api"]);
|
|
85
|
-
expect(state.dataItemFiles[0].groups.find((g) => g.id === "group:
|
|
85
|
+
expect(state.dataItemFiles[0].groups.find((g) => g.id === "group:pd:EmailAddress:staff")?.handledBy).toEqual(["cmp_api"]);
|
|
86
86
|
expect(state.facts.relations).toEqual([]);
|
|
87
87
|
});
|
|
88
88
|
it("drops a data item with its occurrences, its file and its entry in facts.json", () => {
|
|
89
|
-
const state = (0, apply_answers_1.applyAnswers)(facts, files, [answer({ factId: "data_item:
|
|
90
|
-
expect(state.facts.dataItems.map((i) => i.id)).toEqual(["data_item:
|
|
91
|
-
expect(state.dataItemFiles.map((f) => f.id)).toEqual(["data_item:
|
|
92
|
-
expect(state.facts.relations.some((r) => r.source.startsWith("group:
|
|
89
|
+
const state = (0, apply_answers_1.applyAnswers)(facts, files, [answer({ factId: "data_item:pd:EmailAddress", action: "remove" })]);
|
|
90
|
+
expect(state.facts.dataItems.map((i) => i.id)).toEqual(["data_item:pd:TelephoneNumber"]);
|
|
91
|
+
expect(state.dataItemFiles.map((f) => f.id)).toEqual(["data_item:pd:TelephoneNumber"]);
|
|
92
|
+
expect(state.facts.relations.some((r) => r.source.startsWith("group:pd:EmailAddress"))).toBe(false);
|
|
93
93
|
});
|
|
94
94
|
it("drops a group with its occurrences and fixes the counts", () => {
|
|
95
|
-
const state = (0, apply_answers_1.applyAnswers)(facts, files, [answer({ factId: "group:
|
|
96
|
-
expect(state.dataItemFiles[0].occurrences.map((o) => o.id)).toEqual(["occurrence:
|
|
95
|
+
const state = (0, apply_answers_1.applyAnswers)(facts, files, [answer({ factId: "group:pd:EmailAddress:customer", action: "remove" })]);
|
|
96
|
+
expect(state.dataItemFiles[0].occurrences.map((o) => o.id)).toEqual(["occurrence:pd:EmailAddress:src/c.ts:1"]);
|
|
97
97
|
expect(state.facts.dataItems[0].occurrenceCount).toBe(1);
|
|
98
|
-
expect(state.facts.dataItems[0].groups.map((g) => g.id)).toEqual(["group:
|
|
98
|
+
expect(state.facts.dataItems[0].groups.map((g) => g.id)).toEqual(["group:pd:EmailAddress:staff"]);
|
|
99
99
|
});
|
|
100
100
|
it("drops one occurrence and fixes the counts", () => {
|
|
101
|
-
const state = (0, apply_answers_1.applyAnswers)(facts, files, [answer({ factId: "occurrence:
|
|
101
|
+
const state = (0, apply_answers_1.applyAnswers)(facts, files, [answer({ factId: "occurrence:pd:EmailAddress:src/a.ts:3", action: "remove" })]);
|
|
102
102
|
expect(state.dataItemFiles[0].occurrences).toHaveLength(2);
|
|
103
103
|
expect(state.facts.dataItems[0].occurrenceCount).toBe(2);
|
|
104
|
-
expect(state.facts.dataItems[0].groups.find((g) => g.id === "group:
|
|
105
|
-
expect(state.dataItemFiles[0].groups.find((g) => g.id === "group:
|
|
104
|
+
expect(state.facts.dataItems[0].groups.find((g) => g.id === "group:pd:EmailAddress:customer")?.occurrenceCount).toBe(1);
|
|
105
|
+
expect(state.dataItemFiles[0].groups.find((g) => g.id === "group:pd:EmailAddress:customer")?.occurrenceCount).toBe(1);
|
|
106
106
|
});
|
|
107
107
|
it("is final: a later set about a removed Fact is ignored, also through its parent", () => {
|
|
108
108
|
const state = (0, apply_answers_1.applyAnswers)(facts, files, [
|
|
109
|
-
answer({ factId: "data_item:
|
|
110
|
-
answer({ factId: "data_item:
|
|
111
|
-
answer({ factId: "occurrence:
|
|
109
|
+
answer({ factId: "data_item:pd:TelephoneNumber", action: "remove" }),
|
|
110
|
+
answer({ factId: "data_item:pd:TelephoneNumber", action: "set", property: "labels", value: ["x"] }),
|
|
111
|
+
answer({ factId: "occurrence:pd:TelephoneNumber:src/a.ts:7", action: "set", property: "labels", value: ["x"] }),
|
|
112
112
|
]);
|
|
113
113
|
expect(state.ignored).toHaveLength(2);
|
|
114
114
|
expect(state.applied).toHaveLength(1);
|
|
@@ -25,13 +25,13 @@ function scanResult() {
|
|
|
25
25
|
files: [],
|
|
26
26
|
findings: [],
|
|
27
27
|
occurrences: [
|
|
28
|
-
{ id: "occurrence:
|
|
29
|
-
{ id: "occurrence:
|
|
30
|
-
{ id: `occurrence:
|
|
28
|
+
{ id: "occurrence:pd:EmailAddress:src/api.ts:4", filePath: "src/api.ts", startLine: 4, endLine: 4, code: "const email", labels: ["pd:EmailAddress"], group: "pd:EmailAddress:customer", groupBasis: "column", declaration: { line: 3, kind: "const" } },
|
|
29
|
+
{ id: "occurrence:pd:EmailAddress:src/api.ts:3", filePath: "src/api.ts", startLine: 3, endLine: 3, labels: [], group: "pd:EmailAddress:customer", groupBasis: "column" },
|
|
30
|
+
{ id: `occurrence:pd:EmailAddress:${ROOT}/src/abs.ts:9`, filePath: `${ROOT}/src/abs.ts`, startLine: 9, endLine: 9, labels: [] },
|
|
31
31
|
{ id: "occurrence:Credit Card:src/pay.ts:2", filePath: "src/pay.ts", startLine: 2, endLine: 2, labels: [], location: "comment" },
|
|
32
32
|
],
|
|
33
33
|
dataItems: [
|
|
34
|
-
{ id: "data_item:
|
|
34
|
+
{ id: "data_item:pd:EmailAddress", labels: ["pd:EmailAddress"], occurrenceIds: ["occurrence:pd:EmailAddress:src/api.ts:4", "occurrence:pd:EmailAddress:src/api.ts:3", `occurrence:pd:EmailAddress:${ROOT}/src/abs.ts:9`], groups: [{ id: "pd:EmailAddress:customer", occurrenceIds: ["occurrence:pd:EmailAddress:src/api.ts:4", "occurrence:pd:EmailAddress:src/api.ts:3"] }] },
|
|
35
35
|
{ id: "data_item:Credit Card", labels: [], occurrenceIds: ["occurrence:Credit Card:src/pay.ts:2"] },
|
|
36
36
|
],
|
|
37
37
|
};
|
|
@@ -44,14 +44,14 @@ function graph() {
|
|
|
44
44
|
graph: { schema: "dataparade-graph/1" },
|
|
45
45
|
nodes: [],
|
|
46
46
|
links: [
|
|
47
|
-
{ ...base, source: "dp::occurrence:
|
|
47
|
+
{ ...base, source: "dp::occurrence:pd:EmailAddress:src/api.ts:4", target: "src_api_ts_handler", relation: "occurs_in", target_kind: "function", target_file: "src/api.ts", target_line: 3 },
|
|
48
48
|
{ ...base, source: "dp::cmp_api", target: `${ROOT}/src/api.ts`, relation: "defined_in", target_kind: "file", target_file: `${ROOT}/src/api.ts`, target_line: 1 },
|
|
49
49
|
{ ...base, source: "dp::flow_mail", target: "src_api_ts_send", relation: "observed_in", target_kind: "function", target_file: "src/api.ts", target_line: 5 },
|
|
50
|
-
{ ...base, source: "dp::occurrence:
|
|
51
|
-
{ ...base, source: "dp::occurrence:
|
|
52
|
-
{ ...base, source: "dp::group:
|
|
53
|
-
{ ...base, source: "dp::group:
|
|
54
|
-
{ ...base, source: "dp::group:
|
|
50
|
+
{ ...base, source: "dp::occurrence:pd:EmailAddress:src/api.ts:4", target: "dp::occurrence:pd:EmailAddress:src/api.ts:3", relation: "declared_by", declaration_kind: "const" },
|
|
51
|
+
{ ...base, source: "dp::occurrence:pd:EmailAddress:src/api.ts:4", target: "dp::group:pd:EmailAddress:customer", relation: "occurrence_of" },
|
|
52
|
+
{ ...base, source: "dp::group:pd:EmailAddress:customer", target: "dp::data_item:pd:EmailAddress", relation: "part_of" },
|
|
53
|
+
{ ...base, source: "dp::group:pd:EmailAddress:customer", target: "dp::cmp_api", relation: "handled_by", confidence: "INFERRED", confidence_score: 0.65, basis: "same_file" },
|
|
54
|
+
{ ...base, source: "dp::group:pd:EmailAddress:customer", target: "dp::cmp_api", relation: "handled_by", confidence: "INFERRED", confidence_score: 0.65, basis: "same_file" },
|
|
55
55
|
{ ...base, source: "dp::cmp_api", target: "dp::flow_mail", relation: "sends" },
|
|
56
56
|
{ ...base, source: "dp::flow_mail", target: "dp::cmp_mail", relation: "delivers_to" },
|
|
57
57
|
],
|
|
@@ -82,45 +82,45 @@ describe("buildFacts", () => {
|
|
|
82
82
|
it("summarises data items with groups, and points to one file per item", () => {
|
|
83
83
|
expect(facts.dataItems.map((i) => [i.id, i.file, i.occurrenceCount])).toEqual([
|
|
84
84
|
["data_item:Credit Card", "data-items/credit-card.json", 1],
|
|
85
|
-
["data_item:
|
|
85
|
+
["data_item:pd:EmailAddress", "data-items/pd-emailaddress.json", 3],
|
|
86
86
|
]);
|
|
87
|
-
const email = facts.dataItems.find((i) => i.name === "
|
|
87
|
+
const email = facts.dataItems.find((i) => i.name === "pd:EmailAddress");
|
|
88
88
|
expect(email?.groups).toEqual([
|
|
89
89
|
{
|
|
90
|
-
id: "group:
|
|
91
|
-
identity: { kind: "group", key: "
|
|
90
|
+
id: "group:pd:EmailAddress:customer",
|
|
91
|
+
identity: { kind: "group", key: "pd:EmailAddress:customer", parts: { dataItem: "pd:EmailAddress", qualifier: "customer" } },
|
|
92
92
|
label: "customer",
|
|
93
93
|
basis: "column",
|
|
94
94
|
occurrenceCount: 2,
|
|
95
95
|
handledBy: ["cmp_api"],
|
|
96
96
|
},
|
|
97
97
|
]);
|
|
98
|
-
expect([...dataItemFiles.keys()].sort()).toEqual(["data-items/credit-card.json", "data-items/
|
|
98
|
+
expect([...dataItemFiles.keys()].sort()).toEqual(["data-items/credit-card.json", "data-items/pd-emailaddress.json"]);
|
|
99
99
|
});
|
|
100
100
|
it("puts every occurrence once, in its data item file, with group, code refs and declaration", () => {
|
|
101
|
-
const email = dataItemFiles.get("data-items/
|
|
102
|
-
expect(email?.groups).toEqual(facts.dataItems.find((i) => i.name === "
|
|
101
|
+
const email = dataItemFiles.get("data-items/pd-emailaddress.json");
|
|
102
|
+
expect(email?.groups).toEqual(facts.dataItems.find((i) => i.name === "pd:EmailAddress")?.groups);
|
|
103
103
|
expect(email?.occurrences.map((o) => o.id)).toEqual([
|
|
104
|
-
"occurrence:
|
|
105
|
-
"occurrence:
|
|
106
|
-
"occurrence:
|
|
104
|
+
"occurrence:pd:EmailAddress:src/abs.ts:9",
|
|
105
|
+
"occurrence:pd:EmailAddress:src/api.ts:3",
|
|
106
|
+
"occurrence:pd:EmailAddress:src/api.ts:4",
|
|
107
107
|
]);
|
|
108
|
-
const first = email?.occurrences.find((o) => o.id === "occurrence:
|
|
108
|
+
const first = email?.occurrences.find((o) => o.id === "occurrence:pd:EmailAddress:src/api.ts:4");
|
|
109
109
|
expect(first).toMatchObject({
|
|
110
|
-
groupId: "group:
|
|
110
|
+
groupId: "group:pd:EmailAddress:customer",
|
|
111
111
|
filePath: "src/api.ts",
|
|
112
112
|
code: "const email",
|
|
113
113
|
codeRefs: [{ nodeId: "src_api_ts_handler", kind: "function", filePath: "src/api.ts", line: 3 }],
|
|
114
|
-
declaredBy: { id: "occurrence:
|
|
114
|
+
declaredBy: { id: "occurrence:pd:EmailAddress:src/api.ts:3", kind: "const" },
|
|
115
115
|
});
|
|
116
116
|
expect(email?.occurrences.find((o) => o.id.endsWith("abs.ts:9"))?.groupId).toBeNull();
|
|
117
117
|
expect(dataItemFiles.get("data-items/credit-card.json")?.occurrences[0].location).toBe("comment");
|
|
118
|
-
expect(JSON.stringify(facts)).not.toContain("occurrence:
|
|
118
|
+
expect(JSON.stringify(facts)).not.toContain("occurrence:pd:EmailAddress:src/api.ts:4");
|
|
119
119
|
});
|
|
120
120
|
it("keeps the non-occurrence links as relations, once, without code or structure links", () => {
|
|
121
121
|
expect(facts.relations.map((r) => `${r.type} ${r.source} ${r.target}`)).toEqual([
|
|
122
122
|
"delivers_to flow_mail cmp_mail",
|
|
123
|
-
"handled_by group:
|
|
123
|
+
"handled_by group:pd:EmailAddress:customer cmp_api",
|
|
124
124
|
"sends cmp_api flow_mail",
|
|
125
125
|
]);
|
|
126
126
|
});
|
|
@@ -131,39 +131,39 @@ describe("buildFacts", () => {
|
|
|
131
131
|
parts: { scheme: "app", section: "<unsectioned>", type: "asset", subType: "service", file: "src/api.ts", name: "api" },
|
|
132
132
|
});
|
|
133
133
|
expect(facts.dataFlows[0].identity).toMatchObject({ kind: "dataFlow", parts: { source: "app:<unsectioned>|asset|service|src/api.ts|api", file: "src/api.ts" } });
|
|
134
|
-
const email = facts.dataItems.find((d) => d.name === "
|
|
135
|
-
expect(email?.identity).toEqual({ kind: "dataItem", key: "
|
|
136
|
-
expect(email?.groups[0].identity).toEqual({ kind: "group", key: "
|
|
134
|
+
const email = facts.dataItems.find((d) => d.name === "pd:EmailAddress");
|
|
135
|
+
expect(email?.identity).toEqual({ kind: "dataItem", key: "pd:EmailAddress", parts: { name: "pd:EmailAddress" } });
|
|
136
|
+
expect(email?.groups[0].identity).toEqual({ kind: "group", key: "pd:EmailAddress:customer", parts: { dataItem: "pd:EmailAddress", qualifier: "customer" } });
|
|
137
137
|
expect(dataItemFiles.get(email.file)?.identity).toEqual(email?.identity);
|
|
138
138
|
});
|
|
139
139
|
it("drops the line from a declaration-named group's key, and numbers groups that share a key", () => {
|
|
140
140
|
const result = scanResult();
|
|
141
141
|
const occurrences = [
|
|
142
|
-
{ id: "occurrence:
|
|
143
|
-
{ id: "occurrence:
|
|
144
|
-
{ id: "occurrence:
|
|
142
|
+
{ id: "occurrence:pd:TelephoneNumber:src/a.ts:12", filePath: `${ROOT}/src/a.ts`, startLine: 12, endLine: 12, labels: [] },
|
|
143
|
+
{ id: "occurrence:pd:TelephoneNumber:src/a.ts:30", filePath: "src/a.ts", startLine: 30, endLine: 30, labels: [] },
|
|
144
|
+
{ id: "occurrence:pd:TelephoneNumber:src/a.ts:7", filePath: "src/a.ts", startLine: 7, endLine: 7, labels: [] },
|
|
145
145
|
];
|
|
146
146
|
result.occurrences.push(...occurrences);
|
|
147
147
|
result.dataItems.push({
|
|
148
|
-
id: "data_item:
|
|
148
|
+
id: "data_item:pd:TelephoneNumber",
|
|
149
149
|
labels: [],
|
|
150
150
|
occurrenceIds: occurrences.map((o) => o.id),
|
|
151
151
|
groups: [
|
|
152
|
-
{ id: `
|
|
153
|
-
{ id: "
|
|
154
|
-
{ id: "
|
|
152
|
+
{ id: `pd:TelephoneNumber@${ROOT}/src/a.ts:12#phone`, occurrenceIds: [occurrences[0].id] },
|
|
153
|
+
{ id: "pd:TelephoneNumber@src/a.ts:30", occurrenceIds: [occurrences[1].id] },
|
|
154
|
+
{ id: "pd:TelephoneNumber@src/a.ts:7", occurrenceIds: [occurrences[2].id] },
|
|
155
155
|
],
|
|
156
156
|
});
|
|
157
|
-
const groups = (0, build_facts_1.buildFacts)({ result, graph: graph(), ...meta }).facts.dataItems.find((i) => i.name === "
|
|
157
|
+
const groups = (0, build_facts_1.buildFacts)({ result, graph: graph(), ...meta }).facts.dataItems.find((i) => i.name === "pd:TelephoneNumber").groups;
|
|
158
158
|
const byId = new Map(groups.map((g) => [g.id, g.identity]));
|
|
159
|
-
expect(byId.get("group:
|
|
159
|
+
expect(byId.get("group:pd:TelephoneNumber@src/a.ts:12#phone")).toEqual({
|
|
160
160
|
kind: "group",
|
|
161
|
-
key: "
|
|
162
|
-
parts: { dataItem: "
|
|
161
|
+
key: "pd:TelephoneNumber@src/a.ts#phone",
|
|
162
|
+
parts: { dataItem: "pd:TelephoneNumber", declarationFile: "src/a.ts", declarationName: "phone" },
|
|
163
163
|
});
|
|
164
164
|
// Two unnamed declarations in one file share a key; the earlier line keeps it.
|
|
165
|
-
expect(byId.get("group:
|
|
166
|
-
expect(byId.get("group:
|
|
165
|
+
expect(byId.get("group:pd:TelephoneNumber@src/a.ts:7")).toEqual({ kind: "group", key: "pd:TelephoneNumber@src/a.ts", parts: { dataItem: "pd:TelephoneNumber", declarationFile: "src/a.ts" } });
|
|
166
|
+
expect(byId.get("group:pd:TelephoneNumber@src/a.ts:30")).toMatchObject({ key: "pd:TelephoneNumber@src/a.ts#2", duplicateIndex: 2 });
|
|
167
167
|
});
|
|
168
168
|
it("writes scan stamps when given, and leaves them out otherwise (DATAP-876)", () => {
|
|
169
169
|
expect(facts.scan).not.toHaveProperty("stamps");
|
|
@@ -183,11 +183,94 @@ describe("buildFacts", () => {
|
|
|
183
183
|
expect(stamped.scan.stamps).toEqual(stamps);
|
|
184
184
|
expect(() => schema_1.factsFileSchema.parse(stamped)).not.toThrow();
|
|
185
185
|
});
|
|
186
|
+
it("carries the data categories the scanner observed on each flow (DATAP-856)", () => {
|
|
187
|
+
const result = scanResult();
|
|
188
|
+
result.scanResult.dataFlows[0].dataCategories = ["pd:TelephoneNumber", "pd:EmailAddress"];
|
|
189
|
+
result.scanResult.dataFlows.push({ id: "flow_ping", sourceComponentId: "cmp_api", targetComponentId: "cmp_mail", type: "webhook", confidence: 0.8, dataCategories: [] });
|
|
190
|
+
result.scanResult.dataFlows.push({ id: "flow_unchecked", sourceComponentId: "cmp_mail", targetComponentId: "cmp_api", type: "webhook", confidence: 0.8 });
|
|
191
|
+
const built = (0, build_facts_1.buildFacts)({ result, graph: graph(), ...meta }).facts;
|
|
192
|
+
const flow = (id) => built.dataFlows.find((f) => f.id === id);
|
|
193
|
+
expect(flow("flow_mail")?.dataCategories).toEqual(["pd:EmailAddress", "pd:TelephoneNumber"]);
|
|
194
|
+
expect(flow("flow_ping")?.dataCategories).toEqual([]);
|
|
195
|
+
expect(flow("flow_unchecked")).not.toHaveProperty("dataCategories");
|
|
196
|
+
expect(() => schema_1.factsFileSchema.parse(built)).not.toThrow();
|
|
197
|
+
expect(schema_1.factsFileSchema.parse(built).dataFlows.find((f) => f.id === "flow_mail")?.dataCategories).toEqual(["pd:EmailAddress", "pd:TelephoneNumber"]);
|
|
198
|
+
});
|
|
199
|
+
it("copies flow controls with paths relative to the scan root (DATAP-915)", () => {
|
|
200
|
+
const result = scanResult();
|
|
201
|
+
result.scanResult.dataFlows[0].controls = [
|
|
202
|
+
{ control: "tls", effect: "mitigates", filePath: `${ROOT}/src/api.ts`, line: 2 },
|
|
203
|
+
{ control: "timeout", effect: "mitigates", filePath: `${ROOT}/src/api.ts`, line: 5 },
|
|
204
|
+
];
|
|
205
|
+
const { facts } = (0, build_facts_1.buildFacts)({ result, graph: graph(), ...meta });
|
|
206
|
+
const flow = facts.dataFlows[0];
|
|
207
|
+
expect(flow.controls).toEqual([
|
|
208
|
+
{ control: "tls", effect: "mitigates", filePath: "src/api.ts", line: 2 },
|
|
209
|
+
{ control: "timeout", effect: "mitigates", filePath: "src/api.ts", line: 5 },
|
|
210
|
+
]);
|
|
211
|
+
expect(schema_1.factsFileSchema.safeParse(facts).success).toBe(true);
|
|
212
|
+
});
|
|
213
|
+
it("records the Git branch in the scan block, and leaves it out when not given (DATAP-925)", () => {
|
|
214
|
+
const withBranch = (0, build_facts_1.buildFacts)({ result: scanResult(), graph: graph(), ...meta, gitBranch: "feature/threats" }).facts;
|
|
215
|
+
expect(withBranch.scan.gitBranch).toBe("feature/threats");
|
|
216
|
+
expect(schema_1.factsFileSchema.parse(withBranch).scan.gitBranch).toBe("feature/threats");
|
|
217
|
+
const detached = (0, build_facts_1.buildFacts)({ result: scanResult(), graph: graph(), ...meta, gitBranch: null }).facts;
|
|
218
|
+
expect(detached.scan.gitBranch).toBeNull();
|
|
219
|
+
expect(schema_1.factsFileSchema.safeParse(detached).success).toBe(true);
|
|
220
|
+
const withoutBranch = (0, build_facts_1.buildFacts)({ result: scanResult(), graph: graph(), ...meta }).facts;
|
|
221
|
+
expect(withoutBranch.scan).not.toHaveProperty("gitBranch");
|
|
222
|
+
});
|
|
223
|
+
it("writes no threats in facts.json (DATAP-920)", () => {
|
|
224
|
+
const result = scanResult();
|
|
225
|
+
result.scanResult.dataFlows[0].controls = [{ control: "tls", effect: "mitigates", filePath: `${ROOT}/src/api.ts`, line: 2 }];
|
|
226
|
+
const { facts } = (0, build_facts_1.buildFacts)({ result, graph: graph(), ...meta });
|
|
227
|
+
for (const component of facts.components)
|
|
228
|
+
expect(component).not.toHaveProperty("threats");
|
|
229
|
+
for (const dataFlow of facts.dataFlows)
|
|
230
|
+
expect(dataFlow).not.toHaveProperty("threats");
|
|
231
|
+
expect(JSON.stringify(facts)).not.toContain('"threats"');
|
|
232
|
+
});
|
|
233
|
+
it("copies flow authentication evidence with paths relative to the scan root (DATAP-912)", () => {
|
|
234
|
+
const result = scanResult();
|
|
235
|
+
result.scanResult.dataFlows[0].authentication = {
|
|
236
|
+
status: "seen",
|
|
237
|
+
kinds: ["api_key"],
|
|
238
|
+
evidence: [{ kind: "api_key", filePath: `${ROOT}/src/mail.ts`, line: 12 }],
|
|
239
|
+
};
|
|
240
|
+
const { facts } = (0, build_facts_1.buildFacts)({ result, graph: graph(), ...meta });
|
|
241
|
+
expect(facts.dataFlows[0].authentication).toEqual({
|
|
242
|
+
status: "seen",
|
|
243
|
+
kinds: ["api_key"],
|
|
244
|
+
evidence: [{ kind: "api_key", filePath: "src/mail.ts", line: 12 }],
|
|
245
|
+
});
|
|
246
|
+
expect(schema_1.factsFileSchema.safeParse(facts).success).toBe(true);
|
|
247
|
+
});
|
|
248
|
+
it("copies the flow relationship, protocol, transport and channel", () => {
|
|
249
|
+
const result = scanResult();
|
|
250
|
+
Object.assign(result.scanResult.dataFlows[0], {
|
|
251
|
+
relationship: "interacts",
|
|
252
|
+
protocol: "mcp",
|
|
253
|
+
transport: "http",
|
|
254
|
+
channel: "mcp",
|
|
255
|
+
});
|
|
256
|
+
const { facts } = (0, build_facts_1.buildFacts)({ result, graph: graph(), ...meta });
|
|
257
|
+
expect(facts.dataFlows[0]).toMatchObject({
|
|
258
|
+
relationship: "interacts",
|
|
259
|
+
protocol: "mcp",
|
|
260
|
+
transport: "http",
|
|
261
|
+
channel: "mcp",
|
|
262
|
+
});
|
|
263
|
+
expect(schema_1.factsFileSchema.safeParse(facts).success).toBe(true);
|
|
264
|
+
});
|
|
265
|
+
it("leaves authentication out when the scanner did not check the flow", () => {
|
|
266
|
+
const { facts } = (0, build_facts_1.buildFacts)({ result: scanResult(), graph: graph(), ...meta });
|
|
267
|
+
expect(facts.dataFlows[0].authentication).toBeUndefined();
|
|
268
|
+
});
|
|
186
269
|
it("works without a knowledge graph", () => {
|
|
187
270
|
const bare = (0, build_facts_1.buildFacts)({ result: scanResult(), ...meta });
|
|
188
271
|
expect(bare.facts.relations).toEqual([]);
|
|
189
272
|
expect(bare.facts.components[0].codeRefs).toEqual([]);
|
|
190
|
-
expect(bare.facts.dataItems.find((i) => i.name === "
|
|
273
|
+
expect(bare.facts.dataItems.find((i) => i.name === "pd:EmailAddress")?.groups[0].handledBy).toEqual([]);
|
|
191
274
|
});
|
|
192
275
|
});
|
|
193
276
|
describe("writing and reading Facts", () => {
|
|
@@ -201,10 +284,25 @@ describe("writing and reading Facts", () => {
|
|
|
201
284
|
const built = (0, build_facts_1.buildFacts)({ result: scanResult(), graph: graph(), ...meta });
|
|
202
285
|
(0, io_1.writeFactsOutput)(layout, built.facts, built.dataItemFiles);
|
|
203
286
|
expect(fs_1.default.readdirSync(dir).sort()).toEqual(["data-items", "facts.json"]);
|
|
204
|
-
expect(fs_1.default.readdirSync(layout.dataItemsDir).sort()).toEqual(["credit-card.json", "
|
|
287
|
+
expect(fs_1.default.readdirSync(layout.dataItemsDir).sort()).toEqual(["credit-card.json", "pd-emailaddress.json"]);
|
|
205
288
|
const facts = (0, io_1.readFacts)(layout);
|
|
206
289
|
expect(facts).toEqual(built.facts);
|
|
207
|
-
expect((0, io_1.readDataItemFiles)(layout, facts).map((f) => f.name)).toEqual(["Credit Card", "
|
|
290
|
+
expect((0, io_1.readDataItemFiles)(layout, facts).map((f) => f.name)).toEqual(["Credit Card", "pd:EmailAddress"]);
|
|
291
|
+
});
|
|
292
|
+
it("reads a facts.json from an unreleased build that still has threats, without them (DATAP-920)", () => {
|
|
293
|
+
const layout = (0, layout_1.layoutForDir)(dir);
|
|
294
|
+
const built = (0, build_facts_1.buildFacts)({ result: scanResult(), ...meta });
|
|
295
|
+
(0, io_1.writeFactsOutput)(layout, built.facts, built.dataItemFiles);
|
|
296
|
+
const legacyThreats = [{ framework: "stride", category: "S", status: "unknown", ruleId: "stride/v2/process" }];
|
|
297
|
+
const onDisk = JSON.parse(fs_1.default.readFileSync(layout.factsPath, "utf8"));
|
|
298
|
+
onDisk.components[0].threats = legacyThreats;
|
|
299
|
+
onDisk.dataFlows[0].threats = legacyThreats;
|
|
300
|
+
fs_1.default.writeFileSync(layout.factsPath, JSON.stringify(onDisk));
|
|
301
|
+
const facts = (0, io_1.readFacts)(layout);
|
|
302
|
+
for (const component of facts.components)
|
|
303
|
+
expect(component).not.toHaveProperty("threats");
|
|
304
|
+
for (const dataFlow of facts.dataFlows)
|
|
305
|
+
expect(dataFlow).not.toHaveProperty("threats");
|
|
208
306
|
});
|
|
209
307
|
it("replaces facts.json and removes stale data item files on a rescan, but keeps answers.json", () => {
|
|
210
308
|
const layout = (0, layout_1.layoutForDir)(dir);
|
|
@@ -216,7 +314,7 @@ describe("writing and reading Facts", () => {
|
|
|
216
314
|
next.dataItems = next.dataItems.slice(0, 1);
|
|
217
315
|
const second = (0, build_facts_1.buildFacts)({ result: next, ...meta, scannedAt: "2026-10-11T00:00:00.000Z" });
|
|
218
316
|
(0, io_1.writeFactsOutput)(layout, second.facts, second.dataItemFiles);
|
|
219
|
-
expect(fs_1.default.readdirSync(layout.dataItemsDir)).toEqual(["
|
|
317
|
+
expect(fs_1.default.readdirSync(layout.dataItemsDir)).toEqual(["pd-emailaddress.json"]);
|
|
220
318
|
expect((0, io_1.readFacts)(layout).scan.scannedAt).toBe("2026-10-11T00:00:00.000Z");
|
|
221
319
|
expect(fs_1.default.readFileSync(layout.answersPath, "utf8")).toBe(answersBefore);
|
|
222
320
|
expect((0, io_1.readAnswers)(layout).answers).toHaveLength(1);
|
|
@@ -124,6 +124,19 @@ describe("data item and group identities", () => {
|
|
|
124
124
|
it("keys a data item by its name", () => {
|
|
125
125
|
expect((0, identity_1.dataItemIdentity)("Credit Card")).toEqual({ kind: "dataItem", key: "Credit Card", parts: { name: "Credit Card" } });
|
|
126
126
|
});
|
|
127
|
+
it("splits group ids whose data item is a DPV CURIE at the end of the type, not its first colon (DATAP-947)", () => {
|
|
128
|
+
expect((0, identity_1.dataItemIdentity)("pd:EmailAddress")).toEqual({ kind: "dataItem", key: "pd:EmailAddress", parts: { name: "pd:EmailAddress" } });
|
|
129
|
+
expect((0, identity_1.groupIdentity)("pd:EmailAddress", "pd:EmailAddress:customer")).toEqual({
|
|
130
|
+
kind: "group",
|
|
131
|
+
key: "pd:EmailAddress:customer",
|
|
132
|
+
parts: { dataItem: "pd:EmailAddress", qualifier: "customer" },
|
|
133
|
+
});
|
|
134
|
+
expect((0, identity_1.groupIdentity)("pd:EmailAddress", "pd:EmailAddress@src/a.js:12#email")).toEqual({
|
|
135
|
+
kind: "group",
|
|
136
|
+
key: "pd:EmailAddress@src/a.js#email",
|
|
137
|
+
parts: { dataItem: "pd:EmailAddress", declarationFile: "src/a.js", declarationName: "email" },
|
|
138
|
+
});
|
|
139
|
+
});
|
|
127
140
|
it("splits group ids into the data item and the qualifier or column", () => {
|
|
128
141
|
expect((0, identity_1.groupIdentity)("email", "email:customer")).toEqual({ kind: "group", key: "email:customer", parts: { dataItem: "email", qualifier: "customer" } });
|
|
129
142
|
expect((0, identity_1.groupIdentity)("email", "email@contact_email")).toEqual({ kind: "group", key: "email@contact_email", parts: { dataItem: "email", column: "contact_email" } });
|
|
@@ -80,6 +80,38 @@ describe("readGitStamps", () => {
|
|
|
80
80
|
expect((0, scan_stamps_1.readGitStamps)(plain, null)).toEqual({ commitSha: null, dirty: null, rootCommitSha: null, scanRoot: null });
|
|
81
81
|
});
|
|
82
82
|
});
|
|
83
|
+
describe("readGitBranch (DATAP-925)", () => {
|
|
84
|
+
let work;
|
|
85
|
+
let repo;
|
|
86
|
+
const noContinuousIntegration = {};
|
|
87
|
+
beforeEach(() => {
|
|
88
|
+
work = fs_1.default.mkdtempSync(path_1.default.join(os_1.default.tmpdir(), "git-branch-"));
|
|
89
|
+
repo = path_1.default.join(work, "repo");
|
|
90
|
+
fs_1.default.mkdirSync(path_1.default.join(repo, "services"), { recursive: true });
|
|
91
|
+
git(repo, "init", "-q");
|
|
92
|
+
git(repo, "checkout", "-q", "-b", "feature/threats");
|
|
93
|
+
commit(repo, "first");
|
|
94
|
+
});
|
|
95
|
+
afterEach(() => fs_1.default.rmSync(work, { recursive: true, force: true }));
|
|
96
|
+
it("reads the checked-out branch, also from a subfolder", () => {
|
|
97
|
+
expect((0, scan_stamps_1.readGitBranch)(repo, noContinuousIntegration)).toBe("feature/threats");
|
|
98
|
+
expect((0, scan_stamps_1.readGitBranch)(path_1.default.join(repo, "services"), noContinuousIntegration)).toBe("feature/threats");
|
|
99
|
+
});
|
|
100
|
+
it("is null on a detached HEAD, unless a CI branch variable names the branch", () => {
|
|
101
|
+
git(repo, "checkout", "-q", "--detach");
|
|
102
|
+
expect((0, scan_stamps_1.readGitBranch)(repo, noContinuousIntegration)).toBeNull();
|
|
103
|
+
expect((0, scan_stamps_1.readGitBranch)(repo, { GITHUB_HEAD_REF: "pr-branch", GITHUB_REF_NAME: "12/merge", GITHUB_REF_TYPE: "branch" })).toBe("pr-branch");
|
|
104
|
+
expect((0, scan_stamps_1.readGitBranch)(repo, { GITHUB_REF_NAME: "main", GITHUB_REF_TYPE: "branch" })).toBe("main");
|
|
105
|
+
expect((0, scan_stamps_1.readGitBranch)(repo, { GITHUB_REF_NAME: "v1.0.0", GITHUB_REF_TYPE: "tag" })).toBeNull();
|
|
106
|
+
expect((0, scan_stamps_1.readGitBranch)(repo, { CI_COMMIT_REF_NAME: "develop" })).toBe("develop");
|
|
107
|
+
expect((0, scan_stamps_1.readGitBranch)(repo, { CI_COMMIT_REF_NAME: "v1.0.0", CI_COMMIT_TAG: "v1.0.0" })).toBeNull();
|
|
108
|
+
});
|
|
109
|
+
it("is null outside Git", () => {
|
|
110
|
+
const plain = path_1.default.join(work, "plain");
|
|
111
|
+
fs_1.default.mkdirSync(plain);
|
|
112
|
+
expect((0, scan_stamps_1.readGitBranch)(plain, { GITHUB_REF_NAME: "main", GITHUB_REF_TYPE: "branch" })).toBeNull();
|
|
113
|
+
});
|
|
114
|
+
});
|
|
83
115
|
describe("buildScanStamps", () => {
|
|
84
116
|
it("matches the schema", () => {
|
|
85
117
|
const stamps = (0, scan_stamps_1.buildScanStamps)({
|
|
@@ -12,6 +12,8 @@ describe("dataItemSlugs", () => {
|
|
|
12
12
|
expect(slugs.get("../etc/passwd")).toBe("etc-passwd");
|
|
13
13
|
for (const slug of slugs.values())
|
|
14
14
|
expect(slug).toMatch(/^[a-z0-9][a-z0-9._-]*$/);
|
|
15
|
+
// Scanner data item names are DPV CURIEs (DATAP-947).
|
|
16
|
+
expect((0, slug_1.dataItemSlugs)(["pd:EmailAddress", "dpx:FirstName"])).toEqual(new Map([["pd:EmailAddress", "pd-emailaddress"], ["dpx:FirstName", "dpx-firstname"]]));
|
|
15
17
|
});
|
|
16
18
|
it("gives clashing names a hash of their own name, whatever the order", () => {
|
|
17
19
|
const one = (0, slug_1.dataItemSlugs)(["Email", "email"]);
|
|
@@ -19,11 +19,11 @@ const KEYS = {
|
|
|
19
19
|
cmp_user: "app:<unsectioned>|actor|||customer",
|
|
20
20
|
flow_mail: '["flow/v1","app:backend|asset|service|backend/src/main.ts|backend","app:<unsectioned>|third_party|email||sendgrid","api_call","","",""]',
|
|
21
21
|
flow_login: '["flow/v1","app:<unsectioned>|actor|||customer","app:backend|asset|service|backend/src/main.ts|backend","api_call","","",""]',
|
|
22
|
-
"data_item:
|
|
23
|
-
"data_item:
|
|
24
|
-
"group:
|
|
25
|
-
"group:
|
|
26
|
-
"group:
|
|
22
|
+
"data_item:pd:EmailAddress": "pd:EmailAddress",
|
|
23
|
+
"data_item:pd:TelephoneNumber": "pd:TelephoneNumber",
|
|
24
|
+
"group:pd:EmailAddress:customer": "pd:EmailAddress:customer",
|
|
25
|
+
"group:pd:EmailAddress:staff": "pd:EmailAddress:staff",
|
|
26
|
+
"group:pd:TelephoneNumber:customer": "pd:TelephoneNumber:customer",
|
|
27
27
|
};
|
|
28
28
|
function identity(kind, id) {
|
|
29
29
|
return { kind, key: KEYS[id] ?? id, parts: {} };
|
|
@@ -44,7 +44,7 @@ function keyedFacts(change = () => { }) {
|
|
|
44
44
|
}
|
|
45
45
|
function writeScan(paths, change) {
|
|
46
46
|
const { facts, files } = keyedFacts(change);
|
|
47
|
-
(0, io_1.writeFactsOutput)(paths, facts, new Map(files.map((file) => [
|
|
47
|
+
(0, io_1.writeFactsOutput)(paths, facts, new Map(files.map((file) => [facts.dataItems.find((item) => item.id === file.id).file, file])));
|
|
48
48
|
return facts;
|
|
49
49
|
}
|
|
50
50
|
describe("answer fingerprints (DATAP-873)", () => {
|
|
@@ -61,8 +61,8 @@ describe("answer fingerprints (DATAP-873)", () => {
|
|
|
61
61
|
const { facts } = keyedFacts();
|
|
62
62
|
expect((0, answer_fingerprint_1.elementOfFact)(facts, "cmp_mail")).toEqual({ subject: "component", key: KEYS.cmp_mail });
|
|
63
63
|
expect((0, answer_fingerprint_1.elementOfFact)(facts, "flow_mail")).toEqual({ subject: "dataFlow", key: KEYS.flow_mail });
|
|
64
|
-
expect((0, answer_fingerprint_1.elementOfFact)(facts, "data_item:
|
|
65
|
-
expect((0, answer_fingerprint_1.elementOfFact)(facts, "group:
|
|
64
|
+
expect((0, answer_fingerprint_1.elementOfFact)(facts, "data_item:pd:EmailAddress")).toEqual({ subject: "dataItem", key: "pd:EmailAddress" });
|
|
65
|
+
expect((0, answer_fingerprint_1.elementOfFact)(facts, "group:pd:EmailAddress:staff")).toEqual({ subject: "group", key: "pd:EmailAddress:staff" });
|
|
66
66
|
expect((0, answer_fingerprint_1.elementOfFact)(facts, "nope")).toBeNull();
|
|
67
67
|
});
|
|
68
68
|
it("writes the identity key and fingerprint with each new interview answer", () => {
|
|
@@ -87,7 +87,7 @@ describe("answer fingerprints (DATAP-873)", () => {
|
|
|
87
87
|
writeScan(paths);
|
|
88
88
|
const answer = (0, land_1.landReviewAnswer)(paths, { target: "cmp_mail", action: "set", property: "name", value: "SendGrid", reviewer: REVIEWER }).answer;
|
|
89
89
|
expect(answer.identityKey).toBe(KEYS.cmp_mail);
|
|
90
|
-
expect(answer.fingerprint?.handledGroups).toEqual(["
|
|
90
|
+
expect(answer.fingerprint?.handledGroups).toEqual(["pd:EmailAddress:staff"]);
|
|
91
91
|
});
|
|
92
92
|
it("leaves the fields out for a scan without identities", () => {
|
|
93
93
|
const { facts } = (0, facts_fixture_1.sampleFacts)();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const fs_1 = __importDefault(require("fs"));
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const yaml_1 = require("yaml");
|
|
9
|
+
const data_category_catalog_generated_1 = require("../../../src/kb/data-category-catalog.generated");
|
|
10
|
+
function readPinnedScannerTaxonomy() {
|
|
11
|
+
let scannerPackageDirectory = path_1.default.dirname(require.resolve("../../../vendor/scanner/dist/src/index.js"));
|
|
12
|
+
while (!fs_1.default.existsSync(path_1.default.join(scannerPackageDirectory, "patterns", "personal-data-taxonomy.yaml"))) {
|
|
13
|
+
const parentDirectory = path_1.default.dirname(scannerPackageDirectory);
|
|
14
|
+
if (parentDirectory === scannerPackageDirectory)
|
|
15
|
+
throw new Error("Scanner personal-data taxonomy not found");
|
|
16
|
+
scannerPackageDirectory = parentDirectory;
|
|
17
|
+
}
|
|
18
|
+
const taxonomyPath = path_1.default.join(scannerPackageDirectory, "patterns", "personal-data-taxonomy.yaml");
|
|
19
|
+
return (0, yaml_1.parse)(fs_1.default.readFileSync(taxonomyPath, "utf8"));
|
|
20
|
+
}
|
|
21
|
+
describe("data category catalog (DATAP-961)", () => {
|
|
22
|
+
const scannerTaxonomy = readPinnedScannerTaxonomy();
|
|
23
|
+
it("was generated from the pinned scanner's taxonomy", () => {
|
|
24
|
+
expect(data_category_catalog_generated_1.DATA_CATEGORY_SCANNER_TAXONOMY_VERSION).toBe(String(scannerTaxonomy.version));
|
|
25
|
+
});
|
|
26
|
+
it("lists every concept the pinned scanner can put on a data flow, under the same parent", () => {
|
|
27
|
+
for (const scannerConcept of scannerTaxonomy.concepts) {
|
|
28
|
+
const catalogConcept = (0, data_category_catalog_generated_1.findDataCategoryConcept)(scannerConcept.id);
|
|
29
|
+
expect(catalogConcept).toBeDefined();
|
|
30
|
+
expect(catalogConcept?.parent).toBe(scannerConcept.broader);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
it("names every concept as a DPV, DPV-PD or dpx compact IRI with a label", () => {
|
|
34
|
+
for (const concept of data_category_catalog_generated_1.DATA_CATEGORY_CONCEPTS) {
|
|
35
|
+
expect(concept.value).toMatch(/^(dpv|pd|dpx):[A-Z][A-Za-z0-9]*$/);
|
|
36
|
+
expect(concept.label.length).toBeGreaterThan(0);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
it("maps the ontology v0.3.0 interview categories to DPV concepts", () => {
|
|
40
|
+
const interviewCategories = [
|
|
41
|
+
"personal",
|
|
42
|
+
"identifiers",
|
|
43
|
+
"contact",
|
|
44
|
+
"demographic",
|
|
45
|
+
"credentials",
|
|
46
|
+
"financial",
|
|
47
|
+
"health",
|
|
48
|
+
"location",
|
|
49
|
+
"communications",
|
|
50
|
+
"commercial",
|
|
51
|
+
"other",
|
|
52
|
+
];
|
|
53
|
+
for (const interviewCategory of interviewCategories) {
|
|
54
|
+
expect((0, data_category_catalog_generated_1.resolveCatalogDataCategoryValue)(interviewCategory)).toMatch(/^(dpv|pd):/);
|
|
55
|
+
}
|
|
56
|
+
expect((0, data_category_catalog_generated_1.resolveCatalogDataCategoryValue)("credentials")).toBe("pd:Authenticating");
|
|
57
|
+
});
|
|
58
|
+
it("marks authentication, health and financial data as sensitive", () => {
|
|
59
|
+
expect((0, data_category_catalog_generated_1.isSensitiveDataCategory)("pd:Password")).toBe(true);
|
|
60
|
+
expect((0, data_category_catalog_generated_1.isSensitiveDataCategory)("dpx:AccessToken")).toBe(true);
|
|
61
|
+
expect((0, data_category_catalog_generated_1.isSensitiveDataCategory)("pd:MedicalHealth")).toBe(true);
|
|
62
|
+
expect((0, data_category_catalog_generated_1.isSensitiveDataCategory)("pd:PaymentCardNumber")).toBe(true);
|
|
63
|
+
expect((0, data_category_catalog_generated_1.isSensitiveDataCategory)("pd:EmailAddress")).toBe(false);
|
|
64
|
+
});
|
|
65
|
+
});
|