Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions pymongo/asynchronous/srv_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions pymongo/synchronous/srv_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 0 additions & 6 deletions test/asynchronous/test_dns.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 0 additions & 6 deletions test/test_dns.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 6 additions & 0 deletions test/test_uri_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Loading