Skip to content
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
3 changes: 3 additions & 0 deletions openqa-investigate
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ HTTP_NOT_FOUND = 404
USER_AGENT = "openqa-investigate (https://github.com/os-autoinst/os-autoinst-scripts)"
DEFAULT_HTTP_TIMEOUT: float = 90.0
DEFAULT_INVESTIGATION_TIMEOUT: float = 900.0
# Characters allowed by openQA in TEST variable: '\p{Word} _*.,:/#@'
TEST_NAME_INVALID_CHARS = re.compile(r"[^\w _*.,:/#@]")

log = logging.getLogger("openqa-investigate")

Expand Down Expand Up @@ -497,6 +499,7 @@ def _build_clone_settings( # ruff: ignore[too-many-arguments, too-many-position
) -> tuple[list[str], str]:
"""Build clone settings and the full job name."""
base_name = job_info.get("test", "")
name_suffix = TEST_NAME_INVALID_CHARS.sub("", name_suffix)
suffix_str = f":{name_suffix}" if name_suffix else ""
name = f"{base_name}:investigate{suffix_str}"

Expand Down
27 changes: 27 additions & 0 deletions tests/test_openqa_investigate.py
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,33 @@ def test_build_clone_settings(mocker: MockerFixture) -> None:
)
assert "OPENQA_INVESTIGATE_STRICT=1" in settings_strict

# Strip invalid characters from TEST variable (suffix_str)
settings_invalid, name_invalid = openqa_investigate._build_clone_settings(
client,
job_info,
10,
"last_good_tests_and_build:hash+build-123!$(test)",
None,
None,
42,
)
assert "TEST+=:investigate:last_good_tests_and_build:hashbuild123test" in settings_invalid
assert name_invalid == "sample_test:investigate:last_good_tests_and_build:hashbuild123test"

# All characters allowed by openQA (\p{Word} _*.,:/#@) are preserved
allowed = "valid_WORD 123_*.,:/#@"
settings_allowed, name_allowed = openqa_investigate._build_clone_settings(
client,
job_info,
10,
allowed,
None,
None,
42,
)
assert f"TEST+=:investigate:{allowed}" in settings_allowed
assert name_allowed == f"sample_test:investigate:{allowed}"


def test_clone(mocker: MockerFixture) -> None:
client = openqa_investigate.OpenQAClient("https://openqa.opensuse.org")
Expand Down
Loading