forked from microsoft/agent-governance-toolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_email_tool.py
More file actions
96 lines (74 loc) · 2.61 KB
/
Copy pathtest_email_tool.py
File metadata and controls
96 lines (74 loc) · 2.61 KB
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
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
"""Tests for the ACS email-tool example."""
from __future__ import annotations
from pathlib import Path
import pytest
from email_policy import EmailPolicy
ROOT = Path(__file__).parent
def _invocation(args: dict[str, str]) -> dict[str, object]:
return {
"input": {
"intervention_point": "pre_tool_call",
"policy_target": {"value": args},
}
}
def test_policy_allows_internal_email() -> None:
verdict = EmailPolicy().evaluate(
_invocation({"to": "customer@example.com", "body": "Status update"})
)
assert verdict == {"decision": "allow"}
def test_policy_transforms_tracking_token() -> None:
verdict = EmailPolicy().evaluate(
_invocation(
{
"to": "customer@example.com",
"body": "Tracking token: TRACK-123",
}
)
)
assert verdict["decision"] == "transform"
assert verdict["transform"]["value"] == "Tracking token: [REDACTED]"
def test_policy_denies_external_recipient() -> None:
verdict = EmailPolicy().evaluate(
_invocation({"to": "partner@example.net", "body": "Status update"})
)
assert verdict["decision"] == "deny"
assert verdict["reason"] == "external_recipient_blocked"
def test_policy_denies_case_insensitive_external_domain() -> None:
verdict = EmailPolicy().evaluate(
_invocation({"to": "partner@EXAMPLE.NET", "body": "Status update"})
)
assert verdict["decision"] == "deny"
assert verdict["reason"] == "external_recipient_blocked"
def test_native_runtime_applies_transform_and_deny() -> None:
pytest.importorskip("agent_control_specification")
from agent_control_specification import AgentControl, HostSession
from run import enforce_email
control = AgentControl.from_path(
str(ROOT / "manifest.yaml"),
policy_dispatcher=EmailPolicy(),
)
session = HostSession(
control,
agent_id="test-agent",
session_id="test-session",
)
transformed, output = enforce_email(
session,
{
"to": "customer@example.com",
"body": "Tracking token: TRACK-123",
},
call_id="transform-1",
)
assert transformed.verdict.decision.value == "transform"
assert output is not None
assert output["body"] == "Tracking token: [REDACTED]"
denied, output = enforce_email(
session,
{"to": "partner@example.net", "body": "Status update"},
call_id="deny-1",
)
assert denied.verdict.decision.value == "deny"
assert output is None