|
2 | 2 | use log::{debug, error, info, trace, warn, log, Level};
|
3 | 3 | use std::io::Write as _;
|
4 | 4 | use std::fmt::Write as _;
|
| 5 | +use log_err::{LogErrOption, LogErrResult}; |
5 | 6 |
|
6 | 7 | // --- tests ---
|
7 | 8 |
|
@@ -146,6 +147,32 @@ fn test_log(harmless: String, password: String, encrypted_password: String) {
|
146 | 147 | warn!("message = {}", s2); // (this implementation does not output the password field)
|
147 | 148 | warn!("message = {:?}", s2); // $ MISSING: Alert[rust/cleartext-logging]=s2
|
148 | 149 | warn!("message = {:#?}", s2); // $ MISSING: Alert[rust/cleartext-logging]=s2
|
| 150 | + |
| 151 | + // test log_expect with sensitive data |
| 152 | + let password2 = "123456".to_string(); // Create new password for this test |
| 153 | + let sensitive_opt: Option<String> = Some(password2.clone()); |
| 154 | + |
| 155 | + // log_expect tests with LogErrOption trait |
| 156 | + let _ = sensitive_opt.log_expect("Option is None"); // $ Alert[rust/cleartext-logging] |
| 157 | + |
| 158 | + // log_expect tests with LogErrResult trait |
| 159 | + let sensitive_result: Result<String, &str> = Ok(password2.clone()); |
| 160 | + let _ = sensitive_result.log_expect("Result failed"); // $ Alert[rust/cleartext-logging] |
| 161 | + |
| 162 | + // log_unwrap tests with LogErrOption trait |
| 163 | + let sensitive_opt2: Option<String> = Some(password2.clone()); |
| 164 | + let _ = sensitive_opt2.log_unwrap(); // $ Alert[rust/cleartext-logging] |
| 165 | + |
| 166 | + // log_unwrap tests with LogErrResult trait |
| 167 | + let sensitive_result2: Result<String, &str> = Ok(password2.clone()); |
| 168 | + let _ = sensitive_result2.log_unwrap(); // $ Alert[rust/cleartext-logging] |
| 169 | + |
| 170 | + // Negative cases that should fail and log |
| 171 | + let none_opt: Option<String> = None; |
| 172 | + let _ = none_opt.log_expect(&format!("Failed with password: {}", password2)); // $ Alert[rust/cleartext-logging] |
| 173 | + |
| 174 | + let err_result: Result<String, String> = Err(password2); |
| 175 | + let _ = err_result.log_unwrap(); // $ Alert[rust/cleartext-logging] |
149 | 176 | }
|
150 | 177 |
|
151 | 178 | fn test_std(password: String, i: i32, opt_i: Option<i32>) {
|
|
0 commit comments