Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
angelofenoglio committed Oct 17, 2024
1 parent 9b08ea8 commit 4e37e8f
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tests/test_modules/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from unittest.mock import Mock, MagicMock, PropertyMock

import pytest
from botocore.exceptions import ClientError
from configupdater import ConfigUpdater

from leverage._utils import ExitError
Expand Down Expand Up @@ -265,3 +266,19 @@ def test_refresh_layer_credentials(mock_boto, mock_open, mock_update_conf, sso_c
"aws_secret_access_key": "secret-key",
"aws_session_token": "session-token",
}


b3_client_error = Mock()
b3_client_error.get_role_credentials.side_effect = ClientError(
{"Error": {"Code": "ForbiddenException", "Message": "No access"}}, "GetRoleCredentials"
)


@mock.patch("leverage.modules.auth.update_config_section")
@mock.patch("builtins.open", side_effect=open_side_effect)
@mock.patch("boto3.client", return_value=b3_client_error)
@mock.patch("time.time", new=Mock(return_value=1705859000))
@mock.patch("pathlib.Path.touch", new=Mock())
def test_refresh_layer_credentials_no_access(mock_boto, mock_open, mock_update_conf, sso_container, propagate_logs):
with pytest.raises(ExitError):
refresh_layer_credentials(sso_container)

0 comments on commit 4e37e8f

Please sign in to comment.