PYTHON-1761 Include fqdn or srv hosts in srv errors
This commit is contained in:
parent
7888ff08f3
commit
a23ce28942
@ -45,10 +45,10 @@ class _SrvResolver(object):
|
||||
try:
|
||||
self.__plist = self.__fqdn.split(".")[1:]
|
||||
except Exception:
|
||||
raise ConfigurationError("Invalid URI host")
|
||||
raise ConfigurationError("Invalid URI host: %s" % (fqdn,))
|
||||
self.__slen = len(self.__plist)
|
||||
if self.__slen < 2:
|
||||
raise ConfigurationError("Invalid URI host")
|
||||
raise ConfigurationError("Invalid URI host: %s" % (fqdn,))
|
||||
|
||||
def get_options(self):
|
||||
try:
|
||||
@ -88,9 +88,9 @@ class _SrvResolver(object):
|
||||
try:
|
||||
nlist = node[0].split(".")[1:][-self.__slen:]
|
||||
except Exception:
|
||||
raise ConfigurationError("Invalid SRV host")
|
||||
raise ConfigurationError("Invalid SRV host: %s" % (node[0],))
|
||||
if self.__plist != nlist:
|
||||
raise ConfigurationError("Invalid SRV host")
|
||||
raise ConfigurationError("Invalid SRV host: %s" % (node[0],))
|
||||
|
||||
return results, nodes
|
||||
|
||||
|
||||
@ -106,6 +106,18 @@ def create_tests():
|
||||
|
||||
create_tests()
|
||||
|
||||
class TestParsingErrors(unittest.TestCase):
|
||||
|
||||
def test_invalid_host(self):
|
||||
self.assertRaisesRegex(
|
||||
ConfigurationError,
|
||||
"Invalid URI host: mongodb",
|
||||
MongoClient, "mongodb+srv://mongodb")
|
||||
self.assertRaisesRegex(
|
||||
ConfigurationError,
|
||||
"Invalid URI host: mongodb.com",
|
||||
MongoClient, "mongodb+srv://mongodb.com")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user