feat(profiles): implement slice 3 profile system, flock concurrency, and sanitize archiver
This commit is contained in:
1 parent
66ca179937
commit
646bd9d145
8 files changed
+536
-69
No files matched your search
@@ -121,5 +121,65 @@ class TestCliTracerBullet(unittest.TestCase):
|
||||
exit_code = main(["verify", snap_id, "--target-dir", self.backup_dir])
|
||||
self.assertEqual(exit_code, EXIT_CORRUPTED)
|
||||
|
||||
def test_snapshot_sanitize_redacts_secrets(self):
|
||||
# Create sensitive files in mock_etc
|
||||
shadow_path = os.path.join(self.mock_etc, "shadow")
|
||||
with open(shadow_path, "w") as f:
|
||||
f.write("root:$6$secretpasswordhash:19000:0:99999:7:::\n")
|
||||
ssh_key_path = os.path.join(self.mock_etc, "ssh_host_ed25519_key")
|
||||
with open(ssh_key_path, "w") as f:
|
||||
f.write("-----BEGIN OPENSSH PRIVATE KEY-----\nsecret\n-----END OPENSSH PRIVATE KEY-----\n")
|
||||
|
||||
stdout = io.StringIO()
|
||||
with patch("sys.stdout", stdout), patch.dict(os.environ, {"LINUX_BACKUPER_ALLOW_NON_ROOT": "1"}):
|
||||
exit_code = main([
|
||||
"snapshot",
|
||||
"--target-dir", self.backup_dir,
|
||||
"--paths", self.mock_etc,
|
||||
"--sanitize",
|
||||
"--json"
|
||||
])
|
||||
self.assertEqual(exit_code, EXIT_SUCCESS)
|
||||
|
||||
snap_data = json.loads(stdout.getvalue().strip())
|
||||
archive_path = snap_data["archive_path"]
|
||||
|
||||
with tarfile.open(archive_path, "r:gz") as tar:
|
||||
names = tar.getnames()
|
||||
# Sensitive files must NOT be in archive data/
|
||||
self.assertFalse(any("data" in n and "shadow" in n for n in names))
|
||||
self.assertFalse(any("data" in n and "ssh_host_ed25519_key" in n for n in names))
|
||||
# meta/sanitized.txt must exist and list them
|
||||
self.assertIn("meta/sanitized.txt", names)
|
||||
sanitized_log = tar.extractfile("meta/sanitized.txt").read().decode("utf-8")
|
||||
self.assertIn("shadow", sanitized_log)
|
||||
self.assertIn("ssh_host_ed25519_key", sanitized_log)
|
||||
|
||||
def test_snapshot_no_compression(self):
|
||||
stdout = io.StringIO()
|
||||
with patch("sys.stdout", stdout), patch.dict(os.environ, {"LINUX_BACKUPER_ALLOW_NON_ROOT": "1"}):
|
||||
exit_code = main([
|
||||
"snapshot",
|
||||
"--target-dir", self.backup_dir,
|
||||
"--paths", self.mock_etc,
|
||||
"--no-compression",
|
||||
"--json"
|
||||
])
|
||||
self.assertEqual(exit_code, EXIT_SUCCESS)
|
||||
|
||||
snap_data = json.loads(stdout.getvalue().strip())
|
||||
archive_path = snap_data["archive_path"]
|
||||
self.assertTrue(archive_path.endswith(".tar"))
|
||||
|
||||
# Verify it is openable as uncompressed tar
|
||||
with tarfile.open(archive_path, "r:") as tar:
|
||||
self.assertEqual(tar.getmembers()[0].name, "manifest.json")
|
||||
|
||||
# Verify command works on uncompressed tar
|
||||
snap_id = snap_data["snapshot_id"]
|
||||
with patch("sys.stdout", io.StringIO()):
|
||||
exit_code = main(["verify", snap_id, "--target-dir", self.backup_dir])
|
||||
self.assertEqual(exit_code, EXIT_SUCCESS)
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user