Skip to content

Commit 965c812

Browse files
Merge pull request pandas-dev#39 from manahl/authenticate_should_propagate_other_pymongo_errors
MDP-574 Only catch OperationFailure exceptions during auth
2 parents 07b5f84 + adc7662 commit 965c812

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

CHANGES.md

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
* Bugfix: Improve performance of saving multi-index Pandas DataFrames
77
by 9x
8+
* Bugfix: authenticate should propagate non-OperationFailure exceptions
9+
(e.g. ConnectionFailure) as this might be indicative of socket failures
810

911
### 1.10 (2015-10-28)
1012

arctic/auth.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from collections import namedtuple
22
import logging
3+
from pymongo.errors import OperationFailure
34

45
logger = logging.getLogger(__name__)
56

@@ -10,11 +11,10 @@ def authenticate(db, user, password):
1011
1112
PyMongo 2.6 changed the auth API to raise on Auth failure.
1213
"""
13-
from pymongo.errors import PyMongoError
1414
try:
1515
logger.debug("Authenticating {} with {}".format(db, user))
1616
return db.authenticate(user, password)
17-
except PyMongoError, e:
17+
except OperationFailure as e:
1818
logger.debug("Auth Error %s" % e)
1919
return False
2020

tests/unit/test_auth.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from mock import create_autospec, sentinel
22
from pymongo.database import Database
3-
from pymongo.errors import PyMongoError
3+
from pymongo.errors import PyMongoError, OperationFailure
4+
import pytest
45

56
from arctic import auth
67

@@ -13,5 +14,13 @@ def test_authenticate():
1314

1415
def test_authenticate_fails():
1516
db = create_autospec(Database)
16-
db.authenticate.side_effect = PyMongoError("error")
17+
error = "command SON([('saslStart', 1), ('mechanism', 'SCRAM-SHA-1'), ('payload', Binary('n,,n=foo,r=OTI3MzA3MTEzMTIx', 0)), ('autoAuthorize', 1)]) on namespace admin.$cmd failed: Authentication failed."
18+
db.authenticate.side_effect = OperationFailure(error)
1719
assert auth.authenticate(db, sentinel.user, sentinel.password) is False
20+
21+
22+
def test_authenticate_fails_exception():
23+
db = create_autospec(Database)
24+
db.authenticate.side_effect = PyMongoError("error")
25+
with pytest.raises(PyMongoError):
26+
assert auth.authenticate(db, sentinel.user, sentinel.password) is False

0 commit comments

Comments
 (0)