Pass host through to Auth instance in SaslAuthProvider.new_authenticator

PYTHON-300
This commit is contained in:
Adam Holmberg
2015-05-12 08:08:17 -05:00
parent 5a235c46ff
commit 2464085bcc
2 changed files with 18 additions and 5 deletions

View File

@@ -139,8 +139,7 @@ class SaslAuthProvider(AuthProvider):
from cassandra.cluster import Cluster
from cassandra.auth import SaslAuthProvider
sasl_kwargs = {'host': 'localhost',
'service': 'dse',
sasl_kwargs = {'service': 'dse',
'mechanism': 'GSSAPI',
'qops': 'auth'.split(',')}
auth_provider = SaslAuthProvider(**sasl_kwargs)
@@ -152,10 +151,12 @@ class SaslAuthProvider(AuthProvider):
def __init__(self, **sasl_kwargs):
if SASLClient is None:
raise ImportError('The puresasl library has not been installed')
if 'host' in sasl_kwargs:
raise ValueError("kwargs should not contain 'host' since it is passed dynamically to new_authenticator")
self.sasl_kwargs = sasl_kwargs
def new_authenticator(self, host):
return SaslAuthenticator(**self.sasl_kwargs)
return SaslAuthenticator(host, **self.sasl_kwargs)
class SaslAuthenticator(Authenticator):
"""

View File

@@ -138,10 +138,22 @@ class SaslAuthenticatorTests(AuthenticationTests):
raise unittest.SkipTest('pure-sasl is not installed')
def get_authentication_provider(self, username, password):
sasl_kwargs = {'host': 'localhost',
'service': 'cassandra',
sasl_kwargs = {'service': 'cassandra',
'mechanism': 'PLAIN',
'qops': ['auth'],
'username': username,
'password': password}
return SaslAuthProvider(**sasl_kwargs)
# these could equally be unit tests
def test_host_passthrough(self):
sasl_kwargs = {'service': 'cassandra',
'mechanism': 'PLAIN'}
provider = SaslAuthProvider(**sasl_kwargs)
host = 'thehostname'
authenticator = provider.new_authenticator(host)
self.assertEqual(authenticator.sasl.host, host)
def test_host_rejected(self):
sasl_kwargs = {'host': 'something'}
self.assertRaises(ValueError, SaslAuthProvider, **sasl_kwargs)