Merge local CI archive redirect fix
Gitea CI / Check code and tests (push) Successful in 5m31s
Gitea CI / Build Android APK (push) Successful in 3m25s
Gitea CI / Build Windows x64 app (push) Successful in 5m4s
Gitea CI / Audit and package Windows x64 (push) Successful in 1m17s
Gitea CI / Assemble and validate CI artifacts (push) Successful in 53s
Gitea CI / Gitea CI passed (push) Successful in 2s
Gitea Release / Prepare draft Release (push) Successful in 13s
Gitea Release / Upload Android to draft Release (push) Successful in 18s
Gitea Release / Upload Windows to draft Release (push) Successful in 23s
Gitea Release / Verify and publish Release (push) Successful in 16s
Gitea CI / Check code and tests (push) Successful in 5m31s
Gitea CI / Build Android APK (push) Successful in 3m25s
Gitea CI / Build Windows x64 app (push) Successful in 5m4s
Gitea CI / Audit and package Windows x64 (push) Successful in 1m17s
Gitea CI / Assemble and validate CI artifacts (push) Successful in 53s
Gitea CI / Gitea CI passed (push) Successful in 2s
Gitea Release / Prepare draft Release (push) Successful in 13s
Gitea Release / Upload Android to draft Release (push) Successful in 18s
Gitea Release / Upload Windows to draft Release (push) Successful in 23s
Gitea Release / Verify and publish Release (push) Successful in 16s
PR CI #61 passed; verified actual archive download remains on loopback. Keep unpublished version 0.1.1+2.
This commit was merged in pull request #6.
This commit is contained in:
commit
da98df00a8
3 files changed
+40
-1
No files matched your search
@@ -52,6 +52,9 @@ configure a reachable private endpoint before using runners on other hosts.
|
|||||||
Checkout uses the same endpoint through its `github-server-url` input, retaining
|
Checkout uses the same endpoint through its `github-server-url` input, retaining
|
||||||
the requested commit/tag and disabling persisted credentials. Release requests
|
the requested commit/tag and disabling persisted credentials. Release requests
|
||||||
retain the public Host header so Gitea response links pass the public-origin checks.
|
retain the public Host header so Gitea response links pass the public-origin checks.
|
||||||
|
CI artifact ZIP download requests retain the loopback Host instead: Gitea returns
|
||||||
|
a signed redirect to the raw archive, and its Host must remain local for that
|
||||||
|
second request to avoid the public tunnel. Release attachment links stay public.
|
||||||
|
|
||||||
Compare warm CI runs after the first cache fill. Measure checks, Android compile,
|
Compare warm CI runs after the first cache fill. Measure checks, Android compile,
|
||||||
Windows compile, packaging and artifact transfer separately. Total duration follows
|
Windows compile, packaging and artifact transfer separately. Total duration follows
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ from concurrent.futures import ThreadPoolExecutor
|
|||||||
import http.client
|
import http.client
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
import urllib.error
|
import urllib.error
|
||||||
@@ -55,8 +56,13 @@ def retry_read(operation):
|
|||||||
def request(url, data=None, method=None, content_type='application/json'):
|
def request(url, data=None, method=None, content_type='application/json'):
|
||||||
endpoint = transport_url(url)
|
endpoint = transport_url(url)
|
||||||
headers = {'Authorization': 'token ' + os.environ['GITEA_TOKEN']}
|
headers = {'Authorization': 'token ' + os.environ['GITEA_TOKEN']}
|
||||||
if endpoint != url:
|
local_archive = (data is None and method in (None, 'GET')
|
||||||
|
and re.fullmatch(r'/api/v1/repos/[^/]+/[^/]+/actions/artifacts/\d+/zip',
|
||||||
|
urllib.parse.urlparse(url).path))
|
||||||
|
if endpoint != url and not local_archive:
|
||||||
# Gitea constructs response links from Host, even when reached locally.
|
# Gitea constructs response links from Host, even when reached locally.
|
||||||
|
# CI ZIP downloads redirect to a signed raw URL. Keep their local Host
|
||||||
|
# so urllib follows that redirect locally instead of returning to FRP.
|
||||||
headers['Host'] = 'git.orangraph.com'
|
headers['Host'] = 'git.orangraph.com'
|
||||||
if data is not None:
|
if data is not None:
|
||||||
headers['Content-Type'] = content_type
|
headers['Content-Type'] = content_type
|
||||||
|
|||||||
@@ -43,6 +43,36 @@ class TransferToolsTests(unittest.TestCase):
|
|||||||
self.assertEqual(result['sha256'], hashlib.sha256(b'app').hexdigest())
|
self.assertEqual(result['sha256'], hashlib.sha256(b'app').hexdigest())
|
||||||
self.assertEqual(asset['browser_download_url'], 'https://git.orangraph.com/attachments/example')
|
self.assertEqual(asset['browser_download_url'], 'https://git.orangraph.com/attachments/example')
|
||||||
|
|
||||||
|
def test_local_ci_archive_request_keeps_local_host_for_signed_redirect(self):
|
||||||
|
class Response(io.BytesIO):
|
||||||
|
headers = {'Content-Type': 'application/zip'}
|
||||||
|
|
||||||
|
with patch.dict('os.environ', {'CUTDEX_GITEA_INTERNAL_URL': 'http://127.0.0.1:3000',
|
||||||
|
'GITEA_TOKEN': 'test-token'}), \
|
||||||
|
patch.object(transfers.urllib.request, 'urlopen', return_value=Response(b'archive')) as open_url:
|
||||||
|
result = transfers.request(transfers.SERVER + '/api/v1/repos/owner/repo/actions/artifacts/40/zip')
|
||||||
|
request = open_url.call_args.args[0]
|
||||||
|
self.assertEqual(result, b'archive')
|
||||||
|
self.assertEqual(request.full_url, 'http://127.0.0.1:3000/api/v1/repos/owner/repo/actions/artifacts/40/zip')
|
||||||
|
self.assertIsNone(request.get_header('Host'))
|
||||||
|
self.assertEqual(request.get_header('Authorization'), 'token test-token')
|
||||||
|
|
||||||
|
def test_local_host_exception_does_not_change_other_api_response_links(self):
|
||||||
|
for path, method in [
|
||||||
|
('/api/v1/repos/owner/repo/actions/artifacts/40/zip', 'POST'),
|
||||||
|
('/api/v1/repos/owner/repo/actions/artifacts/not-a-number/zip', None),
|
||||||
|
('/api/v1/repos/owner/repo/releases/40/zip', None),
|
||||||
|
]:
|
||||||
|
class Response(io.BytesIO):
|
||||||
|
headers = {'Content-Type': 'application/json'}
|
||||||
|
|
||||||
|
with self.subTest(path=path, method=method), \
|
||||||
|
patch.dict('os.environ', {'CUTDEX_GITEA_INTERNAL_URL': 'http://127.0.0.1:3000',
|
||||||
|
'GITEA_TOKEN': 'test-token'}), \
|
||||||
|
patch.object(transfers.urllib.request, 'urlopen', return_value=Response(b'{}')) as open_url:
|
||||||
|
transfers.request(transfers.SERVER + path, method=method)
|
||||||
|
self.assertEqual(open_url.call_args.args[0].get_header('Host'), 'git.orangraph.com')
|
||||||
|
|
||||||
def test_local_transport_rejects_unexpected_endpoint_or_origin_before_sending_credentials(self):
|
def test_local_transport_rejects_unexpected_endpoint_or_origin_before_sending_credentials(self):
|
||||||
for internal, url, message in [
|
for internal, url, message in [
|
||||||
('http://example.com:3000', transfers.SERVER + '/api/v1/releases', 'internal Gitea endpoint'),
|
('http://example.com:3000', transfers.SERVER + '/api/v1/releases', 'internal Gitea endpoint'),
|
||||||
|
|||||||
Reference in new issue
Block a user