diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2025-12-01 14:31:32 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2025-12-01 15:22:38 +0000 |
| commit | d2ac69816567f092fe0d4661723bc43778cb481b (patch) | |
| tree | e8b51b61a6a7b0ab1a214adebe4e237143b01f0b /grasp-audit/src/specs/grasp01/cors.rs | |
| parent | 7a78815e29b01c83f3d0ec195ba717a2eba8cd37 (diff) | |
fix cargo clippy and fmt warnings
Diffstat (limited to 'grasp-audit/src/specs/grasp01/cors.rs')
| -rw-r--r-- | grasp-audit/src/specs/grasp01/cors.rs | 51 |
1 files changed, 12 insertions, 39 deletions
diff --git a/grasp-audit/src/specs/grasp01/cors.rs b/grasp-audit/src/specs/grasp01/cors.rs index 08c5ab6..c877c04 100644 --- a/grasp-audit/src/specs/grasp01/cors.rs +++ b/grasp-audit/src/specs/grasp01/cors.rs | |||
| @@ -16,7 +16,6 @@ | |||
| 16 | 16 | ||
| 17 | use crate::{AuditClient, AuditResult, FixtureKind, TestContext, TestResult}; | 17 | use crate::{AuditClient, AuditResult, FixtureKind, TestContext, TestResult}; |
| 18 | use nostr_sdk::prelude::*; | 18 | use nostr_sdk::prelude::*; |
| 19 | use std::path::Path; | ||
| 20 | 19 | ||
| 21 | pub struct CorsTests; | 20 | pub struct CorsTests; |
| 22 | 21 | ||
| @@ -42,10 +41,7 @@ impl CorsTests { | |||
| 42 | /// | 41 | /// |
| 43 | /// Spec: Line 44 of ../grasp/01.md | 42 | /// Spec: Line 44 of ../grasp/01.md |
| 44 | /// Requirement: Set `Access-Control-Allow-Origin: *` on ALL responses | 43 | /// Requirement: Set `Access-Control-Allow-Origin: *` on ALL responses |
| 45 | pub async fn test_cors_allow_origin( | 44 | pub async fn test_cors_allow_origin(_client: &AuditClient, relay_domain: &str) -> TestResult { |
| 46 | _client: &AuditClient, | ||
| 47 | relay_domain: &str, | ||
| 48 | ) -> TestResult { | ||
| 49 | TestResult::new( | 45 | TestResult::new( |
| 50 | "cors_allow_origin", | 46 | "cors_allow_origin", |
| 51 | "GRASP-01:git-http:cors:44", | 47 | "GRASP-01:git-http:cors:44", |
| @@ -91,10 +87,7 @@ impl CorsTests { | |||
| 91 | /// | 87 | /// |
| 92 | /// Spec: Line 45 of ../grasp/01.md | 88 | /// Spec: Line 45 of ../grasp/01.md |
| 93 | /// Requirement: Set `Access-Control-Allow-Methods: GET, POST` on ALL responses | 89 | /// Requirement: Set `Access-Control-Allow-Methods: GET, POST` on ALL responses |
| 94 | pub async fn test_cors_allow_methods( | 90 | pub async fn test_cors_allow_methods(_client: &AuditClient, relay_domain: &str) -> TestResult { |
| 95 | _client: &AuditClient, | ||
| 96 | relay_domain: &str, | ||
| 97 | ) -> TestResult { | ||
| 98 | TestResult::new( | 91 | TestResult::new( |
| 99 | "cors_allow_methods", | 92 | "cors_allow_methods", |
| 100 | "GRASP-01:git-http:cors:45", | 93 | "GRASP-01:git-http:cors:45", |
| @@ -138,10 +131,7 @@ impl CorsTests { | |||
| 138 | /// | 131 | /// |
| 139 | /// Spec: Line 46 of ../grasp/01.md | 132 | /// Spec: Line 46 of ../grasp/01.md |
| 140 | /// Requirement: Set `Access-Control-Allow-Headers: Content-Type` on ALL responses | 133 | /// Requirement: Set `Access-Control-Allow-Headers: Content-Type` on ALL responses |
| 141 | pub async fn test_cors_allow_headers( | 134 | pub async fn test_cors_allow_headers(_client: &AuditClient, relay_domain: &str) -> TestResult { |
| 142 | _client: &AuditClient, | ||
| 143 | relay_domain: &str, | ||
| 144 | ) -> TestResult { | ||
| 145 | TestResult::new( | 135 | TestResult::new( |
| 146 | "cors_allow_headers", | 136 | "cors_allow_headers", |
| 147 | "GRASP-01:git-http:cors:46", | 137 | "GRASP-01:git-http:cors:46", |
| @@ -212,10 +202,8 @@ impl CorsTests { | |||
| 212 | check_options_response(&response, "root endpoint")?; | 202 | check_options_response(&response, "root endpoint")?; |
| 213 | 203 | ||
| 214 | // 2. Test OPTIONS on git-upload-pack endpoint | 204 | // 2. Test OPTIONS on git-upload-pack endpoint |
| 215 | let repo_url = format!( | 205 | let repo_url = |
| 216 | "http://{}/npub1test/test.git/git-upload-pack", | 206 | format!("http://{}/npub1test/test.git/git-upload-pack", relay_domain); |
| 217 | relay_domain | ||
| 218 | ); | ||
| 219 | let response = http_client | 207 | let response = http_client |
| 220 | .request(reqwest::Method::OPTIONS, &repo_url) | 208 | .request(reqwest::Method::OPTIONS, &repo_url) |
| 221 | .header("Origin", "https://example.com") | 209 | .header("Origin", "https://example.com") |
| @@ -227,10 +215,7 @@ impl CorsTests { | |||
| 227 | check_options_response(&response, "git-upload-pack endpoint")?; | 215 | check_options_response(&response, "git-upload-pack endpoint")?; |
| 228 | 216 | ||
| 229 | // 3. Test OPTIONS on info/refs endpoint | 217 | // 3. Test OPTIONS on info/refs endpoint |
| 230 | let refs_url = format!( | 218 | let refs_url = format!("http://{}/npub1test/test.git/info/refs", relay_domain); |
| 231 | "http://{}/npub1test/test.git/info/refs", | ||
| 232 | relay_domain | ||
| 233 | ); | ||
| 234 | let response = http_client | 219 | let response = http_client |
| 235 | .request(reqwest::Method::OPTIONS, &refs_url) | 220 | .request(reqwest::Method::OPTIONS, &refs_url) |
| 236 | .header("Origin", "https://example.com") | 221 | .header("Origin", "https://example.com") |
| @@ -255,10 +240,7 @@ impl CorsTests { | |||
| 255 | /// Integration test: CORS Allow-Origin header with repository creation | 240 | /// Integration test: CORS Allow-Origin header with repository creation |
| 256 | /// | 241 | /// |
| 257 | /// For integration tests that want to test against real repositories | 242 | /// For integration tests that want to test against real repositories |
| 258 | pub async fn test_cors_on_real_repo( | 243 | pub async fn test_cors_on_real_repo(client: &AuditClient, relay_domain: &str) -> TestResult { |
| 259 | client: &AuditClient, | ||
| 260 | relay_domain: &str, | ||
| 261 | ) -> TestResult { | ||
| 262 | let test_name = "test_cors_on_real_repo"; | 244 | let test_name = "test_cors_on_real_repo"; |
| 263 | let ctx = TestContext::new(client); | 245 | let ctx = TestContext::new(client); |
| 264 | 246 | ||
| @@ -271,7 +253,7 @@ impl CorsTests { | |||
| 271 | "GRASP-01", | 253 | "GRASP-01", |
| 272 | "CORS headers on real repository endpoint", | 254 | "CORS headers on real repository endpoint", |
| 273 | ) | 255 | ) |
| 274 | .fail(&format!("Failed to create repo fixture: {}", e)) | 256 | .fail(format!("Failed to create repo fixture: {}", e)) |
| 275 | } | 257 | } |
| 276 | }; | 258 | }; |
| 277 | 259 | ||
| @@ -304,7 +286,7 @@ impl CorsTests { | |||
| 304 | "GRASP-01", | 286 | "GRASP-01", |
| 305 | "CORS headers on real repository endpoint", | 287 | "CORS headers on real repository endpoint", |
| 306 | ) | 288 | ) |
| 307 | .fail(&format!("Failed to convert pubkey to npub: {}", e)) | 289 | .fail(format!("Failed to convert pubkey to npub: {}", e)) |
| 308 | } | 290 | } |
| 309 | }; | 291 | }; |
| 310 | 292 | ||
| @@ -323,7 +305,7 @@ impl CorsTests { | |||
| 323 | "GRASP-01", | 305 | "GRASP-01", |
| 324 | "CORS headers on real repository endpoint", | 306 | "CORS headers on real repository endpoint", |
| 325 | ) | 307 | ) |
| 326 | .fail(&format!("Failed to GET info/refs: {}", e)) | 308 | .fail(format!("Failed to GET info/refs: {}", e)) |
| 327 | } | 309 | } |
| 328 | }; | 310 | }; |
| 329 | 311 | ||
| @@ -492,15 +474,6 @@ mod tests { | |||
| 492 | results.print_report(); | 474 | results.print_report(); |
| 493 | 475 | ||
| 494 | // Assert all tests passed | 476 | // Assert all tests passed |
| 495 | assert!( | 477 | assert!(results.all_passed(), "Some GRASP-01 CORS tests failed"); |
| 496 | results.all_passed(), | ||
| 497 | "Some GRASP-01 CORS tests failed" | ||
| 498 | ); | ||
| 499 | } | 478 | } |
| 500 | 479 | } | |
| 501 | #[test] | ||
| 502 | fn test_module_exists() { | ||
| 503 | // Simple compilation test | ||
| 504 | assert!(true); | ||
| 505 | } | ||
| 506 | } \ No newline at end of file | ||