Skip to content

annotate test files for secrets #676

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

Merged
merged 5 commits into from
Apr 7, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 7 additions & 6 deletions crates/bins/src/bin/datadog-static-analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ use secrets::model::secret_result::{SecretResult, SecretValidationStatus};
use secrets::scanner::{build_sds_scanner, find_secrets};
use secrets::secret_files::should_ignore_file_for_secret;
use std::cell::Cell;
use std::collections::hash_map::Entry;
use std::collections::HashMap;
use std::io::prelude::*;
use std::path::PathBuf;
use std::path::{Path, PathBuf};
use std::process::exit;
use std::sync::Arc;
use std::time::{Duration, Instant, SystemTime};
Expand Down Expand Up @@ -771,10 +772,10 @@ fn main() -> Result<()> {
.into_par_iter()
.fold(
|| (Vec::new(), HashMap::new()),
|(_fold_results, mut path_metadata), path| {
|(_, mut path_metadata), path| {
let relative_path = path
.strip_prefix(directory_path)
.unwrap()
.expect("cannot strip prefix from path")
.to_str()
.expect("path contains non-Unicode characters");
let res = if let Ok(file_content) = fs::read_to_string(&path) {
Expand All @@ -797,7 +798,7 @@ fn main() -> Result<()> {
let metadata = if is_test_file(
language,
file_content.as_ref(),
std::path::Path::new(&cloned_path_str),
Path::new(&cloned_path_str),
None,
) {
Some(ArtifactClassification { is_test_file: true })
Expand All @@ -812,7 +813,7 @@ fn main() -> Result<()> {
} else {
// this is generally because the file is binary.
if use_debug {
eprintln!("error when getting content of path {}", &path.display());
eprintln!("error when getting content of path {}", path.display());
}
vec![]
};
Expand Down Expand Up @@ -848,7 +849,7 @@ fn main() -> Result<()> {

// adding metadata from secrets
for (k, v) in path_metadata {
if let std::collections::hash_map::Entry::Vacant(e) = all_path_metadata.entry(k) {
if let Entry::Vacant(e) = all_path_metadata.entry(k) {
if let Some(artifact_classification) = v {
e.insert(artifact_classification);
}
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/src/file_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ fn get_prefix_for_language(language: &Language) -> Option<Vec<String>> {
None
}

/// File the language for a given file.
/// Find the language for a given file.
pub fn get_language_for_file(path: &Path) -> Option<Language> {
// match for extensions (myfile.c, myfile.php, etc).
for (language, extensions) in FILE_EXTENSIONS_PER_LANGUAGE_LIST {
Expand Down
2 changes: 1 addition & 1 deletion misc/integration-test-secrets.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ echo "Found $RES errors on first run"
EXPECTING=5

if [ "$RES" -ne "$EXPECTING" ]; then
echo "incorrect number of errors found, found $RES, expecting $EXPECTING"
echo "incorrect number of errors found, found $RES, expected $EXPECTING"
exit 1
fi

Expand Down
Loading