Skip to content

Commit 7d96db4

Browse files
committed
Update local agent tests for guarded quarantine
1 parent b373985 commit 7d96db4

1 file changed

Lines changed: 28 additions & 3 deletions

File tree

tests/test_local_agent.py

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Unit tests for SourceOS local-agent runtime CLI scaffold."""
22

3+
import json
34
import pathlib
45
import sys
56
import tempfile
@@ -30,9 +31,25 @@ def test_mutating_command_is_plan_only_without_execute_policy_ok(self):
3031
rc = local_agent.main(["quarantine", "node-commander"])
3132
self.assertEqual(rc, 0)
3233

33-
def test_mutating_command_refuses_partial_scaffold_with_execute_policy_ok(self):
34-
rc = local_agent.main(["quarantine", "node-commander", "--execute", "--policy-ok"])
35-
self.assertEqual(rc, 1)
34+
def test_quarantine_executes_with_execute_and_policy_ok(self):
35+
with tempfile.TemporaryDirectory() as tmp:
36+
with mock.patch.object(local_agent, "collect_checks", return_value=[]), \
37+
mock.patch.object(local_agent, "_capture_launchd", return_value=[]), \
38+
mock.patch.object(local_agent, "_capture_podman", return_value=[]), \
39+
mock.patch.object(local_agent, "_capture_redacted_auth", return_value=[]):
40+
rc = local_agent.main([
41+
"quarantine",
42+
"node-commander",
43+
"--execute",
44+
"--policy-ok",
45+
"--output-dir",
46+
tmp,
47+
])
48+
self.assertEqual(rc, 0)
49+
dirs = list(pathlib.Path(tmp).glob("node-commander-*"))
50+
self.assertEqual(len(dirs), 1)
51+
self.assertTrue((dirs[0] / "manifest.json").exists())
52+
self.assertTrue((dirs[0] / "remediation.md").exists())
3653

3754

3855
class TestLocalAgentChecks(unittest.TestCase):
@@ -63,6 +80,14 @@ def test_guarded_mutation_requires_both_execute_and_policy_ok(self):
6380
self.assertTrue(args.execute)
6481
self.assertFalse(args.policy_ok)
6582

83+
def test_redacted_json_masks_auth(self):
84+
with tempfile.NamedTemporaryFile("w", suffix=".json") as f:
85+
json.dump({"auths": {"example.com": {"auth": "secret"}}}, f)
86+
f.flush()
87+
redacted = local_agent._redacted_json(pathlib.Path(f.name))
88+
self.assertIn("<redacted>", redacted)
89+
self.assertNotIn("secret", redacted)
90+
6691

6792
if __name__ == "__main__":
6893
unittest.main()

0 commit comments

Comments
 (0)