Commit 7893e0ef authored by Boxiang Sun's avatar Boxiang Sun

caucase.test: CAUCASE_NETLOC should not contain literal IP addresses

parent 67671d61
...@@ -388,6 +388,14 @@ class CaucaseTest(TestCase): ...@@ -388,6 +388,14 @@ class CaucaseTest(TestCase):
) )
self._caucase_url = 'http://' + netloc self._caucase_url = 'http://' + netloc
parsed_url = urllib_parse.urlparse(self._caucase_url) parsed_url = urllib_parse.urlparse(self._caucase_url)
try:
ipaddress.ip_address(parsed_url.hostname)
except ValueError:
pass # parsed_url.hostname is a hostname as expected
else: # pragma: no cover
raise AssertionError('CAUCASE_NETLOC should not contains literal IP')
self.assertFalse( self.assertFalse(
canConnect((parsed_url.hostname, parsed_url.port)), canConnect((parsed_url.hostname, parsed_url.port)),
'Something else is already listening on %r, define CAUCASE_NETLOC ' 'Something else is already listening on %r, define CAUCASE_NETLOC '
...@@ -3795,10 +3803,21 @@ class CaucaseShellTest(TestCase): ...@@ -3795,10 +3803,21 @@ class CaucaseShellTest(TestCase):
""" """
Run caucase.sh's embedded testsuite. Run caucase.sh's embedded testsuite.
""" """
self._run('--test', os.getenv( netloc = os.getenv(
'CAUCASE_NETLOC', 'CAUCASE_NETLOC',
'localhost:8000', 'localhost:8000',
)) )
caucase_url = 'http://' + netloc
parsed_url = urllib_parse.urlparse(caucase_url)
try:
ipaddress.ip_address(parsed_url.hostname)
except ValueError:
pass # parsed_url.hostname is a hostname as expected
else: # pragma: no cover
raise AssertionError('CAUCASE_NETLOC should not contains literal IP')
self._run('--test',netloc)
if __name__ == '__main__': # pragma: no cover if __name__ == '__main__': # pragma: no cover
unittest.main() unittest.main()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment