-
Notifications
You must be signed in to change notification settings - Fork 72
Expand file tree
/
Copy pathsecurity-map-assessment.test.cjs
More file actions
155 lines (144 loc) · 4.34 KB
/
Copy pathsecurity-map-assessment.test.cjs
File metadata and controls
155 lines (144 loc) · 4.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
const { describe, it } = require('node:test')
const assert = require('node:assert/strict')
const {
ASSESSMENT_SCHEMA_VERSION,
MAX_IMPORT_BYTES,
parseAssessmentJson,
exportAssessment,
} = require('./security-map-assessment.cjs')
const graph = {
schemaVersion: '1.0.0',
nodes: [
{
id: 'control-signer-isolation',
type: 'control',
assessmentEligible: true,
},
{
id: 'control-branch-protection',
type: 'control',
assessmentEligible: true,
},
{ id: 'threat-key-theft', type: 'threat' },
],
}
function doc(controls) {
return JSON.stringify({
schemaVersion: ASSESSMENT_SCHEMA_VERSION,
graphSchemaVersion: '1.0.0',
updatedAt: '2026-01-01T00:00:00.000Z',
controls,
})
}
describe('assessment parse', () => {
it('empty object is invalid without required fields', () => {
const result = parseAssessmentJson('{}', graph)
assert.equal(result.ok, false)
})
it('accepts a valid current schema', () => {
const result = parseAssessmentJson(
doc({
'control-signer-isolation': {
state: 'implemented',
updatedAt: '2026-01-01T00:00:00.000Z',
},
}),
graph,
)
assert.equal(result.ok, true)
assert.deepEqual(result.recognized, ['control-signer-isolation'])
assert.equal(result.document.controls['control-signer-isolation'].state, 'implemented')
})
it('rejects unsupported schema', () => {
const result = parseAssessmentJson(
JSON.stringify({
schemaVersion: '9.0.0',
graphSchemaVersion: '1.0.0',
updatedAt: '2026-01-01T00:00:00.000Z',
controls: {},
}),
graph,
)
assert.equal(result.ok, false)
assert.match(result.errors.join(' '), /unsupported schemaVersion/)
})
it('reports unknown control IDs without applying them', () => {
const result = parseAssessmentJson(
doc({
'control-not-in-graph': {
state: 'implemented',
updatedAt: '2026-01-01T00:00:00.000Z',
},
'control-signer-isolation': {
state: 'verified',
updatedAt: '2026-01-01T00:00:00.000Z',
},
}),
graph,
)
assert.equal(result.ok, true)
assert.deepEqual(result.unknown, ['control-not-in-graph'])
assert.equal(result.document.controls['control-not-in-graph'], undefined)
assert.equal(result.document.controls['control-signer-isolation'].state, 'verified')
})
it('rejects invalid enum', () => {
const result = parseAssessmentJson(
doc({
'control-signer-isolation': {
state: 'secured',
updatedAt: '2026-01-01T00:00:00.000Z',
},
}),
graph,
)
assert.equal(result.ok, false)
assert.deepEqual(result.invalid, ['control-signer-isolation'])
})
it('rejects oversized files', () => {
const result = parseAssessmentJson('x'.repeat(MAX_IMPORT_BYTES + 1), graph)
assert.equal(result.ok, false)
assert.match(result.errors.join(' '), /exceeds/)
})
it('ignores prototype-pollution keys', () => {
const raw = `{
"schemaVersion": "1.0.0",
"graphSchemaVersion": "1.0.0",
"updatedAt": "2026-01-01T00:00:00.000Z",
"controls": {
"__proto__": { "state": "implemented", "updatedAt": "2026-01-01T00:00:00.000Z" },
"control-signer-isolation": { "state": "planned", "updatedAt": "2026-01-01T00:00:00.000Z" }
}
}`
const result = parseAssessmentJson(raw, graph)
assert.equal(result.ok, false)
assert.ok(result.invalid.includes('__proto__'))
})
it('rejects malformed JSON entirely', () => {
const result = parseAssessmentJson('{not json', graph)
assert.equal(result.ok, false)
assert.match(result.errors.join(' '), /malformed JSON/)
})
it('export contains only expected fields', () => {
const parsed = parseAssessmentJson(
doc({
'control-signer-isolation': {
state: 'partially-implemented',
updatedAt: '2026-01-01T00:00:00.000Z',
},
}),
graph,
)
assert.ok(parsed.document)
const exported = JSON.parse(exportAssessment(parsed.document))
assert.deepEqual(Object.keys(exported).sort(), [
'controls',
'graphSchemaVersion',
'schemaVersion',
'updatedAt',
])
assert.deepEqual(Object.keys(exported.controls['control-signer-isolation']).sort(), [
'state',
'updatedAt',
])
})
})