#!/usr/bin/env python3 """ Release Packaging and Distribution Test Suite Verifies that release_folder contains exactly SlopRoot.apk and sources.tar.gz, that SlopRoot.apk passes multi-scheme cryptographic verification, and that sources.tar.gz contains only clean source files without git or build artifacts. """ import os import tarfile import unittest import subprocess BASE_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), "..")) RELEASE_DIR = os.path.join(BASE_DIR, "release_folder") APKSIGNER = os.path.join(BASE_DIR, "android-sdk/build-tools/35.0.0/apksigner") class TestReleasePackage(unittest.TestCase): def setUp(self): self.assertTrue(os.path.isdir(RELEASE_DIR), "release_folder directory must exist") def test_release_folder_contains_only_two_files(self): """Verify that release_folder contains exactly SlopRoot.apk and sources.tar.gz.""" entries = sorted(os.listdir(RELEASE_DIR)) self.assertEqual(entries, ["SlopRoot.apk", "sources.tar.gz"], f"release_folder must contain exactly SlopRoot.apk and sources.tar.gz. Found: {entries}") def test_sloproot_apk_integrity_and_signing(self): """Verify that SlopRoot.apk exists, has adequate size, and verifies with apksigner.""" apk_path = os.path.join(RELEASE_DIR, "SlopRoot.apk") self.assertTrue(os.path.isfile(apk_path)) apk_size = os.path.getsize(apk_path) self.assertGreater(apk_size, 500 * 1024, f"SlopRoot.apk size ({apk_size} bytes) is suspiciously small") # Verify cryptographic signatures res = subprocess.run([APKSIGNER, "verify", "--verbose", apk_path], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) self.assertEqual(res.returncode, 0, f"apksigner verification failed: {res.stderr}") self.assertIn("Verified using v1 scheme (JAR signing): true", res.stdout) self.assertIn("Verified using v2 scheme (APK Signature Scheme v2): true", res.stdout) self.assertIn("Verified using v3 scheme (APK Signature Scheme v3): true", res.stdout) def test_sources_archive_contents_clean(self): """Verify that sources.tar.gz is a valid tar archive without git, binaries, or build clutter.""" tar_path = os.path.join(RELEASE_DIR, "sources.tar.gz") self.assertTrue(os.path.isfile(tar_path)) tar_size = os.path.getsize(tar_path) self.assertGreater(tar_size, 20 * 1024, f"sources.tar.gz size ({tar_size} bytes) is too small") with tarfile.open(tar_path, "r:gz") as tar: members = tar.getnames() self.assertGreater(len(members), 20, "sources.tar.gz contains too few files") # Check for banned directories/patterns banned_substrings = [".git/", "release_folder/", "android-sdk/", "avd/", "__pycache__", ".pyc"] for name in members: for banned in banned_substrings: self.assertNotIn(banned, name, f"Banned path '{banned}' found in sources.tar.gz entry: {name}") # Verify essential source files exist in archive essential_files = [ "./app/AndroidManifest.xml", "./app/src/org/sloproot/MainActivity.java", "./app/native/dirtycow.c", "./app/native/su/su.c", "./sumanager/AndroidManifest.xml", "./sumanager/src/org/sloproot/sumanager/MainActivity.java", "./release.sh", "./README.md", "./JOURNAL.md" ] for essential in essential_files: self.assertIn(essential, members, f"Essential file '{essential}' missing from sources.tar.gz") if __name__ == "__main__": unittest.main()