Secret-refusal tests build their key-shaped values at run time
So no whole key-shaped string sits in the source for secret scanners to flag. The values were never real keys.
1 file+14−110/1 viewed
| 674 | 674 | ||
| 675 | 675 | #[test] | |
| 676 | 676 | fn credentials_are_refused() { | |
| 677 | + | // Key-shaped values are joined at run time: no whole key sits in the | |
| 678 | + | // source for secret scanners to flag. | |
| 679 | + | let join = |a: &str, b: &str| format!("{a}{b}"); | |
| 677 | 680 | for text in [ | |
| 678 | − | "The key is sk-ant-api03-abcdefghijklmnopqrstuvwxyz", | |
| 679 | − | "use ghp_abcdefghijklmnopqrstuvwxyz0123456789 to clone", | |
| 680 | − | "AWS: AKIAIOSFODNN7EXAMPLE", | |
| 681 | − | "STRIPE_KEY=sk_live_51HabcdefghijklmnopQRSTUV", | |
| 682 | − | "password = hunter2hunter2", | |
| 683 | − | "db: postgres://admin:s3cret@db.internal:5432/app", | |
| 684 | − | "token is 3f9a8b7c6d5e4f3a2b1c0d9e8f7a6b5c4d3e2f1a0b9c8d7e6f5a4b3c2d1e0f9a", | |
| 685 | − | "-----BEGIN RSA PRIVATE KEY-----\nMIIE...", | |
| 686 | − | "secret: Zq8wN3vR7tY2uI5oP1aS6dF4gH9jK0lX", | |
| 687 | − | "it is xK9mQ2vL8nR4tP7wZ3yB6cF1dG5hJ0sA", | |
| 681 | + | join("The key is sk-", "ant-api03-abcdefghijklmnopqrstuvwxyz"), | |
| 682 | + | join("use gh", "p_abcdefghijklmnopqrstuvwxyz0123456789 to clone"), | |
| 683 | + | join("AWS: AK", "IAIOSFODNN7EXAMPLE"), | |
| 684 | + | join("STRIPE_KEY=sk_l", "ive_51HabcdefghijklmnopQRSTUV"), | |
| 685 | + | "password = hunter2hunter2".to_owned(), | |
| 686 | + | "db: postgres://admin:s3cret@db.internal:5432/app".to_owned(), | |
| 687 | + | "token is 3f9a8b7c6d5e4f3a2b1c0d9e8f7a6b5c4d3e2f1a0b9c8d7e6f5a4b3c2d1e0f9a".to_owned(), | |
| 688 | + | "-----BEGIN RSA PRIVATE KEY-----\nMIIE...".to_owned(), | |
| 689 | + | "secret: Zq8wN3vR7tY2uI5oP1aS6dF4gH9jK0lX".to_owned(), | |
| 690 | + | "it is xK9mQ2vL8nR4tP7wZ3yB6cF1dG5hJ0sA".to_owned(), | |
| 688 | 691 | ] { | |
| 689 | − | assert!(secret_in(text).is_some(), "{text}"); | |
| 692 | + | assert!(secret_in(&text).is_some(), "{text}"); | |
| 690 | 693 | } | |
| 691 | 694 | } | |
| 692 | 695 |