Skip to content

Commit

Permalink
Test another /tokens/discharge response case
Browse files Browse the repository at this point in the history
  • Loading branch information
cjwatson committed Sep 16, 2016
1 parent 4a69cb2 commit 569720f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
8 changes: 8 additions & 0 deletions snapcraft/tests/fake_servers.py
Expand Up @@ -218,6 +218,8 @@ def _handle_tokens_discharge_request(self):
self._send_tokens_discharge(data)
elif data['password'] == 'test requires 2fa':
self._send_twofactor_required_error()
elif data['password'] == 'test 401 invalid json':
self._send_401_invalid_json()
else:
self._send_invalid_credentials_error()

Expand All @@ -243,6 +245,12 @@ def _send_twofactor_required_error(self):
}
self.wfile.write(json.dumps(response).encode())

def _send_401_invalid_json(self):
self.send_response(401)
self.send_header('Content-Type', 'application/json')
self.end_headers()
self.wfile.write(b'invalid{json')

def _send_invalid_credentials_error(self):
self.send_response(401)
self.send_header('Content-Type', 'application/json')
Expand Down
6 changes: 6 additions & 0 deletions snapcraft/tests/store/test_store_client.py
Expand Up @@ -76,6 +76,12 @@ def test_failed_login_with_wrong_one_time_password(self):

self.assertTrue(config.Config().is_empty())

def test_failed_login_with_invalid_json(self):
with self.assertRaises(errors.StoreAuthenticationError):
self.client.login('dummy email', 'test 401 invalid json')

self.assertTrue(config.Config().is_empty())


class DownloadTestCase(tests.TestCase):

Expand Down

0 comments on commit 569720f

Please sign in to comment.