import sys import unittest from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parents[1])) from core.origins import append_port, csv_values, effective_origins class OriginTests(unittest.TestCase): def test_frontend_port(self): self.assertEqual(effective_origins("http://localhost, https://example.com", 1028), ["http://localhost:1028", "https://example.com:1028"]) def test_backend_port(self): self.assertEqual(effective_origins("http://localhost", 1029), ["http://localhost:1029"]) def test_does_not_duplicate_existing_port(self): self.assertEqual(append_port("http://localhost:5000", 1028), "http://localhost:5000") def test_multiple_hosts_and_duplicates(self): self.assertEqual(csv_values("localhost, 127.0.0.1, localhost"), ["localhost", "127.0.0.1"]) def test_rejects_paths(self): with self.assertRaises(ValueError): append_port("http://localhost/path", 1028) def test_ipv6(self): self.assertEqual(append_port("http://[::1]", 1029), "http://[::1]:1029") if __name__ == "__main__": unittest.main()