Skip to content

Commit 329028f

Browse files
committed
validate
Signed-off-by: Jan Kowalleck <jan.kowalleck@gmail.com>
1 parent caaea9f commit 329028f

File tree

7 files changed

+139
-0
lines changed

7 files changed

+139
-0
lines changed

.github/workflows/nodejs.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,7 @@ jobs:
455455
run: npm run build
456456
working-directory: ${{ env.EXAMPLE_DIR }}
457457

458+
458459
api-doc:
459460
name: api-doc ${{ matrix.target }}
460461
runs-on: "ubuntu-latest"
@@ -487,3 +488,31 @@ jobs:
487488
echo "::endgroup::"
488489
- name: api-doc ${{ matrix.target }}
489490
run: npm run api-doc:${{ matrix.target }}
491+
492+
493+
validate-VEX-VDR:
494+
needs: [ 'build' ]
495+
name: validate VEX/VDR
496+
runs-on: ubuntu-latest
497+
timeout-minutes: 10
498+
steps:
499+
- name: Checkout
500+
# see https://github.com/actions/checkout
501+
uses: actions/checkout@v4
502+
- name: Setup Node.js ${{ env.NODE_ACTIVE_LTS }}
503+
# see https://github.com/actions/setup-node
504+
uses: actions/setup-node@v4
505+
with:
506+
node-version: ${{ env.NODE_ACTIVE_LTS }}
507+
- name: fetch build artifact 'node'
508+
# see https://github.com/actions/download-artifact
509+
uses: actions/download-artifact@v4
510+
with:
511+
name: dist.node
512+
path: dist.node
513+
- name: setup library
514+
run: npm i --ignore-scripts --omit=dev --include=optional --loglevel=silly
515+
working-directory: tools/cdx-json-schema-validator
516+
- name: validate
517+
run: node tools/cdx-json-schema-validator/validate.js SECURITY.cdx.json
518+
File renamed without changes.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
*
2+
!/.gitignore
3+
!/package.json
4+
!/validate.js
5+
!/.npmrc
6+
!/eslint.config.mjs
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
; see the docs: https://docs.npmjs.com/cli/v9/using-npm/config
2+
3+
package-lock=false
4+
engine-strict=true
5+
omit=peer # don't install them automatically; we take cate of them!
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*!
2+
This file is part of CycloneDX JavaScript Library.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
16+
SPDX-License-Identifier: Apache-2.0
17+
Copyright (c) OWASP Foundation. All Rights Reserved.
18+
*/
19+
20+
import baseCfg, { globals } from '../code-style/eslint.config.mjs'
21+
22+
/* eslint-disable jsdoc/valid-types */
23+
24+
/**
25+
* @type {import('@types/eslint').Linter.FlatConfig[]}
26+
* @see {@link https://eslint.org/}
27+
*/
28+
export default [
29+
...baseCfg,
30+
{
31+
files: ['**/*.js'],
32+
languageOptions: {
33+
sourceType: 'module',
34+
globals: globals.node,
35+
}
36+
},
37+
]
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"private": true,
3+
"name": "@cyclonedx/cyclonedx-javascript-library/tools/cdx-json-schema-validator",
4+
"license": "Apache-2.0",
5+
"type": "module",
6+
"main": "validate.js",
7+
"dependencies": {
8+
"@cyclonedx/cyclonedx-library": "file:../.."
9+
},
10+
"scripts": {
11+
"download": "node download.js",
12+
"cs-fix": "npm --prefix ../code-style exec -- eslint --fix ."
13+
},
14+
"engines": {
15+
"node": ">=20.18"
16+
}
17+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*!
2+
This file is part of CycloneDX JavaScript Library.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
16+
SPDX-License-Identifier: Apache-2.0
17+
Copyright (c) OWASP Foundation. All Rights Reserved.
18+
*/
19+
20+
import CDX from "@cyclonedx/cyclonedx-library"
21+
import {readFile} from 'node:fs/promises';
22+
23+
const args = process.argv.slice(2);
24+
if (args.length !== 1) {
25+
console.error("missing args");
26+
process.exit(1);
27+
}
28+
const [filePath] = args
29+
console.debug('filePath', filePath)
30+
31+
const json = await readFile(filePath, 'utf8')
32+
const data = JSON.parse(json);
33+
34+
const CDX_JSON_SCHEMA_RE = /^http:\/\/cyclonedx\.org\/schema\/bom\-(\d+\.\d+)\.schema\.json$/
35+
const specVersion = data['$schema'].match(CDX_JSON_SCHEMA_RE)[1]
36+
const validator = new CDX.Validation.JsonStrictValidator(specVersion)
37+
38+
const validationError = await validator.validate(json)
39+
if (validationError !== null) {
40+
console.error('validation error', validationError)
41+
process.exit(2);
42+
}
43+
44+
console.info('valid')
45+
process.exit(0)

0 commit comments

Comments
 (0)