Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

?authMechanism URI option support backported from 15.1.0 to 15.0.0 #138

Merged
merged 1 commit into from
Nov 13, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions docs/source/NEWS.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
Changelog
=========

Release 15.0.1 (2015-11-13)
---------------------------

This is a maintenance update to outdated 15.0.0 release

Features
^^^^^^^^

- Support for "?authMechanism=..." connection URI option


Release 15.0 (2015-05-04)
-------------------------

Expand Down
3 changes: 2 additions & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ diff-cover
wheel
setuptools
tox
check-manifest
check-manifest
mock
28 changes: 28 additions & 0 deletions tests/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import os
import shutil
import txmongo
from mock import patch
from bson.son import SON
from pymongo.errors import OperationFailure
from twisted.trial import unittest
Expand Down Expand Up @@ -224,3 +225,30 @@ def test_AuthOnTwoDBsSequential(self):
yield conn[self.db2][self.coll].find_one()
finally:
yield conn.disconnect()


class TestAuthMechanismURIParameter(unittest.TestCase):
mongo_host = "localhost"
mongo_port = 27017

@defer.inlineCallbacks
def _test_uri_auth(self, url_suffix, expected_mechanism):
# Connecting to default no-auth MongoDB, so it will be ok with any
# auth mechanism
with patch("txmongo.connection.ConnectionPool.authenticate") as authfunc:
uri = "mongodb://user:pass@{0}/db{2}".format(self.mongo_host,
self.mongo_port,
url_suffix)
conn = txmongo.connection.ConnectionPool(uri)
authfunc.assert_called_once_with("db", "user", "pass", expected_mechanism)
# Issuing some query to make sure connection is established because
# calling disconnect() may leave Trial's reactor unclean if it
# happen before name resolution is done
yield conn.db.coll.find_one()
yield conn.disconnect()

@defer.inlineCallbacks
def test_AuthMechanismURIParameter(self):
yield self._test_uri_auth("", "DEFAULT")
yield self._test_uri_auth("?authMechanism=MONGODB-CR", "MONGODB-CR")
yield self._test_uri_auth("?authMechanism=SCRAM-SHA-1", "SCRAM-SHA-1")
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ envlist =
[testenv]
deps =
coverage
mock
pyopenssl
pyparsing
pycrypto
Expand Down
3 changes: 2 additions & 1 deletion txmongo/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,8 @@ def __init__(self, uri="mongodb://127.0.0.1:27017", pool_size=1, ssl_context_fac

if self.__uri['database'] and self.__uri['username'] and self.__uri['password']:
self.authenticate(self.__uri['database'], self.__uri['username'],
self.__uri['password'])
self.__uri['password'],
self.__uri['options'].get('authmechanism', 'DEFAULT'))

host, port = self.__uri['nodelist'][0]

Expand Down