Skip to content
This repository was archived by the owner on Jan 2, 2026. It is now read-only.

Commit 7c3fc31

Browse files
committed
chore: rustfmt
1 parent 79fba33 commit 7c3fc31

27 files changed

+2414
-2369
lines changed

.sqlx/query-e237af1073cf4a9e21833deccc5acdced42ba4c96d4fa79f92727faab7cb3210.json

Lines changed: 43 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
use vergen::{BuildBuilder, Emitter};
44

55
fn main() -> Result<(), Box<dyn std::error::Error>> {
6-
println!("cargo::rustc-check-cfg=cfg(coverage_nightly)");
7-
let build = BuildBuilder::all_build()?;
8-
Emitter::default().add_instructions(&build)?.emit()?;
9-
Ok(())
6+
println!("cargo::rustc-check-cfg=cfg(coverage_nightly)");
7+
let build = BuildBuilder::all_build()?;
8+
Emitter::default().add_instructions(&build)?.emit()?;
9+
Ok(())
1010
}

src/api/admin/db/mod.rs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,28 @@ use rand::{Rng, distr::Alphanumeric};
66
use sqlx::{query_as, types::Uuid};
77

88
use crate::{
9-
database::{Database, Invite},
10-
errors::Error,
9+
database::{Database, Invite},
10+
errors::Error,
1111
};
1212

