| 1 | #!/usr/bin/env python3 |
| 2 | from pathlib import Path |
| 3 | import tempfile |
| 4 | import unittest |
| 5 | from unittest.mock import patch |
| 6 | |
| 7 | import snowglobe |
| 8 | |
| 9 | |
| 10 | class BuildBoundary(unittest.TestCase): |
| 11 | def test_shared_context_stays_inside_the_service_tree(self): |
| 12 | with tempfile.TemporaryDirectory() as temporary: |
| 13 | root = Path(temporary).resolve() |
| 14 | consumer = root / "service/consumer" |
| 15 | shared = root / "service/shared" |
| 16 | consumer.mkdir(parents=True) |
| 17 | (consumer / "service.pkl").touch() |
| 18 | shared.mkdir() |
| 19 | (shared / "Dockerfile").touch() |
| 20 | (root / "Dockerfile").touch() |
| 21 | (consumer / "escape").symlink_to(root, target_is_directory=True) |
| 22 | with patch.object(snowglobe, "REPO", root), patch.object(snowglobe, "SERVICES", root / "service"): |
| 23 | self.assertEqual(snowglobe.build_context("consumer", "../shared"), shared) |
| 24 | for relative in ("../..", "escape", "."): |
| 25 | with self.subTest(relative=relative), self.assertRaises(ValueError): |
| 26 | snowglobe.build_context("consumer", relative) |
| 27 | with self.assertRaises(ValueError): |
| 28 | snowglobe.config_path("consumer", "../shared/Dockerfile") |
| 29 | |
| 30 | |
| 31 | if __name__ == "__main__": |
| 32 | unittest.main() |