|
28 | 28 | UnixSocketUnthreadedController,
|
29 | 29 | _FakeServer,
|
30 | 30 | get_localhost,
|
| 31 | + is_unspecified_address, |
| 32 | + convert_unspecified_address_to_localhost, |
31 | 33 | )
|
32 | 34 | from aiosmtpd.handlers import Sink
|
33 | 35 | from aiosmtpd.smtp import SMTP as Server
|
@@ -293,6 +295,20 @@ def test_hostname_none(self):
|
293 | 295 | finally:
|
294 | 296 | cont.stop()
|
295 | 297 |
|
| 298 | + def test_hostname_unspecified_ipv4(self): |
| 299 | + cont = Controller(Sink(), hostname="0.0.0.0") |
| 300 | + try: |
| 301 | + cont.start() |
| 302 | + finally: |
| 303 | + cont.stop() |
| 304 | + |
| 305 | + def test_hostname_unspecified_ipv6(self): |
| 306 | + cont = Controller(Sink(), hostname="::") |
| 307 | + try: |
| 308 | + cont.start() |
| 309 | + finally: |
| 310 | + cont.stop() |
| 311 | + |
296 | 312 | def test_testconn_raises(self, mocker: MockFixture):
|
297 | 313 | mocker.patch("socket.socket.recv", side_effect=RuntimeError("MockError"))
|
298 | 314 | cont = Controller(Sink(), hostname="")
|
@@ -347,6 +363,18 @@ def test_getlocalhost_error(self, mocker):
|
347 | 363 | assert exc.value.errno == errno.EFAULT
|
348 | 364 | mock_makesock.assert_called_with(socket.AF_INET6, socket.SOCK_STREAM)
|
349 | 365 |
|
| 366 | + def test_is_unspecified_address(self): |
| 367 | + assert is_unspecified_address("127.0.0.1") is False |
| 368 | + assert is_unspecified_address("0.0.0.0") is True |
| 369 | + assert is_unspecified_address("::") is True |
| 370 | + assert is_unspecified_address("") is True |
| 371 | + |
| 372 | + def test_convert_unspecified_address_to_localhost(self): |
| 373 | + assert convert_unspecified_address_to_localhost("") == get_localhost() |
| 374 | + assert convert_unspecified_address_to_localhost("0.0.0.0") == "127.0.0.1" |
| 375 | + assert convert_unspecified_address_to_localhost("::") == "::1" |
| 376 | + assert convert_unspecified_address_to_localhost("0.0.0.1") == get_localhost() |
| 377 | + |
350 | 378 | def test_stop_default(self):
|
351 | 379 | controller = Controller(Sink())
|
352 | 380 | with pytest.raises(AssertionError, match="SMTP daemon not running"):
|
|
0 commit comments