1313
/// Create an invite.
1414
#[cfg_attr(coverage_nightly, coverage(off))]
1515
pub(super) async fn create_invite(
16-
owner: Option<&Uuid>,
17-
code: Option<&str>,
18-
uses_max: i32,
19-
db: &Database,
16+
owner: Option<&Uuid>,
17+
code: Option<&str>,
18+
uses_max: i32,
19+
db: &Database,
2020
) -> Result<Invite, Error> {
21-
let code = {
22-
if let Some(code) = code {
23-
code
24-
} else {
25-
&rand::rng().sample_iter(&Alphanumeric).take(16).map(char::from).collect::<String>()
26-
}
27-
};
28-
Ok(query_as!(
29-
Invite,
30-
"INSERT INTO invite_links
21+
let code = {
22+
if let Some(code) = code {
23+
code
24+
} else {
25+
&rand::rng().sample_iter(&Alphanumeric).take(16).map(char::from).collect::<String>()
26+
}
27+
};
28+
Ok(query_as!(
29+
Invite,
30+
"INSERT INTO invite_links
3131
(
3232
invite_link_owner,
3333
usages_current, usages_maximum,
@@ -41,11 +41,11 @@ pub(super) async fn create_invite(
4141
usages_maximum,
4242
invite AS invite_code,
4343
invalid",
44-
owner,
45-
uses_max,
46-
code,
47-
false
48-
)
49-
.fetch_one(&db.pool)
50-
.await?)
44+
owner,
45+
uses_max,
46+
code,
47+
false
48+
)
49+
.fetch_one(&db.pool)
50+
.await?)
5151
}

src/api/auth/login.rs

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,59 @@
11
use argon2::{Argon2, PasswordHash, PasswordVerifier};
22
use log::error;
33
use poem::{
4-
IntoResponse, Response, handler,
5-
http::StatusCode,
6-
web::{Data, Json},
4+
IntoResponse, Response, handler,
5+
http::StatusCode,
6+
web::{Data, Json},
77
};
88
use serde_json::json;
99

1010
use crate::{
11-
MAX_PERMITTED_PASSWORD_LEN,
12-
api::auth::models::LoginSchema,
13-
database::{Database, LocalActor, tokens::TokenStore},
14-
errors::{Context, Errcode, Error},
11+
MAX_PERMITTED_PASSWORD_LEN,
12+
api::auth::models::LoginSchema,
13+
database::{Database, LocalActor, tokens::TokenStore},
14+
errors::{Context, Errcode, Error},
1515
};
1616

1717
#[handler]
1818
#[cfg_attr(coverage_nightly, coverage(off))]
1919
pub(super) async fn login(
20-
Json(payload): Json<LoginSchema>,
21-
Data(db): Data<&Database>,
22-
Data(token_store): Data<&TokenStore>,
20+
Json(payload): Json<LoginSchema>,
21+
Data(db): Data<&Database>,
22+
Data(token_store): Data<&TokenStore>,
2323
) -> Result<impl IntoResponse, Error> {
24-
if payload.password.len() > MAX_PERMITTED_PASSWORD_LEN {
25-
return Err(Error::new(
26-
Errcode::IllegalInput,
27-
Some(Context::new(
28-
Some("password"),
29-
Some(&format!("{} characters", payload.password.len())),
30-
Some(&format!("Not more than {MAX_PERMITTED_PASSWORD_LEN} characters")),
31-
None,
32-
)),
33-
));
34-
}
35-
let local_actor = match LocalActor::by_local_name(db, &payload.local_name).await? {
36-
Some(actor) => actor,
37-
None => return Err(Error::new_invalid_login()),
38-
};
39-
let actor_password_hashstring =
40-
match LocalActor::get_password_hash(db, &payload.local_name).await? {
41-
Some(hash_string) => hash_string,
42-
None => {
43-
return Err(Error::new_invalid_login());
44-
}
45-
};
46-
let actor_password_hash = PasswordHash::new(&actor_password_hashstring).map_err(|e| {
47-
error!(
48-
"Password hash for user {} is not in PHC string format? Got error: {e}",
49-
payload.password
50-
);
51-
Error::new(Errcode::Internal, None)
52-
})?;
53-
Argon2::default()
54-
.verify_password(payload.password.as_bytes(), &actor_password_hash)
55-
.map_err(|_| Error::new_invalid_login())?;
56-
let token =
57-
token_store.generate_upsert_token(&local_actor.unique_actor_identifier, None).await?;
58-
Ok(Response::builder().status(StatusCode::OK).body(json!({"token": token}).to_string()))
24+
if payload.password.len() > MAX_PERMITTED_PASSWORD_LEN {
25+
return Err(Error::new(
26+
Errcode::IllegalInput,
27+
Some(Context::new(
28+
Some("password"),
29+
Some(&format!("{} characters", payload.password.len())),
30+
Some(&format!("Not more than {MAX_PERMITTED_PASSWORD_LEN} characters")),
31+
None,
32+
)),
33+
));
34+
}
35+
let local_actor = match LocalActor::by_local_name(db, &payload.local_name).await? {
36+
Some(actor) => actor,
37+
None => return Err(Error::new_invalid_login()),
38+
};
39+
let actor_password_hashstring =
40+
match LocalActor::get_password_hash(db, &payload.local_name).await? {
41+
Some(hash_string) => hash_string,
42+
None => {
43+
return Err(Error::new_invalid_login());
44+
}
45+
};
46+
let actor_password_hash = PasswordHash::new(&actor_password_hashstring).map_err(|e| {
47+
error!(
48+
"Password hash for user {} is not in PHC string format? Got error: {e}",
49+
payload.password
50+
);
51+
Error::new(Errcode::Internal, None)
52+
})?;
53+
Argon2::default()
54+
.verify_password(payload.password.as_bytes(), &actor_password_hash)
55+
.map_err(|_| Error::new_invalid_login())?;
56+
let token =
57+
token_store.generate_upsert_token(&local_actor.unique_actor_identifier, None).await?;
58+
Ok(Response::builder().status(StatusCode::OK).body(json!({"token": token}).to_string()))
5959
}

src/api/auth/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ mod register;
1010
#[cfg_attr(coverage_nightly, coverage(off))]
1111
/// Route handler for the auth module
1212
pub(super) fn setup_routes() -> Route {
13-
Route::new().at("/register", post(register::register)).at("/login", post(login::login))
13+
Route::new().at("/register", post(register::register)).at("/login", post(login::login))
1414
}

src/api/auth/models.rs

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@ use serde::{Deserialize, Serialize};
1313
/// subject to a lot of change. If you build clients around sonata, expect
1414
/// things to break in future versions.
1515
pub struct RegisterSchema {
16-
/// Whether the client has agreed to the terms of service offered by the
17-
/// instance.
18-
pub tos_consent: bool,
19-
/// The local name the client would like to choose
20-
pub local_name: String,
21-
/// A password for the clients' new account
22-
pub password: String,
23-
/// Optional: An invite code, which the client got referred to this instance
24-
/// with.
25-
pub invite: Option<String>,
16+
/// Whether the client has agreed to the terms of service offered by the
17+
/// instance.
18+
pub tos_consent: bool,
19+
/// The local name the client would like to choose
20+
pub local_name: String,
21+
/// A password for the clients' new account
22+
pub password: String,
23+
/// Optional: An invite code, which the client got referred to this instance
24+
/// with.
25+
pub invite: Option<String>,
2626
}
2727

2828
#[derive(PartialEq, Debug, Serialize, Deserialize, Clone)]
@@ -36,47 +36,47 @@ pub struct RegisterSchema {
3636
/// subject to a lot of change. If you build clients around sonata, expect
3737
/// things to break in future versions.
3838
pub struct LoginSchema {
39-
/// The name of the account the client wants to login to
40-
pub local_name: String,
41-
/// The password of the account the client wants to login to
42-
pub password: String,
39+
/// The name of the account the client wants to login to
40+
pub local_name: String,
41+
/// The password of the account the client wants to login to
42+
pub password: String,
4343
}
4444

4545
#[cfg(test)]
4646
#[allow(
47-
clippy::unwrap_used,
48-
clippy::str_to_string,
49-
clippy::indexing_slicing,
50-
clippy::bool_assert_comparison
47+
clippy::unwrap_used,
48+
clippy::str_to_string,
49+
clippy::indexing_slicing,
50+
clippy::bool_assert_comparison
5151
)]
5252
mod test {
53-
use super::*;
54-
#[test]
55-
fn test_register_schema_serialization() {
56-
let schema = RegisterSchema {
57-
tos_consent: true,
58-
local_name: "testuser".to_string(),
59-
password: "testpassword123".to_string(),
60-
invite: Some("invite123".to_string()),
61-
};
53+
use super::*;
54+
#[test]
55+
fn test_register_schema_serialization() {
56+
let schema = RegisterSchema {
57+
tos_consent: true,
58+
local_name: "testuser".to_string(),
59+
password: "testpassword123".to_string(),
60+
invite: Some("invite123".to_string()),
61+
};
6262

63-
let serialized = serde_json::to_string(&schema).unwrap();
64-
let parsed: serde_json::Value = serde_json::from_str(&serialized).unwrap();
63+
let serialized = serde_json::to_string(&schema).unwrap();
64+
let parsed: serde_json::Value = serde_json::from_str(&serialized).unwrap();
6565

66-
assert_eq!(parsed["tosConsent"], true);
67-
assert_eq!(parsed["localName"], "testuser");
68-
assert_eq!(parsed["password"], "testpassword123");
69-
assert_eq!(parsed["invite"], "invite123");
70-
}
66+
assert_eq!(parsed["tosConsent"], true);
67+
assert_eq!(parsed["localName"], "testuser");
68+
assert_eq!(parsed["password"], "testpassword123");
69+
assert_eq!(parsed["invite"], "invite123");
70+
}
7171

72-
#[test]
73-
fn test_register_schema_deserialization() {
74-
let json_str = r#"{"tosConsent":true,"localName":"testuser","password":"testpassword123","invite":"invite123"}"#;
75-
let schema: RegisterSchema = serde_json::from_str(json_str).unwrap();
72+
#[test]
73+
fn test_register_schema_deserialization() {
74+
let json_str = r#"{"tosConsent":true,"localName":"testuser","password":"testpassword123","invite":"invite123"}"#;
75+
let schema: RegisterSchema = serde_json::from_str(json_str).unwrap();
7676

77-
assert_eq!(schema.tos_consent, true);
78-
assert_eq!(schema.local_name, "testuser");
79-
assert_eq!(schema.password, "testpassword123");
80-
assert_eq!(schema.invite, Some("invite123".to_string()));
81-
}
77+
assert_eq!(schema.tos_consent, true);
78+
assert_eq!(schema.local_name, "testuser");
79+
assert_eq!(schema.password, "testpassword123");
80+
assert_eq!(schema.invite, Some("invite123".to_string()));
81+
}
8282
}

0 commit comments

Comments
 (0)