25 lines
993 B
Python
25 lines
993 B
Python
|
|
import sys
|
||
|
|
import tempfile
|
||
|
|
import unittest
|
||
|
|
from pathlib import Path
|
||
|
|
from zipfile import ZipFile, BadZipFile
|
||
|
|
sys.path.insert(0,str(Path(__file__).resolve().parents[1]/'scripts'))
|
||
|
|
from capture_forgejo_archive import validate_archive
|
||
|
|
|
||
|
|
class ArchiveIntegrity(unittest.TestCase):
|
||
|
|
def test_complete_archive(self):
|
||
|
|
with tempfile.TemporaryDirectory() as d:
|
||
|
|
p=Path(d)/'backup.zip'
|
||
|
|
with ZipFile(p,'w') as z:
|
||
|
|
z.writestr('forgejo-db.sql','SELECT 1;')
|
||
|
|
z.writestr('repos/example.git/HEAD','ref: refs/heads/main')
|
||
|
|
validate_archive(p)
|
||
|
|
p.write_bytes(p.read_bytes()[:-22])
|
||
|
|
with self.assertRaises(BadZipFile): validate_archive(p)
|
||
|
|
|
||
|
|
def test_missing_database_rejected(self):
|
||
|
|
with tempfile.TemporaryDirectory() as d:
|
||
|
|
p=Path(d)/'backup.zip'
|
||
|
|
with ZipFile(p,'w') as z: z.writestr('repos/example.git/HEAD','x')
|
||
|
|
with self.assertRaises(ValueError): validate_archive(p)
|