Files
cutdex/tool/windows/test_windows_updates_unit.py
T
lingjhf 27e77fff39 feat: initial Cutdex application
Add the Flutter video editing application with project management, media
import, timeline editing, preview, AI assistance, diagnostics and settings.

Include shared UI and native host packages, platform runners, application
tests and release tooling.

Provide usage and contribution guides, the MIT license and third-party
notices. Exclude local credentials, build outputs and validation data.
2026-10-05 23:36:23 +08:00

122 lines
5.8 KiB
Python

import hashlib
import json
from pathlib import Path
from unittest.mock import patch
import tempfile
import unittest
from windows_updates import resolved_deskup, numeric_version, pack_release, update_version, validate_previous, verify_manifest
class UpdatePublicationTests(unittest.TestCase):
def test_deskup_is_located_from_resolved_package_config(self):
with tempfile.TemporaryDirectory(prefix='deskup package ') as directory:
root = Path(directory)
config = root / '.dart_tool/package_config.json'
config.parent.mkdir()
package = root / 'cache/deskup-0.1.0'
for uri in ['../cache/deskup-0.1.0/', package.as_uri() + '/']:
config.write_text(json.dumps({'packages': [
{'name': 'deskup', 'rootUri': uri},
]}), encoding='utf-8')
with patch('windows_updates.ROOT', root):
self.assertEqual(resolved_deskup().resolve(), package.resolve())
def test_missing_package_config_requests_pub_get(self):
with tempfile.TemporaryDirectory() as directory:
with patch('windows_updates.ROOT', Path(directory)):
with self.assertRaisesRegex(ValueError, 'flutter pub get'):
resolved_deskup()
def test_display_version_conversion_is_shared_and_ordered(self):
self.assertEqual(update_version('1.2.3', '42'), '1.2.3-build.42')
self.assertEqual(update_version('1.2.3', '0042'), '1.2.3-build.42')
for version, build in [('1.2', 1), ('1.2.3', -1), ('1.2.3', 'beta')]:
with self.assertRaises(ValueError):
update_version(version, build)
def test_invalid_pack_version_never_starts_vpk(self):
with patch('windows_updates.subprocess.run') as run:
with self.assertRaises(ValueError):
pack_release(['vpk'], app=Path('app'), output=Path('release'),
package_id='Cutdex', version='1.0.0.42', title='Cutdex')
run.assert_not_called()
def test_build_number_participates_in_version_order(self):
self.assertLess(numeric_version('1.0.0-build.1'), numeric_version('1.0.0-build.2'))
self.assertLess(numeric_version('1.0.0-build.9'), numeric_version('1.0.0-build.10'))
self.assertLess(numeric_version('1.0.0-build.999'), numeric_version('1.0.1-build.1'))
self.assertLess(numeric_version('1.0.0-build.999'), numeric_version('1.0.0'))
for version in ['1.0', '1.0.0+2', '1.0.0.2', '1.0.0-build.02', '1.0.0-beta', '../1.0.0']:
with self.assertRaises(ValueError):
numeric_version(version)
def test_reused_build_and_mixed_identity_are_rejected(self):
with tempfile.TemporaryDirectory() as directory:
root = Path(directory)
(root / 'releases.win-x64.json').write_text(json.dumps({
'Assets': [{'PackageId': 'Cutdex', 'Version': '1.0.0-build.2'}]}))
for candidate in ['1.0.0-build.1', '1.0.0-build.2']:
with self.assertRaises(ValueError):
validate_previous(root, 'Cutdex', candidate)
with self.assertRaises(ValueError):
validate_previous(root, 'Cutdex.Dev', '1.0.0-build.3')
validate_previous(root, 'Cutdex', '1.0.0-build.3')
def test_post_audit_tampering_and_added_files_are_rejected(self):
with tempfile.TemporaryDirectory() as directory:
root = Path(directory)
(root / 'cutdex.exe').write_bytes(b'app')
(root / 'processing').mkdir()
(root / 'processing/checksums.json').write_text('{}')
manifest = {name: hashlib.sha256((root / name).read_bytes()).hexdigest()
for name in ['cutdex.exe', 'processing/checksums.json']}
(root / 'checksums.json').write_text(json.dumps(manifest))
verify_manifest(root)
(root / 'cutdex.exe').write_bytes(b'changed')
with self.assertRaises(ValueError):
verify_manifest(root)
(root / 'cutdex.exe').write_bytes(b'app')
(root / 'injected.dll').write_bytes(b'new')
with self.assertRaises(ValueError):
verify_manifest(root)
def test_escaping_manifest_path_is_rejected(self):
with tempfile.TemporaryDirectory() as directory:
root = Path(directory)
(root / 'checksums.json').write_text(json.dumps({'../outside.exe': '0' * 64}))
with self.assertRaises(ValueError):
verify_manifest(root)
def test_relative_staging_directory_is_normalized(self):
with tempfile.TemporaryDirectory(dir=Path.cwd()) as directory:
root = Path(directory).relative_to(Path.cwd())
(root / 'cutdex.exe').write_bytes(b'app')
(root / 'checksums.json').write_text(json.dumps({
'cutdex.exe': hashlib.sha256(b'app').hexdigest(),
}))
verify_manifest(root)
def test_symlink_inside_staging_directory_is_rejected(self):
with tempfile.TemporaryDirectory() as directory:
root = Path(directory)
original = root / 'cutdex.exe'
original.write_bytes(b'app')
try:
(root / 'linked.exe').symlink_to(original)
except OSError as error:
if getattr(error, 'winerror', None) != 1314:
raise
self.skipTest(f'Symlinks unavailable: {error}')
digest = hashlib.sha256(b'app').hexdigest()
(root / 'checksums.json').write_text(json.dumps({
'cutdex.exe': digest,
'linked.exe': digest,
}))
with self.assertRaisesRegex(ValueError, 'Invalid manifest path'):
verify_manifest(root)
if __name__ == '__main__':
unittest.main()