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 @@ -28,6 +28,7 @@ version = "0.1.0"
[workspace.lints.rust]
unsafe_code = "forbid"
missing_docs = "warn"
unused_qualifications = "warn"

# Every Clippy warning fails CI: `just rust lint` runs Clippy with `-D warnings`.
# The groups sit at priority -1 so the single lints below can override them.
Expand Down
2 changes: 1 addition & 1 deletion apps/auth-service/src/account/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ impl AccountOperation {
Self::ListNotifications => service.notifications(viewer, None).await.map(drop),
// Checked before it looks the notification up, so any ID will do.
Self::ViewNotification => service
.notification(viewer, sourceorigin_common::NotificationId::new())
.notification(viewer, NotificationId::new())
.await
.map(drop),
Self::ViewNotificationPreferences => {
Expand Down
2 changes: 1 addition & 1 deletion apps/auth-service/src/deliveries/email/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@ async fn security_emails_carry_the_sign_out_link() {
panic!("a security notification's email carries the link");
};
let link = url::Url::parse(&link).expect("URL");
assert_eq!(link.path(), routes::page::SIGN_OUT);
assert_eq!(link.path(), page::SIGN_OUT);
let query: std::collections::HashMap<_, _> = link.query_pairs().into_owned().collect();
let checked = config.sign_out_links.check(&crate::notifications::Link {
id: query["id"].parse().expect("notification"),
Expand Down
4 changes: 2 additions & 2 deletions apps/auth-service/src/federation/tests/linking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ impl TestApp {
) -> Result<String, AccountError> {
let account = AccountService::new(self.app.database.clone());
let owner = account
.owner(security::RequestContext::TEST, &Self::cookies(cookie))
.owner(RequestContext::TEST, &Self::cookies(cookie))
.await
.expect("session lookup")
.expect("signed in");
Expand Down Expand Up @@ -76,7 +76,7 @@ async fn linking_requires_target_confirmation_and_unlink_releases_subject_withou
test.app
.database
.sessions()
.confirm_passkey(target_session, PasskeyId::new(), chrono::Utc::now())
.confirm_passkey(target_session, PasskeyId::new(), Utc::now())
.await
.expect("confirm");
let return_to = test
Expand Down
14 changes: 6 additions & 8 deletions apps/auth-service/src/federation/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl Drop for TestApp {
impl TestApp {
/// The federation routes and the shared settings, as the public listener
/// serves them.
fn routes(&self) -> axum::Router {
fn routes(&self) -> Router {
self.app
.clone()
.routes()
Expand All @@ -64,9 +64,7 @@ impl TestApp {
async fn with_email(email: Option<&str>) -> Self {
let database = crate::tests::Replicas::database().await;
let subject = u64::from_be_bytes(
sourceorigin_crypto::Secret::generate()
.expect("random")
.as_bytes()[..8]
Secret::generate().expect("random").as_bytes()[..8]
.try_into()
.expect("eight bytes"),
)
Expand Down Expand Up @@ -108,7 +106,7 @@ impl TestApp {
database,
&FederationConfig {
origin: "https://auth.sourceorigin.dev/"
.parse::<sourceorigin_common::config::Origin>()
.parse::<Origin>()
.expect("origin"),
providers: BTreeMap::from([(Provider::GitHub, config)]),
},
Expand Down Expand Up @@ -252,7 +250,7 @@ impl TestApp {
if confirmed {
database
.sessions()
.confirm_passkey(browser.session_id, PasskeyId::new(), chrono::Utc::now())
.confirm_passkey(browser.session_id, PasskeyId::new(), Utc::now())
.await
.expect("confirm");
}
Expand All @@ -276,7 +274,7 @@ impl TestApp {
.to_str()
.expect("location");
let target = Url::parse(location).expect("target");
assert_eq!(target.path(), crate::routes::page::LOGIN);
assert_eq!(target.path(), routes::page::LOGIN);
assert!(
target
.query_pairs()
Expand All @@ -296,7 +294,7 @@ impl TestApp {
body: &serde_json::Value,
) -> Request<Body> {
let mut request = Request::builder()
.extension(crate::security::RequestContext::TEST)
.extension(RequestContext::TEST)
.method(method)
.uri(path)
.header(header::CONTENT_TYPE, "application/json");
Expand Down
2 changes: 1 addition & 1 deletion apps/auth-service/src/federation/tests/sign_in.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ impl TestApp {
.insert_identity(&InsertExternalIdentity {
id: TokenId::new(),
user_id,
provider: sourceorigin_common::Provider::GitHub,
provider: Provider::GitHub,
issuer: ProviderEndpoints::new(Provider::GitHub)
.expect("GitHub facts")
.issuer
Expand Down
12 changes: 6 additions & 6 deletions apps/auth-service/src/federation/tests/signup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ impl TestApp {
headers: &HeaderMap,
user: UserId,
) -> Result<Option<ProviderPicture>, FederationError> {
let actor = security::RequestContext::TEST.actor(Actor::Anonymous);
let actor = RequestContext::TEST.actor(Actor::Anonymous);
FederationApplication::attach_signup(tx, &actor, &self.email, ip, pending, headers, user)
.await
}
Expand All @@ -40,7 +40,7 @@ async fn onboarding_commits_only_with_first_key_and_browser_and_never_claims_exi
assert!(
test.attach(
&mut tx,
security::RequestContext::TEST.client_ip,
RequestContext::TEST.client_ip,
pending.id,
&headers,
user
Expand All @@ -54,7 +54,7 @@ async fn onboarding_commits_only_with_first_key_and_browser_and_never_claims_exi
assert!(
test.attach(
&mut tx,
security::RequestContext::TEST.client_ip,
RequestContext::TEST.client_ip,
pending.id,
&HeaderMap::new(),
user
Expand All @@ -64,7 +64,7 @@ async fn onboarding_commits_only_with_first_key_and_browser_and_never_claims_exi
);
test.attach(
&mut tx,
security::RequestContext::TEST.client_ip,
RequestContext::TEST.client_ip,
pending.id,
&headers,
user,
Expand All @@ -90,7 +90,7 @@ async fn onboarding_commits_only_with_first_key_and_browser_and_never_claims_exi
assert!(
test.attach(
&mut tx,
security::RequestContext::TEST.client_ip,
RequestContext::TEST.client_ip,
pending.id,
&headers,
user
Expand Down Expand Up @@ -202,7 +202,7 @@ async fn signup_skips_an_address_an_account_being_deleted_holds() {
let mut tx = test.app.database.begin().await.expect("tx");
test.attach(
&mut tx,
security::RequestContext::TEST.client_ip,
RequestContext::TEST.client_ip,
pending.id,
&headers,
user,
Expand Down
25 changes: 14 additions & 11 deletions apps/auth-service/src/notifications/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ async fn owners_choose_which_notifications_are_emailed() {

let service = AccountService::new(harness.database.clone());
service
.unsubscribe(alice.user_id, crate::security::RequestContext::TEST)
.unsubscribe(alice.user_id, RequestContext::TEST)
.await
.expect("unsubscribe");
assert_eq!(preferences(&alice).await, announcements(false));
Expand Down Expand Up @@ -314,7 +314,7 @@ async fn the_sign_out_link_works_once_within_seven_days() {
.expect("inbox")[0]
.id;
let service = AccountService::new(harness.database.clone());
let context = crate::security::RequestContext::TEST;
let context = RequestContext::TEST;
let passkeys = harness
.database
.passkeys()
Expand Down Expand Up @@ -360,13 +360,16 @@ async fn the_sign_out_link_works_once_within_seven_days() {
})
.collect();
assert_eq!(reasons.len(), 2, "{reasons:?}");
assert!(reasons.iter().all(|(reason, actor)| *reason
== sourceorigin_common::events::RevocationReason::SignOutLink
&& *actor
== Actor::User {
user_id: alice.user_id,
session_id: None
}));
assert!(
reasons
.iter()
.all(|(reason, actor)| *reason == RevocationReason::SignOutLink
&& *actor
== Actor::User {
user_id: alice.user_id,
session_id: None
})
);
assert!(
!service
.sign_out_everywhere(id, context)
Expand Down Expand Up @@ -443,7 +446,7 @@ async fn support_signing_an_account_out_tells_its_owner_once() {
&context,
alice.user_id,
sourceorigin_repository::SessionScope::All,
&sourceorigin_common::events::RevocationReason::Admin,
&RevocationReason::Admin,
)
.await
.expect("revoke");
Expand Down Expand Up @@ -501,7 +504,7 @@ async fn every_use_of_the_sign_out_link_is_in_the_history() {
})
.collect()
};
let context = crate::security::RequestContext::TEST;
let context = RequestContext::TEST;
let first = latest().await;
assert!(
service
Expand Down
2 changes: 1 addition & 1 deletion apps/auth-service/src/oidc/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ pub(crate) enum OAuthError {
Url(#[from] url::ParseError),
/// A generated cookie could not be represented as an HTTP header.
#[error("OIDC cookie header is invalid")]
CookieHeader(#[from] axum::http::header::InvalidHeaderValue),
CookieHeader(#[from] header::InvalidHeaderValue),
/// The address of the page the browser goes on to could not be written.
#[error("a page's address could not be written")]
PageAddress(#[from] QueryError),
Expand Down
4 changes: 2 additions & 2 deletions apps/auth-service/src/oidc/tests/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ async fn userinfo_needs_the_openid_scope() {
sub: flow.user_id.to_string(),
aud: sourceorigin_common::protocol::claims::Audience::One("api".into()),
client_id: flow.client.id.clone(),
jti: sourceorigin_common::TokenId::new(),
jti: TokenId::new(),
scope: "profile".parse().expect("scopes"),
iat: Utc::now(),
exp: Utc::now() + chrono::Duration::minutes(5),
Expand All @@ -176,7 +176,7 @@ async fn userinfo_needs_the_openid_scope() {
sourceorigin_common::protocol::claims::AuthenticationClaims::default(),
act: None,
cnf: None,
profile: sourceorigin_common::protocol::claims::ProfileClaims::default(),
profile: ProfileClaims::default(),
extra: (),
},
)
Expand Down
6 changes: 3 additions & 3 deletions apps/auth-service/src/oidc/tests/logout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ async fn logout_receiver() -> (
Arc<Mutex<Vec<String>>>,
) {
let posted = Arc::new(Mutex::new(Vec::new()));
let receiver = axum::Router::new().route(
let receiver = Router::new().route(
"/backchannel-logout",
axum::routing::post({
post({
let posted = Arc::clone(&posted);
async move |axum::Form(form): axum::Form<HashMap<String, String>>| {
posted
Expand Down Expand Up @@ -290,7 +290,7 @@ async fn an_unverifiable_hint_still_signs_out_and_stays_on_auth() {
async fn a_hint_naming_another_account_says_so() {
let flow = Flow::new(true, true).await;
let (hint, sid) = id_token(&flow).await;
let other = crate::tests::Browser::new_account(&flow.app.database).await;
let other = Browser::new_account(&flow.app.database).await;
let elsewhere = Flow {
cookie: other.cookie,
..flow.clone()
Expand Down
10 changes: 4 additions & 6 deletions apps/auth-service/src/oidc/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ struct Flow {
app: OidcApplication,
/// Where requests go: the OIDC routes and their pages, or a replica of the whole
/// service.
router: axum::Router,
router: Router,
/// The scenario's client, registered through [`ClientRegistry`](crate::ClientRegistry).
client: ClientRegistration,
/// The secret of a confidential scenario client.
Expand Down Expand Up @@ -89,9 +89,7 @@ impl Flow {
base64::engine::general_purpose::STANDARD.encode(format!("{}:{secret}", client.id))
)
});
let origin = origin
.parse::<sourceorigin_common::config::Origin>()
.expect("issuer");
let origin = origin.parse::<Origin>().expect("issuer");
let config = AuthConfig::test(&origin);
let federation =
FederationApplication::new(db.clone(), &config.federation).expect("federation");
Expand Down Expand Up @@ -121,7 +119,7 @@ impl Flow {
}
}
/// The same scenario, sending its requests to `router`, such as one of [`Replicas`].
fn on(&self, router: &axum::Router) -> Self {
fn on(&self, router: &Router) -> Self {
Self {
router: router.clone(),
..self.clone()
Expand Down Expand Up @@ -346,7 +344,7 @@ impl Flow {
}
/// The scenario's account, as the owner of its browser session.
async fn owner(&self) -> crate::account::Owner {
let mut headers = axum::http::HeaderMap::new();
let mut headers = HeaderMap::new();
headers.insert(header::COOKIE, self.cookie.parse().expect("cookie"));
crate::account::AccountService::new(self.app.database.clone())
.owner(RequestContext::TEST, &headers)
Expand Down
2 changes: 1 addition & 1 deletion apps/auth-service/src/oidc/tests/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ async fn oauth_failures_preserve_sources_and_statuses() {
assert_eq!(response.status(), StatusCode::INTERNAL_SERVER_ERROR);
let error = OAuthCode::InvalidGrant.reject_with(
"code is \"malformed\" \u{2014} retry",
sourceorigin_crypto::CryptoError::SecretLength,
CryptoError::SecretLength,
);
assert!(error.source().is_some());
let response = error.into_response();
Expand Down
14 changes: 7 additions & 7 deletions apps/auth-service/src/oidc/tests/sdk_routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ impl LoginApp {
let api = Router::new()
.route(
"/settings",
axum::routing::get(|_: RequireAuthentication<RecentPasskey>| async { "settings" }),
get(|_: RequireAuthentication<RecentPasskey>| async { "settings" }),
)
.route(
"/stubborn",
axum::routing::get(|| async {
get(|| async {
let challenge = BearerChallenge::step_up(StepUpRequirement::default());
(
StatusCode::UNAUTHORIZED,
Expand Down Expand Up @@ -117,12 +117,12 @@ impl LoginApp {
let app = Router::new()
.route(
"/notes",
axum::routing::get(|user: SignedIn| async move {
user.login().access_token().expose().to_owned()
}),
get(
|user: SignedIn| async move { user.login().access_token().expose().to_owned() },
),
)
.route("/settings", axum::routing::get(call_api("/settings")))
.route("/stubborn", axum::routing::get(call_api("/stubborn")))
.route("/settings", get(call_api("/settings")))
.route("/stubborn", get(call_api("/stubborn")))
.nest("/auth", auth.router())
.layer(auth.layer());
Self { flow, app, clock }
Expand Down
5 changes: 1 addition & 4 deletions apps/auth-service/src/oidc/tests/tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,10 +309,7 @@ async fn concurrent_refreshes_across_replicas() {
successors.push(json(response).await["refresh_token"].clone());
}
if confidential {
assert!(
successors.iter().all(serde_json::Value::is_null),
"{successors:?}"
);
assert!(successors.iter().all(Value::is_null), "{successors:?}");
assert_eq!(a.refresh(&token).await.status(), StatusCode::OK, "kept");
continue;
}
Expand Down
6 changes: 3 additions & 3 deletions apps/auth-service/src/passkey/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub(crate) struct Fixture {
/// Routes and persistence under test.
app: PasskeyApplication,
/// Where requests go: the passkey routes, or a replica of the whole service.
router: axum::Router,
router: Router,
/// The software key that signs.
key: SoftKey,
/// HTTPS origin passed to the authenticator.
Expand Down Expand Up @@ -153,7 +153,7 @@ impl Fixture {
id
}
/// Sends the next requests to `router`, such as one of [`Replicas`].
fn on(&mut self, router: &axum::Router) -> &mut Self {
fn on(&mut self, router: &Router) -> &mut Self {
self.router = router.clone();
self
}
Expand Down Expand Up @@ -183,7 +183,7 @@ impl Fixture {
.clone()
.oneshot(
request
.extension(crate::security::RequestContext::TEST)
.extension(RequestContext::TEST)
.header("x-sourceorigin-csrf", "1")
.body(Body::from(body))
.expect("request"),
Expand Down
2 changes: 1 addition & 1 deletion apps/auth-service/src/security/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ pub(crate) enum HttpSecurityError {
MultipleForwardedHeaders,
/// The forwarded header is not valid HTTP text.
#[error("forwarded address is not HTTP text")]
ForwardedHeader(#[from] axum::http::header::ToStrError),
ForwardedHeader(#[from] header::ToStrError),
/// The forwarded header does not contain a single IP address.
#[error("forwarded address is not a single IP address")]
ForwardedAddress(#[from] std::net::AddrParseError),
Expand Down
Loading
Loading