Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions tests/test_authentication.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
"""Tests for authentication."""
import pytest

from monzo import authentication
from monzo.exceptions import MonzoAuthenticationError
from tests.helpers import Handler, load_data


Expand Down Expand Up @@ -44,3 +47,38 @@ def test_logout(self, mocker):
path=expected_data['path'],
timeout=expected_data['timeout']
)

def test_authenticate_with_empty_token(self):
"""
Test authenticate raises an error when the authorization token is empty.
"""
auth = authentication.Authentication(
client_id='client_id',
client_secret='client_secret',
redirect_url='',
)

with pytest.raises(MonzoAuthenticationError):
auth.authenticate(authorization_token='', state_token='state_token')

def test_authenticate_state_token_mismatch(self, tmp_path, mocker):
"""
Test authenticate raises an error when the provided state token does not match.

Args:
tmp_path: Pytest fixture for temporary directory.
mocker: Pytest mocker fixture.
"""
mocker.patch('monzo.authentication.gettempdir', return_value=str(tmp_path))
auth = authentication.Authentication(
client_id='client_id',
client_secret='client_secret',
redirect_url='',
)
state_token = auth.state_token

with pytest.raises(MonzoAuthenticationError):
auth.authenticate(
authorization_token='auth_token',
state_token=f'{state_token}invalid',
)