Skip to content

Commit b406ef0

Browse files
committed
WIP - fix remaining issues
Signed-off-by: David Black <[email protected]>
1 parent bb349b4 commit b406ef0

File tree

8 files changed

+98
-98
lines changed

8 files changed

+98
-98
lines changed

atlassian_jwt_auth/contrib/tests/aiohttp/test_public_key_provider.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from unittest.mock import AsyncMock as CoroutineMock
1010
from unittest.mock import Mock
1111
except ImportError:
12-
from asynctest import CoroutineMock, TestCase, Mock
12+
from asynctest import CoroutineMock, TestCase, Mock # type: ignore[import-untyped, no-redef]
1313

1414
from atlassian_jwt_auth.contrib.aiohttp import HTTPSPublicKeyRetriever
1515
from atlassian_jwt_auth.key import PEM_FILE_TYPE
@@ -21,7 +21,7 @@
2121
class DummyHTTPSPublicKeyRetriever(HTTPSPublicKeyRetriever):
2222

2323
def set_headers(self, headers) -> None:
24-
self._session.get.return_value.headers.update(headers)
24+
self._session.get.return_value.headers.update(headers) # type: ignore[attr-defined]
2525

2626
def set_text(self, text: str | bytes) -> None:
2727
self._session.get.return_value.text.return_value = text # type: ignore[attr-defined]

atlassian_jwt_auth/contrib/tests/aiohttp/test_verifier.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from unittest.mock import AsyncMock as CoroutineMock
88
from unittest.mock import Mock
99
except ImportError:
10-
from asynctest import TestCase, CoroutineMock
10+
from asynctest import TestCase, CoroutineMock # type: ignore[import-untyped, no-redef]
1111

1212
from atlassian_jwt_auth.contrib.aiohttp import (HTTPSPublicKeyRetriever,
1313
JWTAuthVerifier)
@@ -32,13 +32,13 @@ def verify_jwt(self, *args: Any, **kwargs: Any):
3232
class JWTAuthVerifierTestMixin(test_verifier.BaseJWTAuthVerifierTest):
3333
loop = None
3434

35-
def _setup_mock_public_key_retriever(self, pub_key_pem: str) -> Mock:
35+
def _setup_mock_public_key_retriever(self, pub_key_pem: str) -> Mock: # type: ignore[override]
3636
m_public_key_ret = CoroutineMock(spec=HTTPSPublicKeyRetriever)
37-
m_public_key_ret.retrieve.return_value = pub_key_pem.decode()
37+
m_public_key_ret.retrieve.return_value = pub_key_pem.decode() # type: ignore[attr-defined]
3838
return m_public_key_ret
3939

4040
def _setup_jwt_auth_verifier(
41-
self, pub_key_pem: str, **kwargs: Any) -> SyncJWTAuthVerifier:
41+
self, pub_key_pem: str, **kwargs: Any) -> SyncJWTAuthVerifier: # type: ignore[override]
4242
m_public_key_ret = self._setup_mock_public_key_retriever(pub_key_pem)
4343
return SyncJWTAuthVerifier(m_public_key_ret, loop=self.loop, **kwargs)
4444

atlassian_jwt_auth/contrib/tests/test_requests.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class BaseRequestsTest(object):
1717
auth_cls: Type[BaseJWTAuth] = JWTAuth
1818

1919
def setUp(self) -> None:
20-
self._private_key_pem = self.get_new_private_key_in_pem_format()
20+
self._private_key_pem = self.get_new_private_key_in_pem_format() # type: ignore[attr-defined]
2121
self._public_key_pem = utils.get_public_key_pem_for_private_key_pem(
2222
self._private_key_pem)
2323

@@ -47,15 +47,15 @@ def test_JWTAuth_make_authenticated_request(self) -> None:
4747
'issuer',
4848
'issuer/key',
4949
self._private_key_pem.decode(),
50-
algorithm=self.algorithm)
50+
algorithm=self.algorithm) # type: ignore[attr-defined]
5151
auth = self.auth_cls(jwt_auth_signer, 'audience')
5252
self.assert_authorization_header_is_valid(auth)
5353

5454
def test_create_jwt_auth(self) -> None:
5555
"""Verify a valid Authorization header is added by JWTAuth"""
5656
auth = self.create_jwt_auth('issuer', 'issuer/key',
5757
self._private_key_pem.decode(), 'audience',
58-
algorithm=self.algorithm)
58+
algorithm=self.algorithm) # type: ignore[attr-defined]
5959
self.assert_authorization_header_is_valid(auth)
6060

