Skip to content

Commit

Permalink
Merge pull request #447 from beav/new-sasl-err-string
Browse files Browse the repository at this point in the history
Add additional string to check for when connecting to qpid
  • Loading branch information
bmbouter committed Feb 3, 2015
2 parents 227f17f + 3802838 commit d9bbe3c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
28 changes: 28 additions & 0 deletions kombu/tests/transport/test_qpid.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,34 @@ def test_mutates_ConnError_by_code(self, mock_qpid, mock_exc_info):
else:
self.fail('ConnectionError type was not mutated correctly')

@patch(QPID_MODULE + '.ConnectionError', new=(QpidException, ))
@patch(QPID_MODULE + '.sys.exc_info')
@patch(QPID_MODULE + '.qpid')
def test_connection__init__mutates_ConnError_by_message2(self, mock_qpid,
mock_exc_info):
"""
Test for PLAIN connection via python-saslwrapper, sans cyrus-sasl-plain
This test is specific for what is returned when we attempt to connect
with PLAIN mech and python-saslwrapper is installed, but
cyrus-sasl-plain is not installed.
"""
my_conn_error = QpidException()
my_conn_error.text = 'Error in sasl_client_start (-4) SASL(-4): no '\
'mechanism available'
mock_qpid.messaging.Connection.establish.side_effect = my_conn_error
mock_exc_info.return_value = ('a', 'b', None)
try:
self.conn = Connection(**self.connection_options)
except AuthenticationFailure as error:
exc_info = sys.exc_info()
self.assertTrue(not isinstance(error, QpidException))
self.assertTrue(exc_info[1] is 'b')
self.assertTrue(exc_info[2] is None)
else:
self.fail('ConnectionError type was not mutated correctly')


@patch(QPID_MODULE + '.ConnectionError', new=(QpidException, ))
@patch(QPID_MODULE + '.sys.exc_info')
@patch(QPID_MODULE + '.qpid')
Expand Down
8 changes: 7 additions & 1 deletion kombu/transport/qpid.py
Original file line number Diff line number Diff line change
Expand Up @@ -1285,14 +1285,20 @@ def __init__(self, **connection_options):
)
break
except ConnectionError as conn_exc:
# if we get one of these errors, do not raise an exception.
# Raising will cause the connection to be retried. Instead,
# just continue on to the next mech.
coded_as_auth_failure = getattr(conn_exc, 'code', None) == 320
contains_auth_fail_text = \
'Authentication failed' in conn_exc.text
contains_mech_fail_text = \
'sasl negotiation failed: no mechanism agreed' \
in conn_exc.text
contains_mech_unavail_text = 'no mechanism available' \
in conn_exc.text
if coded_as_auth_failure or \
contains_auth_fail_text or contains_mech_fail_text:
contains_auth_fail_text or contains_mech_fail_text or \
contains_mech_unavail_text:
logger.debug(
'Unable to connect to qpid with SASL mechanism %s',
sasl_mech,
Expand Down

0 comments on commit d9bbe3c

Please sign in to comment.