|
|
|
|
@ -17,6 +17,7 @@ class GitLabReleaseHelperTests(unittest.TestCase):
|
|
|
|
|
fake_curl = self.bin_dir / "curl"
|
|
|
|
|
fake_curl.write_text(
|
|
|
|
|
"""#!/bin/sh
|
|
|
|
|
printf '%s\\n' \"$@\" > \"$FAKE_CURL_ARGUMENTS\"
|
|
|
|
|
output=
|
|
|
|
|
while [ \"$#\" -gt 0 ]; do
|
|
|
|
|
case \"$1\" in
|
|
|
|
|
@ -39,15 +40,16 @@ printf '%s' \"${FAKE_CURL_STATUS:-201}\"
|
|
|
|
|
def tearDown(self):
|
|
|
|
|
self.temporary.cleanup()
|
|
|
|
|
|
|
|
|
|
def run_helper(self, status, body=""):
|
|
|
|
|
def run_helper(self, status, body="", api_url="https://gitlab.example/api/v4"):
|
|
|
|
|
environment = os.environ.copy()
|
|
|
|
|
environment.update(
|
|
|
|
|
{
|
|
|
|
|
"CI_API_V4_URL": "https://gitlab.example/api/v4",
|
|
|
|
|
"CI_API_V4_URL": api_url,
|
|
|
|
|
"CI_PROJECT_ID": "123",
|
|
|
|
|
"CI_JOB_TOKEN": "not-logged",
|
|
|
|
|
"FAKE_CURL_STATUS": str(status),
|
|
|
|
|
"FAKE_CURL_BODY": body,
|
|
|
|
|
"FAKE_CURL_ARGUMENTS": str(self.bin_dir / "curl-arguments"),
|
|
|
|
|
"PATH": "{}:{}".format(self.bin_dir, environment["PATH"]),
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
@ -77,6 +79,33 @@ printf '%s' \"${FAKE_CURL_STATUS:-201}\"
|
|
|
|
|
self.assertIn('"message":"failure"', result.stderr)
|
|
|
|
|
self.assertNotIn("not-logged", result.stderr)
|
|
|
|
|
|
|
|
|
|
def test_http_api_url_uses_https_without_following_redirects(self):
|
|
|
|
|
result = self.run_helper(201, api_url="http://gitlab.example/gitlab/api/v4")
|
|
|
|
|
self.assertEqual(result.returncode, 0, result.stderr)
|
|
|
|
|
arguments = (self.bin_dir / "curl-arguments").read_text().splitlines()
|
|
|
|
|
self.assertEqual(arguments[-1], "https://gitlab.example/gitlab/api/v4/projects/123/releases")
|
|
|
|
|
self.assertEqual(arguments[arguments.index("--proto") + 1], "=https")
|
|
|
|
|
self.assertNotIn("--location", arguments)
|
|
|
|
|
self.assertNotIn("--location-trusted", arguments)
|
|
|
|
|
self.assertNotIn("-L", arguments)
|
|
|
|
|
self.assertNotIn("not-logged", result.stdout + result.stderr)
|
|
|
|
|
|
|
|
|
|
def test_https_api_url_preserves_explicit_port_and_path(self):
|
|
|
|
|
result = self.run_helper(201, api_url="https://gitlab.example:8443/gitlab/api/v4")
|
|
|
|
|
self.assertEqual(result.returncode, 0, result.stderr)
|
|
|
|
|
arguments = (self.bin_dir / "curl-arguments").read_text().splitlines()
|
|
|
|
|
self.assertEqual(arguments[-1], "https://gitlab.example:8443/gitlab/api/v4/projects/123/releases")
|
|
|
|
|
|
|
|
|
|
def test_other_schemes_are_rejected_before_curl(self):
|
|
|
|
|
result = self.run_helper(201, api_url="file:///tmp/api/v4")
|
|
|
|
|
self.assertNotEqual(result.returncode, 0)
|
|
|
|
|
self.assertFalse((self.bin_dir / "curl-arguments").exists())
|
|
|
|
|
|
|
|
|
|
def test_https_redirect_remains_an_error(self):
|
|
|
|
|
result = self.run_helper(307, "Temporary Redirect")
|
|
|
|
|
self.assertNotEqual(result.returncode, 0)
|
|
|
|
|
self.assertIn("HTTP 307", result.stderr)
|
|
|
|
|
|
|
|
|
|
def test_pipeline_does_not_use_runner_release_keyword(self):
|
|
|
|
|
pipeline = PIPELINE.read_text(encoding="utf-8")
|
|
|
|
|
self.assertNotIn("\n release:\n", pipeline)
|
|
|
|
|
|