Skip to content

Commit

Permalink
Merge pull request #23 from DataDog/juli1/add-schema-validation
Browse files Browse the repository at this point in the history
Add SARIF validation tests + fix level
  • Loading branch information
juli1 authored Jul 12, 2023
2 parents 7eca095 + 9ab73b7 commit f541dd9
Show file tree
Hide file tree
Showing 9 changed files with 3,437 additions and 6 deletions.
14 changes: 14 additions & 0 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ First, start the server using
cargo run --bin datadog-static-analyzer-server
```


### Get an analysis request
```shell

curl -X POST \
Expand All @@ -63,5 +65,17 @@ curl -X POST \
]
}' \
http://localhost:8000/analyze
```

### Get the AST Tree

```shell
curl -X POST \
-H "Content-Type: application/json" \
--data '{
"file_encoding": "utf-8",
"language": "PYTHON",
"code": "ZGVmIGZvbyhhcmcxKToKICAgIHBhc3M="
}' \
http://localhost:8000/get-treesitter-ast
```
1 change: 1 addition & 0 deletions LICENSE-3rdparty.csv
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ sarif-rs,https://github.com/psastras/sarif-rs,MIT,Copyright (c) 2021 Paul Sastra
serde,https://github.com/serde-rs/serde,Apache-2.0,2015 David Tolnay and Serde contributors
serde_json,https://github.com/serde-rs/json,Apache-2.0,2015 David Tolnay and Serde contributors
serde_yaml,https://github.com/dtolnay/serde-yaml,Apache-2.0,2016 David Tolnay
valico,https://github.com/s-panferov/valico,MIT,Copyright (c) 2014 Stanislav Panferov
walkdir,https://github.com/BurntSushi/walkdir,MIT,Copyright (c) 2015 Andrew Gallant
5 changes: 3 additions & 2 deletions bins/src/bin/datadog-static-analyzer-test-ruleset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@ fn test_rule(rule: &Rule, test: &RuleTest) -> Result<String> {
if first_results.violations.len() != test.annotation_count as usize {
let error =
format!(
"error evaluating test {}, expected {} annotations, got {}, error: {}, output: {}",
"error evaluating test {}, expected {} annotations, got {}, execution error: {}, output: {}, rule errors: {}",
test.filename,
test.annotation_count,
first_results.violations.len(),
first_results.execution_error.clone().unwrap_or("none".to_string()),
first_results.output.clone().unwrap_or("none".to_string())
first_results.output.clone().unwrap_or("none".to_string()),
first_results.errors.join(",")
);
Err(Error::msg(error))
} else {
Expand Down
2 changes: 1 addition & 1 deletion bins/src/bin/datadog-static-analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ use cli::datadog_utils::get_rules_from_rulesets;
use cli::file_utils::{filter_files_for_language, get_files};
use cli::model::config_file::ConfigFile;
use cli::rule_utils::{get_languages_for_rules, get_rulesets_from_file};
use cli::sarif_utils::generate_sarif_report;
use kernel::analysis::analyze::analyze;
use kernel::constants::VERSION;
use kernel::model::analysis::AnalysisOptions;
use kernel::model::common::Language;
use kernel::model::rule::{Rule, RuleInternal};

use anyhow::{Context, Result};
use cli::sarif::sarif_utils::generate_sarif_report;
use getopts::Options;
use rayon::prelude::*;
use std::io::prelude::*;
Expand Down
1 change: 1 addition & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ serde-sarif = { workspace = true }
glob-match = "0.2.1"
reqwest = { version = "0.11", features = ["blocking", "json"] }
serde_yaml = "0.9.21"
valico = "4.0.0"
walkdir = "2.3.3"

[dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ pub mod datadog_utils;
pub mod file_utils;
pub mod model;
pub mod rule_utils;
pub mod sarif_utils;
pub mod sarif;
1 change: 1 addition & 0 deletions cli/src/sarif.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod sarif_utils;
Loading

0 comments on commit f541dd9

Please sign in to comment.