Skip to main content

reinhardt_testkit/auth/
error.rs

1use thiserror::Error;
2
3/// Errors that can occur during test authentication setup.
4#[derive(Debug, Error)]
5pub enum TestAuthError {
6	/// Failed to create or save a session.
7	#[error("session backend error: {0}")]
8	SessionError(String),
9	/// Failed to sign or create a JWT.
10	#[error("JWT signing error: {0}")]
11	JwtError(String),
12	/// A secondary auth layer (e.g., MFA) failed.
13	#[error("secondary auth error: {0}")]
14	SecondaryAuthError(String),
15	/// No primary auth method was configured before calling apply().
16	#[error("no primary auth configured")]
17	NoPrimaryAuth,
18	/// The user is not registered with the MFA manager.
19	#[error("MFA user not registered: {0}")]
20	MfaUserNotRegistered(String),
21	/// An error occurred on the APIClient (e.g., setting a header or cookie).
22	#[error("client error: {0}")]
23	ClientError(String),
24}
25
26#[cfg(test)]
27mod tests {
28	use super::*;
29	use rstest::*;
30
31	#[rstest]
32	#[case(TestAuthError::SessionError("timeout".into()), "session backend error: timeout")]
33	#[case(TestAuthError::JwtError("bad key".into()), "JWT signing error: bad key")]
34	#[case(TestAuthError::NoPrimaryAuth, "no primary auth configured")]
35	#[case(TestAuthError::MfaUserNotRegistered("alice".into()), "MFA user not registered: alice")]
36	#[case(TestAuthError::ClientError("header fail".into()), "client error: header fail")]
37	fn display_formats(#[case] error: TestAuthError, #[case] expected: &str) {
38		assert_eq!(error.to_string(), expected);
39	}
40}