fix(release): reject tar listing errors before backup verification
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
"""Exercise deployment backup functions with synthetic commands; never deploy."""
|
||||
import os
|
||||
import io
|
||||
import gzip
|
||||
from pathlib import Path
|
||||
import shlex
|
||||
import shutil
|
||||
@@ -360,7 +361,7 @@ class BackupPermissionTests(unittest.TestCase):
|
||||
|
||||
|
||||
class BackupDatabaseMemberTests(unittest.TestCase):
|
||||
def verify_archive(self, member_name):
|
||||
def verify_archive(self, member_name, truncated_tar=False):
|
||||
source = (ROOT / 'deploy/deploy.sh').read_text(encoding='utf-8')
|
||||
functions = []
|
||||
for name in ['verify_backup_file_shape', 'verify_volume_backup']:
|
||||
@@ -369,18 +370,24 @@ class BackupDatabaseMemberTests(unittest.TestCase):
|
||||
with tempfile.TemporaryDirectory() as temporary:
|
||||
folder = Path(temporary)
|
||||
archive = folder / 'synthetic.tar.gz'
|
||||
with tarfile.open(archive, 'w:gz') as bundle:
|
||||
member = tarfile.TarInfo(member_name)
|
||||
member = tarfile.TarInfo(member_name)
|
||||
if truncated_tar:
|
||||
member.size = 4096
|
||||
with gzip.open(archive, 'wb') as bundle:
|
||||
bundle.write(member.tobuf())
|
||||
else:
|
||||
member.size = len(b'synthetic bytes')
|
||||
bundle.addfile(member, io.BytesIO(b'synthetic bytes'))
|
||||
with tarfile.open(archive, 'w:gz') as bundle:
|
||||
bundle.addfile(member, io.BytesIO(b'synthetic bytes'))
|
||||
script = '\n'.join([
|
||||
'set -euo pipefail',
|
||||
'BACKUP_DIR=' + shlex.quote(folder.as_posix()),
|
||||
'report_backup() { echo "FORMAT VERIFIED"; }',
|
||||
# Only replace the container mount prefix; run its actual tar/grep command.
|
||||
# Replace container-only paths; run its actual tar and grep commands.
|
||||
r'docker() { local argument script="${!#}"; '
|
||||
r'for argument in "$@"; do case "$argument" in ARCHIVE_NAME=*) export "$argument";; esac; done; '
|
||||
r'script="${script//\/backup\//./}"; (cd "$BACKUP_DIR" && sh -c "$script"); }',
|
||||
r'script="${script//\/backup\//./}"; script="${script//\/tmp\/backup-members/backup-members}"; '
|
||||
r'(cd "$BACKUP_DIR" && sh -c "$script"); }',
|
||||
*functions,
|
||||
'if ! verify_volume_backup "$BACKUP_DIR/synthetic.tar.gz"; then exit 1; fi',
|
||||
'echo "NEXT DEPLOY GATE WOULD START"',
|
||||
@@ -406,6 +413,12 @@ class BackupDatabaseMemberTests(unittest.TestCase):
|
||||
self.assertIn('FORMAT VERIFIED', result.stdout)
|
||||
self.assertIn('NEXT DEPLOY GATE WOULD START', result.stdout)
|
||||
|
||||
def test_valid_gzip_with_truncated_tar_database_member_is_rejected(self):
|
||||
result = self.verify_archive('jobtracker.db', truncated_tar=True)
|
||||
self.assertNotEqual(0, result.returncode, result.stdout + result.stderr)
|
||||
self.assertNotIn('FORMAT VERIFIED', result.stdout)
|
||||
self.assertNotIn('NEXT DEPLOY GATE WOULD START', result.stdout)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user