def test_decode__token_is_broken(self): self.mocker.patch.object(jwt, 'decode').side_effect = jwt.DecodeError # -- expired with pytest.raises(EventFactory.AuthError) as e: AuthToken.decode('token') assert e.value.data == { '@event': 'AUTH_TOKEN_WAS_BROKEN', '@type': 'error', }
def test_decode__token_expired(self): self.mocker.patch.object( jwt, 'decode').side_effect = jwt.ExpiredSignature with pytest.raises(EventFactory.AuthError) as e: AuthToken.decode('token') assert e.value.data == { '@event': 'AUTH_TOKEN_EXPIRED', '@type': 'error', }
def test_decode__broken_payload(self): self.mocker.patch.object(jwt, 'decode').return_value = { 'no_id': 134, 'email': '*****@*****.**', } # -- expired with pytest.raises(EventFactory.AuthError) as e: AuthToken.decode('token') assert e.value.data == { '@event': 'AUTH_TOKEN_MISSING_FIELDS_DETECTED', '@type': 'error', }
def setUp(self): ef.clear() self.app = Client() self.account = ef.account(type=AccountType.ADMIN.value) self.ci = ef.catalogue_item(spec=[ { 'name': 'product', 'type': 'STRING', 'is_nullable': True, 'is_enum': True, 'size': None, 'distribution': None, }, { 'name': 'price', 'type': 'INTEGER', 'is_nullable': False, 'is_enum': False, 'size': None, 'distribution': None, }, ], executor_type='ATHENA') token = AuthToken.encode(self.account) self.headers = {'HTTP_AUTHORIZATION': f'Bearer {token}'}
def setUp(self): ef.clear() self.app = Client() self.account = ef.account(type=AccountType.ADMIN.value) token = AuthToken.encode(self.account) self.headers = {'HTTP_AUTHORIZATION': f'Bearer {token}'}
def test_encode(self): assert AuthToken.encode( Mock(type='BOSS', id=18, email='*****@*****.**') ) == ( 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6MTgsImVtYWlsIjoiam' 'Fja3lAZ21haWwuY29tIiwidHlwZSI6IkJPU1MiLCJleHAiOjE1NDE5MzEyNTJ9.' 'oP85pR2O---BKVGsu5r3fYDuUzfbIG0W8ijOsSI9aCU')
def test_decode__account_does_not_exist(self): self.mocker.patch.object(jwt, 'decode').return_value = { 'id': 134, 'email': '*****@*****.**', 'type': 'BOSS', } request = Mock(META={'HTTP_AUTHORIZATION': 'bearer token'}) # -- expired with pytest.raises(EventFactory.AuthError) as e: AuthToken.decode(request) assert e.value.data == { '@event': 'AUTH_TOKEN_MISSING_ACCOUNT', '@type': 'error', }
def test_decode(self): a = ef.account() self.mocker.patch.object( jwt, 'decode' ).return_value = { 'id': a.id, 'email': a.email, 'type': a.type, } assert AuthToken.decode('token') == a