Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI Credentials Validation: correct condition for non-string type and add tests #15562

Merged
merged 2 commits into from
Aug 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tools/ci_credentials/ci_credentials/secrets_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def mask_secrets_from_action_log(self, key, value):
for pattern in MASK_KEY_PATTERNS:
if re.search(pattern, key):
self.logger.info(f"Add mask for key: {key}")
for line in value.splitlines():
for line in str(value).splitlines():
line = str(line).strip()
# don't output } and such
if len(line) > 1 and not os.getenv("VERSION") == "dev":
Expand Down
15 changes: 15 additions & 0 deletions tools/ci_credentials/tests/test_secrets.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import re
import shutil
import tempfile
import sys
from pathlib import Path
from unittest.mock import patch

Expand Down Expand Up @@ -166,3 +167,17 @@ def test_write(connector_name, secrets, expected_files):
has = True
break
assert has, f"incorrect file data: {target_file}"


@pytest.mark.parametrize(
"connector_name,dict_json_value,expected_secret",
(
("source-default", "{\"org_id\": 111}", "::add-mask::111"),
("source-default", "{\"org\": 111}", ""),
)
)
def test_validate_mask_values(connector_name, dict_json_value, expected_secret, capsys):
loader = SecretsLoader(connector_name=connector_name, gsm_credentials={})
json_value = json.loads(dict_json_value)
loader.mask_secrets_from_action_log(None, json_value)
assert expected_secret in capsys.readouterr().out