6161
def test_create_jwt_auth_with_additional_claims(self) -> None:
@@ -66,77 +66,77 @@ def test_create_jwt_auth_with_additional_claims(self) -> None:
6666
'issuer',
6767
'issuer/key',
6868
self._private_key_pem.decode(),
69-
algorithm=self.algorithm)
69+
algorithm=self.algorithm) # type: ignore[attr-defined]
7070
auth = self.auth_cls(jwt_auth_signer, 'audience',
7171
additional_claims={'example': 'claim'})
7272
token = self.assert_authorization_header_is_valid(auth)
73-
self.assertEqual(token.get('example'), 'claim')
73+
self.assertEqual(token.get('example'), 'claim') # type: ignore[attr-defined]
7474

7575
def test_do_not_reuse_jwts(self) -> None:
7676
auth = self.create_jwt_auth('issuer', 'issuer/key',
7777
self._private_key_pem.decode(), 'audience',
78-
algorithm=self.algorithm)
78+
algorithm=self.algorithm) # type: ignore[attr-defined]
7979
auth_header = self._get_auth_header(auth)
80-
self.assertNotEqual(auth_header, self._get_auth_header(auth))
80+
self.assertNotEqual(auth_header, self._get_auth_header(auth)) # type: ignore[attr-defined]
8181

8282
def test_reuse_jwts(self) -> None:
8383
auth = self.create_jwt_auth('issuer', 'issuer/key',
8484
self._private_key_pem.decode(), 'audience',
85-
algorithm=self.algorithm, reuse_jwts=True)
85+
algorithm=self.algorithm, reuse_jwts=True) # type: ignore[attr-defined]
8686
auth_header = self._get_auth_header(auth)
87-
self.assertEqual(auth_header, self._get_auth_header(auth))
87+
self.assertEqual(auth_header, self._get_auth_header(auth)) # type: ignore[attr-defined]
8888

8989
def test_do_not_reuse_jwt_if_audience_changes(self) -> None:
9090
auth = self.create_jwt_auth('issuer', 'issuer/key',
9191
self._private_key_pem.decode(), 'audience',
92-
algorithm=self.algorithm, reuse_jwts=True)
92+
algorithm=self.algorithm, reuse_jwts=True) # type: ignore[attr-defined]
9393
auth_header = self._get_auth_header(auth)
9494
auth._audience = 'not-' + auth._audience
95-
self.assertNotEqual(auth_header, self._get_auth_header(auth))
95+
self.assertNotEqual(auth_header, self._get_auth_header(auth)) # type: ignore[attr-defined]
9696

9797
def test_do_not_reuse_jwt_if_issuer_changes(self) -> None:
9898
auth = self.create_jwt_auth('issuer', 'issuer/key',
9999
self._private_key_pem.decode(), 'audience',
100-
algorithm=self.algorithm, reuse_jwts=True)
100+
algorithm=self.algorithm, reuse_jwts=True) # type: ignore[attr-defined]
101101
auth_header = self._get_auth_header(auth)
102102
auth._signer.issuer = 'not-' + auth._signer.issuer
103-
self.assertNotEqual(auth_header, self._get_auth_header(auth))
103+
self.assertNotEqual(auth_header, self._get_auth_header(auth)) # type: ignore[attr-defined]
104104

105105
def test_do_not_reuse_jwt_if_lifetime_changes(self) -> None:
106106
auth = self.create_jwt_auth('issuer', 'issuer/key',
107107
self._private_key_pem.decode(), 'audience',
108-
algorithm=self.algorithm, reuse_jwts=True)
108+
algorithm=self.algorithm, reuse_jwts=True) # type: ignore[attr-defined]
109109
auth_header = self._get_auth_header(auth)
110110
auth._signer.lifetime = auth._signer.lifetime - timedelta(seconds=1)
111-
self.assertNotEqual(auth_header, self._get_auth_header(auth))
111+
self.assertNotEqual(auth_header, self._get_auth_header(auth)) # type: ignore[attr-defined]
112112

113113
def test_do_not_reuse_jwt_if_subject_changes(self) -> None:
114114
auth = self.create_jwt_auth('issuer', 'issuer/key',
115115
self._private_key_pem.decode(), 'audience',
116-
algorithm=self.algorithm, reuse_jwts=True,
116+
algorithm=self.algorithm, reuse_jwts=True, # type: ignore[attr-defined]
117117
subject='subject')
118118
auth_header = self._get_auth_header(auth)
119-
auth._signer.subject = 'not-' + auth._signer.subject
120-
self.assertNotEqual(auth_header, self._get_auth_header(auth))
119+
auth._signer.subject = 'not-' + auth._signer.subject # type: ignore[operator]
120+
self.assertNotEqual(auth_header, self._get_auth_header(auth)) # type: ignore[attr-defined]
121121

