upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/grasp-audit/src/specs/grasp01/git_clone.rs
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2025-12-01 14:31:32 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2025-12-01 15:22:38 +0000
commitd2ac69816567f092fe0d4661723bc43778cb481b (patch)
treee8b51b61a6a7b0ab1a214adebe4e237143b01f0b /grasp-audit/src/specs/grasp01/git_clone.rs
parent7a78815e29b01c83f3d0ec195ba717a2eba8cd37 (diff)
fix cargo clippy and fmt warnings
Diffstat (limited to 'grasp-audit/src/specs/grasp01/git_clone.rs')
-rw-r--r--grasp-audit/src/specs/grasp01/git_clone.rs54
1 files changed, 18 insertions, 36 deletions
diff --git a/grasp-audit/src/specs/grasp01/git_clone.rs b/grasp-audit/src/specs/grasp01/git_clone.rs
index 9ee6ed7..95338e4 100644
--- a/grasp-audit/src/specs/grasp01/git_clone.rs
+++ b/grasp-audit/src/specs/grasp01/git_clone.rs
@@ -25,10 +25,7 @@ pub struct GitCloneTests;
25 25
26impl GitCloneTests { 26impl GitCloneTests {
27 /// Run all Git clone tests 27 /// Run all Git clone tests
28 pub async fn run_all( 28 pub async fn run_all(client: &AuditClient, relay_domain: &str) -> crate::AuditResult {
29 client: &AuditClient,
30 relay_domain: &str,
31 ) -> crate::AuditResult {
32 let mut results = crate::AuditResult::new("GRASP-01 Git Clone Tests"); 29 let mut results = crate::AuditResult::new("GRASP-01 Git Clone Tests");
33 30
34 results.add(Self::test_basic_git_clone(client, relay_domain).await); 31 results.add(Self::test_basic_git_clone(client, relay_domain).await);
@@ -45,10 +42,7 @@ impl GitCloneTests {
45 /// 2. Waits for repository creation 42 /// 2. Waits for repository creation
46 /// 3. Attempts to clone the repository using git clone 43 /// 3. Attempts to clone the repository using git clone
47 /// 4. Verifies the clone succeeded 44 /// 4. Verifies the clone succeeded
48 pub async fn test_basic_git_clone( 45 pub async fn test_basic_git_clone(client: &AuditClient, relay_domain: &str) -> TestResult {
49 client: &AuditClient,
50 relay_domain: &str,
51 ) -> TestResult {
52 let test_name = "test_basic_git_clone"; 46 let test_name = "test_basic_git_clone";
53 let ctx = TestContext::new(client); 47 let ctx = TestContext::new(client);
54 48
@@ -61,7 +55,7 @@ impl GitCloneTests {
61 "GRASP-01", 55 "GRASP-01",
62 "Repository must be cloneable via Git HTTP backend", 56 "Repository must be cloneable via Git HTTP backend",
63 ) 57 )
64 .fail(&format!("Failed to create repo fixture: {}", e)) 58 .fail(format!("Failed to create repo fixture: {}", e))
65 } 59 }
66 }; 60 };
67 61
@@ -94,7 +88,7 @@ impl GitCloneTests {
94 "GRASP-01", 88 "GRASP-01",
95 "Repository must be cloneable via Git HTTP backend", 89 "Repository must be cloneable via Git HTTP backend",
96 ) 90 )
97 .fail(&format!("Failed to convert pubkey to npub: {}", e)) 91 .fail(format!("Failed to convert pubkey to npub: {}", e))
98 } 92 }
99 }; 93 };
100 94
@@ -102,7 +96,7 @@ impl GitCloneTests {
102 let temp_base = std::env::temp_dir(); 96 let temp_base = std::env::temp_dir();
103 let clone_dir_name = format!("grasp-test-clone-{}", uuid::Uuid::new_v4()); 97 let clone_dir_name = format!("grasp-test-clone-{}", uuid::Uuid::new_v4());
104 let clone_path = temp_base.join(&clone_dir_name); 98 let clone_path = temp_base.join(&clone_dir_name);
105 99
106 // Ensure clean state 100 // Ensure clean state
107 let _ = fs::remove_dir_all(&clone_path); 101 let _ = fs::remove_dir_all(&clone_path);
108 102
@@ -114,7 +108,7 @@ impl GitCloneTests {
114 .args(["clone", &clone_url, clone_path.to_str().unwrap()]) 108 .args(["clone", &clone_url, clone_path.to_str().unwrap()])
115 .env("GIT_TERMINAL_PROMPT", "0") // Disable password prompts 109 .env("GIT_TERMINAL_PROMPT", "0") // Disable password prompts
116 .output(); 110 .output();
117 111
118 // Clean up on success or failure 112 // Clean up on success or failure
119 let cleanup = || { 113 let cleanup = || {
120 let _ = fs::remove_dir_all(&clone_path); 114 let _ = fs::remove_dir_all(&clone_path);
@@ -129,7 +123,7 @@ impl GitCloneTests {
129 "GRASP-01", 123 "GRASP-01",
130 "Repository must be cloneable via Git HTTP backend", 124 "Repository must be cloneable via Git HTTP backend",
131 ) 125 )
132 .fail(&format!("Failed to execute git clone: {}", e)) 126 .fail(format!("Failed to execute git clone: {}", e));
133 } 127 }
134 }; 128 };
135 129
@@ -141,7 +135,7 @@ impl GitCloneTests {
141 "GRASP-01", 135 "GRASP-01",
142 "Repository must be cloneable via Git HTTP backend", 136 "Repository must be cloneable via Git HTTP backend",
143 ) 137 )
144 .fail(&format!("Git clone failed: {}", stderr)); 138 .fail(format!("Git clone failed: {}", stderr));
145 } 139 }
146 140
147 // Verify clone succeeded by checking for .git directory 141 // Verify clone succeeded by checking for .git directory
@@ -169,10 +163,7 @@ impl GitCloneTests {
169 /// This test verifies: 163 /// This test verifies:
170 /// 1. URLs follow the pattern http://domain/npub/identifier.git 164 /// 1. URLs follow the pattern http://domain/npub/identifier.git
171 /// 2. Invalid URLs are rejected properly 165 /// 2. Invalid URLs are rejected properly
172 pub async fn test_clone_url_format( 166 pub async fn test_clone_url_format(client: &AuditClient, relay_domain: &str) -> TestResult {
173 client: &AuditClient,
174 relay_domain: &str,
175 ) -> TestResult {
176 let test_name = "test_clone_url_format"; 167 let test_name = "test_clone_url_format";
177 let ctx = TestContext::new(client); 168 let ctx = TestContext::new(client);
178 169
@@ -185,7 +176,7 @@ impl GitCloneTests {
185 "GRASP-01", 176 "GRASP-01",
186 "Clone URL must follow correct format", 177 "Clone URL must follow correct format",
187 ) 178 )
188 .fail(&format!("Failed to create repo fixture: {}", e)) 179 .fail(format!("Failed to create repo fixture: {}", e))
189 } 180 }
190 }; 181 };
191 182
@@ -205,7 +196,7 @@ impl GitCloneTests {
205 196
206 // Test valid URL format 197 // Test valid URL format
207 let valid_url = format!("http://{}/{}/{}.git", relay_domain, npub, repo_id); 198 let valid_url = format!("http://{}/{}/{}.git", relay_domain, npub, repo_id);
208 199
209 // Verify URL contains expected components 200 // Verify URL contains expected components
210 if !valid_url.contains(&npub) { 201 if !valid_url.contains(&npub) {
211 return TestResult::new( 202 return TestResult::new(
@@ -229,10 +220,10 @@ impl GitCloneTests {
229 let temp_base = std::env::temp_dir(); 220 let temp_base = std::env::temp_dir();
230 let clone_dir_name = format!("grasp-test-invalid-{}", uuid::Uuid::new_v4()); 221 let clone_dir_name = format!("grasp-test-invalid-{}", uuid::Uuid::new_v4());
231 let clone_path = temp_base.join(&clone_dir_name); 222 let clone_path = temp_base.join(&clone_dir_name);
232 223
233 // Ensure clean state 224 // Ensure clean state
234 let _ = fs::remove_dir_all(&clone_path); 225 let _ = fs::remove_dir_all(&clone_path);
235 226
236 let invalid_url = format!("http://{}/invalid/path", relay_domain); 227 let invalid_url = format!("http://{}/invalid/path", relay_domain);
237 228
238 let output = Command::new("git") 229 let output = Command::new("git")
@@ -287,7 +278,7 @@ impl GitCloneTests {
287 "GRASP-01", 278 "GRASP-01",
288 "MUST include allow-reachable-sha1-in-want and allow-tip-sha1-in-want in advertisement", 279 "MUST include allow-reachable-sha1-in-want and allow-tip-sha1-in-want in advertisement",
289 ) 280 )
290 .fail(&format!("Failed to create repo fixture: {}", e)) 281 .fail(format!("Failed to create repo fixture: {}", e))
291 } 282 }
292 }; 283 };
293 284
@@ -320,7 +311,7 @@ impl GitCloneTests {
320 "GRASP-01", 311 "GRASP-01",
321 "MUST include allow-reachable-sha1-in-want and allow-tip-sha1-in-want in advertisement", 312 "MUST include allow-reachable-sha1-in-want and allow-tip-sha1-in-want in advertisement",
322 ) 313 )
323 .fail(&format!("Failed to convert pubkey to npub: {}", e)) 314 .fail(format!("Failed to convert pubkey to npub: {}", e))
324 } 315 }
325 }; 316 };
326 317
@@ -340,7 +331,7 @@ impl GitCloneTests {
340 "GRASP-01", 331 "GRASP-01",
341 "MUST include allow-reachable-sha1-in-want and allow-tip-sha1-in-want in advertisement", 332 "MUST include allow-reachable-sha1-in-want and allow-tip-sha1-in-want in advertisement",
342 ) 333 )
343 .fail(&format!("HTTP request failed: {}", e)) 334 .fail(format!("HTTP request failed: {}", e))
344 } 335 }
345 }; 336 };
346 337
@@ -350,7 +341,7 @@ impl GitCloneTests {
350 "GRASP-01", 341 "GRASP-01",
351 "MUST include allow-reachable-sha1-in-want and allow-tip-sha1-in-want in advertisement", 342 "MUST include allow-reachable-sha1-in-want and allow-tip-sha1-in-want in advertisement",
352 ) 343 )
353 .fail(&format!( 344 .fail(format!(
354 "info/refs request failed with status: {}", 345 "info/refs request failed with status: {}",
355 response.status() 346 response.status()
356 )); 347 ));
@@ -365,7 +356,7 @@ impl GitCloneTests {
365 "GRASP-01", 356 "GRASP-01",
366 "MUST include allow-reachable-sha1-in-want and allow-tip-sha1-in-want in advertisement", 357 "MUST include allow-reachable-sha1-in-want and allow-tip-sha1-in-want in advertisement",
367 ) 358 )
368 .fail(&format!("Failed to read response body: {}", e)) 359 .fail(format!("Failed to read response body: {}", e))
369 } 360 }
370 }; 361 };
371 362
@@ -399,12 +390,3 @@ impl GitCloneTests {
399 .pass() 390 .pass()
400 } 391 }
401} 392}
402
403#[cfg(test)]
404mod tests {
405 #[test]
406 fn test_module_exists() {
407 // Simple compilation test
408 assert!(true);
409 }
410} \ No newline at end of file