aboutsummaryrefslogtreecommitdiffstats
path: root/rs/server/src/main.rs
diff options
context:
space:
mode:
authorLibravatar Rutger Broekhoff2024-01-24 18:12:21 +0100
committerLibravatar Rutger Broekhoff2024-01-24 18:12:21 +0100
commit205bb98cb8a61dd2bc2fc154e3e81c6df0d649a2 (patch)
treeebc2707a1b8a5cbdb9a2636d26fa41ebf4e9d70e /rs/server/src/main.rs
parentdbe5de070b8b4c86abe27bb3378e1685632dfdab (diff)
downloadgitolfs3-205bb98cb8a61dd2bc2fc154e3e81c6df0d649a2.tar.gz
gitolfs3-205bb98cb8a61dd2bc2fc154e3e81c6df0d649a2.zip
Clean up claim validation test
Diffstat (limited to 'rs/server/src/main.rs')
-rw-r--r--rs/server/src/main.rs16
1 files changed, 9 insertions, 7 deletions
diff --git a/rs/server/src/main.rs b/rs/server/src/main.rs
index bdf38ef..68ef3b0 100644
--- a/rs/server/src/main.rs
+++ b/rs/server/src/main.rs
@@ -985,25 +985,27 @@ fn test_validate_claims() {
985 let key = "00232f7a019bd34e3921ee6c5f04caf48a4489d1be5d1999038950a7054e0bfea369ce2becc0f13fd3c69f8af2384a25b7ac2d52eb52c33722f3c00c50d4c9c2"; 985 let key = "00232f7a019bd34e3921ee6c5f04caf48a4489d1be5d1999038950a7054e0bfea369ce2becc0f13fd3c69f8af2384a25b7ac2d52eb52c33722f3c00c50d4c9c2";
986 let key: common::Key = key.parse().unwrap(); 986 let key: common::Key = key.parse().unwrap();
987 987
988 let expires_at = Utc::now() + std::time::Duration::from_secs(5 * 60);
989 let claims = common::Claims { 988 let claims = common::Claims {
990 expires_at, 989 expires_at: Utc::now() + std::time::Duration::from_secs(5 * 60),
991 repo_path: "lfs-test.git", 990 repo_path: "lfs-test.git",
992 specific_claims: common::SpecificClaims::BatchApi(common::Operation::Download), 991 specific_claims: common::SpecificClaims::BatchApi(common::Operation::Download),
993 }; 992 };
994 let tag = common::generate_tag(claims, &key).unwrap(); 993 let tag = common::generate_tag(claims, &key).unwrap();
995 let header_value = format!("Gitolfs3-Hmac-Sha256 {tag} {}", expires_at.timestamp()); 994 let header_value = format!(
995 "Gitolfs3-Hmac-Sha256 {tag} {}",
996 claims.expires_at.timestamp()
997 );
996 998
997 let conf = AuthorizationConfig { 999 let conf = AuthorizationConfig {
998 key, 1000 key,
999 trusted_forwarded_hosts: HashSet::new(), 1001 trusted_forwarded_hosts: HashSet::new(),
1000 }; 1002 };
1001 let claims = VerifyClaimsInput { 1003 let verification_claims = VerifyClaimsInput {
1002 repo_path: "lfs-test.git", 1004 repo_path: claims.repo_path,
1003 specific_claims: common::SpecificClaims::BatchApi(common::Operation::Download), 1005 specific_claims: claims.specific_claims,
1004 }; 1006 };
1005 let mut headers = HeaderMap::new(); 1007 let mut headers = HeaderMap::new();
1006 headers.insert(header::AUTHORIZATION, header_value.try_into().unwrap()); 1008 headers.insert(header::AUTHORIZATION, header_value.try_into().unwrap());
1007 1009
1008 assert!(verify_claims(&conf, &claims, &headers).unwrap()); 1010 assert!(verify_claims(&conf, &verification_claims, &headers).unwrap());
1009} 1011}