Files
ServerKit/backend/tests/test_upload_extract.py
Juan Denis 45bc3c70bd Guard first admin with a setup code, fix Git deploys
A fresh panel no longer lets whoever reaches it first become admin:
registering the first account needs a one-time code the installer
prints (`serverkit setup-code` repeats it). SERVERKIT_ADMIN_EMAIL and
SERVERKIT_ADMIN_PASSWORD create the admin unattended instead.

Git apps now deploy what users expect: a repository with a compose
file deploys every service it declares, "Deploy latest" builds the
branch's newest commit, and push webhooks rebuild the containers.
Also fixes branch switching on single-branch clones, uploads of a
lone file, compose v1 port preflight, and CLI commands that ignored
their flags.
2026-09-24 00:50:02 -04:00

36 lines
1.5 KiB
Python

"""extract_version: what an uploaded archive becomes on disk."""
import zipfile
from app.services.upload_service import extract_version
def _zip(path, entries):
with zipfile.ZipFile(path, 'w') as archive:
for name, content in entries.items():
archive.writestr(name, content)
return str(path)
def test_single_file_archive_keeps_its_file(tmp_path):
# Found by a deploy benchmark (2026-09-24): a zip
# holding only docker-compose.yml extracted to an empty directory.
archive = _zip(tmp_path / 'app.zip', {'docker-compose.yml': 'services: {}\n'})
version_dir = extract_version(str(tmp_path / 'app'), archive, 1)
assert (tmp_path / 'app' / 'versions' / 'v1' / 'docker-compose.yml').read_text() == 'services: {}\n'
assert version_dir.endswith('v1')
def test_wrapper_folder_is_stripped(tmp_path):
archive = _zip(tmp_path / 'app.zip', {'site/': '', 'site/index.html': 'hi', 'site/css/a.css': 'x'})
extract_version(str(tmp_path / 'app'), archive, 1)
root = tmp_path / 'app' / 'versions' / 'v1'
assert (root / 'index.html').read_text() == 'hi'
assert (root / 'css' / 'a.css').read_text() == 'x'
def test_flat_archive_extracts_as_is(tmp_path):
archive = _zip(tmp_path / 'app.zip', {'index.html': 'hi', 'docker-compose.yml': 'services: {}\n'})
extract_version(str(tmp_path / 'app'), archive, 1)
root = tmp_path / 'app' / 'versions' / 'v1'
assert sorted(p.name for p in root.iterdir()) == ['docker-compose.yml', 'index.html']