Fix clippy warnings
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
use thiserror::Error;
|
||||
|
||||
#[allow(clippy::enum_variant_names)]
|
||||
#[derive(Error, Debug)]
|
||||
pub enum Error {
|
||||
pub enum DomainError {
|
||||
#[error("Authentication error for `{0}`")]
|
||||
AuthenticationError(String),
|
||||
#[error("Database error: `{0}`")]
|
||||
@@ -12,4 +13,4 @@ pub enum Error {
|
||||
InternalError(String),
|
||||
}
|
||||
|
||||
pub type Result<T> = std::result::Result<T, Error>;
|
||||
pub type Result<T> = std::result::Result<T, DomainError>;
|
||||
|
||||
@@ -173,8 +173,8 @@ impl BackendHandler for SqlBackendHandler {
|
||||
// Transform it into a single result (the first error if any), and group the group_ids
|
||||
// into a HashSet.
|
||||
.collect::<sqlx::Result<HashSet<_>>>()
|
||||
// Map the sqlx::Error into a domain::Error.
|
||||
.map_err(Error::DatabaseError)
|
||||
// Map the sqlx::Error into a DomainError.
|
||||
.map_err(DomainError::DatabaseError)
|
||||
}
|
||||
|
||||
async fn create_user(&self, request: CreateUserRequest) -> Result<()> {
|
||||
|
||||
@@ -52,7 +52,7 @@ impl LoginHandler for SqlBackendHandler {
|
||||
return Ok(());
|
||||
} else {
|
||||
debug!(r#"Invalid password for LDAP bind user"#);
|
||||
return Err(Error::AuthenticationError(request.name));
|
||||
return Err(DomainError::AuthenticationError(request.name));
|
||||
}
|
||||
}
|
||||
let query = Query::select()
|
||||
@@ -65,7 +65,7 @@ impl LoginHandler for SqlBackendHandler {
|
||||
row.get::<Option<Vec<u8>>, _>(&*Users::PasswordHash.to_string())
|
||||
{
|
||||
if let Err(e) = passwords_match(
|
||||
&&password_hash,
|
||||
&password_hash,
|
||||
&request.password,
|
||||
self.config.get_server_keys().private(),
|
||||
) {
|
||||
@@ -79,7 +79,7 @@ impl LoginHandler for SqlBackendHandler {
|
||||
} else {
|
||||
debug!(r#"No user found for "{}""#, request.name);
|
||||
}
|
||||
Err(Error::AuthenticationError(request.name))
|
||||
Err(DomainError::AuthenticationError(request.name))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,11 +101,11 @@ impl OpaqueHandler for SqlOpaqueHandler {
|
||||
.await?
|
||||
.get::<Option<Vec<u8>>, _>(&*Users::PasswordHash.to_string())
|
||||
// If no password, always fail.
|
||||
.ok_or_else(|| Error::AuthenticationError(request.username.clone()))?
|
||||
.ok_or_else(|| DomainError::AuthenticationError(request.username.clone()))?
|
||||
};
|
||||
let password_file = opaque::server::ServerRegistration::deserialize(&password_file_bytes)
|
||||
.map_err(|_| {
|
||||
Error::InternalError(format!("Corrupted password file for {}", request.username))
|
||||
DomainError::InternalError(format!("Corrupted password file for {}", request.username))
|
||||
})?;
|
||||
|
||||
let mut rng = rand::rngs::OsRng;
|
||||
@@ -163,7 +163,7 @@ impl OpaqueHandler for SqlOpaqueHandler {
|
||||
&row.get::<Vec<u8>, _>(&*LoginAttempts::ServerLoginData.to_string()),
|
||||
)
|
||||
.map_err(|_| {
|
||||
Error::InternalError(format!(
|
||||
DomainError::InternalError(format!(
|
||||
"Corrupted login data for user `{}` [id `{}`]",
|
||||
username, request.login_key
|
||||
))
|
||||
@@ -248,7 +248,7 @@ impl OpaqueHandler for SqlOpaqueHandler {
|
||||
&row.get::<Vec<u8>, _>(&*RegistrationAttempts::ServerRegistrationData.to_string()),
|
||||
)
|
||||
.map_err(|_| {
|
||||
Error::InternalError(format!(
|
||||
DomainError::InternalError(format!(
|
||||
"Corrupted registration data for user `{}` [id `{}`]",
|
||||
username, request.registration_key
|
||||
))
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use crate::{
|
||||
domain::{
|
||||
error::DomainError,
|
||||
handler::{BackendHandler, LoginHandler},
|
||||
opaque_handler::OpaqueHandler,
|
||||
},
|
||||
@@ -191,7 +192,7 @@ where
|
||||
// token.
|
||||
data.backend_handler
|
||||
.get_user_groups(name.to_string())
|
||||
.and_then(|g| async { Ok((g, data.backend_handler.create_refresh_token(&name).await?)) })
|
||||
.and_then(|g| async { Ok((g, data.backend_handler.create_refresh_token(name).await?)) })
|
||||
.await
|
||||
.map(|(groups, (refresh_token, max_age))| {
|
||||
let token = create_jwt(&data.jwt_key, name.to_string(), groups);
|
||||
@@ -205,7 +206,7 @@ where
|
||||
.finish(),
|
||||
)
|
||||
.cookie(
|
||||
Cookie::build("refresh_token", refresh_token + "+" + &name)
|
||||
Cookie::build("refresh_token", refresh_token + "+" + name)
|
||||
.max_age(max_age.num_days().days())
|
||||
.path("/auth")
|
||||
.http_only(true)
|
||||
|
||||
@@ -33,7 +33,7 @@ pub struct Configuration {
|
||||
impl ConfigurationBuilder {
|
||||
#[cfg(test)]
|
||||
pub fn build(self) -> Result<Configuration> {
|
||||
let server_keys = get_server_keys(&self.key_file.as_deref().unwrap_or("server_key"))?;
|
||||
let server_keys = get_server_keys(self.key_file.as_deref().unwrap_or("server_key"))?;
|
||||
Ok(self.server_keys(server_keys).private_build()?)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::{
|
||||
domain::handler::*,
|
||||
domain::{error::DomainError, handler::*},
|
||||
infra::{
|
||||
tcp_backend_handler::*,
|
||||
tcp_server::{error_to_http_response, AppState},
|
||||
@@ -54,7 +54,7 @@ where
|
||||
let msg = err.to_string();
|
||||
actix_web::error::InternalError::from_response(
|
||||
err,
|
||||
HttpResponse::BadRequest().body(msg).into(),
|
||||
HttpResponse::BadRequest().body(msg),
|
||||
)
|
||||
.into()
|
||||
});
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
use async_trait::async_trait;
|
||||
use std::collections::HashSet;
|
||||
|
||||
pub type DomainError = crate::domain::error::Error;
|
||||
pub type DomainResult<T> = crate::domain::error::Result<T>;
|
||||
|
||||
#[async_trait]
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use crate::{
|
||||
domain::{
|
||||
error::DomainError,
|
||||
handler::{BackendHandler, LoginHandler},
|
||||
opaque_handler::OpaqueHandler,
|
||||
},
|
||||
@@ -48,7 +49,7 @@ fn http_config<Backend>(
|
||||
{
|
||||
cfg.data(AppState::<Backend> {
|
||||
backend_handler,
|
||||
jwt_key: Hmac::new_varkey(&jwt_secret.as_bytes()).unwrap(),
|
||||
jwt_key: Hmac::new_varkey(jwt_secret.as_bytes()).unwrap(),
|
||||
jwt_blacklist: RwLock::new(jwt_blacklist),
|
||||
})
|
||||
// Serve index.html and main.js, and default to index.html.
|
||||
|
||||
Reference in New Issue
Block a user