Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion apps/auth-service/src/admin/operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
10 changes: 8 additions & 2 deletions apps/auth-service/src/admin/tests/handles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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));
}
4 changes: 2 additions & 2 deletions apps/auth-service/src/admin/types/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}
Expand Down Expand Up @@ -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!(
Expand Down
4 changes: 2 additions & 2 deletions apps/auth-service/src/cli/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}
Expand Down
3 changes: 2 additions & 1 deletion apps/auth-service/src/federation/tests/callback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions apps/auth-service/src/federation/tests/protocols.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down Expand Up @@ -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;
Expand Down
60 changes: 27 additions & 33 deletions apps/auth-service/src/federation/tests/signup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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");
}

Expand Down
2 changes: 1 addition & 1 deletion apps/auth-service/src/keys/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
4 changes: 2 additions & 2 deletions apps/auth-service/src/oidc/authorize/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions apps/auth-service/src/oidc/tests/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Vec<_>>()
.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
Expand Down
5 changes: 4 additions & 1 deletion apps/auth-service/src/security/tests/forwarding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ async fn forwarded_addresses_require_an_explicit_trusted_peer() {
"192.0.2.7".parse::<IpAddr>().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.
Expand Down
2 changes: 1 addition & 1 deletion apps/auth-service/src/security/tests/sessions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ fn confirmation_age_is_fixed_from_its_timestamp() {
last_seen_ip: None,
}
};
assert!(Confirmed::<CONFIRMATION_MAX_AGE>::check(&session(Some(290))).is_ok());
Confirmed::<CONFIRMATION_MAX_AGE>::check(&session(Some(290))).expect("should be accepted");
for age in [None, Some(310), Some(86_400)] {
assert!(matches!(
Confirmed::<CONFIRMATION_MAX_AGE>::check(&session(age)),
Expand Down
4 changes: 2 additions & 2 deletions crates/auth-sdk/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 14 additions & 7 deletions crates/common/src/clients/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fn client_ids_are_bounded_identifiers() {
] {
assert_eq!(value.parse::<ClientId>().is_ok(), valid, "{value}");
}
assert!(serde_json::from_str::<ClientId>("\"bad id\"").is_err());
serde_json::from_str::<ClientId>("\"bad id\"").expect_err("should be rejected");
assert_eq!(
"bad id".parse::<ClientId>().expect_err("space").to_string(),
"client ID \"bad id\" must be 1 to 64 characters from A-Z, a-z, 0-9, '.', '_' and '-'"
Expand Down Expand Up @@ -132,16 +132,23 @@ fn related_origins_are_bare_https_domain_origins() {
] {
assert_eq!(value.parse::<RelatedOrigin>(), Err(expected), "{value}");
}
assert!(serde_json::from_str::<RelatedOrigin>("\"https://notes.example/\"").is_err());
serde_json::from_str::<RelatedOrigin>("\"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::<DisplayName>().is_ok());
assert!("é".repeat(81).parse::<DisplayName>().is_err());
assert!(" ".parse::<DisplayName>().is_err());
assert!("Web\x1b[2J".parse::<DisplayName>().is_err());
"é".repeat(80)
.parse::<DisplayName>()
.expect("should be accepted");
"é".repeat(81)
.parse::<DisplayName>()
.expect_err("should be rejected");
" ".parse::<DisplayName>().expect_err("should be rejected");
"Web\x1b[2J"
.parse::<DisplayName>()
.expect_err("should be rejected");
for (value, valid) in [
("notes:read", true),
("", false),
Expand All @@ -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
Expand Down
12 changes: 8 additions & 4 deletions crates/common/src/config/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ use super::*;
/// Origins reject every insecure or ambiguous component.
#[test]
fn urls_validate_once() {
assert!("https://auth.sourceorigin.dev".parse::<Origin>().is_ok());
"https://auth.sourceorigin.dev"
.parse::<Origin>()
.expect("should be accepted");
for value in [
"http://localhost",
"https://user@auth.sourceorigin.dev",
Expand All @@ -15,7 +17,9 @@ fn urls_validate_once() {
] {
assert!(value.parse::<Origin>().is_err(), "accepted {value}");
}
assert!("https://[::1]".parse::<Origin>().is_ok());
"https://[::1]"
.parse::<Origin>()
.expect("should be accepted");
}

/// References and resolved bytes redact secrets in all diagnostic formatting.
Expand All @@ -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 [
Expand Down
2 changes: 1 addition & 1 deletion crates/common/src/email/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
4 changes: 3 additions & 1 deletion crates/common/src/events/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<UserAgentFamily>().is_err());
"firefox"
.parse::<UserAgentFamily>()
.expect_err("should be rejected");
assert_eq!(
"samsung/harmony_os".parse(),
Ok(UserAgentFamily {
Expand Down
15 changes: 8 additions & 7 deletions crates/common/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fn vocabulary_round_trips() {
.vocabulary,
"Example"
);
assert!(serde_json::from_str::<Example>("\"unknown\"").is_err());
serde_json::from_str::<Example>("\"unknown\"").expect_err("should be rejected");
}

open_str_enum! {
Expand Down Expand Up @@ -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::<UserId>(), Ok(id));
assert!(
"00000000-0000-4000-8000-000000000000"
.parse::<UserId>()
.is_err()
);
assert!(id.to_string().to_uppercase().parse::<UserId>().is_err());
"00000000-0000-4000-8000-000000000000"
.parse::<UserId>()
.expect_err("should be rejected");
id.to_string()
.to_uppercase()
.parse::<UserId>()
.expect_err("should be rejected");
let error = "not-a-uuid".parse::<UserId>().expect_err("UUID syntax");
assert!(std::error::Error::source(&error).is_some());
}
Expand Down
5 changes: 3 additions & 2 deletions crates/crypto/src/sealing/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
Loading
Loading