Fix clippy findings
This commit is contained in:
parent
99b9d85e47
commit
91559224e5
4 changed files with 22 additions and 13 deletions
|
|
@ -21,6 +21,8 @@ use axum::{body::Body, response::Response, Router};
|
|||
#[cfg(feature = "oidc")]
|
||||
use axum_oidc::{EmptyAdditionalClaims, OidcClaims};
|
||||
use serde::{Deserialize, Serialize};
|
||||
#[cfg(feature = "mock_auth")]
|
||||
use service::permission::MockContext;
|
||||
use service::user_service::UserService;
|
||||
use service::PermissionService;
|
||||
use service::ServiceError;
|
||||
|
|
@ -31,9 +33,8 @@ use tower::ServiceBuilder;
|
|||
use tower_sessions::{cookie::SameSite, Expiry, MemoryStore, SessionManagerLayer};
|
||||
use uuid::Uuid;
|
||||
|
||||
// TODO: In prod, it must be a different type than in dev mode.
|
||||
#[cfg(feature = "mock_auth")]
|
||||
type Context = ();
|
||||
type Context = MockContext;
|
||||
#[cfg(feature = "oidc")]
|
||||
type Context = Option<Arc<str>>;
|
||||
|
||||
|
|
@ -216,9 +217,9 @@ pub fn oidc_config() -> OidcConfig {
|
|||
let client_id = std::env::var("CLIENT_ID").expect("CLIENT_ID env variable");
|
||||
let client_secret = std::env::var("CLIENT_SECRET").ok();
|
||||
OidcConfig {
|
||||
app_url: app_url.into(),
|
||||
issuer: issuer.into(),
|
||||
client_id: client_id.into(),
|
||||
app_url,
|
||||
issuer,
|
||||
client_id,
|
||||
client_secret: client_secret.unwrap_or_default().into(),
|
||||
}
|
||||
}
|
||||
|
|
@ -245,7 +246,7 @@ pub async fn auth_info<RestState: RestStateDef>(
|
|||
) -> Response {
|
||||
let user = rest_state
|
||||
.user_service()
|
||||
.current_user(context.clone().into())
|
||||
.current_user(context.clone())
|
||||
.await
|
||||
.unwrap_or_else(|_| "NoUser".into());
|
||||
let privileges: Arc<[Arc<str>]> = rest_state
|
||||
|
|
@ -253,12 +254,12 @@ pub async fn auth_info<RestState: RestStateDef>(
|
|||
.get_privileges_for_current_user(context.into())
|
||||
.await
|
||||
.unwrap_or_else(|_| Arc::new([]))
|
||||
.into_iter()
|
||||
.iter()
|
||||
.map(|privilege| privilege.name.clone())
|
||||
.collect();
|
||||
let auth_info = AuthInfoTO { user, privileges };
|
||||
|
||||
let response = serde_json::to_string(&AuthInfoTO::from(auth_info)).unwrap();
|
||||
let response = serde_json::to_string(&auth_info).unwrap();
|
||||
Response::builder()
|
||||
.status(200)
|
||||
.body(Body::new(response))
|
||||
|
|
|
|||
|
|
@ -6,6 +6,11 @@ use mockall::automock;
|
|||
|
||||
use crate::ServiceError;
|
||||
|
||||
/// For mocking the context locally since there is actually
|
||||
/// no context.
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct MockContext;
|
||||
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub struct User {
|
||||
pub name: Arc<str>,
|
||||
|
|
|
|||
|
|
@ -11,12 +11,13 @@ mod test;
|
|||
pub mod uuid_service;
|
||||
|
||||
pub use permission::PermissionServiceImpl;
|
||||
use service::permission::MockContext;
|
||||
|
||||
pub struct UserServiceDev;
|
||||
|
||||
#[async_trait]
|
||||
impl service::user_service::UserService for UserServiceDev {
|
||||
type Context = ();
|
||||
type Context = MockContext;
|
||||
|
||||
async fn current_user(
|
||||
&self,
|
||||
|
|
@ -36,8 +37,6 @@ impl service::user_service::UserService for UserServiceImpl {
|
|||
&self,
|
||||
context: Self::Context,
|
||||
) -> Result<Arc<str>, service::ServiceError> {
|
||||
context
|
||||
.ok_or_else(|| service::ServiceError::Unauthorized)
|
||||
.map(|user| user.clone())
|
||||
context.ok_or_else(|| service::ServiceError::Unauthorized)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,7 +54,11 @@ async fn test_user_service_dev() {
|
|||
let user_service = UserServiceDev;
|
||||
assert_eq!(
|
||||
"DEVUSER",
|
||||
user_service.current_user(()).await.unwrap().as_ref()
|
||||
user_service
|
||||
.current_user(MockContext)
|
||||
.await
|
||||
.unwrap()
|
||||
.as_ref()
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue