From 73c17840fffa50b2f701a1f001e4320b07c04d8b Mon Sep 17 00:00:00 2001 From: phoenix Date: Thu, 10 Apr 2025 22:30:01 +0000 Subject: [PATCH] Implemented functionality and wrote test for checking token scope (#39) Reviewed-on: https://git.kundeng.us/phoenix/icarus_models/pulls/39 Co-authored-by: phoenix Co-committed-by: phoenix --- src/token.rs | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/src/token.rs b/src/token.rs index badb6ec..8d85986 100644 --- a/src/token.rs +++ b/src/token.rs @@ -57,14 +57,27 @@ impl Token { false } - // TODO: Implement pub fn contains_scope(&self, des_scope: &String) -> bool { - let extracted_token: String = String::from("Token"); - - if extracted_token == *des_scope { - return true; - } - - false + self.scope.contains(des_scope) + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_token_scope_check() { + let mut token = Token::default(); + token.scope = String::from("song:read song:upload song:download"); + + let check_scope = String::from("song:download"); + let result = token.contains_scope(&check_scope); + + assert!( + result, + "Error: The scope {:?} was not found in the token's scope {:?}", + check_scope, token.scope + ); } }