|
1 | 1 | """Unit tests for SourceOS local-agent runtime CLI scaffold.""" |
2 | 2 |
|
| 3 | +import json |
3 | 4 | import pathlib |
4 | 5 | import sys |
5 | 6 | import tempfile |
@@ -30,9 +31,25 @@ def test_mutating_command_is_plan_only_without_execute_policy_ok(self): |
30 | 31 | rc = local_agent.main(["quarantine", "node-commander"]) |
31 | 32 | self.assertEqual(rc, 0) |
32 | 33 |
|
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()) |
36 | 53 |
|
37 | 54 |
|
38 | 55 | class TestLocalAgentChecks(unittest.TestCase): |
@@ -63,6 +80,14 @@ def test_guarded_mutation_requires_both_execute_and_policy_ok(self): |
63 | 80 | self.assertTrue(args.execute) |
64 | 81 | self.assertFalse(args.policy_ok) |
65 | 82 |
|
| 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 | + |
66 | 91 |
|
67 | 92 | if __name__ == "__main__": |
68 | 93 | unittest.main() |
0 commit comments