Skip to content

Commit

Permalink
feat: write test (wip)
Browse files Browse the repository at this point in the history
  • Loading branch information
raimundo-henriques committed Nov 30, 2023
1 parent 0c89e38 commit 46697c5
Show file tree
Hide file tree
Showing 4 changed files with 178 additions and 79 deletions.
91 changes: 69 additions & 22 deletions endpoint/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions endpoint/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ base64 = "0.13"
url = { version = "2.4.1", features = ["serde"] }
rsa = { version = "0.9.2", features = ["pem", "sha2"] }
rand = "0.8.5"
jsonwebkey = "0.3.5"


[dependencies.lambda-web]
Expand Down
11 changes: 2 additions & 9 deletions endpoint/src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use rocket::request::{self, FromRequest, Request};
use rocket::response::status;
use rocket::serde::{Deserialize, Serialize};

use rocket::State;
use rocket_okapi::okapi::map;
use rocket_okapi::okapi::openapi3::{
Object, SecurityRequirement, SecurityScheme, SecuritySchemeData,
Expand Down Expand Up @@ -137,13 +136,9 @@ impl<'r> FromRequest<'r> for UserToken {
if authen_str.starts_with("Bearer") {
let token = authen_str[6..authen_str.len()].trim();
let pub_key = &req.rocket().state::<KeyPair>().unwrap().pub_key;
match decode_token(token.to_string(), pub_key.to_string()) {
Ok(token_data) => return Outcome::Success(token_data.claims),
Err(e) => println!("error: {:?}", e),
if let Ok(token_data) = decode_token(token.to_string(), pub_key.to_string()) {
return Outcome::Success(token_data.claims);
}
// if let Ok(token_data) = decode_token(token.to_string(), pub_key.to_string()) {
// return Outcome::Success(token_data.claims);
// }
}

Outcome::Failure((
Expand Down Expand Up @@ -184,8 +179,6 @@ fn decode_token(token: String, pub_key: String) -> Result<TokenData<UserToken>>
v.validate_exp = false;
v.required_spec_claims = HashSet::new();

println!("{v:?}");

jsonwebtoken::decode::<UserToken>(
&token,
&DecodingKey::from_rsa_pem(pub_key.as_bytes()).unwrap(),
Expand Down
Loading

0 comments on commit 46697c5

Please sign in to comment.