Mercurial > crates > nonstick
comparison testharness/src/bin/testharness.rs @ 172:6727cbe56f4a
Test environment variable setting; minor cleanup.
| author | Paul Fisher <paul@pfish.zone> |
|---|---|
| date | Fri, 25 Jul 2025 21:02:53 -0400 |
| parents | e27c5c667a5a |
| children | 46e8ce5cd5d1 |
comparison
equal
deleted
inserted
replaced
| 171:e27c5c667a5a | 172:6727cbe56f4a |
|---|---|
| 1 //! The actual program which runs the tests. | 1 //! The actual program which runs the tests. |
| 2 | 2 |
| 3 use nonstick::conv::Exchange; | 3 use nonstick::conv::Exchange; |
| 4 use nonstick::items::Items; | 4 use nonstick::items::Items; |
| 5 use nonstick::libpam::TransactionBuilder; | 5 use nonstick::libpam::TransactionBuilder; |
| 6 use nonstick::EnvironMap; | |
| 6 use nonstick::{ | 7 use nonstick::{ |
| 7 AuthnFlags, AuthtokFlags, Conversation, ErrorCode, LibPamTransaction, PamShared, Transaction, | 8 AuthnFlags, AuthtokFlags, Conversation, ErrorCode, LibPamTransaction, PamShared, Transaction, |
| 8 }; | 9 }; |
| 9 use std::cell::Cell; | 10 use std::cell::Cell; |
| 11 use std::collections::HashMap; | |
| 10 use std::ffi::OsString; | 12 use std::ffi::OsString; |
| 11 use std::os::unix::ffi::OsStrExt; | 13 use std::os::unix::ffi::OsStrExt; |
| 12 | 14 |
| 13 fn main() { | 15 fn main() { |
| 14 test_wrong_user(); | 16 test_wrong_user(); |
| 41 self.username_requested.set(true) | 43 self.username_requested.set(true) |
| 42 } | 44 } |
| 43 Exchange::MaskedPrompt(p) => { | 45 Exchange::MaskedPrompt(p) => { |
| 44 let answer = if self.changing_password.get() { | 46 let answer = if self.changing_password.get() { |
| 45 let prompt_count = self.change_prompt_count.get(); | 47 let prompt_count = self.change_prompt_count.get(); |
| 46 eprintln!("CHANGING PASSWORD PROMPT {prompt_count}"); | |
| 47 eprintln!("-> {p:?}"); | |
| 48 self.change_prompt_count.set(prompt_count + 1); | 48 self.change_prompt_count.set(prompt_count + 1); |
| 49 // When changing passwords after logging in, Sun PAM | 49 // When changing passwords after logging in, Sun PAM |
| 50 // uses the existing authtok that was just entered as | 50 // uses the existing authtok that was just entered as |
| 51 // the old_authtok. Other PAMs prompt the user to enter | 51 // the old_authtok. Other PAMs prompt the user to enter |
| 52 // their existing password again. | 52 // their existing password again. |
| 131 harness.changing_password.set(true); | 131 harness.changing_password.set(true); |
| 132 let change = tx.change_authtok(AuthtokFlags::CHANGE_EXPIRED_AUTHTOK); | 132 let change = tx.change_authtok(AuthtokFlags::CHANGE_EXPIRED_AUTHTOK); |
| 133 assert_eq!(change, Err(ErrorCode::TryAgain)); | 133 assert_eq!(change, Err(ErrorCode::TryAgain)); |
| 134 tx.change_authtok(AuthtokFlags::CHANGE_EXPIRED_AUTHTOK) | 134 tx.change_authtok(AuthtokFlags::CHANGE_EXPIRED_AUTHTOK) |
| 135 .unwrap(); | 135 .unwrap(); |
| 136 let environ: HashMap<_, _> = tx.environ().iter().collect(); | |
| 137 assert_eq!( | |
| 138 environ, | |
| 139 HashMap::from([("nin".into(), "nine inch nails".into())]) | |
| 140 ); | |
| 136 } | 141 } |
