Skip to content

Commit

Permalink
fix(nhn): replace sys.exit with exceptions for token retrieval errors
Browse files Browse the repository at this point in the history
  • Loading branch information
eeche committed Mar 4, 2025
1 parent 14005c7 commit 4fce107
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
5 changes: 2 additions & 3 deletions prowler/providers/nhn/nhn_provider.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import sys
from typing import Optional

import requests
Expand Down Expand Up @@ -209,10 +208,10 @@ def setup_session(self) -> None:
logger.critical(
f"Failed to get token. Status: {response.status_code}, Body: {response.text}"
)
sys.exit(1)
raise ValueError("Failed to get NHN token")
except Exception as e:
logger.critical(f"[setup_session] Error: {e}")
sys.exit(1)
raise e

@staticmethod
def test_connection(
Expand Down
14 changes: 7 additions & 7 deletions tests/providers/nhn/nhn_provider_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@ def test_nhn_provider_init_token_fail(self, mock_post, mock_load_config):
mock_post.return_value.status_code = 401
mock_post.return_value.text = "Unauthorized"

provider = NhnProvider(
username="test_user",
password="test_pass",
tenant_id="tenant123",
)
with pytest.raises(ValueError) as exc_info:
NhnProvider(
username="test_user",
password="test_pass",
tenant_id="tenant123",
)

assert provider._token is None
assert provider.session is None
assert "Failed to get NHN token" in str(exc_info.value)

@patch("prowler.providers.nhn.nhn_provider.requests")
def test_test_connection_success(self, mock_requests):
Expand Down

0 comments on commit 4fce107

Please sign in to comment.