Mercurial > crates > nonstick
annotate testharness/src/bin/testharness.rs @ 173:46e8ce5cd5d1
Miscellaneous doc and code cleanups.
author | Paul Fisher <paul@pfish.zone> |
---|---|
date | Tue, 29 Jul 2025 16:52:32 -0400 |
parents | 6727cbe56f4a |
children | a8c814843ccb |
rev | line source |
---|---|
104
a2676475e86b
Create the very start of a test suite.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
1 //! The actual program which runs the tests. |
a2676475e86b
Create the very start of a test suite.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
2 |
163
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
3 use nonstick::conv::Exchange; |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
4 use nonstick::items::Items; |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
5 use nonstick::libpam::TransactionBuilder; |
172
6727cbe56f4a
Test environment variable setting; minor cleanup.
Paul Fisher <paul@pfish.zone>
parents:
171
diff
changeset
|
6 use nonstick::EnvironMap; |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
163
diff
changeset
|
7 use nonstick::{ |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
163
diff
changeset
|
8 AuthnFlags, AuthtokFlags, Conversation, ErrorCode, LibPamTransaction, PamShared, Transaction, |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
163
diff
changeset
|
9 }; |
163
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
10 use std::cell::Cell; |
172
6727cbe56f4a
Test environment variable setting; minor cleanup.
Paul Fisher <paul@pfish.zone>
parents:
171
diff
changeset
|
11 use std::collections::HashMap; |
163
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
12 use std::ffi::OsString; |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
13 use std::os::unix::ffi::OsStrExt; |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
14 |
173
46e8ce5cd5d1
Miscellaneous doc and code cleanups.
Paul Fisher <paul@pfish.zone>
parents:
172
diff
changeset
|
15 macro_rules! run { |
46e8ce5cd5d1
Miscellaneous doc and code cleanups.
Paul Fisher <paul@pfish.zone>
parents:
172
diff
changeset
|
16 ($x:expr) => { |
46e8ce5cd5d1
Miscellaneous doc and code cleanups.
Paul Fisher <paul@pfish.zone>
parents:
172
diff
changeset
|
17 eprintln!("START {}", stringify!($x)); |
46e8ce5cd5d1
Miscellaneous doc and code cleanups.
Paul Fisher <paul@pfish.zone>
parents:
172
diff
changeset
|
18 $x; |
46e8ce5cd5d1
Miscellaneous doc and code cleanups.
Paul Fisher <paul@pfish.zone>
parents:
172
diff
changeset
|
19 eprintln!("..END {}", stringify!($x)); |
46e8ce5cd5d1
Miscellaneous doc and code cleanups.
Paul Fisher <paul@pfish.zone>
parents:
172
diff
changeset
|
20 }; |
46e8ce5cd5d1
Miscellaneous doc and code cleanups.
Paul Fisher <paul@pfish.zone>
parents:
172
diff
changeset
|
21 } |
46e8ce5cd5d1
Miscellaneous doc and code cleanups.
Paul Fisher <paul@pfish.zone>
parents:
172
diff
changeset
|
22 |
163
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
23 fn main() { |
173
46e8ce5cd5d1
Miscellaneous doc and code cleanups.
Paul Fisher <paul@pfish.zone>
parents:
172
diff
changeset
|
24 run!(test_wrong_user()); |
46e8ce5cd5d1
Miscellaneous doc and code cleanups.
Paul Fisher <paul@pfish.zone>
parents:
172
diff
changeset
|
25 run!(test_wrong_password()); |
46e8ce5cd5d1
Miscellaneous doc and code cleanups.
Paul Fisher <paul@pfish.zone>
parents:
172
diff
changeset
|
26 run!(test_correct()); |
163
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
27 } |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
28 |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
29 #[derive(Debug, Default)] |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
30 struct TestHarness { |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
31 username_requested: Cell<bool>, |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
32 wrong_username: bool, |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
33 wrong_password: bool, |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
34 changing_password: Cell<bool>, |
171
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
167
diff
changeset
|
35 change_prompt_count: Cell<usize>, |
163
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
36 } |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
37 |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
38 impl Conversation for &TestHarness { |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
39 fn communicate(&self, messages: &[Exchange]) { |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
40 if let [only_msg] = messages { |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
41 match only_msg { |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
42 Exchange::Prompt(p) => { |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
43 if self.username_requested.get() { |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
44 panic!("username already requested!") |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
45 } |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
46 if self.wrong_username { |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
47 p.set_answer(Ok(OsString::from("not-right"))) |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
48 } else { |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
49 p.set_answer(Ok(OsString::from("initial"))) |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
50 } |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
51 self.username_requested.set(true) |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
52 } |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
53 Exchange::MaskedPrompt(p) => { |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
54 let answer = if self.changing_password.get() { |
171
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
167
diff
changeset
|
55 let prompt_count = self.change_prompt_count.get(); |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
167
diff
changeset
|
56 self.change_prompt_count.set(prompt_count + 1); |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
167
diff
changeset
|
57 // When changing passwords after logging in, Sun PAM |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
167
diff
changeset
|
58 // uses the existing authtok that was just entered as |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
167
diff
changeset
|
59 // the old_authtok. Other PAMs prompt the user to enter |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
167
diff
changeset
|
60 // their existing password again. |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
167
diff
changeset
|
61 let responses: &[&str] = if cfg!(pam_impl = "Sun") { |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
167
diff
changeset
|
62 &["mistake", "mismatch", "acceptable", "acceptable"] |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
167
diff
changeset
|
63 } else { |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
167
diff
changeset
|
64 &[ |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
167
diff
changeset
|
65 "old token!", |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
167
diff
changeset
|
66 "mistake", |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
167
diff
changeset
|
67 "mismatch", |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
167
diff
changeset
|
68 "old token!", |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
167
diff
changeset
|
69 "acceptable", |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
167
diff
changeset
|
70 "acceptable", |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
167
diff
changeset
|
71 ] |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
167
diff
changeset
|
72 }; |
e27c5c667a5a
Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents:
167
diff
changeset
|
73 responses[prompt_count] |
163
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
74 } else if self.wrong_password { |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
75 "bogus" |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
76 } else { |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
77 "valid" |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
78 }; |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
79 p.set_answer(Ok(OsString::from(answer))); |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
80 } |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
81 Exchange::Error(e) if self.changing_password.get() => e.set_answer(Ok(())), |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
82 other => panic!("Unknown message {other:?}!"), |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
83 } |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
84 } else { |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
85 for msg in messages { |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
86 match msg { |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
87 Exchange::Info(i) => i.set_answer(Ok(())), |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
88 Exchange::Error(e) => e.set_answer(Ok(())), |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
89 Exchange::Prompt(p) => match p.question().as_bytes() { |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
90 b"How many?" => p.set_answer(Ok(OsString::from("123"))), |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
91 _ => p.set_answer(Err(ErrorCode::ConversationError)), |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
92 }, |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
93 Exchange::MaskedPrompt(p) => match p.question().as_bytes() { |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
94 b"Where?" => p.set_answer(Ok(OsString::from("abc"))), |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
95 _ => p.set_answer(Err(ErrorCode::ConversationError)), |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
96 }, |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
97 other => other.set_error(ErrorCode::Abort), |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
98 } |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
99 } |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
100 } |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
101 } |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
102 } |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
103 |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
104 impl TestHarness { |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
105 fn start(&self) -> LibPamTransaction<&Self> { |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
106 TransactionBuilder::new_with_service("nonstick-testharness") |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
107 .build(self) |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
108 .expect("expected build success") |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
109 } |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
110 } |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
111 |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
112 fn test_wrong_user() { |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
113 let harness = TestHarness { |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
114 wrong_username: true, |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
115 ..Default::default() |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
116 }; |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
117 let mut tx = harness.start(); |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
163
diff
changeset
|
118 let auth = tx.authenticate(AuthnFlags::empty()); |
163
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
119 assert_eq!(auth, Err(ErrorCode::UserUnknown)); |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
120 } |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
121 |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
122 fn test_wrong_password() { |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
123 let harness = TestHarness { |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
124 wrong_password: true, |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
125 ..Default::default() |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
126 }; |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
127 let mut tx = harness.start(); |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
163
diff
changeset
|
128 let auth = tx.authenticate(AuthnFlags::empty()); |
163
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
129 assert_eq!(auth, Err(ErrorCode::AuthenticationError)); |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
130 } |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
131 |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
132 fn test_correct() { |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
133 let harness = TestHarness::default(); |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
134 let mut tx = harness.start(); |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
163
diff
changeset
|
135 tx.authenticate(AuthnFlags::empty()).unwrap(); |
163
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
136 assert_eq!(tx.items().user().unwrap().unwrap(), "updated-in-process"); |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
163
diff
changeset
|
137 let result = tx.account_management(AuthnFlags::empty()); |
163
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
138 assert_eq!(result, Err(ErrorCode::NewAuthTokRequired)); |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
139 harness.changing_password.set(true); |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
163
diff
changeset
|
140 let change = tx.change_authtok(AuthtokFlags::CHANGE_EXPIRED_AUTHTOK); |
163
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
141 assert_eq!(change, Err(ErrorCode::TryAgain)); |
166
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
163
diff
changeset
|
142 tx.change_authtok(AuthtokFlags::CHANGE_EXPIRED_AUTHTOK) |
2f5913131295
Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents:
163
diff
changeset
|
143 .unwrap(); |
172
6727cbe56f4a
Test environment variable setting; minor cleanup.
Paul Fisher <paul@pfish.zone>
parents:
171
diff
changeset
|
144 let environ: HashMap<_, _> = tx.environ().iter().collect(); |
6727cbe56f4a
Test environment variable setting; minor cleanup.
Paul Fisher <paul@pfish.zone>
parents:
171
diff
changeset
|
145 assert_eq!( |
6727cbe56f4a
Test environment variable setting; minor cleanup.
Paul Fisher <paul@pfish.zone>
parents:
171
diff
changeset
|
146 environ, |
6727cbe56f4a
Test environment variable setting; minor cleanup.
Paul Fisher <paul@pfish.zone>
parents:
171
diff
changeset
|
147 HashMap::from([("nin".into(), "nine inch nails".into())]) |
6727cbe56f4a
Test environment variable setting; minor cleanup.
Paul Fisher <paul@pfish.zone>
parents:
171
diff
changeset
|
148 ); |
163
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
104
diff
changeset
|
149 } |