test_socket_configuration.py (2027B)
1 # This file is in the public domain. 2 3 import re 4 import unittest 5 from pathlib import Path 6 7 8 REPOSITORY = Path(__file__).resolve().parents[1] 9 SETUP_SCRIPT = (REPOSITORY / "scripts/demo/setup-sandcastle.sh").read_text( 10 encoding="utf-8" 11 ) 12 13 14 class SocketConfigurationTests(unittest.TestCase): 15 def test_systemd_activated_services_use_public_sockets(self): 16 sockets = { 17 "taler-exchange-httpd.socket": "exchange.sock", 18 "taler-merchant-httpd.socket": "merchant-backend.sock", 19 "taler-auditor-httpd.socket": "auditor.sock", 20 "donau-httpd.socket": "donau.sock", 21 "paivana-httpd.socket": "paivana.sock", 22 } 23 24 for unit, socket in sockets.items(): 25 with self.subTest(unit=unit): 26 self.assertIn( 27 f"configure_public_socket {unit} /sockets/{socket}", 28 SETUP_SCRIPT, 29 ) 30 31 def test_demo_applications_use_unix_sockets(self): 32 sockets = { 33 "landing": "/run/taler-merchant-demos/landing.sock", 34 "blog": "/sockets/blog.sock", 35 "donations": "/sockets/donations.sock", 36 } 37 38 for application, socket in sockets.items(): 39 with self.subTest(application=application): 40 section = re.search( 41 rf"\[frontend-demo-{application}\]\n(.*?)(?=\n\[)", 42 SETUP_SCRIPT, 43 re.DOTALL, 44 ) 45 self.assertIsNotNone(section) 46 self.assertIn("HTTP_SERVE = unix", section.group(1)) 47 self.assertIn(f"HTTP_UNIXPATH = {socket}", section.group(1)) 48 49 def test_caddy_only_owns_bridge_or_composed_service_sockets(self): 50 sockets = re.findall( 51 r"bind unix//sockets/([^|]+)\|0666", 52 SETUP_SCRIPT, 53 ) 54 55 self.assertEqual( 56 ["bank.sock", "landing.sock", "challenger.sock", "drupal.sock"], 57 sockets, 58 ) 59 60 61 if __name__ == "__main__": 62 unittest.main()