aboutsummaryrefslogtreecommitdiffstats
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
parentdbe5de070b8b4c86abe27bb3378e1685632dfdab (diff)
downloadgitolfs3-205bb98cb8a61dd2bc2fc154e3e81c6df0d649a2.tar.gz
gitolfs3-205bb98cb8a61dd2bc2fc154e3e81c6df0d649a2.zip
Clean up claim validation test
-rw-r--r--rs/common/src/lib.rs2
-rw-r--r--rs/server/src/main.rs16
2 files changed, 10 insertions, 8 deletions
diff --git a/rs/common/src/lib.rs b/rs/common/src/lib.rs
index 89c3286..995352d 100644
--- a/rs/common/src/lib.rs
+++ b/rs/common/src/lib.rs
@@ -136,7 +136,7 @@ fn parse_hex_exact(value: &str, buf: &mut [u8]) -> Result<(), ParseHexError> {
136 for (i, c) in value.bytes().enumerate() { 136 for (i, c) in value.bytes().enumerate() {
137 if let Some(b) = decode_nibble(c) { 137 if let Some(b) = decode_nibble(c) {
138 if i % 2 == 0 { 138 if i % 2 == 0 {
139 buf[i / 2] |= b << 4; 139 buf[i / 2] = b << 4;
140 } else { 140 } else {
141 buf[i / 2] |= b; 141 buf[i / 2] |= b;
142 } 142 }
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}