()
| 156 | |
| 157 | #[test] |
| 158 | fn test_secure_preferences() -> Result<()> { |
| 159 | let test_dir = setup_test_dir(); |
| 160 | |
| 161 | let prefs = PreferenceConfig::new(test_dir.clone())?; |
| 162 | |
| 163 | // Create secure test data with distinctive content that would be easy to spot in plaintext |
| 164 | let secure_data = SecureTestData { |
| 165 | username: "user123".to_string(), |
| 166 | password: "VERY_DISTINCTIVE_PASSWORD_STRING_FOR_TESTING".to_string(), |
| 167 | }; |
| 168 | |
| 169 | // Save secure data |
| 170 | prefs.set_secure("secure_key".to_string(), Some(secure_data.clone()))?; |
| 171 | |
| 172 | // Get the path to the config file |
| 173 | let config_file_path = prefs.config_file.lock().unwrap().clone(); |
| 174 | |
| 175 | // Read the raw file content to check if it contains the plaintext password |
| 176 | let raw_file_content = fs::read_to_string(&config_file_path)?; |
| 177 | |
| 178 | // Verify the file doesn't contain the plaintext password |
| 179 | assert!( |
| 180 | !raw_file_content.contains(&secure_data.password), |
| 181 | "Config file should not contain plaintext password" |
| 182 | ); |
| 183 | |
| 184 | // Optional: Print file content for debugging |
| 185 | // println!("File content: {}", raw_file_content); |
| 186 | |
| 187 | // Verify the file does contain some reference to the secure key |
| 188 | assert!( |
| 189 | raw_file_content.contains("secure_key"), |
| 190 | "Config file should contain reference to the secure key" |
| 191 | ); |
| 192 | |
| 193 | // Load secure data using the API |
| 194 | let loaded_secure: SecureTestData = prefs.get_secure("secure_key".to_string())?; |
| 195 | |
| 196 | // Verify secure data can be correctly decrypted and loaded |
| 197 | assert_eq!( |
| 198 | loaded_secure.username, secure_data.username, |
| 199 | "Username should match" |
| 200 | ); |
| 201 | assert_eq!( |
| 202 | loaded_secure.password, secure_data.password, |
| 203 | "Password should match" |
| 204 | ); |
| 205 | |
| 206 | cleanup_test_dir(test_dir); |
| 207 | Ok(()) |
| 208 | } |
| 209 | |
| 210 | #[test] |
| 211 | fn test_update_preferences() -> Result<()> { |
nothing calls this directly
no test coverage detected