Skip to content

Commit

Permalink
test: fix tests and add new Exception (#99)
Browse files Browse the repository at this point in the history
Release-as: 1.1.0

* test: fix tests and add new Exception

* build: fix code coverage step

---------

Co-authored-by: Emmanuel Hadoux <[email protected]>
  • Loading branch information
ailinvenerus and EHadoux authored Nov 6, 2023
1 parent 622f7ae commit c2fffd9
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ jobs:
env:
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
with:
coverageLocations: ${{github.workspace}}/.coverage:coverage.py
coverageCommand: coverage xml
8 changes: 7 additions & 1 deletion scribeauth/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
from .scribeauth import ScribeAuth, Tokens
from .scribeauth import (
ScribeAuth,
Tokens,
ResourceNotFoundException,
MissingIdException,
UnauthorizedException,
)
6 changes: 6 additions & 0 deletions scribeauth/scribeauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ class MissingIdException(Exception):
pass


class ResourceNotFoundException(Exception):
pass


class UnknownException(Exception):
pass

Expand Down Expand Up @@ -302,6 +306,8 @@ def get_federated_credentials(self, id: str, id_token: str) -> Credentials:
raise UnauthorizedException("Could not retrieve federated credentials")
if err.response["Error"]["Code"] == "TooManyRequestsException":
raise TooManyRequestsException("Too many requests. Try again later")
if err.response["Error"]["Code"] == "ResourceNotFoundException":
raise ResourceNotFoundException("Invalid federated_id")
raise err

def get_signature_for_request(self, request: AWSRequest, credentials: Credentials):
Expand Down
15 changes: 10 additions & 5 deletions tests/test_scribeauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@

from botocore.awsrequest import AWSRequest
from dotenv import load_dotenv

from scribeauth import ScribeAuth, Tokens
from scribeauth.scribeauth import MissingIdException, UnauthorizedException
from scribeauth import (
ScribeAuth,
Tokens,
ResourceNotFoundException,
MissingIdException,
UnauthorizedException,
)

load_dotenv()

Expand Down Expand Up @@ -132,8 +136,9 @@ def test_get_federated_credentials_fails(self):
username=username, password=password
)
id_token = user_tokens.get("id_token")
with self.assertRaises(UnauthorizedException):
pool_access.get_federated_credentials("id", id_token)
id = "eu-west-2:00000000-1111-2abc-3def-4444aaaa5555"
with self.assertRaises(ResourceNotFoundException):
pool_access.get_federated_credentials(id, id_token)


class TestScribeAuthGetSignatureForRequest(unittest.TestCase):
Expand Down

0 comments on commit c2fffd9

Please sign in to comment.