122122
def test_do_not_reuse_jwt_if_additional_claims_change(self) -> None:
123123
auth = self.create_jwt_auth('issuer', 'issuer/key',
124124
self._private_key_pem.decode(), 'audience',
125-
algorithm=self.algorithm, reuse_jwts=True)
125+
algorithm=self.algorithm, reuse_jwts=True) # type: ignore[attr-defined]
126126
auth_header = self._get_auth_header(auth)
127127
auth._additional_claims['foo'] = 'bar'
128-
self.assertNotEqual(auth_header, self._get_auth_header(auth))
128+
self.assertNotEqual(auth_header, self._get_auth_header(auth)) # type: ignore[attr-defined]
129129

130130
def test_reuse_jwt_with_additional_claims(self) -> None:
131131
# calculating the cache key with additional claims is non-trivial
132132
auth = self.create_jwt_auth('issuer', 'issuer/key',
133133
self._private_key_pem.decode(), 'audience',
134-
algorithm=self.algorithm, reuse_jwts=True)
134+
algorithm=self.algorithm, reuse_jwts=True) # type: ignore[attr-defined]
135135
auth._additional_claims['foo'] = 'bar'
136136
auth._additional_claims['fool'] = 'blah'
137137
auth._additional_claims['foot'] = 'quux'
138138
auth_header = self._get_auth_header(auth)
139-
self.assertEqual(auth_header, self._get_auth_header(auth))
139+
self.assertEqual(auth_header, self._get_auth_header(auth)) # type: ignore[attr-defined]
140140

141141

