Skip to content

Commit

Permalink
[AWS] Fix: Handle NoneType response in is_access_denied_exception (#1046
Browse files Browse the repository at this point in the history
)
  • Loading branch information
phalbert authored Sep 23, 2024
1 parent 50514c7 commit a49d0b2
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 4 deletions.
5 changes: 5 additions & 0 deletions integrations/aws/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

<!-- towncrier release notes start -->
## 0.2.42 (2024-09-24)

### Bug Fixes

- Fixes an issue where `is_access_denied_exception` could raise an `AttributeError` if `e.response` is `None`.

## 0.2.41 (2024-09-22)

Expand Down
2 changes: 1 addition & 1 deletion integrations/aws/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "aws"
version = "0.2.41"
version = "0.2.42"
description = "This integration will map all your resources in all the available accounts to your Port entities"
authors = ["Shalev Avhar <[email protected]>", "Erik Zaadi <[email protected]>"]

Expand Down
2 changes: 0 additions & 2 deletions integrations/aws/tests/test_sample.py

This file was deleted.

27 changes: 27 additions & 0 deletions integrations/aws/tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from utils.misc import is_access_denied_exception
from typing import Optional, Dict, Any


class MockException(Exception):
def __init__(self, response: Optional[Dict[str, Any]]) -> None:
self.response = response


def test_access_denied_exception_with_response() -> None:
e = MockException(response={"Error": {"Code": "AccessDenied"}})
assert is_access_denied_exception(e)


def test_access_denied_exception_without_response() -> None:
e = MockException(response=None)
assert not is_access_denied_exception(e)


def test_access_denied_exception_with_other_error() -> None:
e = MockException(response={"Error": {"Code": "SomeOtherError"}})
assert not is_access_denied_exception(e)


def test_access_denied_exception_no_response_attribute() -> None:
e = Exception("Test exception")
assert not is_access_denied_exception(e)
2 changes: 1 addition & 1 deletion integrations/aws/utils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def is_access_denied_exception(e: Exception) -> bool:
"UnauthorizedOperation",
]

if hasattr(e, "response"):
if hasattr(e, "response") and e.response is not None:
error_code = e.response.get("Error", {}).get("Code")
return error_code in access_denied_error_codes

Expand Down

0 comments on commit a49d0b2

Please sign in to comment.