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
+2 -2
View File
@@ -12,11 +12,11 @@ pub fn deserialize_attribute_value(
let parse_int = |value: &String| -> Result<i64> {
value
.parse::<i64>()
.with_context(|| format!("Invalid integer value {}", value))
.with_context(|| format!("Invalid integer value {value}"))
};
let parse_date = |value: &String| -> Result<chrono::NaiveDateTime> {
Ok(chrono::DateTime::parse_from_rfc3339(value)
.with_context(|| format!("Invalid date value {}", value))?
.with_context(|| format!("Invalid date value {value}"))?
.naive_utc())
};
let parse_photo = |value: &String| -> Result<JpegPhoto> {
+1 -1
View File
@@ -377,7 +377,7 @@ impl std::fmt::Debug for JpegPhoto {
encoded.push_str(" ...");
};
f.debug_tuple("JpegPhoto")
.field(&format!("b64[{}]", encoded))
.field(&format!("b64[{encoded}]"))
.finish()
}
}
+1 -1
View File
@@ -75,7 +75,7 @@ pub fn export_schema(output_file: Option<String>) -> anyhow::Result<()> {
use lldap_sql_backend_handler::SqlBackendHandler;
let output = schema::<SqlBackendHandler>().as_schema_language();
match output_file {
None => println!("{}", output),
None => println!("{output}"),
Some(path) => {
use std::fs::File;
use std::io::prelude::*;
+6 -8
View File
@@ -76,7 +76,7 @@ pub fn get_group_attribute(
.users
.iter()
.filter(|u| user_filter.as_ref().map(|f| *u == f).unwrap_or(true))
.map(|u| format!("uid={},ou=people,{}", u, base_dn_str).into_bytes())
.map(|u| format!("uid={u},ou=people,{base_dn_str}").into_bytes())
.collect(),
GroupFieldType::Uuid => vec![group.uuid.to_string().into_bytes()],
GroupFieldType::Attribute(attr, _, _) => get_custom_attribute(&group.attributes, &attr)?,
@@ -86,8 +86,7 @@ pub fn get_group_attribute(
"+" => return None,
"*" => {
panic!(
"Matched {}, * should have been expanded into attribute list and * removed",
attribute
"Matched {attribute}, * should have been expanded into attribute list and * removed"
)
}
_ => {
@@ -211,7 +210,7 @@ fn convert_group_filter(
.map(GroupRequestFilter::Uuid)
.map_err(|e| LdapError {
code: LdapResultCode::Other,
message: format!("Invalid UUID: {:#}", e),
message: format!("Invalid UUID: {e:#}"),
}),
GroupFieldType::Member => Ok(get_user_id_from_distinguished_name_or_plain_name(
&value_lc,
@@ -290,15 +289,14 @@ fn convert_group_filter(
_ => Err(LdapError {
code: LdapResultCode::UnwillingToPerform,
message: format!(
"Unsupported group attribute for substring filter: \"{}\"",
field
"Unsupported group attribute for substring filter: \"{field}\""
),
}),
}
}
_ => Err(LdapError {
code: LdapResultCode::UnwillingToPerform,
message: format!("Unsupported group filter: {:?}", filter),
message: format!("Unsupported group filter: {filter:?}"),
}),
}
}
@@ -318,7 +316,7 @@ pub async fn get_groups_list<Backend: GroupListerBackendHandler>(
.await
.map_err(|e| LdapError {
code: LdapResultCode::Other,
message: format!(r#"Error while listing groups "{}": {:#}"#, base, e),
message: format!(r#"Error while listing groups "{base}": {e:#}"#),
})
}
+4 -8
View File
@@ -100,8 +100,7 @@ pub fn get_user_attribute(
"+" => return None,
"*" => {
panic!(
"Matched {}, * should have been expanded into attribute list and * removed",
attribute
"Matched {attribute}, * should have been expanded into attribute list and * removed"
)
}
_ => {
@@ -298,10 +297,7 @@ fn convert_user_filter(
| UserFieldType::PrimaryField(UserColumn::CreationDate)
| UserFieldType::PrimaryField(UserColumn::Uuid) => Err(LdapError {
code: LdapResultCode::UnwillingToPerform,
message: format!(
"Unsupported user attribute for substring filter: {:?}",
field
),
message: format!("Unsupported user attribute for substring filter: {field:?}"),
}),
UserFieldType::NoMatch => Ok(UserRequestFilter::from(false)),
UserFieldType::PrimaryField(UserColumn::Email) => Ok(UserRequestFilter::SubString(
@@ -316,7 +312,7 @@ fn convert_user_filter(
}
_ => Err(LdapError {
code: LdapResultCode::UnwillingToPerform,
message: format!("Unsupported user filter: {:?}", filter),
message: format!("Unsupported user filter: {filter:?}"),
}),
}
}
@@ -341,7 +337,7 @@ pub async fn get_user_list<Backend: UserListerBackendHandler>(
.await
.map_err(|e| LdapError {
code: LdapResultCode::Other,
message: format!(r#"Error while searching user "{}": {:#}"#, base, e),
message: format!(r#"Error while searching user "{base}": {e:#}"#),
})
}
+6 -7
View File
@@ -66,10 +66,9 @@ impl UserOrGroupName {
UserOrGroupName::InvalidSyntax(err) => return err,
UserOrGroupName::UnexpectedFormat
| UserOrGroupName::User(_)
| UserOrGroupName::Group(_) => format!(
r#"Unexpected DN format. Got "{}", expected: {}"#,
input, expected_format
),
| UserOrGroupName::Group(_) => {
format!(r#"Unexpected DN format. Got "{input}", expected: {expected_format}"#)
}
},
}
}
@@ -105,7 +104,7 @@ pub fn get_user_id_from_distinguished_name(
) -> LdapResult<UserId> {
match get_user_or_group_id_from_distinguished_name(dn, base_tree) {
UserOrGroupName::User(user_id) => Ok(user_id),
err => Err(err.into_ldap_error(dn, format!(r#""uid=id,ou=people,{}""#, base_dn_str))),
err => Err(err.into_ldap_error(dn, format!(r#""uid=id,ou=people,{base_dn_str}""#))),
}
}
@@ -116,7 +115,7 @@ pub fn get_group_id_from_distinguished_name(
) -> LdapResult<GroupName> {
match get_user_or_group_id_from_distinguished_name(dn, base_tree) {
UserOrGroupName::Group(group_name) => Ok(group_name),
err => Err(err.into_ldap_error(dn, format!(r#""uid=id,ou=groups,{}""#, base_dn_str))),
err => Err(err.into_ldap_error(dn, format!(r#""uid=id,ou=groups,{base_dn_str}""#))),
}
}
@@ -343,7 +342,7 @@ pub struct ObjectClassList(Vec<LdapObjectClass>);
// See RFC4512 section 4.2.1 "objectClasses"
impl ObjectClassList {
pub fn format_for_ldap_schema_description(&self) -> String {
join(self.0.iter().map(|c| format!("'{}'", c)), " ")
join(self.0.iter().map(|c| format!("'{c}'")), " ")
}
}
+5 -11
View File
@@ -33,10 +33,7 @@ pub(crate) async fn create_user_or_group(
}
err => Err(err.into_ldap_error(
&request.dn,
format!(
r#""uid=id,ou=people,{}" or "uid=id,ou=groups,{}""#,
base_dn_str, base_dn_str
),
format!(r#""uid=id,ou=people,{base_dn_str}" or "uid=id,ou=groups,{base_dn_str}""#),
)),
}
}
@@ -73,10 +70,7 @@ async fn create_user(
std::str::from_utf8(val)
.map_err(|e| LdapError {
code: LdapResultCode::ConstraintViolation,
message: format!(
"Attribute value is invalid UTF-8: {:#?} (value {:?})",
e, val
),
message: format!("Attribute value is invalid UTF-8: {e:#?} (value {val:?})"),
})
.map(str::to_owned)
}
@@ -92,7 +86,7 @@ async fn create_user(
value: deserialize::deserialize_attribute_value(&[value], typ, false).map_err(|e| {
LdapError {
code: LdapResultCode::ConstraintViolation,
message: format!("Invalid attribute value: {}", e),
message: format!("Invalid attribute value: {e}"),
}
})?,
})
@@ -134,7 +128,7 @@ async fn create_user(
.await
.map_err(|e| LdapError {
code: LdapResultCode::OperationsError,
message: format!("Could not create user: {:#?}", e),
message: format!("Could not create user: {e:#?}"),
})?;
Ok(vec![make_add_response(
LdapResultCode::Success,
@@ -156,7 +150,7 @@ async fn create_group(
.await
.map_err(|e| LdapError {
code: LdapResultCode::OperationsError,
message: format!("Could not create group: {:#?}", e),
message: format!("Could not create group: {e:#?}"),
})?;
Ok(vec![make_add_response(
LdapResultCode::Success,
+5 -8
View File
@@ -30,10 +30,7 @@ pub(crate) async fn delete_user_or_group(
UserOrGroupName::Group(group_name) => delete_group(backend_handler, group_name).await,
err => Err(err.into_ldap_error(
&request,
format!(
r#""uid=id,ou=people,{}" or "uid=id,ou=groups,{}""#,
base_dn_str, base_dn_str
),
format!(r#""uid=id,ou=people,{base_dn_str}" or "uid=id,ou=groups,{base_dn_str}""#),
)),
}
}
@@ -53,7 +50,7 @@ async fn delete_user(
},
e => LdapError {
code: LdapResultCode::OperationsError,
message: format!("Error while finding user: {:?}", e),
message: format!("Error while finding user: {e:?}"),
},
})?;
backend_handler
@@ -61,7 +58,7 @@ async fn delete_user(
.await
.map_err(|e| LdapError {
code: LdapResultCode::OperationsError,
message: format!("Error while deleting user: {:?}", e),
message: format!("Error while deleting user: {e:?}"),
})?;
Ok(vec![make_del_response(
LdapResultCode::Success,
@@ -79,7 +76,7 @@ async fn delete_group(
.await
.map_err(|e| LdapError {
code: LdapResultCode::OperationsError,
message: format!("Error while finding group: {:?}", e),
message: format!("Error while finding group: {e:?}"),
})?;
let group_id = groups
.iter()
@@ -94,7 +91,7 @@ async fn delete_group(
.await
.map_err(|e| LdapError {
code: LdapResultCode::OperationsError,
message: format!("Error while deleting group: {:?}", e),
message: format!("Error while deleting group: {e:?}"),
})?;
Ok(vec![make_del_response(
LdapResultCode::Success,
+4 -7
View File
@@ -100,10 +100,7 @@ impl<Backend: BackendHandler + LoginHandler + OpaqueHandler> LdapHandler<Backend
backend_handler,
ldap_info: LdapInfo {
base_dn: parse_distinguished_name(&ldap_base_dn).unwrap_or_else(|_| {
panic!(
"Invalid value for ldap_base_dn in configuration: {}",
ldap_base_dn
)
panic!("Invalid value for ldap_base_dn in configuration: {ldap_base_dn}")
}),
base_dn_str: ldap_base_dn,
ignored_user_attributes,
@@ -155,7 +152,7 @@ impl<Backend: BackendHandler + LoginHandler + OpaqueHandler> LdapHandler<Backend
let schema = backend_handler.get_schema().await.map_err(|e| LdapError {
code: LdapResultCode::OperationsError,
message: format!("Unable to get schema: {:#}", e),
message: format!("Unable to get schema: {e:#}"),
})?;
return Ok(vec![
make_ldap_subschema_entry(PublicSchema::from(schema)),
@@ -224,7 +221,7 @@ impl<Backend: BackendHandler + LoginHandler + OpaqueHandler> LdapHandler<Backend
}
Err(e) => vec![make_extended_response(
LdapResultCode::ProtocolError,
format!("Error while parsing password modify request: {:#?}", e),
format!("Error while parsing password modify request: {e:#?}"),
)],
},
OID_WHOAMI => {
@@ -343,7 +340,7 @@ impl<Backend: BackendHandler + LoginHandler + OpaqueHandler> LdapHandler<Backend
.unwrap_or_else(|e: LdapError| vec![make_search_error(e.code, e.message)]),
op => vec![make_extended_response(
LdapResultCode::UnwillingToPerform,
format!("Unsupported operation: {:#?}", op),
format!("Unsupported operation: {op:#?}"),
)],
})
}
+5 -5
View File
@@ -47,7 +47,7 @@ async fn handle_modify_change(
.await
.map_err(|e| LdapError {
code: LdapResultCode::Other,
message: format!("Error while changing the password: {:#?}", e),
message: format!("Error while changing the password: {e:#?}"),
})?;
} else {
return Err(LdapError {
@@ -94,7 +94,7 @@ where
.await
.map_err(|e| LdapError {
code: LdapResultCode::OperationsError,
message: format!("Internal error while requesting user's groups: {:#?}", e),
message: format!("Internal error while requesting user's groups: {e:#?}"),
})?
.iter()
.any(|g| g.display_name == "lldap_admin".into());
@@ -115,7 +115,7 @@ where
}
Err(e) => Err(LdapError {
code: LdapResultCode::InvalidDNSyntax,
message: format!("Invalid username: {}", e),
message: format!("Invalid username: {e}"),
}),
}
}
@@ -166,7 +166,7 @@ mod tests {
fn make_password_modify_request(target_user: &str) -> LdapModifyRequest {
LdapModifyRequest {
dn: format!("uid={},ou=people,dc=example,dc=com", target_user),
dn: format!("uid={target_user},ou=people,dc=example,dc=com"),
changes: vec![LdapModify {
operation: LdapModifyType::Replace,
modification: ldap3_proto::LdapPartialAttribute {
@@ -284,7 +284,7 @@ mod tests {
let request = {
let target_user = "bob";
LdapModifyRequest {
dn: format!("uid={},ou=people,dc=example,dc=com", target_user),
dn: format!("uid={target_user},ou=people,dc=example,dc=com"),
changes: vec![LdapModify {
operation: LdapModifyType::Replace,
modification: ldap3_proto::LdapPartialAttribute {
+3 -4
View File
@@ -112,8 +112,7 @@ pub(crate) async fn do_password_modification<Handler: BackendHandler>(
.map_err(|e| LdapError {
code: LdapResultCode::OperationsError,
message: format!(
"Internal error while requesting user's groups: {:#?}",
e
"Internal error while requesting user's groups: {e:#?}"
),
})?
.iter()
@@ -131,7 +130,7 @@ pub(crate) async fn do_password_modification<Handler: BackendHandler>(
{
Err(LdapError {
code: LdapResultCode::Other,
message: format!("Error while changing the password: {:#?}", e),
message: format!("Error while changing the password: {e:#?}"),
})
} else {
Ok(vec![make_extended_response(
@@ -142,7 +141,7 @@ pub(crate) async fn do_password_modification<Handler: BackendHandler>(
}
Err(e) => Err(LdapError {
code: LdapResultCode::InvalidDNSyntax,
message: format!("Invalid username: {}", e),
message: format!("Invalid username: {e}"),
}),
}
}
+1 -1
View File
@@ -369,7 +369,7 @@ pub async fn do_search(
) -> LdapResult<Vec<LdapOp>> {
let schema = PublicSchema::from(backend_handler.get_schema().await.map_err(|e| LdapError {
code: LdapResultCode::OperationsError,
message: format!("Unable to get schema: {:#}", e),
message: format!("Unable to get schema: {e:#}"),
})?);
let search_results = do_search_internal(ldap_info, backend_handler, request, &schema).await?;
let mut results = match search_results {
@@ -91,7 +91,7 @@ pub mod tests {
handler
.create_user(CreateUserRequest {
user_id: UserId::new(name),
email: format!("{}@bob.bob", name).into(),
email: format!("{name}@bob.bob").into(),
display_name: Some("display ".to_string() + name),
attributes: vec![
DomainAttribute {
@@ -164,7 +164,7 @@ impl GroupBackendHandler for SqlBackendHandler {
.one(&self.sql_pool)
.await?
.map(Into::<GroupDetails>::into)
.ok_or_else(|| DomainError::EntityNotFound(format!("{:?}", group_id)))?;
.ok_or_else(|| DomainError::EntityNotFound(format!("{group_id:?}")))?;
let attributes = model::GroupAttributes::find()
.filter(model::GroupAttributesColumn::GroupId.eq(group_details.group_id))
.order_by_asc(model::GroupAttributesColumn::AttributeName)
@@ -252,8 +252,7 @@ impl GroupBackendHandler for SqlBackendHandler {
.await?;
if res.rows_affected == 0 {
return Err(DomainError::EntityNotFound(format!(
"No such group: '{:?}'",
group_id
"No such group: '{group_id:?}'"
)));
}
Ok(())
@@ -306,8 +305,7 @@ impl SqlBackendHandler {
remove_group_attributes.push(attribute);
} else {
return Err(DomainError::InternalError(format!(
"Group attribute name {} doesn't exist in the schema, yet was attempted to be removed from the database",
attribute
"Group attribute name {attribute} doesn't exist in the schema, yet was attempted to be removed from the database"
)));
}
}
@@ -240,8 +240,7 @@ impl SqlBackendHandler {
remove_user_attributes.push(attribute);
} else {
return Err(DomainError::InternalError(format!(
"User attribute name {} doesn't exist in the schema, yet was attempted to be removed from the database",
attribute
"User attribute name {attribute} doesn't exist in the schema, yet was attempted to be removed from the database"
)));
}
}
@@ -384,8 +383,7 @@ impl UserBackendHandler for SqlBackendHandler {
.await?;
if res.rows_affected == 0 {
return Err(DomainError::EntityNotFound(format!(
"No such user: '{}'",
user_id
"No such user: '{user_id}'"
)));
}
Ok(())
@@ -408,8 +406,7 @@ impl UserBackendHandler for SqlBackendHandler {
.await?;
if res.rows_affected == 0 {
return Err(DomainError::EntityNotFound(format!(
"No such membership: '{}' -> {:?}",
user_id, group_id
"No such membership: '{user_id}' -> {group_id:?}"
)));
}
Ok(())
+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");
}