upleb.uk

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

summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2025-11-26 03:53:31 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2025-11-26 03:53:31 +0000
commit963b2971ec2f43b1c2f669a969c294fc1d291d3b (patch)
tree9495d5bd350ebf5123a9c72b9da3367b17e5534f /tests
parent75f3da90edb66b81dbb6ed9806155f6bd7925fe1 (diff)
add cors support
Diffstat (limited to 'tests')
-rw-r--r--tests/cors.rs95
1 files changed, 95 insertions, 0 deletions
diff --git a/tests/cors.rs b/tests/cors.rs
new file mode 100644
index 0000000..9cce817
--- /dev/null
+++ b/tests/cors.rs
@@ -0,0 +1,95 @@
1//! CORS Integration Tests
2//!
3//! Tests that verify CORS headers are correctly set on Git HTTP backend responses.
4//!
5//! # Test Strategy
6//!
7//! - Each test runs in complete isolation with its own fresh relay instance
8//! - Uses macro to eliminate boilerplate while maintaining test isolation
9//! - Calls individual test methods from grasp-audit for minimal duplication
10//! - Automatic cleanup via TestRelay fixture (removes container and temp dirs)
11//!
12//! # Running Tests
13//!
14//! ```bash
15//! # Run all CORS tests
16//! cargo test --test cors
17//!
18//! # Run specific test
19//! cargo test --test cors test_cors_allow_origin
20//!
21//! # With output
22//! cargo test --test cors -- --nocapture
23//! ```
24
25mod common;
26
27use common::TestRelay;
28use grasp_audit::specs::grasp01::CorsTests;
29use grasp_audit::*;
30
31/// Macro to generate isolated CORS integration tests with relay domain
32///
33/// Each test runs with its own fresh relay instance to ensure complete isolation.
34macro_rules! isolated_cors_test {
35 ($test_name:ident) => {
36 #[tokio::test]
37 async fn $test_name() {
38 let relay = TestRelay::start().await;
39 let config = AuditConfig::ci();
40 let client = AuditClient::new(relay.url(), config)
41 .await
42 .expect("Failed to create audit client");
43
44 let result = CorsTests::$test_name(&client, &relay.domain()).await;
45
46 relay.stop().await;
47
48 assert!(
49 result.passed,
50 "{} failed: {}",
51 stringify!($test_name),
52 result.error.as_deref().unwrap_or("unknown error")
53 );
54 }
55 };
56}
57
58/// Macro for CORS tests that need git_data_dir (the full integration test)
59macro_rules! isolated_cors_test_with_repo {
60 ($test_name:ident) => {
61 #[tokio::test]
62 async fn $test_name() {
63 let relay = TestRelay::start().await;
64 let config = AuditConfig::ci();
65 let client = AuditClient::new(relay.url(), config)
66 .await
67 .expect("Failed to create audit client");
68
69 let result = CorsTests::$test_name(
70 &client,
71 relay.git_data_dir(),
72 &relay.domain(),
73 )
74 .await;
75
76 relay.stop().await;
77
78 assert!(
79 result.passed,
80 "{} failed: {}",
81 stringify!($test_name),
82 result.error.as_deref().unwrap_or("unknown error")
83 );
84 }
85 };
86}
87
88// Generate isolated tests for all CORS tests
89isolated_cors_test!(test_cors_allow_origin);
90isolated_cors_test!(test_cors_allow_methods);
91isolated_cors_test!(test_cors_allow_headers);
92isolated_cors_test!(test_cors_options_preflight);
93
94// Integration test that creates a real repository and tests CORS on it
95isolated_cors_test_with_repo!(test_cors_on_real_repo); \ No newline at end of file