Spaces:
Sleeping
Sleeping
| """ | |
| Verification Script for Phase 1A (C-FED-NODE-001) | |
| Perform a self-handshake and envelope injection test. | |
| """ | |
| import sys | |
| import json | |
| from fastapi.testclient import TestClient | |
| # Import the configured federation node app | |
| from app import app, NODE_SEAL_STR | |
| client = TestClient(app) | |
| def run_verification(): | |
| print("="*60) | |
| print("π PANTHEON FEDERATION NODE β BEHAVIOR VERIFICATION") | |
| print("="*60) | |
| # 1. Verify Identity | |
| print("\n[TEST 1] GET /identity") | |
| res = client.get("/identity") | |
| assert res.status_code == 200 | |
| iden = res.json() | |
| print(f" Seal: {iden['identity']['glyph_seal']}") | |
| print(f" Alias: {iden['identity']['alias']}") | |
| print(" β Identity endpoint returned valid NodeRecord") | |
| # 2. Verify Capabilities | |
| print("\n[TEST 2] GET /capabilities") | |
| res = client.get("/capabilities") | |
| assert res.status_code == 200 | |
| caps = res.json() | |
| print(f" Conformance: {caps['conformance']['level']} (Contract: {caps['conformance']['contract']})") | |
| print(" β Capabilities endpoint returned valid structure") | |
| # 3. Malformed Sender Seal (The Malenia Rule) | |
| print("\n[TEST 3] POST /envelope (Malformed Sender Seal)") | |
| mal_env = { | |
| "protocol_version": "1.0.0", | |
| "message_class": "THOUGHT", | |
| "sender": {"seal": "β¦ INVALID :: SYNTAX β§"}, | |
| "recipient": {"seal": NODE_SEAL_STR}, | |
| "payload": {"content_type": "text/plain", "body": "Hello"} | |
| } | |
| res = client.post("/envelope", json=mal_env) | |
| assert res.status_code == 400 | |
| err = res.json()["detail"] | |
| print(f" Refusal Reason: {err['reason']}") | |
| print(" β Malenia Rule enforced (structured refusal)") | |
| # 4. Unknown Sender -> Quarantine (Default Policy) | |
| print("\n[TEST 4] POST /envelope (Unknown Sender)") | |
| unk_env = { | |
| "protocol_version": "1.0.0", | |
| "message_class": "THOUGHT", | |
| "sender": {"seal": "β¦ NODE :: TEST-ORIGIN :: anchor123 :: ACTIVE β§"}, | |
| "recipient": {"seal": NODE_SEAL_STR}, | |
| "payload": {"content_type": "text/plain", "body": "Knock knock"} | |
| } | |
| res = client.post("/envelope", json=unk_env) | |
| assert res.status_code == 200 | |
| data = res.json() | |
| env_id = data["envelope_id"] | |
| print(f" Result: {data['status']}") | |
| print(" β Unknown sender quarantined correctly according to FEDERATION_DEFAULT_ACTION") | |
| # 5. Delivery Status Progression | |
| print("\n[TEST 5] GET /envelope/{id}/status") | |
| res = client.get(f"/envelope/{env_id}/status") | |
| assert res.status_code == 200 | |
| status = res.json() | |
| history = [h["status"] for h in status["status_history"]] | |
| print(f" History: {' -> '.join(history)}") | |
| print(" β Envelope states progressed properly") | |
| # 6. Trust Establishment (Handshake) | |
| print("\n[TEST 6] POST /handshake (Trust Promotion)") | |
| hs_req = { | |
| "caller_seal": "β¦ NODE :: FRIENDLY-ORIGIN :: frnd123 :: ACTIVE β§", | |
| "protocol": "C-FED-001" | |
| } | |
| res = client.post("/handshake", json=hs_req) | |
| assert res.status_code == 200 | |
| print(f" Handshake result: {res.json()['status']}") | |
| print(" β Sender promoted to TRUSTED") | |
| # 7. Trusted Sender -> Queued | |
| print("\n[TEST 7] POST /envelope (Trusted Sender)") | |
| trusted_env = { | |
| "protocol_version": "1.0.0", | |
| "message_class": "PROPOSAL", | |
| "sender": {"seal": "β¦ NODE :: FRIENDLY-ORIGIN :: frnd123 :: ACTIVE β§"}, | |
| "recipient": {"seal": NODE_SEAL_STR}, | |
| "payload": {"content_type": "text/plain", "body": "I am a friend now."} | |
| } | |
| res = client.post("/envelope", json=trusted_env) | |
| assert res.status_code == 200 | |
| print(f" Result: {res.json()['status']}") | |
| print(" β Envelope bypassed quarantine and was QUEUED directly") | |
| print("\n" + "="*60) | |
| print("π ALL PHASE 1A VERIFICATION CHECKS PASSED π") | |
| print("="*60) | |
| if __name__ == "__main__": | |
| run_verification() | |