-
-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'v1.5-dev' into v1.5-explicit-bomlink
- Loading branch information
Showing
16 changed files
with
259 additions
and
38 deletions.
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
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,93 @@ | ||
<?php declare(strict_types=1); | ||
|
||
/** | ||
* validate all test data for a given version of CycloneDX. | ||
* call the script via `php -f <this-file> -- -v <CDX-version>` | ||
*/ | ||
|
||
use Opis\JsonSchema; | ||
|
||
require_once __DIR__ . '/vendor/autoload.php'; | ||
|
||
// region config | ||
|
||
define('TESTSCHEMA_VERSION', getopt('v:')['v']); | ||
define('SCHEMA_DIR', realpath(__DIR__ . '/../../../../schema')); | ||
define('SCHEMA_FILE', SCHEMA_DIR . '/bom-' . TESTSCHEMA_VERSION . '.schema.json'); | ||
define('TESTDATA_DIR', realpath(__DIR__ . '/../resources/' . TESTSCHEMA_VERSION)); | ||
|
||
if (empty(TESTSCHEMA_VERSION)) { | ||
throw new Exception('missing TESTSCHEMA_VERSION. expected via opt "-v"'); | ||
} | ||
fwrite(STDOUT, 'DEBUG | TESTSCHEMA_VERSION = ' . TESTSCHEMA_VERSION . PHP_EOL); | ||
|
||
if (!is_file(SCHEMA_FILE)) { | ||
throw new Exception('missing SCHEMA_FILE: ' . SCHEMA_FILE); | ||
} | ||
fwrite(STDOUT, 'DEBUG | SCHEMA_FILE = ' . SCHEMA_FILE . PHP_EOL); | ||
|
||
if (!is_dir(TESTDATA_DIR)) { | ||
throw new Exception('missing TESTDATA_DIR: ' . TESTDATA_DIR); | ||
} | ||
fwrite(STDOUT, 'DEBUG | TESTDATA_DIR = ' . TESTDATA_DIR . PHP_EOL); | ||
|
||
// endregion config | ||
|
||
// region validator | ||
|
||
$schemaId = uniqid('validate:cdx-test?f=' . SCHEMA_FILE . '&r=', true); | ||
$resolver = new JsonSchema\Resolvers\SchemaResolver(); | ||
$resolver->registerFile($schemaId, SCHEMA_FILE); | ||
$resolver->registerPrefix('http://cyclonedx.org/schema/', SCHEMA_DIR); | ||
$validator = new JsonSchema\Validator(); | ||
$validator->setResolver($resolver); | ||
$errorFormatter = new JsonSchema\Errors\ErrorFormatter(); | ||
|
||
/** | ||
* @param string $file file path to validate | ||
*/ | ||
function validateFile(string $file): ?JsonSchema\Errors\ValidationError | ||
{ | ||
global $validator, $schemaId; | ||
return $validator->validate( | ||
json_decode(file_get_contents($file), false, 1024, \JSON_THROW_ON_ERROR), | ||
$schemaId | ||
)->error(); | ||
} | ||
|
||
// endregion validator | ||
|
||
$errCnt = 0; | ||
|
||
foreach (glob(TESTDATA_DIR . '/valid-*.json') as $file) { | ||
fwrite(STDOUT, PHP_EOL . "test $file ..." . PHP_EOL); | ||
$validationError = validateFile($file); | ||
if ($validationError === null) { | ||
fwrite(STDOUT, 'OK.' . PHP_EOL); | ||
} else { | ||
++$errCnt; | ||
fwrite(STDERR, "ERROR: Unexpected validation error for file: $file" . PHP_EOL); | ||
fwrite(STDERR, json_encode( | ||
$errorFormatter->format($validationError), | ||
JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | ||
) . PHP_EOL); | ||
} | ||
unset($validationError); | ||
} | ||
|
||
foreach (glob(TESTDATA_DIR . '/invalid-*.json') as $file) { | ||
fwrite(STDOUT, PHP_EOL . "test $file ..." . PHP_EOL); | ||
$validationError = validateFile($file); | ||
if ($validationError === null) { | ||
++$errCnt; | ||
fwrite(STDERR, "ERROR: Missing expected validation error for file: $file" . PHP_EOL); | ||
} else { | ||
fwrite(STDOUT, 'OK.' . PHP_EOL); | ||
} | ||
unset($validationError); | ||
} | ||
|
||
|
||
// Exit statuses should be in the range 0 to 254, the exit status 255 is reserved by PHP and shall not be used. | ||
// The status 0 is used to terminate the program successfully. | ||
exit(min($errCnt, 254)); |
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,99 @@ | ||
<?php declare(strict_types=1); | ||
|
||
/** | ||
* validate all test data for a given version of CycloneDX. | ||
* call the script via `php -f <this-file> -- -v <CDX-version>` | ||
*/ | ||
|
||
use Opis\JsonSchema; | ||
|
||
require_once __DIR__ . '/vendor/autoload.php'; | ||
|
||
// region config | ||
|
||
define('TESTSCHEMA_VERSION', getopt('v:')['v']); | ||
define('SCHEMA_DIR', realpath(__DIR__ . '/../../../../schema')); | ||
define('SCHEMA_FILE', SCHEMA_DIR . '/bom-' . TESTSCHEMA_VERSION . '.xsd'); | ||
define('TESTDATA_DIR', realpath(__DIR__ . '/../resources/' . TESTSCHEMA_VERSION)); | ||
|
||
if (empty(TESTSCHEMA_VERSION)) { | ||
throw new Exception('missing TESTSCHEMA_VERSION. expected via opt "-v"'); | ||
} | ||
fwrite(STDOUT, 'DEBUG | TESTSCHEMA_VERSION = ' . TESTSCHEMA_VERSION . PHP_EOL); | ||
|
||
if (!is_file(SCHEMA_FILE)) { | ||
throw new Exception('missing SCHEMA_FILE: ' . SCHEMA_FILE); | ||
} | ||
fwrite(STDOUT, 'DEBUG | SCHEMA_FILE = ' . SCHEMA_FILE . PHP_EOL); | ||
|
||
if (!is_dir(TESTDATA_DIR)) { | ||
throw new Exception('missing TESTDATA_DIR: ' . TESTDATA_DIR); | ||
} | ||
fwrite(STDOUT, 'DEBUG | TESTDATA_DIR = ' . TESTDATA_DIR . PHP_EOL); | ||
|
||
// endregion config | ||
|
||
// region validator | ||
|
||
$xmlOptions = \LIBXML_NONET; | ||
if (\defined('LIBXML_COMPACT')) { | ||
$xmlOptions |= \LIBXML_COMPACT; | ||
} | ||
if (\defined('LIBXML_PARSEHUGE')) { | ||
$xmlOptions |= \LIBXML_PARSEHUGE; | ||
} | ||
|
||
/** | ||
* @param string $file file path to validate | ||
*/ | ||
function validateFile(string $file): ?LibXMLError | ||
{ | ||
global $xmlOptions; | ||
|
||
libxml_use_internal_errors(true); | ||
libxml_clear_errors(); | ||
|
||
$doc = new DOMDocument(); | ||
if (!$doc->loadXML(file_get_contents($file), $xmlOptions)) { | ||
throw new Exception("failed loading file: $file" . PHP_EOL . libxml_get_last_error()->message); | ||
} | ||
|
||
$valid = $doc->schemaValidate(SCHEMA_FILE); | ||
return $valid | ||
? null | ||
: libxml_get_last_error(); | ||
} | ||
|
||
// endregion validator | ||
|
||
$errCnt = 0; | ||
|
||
foreach (glob(TESTDATA_DIR . '/valid-*.xml') as $file) { | ||
fwrite(STDOUT, PHP_EOL . "test $file ..." . PHP_EOL); | ||
$validationError = validateFile($file); | ||
if ($validationError === null) { | ||
fwrite(STDOUT, 'OK.' . PHP_EOL); | ||
} else { | ||
++$errCnt; | ||
fwrite(STDERR, "ERROR: Unexpected validation error for file: $file" . PHP_EOL); | ||
fwrite(STDERR, print_r($validationError, true) . PHP_EOL); | ||
} | ||
unset($validationError); | ||
} | ||
|
||
foreach (glob(TESTDATA_DIR . '/invalid-*.xml') as $file) { | ||
fwrite(STDOUT, PHP_EOL . "test $file ..." . PHP_EOL); | ||
$validationError = validateFile($file); | ||
if ($validationError === null) { | ||
++$errCnt; | ||
fwrite(STDERR, "ERROR: Missing expected validation error for file: $file" . PHP_EOL); | ||
} else { | ||
fwrite(STDOUT, 'OK.' . PHP_EOL); | ||
} | ||
unset($validationError); | ||
} | ||
|
||
|
||
// Exit statuses should be in the range 0 to 254, the exit status 255 is reserved by PHP and shall not be used. | ||
// The status 0 is used to terminate the program successfully. | ||
exit(min($errCnt, 254)); |
11 changes: 0 additions & 11 deletions
11
tools/src/test/resources/1.2/invalid-empty-component-1.2.json
This file was deleted.
Oops, something went wrong.
12 changes: 12 additions & 0 deletions
12
tools/src/test/resources/1.2/skip_invalid-empty-component-1.2.json
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,12 @@ | ||
{ | ||
"bomFormat": "CycloneDX", | ||
"specVersion": "1.2", | ||
"serialNumber": "urn:uuid:3e671687-395b-41f5-a30f-a58921a69b79", | ||
"version": 1, | ||
"components": [ | ||
{ | ||
"type": "library", | ||
"$comment": "expected to fail, since `name` and `version` are missing. But in fact `name` and `version` are optional as they have a default value in CDX-v1.2" | ||
} | ||
] | ||
} |
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 |
---|---|---|
|
@@ -129,12 +129,12 @@ | |
], | ||
"commits": [ | ||
{ | ||
"uid": "123", | ||
"url": "", | ||
"uid": "7638417db6d59f3c431d3e1f261cc637155684cd", | ||
"url": "https://location/to/7638417db6d59f3c431d3e1f261cc637155684cd", | ||
"author": { | ||
"timestamp": "2018-11-13T20:20:39+00:00", | ||
"name": "", | ||
"email": "" | ||
"name": "me", | ||
"email": "[email protected]" | ||
} | ||
} | ||
] | ||
|
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 |
---|---|---|
|
@@ -129,12 +129,12 @@ | |
], | ||
"commits": [ | ||
{ | ||
"uid": "123", | ||
"url": "", | ||
"uid": "7638417db6d59f3c431d3e1f261cc637155684cd", | ||
"url": "https://location/to/7638417db6d59f3c431d3e1f261cc637155684cd", | ||
"author": { | ||
"timestamp": "2018-11-13T20:20:39+00:00", | ||
"name": "", | ||
"email": "" | ||
"name": "me", | ||
"email": "[email protected]" | ||
} | ||
} | ||
] | ||
|
Oops, something went wrong.