diff --git a/.clippy.toml b/.clippy.toml new file mode 100644 index 0000000..0358cdb --- /dev/null +++ b/.clippy.toml @@ -0,0 +1,2 @@ +allow-unwrap-in-tests = true +allow-expect-in-tests = true diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..fd16ae8 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,22 @@ +name: ci + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + ci: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: Swatinem/rust-cache@v2 + - name: Format + run: cargo fmt --check + - name: Check + run: cargo check + - name: Clippy + run: cargo clippy --all-targets --all-features -- -D warnings -D clippy::unwrap_used -D clippy::expect_used diff --git a/README.md b/README.md index 076e01d..e93a8b9 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,15 @@ # scale-testing + Utility for testing trustification at scale. -This tool is to help replicating existing SBOMs (SPDX or CycloneDX) file in order to augment an existing data set by multipling the number SBOMs files. +This tool is to help replicating existing SBOMs (SPDX or CycloneDX) file in order to augment an existing data set by multiplying the number SBOMs files. -For instance let's say we have a total of 1000 SBMS (500 SPDX and 500) and we'd like to obtain a total of 10K SBOMs files for our scale test, so we can run the tool using a replication size of 10. +For instance let's say we have a total of 1000 SBMS (500 SPDX and 500) and we'd like to obtain a total of 10K SBOMs files for our scale test, so we can run the tool using a replication size of 10. The tool replicates existing SBOMs, by copying each file content and change its file name and its key records. +## Usage -## Usage ## After installing trustification/scale-testing repo, We can run the tool, by providing the size of the replication, the source directory and the destination directory : @@ -19,8 +20,7 @@ The latter will replicate 10 times each SBOM file available in /SBOMs/. Each replicated SBOM file will be created under its corresponding batch directory under `/data-set`. - -## Example ## +> Example ```sh $ cargo run -- 2 ./SBOMs ./data-set @@ -61,23 +61,21 @@ data-set/ 5 directories, 6 files ``` -## scale test example - -### Using bombastic_walker +## Using bombastic_walker -#### Prepare initial SBOMs data set +### Prepare initial SBOMs data set Provide initial set of SBOMs files to be replicated, i.e `/SBOMs/`. Use only SPDX files, for now, because the CycloneDX files tested were rejected with following error: `JSON: Unsupported CycloneDX version: 1.4` -#### Replicate SBOMs +### Replicate SBOMs Run the replication tool to multiply your existing SBOM files set `cargo run -- 10 /SBOMs /data-set` -#### Use the replicated SBOMs +### Use the replicated SBOMs -The bombastic_walker could exploit each replicated SBOMs batch, for example in devmode : +The bombastic_walker could exploit each replicated SBOMs batch, for example in devmode : `RUST_LOG=info cargo run -p trust bombastic walker --sink http://localhost:8082 --source /data-set/batch1/ --devmode -3` diff --git a/benchmarks/README.md b/benchmarks/README.md index 8d60e4c..608931a 100644 --- a/benchmarks/README.md +++ b/benchmarks/README.md @@ -3,10 +3,5 @@ > [!NOTE] > This is a working in progress. -## trustify - -In this directory we are using [PM-mode](https://github.com/trustification/trustify/?tab=readme-ov-file#quick-start) + [Hyperfoil](https://hyperfoil.io/) (in-vm) to experiment the tool and create some basic scenarios. - -## trustification - -TBD +* [trustify](./trustify/README.md) +* [trustification](./trustification/README.md) diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..d322aab --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,3 @@ +[toolchain] +channel = "1.78.0" +components = [ "rustfmt", "clippy" ] diff --git a/src/replicator.rs b/src/replicator.rs index 48c52c5..449eecb 100644 --- a/src/replicator.rs +++ b/src/replicator.rs @@ -20,7 +20,7 @@ impl Replication { // In the dst dir. create as many batch directories as replicator value. // In each batch directory, add a metadata subdirectory containting metadata.json file. // This is necessary for the bombastic-walker to parse the files. - for i in 1..self.config.replicator.parse::().unwrap() + 1 { + for i in 1..self.config.replicator.parse::().unwrap_or_default() + 1 { let batch_path = format!("batch{}", i); fs::create_dir_all( Path::new(&self.config.dst) @@ -49,7 +49,7 @@ impl Replication { file, &self.config.src.clone(), &self.config.dst.clone(), - self.config.replicator.parse::().unwrap(), + self.config.replicator.parse::().unwrap_or_default(), ), Err(e) => println!("Error: {}", e), } @@ -60,7 +60,7 @@ impl Replication { } fn replicate_file(file: fs::DirEntry, src: &str, dst: &str, times: u32) { - let file_name_base: String = file.file_name().into_string().unwrap(); + let file_name_base: String = file.file_name().into_string().unwrap_or_default(); for i in 1..times + 1 { let dst_file_name = @@ -78,7 +78,7 @@ fn replicate_file(file: fs::DirEntry, src: &str, dst: &str, times: u32) { }; let contents = fs::read_to_string(Path::new(src).join(file_name_base.as_str())) - .unwrap() + .unwrap_or_default() .lines() .map(|line| { // SPDX @@ -109,14 +109,17 @@ fn replicate_file(file: fs::DirEntry, src: &str, dst: &str, times: u32) { /// Insert provided string after the file base name and before the extensions /// Example with string being "blah": "ubi9-minimal-9.3-830.json" becomes "ubi9-minimal-9.blah.3-830.json" fn replicate_file_name(file_name: &str, str: &str) -> String { - let mut file_name_with_extensions = file_name.split("."); - let base_file_name: String = file_name_with_extensions.next().unwrap().to_string(); + let mut file_name_with_extensions = file_name.split('.'); + let base_file_name: String = file_name_with_extensions + .next() + .unwrap_or_default() + .to_string(); let mut dst_file_name = base_file_name.clone(); dst_file_name.push_str(str); for extension in file_name_with_extensions { - dst_file_name.push_str("."); + dst_file_name.push('.'); dst_file_name.push_str(extension); } @@ -127,10 +130,11 @@ fn replace(line: &str, key: &str, value: &str, index: u32) -> String { println!("Amending {}: {}", key, line); let mut document_key = line.split(": "); document_key.next(); - let remainder = document_key.next().unwrap(); + let remainder = document_key.next().unwrap_or_default().to_string(); let new_remainder = remainder.replace("\",", format!("-{}{}\",", value, index).as_str()); let new_remainder_str = new_remainder.as_str(); - line.replace(remainder, new_remainder_str).to_string() + line.replace(remainder.as_str(), new_remainder_str) + .to_string() }