Skip to content

Commit

Permalink
Add clearer error message for bad user credentials.
Browse files Browse the repository at this point in the history
  • Loading branch information
mharista committed Nov 21, 2017
1 parent df060d7 commit 79e52f3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pyeapi/eapilib.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,10 @@ def send(self, data):
reason=response.reason))
_LOGGER.debug('Response content: {}'.format(response_content))

if response.status == 401:
raise ConnectionError(str(self), '%s. %s' % (response.reason,
response_content))

# Work around for Python 2.7/3.x compatibility
if not type(response_content) == str:
# For Python 3.x - decode bytes into string
Expand Down
14 changes: 14 additions & 0 deletions test/system/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,20 @@ def setUp(self):
# enable password on the dut and clear it on tearDown
dut.config("enable secret %s" % dut._enablepwd)

def test_unauthorized_user(self):
error_string = ('Unauthorized. Unable to authenticate user: Bad'
' username/password combination')
for dut in self.duts:
temp_node = pyeapi.connect(host=dut.settings['host'],
transport=dut.settings['transport'],
username='wrong', password='nope',
port=dut.settings['port'],
return_node=True)
try:
temp_node.run_commands('show version')
except pyeapi.eapilib.ConnectionError as err:
self.assertEqual(err.message, error_string)

def test_populate_version_properties(self):
for dut in self.duts:
result = dut.run_commands('show version')
Expand Down

0 comments on commit 79e52f3

Please sign in to comment.