Skip to content

Commit c7785d2

Browse files
authored
test: cover authentication error scenarios (#85)
1 parent 7acc61c commit c7785d2

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

tests/test_authentication.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
"""Tests for authentication."""
2+
import pytest
3+
24
from monzo import authentication
5+
from monzo.exceptions import MonzoAuthenticationError
36
from tests.helpers import Handler, load_data
47

58

@@ -44,3 +47,38 @@ def test_logout(self, mocker):
4447
path=expected_data['path'],
4548
timeout=expected_data['timeout']
4649
)
50+
51+
def test_authenticate_with_empty_token(self):
52+
"""
53+
Test authenticate raises an error when the authorization token is empty.
54+
"""
55+
auth = authentication.Authentication(
56+
client_id='client_id',
57+
client_secret='client_secret',
58+
redirect_url='',
59+
)
60+
61+
with pytest.raises(MonzoAuthenticationError):
62+
auth.authenticate(authorization_token='', state_token='state_token')
63+
64+
def test_authenticate_state_token_mismatch(self, tmp_path, mocker):
65+
"""
66+
Test authenticate raises an error when the provided state token does not match.
67+
68+
Args:
69+
tmp_path: Pytest fixture for temporary directory.
70+
mocker: Pytest mocker fixture.
71+
"""
72+
mocker.patch('monzo.authentication.gettempdir', return_value=str(tmp_path))
73+
auth = authentication.Authentication(
74+
client_id='client_id',
75+
client_secret='client_secret',
76+
redirect_url='',
77+
)
78+
state_token = auth.state_token
79+
80+
with pytest.raises(MonzoAuthenticationError):
81+
auth.authenticate(
82+
authorization_token='auth_token',
83+
state_token=f'{state_token}invalid',
84+
)

0 commit comments

Comments
 (0)