Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
MadsSR committed Nov 24, 2023
1 parent 892692a commit 27a5a8b
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 40 deletions.
21 changes: 9 additions & 12 deletions src/api/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use chrono::{Duration, Utc};
use jsonwebtoken::{
decode, encode, Algorithm, DecodingKey, EncodingKey, Header, TokenData, Validation,
};
use mockall::Any;

use serde::{Deserialize, Serialize};
use std::{env, fmt::Display, str::FromStr};
use tonic::{metadata, Request, Status};
Expand All @@ -22,7 +22,7 @@ pub fn validation_interceptor(mut req: Request<()>) -> Result<Request<()>, Statu
);
Ok(req)
}
Err(err) => Err(err.into())
Err(err) => Err(err.into()),
}
}

Expand Down Expand Up @@ -250,16 +250,13 @@ pub trait RequestTrait {
impl<T> RequestTrait for Request<T> {
/// Returns the token string from the request metadata.
fn token_string(&self) -> Option<String> {
match self.metadata().get("authorization") {
Some(token) => Some(
token
.to_str()
.unwrap()
.trim_start_matches("Bearer ")
.to_string(),
),
None => None,
}
self.metadata().get("authorization").map(|token| {
token
.to_str()
.unwrap()
.trim_start_matches("Bearer ")
.to_string()
})
}
/// Returns the token string slice from the request metadata.
fn token_str(&self) -> Option<&str> {
Expand Down
12 changes: 4 additions & 8 deletions src/api/ecdar_api.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::fmt::Display;
use std::sync::Arc;

use crate::api::auth::{RequestTrait, Token, TokenType};
Expand All @@ -18,13 +17,10 @@ use crate::database::session_context::SessionContextTrait;
use crate::database::user_context::UserContextTrait;
use crate::entities::user::Model as User;

use super::{
auth,
server::server::{
ecdar_backend_server::EcdarBackend, CreateUserRequest, GetAuthTokenRequest,
GetAuthTokenResponse, QueryRequest, QueryResponse, SimulationStartRequest,
SimulationStepRequest, SimulationStepResponse, UpdateUserRequest, UserTokenResponse,
},
use super::server::server::{
ecdar_backend_server::EcdarBackend, CreateUserRequest, GetAuthTokenRequest,
GetAuthTokenResponse, QueryRequest, QueryResponse, SimulationStartRequest,
SimulationStepRequest, SimulationStepResponse, UpdateUserRequest, UserTokenResponse,
};

#[derive(Clone)]
Expand Down
3 changes: 1 addition & 2 deletions src/database/session_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ impl EntityContextTrait<session::Model> for SessionContext {
updated_at: Set(Utc::now().naive_local()),
};

let session = session.insert(&self.db_context.get_connection()).await;
session
session.insert(&self.db_context.get_connection()).await
}

/// Returns a session by searching for its id.
Expand Down
21 changes: 5 additions & 16 deletions src/tests/api/ecdar_api.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,15 @@
#[cfg(test)]
mod ecdar_api {
use crate::api::ecdar_api::handle_session;
use crate::api::server::server::ecdar_api_auth_server::EcdarApiAuth;
use crate::api::server::server::get_auth_token_request::user_credentials;
use crate::api::server::server::get_auth_token_request::UserCredentials;
use crate::api::server::server::{CreateUserRequest, GetAuthTokenRequest, UpdateUserRequest};
use crate::{
api::server::server::ecdar_api_server::EcdarApi, entities::session::Model as Session,
entities::user::Model as User,
};
use async_trait::async_trait;

use crate::api::server::server::ecdar_api_server::EcdarApi;

use futures::SinkExt;
use mockall::predicate;
use sea_orm::DbErr;
use std::str::FromStr;

use crate::database::database_context::DatabaseContextTrait;
use crate::database::entity_context::EntityContextTrait;
use crate::database::user_context::{UserContext, UserContextTrait};
use crate::entities::user;
use crate::tests::api::helpers::{get_mock_concrete_ecdar_api, get_mock_services};
use tonic::{metadata, Code, Request, Response, Status};
use tonic::{metadata, Code, Request};

#[tokio::test]
async fn delete_user_nonexistent_user_returns_err() {
Expand All @@ -34,7 +23,7 @@ mod ecdar_api {

let api = get_mock_concrete_ecdar_api(mock_services).await;

let mut delete_request = Request::new({});
let mut delete_request = Request::new(());

// Insert uid into request metadata
delete_request
Expand Down
2 changes: 1 addition & 1 deletion src/tests/database/model_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ mod database_tests {
.unwrap()
.unwrap();

assert_eq!(fetched_query.outdated, true);
assert!(fetched_query.outdated);
}

#[tokio::test]
Expand Down
2 changes: 1 addition & 1 deletion src/tests/database/query_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ mod database_tests {
.unwrap();

let new_query = query::Model {
string: query.clone().string + "123".into(),
string: query.clone().string + "123",
..query.clone()
};

Expand Down

0 comments on commit 27a5a8b

Please sign in to comment.