diff --git a/pymongo/asynchronous/srv_resolver.py b/pymongo/asynchronous/srv_resolver.py index 8b811e5dc2..cedd0749e9 100644 --- a/pymongo/asynchronous/srv_resolver.py +++ b/pymongo/asynchronous/srv_resolver.py @@ -96,8 +96,6 @@ def __init__( except Exception: raise ConfigurationError(_INVALID_HOST_MSG % (fqdn,)) from None self.__slen = len(self.__plist) - if self.__slen < 2: - raise ConfigurationError(_INVALID_HOST_MSG % (fqdn,)) async def get_options(self) -> Optional[str]: from dns import resolver diff --git a/pymongo/synchronous/srv_resolver.py b/pymongo/synchronous/srv_resolver.py index 1b36efd1c9..afe5b23a93 100644 --- a/pymongo/synchronous/srv_resolver.py +++ b/pymongo/synchronous/srv_resolver.py @@ -96,8 +96,6 @@ def __init__( except Exception: raise ConfigurationError(_INVALID_HOST_MSG % (fqdn,)) from None self.__slen = len(self.__plist) - if self.__slen < 2: - raise ConfigurationError(_INVALID_HOST_MSG % (fqdn,)) def get_options(self) -> Optional[str]: from dns import resolver diff --git a/test/asynchronous/test_dns.py b/test/asynchronous/test_dns.py index d0e801e123..7316b4df9a 100644 --- a/test/asynchronous/test_dns.py +++ b/test/asynchronous/test_dns.py @@ -186,12 +186,6 @@ def create_tests(cls): class TestParsingErrors(AsyncPyMongoTestCase): async def test_invalid_host(self): - with self.assertRaisesRegex(ConfigurationError, "Invalid URI host: mongodb is not"): - client = self.simple_client("mongodb+srv://mongodb") - await client.aconnect() - with self.assertRaisesRegex(ConfigurationError, "Invalid URI host: mongodb.com is not"): - client = self.simple_client("mongodb+srv://mongodb.com") - await client.aconnect() with self.assertRaisesRegex(ConfigurationError, "Invalid URI host: an IP address is not"): client = self.simple_client("mongodb+srv://127.0.0.1") await client.aconnect() diff --git a/test/test_dns.py b/test/test_dns.py index 0290eb16d9..c478e481f6 100644 --- a/test/test_dns.py +++ b/test/test_dns.py @@ -184,12 +184,6 @@ def create_tests(cls): class TestParsingErrors(PyMongoTestCase): def test_invalid_host(self): - with self.assertRaisesRegex(ConfigurationError, "Invalid URI host: mongodb is not"): - client = self.simple_client("mongodb+srv://mongodb") - client._connect() - with self.assertRaisesRegex(ConfigurationError, "Invalid URI host: mongodb.com is not"): - client = self.simple_client("mongodb+srv://mongodb.com") - client._connect() with self.assertRaisesRegex(ConfigurationError, "Invalid URI host: an IP address is not"): client = self.simple_client("mongodb+srv://127.0.0.1") client._connect() diff --git a/test/test_uri_parser.py b/test/test_uri_parser.py index 0baefa0c3a..d96cad6b6a 100644 --- a/test/test_uri_parser.py +++ b/test/test_uri_parser.py @@ -24,6 +24,7 @@ sys.path[0:0] = [""] from test import unittest +from unittest.mock import patch from bson.binary import JAVA_LEGACY from pymongo import ReadPreference @@ -553,6 +554,11 @@ def test_port_with_whitespace(self): with self.assertRaisesRegex(ValueError, r"Port contains whitespace character: '\\n'"): parse_uri("mongodb://localhost:27\n017") + def test_allow_srv_hosts_with_fewer_than_three_dot_separated_parts(self): + with patch("dns.resolver.resolve"): + parse_uri("mongodb+srv://localhost/") + parse_uri("mongodb+srv://mongo.local/") + if __name__ == "__main__": unittest.main()