summaryrefslogtreecommitdiffstats
path: root/contrib/python/google-auth/py3/tests/test__helpers.py
diff options
context:
space:
mode:
authorrobot-piglet <[email protected]>2025-10-14 13:58:45 +0300
committerrobot-piglet <[email protected]>2025-10-14 14:26:06 +0300
commit09cc5fe0eb0747ac9ce1444c9acc944838a8cfa2 (patch)
tree61e19f6a3c904d77e58ff647f4c9473378d6954b /contrib/python/google-auth/py3/tests/test__helpers.py
parente9146d8a4d0ee112c89906f9fc8ce23b92250439 (diff)
Intermediate changes
commit_hash:bc75ab7ba0ee5a6571045c99062e8d4a996d16dd
Diffstat (limited to 'contrib/python/google-auth/py3/tests/test__helpers.py')
-rw-r--r--contrib/python/google-auth/py3/tests/test__helpers.py29
1 files changed, 28 insertions, 1 deletions
diff --git a/contrib/python/google-auth/py3/tests/test__helpers.py b/contrib/python/google-auth/py3/tests/test__helpers.py
index a4337c01608..ce3ec11e29c 100644
--- a/contrib/python/google-auth/py3/tests/test__helpers.py
+++ b/contrib/python/google-auth/py3/tests/test__helpers.py
@@ -20,7 +20,7 @@ import urllib
import pytest # type: ignore
-from google.auth import _helpers
+from google.auth import _helpers, exceptions
# _MOCK_BASE_LOGGER_NAME is the base logger namespace used for testing.
_MOCK_BASE_LOGGER_NAME = "foogle"
@@ -234,6 +234,33 @@ def test_unpadded_urlsafe_b64encode():
assert _helpers.unpadded_urlsafe_b64encode(case) == expected
+def test_get_bool_from_env(monkeypatch):
+ # Test default value when environment variable is not set.
+ assert _helpers.get_bool_from_env("TEST_VAR") is False
+ assert _helpers.get_bool_from_env("TEST_VAR", default=True) is True
+
+ # Test true values (case-insensitive)
+ for true_value in ("true", "True", "TRUE", "1"):
+ monkeypatch.setenv("TEST_VAR", true_value)
+ assert _helpers.get_bool_from_env("TEST_VAR") is True
+
+ # Test false values (case-insensitive)
+ for false_value in ("false", "False", "FALSE", "0"):
+ monkeypatch.setenv("TEST_VAR", false_value)
+ assert _helpers.get_bool_from_env("TEST_VAR") is False
+
+ # Test invalid value
+ monkeypatch.setenv("TEST_VAR", "invalid_value")
+ with pytest.raises(exceptions.InvalidValue) as excinfo:
+ _helpers.get_bool_from_env("TEST_VAR")
+ assert 'must be one of "true", "false", "1", or "0"' in str(excinfo.value)
+
+ # Test empty string value
+ monkeypatch.setenv("TEST_VAR", "")
+ with pytest.raises(exceptions.InvalidValue):
+ _helpers.get_bool_from_env("TEST_VAR")
+
+
def test_hash_sensitive_info_basic():
test_data = {
"expires_in": 3599,