-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial draft of a validation testing framework
This is work in progress, but it tries to provide an API for the implementation of 6.1 mandatory tests for validation.
- Loading branch information
Showing
18 changed files
with
1,036 additions
and
211 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[submodule "csaf"] | ||
path = csaf | ||
url = https://github.com/oasis-tcs/csaf | ||
branch = master |
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
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
65 changes: 65 additions & 0 deletions
65
csaf-validation/src/main/kotlin/io/github/csaf/sbom/validation/Main.kt
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,65 @@ | ||
/* | ||
* Copyright (c) 2024, The Authors. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
package io.github.csaf.sbom.validation | ||
|
||
import io.github.csaf.sbom.schema.KoverIgnore | ||
import io.github.csaf.sbom.schema.generated.Csaf | ||
import io.github.csaf.sbom.validation.tests.informativeTests | ||
import io.github.csaf.sbom.validation.tests.mandatoryTests | ||
import io.github.csaf.sbom.validation.tests.optionalTests | ||
import java.time.Duration | ||
import java.time.Instant | ||
import kotlin.io.path.Path | ||
import kotlin.io.path.readText | ||
import kotlinx.serialization.json.Json | ||
|
||
@KoverIgnore("Entry point for demo purposes only") | ||
fun main(args: Array<String>) { | ||
val path = Path(args[0]) | ||
val doc = Json.decodeFromString<Csaf>(path.readText()) | ||
|
||
println("Analyzing file ${path}...\n") | ||
|
||
val globalStart = Instant.now() | ||
|
||
val allTests = | ||
mapOf( | ||
mandatoryTests to "mandatory", | ||
optionalTests to "optional", | ||
informativeTests to "informative", | ||
) | ||
|
||
for (entry in allTests) { | ||
println("== ${entry.value.uppercase()} TESTS ==") | ||
|
||
for (test in entry.key) { | ||
val start = Instant.now() | ||
val result = test.test(doc) | ||
println( | ||
"Test ${test::class.simpleName}: $result. It took ${ | ||
Duration.between(start, Instant.now()).toMillis() | ||
} ms" | ||
) | ||
} | ||
|
||
println("") | ||
} | ||
|
||
println( | ||
"Executing all tests took ${Duration.between(globalStart, Instant.now()).toMillis()} ms" | ||
) | ||
} |
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
29 changes: 29 additions & 0 deletions
29
csaf-validation/src/main/kotlin/io/github/csaf/sbom/validation/Test.kt
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,29 @@ | ||
/* | ||
* Copyright (c) 2024, The Authors. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
package io.github.csaf.sbom.validation | ||
|
||
import io.github.csaf.sbom.schema.generated.Csaf | ||
|
||
/** | ||
* Represents a test as described in | ||
* [Section 6](https://docs.oasis-open.org/csaf/csaf/v2.0/os/csaf-v2.0-os.html#6-tests). They all | ||
* target a CSAF document, represented by the [Csaf] type. | ||
*/ | ||
interface Test { | ||
|
||
fun test(doc: Csaf): ValidationResult | ||
} |
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
Oops, something went wrong.