fix(ci): bootstrap pinned Node before checkout and align SDK locks
This commit is contained in:
1 parent
087161db76
commit
b6701fe30e
8 files changed
+118
-8
No files matched your search
@@ -2,7 +2,7 @@
|
||||
set -euo pipefail
|
||||
export DEBIAN_FRONTEND=noninteractive
|
||||
apt-get update -qq
|
||||
apt-get install -y --no-install-recommends ca-certificates curl git nodejs python3 unzip postgresql-client docker.io docker-compose-v2
|
||||
apt-get install -y --no-install-recommends ca-certificates curl git python3 unzip postgresql-client docker.io docker-compose-v2
|
||||
# Fail explicitly if a runner cannot provide the required Docker build service.
|
||||
docker version --format '{{.Server.Version}}'
|
||||
docker compose version
|
||||
|
||||
@@ -4,6 +4,8 @@ import sys
|
||||
|
||||
with open(sys.argv[1], encoding="utf-8") as report:
|
||||
data = json.load(report)
|
||||
if data.get("version") != 1 or not isinstance(data.get("projects"), list) or not data["projects"]:
|
||||
raise SystemExit("Invalid or empty NuGet advisory report")
|
||||
if data.get("problems"):
|
||||
raise SystemExit("NuGet advisory lookup failed; see retained report")
|
||||
findings = []
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
mkdir -p artifacts/security
|
||||
dotnet list Heimdall.slnx package --vulnerable --include-transitive --format json > artifacts/security/nuget.json
|
||||
dotnet list Heimdall.slnx package --no-restore --vulnerable --include-transitive --format json > artifacts/security/nuget.json
|
||||
status=0
|
||||
python3 scripts/ci/check-advisories.py artifacts/security/nuget.json || status=1
|
||||
sha=$(git rev-parse HEAD)
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
"""Contract tests for security gates and draft release uploads, without network."""
|
||||
import contextlib
|
||||
import io
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import runpy
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
ROOT = Path(__file__).resolve().parent
|
||||
|
||||
class AdvisoryTests(unittest.TestCase):
|
||||
def check(self, data):
|
||||
with tempfile.TemporaryDirectory() as temp:
|
||||
path = Path(temp)/'report.json'
|
||||
path.write_text(json.dumps(data))
|
||||
return subprocess.run([sys.executable, str(ROOT/'check-advisories.py'), str(path)],
|
||||
capture_output=True, text=True).returncode
|
||||
|
||||
def test_high_and_critical_transitive_advisories_fail(self):
|
||||
for severity in ('High', 'Critical'):
|
||||
report = {'version': 1, 'projects': [{'frameworks': [{'transitivePackages': [{
|
||||
'id': 'Example', 'vulnerabilities': [{'severity': severity, 'advisoryurl': 'https://example.test'}]
|
||||
}]}]}]}
|
||||
self.assertNotEqual(self.check(report), 0)
|
||||
|
||||
def test_clean_report_passes(self):
|
||||
self.assertEqual(self.check({'version': 1, 'projects': [{'frameworks': []}]}), 0)
|
||||
|
||||
def test_failed_empty_and_invalid_reports_fail_closed(self):
|
||||
for report in ({}, {'version': 1, 'projects': []},
|
||||
{'version': 1, 'projects': [{}], 'problems': [{'message': 'offline'}]}):
|
||||
self.assertNotEqual(self.check(report), 0)
|
||||
|
||||
class ReleaseTests(unittest.TestCase):
|
||||
def execute(self, public=False):
|
||||
calls = []
|
||||
class Response(io.BytesIO):
|
||||
def __enter__(self): return self
|
||||
def __exit__(self, *args): self.close()
|
||||
def fake_request(req, timeout):
|
||||
calls.append(req)
|
||||
if req.method == 'GET' and '/releases/tags/' in req.full_url:
|
||||
return Response(json.dumps({'id': 7, 'draft': not public,
|
||||
'html_url': 'https://example.test/releases/7'}).encode())
|
||||
if req.method == 'GET':
|
||||
return Response(b'[{"id":8}]')
|
||||
if req.method == 'DELETE': return Response(b'')
|
||||
return Response(b'{"id":9}')
|
||||
with tempfile.TemporaryDirectory() as temp:
|
||||
directory = Path(temp)/'artifacts/packages'
|
||||
directory.mkdir(parents=True)
|
||||
(directory/'provenance.json').write_text(json.dumps({'commit':'abc123','run_id':'42'}))
|
||||
(directory/'package.tar.gz').write_bytes(b'archive')
|
||||
original = Path.cwd()
|
||||
try:
|
||||
os.chdir(temp)
|
||||
with patch.dict(os.environ, {'BUILD_SERVER_URL':'https://example.test',
|
||||
'BUILD_REPOSITORY':'owner/repo','BUILD_REF':'refs/tags/v1.2.3','RELEASE_TOKEN':'dummy'}), \
|
||||
patch('urllib.request.urlopen', fake_request), contextlib.redirect_stdout(io.StringIO()):
|
||||
runpy.run_path(str(ROOT/'release-gitea.py'), run_name='__main__')
|
||||
finally:
|
||||
os.chdir(original)
|
||||
return calls
|
||||
|
||||
def test_draft_assets_use_multipart_and_delete_accepts_204(self):
|
||||
calls = self.execute()
|
||||
uploads = [x for x in calls if x.method == 'POST']
|
||||
self.assertEqual(len(uploads), 2)
|
||||
for request in uploads:
|
||||
self.assertTrue(request.get_header('Content-type').startswith('multipart/form-data; boundary='))
|
||||
self.assertIn(b'name="attachment"', request.data)
|
||||
self.assertEqual(sum(x.method == 'DELETE' for x in calls), 1)
|
||||
|
||||
def test_public_release_cannot_be_mutated(self):
|
||||
with self.assertRaisesRegex(SystemExit, 'already public'):
|
||||
self.execute(public=True)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user