Files
cutdex/tool/tests/public_repository_test.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

59 lines
2.4 KiB
Python

import importlib.util
from pathlib import Path
import tempfile
import unittest
SPEC = importlib.util.spec_from_file_location(
'public_repository', Path(__file__).resolve().parents[1] / 'check_public_repository.py')
CHECKER = importlib.util.module_from_spec(SPEC)
SPEC.loader.exec_module(CHECKER)
class PublicRepositoryTest(unittest.TestCase):
def setUp(self):
self.temporary = tempfile.TemporaryDirectory()
self.addCleanup(self.temporary.cleanup)
self.root = Path(self.temporary.name)
def write(self, name, text='local value'):
path = self.root / name
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text(text)
def test_credential_report_does_not_echo_secret(self):
secret = 'gh' + 'p_' + 'a' * 40
self.write('config.txt', 'token=' + secret)
errors = CHECKER.check_files(self.root, ['config.txt'])
self.assertEqual(len(errors), 1)
self.assertIn('config.txt:1', errors[0])
self.assertNotIn(secret, errors[0])
def test_local_inputs_are_rejected_but_examples_are_allowed(self):
names = ['.env', '.env.production', 'android/key.properties',
'.local/config.json', 'nested/build/output.txt',
'example.cutdex/project.json', 'signing.p12']
for name in names + ['.env.example', '.env.production.sample']:
self.write(name)
self.assertEqual(len(CHECKER.check_files(self.root, names)), len(names))
self.assertEqual(CHECKER.check_files(
self.root, ['.env.example', '.env.production.sample']), [])
def test_links_allow_urls_fragments_and_relative_files(self):
self.write('docs/guide.md', '[file](../LICENSE) [section](#intro) '
'[web](https://example.com) [missing](missing.md)')
self.write('LICENSE')
errors = CHECKER.check_files(self.root, ['docs/guide.md'])
self.assertEqual(errors, ['docs/guide.md: missing or external local link missing.md'])
def test_symlinks_cannot_publish_external_files(self):
(self.root / 'external').symlink_to(self.root.parent)
self.assertEqual(CHECKER.check_files(self.root, ['external']),
['external: symlink escapes repository'])
def test_deleted_worktree_file_is_not_published(self):
self.assertEqual(CHECKER.check_files(self.root, ['deleted.txt']), [])
if __name__ == '__main__':
unittest.main()