Spaces:
Sleeping
Sleeping
File size: 3,908 Bytes
e61e751 | 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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | """
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()
|