From b2a43ffbd965a2b561d7b4e4c582dfeadd099ed3 Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Fri, 28 Nov 2025 03:50:51 +0000 Subject: test: rationalise repository creation tests --- .../src/specs/grasp01/repository_creation.rs | 155 ++------------------- 1 file changed, 13 insertions(+), 142 deletions(-) (limited to 'grasp-audit/src/specs') diff --git a/grasp-audit/src/specs/grasp01/repository_creation.rs b/grasp-audit/src/specs/grasp01/repository_creation.rs index 588187b..63b3dee 100644 --- a/grasp-audit/src/specs/grasp01/repository_creation.rs +++ b/grasp-audit/src/specs/grasp01/repository_creation.rs @@ -5,9 +5,9 @@ //! //! ## Test Coverage //! -//! - Repository creation on valid announcement (verified via HTTP) -//! - Idempotent creation (no error if repo already exists) -//! - Repository accessibility via Smart HTTP service +//! - Repository creation on valid announcement +//! - Repository accessibility via Smart HTTP service (git-upload-pack) +//! - URL format: http://domain/npub/identifier.git //! //! ## Running Tests //! @@ -30,18 +30,18 @@ impl RepositoryCreationTests { let mut results = crate::AuditResult::new("GRASP-01 Repository Creation Tests"); results.add(Self::test_bare_repo_created_on_announcement(client, relay_domain).await); - results.add(Self::test_repo_creation_idempotent(client, relay_domain).await); - results.add(Self::test_repo_accessible_via_http(client, relay_domain).await); results } /// Test that a bare repository is created when a valid announcement is accepted + /// and is accessible via Smart HTTP service /// - /// This test: + /// This test verifies: /// 1. Sends a valid repository announcement via TestContext /// 2. Verifies the announcement was accepted - /// 3. Verifies the repository is accessible via Smart HTTP service + /// 3. Repository responds to git-upload-pack service discovery + /// 4. URL format follows http://domain/npub/identifier.git pattern pub async fn test_bare_repo_created_on_announcement( client: &AuditClient, relay_domain: &str, @@ -56,7 +56,7 @@ impl RepositoryCreationTests { return TestResult::new( test_name, "GRASP-01", - "Bare repository must be created when announcement is accepted", + "Bare repository must be created and accessible via Smart HTTP when announcement is accepted", ) .fail(&format!("Failed to create repo fixture: {}", e)) } @@ -77,7 +77,7 @@ impl RepositoryCreationTests { return TestResult::new( test_name, "GRASP-01", - "Bare repository must be created when announcement is accepted", + "Bare repository must be created and accessible via Smart HTTP when announcement is accepted", ) .fail("Repository announcement missing d tag") } @@ -89,18 +89,18 @@ impl RepositoryCreationTests { return TestResult::new( test_name, "GRASP-01", - "Bare repository must be created when announcement is accepted", + "Bare repository must be created and accessible via Smart HTTP when announcement is accepted", ) .fail(&format!("Failed to convert pubkey to npub: {}", e)) } }; - // Verify repository exists via HTTP (info/refs endpoint) + // Verify repository exists and is accessible via HTTP (info/refs endpoint) if let Err(e) = check_repo_accessible_via_http(relay_domain, &npub, &repo_id).await { return TestResult::new( test_name, "GRASP-01", - "Bare repository must be created when announcement is accepted", + "Bare repository must be created and accessible via Smart HTTP when announcement is accepted", ) .fail(&format!("Repository not accessible via HTTP: {}", e)); } @@ -108,136 +108,7 @@ impl RepositoryCreationTests { TestResult::new( test_name, "GRASP-01", - "Bare repository must be created when announcement is accepted", - ) - .pass() - } - - /// Test that repository creation is idempotent - /// - /// This test: - /// 1. Sends a repository announcement (creates repo) via TestContext - /// 2. Sends the same announcement again - /// 3. Verifies no error occurs and repo still exists - pub async fn test_repo_creation_idempotent( - client: &AuditClient, - relay_domain: &str, - ) -> TestResult { - let test_name = "test_repo_creation_idempotent"; - let ctx = TestContext::new(client); - - // Create and send repository announcement first time via TestContext - let repo = match ctx.get_fixture(FixtureKind::ValidRepo).await { - Ok(r) => r, - Err(e) => { - return TestResult::new( - test_name, - "GRASP-01", - "Repository creation must be idempotent", - ) - .fail(&format!("Failed to create repo fixture: {}", e)) - } - }; - - // Wait for repository creation - tokio::time::sleep(std::time::Duration::from_millis(200)).await; - - // Send the same announcement again (should be idempotent) - if let Err(e) = client.send_event(repo.clone()).await { - return TestResult::new( - test_name, - "GRASP-01", - "Repository creation must be idempotent", - ) - .fail(&format!("Second send failed (not idempotent): {}", e)); - } - - // Wait again - tokio::time::sleep(std::time::Duration::from_millis(200)).await; - - // Verify repository still exists and is accessible via HTTP - let repo_id = repo - .tags - .iter() - .find(|t| t.kind() == TagKind::d()) - .and_then(|t| t.content()) - .ok_or("Missing d tag") - .unwrap() - .to_string(); - - let npub = repo.pubkey.to_bech32().unwrap(); - - if let Err(e) = check_repo_accessible_via_http(relay_domain, &npub, &repo_id).await { - return TestResult::new( - test_name, - "GRASP-01", - "Repository creation must be idempotent", - ) - .fail(&format!("Repository not accessible after second send: {}", e)); - } - - TestResult::new( - test_name, - "GRASP-01", - "Repository creation must be idempotent", - ) - .pass() - } - - /// Test that the repository is accessible via Smart HTTP service - /// - /// This test verifies: - /// 1. Repository responds to git-upload-pack service discovery - /// 2. URL format follows http://domain/npub/identifier.git pattern - pub async fn test_repo_accessible_via_http( - client: &AuditClient, - relay_domain: &str, - ) -> TestResult { - let test_name = "test_repo_accessible_via_http"; - let ctx = TestContext::new(client); - - // Create and send repository announcement via TestContext - let repo = match ctx.get_fixture(FixtureKind::ValidRepo).await { - Ok(r) => r, - Err(e) => { - return TestResult::new( - test_name, - "GRASP-01", - "Repository must be accessible via Smart HTTP service", - ) - .fail(&format!("Failed to create repo fixture: {}", e)) - } - }; - - // Wait for repository creation - tokio::time::sleep(std::time::Duration::from_millis(200)).await; - - // Extract repo identifier and npub - let repo_id = repo - .tags - .iter() - .find(|t| t.kind() == TagKind::d()) - .and_then(|t| t.content()) - .ok_or("Missing d tag") - .unwrap() - .to_string(); - - let npub = repo.pubkey.to_bech32().unwrap(); - - // Verify repository is accessible via HTTP - if let Err(e) = check_repo_accessible_via_http(relay_domain, &npub, &repo_id).await { - return TestResult::new( - test_name, - "GRASP-01", - "Repository must be accessible via Smart HTTP service", - ) - .fail(&e); - } - - TestResult::new( - test_name, - "GRASP-01", - "Repository must be accessible via Smart HTTP service", + "Bare repository must be created and accessible via Smart HTTP when announcement is accepted", ) .pass() } -- cgit v1.2.3