Permalink
Browse files

Fix exception handling when ssl isn't available.

  • Loading branch information...
1 parent d2a2866 commit 40f241d2b4b09b3fa2468cd3dd5396038f895aaf @behackett behackett committed Feb 22, 2013
Showing with 20 additions and 13 deletions.
  1. +6 −6 pymongo/mongo_client.py
  2. +6 −6 pymongo/mongo_replica_set_client.py
  3. +8 −1 test/test_ssl.py
View
@@ -259,12 +259,6 @@ def __init__(self, host=None, port=None, max_pool_size=10,
self.__ssl_cert_reqs = options.get('ssl_cert_reqs', None)
self.__ssl_ca_certs = options.get('ssl_ca_certs', None)
- if self.__use_ssl and not HAS_SSL:
- raise ConfigurationError("The ssl module is not available. If you "
- "are using a python version previous to "
- "2.6 you must install the ssl package "
- "from PyPI.")
-
ssl_kwarg_keys = [k for k in kwargs.keys() if k.startswith('ssl_')]
if self.__use_ssl == False and ssl_kwarg_keys:
raise ConfigurationError("ssl has not been enabled but the "
@@ -282,6 +276,12 @@ def __init__(self, host=None, port=None, max_pool_size=10,
# ssl options imply ssl = True
self.__use_ssl = True
+ if self.__use_ssl and not HAS_SSL:
+ raise ConfigurationError("The ssl module is not available. If you "
+ "are using a python version previous to "
+ "2.6 you must install the ssl package "
+ "from PyPI.")
+
self.__use_greenlets = options.get('use_greenlets', False)
self.__pool = pool_class(
None,
@@ -467,12 +467,6 @@ def __init__(self, hosts_or_uri=None, max_pool_size=10,
self.__ssl_cert_reqs = self.__opts.get('ssl_cert_reqs', None)
self.__ssl_ca_certs = self.__opts.get('ssl_ca_certs', None)
- if self.__use_ssl and not common.HAS_SSL:
- raise ConfigurationError("The ssl module is not available. If you "
- "are using a python version previous to "
- "2.6 you must install the ssl package "
- "from PyPI.")
-
ssl_kwarg_keys = [k for k in kwargs.keys() if k.startswith('ssl_')]
if self.__use_ssl == False and ssl_kwarg_keys:
raise ConfigurationError("ssl has not been enabled but the "
@@ -490,6 +484,12 @@ def __init__(self, hosts_or_uri=None, max_pool_size=10,
# ssl options imply ssl = True
self.__use_ssl = True
+ if self.__use_ssl and not common.HAS_SSL:
+ raise ConfigurationError("The ssl module is not available. If you "
+ "are using a python version previous to "
+ "2.6 you must install the ssl package "
+ "from PyPI.")
+
super(MongoReplicaSetClient, self).__init__(**self.__opts)
if self.slave_okay:
warnings.warn("slave_okay is deprecated. Please "
View
@@ -40,6 +40,7 @@
# mongod --dbpath /path/to/data/directory --sslOnNormalPorts \
# --sslPEMKeyFile /path/to/mongo/jstests/libs/server.pem \
# --sslCAFile /path/to/mongo/jstests/libs/ca.pem \
+# --sslCRLFile /path/to/mongo/jstests/libs/crl.pem \
# --sslWeakCertificateValidation
# Also, make sure you have 'server' as an alias for localhost in /etc/hosts
#
@@ -73,7 +74,7 @@ def is_server_resolvable():
pass
if SIMPLE_SSL:
- # Is MongoDB configured with server.pem and ca.pem from
+ # Is MongoDB configured with server.pem, ca.pem, and crl.pem from
# mongodb jstests/lib?
try:
MongoClient(host, port, connectTimeoutMS=100, ssl=True,
@@ -97,10 +98,16 @@ def test_no_ssl_module(self):
"without it."
)
+ # Explicit
self.assertRaises(ConfigurationError,
MongoClient, ssl=True)
self.assertRaises(ConfigurationError,
MongoReplicaSetClient, ssl=True)
+ # Implied
+ self.assertRaises(ConfigurationError,
+ MongoClient, ssl_certfile=CLIENT_PEM)
+ self.assertRaises(ConfigurationError,
+ MongoReplicaSetClient, ssl_certfile=CLIENT_PEM)
class TestSSL(unittest.TestCase):

0 comments on commit 40f241d

Please sign in to comment.