Skip to content

Commit

Permalink
plain token tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sdankel committed May 3, 2024
1 parent 869f07e commit d9eb6b1
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/db/api_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,21 @@ impl DbConn {
.map_err(|_| DatabaseError::NotFound("API Token".to_string()))
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_plain_token_new() {
let token = PlainToken::new();
assert!(token.0.starts_with(TOKEN_PREFIX));
assert_eq!(token.hash(), Sha256::digest(token.0.as_bytes()).as_slice());
}

#[test]
fn test_plain_token_from() {
let token = PlainToken::from("123456".to_string());
assert_eq!(token.hash(), Sha256::digest(token.0.as_bytes()).as_slice());
}
}

0 comments on commit d9eb6b1

Please sign in to comment.