annotate testharness/src/bin/testharness.rs @ 189:b2456d274576 default tip

Add line breaks that rustfmt ate back to documentation.
author Paul Fisher <paul@pfish.zone>
date Thu, 31 Jul 2025 15:42:12 -0400
parents 42f747774d94
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
184
42f747774d94 Really get documentation stuff squared away.
Paul Fisher <paul@pfish.zone>
parents: 181
diff changeset
1 //! Test program to interact with PAM and `../lib.rs` to ensure that nonstick
42f747774d94 Really get documentation stuff squared away.
Paul Fisher <paul@pfish.zone>
parents: 181
diff changeset
2 //! does everything right.
104
a2676475e86b Create the very start of a test suite.
Paul Fisher <paul@pfish.zone>
parents:
diff changeset
3
163
a75a66cb4181 Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents: 104
diff changeset
4 use nonstick::conv::Exchange;
a75a66cb4181 Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents: 104
diff changeset
5 use nonstick::items::Items;
a75a66cb4181 Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents: 104
diff changeset
6 use nonstick::libpam::TransactionBuilder;
172
6727cbe56f4a Test environment variable setting; minor cleanup.
Paul Fisher <paul@pfish.zone>
parents: 171
diff changeset
7 use nonstick::EnvironMap;
166
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 163
diff changeset
8 use nonstick::{
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 163
diff changeset
9 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
10 };
163
a75a66cb4181 Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents: 104
diff changeset
11 use std::cell::Cell;
172
6727cbe56f4a Test environment variable setting; minor cleanup.
Paul Fisher <paul@pfish.zone>
parents: 171
diff changeset
12 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
13 use std::ffi::OsString;
a75a66cb4181 Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents: 104
diff changeset
14 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
15
173
46e8ce5cd5d1 Miscellaneous doc and code cleanups.
Paul Fisher <paul@pfish.zone>
parents: 172
diff changeset
16 macro_rules! run {
46e8ce5cd5d1 Miscellaneous doc and code cleanups.
Paul Fisher <paul@pfish.zone>
parents: 172
diff changeset
17 ($x:expr) => {
46e8ce5cd5d1 Miscellaneous doc and code cleanups.
Paul Fisher <paul@pfish.zone>
parents: 172
diff changeset
18 eprintln!("START {}", stringify!($x));
46e8ce5cd5d1 Miscellaneous doc and code cleanups.
Paul Fisher <paul@pfish.zone>
parents: 172
diff changeset
19 $x;
46e8ce5cd5d1 Miscellaneous doc and code cleanups.
Paul Fisher <paul@pfish.zone>
parents: 172
diff changeset
20 eprintln!("..END {}", stringify!($x));
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 }
46e8ce5cd5d1 Miscellaneous doc and code cleanups.
Paul Fisher <paul@pfish.zone>
parents: 172
diff changeset
23
163
a75a66cb4181 Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents: 104
diff changeset
24 fn main() {
173
46e8ce5cd5d1 Miscellaneous doc and code cleanups.
Paul Fisher <paul@pfish.zone>
parents: 172
diff changeset
25 run!(test_wrong_user());
46e8ce5cd5d1 Miscellaneous doc and code cleanups.
Paul Fisher <paul@pfish.zone>
parents: 172
diff changeset
26 run!(test_wrong_password());
46e8ce5cd5d1 Miscellaneous doc and code cleanups.
Paul Fisher <paul@pfish.zone>
parents: 172
diff changeset
27 run!(test_correct());
163
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
a75a66cb4181 Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents: 104
diff changeset
30 #[derive(Debug, Default)]
a75a66cb4181 Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents: 104
diff changeset
31 struct TestHarness {
a75a66cb4181 Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents: 104
diff changeset
32 username_requested: Cell<bool>,
a75a66cb4181 Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents: 104
diff changeset
33 wrong_username: bool,
a75a66cb4181 Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents: 104
diff changeset
34 wrong_password: bool,
a75a66cb4181 Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents: 104
diff changeset
35 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
36 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
37 }
a75a66cb4181 Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents: 104
diff changeset
38
a75a66cb4181 Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents: 104
diff changeset
39 impl Conversation for &TestHarness {
a75a66cb4181 Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents: 104
diff changeset
40 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
41 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
42 match only_msg {
a75a66cb4181 Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents: 104
diff changeset
43 Exchange::Prompt(p) => {
a75a66cb4181 Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents: 104
diff changeset
44 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
45 panic!("username already requested!")
a75a66cb4181 Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents: 104
diff changeset
46 }
a75a66cb4181 Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents: 104
diff changeset
47 if self.wrong_username {
a75a66cb4181 Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents: 104
diff changeset
48 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
49 } else {
a75a66cb4181 Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents: 104
diff changeset
50 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
51 }
a75a66cb4181 Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents: 104
diff changeset
52 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
53 }
a75a66cb4181 Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents: 104
diff changeset
54 Exchange::MaskedPrompt(p) => {
a75a66cb4181 Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents: 104
diff changeset
55 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
56 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
57 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
58 // 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
59 // 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
60 // 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
61 // 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
62 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
63 &["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
64 } else {
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 167
diff changeset
65 &[
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 167
diff changeset
66 "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
67 "mistake",
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 167
diff changeset
68 "mismatch",
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 167
diff changeset
69 "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
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 "acceptable",
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 };
e27c5c667a5a Create full new types for return code and flags, separate end to end.
Paul Fisher <paul@pfish.zone>
parents: 167
diff changeset
74 responses[prompt_count]
163
a75a66cb4181 Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents: 104
diff changeset
75 } 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
76 "bogus"
a75a66cb4181 Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents: 104
diff changeset
77 } else {
a75a66cb4181 Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents: 104
diff changeset
78 "valid"
a75a66cb4181 Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents: 104
diff changeset
79 };
a75a66cb4181 Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents: 104
diff changeset
80 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
81 }
a75a66cb4181 Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents: 104
diff changeset
82 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
83 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
84 }
a75a66cb4181 Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents: 104
diff changeset
85 } else {
a75a66cb4181 Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents: 104
diff changeset
86 for msg in messages {
a75a66cb4181 Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents: 104
diff changeset
87 match msg {
a75a66cb4181 Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents: 104
diff changeset
88 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
89 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
90 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
91 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
92 _ => 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
93 },
a75a66cb4181 Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents: 104
diff changeset
94 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
95 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
96 _ => 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
97 },
a75a66cb4181 Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents: 104
diff changeset
98 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
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
a75a66cb4181 Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents: 104
diff changeset
105 impl TestHarness {
a75a66cb4181 Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents: 104
diff changeset
106 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
107 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
108 .build(self)
a75a66cb4181 Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents: 104
diff changeset
109 .expect("expected build success")
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
a75a66cb4181 Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents: 104
diff changeset
113 fn test_wrong_user() {
a75a66cb4181 Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents: 104
diff changeset
114 let harness = TestHarness {
a75a66cb4181 Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents: 104
diff changeset
115 wrong_username: true,
a75a66cb4181 Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents: 104
diff changeset
116 ..Default::default()
a75a66cb4181 Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents: 104
diff changeset
117 };
a75a66cb4181 Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents: 104
diff changeset
118 let mut tx = harness.start();
166
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 163
diff changeset
119 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
120 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
121 }
a75a66cb4181 Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents: 104
diff changeset
122
a75a66cb4181 Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents: 104
diff changeset
123 fn test_wrong_password() {
a75a66cb4181 Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents: 104
diff changeset
124 let harness = TestHarness {
a75a66cb4181 Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents: 104
diff changeset
125 wrong_password: true,
a75a66cb4181 Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents: 104
diff changeset
126 ..Default::default()
a75a66cb4181 Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents: 104
diff changeset
127 };
a75a66cb4181 Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents: 104
diff changeset
128 let mut tx = harness.start();
166
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 163
diff changeset
129 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
130 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
131 }
a75a66cb4181 Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents: 104
diff changeset
132
a75a66cb4181 Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents: 104
diff changeset
133 fn test_correct() {
a75a66cb4181 Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents: 104
diff changeset
134 let harness = TestHarness::default();
a75a66cb4181 Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents: 104
diff changeset
135 let mut tx = harness.start();
166
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 163
diff changeset
136 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
137 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
138 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
139 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
140 harness.changing_password.set(true);
166
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 163
diff changeset
141 let change = tx.change_authtok(AuthtokFlags::CHANGE_EXPIRED_AUTHTOK);
181
a8c814843ccb Update test harness to work with Sun error codes.
Paul Fisher <paul@pfish.zone>
parents: 173
diff changeset
142 if cfg!(pam_impl = "Sun") {
a8c814843ccb Update test harness to work with Sun error codes.
Paul Fisher <paul@pfish.zone>
parents: 173
diff changeset
143 assert!(change.is_err())
a8c814843ccb Update test harness to work with Sun error codes.
Paul Fisher <paul@pfish.zone>
parents: 173
diff changeset
144 } else {
a8c814843ccb Update test harness to work with Sun error codes.
Paul Fisher <paul@pfish.zone>
parents: 173
diff changeset
145 assert_eq!(change, Err(ErrorCode::TryAgain));
a8c814843ccb Update test harness to work with Sun error codes.
Paul Fisher <paul@pfish.zone>
parents: 173
diff changeset
146 }
166
2f5913131295 Separate flag/action flags into flags and action.
Paul Fisher <paul@pfish.zone>
parents: 163
diff changeset
147 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
148 .unwrap();
172
6727cbe56f4a Test environment variable setting; minor cleanup.
Paul Fisher <paul@pfish.zone>
parents: 171
diff changeset
149 let environ: HashMap<_, _> = tx.environ().iter().collect();
6727cbe56f4a Test environment variable setting; minor cleanup.
Paul Fisher <paul@pfish.zone>
parents: 171
diff changeset
150 assert_eq!(
6727cbe56f4a Test environment variable setting; minor cleanup.
Paul Fisher <paul@pfish.zone>
parents: 171
diff changeset
151 environ,
6727cbe56f4a Test environment variable setting; minor cleanup.
Paul Fisher <paul@pfish.zone>
parents: 171
diff changeset
152 HashMap::from([("nin".into(), "nine inch nails".into())])
6727cbe56f4a Test environment variable setting; minor cleanup.
Paul Fisher <paul@pfish.zone>
parents: 171
diff changeset
153 );
163
a75a66cb4181 Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents: 104
diff changeset
154 }