TestProtectionPutGetRoundTrip: PUT a posture, then confirm GET returns the nested shape with the written values.
(t *testing.T)
| 58 | // TestProtectionPutGetRoundTrip: PUT a posture, then confirm GET returns the |
| 59 | // nested shape with the written values. |
| 60 | func 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). |
nothing calls this directly
no test coverage detected