142142
class RequestsRS256Test(BaseRequestsTest,

atlassian_jwt_auth/tests/test_private_key_provider.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class BaseDataUriPrivateKeyRetrieverTest(object):
2525
""" tests for the DataUriPrivateKeyRetriever class. """
2626

2727
def setUp(self) -> None:
28-
self._private_key_pem = self.get_new_private_key_in_pem_format()
28+
self._private_key_pem = self.get_new_private_key_in_pem_format() # type: ignore[attr-defined]
2929
self._public_key_pem = utils.get_public_key_pem_for_private_key_pem(
3030
self._private_key_pem)
3131
self._private_key_der = convert_key_pem_format_to_der_format(
@@ -41,8 +41,8 @@ def test_load_data_uri(self) -> None:
4141
data_uri = self.get_example_data_uri(self._private_key_der)
4242
provider = DataUriPrivateKeyRetriever(data_uri)
4343
kid, private_key_pem = provider.load('example')
44-
self.assertEqual(kid.key_id, expected_kid)
45-
self.assertEqual(private_key_pem,
44+
self.assertEqual(kid.key_id, expected_kid) # type: ignore[attr-defined]
45+
self.assertEqual(private_key_pem, # type: ignore[attr-defined]
4646
self._private_key_pem.decode('utf-8'))
4747

4848
def test_load_data_uri_can_be_used_with_a_signer(self) -> None:
@@ -52,7 +52,7 @@ def test_load_data_uri_can_be_used_with_a_signer(self) -> None:
5252
data_uri = self.get_example_data_uri(self._private_key_der)
5353
provider = DataUriPrivateKeyRetriever(data_uri)
5454
jwt_auth_signer = JWTAuthSigner(
55-
'issuer', provider, algorithm=self.algorithm)
55+
'issuer', provider, algorithm=self.algorithm) # type: ignore[attr-defined]
5656
jwt_auth_signer.generate_jwt('aud')
5757

5858

atlassian_jwt_auth/tests/test_public_key_provider.py

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def create_retriever(self, url) -> HTTPSPublicKeyRetriever:
3737
return HTTPSPublicKeyRetriever(url)
3838

3939
def setUp(self) -> None:
40-
self._private_key_pem = self.get_new_private_key_in_pem_format()
40+
self._private_key_pem = self.get_new_private_key_in_pem_format() # type: ignore[attr-defined]
4141
self._public_key_pem = utils.get_public_key_pem_for_private_key_pem(
4242
self._private_key_pem)
4343
self.base_url = 'https://example.com'
@@ -47,15 +47,15 @@ def test_https_public_key_retriever_does_not_support_http_url(
4747
""" tests that HTTPSPublicKeyRetriever does not support http://
4848
base urls.
4949
"""
50-
with self.assertRaises(ValueError):
50+
with self.assertRaises(ValueError): # type: ignore[attr-defined]
5151
self.create_retriever('http://example.com')
5252

5353
def test_https_public_key_retriever_does_not_support_none_url(
5454
self) -> None:
5555
""" tests that HTTPSPublicKeyRetriever does not support None
5656
base urls.
5757
"""
58-
with self.assertRaises(ValueError):
58+
with self.assertRaises(ValueError): # type: ignore[attr-defined]
5959
self.create_retriever(None)
6060

6161
def test_https_public_key_retriever_session_uses_env_proxy(self) -> None:
@@ -69,9 +69,9 @@ def test_https_public_key_retriever_session_uses_env_proxy(self) -> None:
6969
retriever = self.create_retriever(self.base_url)
7070
key_retrievers = [retriever]
7171
if isinstance(retriever, HTTPSMultiRepositoryPublicKeyRetriever):
72-
key_retrievers = retriever._retrievers
72+
key_retrievers = retriever._retrievers # type: ignore[assignment]
7373
for key_retriever in key_retrievers:
74-
self.assertEqual(key_retriever._proxies, expected_proxies)
74+
self.assertEqual(key_retriever._proxies, expected_proxies) # type: ignore[attr-defined]
7575

7676
def test_https_public_key_retriever_supports_https_url(self) -> None:
7777
""" tests that HTTPSPublicKeyRetriever supports https://
@@ -83,9 +83,9 @@ def test_https_public_key_retriever_supports_https_url(self) -> None:
8383
def test_retrieve(self, mock_get_method: Mock) -> None:
8484
""" tests that the retrieve method works expected. """
8585
_setup_mock_response_for_retriever(
86-
mock_get_method, self._public_key_pem)
86+
mock_get_method, self._public_key_pem) # type: ignore[arg-type]
8787
retriever = self.create_retriever(self.base_url)
88-
self.assertEqual(
88+
self.assertEqual( # type: ignore[attr-defined]
8989
retriever.retrieve('example/eg'),
9090
self._public_key_pem)
9191

@@ -99,7 +99,7 @@ def test_retrieve_with_proxy(self, mock_get_method: Mock) -> None:
9999
expected_proxies, proxy_dict = get_expected_and_os_proxies_dict(
100100
proxy_location)
101101
_setup_mock_response_for_retriever(
102-
mock_get_method, self._public_key_pem)
102+
mock_get_method, self._public_key_pem) # type: ignore[arg-type]
103103
with mock.patch.dict(os.environ, proxy_dict, clear=True):
104104
retriever = self.create_retriever(self.base_url)
105105
retriever.retrieve(key_id)
@@ -122,7 +122,7 @@ def test_retrieve_with_proxy_explicitly_set(
122122
expected_proxies, _ = get_expected_and_os_proxies_dict(
123123
explicit_proxy_location)
124124
_setup_mock_response_for_retriever(
125-
mock_get_method, self._public_key_pem)
125+
mock_get_method, self._public_key_pem) # type: ignore[arg-type]
126126
with mock.patch.dict(os.environ, proxy_dict, clear=True):
127127
retriever = self.create_retriever(self.base_url)
128128
retriever.retrieve(key_id, proxies=expected_proxies)
@@ -140,9 +140,9 @@ def test_retrieve_with_charset_in_content_type_h(
140140
"""
141141
headers = {'content-type': 'application/x-pem-file;charset=UTF-8'}
142142
_setup_mock_response_for_retriever(
143-
mock_get_method, self._public_key_pem, headers)
143+
mock_get_method, self._public_key_pem, headers) # type: ignore[arg-type]
144144
retriever = self.create_retriever(self.base_url)
145-
self.assertEqual(
145+
self.assertEqual( # type: ignore[attr-defined]
146146
retriever.retrieve('example/eg'),
147147
self._public_key_pem)
148148

@@ -154,9 +154,9 @@ def test_retrieve_fails_with_different_content_type(
154154
"""
155155
headers = {'content-type': 'different/not-supported'}
156156
_setup_mock_response_for_retriever(
157-
mock_get_method, self._public_key_pem, headers)
157+
mock_get_method, self._public_key_pem, headers) # type: ignore[arg-type]
158158
retriever = self.create_retriever(self.base_url)
159-
with self.assertRaises(ValueError):
159+
with self.assertRaises(ValueError): # type: ignore[attr-defined]
160160
retriever.retrieve('example/eg')
161161

162162
@mock.patch.object(requests.Session, 'get',
@@ -169,9 +169,9 @@ def test_retrieve_fails_with_forbidden_error(
169169
403 forbidden error.
170170
"""
171171
_setup_mock_response_for_retriever(
172-
mock_get_method, self._public_key_pem)
172+
mock_get_method, self._public_key_pem) # type: ignore[arg-type]
173173
retriever = self.create_retriever(self.base_url)
174-
with self.assertRaises(ValueError):
174+
with self.assertRaises(ValueError): # type: ignore[attr-defined]
175175
retriever.retrieve('example/eg')
176176

177177

@@ -225,13 +225,13 @@ class BaseHTTPSMultiRepositoryPublicKeyRetrieverTest(
225225
BaseHTTPSPublicKeyRetrieverTest):
226226
""" tests for the HTTPSMultiRepositoryPublicKeyRetriever class. """
227227

228-
def create_retriever(
228+
def create_retriever( # type: ignore[override]
229229
self, url: str) -> HTTPSMultiRepositoryPublicKeyRetriever:
230230
""" returns a public key retriever created using the given url. """
231231
return HTTPSMultiRepositoryPublicKeyRetriever([url])
232232

233233
def setUp(self) -> None:
234-
self._private_key_pem = self.get_new_private_key_in_pem_format()
234+
self._private_key_pem = self.get_new_private_key_in_pem_format() # type: ignore[attr-defined]
235235
self._public_key_pem = utils.get_public_key_pem_for_private_key_pem(
236236
self._private_key_pem)
237237
self.keystore_urls = ['https://example.com', 'https://example.ly']
@@ -242,16 +242,16 @@ def test_https_multi_public_key_retriever_does_not_support_strings(
242242
""" tests that HTTPSMultiRepositoryPublicKeyRetriever does not
243243
support a string key repository url.
244244
"""
245-
with self.assertRaises(TypeError):
245+
with self.assertRaises(TypeError): # type: ignore[attr-defined]
246246
HTTPSMultiRepositoryPublicKeyRetriever('https://example.com')
247247

248248
@mock.patch.object(requests.Session, 'get')
249249
def test_retrieve(self, mock_get_method: Mock) -> None:
250250
""" tests that the retrieve method works expected. """
251251
_setup_mock_response_for_retriever(
252-
mock_get_method, self._public_key_pem)
252+
mock_get_method, self._public_key_pem) # type: ignore[arg-type]
253253
retriever = HTTPSMultiRepositoryPublicKeyRetriever(self.keystore_urls)
254-
self.assertEqual(
254+
self.assertEqual( # type: ignore[attr-defined]
255255
retriever.retrieve('example/eg'),
256256
self._public_key_pem)
257257

@@ -262,13 +262,13 @@ def test_retrieve_with_500_error(self, mock_get_method: Mock) -> None:
262262
"""
263263
retriever = HTTPSMultiRepositoryPublicKeyRetriever(self.keystore_urls)
264264
_setup_mock_response_for_retriever(
265-
mock_get_method, self._public_key_pem)
265+
mock_get_method, self._public_key_pem) # type: ignore[arg-type]
266266
valid_response = mock_get_method.return_value
267267
del mock_get_method.return_value
268268
server_exception = requests.exceptions.HTTPError(
269269
response=mock.Mock(status_code=500))
270270
mock_get_method.side_effect = [server_exception, valid_response]
271-
self.assertEqual(
271+
self.assertEqual( # type: ignore[attr-defined]
272272
retriever.retrieve('example/eg'),
273273
self._public_key_pem)
274274

@@ -280,13 +280,13 @@ def test_retrieve_with_connection_error(
280280
"""
281281
retriever = HTTPSMultiRepositoryPublicKeyRetriever(self.keystore_urls)
282282
_setup_mock_response_for_retriever(
283-
mock_get_method, self._public_key_pem)
283+
mock_get_method, self._public_key_pem) # type: ignore[arg-type]
284284
valid_response = mock_get_method.return_value
285285
del mock_get_method.return_value
286286
connection_exception = requests.exceptions.ConnectionError(
287287
response=mock.Mock(status_code=None))
288288
mock_get_method.side_effect = [connection_exception, valid_response]
289-
self.assertEqual(
289+
self.assertEqual( # type: ignore[attr-defined]
290290
retriever.retrieve('example/eg'),
291291
self._public_key_pem)
292292

0 commit comments

Comments
 (0)