diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2025-11-04 06:17:55 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2025-11-04 06:17:55 +0000 |
| commit | 001ca45e385c05b0eaa36d9879e051853aaff107 (patch) | |
| tree | 603fb85d2563db5b7c418e9fd143d479bd09676e /grasp-audit/README.md | |
| parent | d428baf30feec295870fadda2d335d1e7f89507b (diff) | |
created POC grasp-auditor
Diffstat (limited to 'grasp-audit/README.md')
| -rw-r--r-- | grasp-audit/README.md | 167 |
1 files changed, 167 insertions, 0 deletions
diff --git a/grasp-audit/README.md b/grasp-audit/README.md new file mode 100644 index 0000000..558e201 --- /dev/null +++ b/grasp-audit/README.md | |||
| @@ -0,0 +1,167 @@ | |||
| 1 | # GRASP Audit | ||
| 2 | |||
| 3 | A reusable audit and compliance testing tool for GRASP protocol implementations. | ||
| 4 | |||
| 5 | ## Features | ||
| 6 | |||
| 7 | - ✅ **Isolated Testing**: Tests run in parallel with unique audit IDs | ||
| 8 | - ✅ **Production Audit**: Test live services with minimal impact | ||
| 9 | - ✅ **Clean Audit Events**: Special tags for easy cleanup (no deletion trails) | ||
| 10 | - ✅ **Spec-Mirrored Tests**: Test structure matches GRASP protocol exactly | ||
| 11 | - ✅ **Reusable**: Can test any GRASP implementation (Rust, Go, Python, etc.) | ||
| 12 | |||
| 13 | ## Quick Start | ||
| 14 | |||
| 15 | ### As a Library | ||
| 16 | |||
| 17 | ```rust | ||
| 18 | use grasp_audit::*; | ||
| 19 | |||
| 20 | #[tokio::main] | ||
| 21 | async fn main() -> Result<()> { | ||
| 22 | // Create audit client for CI testing | ||
| 23 | let config = AuditConfig::ci(); | ||
| 24 | let client = AuditClient::new("ws://localhost:7000", config).await?; | ||
| 25 | |||
| 26 | // Run NIP-01 smoke tests | ||
| 27 | let results = specs::Nip01SmokeTests::run_all(&client).await; | ||
| 28 | results.print_report(); | ||
| 29 | |||
| 30 | if !results.all_passed() { | ||
| 31 | std::process::exit(1); | ||
| 32 | } | ||
| 33 | |||
| 34 | Ok(()) | ||
| 35 | } | ||
| 36 | ``` | ||
| 37 | |||
| 38 | ### As a CLI Tool | ||
| 39 | |||
| 40 | ```bash | ||
| 41 | # Install | ||
| 42 | cargo install --path . | ||
| 43 | |||
| 44 | # Run smoke tests against local relay | ||
| 45 | grasp-audit audit --relay ws://localhost:7000 --mode ci --spec nip01-smoke | ||
| 46 | |||
| 47 | # Audit production server (read-only) | ||
| 48 | grasp-audit audit --relay wss://relay.example.com --mode production --spec all | ||
| 49 | ``` | ||
| 50 | |||
| 51 | ## Test Specifications | ||
| 52 | |||
| 53 | ### NIP-01 Smoke Tests (6 tests) | ||
| 54 | |||
| 55 | Basic Nostr relay functionality: | ||
| 56 | |||
| 57 | 1. `websocket_connection` - Can connect to / | ||
| 58 | 2. `send_receive_event` - Can send EVENT, get OK | ||
| 59 | 3. `create_subscription` - Can subscribe with REQ | ||
| 60 | 4. `close_subscription` - Can close subscriptions | ||
| 61 | 5. `reject_invalid_signature` - Rejects bad signatures | ||
| 62 | 6. `reject_invalid_event_id` - Rejects wrong IDs | ||
| 63 | |||
| 64 | **Why only smoke tests?** rust-nostr already has 1000+ tests for NIP-01 compliance. We focus on GRASP-specific behavior. | ||
| 65 | |||
| 66 | ### GRASP-01 Tests (Coming Soon) | ||
| 67 | |||
| 68 | - Repository announcement acceptance | ||
| 69 | - State event handling | ||
| 70 | - Policy enforcement | ||
| 71 | - And more... | ||
| 72 | |||
| 73 | ## Audit Event Strategy | ||
| 74 | |||
| 75 | All audit events include special tags: | ||
| 76 | |||
| 77 | ```json | ||
| 78 | { | ||
| 79 | "tags": [ | ||
| 80 | ["grasp-audit", "true"], | ||
| 81 | ["audit-run-id", "ci-a1b2c3d4-e5f6-7890-abcd-ef1234567890"], | ||
| 82 | ["audit-cleanup", "2025-11-03T12:00:00Z"] | ||
| 83 | ] | ||
| 84 | } | ||
| 85 | ``` | ||
| 86 | |||
| 87 | This allows: | ||
| 88 | - **Isolation**: Each test run has unique ID | ||
| 89 | - **Cleanup**: Events marked for cleanup after timestamp | ||
| 90 | - **No deletion trails**: Direct database cleanup (no NIP-09 deletion events) | ||
| 91 | |||
| 92 | ## Modes | ||
| 93 | |||
| 94 | ### CI Mode (Default) | ||
| 95 | |||
| 96 | - Tests are isolated by unique run ID | ||
| 97 | - Tests only see their own events | ||
| 98 | - Full read/write access | ||
| 99 | - Cleanup after 1 hour | ||
| 100 | |||
| 101 | ```rust | ||
| 102 | let config = AuditConfig::ci(); | ||
| 103 | ``` | ||
| 104 | |||
| 105 | ### Production Mode | ||
| 106 | |||
| 107 | - Tests see all events (including real ones) | ||
| 108 | - Read-only by default (minimal impact) | ||
| 109 | - Cleanup after 5 minutes | ||
| 110 | |||
| 111 | ```rust | ||
| 112 | let config = AuditConfig::production(); | ||
| 113 | ``` | ||
| 114 | |||
| 115 | ## Examples | ||
| 116 | |||
| 117 | See `examples/` directory: | ||
| 118 | |||
| 119 | ```bash | ||
| 120 | # Simple audit example | ||
| 121 | cargo run --example simple_audit | ||
| 122 | ``` | ||
| 123 | |||
| 124 | ## Testing | ||
| 125 | |||
| 126 | ```bash | ||
| 127 | # Run unit tests | ||
| 128 | cargo test | ||
| 129 | |||
| 130 | # Run integration tests (requires running relay) | ||
| 131 | cargo test --ignored | ||
| 132 | ``` | ||
| 133 | |||
| 134 | ## Architecture | ||
| 135 | |||
| 136 | ``` | ||
| 137 | grasp-audit/ | ||
| 138 | ├── src/ | ||
| 139 | │ ├── lib.rs # Public API | ||
| 140 | │ ├── audit.rs # Audit config and event tagging | ||
| 141 | │ ├── client.rs # Audit client | ||
| 142 | │ ├── result.rs # Test result types | ||
| 143 | │ ├── isolation.rs # Test isolation utilities | ||
| 144 | │ └── specs/ | ||
| 145 | │ ├── mod.rs | ||
| 146 | │ └── nip01_smoke.rs # NIP-01 smoke tests | ||
| 147 | ├── examples/ | ||
| 148 | │ └── simple_audit.rs # Example usage | ||
| 149 | └── bin/ | ||
| 150 | └── grasp-audit.rs # CLI tool | ||
| 151 | ``` | ||
| 152 | |||
| 153 | ## Development Status | ||
| 154 | |||
| 155 | - ✅ Audit framework | ||
| 156 | - ✅ NIP-01 smoke tests (6 tests) | ||
| 157 | - 🚧 GRASP-01 relay tests (planned) | ||
| 158 | - 🚧 GRASP-01 git tests (planned) | ||
| 159 | - 🚧 Cleanup utilities (planned) | ||
| 160 | |||
| 161 | ## Contributing | ||
| 162 | |||
| 163 | This tool is designed to be reusable by any GRASP implementation. Contributions welcome! | ||
| 164 | |||
| 165 | ## License | ||
| 166 | |||
| 167 | MIT | ||