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

Function protectionServer

internal/httpapi/protection_test.go:16–56  ·  view source on GitHub ↗

protectionServer builds a server whose UpdateAgentProtection mutates a captured agent so the handler's re-read reflects the write — the full PUT → store → re-read → view round-trip over the real chi+Huma stack.

(t *testing.T)

Source from the content-addressed store, hash-verified

14// agent so the handler's re-read reflects the write — the full PUT → store →
15// re-read → view round-trip over the real chi+Huma stack.
16func protectionServer(t *testing.T) (*httptest.Server, *identity.AgentIdentity) {
17 t.Helper()
18 ag := sampleAgent()
19 ag.InboundPolicy = "open"
20 ag.InboundPolicyAction = "flag"
21 ag.OutboundPolicy = "open"
22 ag.OutboundPolicyAction = "flag"
23 ag.InboundScanSensitivity = "off"
24 ag.OutboundScanSensitivity = "off"
25 deps := Deps{
26 Authenticator: func(r *http.Request) (*identity.User, error) {
27 if r.Header.Get("Authorization") == "Bearer good" {
28 return &identity.User{ID: "u_1", Email: "owner@acme.com"}, nil
29 }
30 return nil, errors.New("unauthorized")
31 },
32 GetAgent: func(ctx context.Context, address string) (*identity.AgentIdentity, error) {
33 if address == "support@acme.com" {
34 a := ag
35 return &a, nil
36 }
37 return nil, errors.New("not found")
38 },
39 UpdateAgentProtection: func(ctx context.Context, agentID, userID string, cfg identity.ProtectionConfig) error {
40 ag.InboundPolicy = cfg.InboundGatePolicy
41 ag.InboundAllowlist = cfg.InboundAllowlist
42 ag.InboundPolicyAction = cfg.InboundGateAction
43 ag.InboundScanSensitivity = cfg.InboundScanSensitivity
44 ag.OutboundPolicy = cfg.OutboundGatePolicy
45 ag.OutboundPolicyAction = cfg.OutboundGateAction
46 ag.OutboundScanSensitivity = cfg.OutboundScanSensitivity
47 ag.HITLTTLSeconds = cfg.HITLTTLSeconds
48 ag.HITLExpirationAction = cfg.HITLExpirationAction
49 return nil
50 },
51 Legacy: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusTeapot) }),
52 }
53 srv := httptest.NewServer(New(deps))
54 t.Cleanup(srv.Close)
55 return srv, &ag
56}
57
58// TestProtectionPutGetRoundTrip: PUT a posture, then confirm GET returns the
59// nested shape with the written values.

Calls 5

sampleAgentFunction · 0.85
CleanupMethod · 0.80
NewFunction · 0.70
GetMethod · 0.65
WriteHeaderMethod · 0.45

Tested by

no test coverage detected