upleb.uk

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

summaryrefslogtreecommitdiff
path: root/tests/cors.rs
blob: a4e92bc0fa7c32d531719e99331b697c5d4e8ca9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//! CORS Integration Tests
//!
//! Tests that verify CORS headers are correctly set on Git HTTP backend responses.
//!
//! # Test Strategy
//!
//! - Each test runs in complete isolation with its own fresh relay instance
//! - Uses macro to eliminate boilerplate while maintaining test isolation
//! - Calls individual test methods from grasp-audit for minimal duplication
//! - Automatic cleanup via TestRelay fixture (removes container and temp dirs)
//!
//! # Running Tests
//!
//! ```bash
//! # Run all CORS tests
//! cargo test --test cors
//!
//! # Run specific test
//! cargo test --test cors test_cors_allow_origin
//!
//! # With output
//! cargo test --test cors -- --nocapture
//! ```

mod common;

use common::TestRelay;
use grasp_audit::specs::grasp01::CorsTests;
use grasp_audit::*;

/// Macro to generate isolated CORS integration tests with relay domain
///
/// Each test runs with its own fresh relay instance to ensure complete isolation.
macro_rules! isolated_cors_test {
    ($test_name:ident) => {
        #[tokio::test]
        async fn $test_name() {
            let relay = TestRelay::start().await;
            let config = AuditConfig::isolated();
            let client = AuditClient::new(relay.url(), config)
                .await
                .expect("Failed to create audit client");

            let result = CorsTests::$test_name(&client, &relay.domain()).await;

            relay.stop().await;

            assert!(
                result.passed,
                "{} failed: {}",
                stringify!($test_name),
                result.error.as_deref().unwrap_or("unknown error")
            );
        }
    };
}

// Generate isolated tests for all CORS tests
isolated_cors_test!(test_cors_allow_origin);
isolated_cors_test!(test_cors_allow_methods);
isolated_cors_test!(test_cors_allow_headers);
isolated_cors_test!(test_cors_options_preflight);

isolated_cors_test!(test_cors_on_real_repo);