MCPcopy Create free account
hub / github.com/Mnexa-AI/e2a / TestProtectionPutGetRoundTrip

Function TestProtectionPutGetRoundTrip

internal/httpapi/protection_test.go:60–95  ·  view source on GitHub ↗

TestProtectionPutGetRoundTrip: PUT a posture, then confirm GET returns the nested shape with the written values.

(t *testing.T)

Source from the content-addressed store, hash-verified

58// TestProtectionPutGetRoundTrip: PUT a posture, then confirm GET returns the
59// nested shape with the written values.
60func TestProtectionPutGetRoundTrip(t *testing.T) {
61 srv, _ := protectionServer(t)
62 put := map[string]any{
63 "inbound": map[string]any{
64 "gate": map[string]any{"policy": "allowlist", "allowlist": []string{"partner@acme.com"}, "action": "review"},
65 "scan": map[string]any{"sensitivity": "high"},
66 },
67 "outbound": map[string]any{
68 "gate": map[string]any{"policy": "domain", "allowlist": []string{"acme.com"}, "action": "block"},
69 "scan": map[string]any{"sensitivity": "off"},
70 },
71 "holds": map[string]any{"ttl_seconds": 3600, "on_expiry": "approve"},
72 }
73 code, body := sendJSON(t, "PUT", srv.URL+"/v1/agents/support%40acme.com/protection", "good", put)
74 if code != 200 {
75 t.Fatalf("PUT status %d body %v", code, body)
76 }
77
78 code, got := sendJSON(t, "GET", srv.URL+"/v1/agents/support%40acme.com/protection", "good", nil)
79 if code != 200 {
80 t.Fatalf("GET status %d body %v", code, got)
81 }
82 inbound, _ := got["inbound"].(map[string]any)
83 gate, _ := inbound["gate"].(map[string]any)
84 scan, _ := inbound["scan"].(map[string]any)
85 if gate["policy"] != "allowlist" || gate["action"] != "review" {
86 t.Errorf("inbound gate not persisted: %v", gate)
87 }
88 if scan["sensitivity"] != "high" {
89 t.Errorf("inbound sensitivity = %v, want high", scan["sensitivity"])
90 }
91 holds, _ := got["holds"].(map[string]any)
92 if holds["on_expiry"] != "approve" {
93 t.Errorf("holds.on_expiry = %v, want approve", holds["on_expiry"])
94 }
95}
96
97// TestProtectionPutRequiresTopLevelKeys: a body missing a top-level section is a
98// 422 (D3 — no silent reset).

Callers

nothing calls this directly

Calls 2

protectionServerFunction · 0.85
sendJSONFunction · 0.85

Tested by

no test coverage detected