Skip to content

Commit 67bdc2c

Browse files
committed
polish
1 parent 04d40a6 commit 67bdc2c

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

splitio/models/token.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import base64
44
import json
5-
5+
import pytest
66

77
class Token(object):
88
"""Token object class."""
@@ -62,15 +62,14 @@ def decode_token(raw_token):
6262
"""Decode token"""
6363
if not 'pushEnabled' in raw_token or not 'token' in raw_token:
6464
return None, None, None
65-
6665
token = raw_token['token']
6766
push_enabled = raw_token['pushEnabled']
6867
if not push_enabled or len(token.strip()) == 0:
69-
return None, None, None
68+
return False, None, None
7069

7170
token_parts = token.split('.')
7271
if len(token_parts) < 2:
73-
return None, None, None
72+
return False, None, None
7473

7574
to_decode = token_parts[1]
7675
decoded_payload = base64.b64decode(to_decode + '='*(-len(to_decode) % 4))
@@ -88,4 +87,4 @@ def from_raw(raw_token):
8887
:rtype: splitio.models.token.Token
8988
"""
9089
push_enabled, token, decoded_token = decode_token(raw_token)
91-
return None if push_enabled is None else Token(push_enabled, token, json.loads(decoded_token['x-ably-capability']), decoded_token['exp'], decoded_token['iat'])
90+
return Token(push_enabled, None, None, None, None) if not push_enabled else Token(push_enabled, token, json.loads(decoded_token['x-ably-capability']), decoded_token['exp'], decoded_token['iat'])

splitio/push/manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def _trigger_connection_flow(self):
143143
self._feedback_loop.put(Status.PUSH_RETRYABLE_ERROR)
144144
return
145145

146-
if token is None or not token.push_enabled:
146+
if not token.push_enabled:
147147
self._feedback_loop.put(Status.PUSH_NONRETRYABLE_ERROR)
148148
return
149149
self._telemetry_runtime_producer.record_token_refreshes()

tests/push/test_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def new_start(*args, **kwargs): # pylint: disable=unused-argument
9393
def test_empty_auth_respnse(self, mocker):
9494
"""Test the initial status is ok and reset() works as expected."""
9595
api_mock = mocker.Mock()
96-
api_mock.authenticate.return_value = None
96+
api_mock.authenticate.return_value = Token(False, None, None, None, None)
9797

9898
sse_mock = mocker.Mock(spec=SplitSSEClient)
9999
sse_constructor_mock = mocker.Mock()

0 commit comments

Comments
 (0)