()
| 383 | |
| 384 | #[test] |
| 385 | fn roundtrip_encryption() { |
| 386 | let name = "encrypted"; |
| 387 | let unencrypted_value = "tamper-proof"; |
| 388 | let processor: Processor = ProcessorConfig { |
| 389 | crypto_rules: vec![CryptoRule { |
| 390 | cookie_names: vec![name.to_string()], |
| 391 | algorithm: CryptoAlgorithm::Encryption, |
| 392 | key: Key::generate(), |
| 393 | fallbacks: vec![], |
| 394 | }], |
| 395 | ..Default::default() |
| 396 | } |
| 397 | .into(); |
| 398 | |
| 399 | assert!(processor.will_encrypt(name)); |
| 400 | assert!(!processor.will_sign(name)); |
| 401 | |
| 402 | let cookie = ResponseCookie::new(name, unencrypted_value); |
| 403 | let encrypted_cookie = processor.process_outgoing(cookie); |
| 404 | assert_ne!(encrypted_cookie.value(), unencrypted_value); |
| 405 | // The encrypted value should be safe to use in a cookie. |
| 406 | assert_eq!( |
| 407 | encode(encrypted_cookie.value()).to_string(), |
| 408 | encrypted_cookie.value() |
| 409 | ); |
| 410 | |
| 411 | let header = format!("{}={}", encrypted_cookie.name(), encrypted_cookie.value()); |
| 412 | let request_cookies = RequestCookies::parse_header(&header, &processor) |
| 413 | .expect("Failed to parse the encrypted cookie"); |
| 414 | let decrypted_cookie = request_cookies |
| 415 | .get(name) |
| 416 | .expect("Failed to get the decrypted cookie"); |
| 417 | |
| 418 | assert_eq!(decrypted_cookie.name(), name); |
| 419 | assert_eq!(decrypted_cookie.value(), unencrypted_value); |
| 420 | } |
| 421 | |
| 422 | #[test] |
| 423 | fn roundtrip_signing() { |
nothing calls this directly
no test coverage detected