-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
101 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import Ajv from 'ajv/dist/jtd.js' | ||
|
||
/** | ||
* The max uuid to check the sharing_group.id for. | ||
*/ | ||
const MAX_UUID = 'ffffffff-ffff-ffff-ffff-ffffffffffff' | ||
|
||
/** | ||
* The nil uuid to check the sharing_group.id for. | ||
*/ | ||
const NIL_UUID = '00000000-0000-0000-0000-000000000000' | ||
|
||
const ajv = new Ajv() | ||
|
||
/* | ||
This is the jtd schema that needs to match the input document so that the | ||
test is activated. If this schema doesn't match it normally means that the input | ||
document does not validate against the csaf json schema or optional fields that | ||
the test checks are not present. | ||
*/ | ||
const inputSchema = /** @type {const} */ ({ | ||
additionalProperties: true, | ||
properties: { | ||
document: { | ||
additionalProperties: true, | ||
properties: { | ||
distribution: { | ||
additionalProperties: true, | ||
optionalProperties: { | ||
sharing_group: { | ||
additionalProperties: true, | ||
properties: { | ||
id: { | ||
type: 'string', | ||
}, | ||
}, | ||
}, | ||
tlp: { | ||
additionalProperties: true, | ||
optionalProperties: { | ||
label: { type: 'string' }, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}) | ||
|
||
const validate = ajv.compile(inputSchema) | ||
|
||
/** | ||
* This implements the mandatory test 6.1.40 of the CSAF 2.1 standard. | ||
* | ||
* @param {any} doc | ||
*/ | ||
export function mandatoryTest_6_1_40(doc) { | ||
/* | ||
The `ctx` variable holds the state that is accumulated during the test ran and is | ||
finally returned by the function. | ||
*/ | ||
const ctx = { | ||
errors: | ||
/** @type {Array<{ instancePath: string; message: string }>} */ ([]), | ||
isValid: true, | ||
} | ||
|
||
if (!validate(doc)) return ctx | ||
|
||
const sharingGroupId = doc.document.distribution.sharing_group?.id | ||
const sharingGroupName = doc.document.distribution.sharing_group?.name | ||
|
||
if (sharingGroupName === 'Public' && sharingGroupId !== MAX_UUID) { | ||
ctx.isValid = false | ||
ctx.errors.push({ | ||
instancePath: '/document/distribution/sharing_group/id', | ||
message: `the sharing group name is "Public" but it does not use the max UUID`, | ||
}) | ||
} else if ( | ||
sharingGroupName === 'No sharing allowed' && | ||
sharingGroupId !== NIL_UUID | ||
) { | ||
ctx.isValid = false | ||
ctx.errors.push({ | ||
instancePath: '/document/distribution/sharing_group/id', | ||
message: `the sharing group name is "No sharing allowed" but it does not use the nil UUID`, | ||
}) | ||
} | ||
|
||
return ctx | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import assert from 'node:assert/strict' | ||
import { mandatoryTest_6_1_40 } from '../../csaf_2_1/mandatoryTests/mandatoryTest_6_1_40.js' | ||
|
||
describe('mandatoryTest_6_1_40', function () { | ||
it('only runs on relevant documents', function () { | ||
assert.equal(mandatoryTest_6_1_40({ document: 'mydoc' }).isValid, true) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,6 @@ const excluded = [ | |
'6.1.37', | ||
'6.1.38', | ||
'6.1.39', | ||
'6.1.40', | ||
'6.1.41', | ||
'6.1.42', | ||
'6.2.6', | ||
|