Skip to content

Commit 75d4832

Browse files
author
Alexander Demin
committed
Unit test for empty AWS variables
1 parent ace459b commit 75d4832

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

pre_commit_hooks/detect_aws_credentials.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def get_aws_secrets_from_env() -> Set[str]:
3131
for env_var in (
3232
'AWS_SECRET_ACCESS_KEY', 'AWS_SECURITY_TOKEN', 'AWS_SESSION_TOKEN',
3333
):
34-
if env_var in os.environ:
34+
if env_var in os.environ and os.environ[env_var]:
3535
keys.add(os.environ[env_var])
3636
return keys
3737

@@ -84,7 +84,7 @@ def check_file_for_aws_keys(
8484
for key in keys:
8585
# naively match the entire file, low chance of incorrect
8686
# collision
87-
if key and key in text_body:
87+
if key in text_body:
8888
bad_files.append(BadFile(filename, key[:4].ljust(28, '*')))
8989
return bad_files
9090

tests/detect_aws_credentials_test.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ def test_get_aws_credentials_file_from_env(env_vars, values):
4747
({'AWS_SECRET_ACCESS_KEY': 'foo'}, {'foo'}),
4848
({'AWS_SECURITY_TOKEN': 'foo'}, {'foo'}),
4949
({'AWS_SESSION_TOKEN': 'foo'}, {'foo'}),
50+
({'AWS_SESSION_TOKEN': ''}, set()),
51+
({'AWS_SESSION_TOKEN': 'foo', 'AWS_SECURITY_TOKEN': ''}, {'foo'}),
5052
({'AWS_DUMMY_KEY': 'foo', 'AWS_SECRET_ACCESS_KEY': 'bar'}, {'bar'}),
5153
(
5254
{'AWS_SECRET_ACCESS_KEY': 'foo', 'AWS_SECURITY_TOKEN': 'bar'},

0 commit comments

Comments
 (0)