Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add example SARIF files as test data #2252

Merged
merged 1 commit into from
Mar 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 46 additions & 1 deletion libs/sarif/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ impl SchemaVersion {
#[cfg(test)]
#[cfg(feature = "serde")]
pub(crate) mod tests {
use std::eprintln;
use std::{eprintln, fs::File, io::BufReader};

use coverage_helper::test;

use super::*;

Expand Down Expand Up @@ -66,4 +68,47 @@ pub(crate) mod tests {
panic!("JSON schema validation failed");
}
}

#[test]
fn example_k1() {
let log = serde_json::from_reader(BufReader::new(
File::open("tests/example_reports/k1_minimal.sarif.json").expect("could not open file"),
))
.expect("could not parse SARIF log");

validate_schema(&log);
}

#[test]
fn example_k2() {
let log = serde_json::from_reader(BufReader::new(
File::open("tests/example_reports/k2_recommended_with_source.sarif.json")
.expect("could not open file"),
))
.expect("could not parse SARIF log");

validate_schema(&log);
}

#[test]
fn example_k3() {
let log = serde_json::from_reader(BufReader::new(
File::open("tests/example_reports/k3_recommended_without_source.sarif.json")
.expect("could not open file"),
))
.expect("could not parse SARIF log");

validate_schema(&log);
}

#[test]
fn example_k4() {
let log = serde_json::from_reader(BufReader::new(
File::open("tests/example_reports/k4_comprehensive.sarif.json")
.expect("could not open file"),
))
.expect("could not parse SARIF log");

validate_schema(&log);
}
}
13 changes: 13 additions & 0 deletions libs/sarif/tests/example_reports/k1_minimal.sarif.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"version": "2.1.0",
"runs": [
{
"tool": {
"driver": {
"name": "CodeScanner"
}
},
"results": []
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"version": "2.1.0",
"runs": [
{
"tool": {
"driver": {
"name": "CodeScanner",
"rules": [
{
"id": "C2001",
"fullDescription": {
"text": "A variable was used without being initialized. This can result in runtime errors such as null reference exceptions."
},
"messageStrings": {
"default": {
"text": "Variable \"{0}\" was used without being initialized."
}
}
}
]
}
},
"artifacts": [
{
"location": {
"uri": "src/collections/list.cpp",
"uriBaseId": "SRCROOT"
},
"sourceLanguage": "c"
}
],
"results": [
{
"ruleId": "C2001",
"ruleIndex": 0,
"message": {
"id": "default",
"arguments": ["count"]
},
"locations": [
{
"physicalLocation": {
"artifactLocation": {
"uri": "src/collections/list.cpp",
"uriBaseId": "SRCROOT",
"index": 0
},
"region": {
"startLine": 15
}
},
"logicalLocations": [
{
"fullyQualifiedName": "collections::list::add"
}
]
}
]
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"version": "2.1.0",
"runs": [
{
"tool": {
"driver": {
"name": "BinaryScanner"
}
},
"artifact": [
{
"location": {
"uri": "bin/example",
"uriBaseId": "BINROOT"
}
}
],
"logicalLocations": [
{
"name": "Example",
"kind": "namespace"
},
{
"name": "Worker",
"fullyQualifiedName": "Example.Worker",
"kind": "type",
"parentIndex": 0
},
{
"name": "DoWork",
"fullyQualifiedName": "Example.Worker.DoWork",
"kind": "function",
"parentIndex": 1
}
],
"results": [
{
"ruleId": "B6412",
"message": {
"text": "The insecure method \"Crypto.Sha1.Encrypt\" should not be used."
},
"level": "warning",
"locations": [
{
"logicalLocations": [
{
"fullyQualifiedName": "Example.Worker.DoWork",
"index": 2
}
]
}
]
}
]
}
]
}
Loading