from pathlib import Path import importlib.util import pytest ROOT = Path(__file__).parents[1] def publisher(): spec = importlib.util.spec_from_file_location("publish_release", ROOT / "packaging/publish_release.py") module = importlib.util.module_from_spec(spec) spec.loader.exec_module(module) return module @pytest.mark.parametrize("value", ["../other", "org/name", "org?token=x", "", "name with spaces"]) def test_repository_names_cannot_change_request_paths(value): with pytest.raises(ValueError): publisher().validate_name(value) def test_expected_organization_name_is_valid(): assert publisher().validate_name("simgreek") == "simgreek" def test_attachment_uses_gitea_multipart_field(tmp_path): file = tmp_path / "release.zip" file.write_bytes(b"ZIP-CONTENT") body, content_type = publisher().multipart_attachment(file, "safe-boundary") assert 'boundary=safe-boundary' in content_type assert b'name="attachment"; filename="release.zip"' in body assert b"ZIP-CONTENT" in body and body.endswith(b"--safe-boundary--\r\n") def test_server_redirect_never_forwards_credentials(): handler = publisher().NoRedirect() assert handler.redirect_request(None, None, 302, "redirect", {}, "https://other-host.invalid") is None