1
0
mirror of https://github.com/matrix-org/matrix-authentication-service.git synced 2025-07-28 11:02:02 +03:00

Enable the clippy::str_to_string lint

This commit is contained in:
Quentin Gliech
2022-08-05 10:18:32 +02:00
parent 78fe152d9b
commit c1ed726dc8
39 changed files with 120 additions and 81 deletions

View File

@ -75,7 +75,7 @@ impl Options {
// Read the MAS_CONFIG environment variable
std::env::var("MAS_CONFIG")
// Default to "config.yaml"
.unwrap_or_else(|_| "config.yaml".to_string())
.unwrap_or_else(|_| "config.yaml".to_owned())
// Split the file list on `:`
.split(':')
.map(PathBuf::from)

View File

@ -13,7 +13,7 @@
// limitations under the License.
#![forbid(unsafe_code)]
#![deny(clippy::all)]
#![deny(clippy::all, clippy::str_to_string)]
#![warn(clippy::pedantic)]
#![allow(clippy::module_name_repetitions)]

View File

@ -36,7 +36,7 @@ pub fn port(_gen: &mut SchemaGenerator) -> Schema {
pub fn hostname(_gen: &mut SchemaGenerator) -> Schema {
Schema::Object(SchemaObject {
instance_type: Some(InstanceType::String.into()),
format: Some("hostname".to_string()),
format: Some("hostname".to_owned()),
..SchemaObject::default()
})
}

View File

@ -29,7 +29,7 @@ use super::ConfigurationSection;
use crate::schema;
fn default_connection_string() -> String {
"postgresql://".to_string()
"postgresql://".to_owned()
}
fn default_max_connections() -> NonZeroU32 {

View File

@ -28,7 +28,7 @@ use super::ConfigurationSection;
fn mailbox_schema(_gen: &mut SchemaGenerator) -> Schema {
Schema::Object(SchemaObject {
instance_type: Some(InstanceType::String.into()),
format: Some("email".to_string()),
format: Some("email".to_owned()),
..SchemaObject::default()
})
}
@ -36,7 +36,7 @@ fn mailbox_schema(_gen: &mut SchemaGenerator) -> Schema {
fn hostname_schema(_gen: &mut SchemaGenerator) -> Schema {
Schema::Object(SchemaObject {
instance_type: Some(InstanceType::String.into()),
format: Some("hostname".to_string()),
format: Some("hostname".to_owned()),
..SchemaObject::default()
})
}
@ -107,11 +107,11 @@ impl Default for EmailTransportConfig {
fn default_email() -> Mailbox {
let address = Address::new("root", "localhost").unwrap();
Mailbox::new(Some("Authentication Service".to_string()), address)
Mailbox::new(Some("Authentication Service".to_owned()), address)
}
fn default_sendmail_command() -> String {
"sendmail".to_string()
"sendmail".to_owned()
}
/// Configuration related to sending emails

View File

@ -20,7 +20,7 @@ use serde_with::serde_as;
use super::ConfigurationSection;
fn default_homeserver() -> String {
"localhost:8008".to_string()
"localhost:8008".to_owned()
}
/// Configuration related to the Matrix homeserver
@ -74,7 +74,7 @@ mod tests {
let config = MatrixConfig::load_from_file("config.yaml")?;
assert_eq!(config.homeserver, "matrix.org".to_string());
assert_eq!(config.homeserver, "matrix.org".to_owned());
Ok(())
});

View File

@ -22,15 +22,15 @@ use serde_with::serde_as;
use super::ConfigurationSection;
fn default_client_registration_endpoint() -> String {
"client_registration/violation".to_string()
"client_registration/violation".to_owned()
}
fn default_register_endpoint() -> String {
"register/violation".to_string()
"register/violation".to_owned()
}
fn default_authorization_grant_endpoint() -> String {
"authorization_grant/violation".to_string()
"authorization_grant/violation".to_owned()
}
/// Application secrets

View File

@ -293,7 +293,7 @@ impl ConfigurationSection<'_> for SecretsConfig {
Gh7BNzCeN+D6
-----END PRIVATE KEY-----
"#}
.to_string(),
.to_owned(),
),
};
let ecdsa_key = KeyConfig {
@ -306,7 +306,7 @@ impl ConfigurationSection<'_> for SecretsConfig {
OhBAAUVci1RpmUA+KdCL5sw9nadAEiONeiGr+28RYHZmlB9qXnjC
-----END PRIVATE KEY-----
"#}
.to_string(),
.to_owned(),
),
};

View File

@ -13,7 +13,7 @@
// limitations under the License.
#![forbid(unsafe_code)]
#![deny(clippy::all, rustdoc::broken_intra_doc_links)]
#![deny(clippy::all, clippy::str_to_string, rustdoc::broken_intra_doc_links)]
#![warn(clippy::pedantic)]
#![allow(
clippy::module_name_repetitions,

View File

@ -153,7 +153,7 @@ impl TokenType {
let token_type =
TokenType::match_prefix(prefix).ok_or_else(|| TokenFormatError::UnknownPrefix {
prefix: prefix.to_string(),
prefix: prefix.to_owned(),
})?;
let base = format!("{}_{}", token_type.prefix(), random_part);
@ -162,7 +162,7 @@ impl TokenType {
if crc != expected_crc {
return Err(TokenFormatError::InvalidCrc {
expected: expected_crc,
got: crc.to_string(),
got: crc.to_owned(),
});
}

View File

@ -34,8 +34,8 @@ where
pub fn samples() -> Vec<Self> {
vec![User {
data: Default::default(),
username: "john".to_string(),
sub: "123-456".to_string(),
username: "john".to_owned(),
sub: "123-456".to_owned(),
primary_email: None,
}]
}
@ -147,13 +147,13 @@ where
vec![
Self {
data: T::UserEmailData::default(),
email: "alice@example.com".to_string(),
email: "alice@example.com".to_owned(),
created_at: Utc::now(),
confirmed_at: Some(Utc::now()),
},
Self {
data: T::UserEmailData::default(),
email: "bob@example.com".to_string(),
email: "bob@example.com".to_owned(),
created_at: Utc::now(),
confirmed_at: None,
},
@ -209,7 +209,7 @@ where
.flat_map(|state| {
UserEmail::samples().into_iter().map(move |email| Self {
data: Default::default(),
code: "123456".to_string(),
code: "123456".to_owned(),
email,
created_at: Utc::now() - Duration::minutes(10),
state: state.clone(),

View File

@ -15,7 +15,12 @@
//! Helps sending emails to users, with different email backends
#![forbid(unsafe_code)]
#![deny(clippy::all, missing_docs, rustdoc::broken_intra_doc_links)]
#![deny(
clippy::all,
clippy::str_to_string,
missing_docs,
rustdoc::broken_intra_doc_links
)]
#![warn(clippy::pedantic)]
mod mailer;

View File

@ -98,7 +98,7 @@ pub async fn get(
if Utc::now() > login.created_at + Duration::minutes(30) {
let ctx = ErrorContext::new()
.with_code("compat_sso_login_expired")
.with_description("This login session expired.".to_string());
.with_description("This login session expired.".to_owned());
let content = templates.render_error(&ctx).await?;
return Ok((cookie_jar, Html(content)).into_response());
@ -163,7 +163,7 @@ pub async fn post(
if Utc::now() > login.created_at + Duration::minutes(30) {
let ctx = ErrorContext::new()
.with_code("compat_sso_login_expired")
.with_description("This login session expired.".to_string());
.with_description("This login session expired.".to_owned());
let content = templates.render_error(&ctx).await?;
return Ok((cookie_jar, Html(content)).into_response());

View File

@ -13,7 +13,7 @@
// limitations under the License.
#![forbid(unsafe_code)]
#![deny(clippy::all, rustdoc::broken_intra_doc_links)]
#![deny(clippy::all, clippy::str_to_string, rustdoc::broken_intra_doc_links)]
#![warn(clippy::pedantic)]
#![allow(
clippy::unused_async // Some axum handlers need that
@ -267,7 +267,7 @@ async fn test_router(pool: &PgPool) -> Result<Router, anyhow::Error> {
let url_builder = UrlBuilder::new("https://example.com/".parse()?);
let matrix_config = MatrixConfig {
homeserver: "example.com".to_string(),
homeserver: "example.com".to_owned(),
};
let policy_factory = PolicyFactory::load_default(serde_json::json!({})).await?;

View File

@ -117,15 +117,15 @@ pub(crate) async fn get(
let claim_types_supported = Some(vec![ClaimType::Normal]);
let claims_supported = Some(vec![
"iss".to_string(),
"sub".to_string(),
"aud".to_string(),
"iat".to_string(),
"exp".to_string(),
"nonce".to_string(),
"auth_time".to_string(),
"at_hash".to_string(),
"c_hash".to_string(),
"iss".to_owned(),
"sub".to_owned(),
"aud".to_owned(),
"iat".to_owned(),
"exp".to_owned(),
"nonce".to_owned(),
"auth_time".to_owned(),
"at_hash".to_owned(),
"c_hash".to_owned(),
]);
let claims_parameter_supported = Some(false);

View File

@ -93,7 +93,7 @@ impl IntoResponse for RouteError {
(
StatusCode::UNAUTHORIZED,
Json(PolicyError::new(
"invalid_client_metadata".to_string(),
"invalid_client_metadata".to_owned(),
joined,
)),
)

View File

@ -178,11 +178,11 @@ impl<B> MakeSpanBuilder<Request<B>> for SpanFromAxumRequest {
}
let name = if let Some(path) = request.extensions().get::<MatchedPath>() {
let path = path.as_str().to_string();
let path = path.as_str().to_owned();
attributes.push(HTTP_ROUTE.string(path.clone()));
path
} else {
request.uri().path().to_string()
request.uri().path().to_owned()
};
SpanBuilder::from_name(name)
@ -196,7 +196,7 @@ pub struct SpanFromDnsRequest;
impl MakeSpanBuilder<Name> for SpanFromDnsRequest {
fn make_span_builder(&self, request: &Name) -> SpanBuilder {
let attributes = vec![NET_HOST_NAME.string(request.as_str().to_string())];
let attributes = vec![NET_HOST_NAME.string(request.as_str().to_owned())];
SpanBuilder::from_name("resolve")
.with_kind(SpanKind::Client)

View File

@ -28,6 +28,6 @@ where
{
fn on_error(&self, span: &SpanRef<'_>, err: &E) {
let attributes = vec![EXCEPTION_MESSAGE.string(err.to_string())];
span.add_event("exception".to_string(), attributes);
span.add_event("exception".to_owned(), attributes);
}
}

View File

@ -17,6 +17,7 @@
#![forbid(unsafe_code)]
#![deny(
clippy::all,
clippy::str_to_string,
rustdoc::missing_crate_level_docs,
rustdoc::broken_intra_doc_links
)]

View File

@ -13,7 +13,7 @@
// limitations under the License.
#![forbid(unsafe_code)]
#![deny(clippy::all, rustdoc::broken_intra_doc_links)]
#![deny(clippy::all, clippy::str_to_string, rustdoc::broken_intra_doc_links)]
#![warn(clippy::pedantic)]
use std::{collections::HashMap, fmt::Display, path::PathBuf, sync::Arc};

View File

@ -89,8 +89,8 @@ pub trait EnumEntry: DeserializeOwned + Send + Sync {
(
key,
EnumMember {
value: item.name().to_string(),
description: item.description().map(ToString::to_string),
value: item.name().to_owned(),
description: item.description().map(ToOwned::to_owned),
enum_name: item.enum_name(),
},
)

View File

@ -15,7 +15,12 @@
//! Values from IANA registries, generated by the `mas-iana-codegen` crate
#![forbid(unsafe_code)]
#![deny(clippy::all, missing_docs, rustdoc::broken_intra_doc_links)]
#![deny(
clippy::all,
clippy::str_to_string,
missing_docs,
rustdoc::broken_intra_doc_links
)]
#![warn(clippy::pedantic)]
#![allow(clippy::module_name_repetitions)]

View File

@ -71,7 +71,7 @@ impl<T, V> Claim<T, V> {
let value = value.into();
let value: serde_json::Value =
serde_json::to_value(&value).map_err(|_| ClaimError::InvalidClaim(self.claim))?;
claims.insert(self.claim.to_string(), value);
claims.insert(self.claim.to_owned(), value);
Ok(())
}
@ -365,8 +365,8 @@ mod tests {
#[test]
fn one_or_many_serde() {
let one = OneOrMany(vec!["one".to_string()]);
let many = OneOrMany(vec!["one".to_string(), "two".to_string()]);
let one = OneOrMany(vec!["one".to_owned()]);
let many = OneOrMany(vec!["one".to_owned(), "two".to_owned()]);
assert_eq!(
one,
@ -424,13 +424,13 @@ mod tests {
.unwrap();
let jti = JTI.extract_optional(&mut claims).unwrap();
assert_eq!(iss, "https://foo.com".to_string());
assert_eq!(sub, Some("johndoe".to_string()));
assert_eq!(aud.as_deref(), Some(&vec!["abcd-efgh".to_string()]));
assert_eq!(iss, "https://foo.com".to_owned());
assert_eq!(sub, Some("johndoe".to_owned()));
assert_eq!(aud.as_deref(), Some(&vec!["abcd-efgh".to_owned()]));
assert_eq!(iat.as_deref(), Some(&now));
assert_eq!(nbf.as_deref(), Some(&now));
assert_eq!(exp.as_deref(), Some(&expiration));
assert_eq!(jti, Some("1122-3344-5566-7788".to_string()));
assert_eq!(jti, Some("1122-3344-5566-7788".to_owned()));
assert!(claims.is_empty());
}

View File

@ -252,7 +252,7 @@ mod tests {
let jwt: DecodedJsonWebToken<serde_json::Value> =
jwt.decode_and_verify(&store).await.unwrap();
assert_eq!(jwt.header.typ, Some("JWT".to_string()));
assert_eq!(jwt.header.typ, Some("JWT".to_owned()));
assert_eq!(jwt.header.alg, JsonWebSignatureAlg::Hs256);
assert_eq!(
jwt.payload,

View File

@ -13,7 +13,7 @@
// limitations under the License.
#![forbid(unsafe_code)]
#![deny(clippy::all, rustdoc::broken_intra_doc_links)]
#![deny(clippy::all, clippy::str_to_string, rustdoc::broken_intra_doc_links)]
#![warn(clippy::pedantic)]
#![allow(clippy::missing_errors_doc, clippy::module_name_repetitions)]

View File

@ -13,7 +13,7 @@
// limitations under the License.
#![forbid(unsafe_code)]
#![deny(clippy::all, rustdoc::broken_intra_doc_links)]
#![deny(clippy::all, clippy::str_to_string, rustdoc::broken_intra_doc_links)]
#![warn(clippy::pedantic)]
use mas_iana::oauth::OAuthAuthorizationEndpointResponseType;

View File

@ -64,7 +64,7 @@ mod tests {
#[test]
fn serialize_webfinger_response_test() {
let res = WebFingerResponse::new("acct:john@example.com".to_string())
let res = WebFingerResponse::new("acct:john@example.com".to_owned())
.with_issuer(Url::parse("https://account.example.com/").unwrap());
let res = serde_json::to_value(&res).unwrap();

View File

@ -12,6 +12,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#![forbid(unsafe_code)]
#![deny(clippy::all, clippy::str_to_string, rustdoc::broken_intra_doc_links)]
#![warn(clippy::pedantic)]
#![allow(clippy::missing_errors_doc)]
use std::io::Cursor;
use anyhow::bail;
@ -25,6 +30,7 @@ use wasmtime::{Config, Engine, Module, Store};
const DEFAULT_POLICY: &[u8] = include_bytes!("../policies/policy.wasm");
#[must_use]
pub fn default_wasm_policy() -> impl AsyncRead + std::marker::Unpin {
Cursor::new(DEFAULT_POLICY)
}
@ -109,9 +115,9 @@ impl PolicyFactory {
Self::load(
default_wasm_policy(),
data,
"register/violation".to_string(),
"client_registration/violation".to_string(),
"authorization_grant/violation".to_string(),
"register/violation".to_owned(),
"client_registration/violation".to_owned(),
"authorization_grant/violation".to_owned(),
)
.await
}
@ -158,6 +164,7 @@ pub struct EvaluationResult {
}
impl EvaluationResult {
#[must_use]
pub fn valid(&self) -> bool {
self.violations.is_empty()
}

View File

@ -12,7 +12,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#![deny(clippy::pedantic)]
#![forbid(unsafe_code)]
#![deny(
clippy::all,
clippy::pedantic,
clippy::str_to_string,
rustdoc::broken_intra_doc_links
)]
pub(crate) mod endpoints;
pub(crate) mod traits;

View File

@ -15,7 +15,12 @@
//! Serve static files used by the web frontend
#![forbid(unsafe_code)]
#![deny(clippy::all, missing_docs, rustdoc::broken_intra_doc_links)]
#![deny(
clippy::all,
clippy::str_to_string,
missing_docs,
rustdoc::broken_intra_doc_links
)]
#![warn(clippy::pedantic)]
#[cfg(not(feature = "dev"))]

View File

@ -317,7 +317,7 @@ pub async fn compat_login(
// TODO: pass verifiers list as parameter
// Verify the password in a blocking thread to avoid blocking the async executor
let password = password.to_string();
let password = password.to_owned();
task::spawn_blocking(move || {
let context = Argon2::default();
let hasher = PasswordHash::new(&hashed_password)?;

View File

@ -15,7 +15,7 @@
//! Interactions with the database
#![forbid(unsafe_code)]
#![deny(clippy::all, rustdoc::broken_intra_doc_links)]
#![deny(clippy::all, clippy::str_to_string, rustdoc::broken_intra_doc_links)]
#![warn(clippy::pedantic)]
#![allow(
clippy::missing_errors_doc,

View File

@ -51,7 +51,7 @@ pub async fn add_access_token(
Ok(AccessToken {
data: res.id,
expires_after,
token: token.to_string(),
token: token.to_owned(),
jti: format!("{}", res.id),
created_at: res.created_at,
})

View File

@ -49,7 +49,7 @@ pub async fn add_refresh_token(
Ok(RefreshToken {
data: res.id,
token: token.to_string(),
token: token.to_owned(),
access_token: Some(access_token),
created_at: res.created_at,
})

View File

@ -73,7 +73,7 @@ pub async fn login(
.map_err(|source| {
if source.not_found() {
LoginError::NotFound {
username: username.to_string(),
username: username.to_owned(),
source,
}
} else {
@ -87,7 +87,7 @@ pub async fn login(
.map_err(|source| {
if matches!(source, AuthenticationError::Password { .. }) {
LoginError::Authentication {
username: username.to_string(),
username: username.to_owned(),
source,
}
} else {
@ -297,7 +297,7 @@ pub async fn authenticate_session(
// TODO: pass verifiers list as parameter
// Verify the password in a blocking thread to avoid blocking the async executor
let password = password.to_string();
let password = password.to_owned();
task::spawn_blocking(move || {
let context = Argon2::default();
let hasher = PasswordHash::new(&hashed_password).map_err(AuthenticationError::Password)?;
@ -353,7 +353,7 @@ pub async fn register_user(
let user = User {
data: id,
username: username.to_string(),
username: username.to_owned(),
sub: format!("fake-sub-{}", id),
primary_email: None,
};

View File

@ -19,7 +19,12 @@
//! considered "good enough" for now.
#![forbid(unsafe_code)]
#![deny(clippy::all, missing_docs, rustdoc::broken_intra_doc_links)]
#![deny(
clippy::all,
clippy::str_to_string,
missing_docs,
rustdoc::broken_intra_doc_links
)]
#![warn(clippy::pedantic)]
use std::{collections::VecDeque, sync::Arc, time::Duration};

View File

@ -281,7 +281,7 @@ impl TemplateContext for LoginContext {
vec![LoginContext {
form: FormState::default(),
next: None,
register_link: "/register".to_string(),
register_link: "/register".to_owned(),
}]
}
}
@ -355,7 +355,7 @@ impl TemplateContext for RegisterContext {
vec![RegisterContext {
form: FormState::default(),
next: None,
login_link: "/login".to_string(),
login_link: "/login".to_owned(),
}]
}
}
@ -621,14 +621,14 @@ impl TemplateContext for EmailVerificationContext {
.map(|user| {
let email = UserEmail {
data: (),
email: "foobar@example.com".to_string(),
email: "foobar@example.com".to_owned(),
created_at: Utc::now(),
confirmed_at: None,
};
let verification = UserEmailVerification {
data: (),
code: "123456".to_string(),
code: "123456".to_owned(),
email,
created_at: Utc::now(),
state: mas_data_model::UserEmailVerificationState::Valid,
@ -690,7 +690,7 @@ impl TemplateContext for EmailVerificationPageContext {
{
let email = UserEmail {
data: (),
email: "foobar@example.com".to_string(),
email: "foobar@example.com".to_owned(),
created_at: Utc::now(),
confirmed_at: None,
};

View File

@ -203,8 +203,8 @@ mod tests {
#[test]
fn form_state_serialization() {
let form = TestForm {
foo: "john".to_string(),
bar: "hunter2".to_string(),
foo: "john".to_owned(),
bar: "hunter2".to_owned(),
};
let state = form.to_form_state();
@ -227,8 +227,8 @@ mod tests {
);
let form = TestForm {
foo: "".to_string(),
bar: "".to_string(),
foo: "".to_owned(),
bar: "".to_owned(),
};
let state = form
.to_form_state()

View File

@ -13,7 +13,12 @@
// limitations under the License.
#![forbid(unsafe_code)]
#![deny(clippy::all, missing_docs, rustdoc::broken_intra_doc_links)]
#![deny(
clippy::all,
clippy::str_to_string,
missing_docs,
rustdoc::broken_intra_doc_links
)]
#![warn(clippy::pedantic)]
#![allow(clippy::module_name_repetitions, clippy::missing_errors_doc)]