telegram-mcp/tests/test_export.py
2026-11-05 14:26:28 +03:00

38 lines
1.8 KiB
Python

"""Public source export must not silently include runtime artifacts."""
from pathlib import Path
import sys
import tempfile
import unittest
from unittest.mock import patch
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / 'scripts'))
import export_source
class SourceExportContracts(unittest.TestCase):
def test_unexpected_file_is_rejected(self):
with tempfile.TemporaryDirectory() as tmp:
root=Path(tmp)
(root/'code').mkdir()
(root/'code'/'account.session').write_text('synthetic')
with patch.object(export_source,'ROOT',root), patch.object(export_source,'FILES',[]), patch.object(export_source,'DIRECTORIES',['code']):
with self.assertRaises(ValueError):export_source.source_files()
def test_symlink_is_rejected(self):
with tempfile.TemporaryDirectory() as tmp:
root=Path(tmp)
(root/'code').mkdir()
(root/'private').write_text('synthetic')
(root/'code'/'innocent.py').symlink_to(root/'private')
with patch.object(export_source,'ROOT',root), patch.object(export_source,'FILES',[]), patch.object(export_source,'DIRECTORIES',['code']):
with self.assertRaises(ValueError):export_source.source_files()
def test_secret_finding_never_prints_value(self):
with tempfile.TemporaryDirectory() as tmp:
root=Path(tmp)
path=root/'fixture.py'
token='123456789'+':'+'a'*35
path.write_text('token = '+repr(token))
with patch.object(export_source,'ROOT',root):
with self.assertRaises(ValueError) as caught:export_source.validate([path])
self.assertNotIn(token,str(caught.exception))
self.assertIn('bot-token',str(caught.exception))