Skip to content

Commit 8df5814

Browse files
committed
chore: annotate secrets detection fixtures for gitleaks
Signed-off-by: lucarlig <luca.carlig@ibm.com>
1 parent ae63d74 commit 8df5814

3 files changed

Lines changed: 20 additions & 20 deletions

File tree

plugins_rust/secrets_detection/src/patterns.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,11 @@ mod tests {
142142

143143
// Valid Google API keys (AIza + exactly 35 chars)
144144
assert!(
145-
pattern.is_match("AIzaFAKE_KEY_FOR_TESTING_ONLY_fake12345"),
145+
pattern.is_match("AIzaFAKE_KEY_FOR_TESTING_ONLY_fake12345"), // gitleaks:allow
146146
"Should match valid Google API key"
147147
);
148148
assert!(
149-
pattern.is_match("AIzaFAKE_KEY_FOR_TESTING_ONLY_fake56789"),
149+
pattern.is_match("AIzaFAKE_KEY_FOR_TESTING_ONLY_fake56789"), // gitleaks:allow
150150
"Should match valid Google API key"
151151
);
152152

@@ -212,7 +212,7 @@ mod tests {
212212
let pattern = PATTERNS.get("generic_api_key_assignment").unwrap();
213213

214214
assert!(
215-
pattern.is_match("X-API-Key: test12345678901234567890"),
215+
pattern.is_match("X-API-Key: test12345678901234567890"), // gitleaks:allow
216216
"Should match X-API-Key header"
217217
);
218218
assert!(
@@ -269,19 +269,19 @@ mod tests {
269269

270270
// Valid private key headers
271271
assert!(
272-
pattern.is_match("-----BEGIN RSA PRIVATE KEY-----"),
272+
pattern.is_match("-----BEGIN RSA PRIVATE KEY-----"), // gitleaks:allow
273273
"Should match RSA private key header"
274274
);
275275
assert!(
276-
pattern.is_match("-----BEGIN DSA PRIVATE KEY-----"),
276+
pattern.is_match("-----BEGIN DSA PRIVATE KEY-----"), // gitleaks:allow
277277
"Should match DSA private key header"
278278
);
279279
assert!(
280-
pattern.is_match("-----BEGIN EC PRIVATE KEY-----"),
280+
pattern.is_match("-----BEGIN EC PRIVATE KEY-----"), // gitleaks:allow
281281
"Should match EC private key header"
282282
);
283283
assert!(
284-
pattern.is_match("-----BEGIN OPENSSH PRIVATE KEY-----"),
284+
pattern.is_match("-----BEGIN OPENSSH PRIVATE KEY-----"), // gitleaks:allow
285285
"Should match OpenSSH private key header"
286286
);
287287

@@ -398,7 +398,7 @@ mod tests {
398398

399399
let text = r#"
400400
Authorization: Bearer eyJfake_header_12345.eyJfake_payload_1234.fake_signature_12345678
401-
API_SECRET=a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1b2
401+
API_SECRET=a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1b2 // gitleaks:allow
402402
"#;
403403

404404
assert!(

plugins_rust/secrets_detection/src/scanner.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -238,12 +238,12 @@ mod tests {
238238
};
239239

240240
// Test that hex secrets are detected
241-
let hex_text = "secret=0123456789abcdef0123456789abcdef";
241+
let hex_text = "secret=0123456789abcdef0123456789abcdef"; // gitleaks:allow
242242
let (hex_findings, _) = detect_and_redact(hex_text, &cfg);
243243
assert!(!hex_findings.is_empty(), "Should detect hex secrets");
244244

245245
// Test that base64 secrets are detected
246-
let base64_text = "token=SGVsbG8gV29ybGQgdGhpcyBpcyBhIGxvbmcgYmFzZTY0IGVuY29kZWQgc3RyaW5n";
246+
let base64_text = "token=SGVsbG8gV29ybGQgdGhpcyBpcyBhIGxvbmcgYmFzZTY0IGVuY29kZWQgc3RyaW5n"; // gitleaks:allow
247247
let (b64_findings, _) = detect_and_redact(base64_text, &cfg);
248248
assert!(!b64_findings.is_empty(), "Should detect base64 secrets");
249249
}
@@ -256,7 +256,7 @@ mod tests {
256256
..Default::default()
257257
};
258258

259-
let text = "GOOGLE_API_KEY=AIzaFAKE_KEY_FOR_TESTING_ONLY_fake12345";
259+
let text = "GOOGLE_API_KEY=AIzaFAKE_KEY_FOR_TESTING_ONLY_fake12345"; // gitleaks:allow
260260
let (findings, redacted) = detect_and_redact(text, &cfg);
261261

262262
assert!(!findings.is_empty());
@@ -272,7 +272,7 @@ mod tests {
272272
..Default::default()
273273
};
274274

275-
let text = "SLACK_TOKEN=xoxr-fake-000000000-fake000000000-fakefakefakefake";
275+
let text = "SLACK_TOKEN=xoxr-fake-000000000-fake000000000-fakefakefakefake"; // gitleaks:allow
276276
let (findings, redacted) = detect_and_redact(text, &cfg);
277277

278278
assert!(!findings.is_empty());
@@ -287,7 +287,7 @@ mod tests {
287287
..Default::default()
288288
};
289289

290-
let text = "-----BEGIN RSA PRIVATE KEY-----\nMIIEpAIBAAKCAQEA...";
290+
let text = "-----BEGIN RSA PRIVATE KEY-----\nMIIEpAIBAAKCAQEA..."; // gitleaks:allow
291291
let (findings, redacted) = detect_and_redact(text, &cfg);
292292

293293
assert!(!findings.is_empty());
@@ -444,7 +444,7 @@ mod tests {
444444
let items = vec![
445445
"AKIAFAKE12345EXAMPLE",
446446
"normal text",
447-
"AIzaFAKE_KEY_FOR_TESTING_ONLY_fake12345",
447+
"AIzaFAKE_KEY_FOR_TESTING_ONLY_fake12345", // gitleaks:allow
448448
];
449449

450450
let mut total_count = 0;
@@ -583,7 +583,7 @@ mod tests {
583583
// Test that findings accumulate correctly across multiple values
584584
let secrets = vec![
585585
"AKIAFAKE12345EXAMPLE",
586-
"AIzaFAKE_KEY_FOR_TESTING_ONLY_fake12345",
586+
"AIzaFAKE_KEY_FOR_TESTING_ONLY_fake12345", // gitleaks:allow
587587
"xoxr-fake-000000000-fake000000000-fakefakefakefake",
588588
];
589589

@@ -609,7 +609,7 @@ mod tests {
609609
..Default::default()
610610
};
611611

612-
let text = "AWS: AKIAFAKE12345EXAMPLE Google: AIzaFAKE_KEY_FOR_TESTING_ONLY_fake12345";
612+
let text = "AWS: AKIAFAKE12345EXAMPLE Google: AIzaFAKE_KEY_FOR_TESTING_ONLY_fake12345"; // gitleaks:allow
613613
let (findings, redacted) = detect_and_redact(text, &cfg);
614614

615615
// AWS pattern is disabled, so it should not be detected
@@ -635,7 +635,7 @@ mod tests {
635635
..Default::default()
636636
};
637637

638-
let text = "AKIAFAKE12345EXAMPLE AIzaFAKE_KEY_FOR_TESTING_ONLY_fake12345";
638+
let text = "AKIAFAKE12345EXAMPLE AIzaFAKE_KEY_FOR_TESTING_ONLY_fake12345"; // gitleaks:allow
639639
let (findings, redacted) = detect_and_redact(text, &cfg);
640640

641641
// No patterns enabled, so no findings
@@ -692,7 +692,7 @@ mod tests {
692692
..Default::default()
693693
};
694694

695-
let text = "Google: AIzaFAKE_KEY_FOR_TESTING_ONLY_fake12345";
695+
let text = "Google: AIzaFAKE_KEY_FOR_TESTING_ONLY_fake12345"; // gitleaks:allow
696696
let (findings, redacted) = detect_and_redact(text, &cfg);
697697

698698
// google_api_key is not in enabled map, so it should default to true (enabled)
@@ -732,7 +732,7 @@ mod tests {
732732
};
733733

734734
// A base64 string that might also match hex pattern
735-
let text = "secret=SGVsbG8gV29ybGQgdGhpcyBpcyBhIGxvbmcgYmFzZTY0IGVuY29kZWQgc3RyaW5n";
735+
let text = "secret=SGVsbG8gV29ybGQgdGhpcyBpcyBhIGxvbmcgYmFzZTY0IGVuY29kZWQgc3RyaW5n"; // gitleaks:allow
736736
let (findings, redacted) = detect_and_redact(text, &cfg);
737737

738738
// Should detect at least one pattern

tests/unit/plugins/test_secrets_detection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ def test_detects_google_api_key(self, use_rust):
278278
from plugins.secrets_detection.secrets_detection import SecretsDetectionConfig, _scan_container
279279

280280
config = SecretsDetectionConfig()
281-
data = {"message": "AIzaFAKE_KEY_FOR_TESTING_ONLY_fake12345"}
281+
data = {"message": "AIzaFAKE_KEY_FOR_TESTING_ONLY_fake12345"} # gitleaks:allow
282282

283283
count, _redacted, findings = _scan_container(data, config, use_rust=use_rust)
284284

0 commit comments

Comments
 (0)