From c2fffd96fdbb0dcd40d46e88c6da4d6f24024c8b Mon Sep 17 00:00:00 2001 From: Ailin Venerus Date: Mon, 6 Nov 2023 12:09:57 +0000 Subject: [PATCH] test: fix tests and add new Exception (#99) Release-as: 1.1.0 * test: fix tests and add new Exception * build: fix code coverage step --------- Co-authored-by: Emmanuel Hadoux --- .github/workflows/test.yml | 2 +- scribeauth/__init__.py | 8 +++++++- scribeauth/scribeauth.py | 6 ++++++ tests/test_scribeauth.py | 15 ++++++++++----- 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 15db6a7..c113508 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 diff --git a/scribeauth/__init__.py b/scribeauth/__init__.py index 52a1567..129f8bf 100644 --- a/scribeauth/__init__.py +++ b/scribeauth/__init__.py @@ -1 +1,7 @@ -from .scribeauth import ScribeAuth, Tokens +from .scribeauth import ( + ScribeAuth, + Tokens, + ResourceNotFoundException, + MissingIdException, + UnauthorizedException, +) diff --git a/scribeauth/scribeauth.py b/scribeauth/scribeauth.py index 5ec9f1c..da50ff9 100644 --- a/scribeauth/scribeauth.py +++ b/scribeauth/scribeauth.py @@ -65,6 +65,10 @@ class MissingIdException(Exception): pass +class ResourceNotFoundException(Exception): + pass + + class UnknownException(Exception): pass @@ -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): diff --git a/tests/test_scribeauth.py b/tests/test_scribeauth.py index d8e7c20..337b208 100644 --- a/tests/test_scribeauth.py +++ b/tests/test_scribeauth.py @@ -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() @@ -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):