From 5f04dc0d87de926ce2fd88e546ce37a8f417ff53 Mon Sep 17 00:00:00 2001 From: piquel Date: Sun, 22 Nov 2026 20:44:12 +0100 Subject: [PATCH] chore(lint): tests show the error they got instead of asserting is_err --- Cargo.toml | 1 + apps/auth-service/src/admin/operator.rs | 2 +- apps/auth-service/src/admin/tests/handles.rs | 10 ++- apps/auth-service/src/admin/types/tests.rs | 4 +- apps/auth-service/src/cli/tests.rs | 4 +- .../src/federation/tests/callback.rs | 3 +- .../src/federation/tests/protocols.rs | 4 +- .../src/federation/tests/signup.rs | 60 ++++++++---------- apps/auth-service/src/keys/tests.rs | 2 +- apps/auth-service/src/oidc/authorize/tests.rs | 4 +- apps/auth-service/src/oidc/tests/protocol.rs | 4 +- .../src/security/tests/forwarding.rs | 5 +- .../src/security/tests/sessions.rs | 2 +- crates/auth-sdk/src/tests.rs | 4 +- crates/common/src/clients/tests.rs | 21 ++++--- crates/common/src/config/tests.rs | 12 ++-- crates/common/src/email/tests.rs | 2 +- crates/common/src/events/tests.rs | 4 +- crates/common/src/tests.rs | 15 ++--- crates/crypto/src/sealing/tests.rs | 5 +- crates/crypto/src/signing/tests.rs | 62 +++++++------------ crates/crypto/src/tests.rs | 32 ++++------ crates/database/src/connection/tests.rs | 4 +- .../database/src/repositories/emails/tests.rs | 22 +++---- 24 files changed, 141 insertions(+), 147 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 16baab021..327afdcd8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -40,6 +40,7 @@ unwrap_used = "warn" expect_used = "warn" panic = "warn" todo = "warn" +assertions_on_result_states = "warn" unimplemented = "warn" dbg_macro = "warn" # Every exception names its lint with `#[expect]` and says why. diff --git a/apps/auth-service/src/admin/operator.rs b/apps/auth-service/src/admin/operator.rs index fbd2f1c28..904c64e4c 100644 --- a/apps/auth-service/src/admin/operator.rs +++ b/apps/auth-service/src/admin/operator.rs @@ -390,6 +390,6 @@ mod tests { assert_eq!(host(Some(" \n"), Ok(Some("env"))).expect("HOSTNAME"), "env"); assert_eq!(host(None, Ok(Some("env"))).expect("HOSTNAME"), "env"); assert_eq!(host(Some(""), Ok(None)).expect("no name"), UNKNOWN); - assert!(host(None, invalid()).is_err()); + host(None, invalid()).expect_err("should be rejected"); } } diff --git a/apps/auth-service/src/admin/tests/handles.rs b/apps/auth-service/src/admin/tests/handles.rs index 5dc4e484b..3e94bf284 100644 --- a/apps/auth-service/src/admin/tests/handles.rs +++ b/apps/auth-service/src/admin/tests/handles.rs @@ -129,7 +129,10 @@ async fn administrators_reserve_handles_until_they_give_them_out() { let look_alike = Handle::parse(&format!("kept{suffix}")).expect("handle"); let handles = crate::handles::Handles::new(&harness.database); let reserved = |result: Result<(), HandlesError>| matches!(result, Err(HandlesError::Refused(HandleError::Reserved(name))) if name == kept.as_str()); - assert!(handles.ensure_unreserved(&kept).await.is_ok()); + handles + .ensure_unreserved(&kept) + .await + .expect("should be accepted"); service .reserve_handle(&cli(), kept.clone(), reason("For the new CTO")) .await @@ -188,7 +191,10 @@ async fn administrators_reserve_handles_until_they_give_them_out() { .await, Err(AdminError::HandleNotReserved) )); - assert!(handles.ensure_unreserved(&kept).await.is_ok()); + handles + .ensure_unreserved(&kept) + .await + .expect("should be accepted"); let problems = service.check_handles(&cli()).await.expect("check"); assert!(!problems.iter().any(|problem| problem.user_id == user)); } diff --git a/apps/auth-service/src/admin/types/tests.rs b/apps/auth-service/src/admin/types/tests.rs index 5705d84bf..73e1d801d 100644 --- a/apps/auth-service/src/admin/types/tests.rs +++ b/apps/auth-service/src/admin/types/tests.rs @@ -79,7 +79,7 @@ fn announcements_go_to_bounded_accounts() { AnnouncementRecipients::Accounts(vec![UserRef::Handle("ada".into()); count]); AnnouncementDraft::new(letter, recipients, false) }; - assert!(draft(1_000).is_ok()); + draft(1_000).expect("should be accepted"); assert!(matches!(draft(0), Err(AdminError::NoRecipients))); assert!(matches!(draft(1_001), Err(AdminError::TooManyRecipients))); } @@ -112,7 +112,7 @@ fn the_form_names_one_account_per_line() { #[test] fn reasons_are_bounded_visible_text() { for valid in ["Spam".to_owned(), "é".repeat(500)] { - assert!(Reason::parse(valid).is_ok()); + Reason::parse(valid).expect("should be accepted"); } for invalid in [String::new(), " \t ".into(), "a\nb".into(), "é".repeat(501)] { assert!(matches!( diff --git a/apps/auth-service/src/cli/tests.rs b/apps/auth-service/src/cli/tests.rs index be2ff4571..d31a41257 100644 --- a/apps/auth-service/src/cli/tests.rs +++ b/apps/auth-service/src/cli/tests.rs @@ -291,8 +291,8 @@ fn confirmation_needs_a_terminal_or_yes() { ask(false, false, "y\n"), Err(CliError::Unconfirmed) )); - assert!(ask(true, false, "").is_ok()); - assert!(ask(false, true, "y\n").is_ok()); + ask(true, false, "").expect("should be accepted"); + ask(false, true, "y\n").expect("should be accepted"); assert!(matches!(ask(false, true, "\n"), Err(CliError::Declined))); assert!(matches!(ask(false, true, "no\n"), Err(CliError::Declined))); } diff --git a/apps/auth-service/src/federation/tests/callback.rs b/apps/auth-service/src/federation/tests/callback.rs index 4b3e92255..ebc6d23b7 100644 --- a/apps/auth-service/src/federation/tests/callback.rs +++ b/apps/auth-service/src/federation/tests/callback.rs @@ -25,7 +25,8 @@ fn return_destinations_and_browser_bindings_are_strict() { ReturnTo::parse(None).expect("default return").0, DEFAULT_RETURN_TO ); - assert!(ReturnTo::parse(Some(&format!("/{}", "x".repeat(MAX_RETURN_TO_BYTES)))).is_err()); + ReturnTo::parse(Some(&format!("/{}", "x".repeat(MAX_RETURN_TO_BYTES)))) + .expect_err("should be rejected"); let secret = Secret::generate().expect("browser secret"); let mut headers = HeaderMap::new(); headers.insert( diff --git a/apps/auth-service/src/federation/tests/protocols.rs b/apps/auth-service/src/federation/tests/protocols.rs index c531bf0a3..289379d36 100644 --- a/apps/auth-service/src/federation/tests/protocols.rs +++ b/apps/auth-service/src/federation/tests/protocols.rs @@ -180,7 +180,7 @@ async fn google_signed_tokens_are_verified() { let token = rsa.sign(TokenType::Id, claims).expect("signed token"); GoogleClaims::verify(&token, &protocol, "client", "nonce").await }; - assert!(verify(&valid).await.is_ok()); + verify(&valid).await.expect("should be accepted"); let untrusted = Rs256Key::generate("google-test").expect("untrusted key"); let token = untrusted.sign(TokenType::Id, &valid).expect("signed token"); assert_eq!( @@ -247,7 +247,7 @@ async fn google_signed_tokens_are_verified() { } let mut claims = valid.clone(); claims["aud"] = serde_json::json!(["client"]); - assert!(verify(&claims).await.is_ok()); + verify(&claims).await.expect("should be accepted"); claims["iss"] = serde_json::json!("https://untrusted.example"); assert!(verify(&claims).await.is_err()); claims = valid; diff --git a/apps/auth-service/src/federation/tests/signup.rs b/apps/auth-service/src/federation/tests/signup.rs index 8033f644f..72b794d0c 100644 --- a/apps/auth-service/src/federation/tests/signup.rs +++ b/apps/auth-service/src/federation/tests/signup.rs @@ -37,31 +37,27 @@ async fn onboarding_commits_only_with_first_key_and_browser_and_never_claims_exi .expect("pending signup"); let user = test.user(None, false).await; let mut tx = test.app.database.begin().await.expect("tx"); - assert!( - test.attach( - &mut tx, - security::RequestContext::TEST.client_ip, - pending.id, - &headers, - user - ) - .await - .is_err() - ); + test.attach( + &mut tx, + security::RequestContext::TEST.client_ip, + pending.id, + &headers, + user, + ) + .await + .expect_err("should be rejected"); tx.rollback().await.expect("rollback"); let mut tx = test.app.database.begin().await.expect("tx"); test.key(&mut tx, user).await; - assert!( - test.attach( - &mut tx, - security::RequestContext::TEST.client_ip, - pending.id, - &HeaderMap::new(), - user - ) - .await - .is_err() - ); + test.attach( + &mut tx, + security::RequestContext::TEST.client_ip, + pending.id, + &HeaderMap::new(), + user, + ) + .await + .expect_err("should be rejected"); test.attach( &mut tx, security::RequestContext::TEST.client_ip, @@ -87,17 +83,15 @@ async fn onboarding_commits_only_with_first_key_and_browser_and_never_claims_exi test.user(Some(&email), true).await; let (pending, headers) = test.pending(None, Some(&email)).await; let mut tx = test.app.database.begin().await.expect("tx"); - assert!( - test.attach( - &mut tx, - security::RequestContext::TEST.client_ip, - pending.id, - &headers, - user - ) - .await - .is_err() - ); + test.attach( + &mut tx, + security::RequestContext::TEST.client_ip, + pending.id, + &headers, + user, + ) + .await + .expect_err("should be rejected"); tx.rollback().await.expect("rollback"); } diff --git a/apps/auth-service/src/keys/tests.rs b/apps/auth-service/src/keys/tests.rs index 53086719e..f272c653f 100644 --- a/apps/auth-service/src/keys/tests.rs +++ b/apps/auth-service/src/keys/tests.rs @@ -668,5 +668,5 @@ async fn a_replica_that_cannot_reload_turns_unready() { assert!(keys.current().is_err(), "a stale key set is not used"); store.reload(&keys).await; assert_eq!(ready().await, StatusCode::NO_CONTENT); - assert!(keys.current().is_ok()); + keys.current().expect("should be accepted"); } diff --git a/apps/auth-service/src/oidc/authorize/tests.rs b/apps/auth-service/src/oidc/authorize/tests.rs index bd00e4f56..48b93beb1 100644 --- a/apps/auth-service/src/oidc/authorize/tests.rs +++ b/apps/auth-service/src/oidc/authorize/tests.rs @@ -17,8 +17,8 @@ fn prompts_enforce_interaction_policy() { let interactive = interaction("login consent select_account login"); assert_eq!(interactive.ok(), Some(Interaction::LoginAndConsent)); assert_eq!(interaction("").ok(), Some(Interaction::AsNeeded)); - assert!(interaction("none login").is_err()); - assert!(interaction("unrecognized").is_err()); + interaction("none login").expect_err("should be rejected"); + interaction("unrecognized").expect_err("should be rejected"); } /// `max_age` holds up to its boundary at authorize too. `0` needs a sign-in after diff --git a/apps/auth-service/src/oidc/tests/protocol.rs b/apps/auth-service/src/oidc/tests/protocol.rs index 65e591144..ece78aaa8 100644 --- a/apps/auth-service/src/oidc/tests/protocol.rs +++ b/apps/auth-service/src/oidc/tests/protocol.rs @@ -182,12 +182,12 @@ fn scope_sets_preserve_existing_wire_semantics() { assert!(scopes.allowed_by(&stored)); assert!(!scopes.allowed_by(&[Scope::OpenId.as_str().into()])); assert_eq!(Scopes::from_stored(&stored), Ok(scopes)); - assert!(Scopes::parse(" ").is_err()); + Scopes::parse(" ").expect_err("should be rejected"); let too_many = (0..=MAX_SCOPES) .map(|index| format!("scope{index}")) .collect::>() .join(" "); - assert!(Scopes::parse(&too_many).is_err()); + Scopes::parse(&too_many).expect_err("should be rejected"); } /// Checks purpose binding, the length bound and exact opaque envelope/secret round diff --git a/apps/auth-service/src/security/tests/forwarding.rs b/apps/auth-service/src/security/tests/forwarding.rs index 2065388d7..61c15ed1c 100644 --- a/apps/auth-service/src/security/tests/forwarding.rs +++ b/apps/auth-service/src/security/tests/forwarding.rs @@ -24,7 +24,10 @@ async fn forwarded_addresses_require_an_explicit_trusted_peer() { "192.0.2.7".parse::().expect("IP") ); request.headers_mut().remove("x-forwarded-for"); - assert!(fixture.policy.client_ip(&request).is_err()); + fixture + .policy + .client_ip(&request) + .expect_err("should be rejected"); } /// Forwarded addresses accept one IP and retain diagnostics for malformed header text or syntax. diff --git a/apps/auth-service/src/security/tests/sessions.rs b/apps/auth-service/src/security/tests/sessions.rs index 3d0164541..f1864c20d 100644 --- a/apps/auth-service/src/security/tests/sessions.rs +++ b/apps/auth-service/src/security/tests/sessions.rs @@ -59,7 +59,7 @@ fn confirmation_age_is_fixed_from_its_timestamp() { last_seen_ip: None, } }; - assert!(Confirmed::::check(&session(Some(290))).is_ok()); + Confirmed::::check(&session(Some(290))).expect("should be accepted"); for age in [None, Some(310), Some(86_400)] { assert!(matches!( Confirmed::::check(&session(age)), diff --git a/crates/auth-sdk/src/tests.rs b/crates/auth-sdk/src/tests.rs index af054b752..207acafc2 100644 --- a/crates/auth-sdk/src/tests.rs +++ b/crates/auth-sdk/src/tests.rs @@ -273,9 +273,9 @@ fn authentication_requirements_follow_auth() { acr: Some(Acr::Social), max_age: None, }; - assert!(check(Acr::PhishingResistant, 0, social).is_ok()); + check(Acr::PhishingResistant, 0, social).expect("should be accepted"); let recent = StepUpRequirement::passkey_within(300); - assert!(check(Acr::PhishingResistant, 330, recent).is_ok()); + check(Acr::PhishingResistant, 330, recent).expect("should be accepted"); assert!(matches!( check(Acr::PhishingResistant, 331, recent), Err(TokenError::InsufficientUserAuthentication(requirement)) if requirement == recent diff --git a/crates/common/src/clients/tests.rs b/crates/common/src/clients/tests.rs index c07960258..f130e4eb8 100644 --- a/crates/common/src/clients/tests.rs +++ b/crates/common/src/clients/tests.rs @@ -14,7 +14,7 @@ fn client_ids_are_bounded_identifiers() { ] { assert_eq!(value.parse::().is_ok(), valid, "{value}"); } - assert!(serde_json::from_str::("\"bad id\"").is_err()); + serde_json::from_str::("\"bad id\"").expect_err("should be rejected"); assert_eq!( "bad id".parse::().expect_err("space").to_string(), "client ID \"bad id\" must be 1 to 64 characters from A-Z, a-z, 0-9, '.', '_' and '-'" @@ -132,16 +132,23 @@ fn related_origins_are_bare_https_domain_origins() { ] { assert_eq!(value.parse::(), Err(expected), "{value}"); } - assert!(serde_json::from_str::("\"https://notes.example/\"").is_err()); + serde_json::from_str::("\"https://notes.example/\"") + .expect_err("should be rejected"); } /// Display names are nonblank and count characters, not bytes; scopes are tokens. #[test] fn names_and_scopes_are_bounded() { - assert!("é".repeat(80).parse::().is_ok()); - assert!("é".repeat(81).parse::().is_err()); - assert!(" ".parse::().is_err()); - assert!("Web\x1b[2J".parse::().is_err()); + "é".repeat(80) + .parse::() + .expect("should be accepted"); + "é".repeat(81) + .parse::() + .expect_err("should be rejected"); + " ".parse::().expect_err("should be rejected"); + "Web\x1b[2J" + .parse::() + .expect_err("should be rejected"); for (value, valid) in [ ("notes:read", true), ("", false), @@ -167,7 +174,7 @@ fn bounded_lists_count_distinct_values() { found: 0 }) ); - assert!(PostLogoutUris::new([]).is_ok()); + PostLogoutUris::new([]).expect("should be accepted"); } /// Generated client IDs are valid IDs with the `c_` prefix and 20 base32 diff --git a/crates/common/src/config/tests.rs b/crates/common/src/config/tests.rs index 2a144e6c2..0fefef64d 100644 --- a/crates/common/src/config/tests.rs +++ b/crates/common/src/config/tests.rs @@ -4,7 +4,9 @@ use super::*; /// Origins reject every insecure or ambiguous component. #[test] fn urls_validate_once() { - assert!("https://auth.sourceorigin.dev".parse::().is_ok()); + "https://auth.sourceorigin.dev" + .parse::() + .expect("should be accepted"); for value in [ "http://localhost", "https://user@auth.sourceorigin.dev", @@ -15,7 +17,9 @@ fn urls_validate_once() { ] { assert!(value.parse::().is_err(), "accepted {value}"); } - assert!("https://[::1]".parse::().is_ok()); + "https://[::1]" + .parse::() + .expect("should be accepted"); } /// References and resolved bytes redact secrets in all diagnostic formatting. @@ -30,11 +34,11 @@ fn secrets_are_redacted() { "https://example.com/key", "env://HAS SPACE", ] { - assert!(SecretReference::parse(value).is_err()); + SecretReference::parse(value).expect_err("should be rejected"); } let secret = |bytes: &[u8]| SecretBytes(Zeroizing::new(bytes.to_vec())); assert!(!format!("{:?}", secret(b"private")).contains("private")); - assert!(secret(&[255]).text().is_err()); + secret(&[255]).text().expect_err("should be rejected"); // One trailing line ending goes, as a file written by a shell or an editor ends; // anything else is the secret's own. for (bytes, text) in [ diff --git a/crates/common/src/email/tests.rs b/crates/common/src/email/tests.rs index 72c7116aa..ecedc0507 100644 --- a/crates/common/src/email/tests.rs +++ b/crates/common/src/email/tests.rs @@ -65,7 +65,7 @@ fn normalizes_unicode_and_enforces_component_limits() { .as_str(), "é@example.com" ); - assert!(NormalizedEmail::parse(&format!("{}@example.com", "a".repeat(64))).is_ok()); + NormalizedEmail::parse(&format!("{}@example.com", "a".repeat(64))).expect("should be accepted"); assert_eq!( NormalizedEmail::parse(&format!("{}@example.com", "a".repeat(65))), Err(InvalidEmail::LocalPartTooLong(65)) diff --git a/crates/common/src/events/tests.rs b/crates/common/src/events/tests.rs index 0043d910c..51db9853a 100644 --- a/crates/common/src/events/tests.rs +++ b/crates/common/src/events/tests.rs @@ -87,7 +87,9 @@ fn user_agent_family_text_round_trips() { }; assert_eq!(family.to_string(), "firefox/linux"); assert_eq!("firefox/linux".parse(), Ok(family)); - assert!("firefox".parse::().is_err()); + "firefox" + .parse::() + .expect_err("should be rejected"); assert_eq!( "samsung/harmony_os".parse(), Ok(UserAgentFamily { diff --git a/crates/common/src/tests.rs b/crates/common/src/tests.rs index edd01152a..e06a375aa 100644 --- a/crates/common/src/tests.rs +++ b/crates/common/src/tests.rs @@ -30,7 +30,7 @@ fn vocabulary_round_trips() { .vocabulary, "Example" ); - assert!(serde_json::from_str::("\"unknown\"").is_err()); + serde_json::from_str::("\"unknown\"").expect_err("should be rejected"); } open_str_enum! { @@ -59,12 +59,13 @@ fn open_vocabulary_keeps_unknown_values() { fn ids_are_canonical_uuid_v7() { let id = UserId::new(); assert_eq!(id.to_string().parse::(), Ok(id)); - assert!( - "00000000-0000-4000-8000-000000000000" - .parse::() - .is_err() - ); - assert!(id.to_string().to_uppercase().parse::().is_err()); + "00000000-0000-4000-8000-000000000000" + .parse::() + .expect_err("should be rejected"); + id.to_string() + .to_uppercase() + .parse::() + .expect_err("should be rejected"); let error = "not-a-uuid".parse::().expect_err("UUID syntax"); assert!(std::error::Error::source(&error).is_some()); } diff --git a/crates/crypto/src/sealing/tests.rs b/crates/crypto/src/sealing/tests.rs index c2d4051a2..03ae24ae8 100644 --- a/crates/crypto/src/sealing/tests.rs +++ b/crates/crypto/src/sealing/tests.rs @@ -26,10 +26,11 @@ fn sealed_values_open_only_with_their_key_and_associated_data() { modified[index] ^= 1; assert!(kek.open(&modified, b"kid-1rsa").is_err(), "byte {index}"); } - assert!(kek.open(&sealed[..NONCE_LEN], b"kid-1rsa").is_err()); + kek.open(&sealed[..NONCE_LEN], b"kid-1rsa") + .expect_err("should be rejected"); let encoded = Secret::generate().expect("secret").encoded(); - assert!(KeyEncryptionKey::parse(&encoded).is_ok()); + KeyEncryptionKey::parse(&encoded).expect("should be accepted"); for invalid in [format!("{encoded}="), "not base64!".to_owned()] { assert!(matches!( KeyEncryptionKey::parse(&invalid), diff --git a/crates/crypto/src/signing/tests.rs b/crates/crypto/src/signing/tests.rs index b023a7382..c81bd0769 100644 --- a/crates/crypto/src/signing/tests.rs +++ b/crates/crypto/src/signing/tests.rs @@ -12,42 +12,30 @@ fn rsa_verifies_signatures_types_expiry_and_logout_hints() { let expired = keys .sign(TokenType::Id, &claims) .expect("sign expired ID token hint"); - assert!( - keys.verify::(&expired, TokenType::Id, "https://auth.example") - .is_err() - ); - assert!( - keys.verify_id_token_hint(&expired, "https://auth.example") - .is_ok() - ); - assert!( - keys.verify_id_token_hint(&expired, "https://evil.example") - .is_err() - ); + keys.verify::(&expired, TokenType::Id, "https://auth.example") + .expect_err("should be rejected"); + keys.verify_id_token_hint(&expired, "https://auth.example") + .expect("should be accepted"); + keys.verify_id_token_hint(&expired, "https://evil.example") + .expect_err("should be rejected"); let mut valid = claims; valid["exp"] = json!(now + 300); let token = keys .sign(TokenType::Access, &valid) .expect("sign access token"); - assert!( - keys.verify::(&token, TokenType::Access, "https://auth.example") - .is_ok() - ); - assert!( - keys.verify::(&token, TokenType::Id, "https://auth.example") - .is_err() - ); + keys.verify::(&token, TokenType::Access, "https://auth.example") + .expect("should be accepted"); + keys.verify::(&token, TokenType::Id, "https://auth.example") + .expect_err("should be rejected"); let mut bytes = token.into_bytes(); let n = bytes.len(); bytes[n - 10] = if bytes[n - 10] == b'A' { b'B' } else { b'A' }; - assert!( - keys.verify::( - std::str::from_utf8(&bytes).expect("modified compact token remains ASCII"), - TokenType::Access, - "https://auth.example" - ) - .is_err() - ); + keys.verify::( + std::str::from_utf8(&bytes).expect("modified compact token remains ASCII"), + TokenType::Access, + "https://auth.example", + ) + .expect_err("should be rejected"); } /// Even correctly RSA-signed inputs cannot choose an algorithm, type, key or critical extension. @@ -116,23 +104,17 @@ fn key_set_verifies_by_kid_and_limits_retired_keys_to_hints() { let keys = KeySet::new(active, published, vec![retired.public_key().clone()]).expect("key set"); let by_active = keys.sign(TokenType::Id, &claims).expect("sign"); for token in [&by_active, &by_retiring] { - assert!( - keys.verify::(token, TokenType::Id, "https://auth.example") - .is_ok() - ); - assert!( - keys.verify_id_token_hint(token, "https://auth.example") - .is_ok() - ); + keys.verify::(token, TokenType::Id, "https://auth.example") + .expect("should be accepted"); + keys.verify_id_token_hint(token, "https://auth.example") + .expect("should be accepted"); } assert!(matches!( keys.verify::(&by_retired, TokenType::Id, "https://auth.example"), Err(CryptoError::UnknownKey) )); - assert!( - keys.verify_id_token_hint(&by_retired, "https://auth.example") - .is_ok() - ); + keys.verify_id_token_hint(&by_retired, "https://auth.example") + .expect("should be accepted"); assert!(matches!( keys.verify_id_token_hint(&by_unknown, "https://auth.example"), Err(CryptoError::UnknownKey) diff --git a/crates/crypto/src/tests.rs b/crates/crypto/src/tests.rs index b39364bb0..2b5530404 100644 --- a/crates/crypto/src/tests.rs +++ b/crates/crypto/src/tests.rs @@ -15,9 +15,9 @@ fn secrets_round_trip() { assert_eq!(first.encoded().len(), 43); assert_eq!(first.digest(), Digest::sha256(first.as_bytes())); for value in ["", "short", "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"] { - assert!(Secret::parse(value).is_err()); + Secret::parse(value).expect_err("should be rejected"); } - assert!(Secret::parse(&(first.encoded() + "=")).is_err()); + Secret::parse(&(first.encoded() + "=")).expect_err("should be rejected"); assert_eq!(format!("{first:?}"), "Secret(REDACTED)"); } @@ -50,7 +50,7 @@ fn client_secret_contract() { let secret = ClientSecret::generate().expect("secret"); let (prefix, random) = secret.expose().split_at(CLIENT_SECRET_PREFIX.len()); assert_eq!(prefix, CLIENT_SECRET_PREFIX); - assert!(Secret::parse(random).is_ok()); + Secret::parse(random).expect("should be accepted"); assert_eq!( secret.digest(), ClientSecret::digest_presented(secret.expose()) @@ -80,12 +80,12 @@ fn pkce_matches_rfc() { let verifier = "dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk"; let challenge = "E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM"; assert_eq!(Pkce::challenge(verifier).expect("challenge"), challenge); - assert!(Pkce::verify(verifier, challenge).is_ok()); + Pkce::verify(verifier, challenge).expect("should be accepted"); assert!(Pkce::verify(verifier, "incorrect").is_err()); assert!(Pkce::valid_challenge(challenge)); assert!(!Pkce::valid_challenge("short")); for verifier in ["short".to_owned(), "x".repeat(129), "!".repeat(43)] { - assert!(Pkce::challenge(&verifier).is_err()); + Pkce::challenge(&verifier).expect_err("should be rejected"); } } @@ -151,11 +151,9 @@ fn jwt_persistence_and_trust_boundaries() { let unrelated = KeySet::single( Rs256Key::generate("persistent").expect("different RSA key with the same ID"), ); - assert!( - unrelated - .verify::(&token, TokenType::Id, "https://auth.example") - .is_err() - ); + unrelated + .verify::(&token, TokenType::Id, "https://auth.example") + .expect_err("should be rejected"); let key = KeySet::single(key); for token in [ String::new(), @@ -163,10 +161,8 @@ fn jwt_persistence_and_trust_boundaries() { "a.b.c.d".to_owned(), "x".repeat(16385), ] { - assert!( - key.verify::(&token, TokenType::Id, "https://auth.example") - .is_err() - ); + key.verify::(&token, TokenType::Id, "https://auth.example") + .expect_err("should be rejected"); } for (field, invalid) in [ ("iat", serde_json::json!(now + 60)), @@ -180,10 +176,8 @@ fn jwt_persistence_and_trust_boundaries() { let token = key .sign(TokenType::Id, &invalid_claims) .expect("sign malformed claims"); - assert!( - key.verify::(&token, TokenType::Id, "https://auth.example") - .is_err() - ); + key.verify::(&token, TokenType::Id, "https://auth.example") + .expect_err("should be rejected"); } } @@ -288,7 +282,7 @@ fn notes_open_only_with_a_valid_listed_signature() { #[test] fn note_keys_reject_malformed_seeds_and_names() { let seed = "00".repeat(32); - assert!(NoteKey::from_hex_seed("audit", &seed).is_ok()); + NoteKey::from_hex_seed("audit", &seed).expect("should be accepted"); for bad in [ String::new(), "00".repeat(31), diff --git a/crates/database/src/connection/tests.rs b/crates/database/src/connection/tests.rs index 4a6ef9c00..db51ce5b3 100644 --- a/crates/database/src/connection/tests.rs +++ b/crates/database/src/connection/tests.rs @@ -260,8 +260,8 @@ fn runtime_roles_need_plain_names() { "password", ) }; - assert!(role("sourceorigin_auth").is_ok()); - assert!(role(&"a".repeat(63)).is_ok()); + role("sourceorigin_auth").expect("should be accepted"); + role(&"a".repeat(63)).expect("should be accepted"); for user in [ "SourceOrigin", "1auth", diff --git a/crates/database/src/repositories/emails/tests.rs b/crates/database/src/repositories/emails/tests.rs index abba66de3..353dad135 100644 --- a/crates/database/src/repositories/emails/tests.rs +++ b/crates/database/src/repositories/emails/tests.rs @@ -52,18 +52,16 @@ async fn verified_email_updates_preserve_and_release_ownership() { .execute(&mut *tx) .await .expect("savepoint"); - assert!( - sqlx::query( - "INSERT INTO user_emails (id, user_id, normalized_email, verified_at, is_primary) - VALUES ($1, $2, $3, now(), true)" - ) - .bind(uuid::Uuid::now_v7()) - .bind(users[1].as_uuid()) - .bind(&address) - .execute(&mut *tx) - .await - .is_err() - ); + sqlx::query( + "INSERT INTO user_emails (id, user_id, normalized_email, verified_at, is_primary) + VALUES ($1, $2, $3, now(), true)", + ) + .bind(uuid::Uuid::now_v7()) + .bind(users[1].as_uuid()) + .bind(&address) + .execute(&mut *tx) + .await + .expect_err("should be rejected"); sqlx::query("ROLLBACK TO duplicate_email") .execute(&mut *tx) .await