Skip to content

Commit

Permalink
Make login backwards-compatible.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexey Kuzmenko committed Jul 16, 2021
1 parent 49e9fdf commit 828116c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
10 changes: 6 additions & 4 deletions archfx_cloud/api/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"""
import logging
import requests
from .exceptions import (
from archfx_cloud.api.exceptions import (
ImproperlyConfigured,
HttpClientError,
HttpCouldNotVerifyServerError,
Expand Down Expand Up @@ -258,9 +258,11 @@ def login(self, password, email):

if r.status_code == 200:
content = r.json()
if self.token_type in content:
if not self._validate_and_set_tokens(content[self.token_type]):
logger.warning("Incompatible %s token received from server", self.token_type)
if access_token := content.get('jwt'):
if not self._validate_and_set_tokens(access_token):
logger.warning(f"Incompatible JWT token received from server: {access_token}")
if refresh_token := content.get('jwt_refresh_token'):
self.refresh_token_data = refresh_token

self.username = content['username']
logger.debug('Welcome @{0}'.format(self.username))
Expand Down
14 changes: 5 additions & 9 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,14 @@ def test_token_refresh(self, m):
self.assertEqual(api.token, 'new-token')

@requests_mock.Mocker()
def test_new_jwt_login(self, m):
def test_login_new_jwt(self, m):
m.post(
'http://archfx.test/api/v1/auth/login/',
additional_matcher=lambda request: 'Authorization' not in request.headers,
json={
'username': 'user1',
'jwt': {
'access': 'access-token',
'refresh': 'refresh-token',
},
'jwt': 'access-token',
'jwt_refresh_token': 'refresh-token',
}
)
api = Api(domain='http://archfx.test')
Expand All @@ -110,10 +108,8 @@ def test_new_jwt_refresh(self, m):
additional_matcher=lambda request: 'Authorization' not in request.headers,
json={
'username': 'user1',
'jwt': {
'access': 'access-token',
'refresh': 'refresh-token',
},
'jwt': 'access-token',
'jwt_refresh_token': 'refresh-token',
}
)
api = Api(domain='http://archfx.test')
Expand Down

0 comments on commit 828116c

Please sign in to comment.