Skip to content

Commit 49a7b9a

Browse files
author
Mat Lord
committed
chore(tests): Add Api._auth() test
1 parent e6002aa commit 49a7b9a

2 files changed

Lines changed: 25 additions & 2 deletions

File tree

staxapp/api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ class Api:
88
_requests_auth = None
99

1010
@classmethod
11-
def _auth(cls):
11+
def _auth(cls, **kwargs):
1212
if not cls._requests_auth:
1313
cls._requests_auth = Config.get_auth_class().requests_auth(
14-
Config.access_key, Config.secret_key
14+
Config.access_key, Config.secret_key, **kwargs
1515
)
1616
return cls._requests_auth
1717

tests/test_auth.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from botocore.stub import Stubber, ANY
1717
from datetime import datetime, timedelta, timezone
1818

19+
from staxapp.api import Api
1920
from staxapp.auth import StaxAuth, ApiTokenAuth, RootAuth
2021
from staxapp.config import Config
2122
from staxapp.exceptions import InvalidCredentialsException
@@ -311,6 +312,28 @@ def testRootAuth(self):
311312
)
312313
self.assertIsNotNone(StaxConfig.auth)
313314

315+
def testApiAuth(self):
316+
"""
317+
Test auth through the Api class
318+
"""
319+
sa = StaxAuth("ApiAuth")
320+
StaxConfig = Config
321+
StaxConfig.expiration = None
322+
StaxConfig.access_key = "username"
323+
StaxConfig.secret_key = "password"
324+
325+
token = jwt.encode({"sub": "valid_token"}, "secret", algorithm="HS256")
326+
jwt_token = jwt.decode(token, verify=False)
327+
328+
self.stub_cognito_creds(sa, jwt_token.get("sub"))
329+
self.stub_aws_srp(sa, "username")
330+
331+
Api._requests_auth = None
332+
Api._auth(
333+
srp_client=self.aws_srp_client, cognito_client=self.cognito_client,
334+
)
335+
self.assertIsNotNone(Api._requests_auth)
336+
314337

315338
if __name__ == "__main__":
316339
unittest.main()

0 commit comments

Comments
 (0)