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

Function TestRecipientGate

internal/agent/screening_test.go:27–57  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

25}
26
27func TestRecipientGate(t *testing.T) {
28 cases := []struct {
29 name string
30 policy string
31 allowlist []string
32 domain string
33 req outbound.SendRequest
34 wantFlag bool
35 wantAddr string
36 }{
37 {"open never flags", identity.OutboundPolicyOpen, nil, "bot.example.com",
38 outbound.SendRequest{To: []string{"stranger@evil.com"}}, false, ""},
39 {"allowlist permits listed", identity.OutboundPolicyAllowlist, []string{"ok@friend.com"}, "bot.example.com",
40 outbound.SendRequest{To: []string{"ok@friend.com"}}, false, ""},
41 {"allowlist flags unlisted", identity.OutboundPolicyAllowlist, []string{"ok@friend.com"}, "bot.example.com",
42 outbound.SendRequest{To: []string{"ok@friend.com"}, CC: []string{"who@stranger.com"}}, true, "who@stranger.com"},
43 {"domain permits same domain", identity.OutboundPolicyDomain, nil, "bot.example.com",
44 outbound.SendRequest{To: []string{"alice@bot.example.com"}}, false, ""},
45 {"domain flags foreign", identity.OutboundPolicyDomain, nil, "bot.example.com",
46 outbound.SendRequest{To: []string{"alice@bot.example.com"}, BCC: []string{"x@elsewhere.com"}}, true, "x@elsewhere.com"},
47 }
48 for _, tc := range cases {
49 t.Run(tc.name, func(t *testing.T) {
50 ag := &identity.AgentIdentity{OutboundPolicy: tc.policy, OutboundAllowlist: tc.allowlist, Domain: tc.domain}
51 flagged, addr := recipientGate(ag, tc.req)
52 if flagged != tc.wantFlag || addr != tc.wantAddr {
53 t.Errorf("recipientGate = (%v, %q), want (%v, %q)", flagged, addr, tc.wantFlag, tc.wantAddr)
54 }
55 })
56 }
57}
58
59// TestScreenOutbound_GateAction: a flagged recipient escalates to the agent's
60// outbound_policy_action; open/allow produces ActionAllow.

Callers

nothing calls this directly

Calls 2

recipientGateFunction · 0.85
RunMethod · 0.80

Tested by

no test coverage detected