refactor: extract inline tests to separate files in auth + storage adapters
This commit is contained in:
@@ -47,25 +47,3 @@ impl TokenIssuer for JwtTokenIssuer {
|
||||
Ok((SystemId::from_uuid(uuid), data.claims.role))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[tokio::test]
|
||||
async fn issue_and_verify_roundtrip() {
|
||||
let issuer = JwtTokenIssuer::new("test-secret-key-long-enough-32chars!!");
|
||||
let user_id = SystemId::new();
|
||||
let token = issuer.issue(&user_id, "user").await.unwrap();
|
||||
let (verified_id, verified_role) = issuer.verify(&token).await.unwrap();
|
||||
assert_eq!(verified_id, user_id);
|
||||
assert_eq!(verified_role, "user");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn rejects_invalid_token() {
|
||||
let issuer = JwtTokenIssuer::new("test-secret-key-long-enough-32chars!!");
|
||||
let result = issuer.verify("not.a.valid.jwt").await;
|
||||
assert!(matches!(result, Err(DomainError::Unauthorized(_))));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,16 +23,3 @@ impl PasswordHasher for BcryptPasswordHasher {
|
||||
.map_err(|e| DomainError::Internal(e.to_string()))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[tokio::test]
|
||||
async fn hash_and_verify_roundtrip() {
|
||||
let h = BcryptPasswordHasher;
|
||||
let hash = h.hash("mysecretpassword").await.unwrap();
|
||||
assert!(h.verify("mysecretpassword", &hash).await.unwrap());
|
||||
assert!(!h.verify("wrongpassword", &hash).await.unwrap());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user