new laptop setup

This commit is contained in:
2022-12-24 16:34:17 +01:00
parent 5b95621d04
commit 31b47e892d
55 changed files with 789 additions and 5 deletions
+55
View File
@@ -0,0 +1,55 @@
use actix_web::dev::ServiceRequest;
pub mod jwt;
pub mod processes;
use crate::auth::processes::check_password;
use crate::auth::processes::extract_header_token;
pub fn process_token(request: &ServiceRequest) -> Result<String, &'static str> {
match extract_header_token(request) {
Ok(token) => check_password(token),
Err(message) => Err(message),
}
}
#[cfg(test)]
mod mod_test {
use actix_web::test::TestRequest;
use super::{jwt::JwtToken, process_token};
#[test]
fn process_token_test() {
let token = JwtToken::encode(32);
let request = TestRequest::delete()
.insert_header(("user-token", token))
.to_srv_request();
match process_token(&request) {
Ok(message) => assert_eq!("passed", message),
Err(_) => panic!("process token failed"),
}
}
#[actix_web::test]
async fn process_token_not_existing() {
let request = TestRequest::default().to_srv_request();
match process_token(&request) {
Err(error) => assert_eq!("there is no token", error),
_ => panic!("Not existing token should not be processes"),
}
}
#[actix_web::test]
async fn process_wrong_token() {
let request = TestRequest::default()
.insert_header(("user-token", "bla"))
.to_srv_request();
match process_token(&request) {
Err(error) => assert_eq!("could not decode token", error),
_ => panic!("Not existing token should not be processes"),
}
}
}