Configure arbitrary NPM endpoint lists
This commit is contained in:
+72
-1
@@ -1,6 +1,8 @@
|
||||
import os
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
from dns_sync.config import parse_endpoint_list
|
||||
from dns_sync.config import AppConfig, parse_endpoint_list
|
||||
|
||||
|
||||
class EndpointParsingTests(unittest.TestCase):
|
||||
@@ -45,5 +47,74 @@ class EndpointParsingTests(unittest.TestCase):
|
||||
)
|
||||
|
||||
|
||||
class AppConfigEndpointTests(unittest.TestCase):
|
||||
def test_legacy_proxy_ip_remains_supported(self):
|
||||
with patch.dict(
|
||||
os.environ,
|
||||
{"PROXY_IP": "192.168.1.101"},
|
||||
clear=True,
|
||||
):
|
||||
config = AppConfig.from_env()
|
||||
|
||||
self.assertEqual(
|
||||
tuple(endpoint.identity for endpoint in config.npm_endpoints),
|
||||
("npm://192.168.1.101:81",),
|
||||
)
|
||||
self.assertEqual(config.proxy_url, "http://192.168.1.101:81")
|
||||
self.assertEqual(config.target_ip, "192.168.1.101")
|
||||
|
||||
def test_endpoint_list_controls_api_and_proxy_ip_remains_target(self):
|
||||
with patch.dict(
|
||||
os.environ,
|
||||
{
|
||||
"NPM_ENDPOINTS": (
|
||||
"192.168.1.3,192.168.1.4:8081,192.168.1.5"
|
||||
),
|
||||
"PROXY_IP": "192.168.1.101",
|
||||
},
|
||||
clear=True,
|
||||
):
|
||||
config = AppConfig.from_env()
|
||||
|
||||
self.assertEqual(
|
||||
tuple(endpoint.identity for endpoint in config.npm_endpoints),
|
||||
(
|
||||
"npm://192.168.1.3:81",
|
||||
"npm://192.168.1.4:8081",
|
||||
"npm://192.168.1.5:81",
|
||||
),
|
||||
)
|
||||
self.assertEqual(config.proxy_url, "http://192.168.1.3:81")
|
||||
self.assertEqual(config.target_ip, "192.168.1.101")
|
||||
|
||||
def test_explicit_dns_target_supports_multiple_endpoints(self):
|
||||
with patch.dict(
|
||||
os.environ,
|
||||
{
|
||||
"NPM_ENDPOINTS": "192.168.1.3,192.168.1.4",
|
||||
"DNS_TARGET_IP": "192.168.1.101",
|
||||
},
|
||||
clear=True,
|
||||
):
|
||||
config = AppConfig.from_env()
|
||||
|
||||
self.assertEqual(config.proxy_url, "http://192.168.1.3:81")
|
||||
self.assertEqual(config.target_ip, "192.168.1.101")
|
||||
|
||||
def test_multiple_endpoints_require_target_without_proxy_ip(self):
|
||||
with patch.dict(
|
||||
os.environ,
|
||||
{
|
||||
"NPM_ENDPOINTS": "192.168.1.3,192.168.1.4",
|
||||
},
|
||||
clear=True,
|
||||
):
|
||||
with self.assertRaisesRegex(
|
||||
RuntimeError,
|
||||
"DNS_TARGET_IP is required",
|
||||
):
|
||||
AppConfig.from_env()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user