Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_ipv4_and_ipv6_diff_port(self):
cfile = create_config(("tls_listen=127.0.0.1:9000,:::9001",))
conf = Config(cfile).load()
assert conf.tls_listen == [
("127.0.0.1", 9000, socket.AF_INET, {}),
("::", 9001, socket.AF_INET6, {}),
]
"mode=bounce #default accept",
)
)
conf = Config(cfile).load()
assert conf.listen == [("10.0.0.1", 1025, socket.AF_INET, {})]
assert conf.tls_listen == []
cfile = create_config(
(
"#not=thisline",
"listen=10.0.0.1:1025",
"""this won't be added""",
"mode=bounce #default accept",
)
)
with pytest.raises(ConfigException):
Config(cfile).load()
def test_invalid_options():
cfile = create_config(("workers=2", "delay=10", "test=option"))
with pytest.raises(ConfigException):
Config(cfile).load()
def test_port_under_1024_no_perms(self):
cfile = create_config(("listen=127.0.0.1:1023",))
conf = Config(cfile).load()
with mock.patch(
"os.getuid", return_value=9000
) as mock_getuid, pytest.raises(ConfigException):
conf.test_port()
assert mock_getuid.called is True
assert mock_getuid.call_count == 1
def test_setgid_invalid_group(_):
cfile = create_config(("group=testgroup",))
with pytest.raises(SystemExit) as exc:
Config(cfile).load()
setgid()
assert exc.value.code == 64
def test_mode_and_delay_range_flag(self):
key = create_file("key.key")
cert = create_file("crt.crt")
settings = (
"tls_listen=:123 mode=bounce delay=15-20",
"tls_cert={}".format(cert),
"tls_key={}".format(key),
)
cfile = create_config(settings)
conf = Config(cfile).load()
assert conf.tls_listen == [
(
"",
123,
socket.AF_INET,
{"delay": ("15", "20"), "mode": "bounce"},
)
def test_port_over_1023_available(self):
cfile = create_config(("listen=127.0.0.1:1024",))
conf = Config(cfile).load()
with mock.patch(
"os.getuid", return_value=9000
) as mock_getuid, mock.patch("socket.socket.bind", return_value=True):
conf.test_port()
assert mock_getuid.called is True
assert mock_getuid.call_count == 1
def test_tls_listen_flags_special_ipv6(self):
cfile = create_config(("listen=:::465 mode=bounce",))
conf = Config(cfile).load()
assert conf.flags_from_listener("::1", 465) == {"mode": "bounce"}
def test_size(self):
cfile = create_config(("max_message_size=1024000",))
conf = Config(cfile).load()
assert conf.max_message_size == 1024000
assert conf.test_max_message_size() is None
def test_same_port_tls_port(self):
cfile = create_config(
("listen=127.0.0.1:25", "tls_listen=127.0.0.1:25")
)
conf = Config(cfile).load()
with pytest.raises(ConfigException):
conf.test_tls_port()