meta: Fix cargo clippy failures (format strings)

This commit is contained in:
selfhoster1312
2025-07-16 18:48:09 +02:00
committed by nitnelave
parent 53e62ecf5a
commit 87e9311a44
28 changed files with 88 additions and 125 deletions
+5 -6
View File
@@ -199,8 +199,7 @@ where
warn!("Error sending email: {:#?}", e);
info!("Reset token: {}", token);
return Err(TcpError::InternalServerError(format!(
"Could not send email: {}",
e
"Could not send email: {e}"
)));
}
Ok(())
@@ -254,7 +253,7 @@ where
Cookie::build("token", token.as_str())
.max_age(5.minutes())
// Cookie is only valid to reset the password.
.path(format!("{}auth", path))
.path(format!("{path}auth"))
.http_only(true)
.same_site(SameSite::Strict)
.finish(),
@@ -310,7 +309,7 @@ where
.cookie(
Cookie::build("refresh_token", "")
.max_age(0.days())
.path(format!("{}auth", path))
.path(format!("{path}auth"))
.http_only(true)
.same_site(SameSite::Strict)
.finish(),
@@ -381,7 +380,7 @@ where
.cookie(
Cookie::build("refresh_token", refresh_token_plus_name.clone())
.max_age(max_age.num_days().days())
.path(format!("{}auth", path))
.path(format!("{path}auth"))
.http_only(true)
.same_site(SameSite::Strict)
.finish(),
@@ -475,7 +474,7 @@ where
inner_payload,
)
.await
.map_err(|e| TcpError::BadRequest(format!("{:#?}", e)))?
.map_err(|e| TcpError::BadRequest(format!("{e:#?}")))?
.into_inner();
let user_id = &registration_start_request.username;
let user_is_admin = data
+8 -10
View File
@@ -299,14 +299,14 @@ impl PrivateKeyLocationOrFigment {
source: Some(figment::Source::Code(_)),
..
}) => PrivateKeyLocation::Default,
other => panic!("Unexpected config location: {:?}", other),
other => panic!("Unexpected config location: {other:?}"),
}
}
PrivateKeyLocationOrFigment::PrivateKeyLocation(PrivateKeyLocation::KeyFile(
config_location,
_,
)) => {
panic!("Unexpected location: {:?}", config_location)
panic!("Unexpected location: {config_location:?}")
}
PrivateKeyLocationOrFigment::PrivateKeyLocation(location) => location.clone(),
}
@@ -334,11 +334,11 @@ impl PrivateKeyLocationOrFigment {
source: Some(figment::Source::Code(_)),
..
}) => PrivateKeyLocation::Default,
other => panic!("Unexpected config location: {:?}", other),
other => panic!("Unexpected config location: {other:?}"),
}
}
PrivateKeyLocationOrFigment::PrivateKeyLocation(PrivateKeyLocation::KeySeed(file)) => {
panic!("Unexpected location: {:?}", file)
panic!("Unexpected location: {file:?}")
}
PrivateKeyLocationOrFigment::PrivateKeyLocation(location) => location.clone(),
}
@@ -373,19 +373,17 @@ fn get_server_setup<L: Into<PrivateKeyLocationOrFigment>>(
private_key_location: private_key_location.for_key_seed(),
})
} else if path.exists() {
let bytes = read(file_path).context(format!("Could not read key file `{}`", file_path))?;
let bytes = read(file_path).context(format!("Could not read key file `{file_path}`"))?;
Ok(ServerSetupConfig {
server_setup: ServerSetup::deserialize(&bytes).context(format!(
"while parsing the contents of the `{}` file",
file_path
"while parsing the contents of the `{file_path}` file"
))?,
private_key_location: private_key_location.for_key_file(file_path),
})
} else {
let server_setup = generate_random_private_key();
write_to_readonly_file(path, &server_setup.serialize()).context(format!(
"Could not write the generated server setup to file `{}`",
file_path,
"Could not write the generated server setup to file `{file_path}`",
))?;
Ok(ServerSetupConfig {
server_setup,
@@ -596,7 +594,7 @@ where
.iter()
.filter(|k| !expected_keys.contains(k.as_str()))
.for_each(|k| {
eprintln!("WARNING: Unknown environment variable: LLDAP_{}", k);
eprintln!("WARNING: Unknown environment variable: LLDAP_{k}");
});
}
config.server_setup = Some(get_server_setup(
+2 -2
View File
@@ -29,7 +29,7 @@ impl std::fmt::Debug for DatabaseUrl {
let mut url = self.0.clone();
// It can fail for URLs that cannot have a password, like "mailto:bob@example".
let _ = url.set_password(Some("***PASSWORD***"));
f.write_fmt(format_args!(r#""{}""#, url))
f.write_fmt(format_args!(r#""{url}""#))
} else {
f.write_fmt(format_args!(r#""{}""#, self.0))
}
@@ -44,7 +44,7 @@ mod tests {
fn test_database_url_debug() {
let url = DatabaseUrl::from("postgres://user:pass@localhost:5432/dbname");
assert_eq!(
format!("{:?}", url),
format!("{url:?}"),
r#""postgres://user:***PASSWORD***@localhost:5432/dbname""#
);
assert_eq!(
+2 -2
View File
@@ -71,7 +71,7 @@ where
#[instrument(level = "info", err)]
pub async fn check_ldap(port: u16) -> Result<()> {
check_ldap_endpoint(TcpStream::connect(format!("localhost:{}", port)).await?).await
check_ldap_endpoint(TcpStream::connect(format!("localhost:{port}")).await?).await
}
fn get_root_certificates() -> rustls::RootCertStore {
@@ -152,7 +152,7 @@ pub async fn check_ldaps(ldaps_options: &LdapsOptions) -> Result<()> {
#[instrument(level = "info", err)]
pub async fn check_api(port: u16) -> Result<()> {
reqwest::get(format!("http://localhost:{}/health", port))
reqwest::get(format!("http://localhost:{port}/health"))
.await?
.error_for_status()?;
info!("Success");
+1 -4
View File
@@ -132,10 +132,7 @@ fn read_private_key(key_file: &str) -> Result<PrivateKey> {
.and_then(|keys| keys.into_iter().next().ok_or_else(|| anyhow!("No EC key")))
})
.with_context(|| {
format!(
"Cannot read either PKCS1, PKCS8 or EC private key from {}",
key_file
)
format!("Cannot read either PKCS1, PKCS8 or EC private key from {key_file}")
})
.map(rustls::PrivateKey)
}
+3 -4
View File
@@ -93,15 +93,14 @@ pub async fn send_password_reset_email(
.unwrap()
.extend(["reset-password", "step2", token]);
let body = format!(
"Hello {},
"Hello {username},
This email has been sent to you in order to validate your identity.
If you did not initiate the process your credentials might have been
compromised. You should reset your password and contact an administrator.
To reset your password please visit the following URL: {}
To reset your password please visit the following URL: {reset_url}
Please contact an administrator if you did not initiate the process.",
username, reset_url
Please contact an administrator if you did not initiate the process."
);
let res = send_email(
to,
+2 -3
View File
@@ -55,8 +55,7 @@ async fn create_admin_user(handler: &SqlBackendHandler, config: &Configuration)
.len();
assert!(
pass_length >= 8,
"Minimum password length is 8 characters, got {} characters",
pass_length
"Minimum password length is 8 characters, got {pass_length} characters"
);
handler
.create_user(CreateUserRequest {
@@ -97,7 +96,7 @@ async fn ensure_group_exists(handler: &SqlBackendHandler, group_name: &str) -> R
..Default::default()
})
.await
.context(format!("while creating {} group", group_name))?;
.context(format!("while creating {group_name} group"))?;
}
Ok(())
}
+1 -2
View File
@@ -169,8 +169,7 @@ impl TcpBackendHandler for SqlBackendHandler {
.await?;
if result.rows_affected == 0 {
return Err(DomainError::EntityNotFound(format!(
"No such password reset token: '{}'",
token
"No such password reset token: '{token}'"
)));
}
Ok(())
+2 -2
View File
@@ -14,13 +14,13 @@ pub fn database_url() -> String {
pub fn ldap_url() -> String {
let port = var("LLDAP_LDAP_PORT").ok();
let port = port.unwrap_or("3890".to_string());
format!("ldap://localhost:{}", port)
format!("ldap://localhost:{port}")
}
pub fn http_url() -> String {
let port = var("LLDAP_HTTP_PORT").ok();
let port = port.unwrap_or("17170".to_string());
format!("http://localhost:{}", port)
format!("http://localhost:{port}")
}
pub fn admin_dn() -> String {
+7 -10
View File
@@ -102,7 +102,7 @@ impl LLDAPFixture {
create_user::Variables {
user: create_user::CreateUserInput {
id: user.clone(),
email: Some(format!("{}@lldap.test", user)),
email: Some(format!("{user}@lldap.test")),
avatar: None,
display_name: None,
first_name: None,
@@ -181,11 +181,11 @@ impl Drop for LLDAPFixture {
Signal::SIGTERM,
);
if let Err(err) = result {
println!("Failed to send kill signal: {:?}", err);
println!("Failed to send kill signal: {err:?}");
let _ = self
.child
.kill()
.map_err(|err| println!("Failed to kill LLDAP: {:?}", err));
.map_err(|err| println!("Failed to kill LLDAP: {err:?}"));
return;
}
@@ -193,10 +193,7 @@ impl Drop for LLDAPFixture {
let status = self.child.try_wait();
match status {
Err(e) => {
println!(
"Failed to get status while waiting for graceful exit: {}",
e
);
println!("Failed to get status while waiting for graceful exit: {e}");
break;
}
Ok(None) => {
@@ -204,7 +201,7 @@ impl Drop for LLDAPFixture {
}
Ok(Some(status)) => {
if !status.success() {
println!("LLDAP exited with status {}", status)
println!("LLDAP exited with status {status}")
}
return;
}
@@ -215,7 +212,7 @@ impl Drop for LLDAPFixture {
let _ = self
.child
.kill()
.map_err(|err| println!("Failed to kill LLDAP: {:?}", err));
.map_err(|err| println!("Failed to kill LLDAP: {err:?}"));
}
}
@@ -223,7 +220,7 @@ pub fn new_id(prefix: Option<&str>) -> String {
let id = Uuid::new_v4();
let id = format!("{}-lldap-test", id.simple());
match prefix {
Some(prefix) => format!("{}{}", prefix, id),
Some(prefix) => format!("{prefix}{id}"),
None => id,
}
}
+1 -1
View File
@@ -103,7 +103,7 @@ where
})
};
let url = env::http_url() + "/api/graphql";
let auth_header = format!("Bearer {}", token);
let auth_header = format!("Bearer {token}");
client
.post(url)
.header(reqwest::header::AUTHORIZATION, auth_header)
+2 -2
View File
@@ -31,13 +31,13 @@ fn gitea() {
ldap.simple_bind(bind_dn.as_str(), env::admin_password().as_str())
.expect("failed to bind to ldap");
let user_base = format!("ou=people,{}", base_dn);
let user_base = format!("ou=people,{base_dn}");
let attrs = vec!["uid", "givenName", "sn", "mail", "jpegPhoto"];
let results = ldap
.search(
user_base.as_str(),
Scope::Subtree,
format!("(memberof=cn={},ou=groups,{})", gitea_user_group, base_dn).as_str(),
format!("(memberof=cn={gitea_user_group},ou=groups,{base_dn})").as_str(),
attrs,
)
.expect("failed to find gitea users")
+2 -2
View File
@@ -86,7 +86,7 @@ fn admin_search() {
ldap.search(
env::base_dn().as_str(),
Scope::Subtree,
format!("(&(objectclass=person)(uid={}))", admin_name).as_str(),
format!("(&(objectclass=person)(uid={admin_name}))").as_str(),
attrs,
)
.expect("failed to find admin"),
@@ -97,7 +97,7 @@ fn admin_search() {
found_users
.get(&admin_name)
.unwrap()
.contains(format!("cn={},ou=groups,{}", admin_group_name, base_dn).as_str())
.contains(format!("cn={admin_group_name},ou=groups,{base_dn}").as_str())
);
ldap.unbind().expect("failed to unbind ldap connection");
}