Move editor UI into the app and release verified Core dependencies (#14)
Gitea CI / Assemble and validate CI artifacts (push) Successful in 1m47s
Gitea CI / Check code and tests (push) Successful in 7m15s
Gitea CI / Build Android APK (push) Successful in 4m6s
Gitea CI / Build Windows x64 app (push) Successful in 3m34s
Gitea CI / Audit and package Windows x64 (push) Successful in 1m29s
Gitea CI / Gitea CI passed (push) Successful in 1s
Gitea Release / Prepare draft Release (push) Failing after 8s
Gitea Release / Upload Android to draft Release (push) Skipped
Gitea Release / Upload Windows to draft Release (push) Skipped
Gitea Release / Verify and publish Release (push) Skipped
Gitea CI / Assemble and validate CI artifacts (push) Successful in 1m47s
Gitea CI / Check code and tests (push) Successful in 7m15s
Gitea CI / Build Android APK (push) Successful in 4m6s
Gitea CI / Build Windows x64 app (push) Successful in 3m34s
Gitea CI / Audit and package Windows x64 (push) Successful in 1m29s
Gitea CI / Gitea CI passed (push) Successful in 1s
Gitea Release / Prepare draft Release (push) Failing after 8s
Gitea Release / Upload Android to draft Release (push) Skipped
Gitea Release / Upload Windows to draft Release (push) Skipped
Gitea Release / Verify and publish Release (push) Skipped
This commit was merged in pull request #14.
This commit is contained in:
1 parent
abc1868550
commit
06f1c26681
452 files changed
+43806
-2329
No files matched your search
@@ -0,0 +1,112 @@
|
||||
import copy
|
||||
import hashlib
|
||||
import io
|
||||
import json
|
||||
from pathlib import Path
|
||||
import tempfile
|
||||
from unittest.mock import patch
|
||||
import unittest
|
||||
import zipfile
|
||||
|
||||
from prepare_dependencies import extract_archive, prepare, release_archive, verify_archive
|
||||
|
||||
|
||||
class CoreSourceDependencyTests(unittest.TestCase):
|
||||
def test_local_gitea_response_links_use_verified_public_origin(self):
|
||||
_, pins = self.bundle()
|
||||
asset = {'name': pins['core']['artifact']['file'],
|
||||
'browser_download_url': 'http://git.orangraph.com/lingjhf/cutdex_core/releases/download/v0.0.1/cutdex-core-0.0.1.zip'}
|
||||
release = {'tag_name': 'v0.0.1', 'draft': False, 'prerelease': False, 'assets': [asset]}
|
||||
with patch('prepare_dependencies.request', side_effect=[release, b'archive']) as send:
|
||||
self.assertEqual(release_archive(pins), b'archive')
|
||||
self.assertEqual(send.call_args.args[0], asset['browser_download_url'].replace('http:', 'https:'))
|
||||
asset['browser_download_url'] = 'https://untrusted.example/archive.zip'
|
||||
with patch('prepare_dependencies.request', return_value=release), self.assertRaises(ValueError):
|
||||
release_archive(pins)
|
||||
|
||||
def bundle(self, extra=None):
|
||||
prefix = 'cutdex-core-0.0.1/'
|
||||
native = {'version': '0.0.1', 'source_commit': 'b' * 40, 'path': 'native_flutter',
|
||||
'platform_dependencies': {'schemaVersion': 1, 'platforms': {}}}
|
||||
files = {'RELEASE.json': json.dumps({'version': '0.0.1', 'source_commit': 'a' * 40,
|
||||
'native_flutter': native}),
|
||||
'pubspec.yaml': 'name: cutdex_core\nversion: 0.0.1\n',
|
||||
'native_flutter/pubspec.yaml': 'name: cutdex_native_flutter\nversion: 0.0.1\n',
|
||||
'native_flutter/native-dependencies.json': json.dumps(native['platform_dependencies']),
|
||||
'native-flutter-dependency.json': json.dumps({'repository': 'cutdex-native/cutdex_native_flutter',
|
||||
'revision': 'b' * 40, 'version': '0.0.1'}),
|
||||
'native_flutter/darwin/runtime/source.swift': 'source'}
|
||||
data = io.BytesIO()
|
||||
with zipfile.ZipFile(data, 'w') as archive:
|
||||
for name, body in files.items():
|
||||
archive.writestr(prefix + name, body)
|
||||
link = zipfile.ZipInfo(prefix + 'native_flutter/darwin/cutdex_native_flutter')
|
||||
link.external_attr = 0o120777 << 16
|
||||
archive.writestr(link, 'runtime')
|
||||
if extra:
|
||||
archive.writestr(extra[0], extra[1])
|
||||
body = data.getvalue()
|
||||
pins = {'schemaVersion': 1,
|
||||
'core': {'repository': 'lingjhf/cutdex_core', 'version': '0.0.1', 'ref': 'v0.0.1',
|
||||
'revision': 'a' * 40, 'artifact': {'file': 'cutdex-core-0.0.1.zip',
|
||||
'sha256': hashlib.sha256(body).hexdigest()}},
|
||||
'nativeFlutter': {'repository': 'cutdex-native/cutdex_native_flutter',
|
||||
'revision': 'b' * 40, 'version': '0.0.1', 'ref': 'v0.0.1'}}
|
||||
return body, pins
|
||||
|
||||
def test_exact_release_bundle_materializes_apple_alias_without_symlink_privileges(self):
|
||||
data, pins = self.bundle()
|
||||
prefix, manifest = verify_archive(data, pins)
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
root = Path(directory)
|
||||
extract_archive(data, prefix, root)
|
||||
self.assertEqual((root / 'native_flutter/darwin/cutdex_native_flutter/source.swift').read_text(), 'source')
|
||||
self.assertFalse((root / 'native_flutter/darwin/cutdex_native_flutter').is_symlink())
|
||||
self.assertEqual(manifest['native_flutter']['source_commit'], pins['nativeFlutter']['revision'])
|
||||
|
||||
def test_digest_core_commit_and_native_commit_mismatches_fail_before_extraction(self):
|
||||
data, pins = self.bundle()
|
||||
for package, field in [('core', 'revision'), ('nativeFlutter', 'revision'), ('nativeFlutter', 'repository')]:
|
||||
altered = copy.deepcopy(pins)
|
||||
altered[package][field] = 'old/native_flutter' if field == 'repository' else 'c' * 40
|
||||
with self.subTest(package=package), self.assertRaises(ValueError):
|
||||
verify_archive(data, altered)
|
||||
with self.assertRaisesRegex(ValueError, 'SHA256'):
|
||||
verify_archive(data + b'changed', pins)
|
||||
|
||||
def test_cached_archive_is_verified_and_extracted_fresh_for_retry(self):
|
||||
data, pins = self.bundle()
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
root = Path(directory)
|
||||
cache = root / 'cache'
|
||||
cache.mkdir()
|
||||
(cache / (pins['core']['artifact']['sha256'] + '.zip')).write_bytes(data)
|
||||
with patch.dict('os.environ', {'CUTDEX_CORE_ARCHIVE_CACHE': str(cache)}), patch('prepare_dependencies.release_archive') as fetch:
|
||||
prepare(pins, root)
|
||||
source = root / '.dependencies/cutdex_core/native_flutter/darwin/runtime/source.swift'
|
||||
source.write_text('local stale content')
|
||||
prepare(pins, root)
|
||||
self.assertEqual(source.read_text(), 'source')
|
||||
fetch.assert_not_called()
|
||||
|
||||
def test_development_checkout_is_never_removed_by_release_preparation(self):
|
||||
data, pins = self.bundle()
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
root = Path(directory)
|
||||
development = root / '.dependencies/cutdex_core'
|
||||
development.mkdir(parents=True)
|
||||
(development / '.git').mkdir()
|
||||
with patch('prepare_dependencies.release_archive', return_value=data), patch.dict('os.environ', {'CUTDEX_CORE_ARCHIVE_CACHE': str(root / 'cache')}):
|
||||
with self.assertRaisesRegex(ValueError, 'development'):
|
||||
prepare(pins, root)
|
||||
self.assertTrue((development / '.git').is_dir())
|
||||
|
||||
def test_archive_escape_and_duplicate_paths_are_rejected(self):
|
||||
for name in ['cutdex-core-0.0.1/../outside', 'cutdex-core-0.0.1/pubspec.yaml']:
|
||||
data, pins = self.bundle((name, 'unexpected'))
|
||||
with self.subTest(name=name), self.assertRaises(ValueError):
|
||||
verify_archive(data, pins)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user