LifeMate — Personal, Family & Learning Companion
feat/local-signing-preflight
chore/phase1-repository-cleanup
deploy/stable-web-apk
deployment-static
design/mobile-accessibility-v2
design/mobile-navigation-review
docs/child-education-access-decision
docs/offline-data-rescue-options
docs/owner-guide-and-delivery-plan
docs/phase1-policy-options
docs/public-review-live-2026-10-15
feat/aparat-learning-library
feat/child-device-safety
feat/child-identity-schema
feat/flutter-mobile-navigation
feat/learning-content-operations
feat/local-signing-preflight
feat/online-family-stage0
feat/personal-encrypted-recovery
feat/private-planner-series-api
feat/public-review-page
feat/standalone-weekly-planner
feat/weekly-planner-android
final-feature-1/iran-family-school
fix/auth-abuse-expiry-safety
fix/auth-expiry-after-lock
fix/backend-request-safety
fix/lifeguide-bootstrap-naming-ci
fix/lifeguide-pages-qa-base-preflight
fix/lifeguide-qa-pages-env-deployment
fix/local-task-persistence
fix/managed-child-session-boundary
fix/personal-jalali-dates
fix/personal-notification-controls
fix/personal-upgrade-delivery-guard
fix/sms-approval-gates
fix/study-duration-display
infra/cloudflare-neon-migration
infra/lifeguide-cloudflare-qa
infra/lifeguide-github-pages-qa
infra/lifeguide-supabase-qa
main
phase-1/foundation-completion
phase-2/product-foundation-identity
phase-3/planner-school-family-core
phase-4/ai-learning-wellbeing
phase-5/hardening-observability-release
test/android-reminder-acceptance
test/personal-notification-settings
test/personal-recovery-acceptance
test/role-entry-apk
| 1 | """Synthetic manifest contracts; no actual APK installation is inferred.""" |
| 2 | import tempfile |
| 3 | import unittest |
| 4 | from pathlib import Path |
| 5 | from unittest.mock import patch |
| 6 | from zipfile import ZipFile |
| 7 | |
| 8 | import check_personal_recovery_apk as subject |
| 9 | |
| 10 | |
| 11 | class RecoveryManifestTest(unittest.TestCase): |
| 12 | def setUp(self): |
| 13 | directory = tempfile.TemporaryDirectory() |
| 14 | self.addCleanup(directory.cleanup) |
| 15 | self.apk = Path(directory.name) / 'qa.apk' |
| 16 | with ZipFile(self.apk, 'w') as archive: |
| 17 | archive.writestr('AndroidManifest.xml', b'parser fixture') |
| 18 | self.tags = [ |
| 19 | ('manifest', {'package': 'ir.lifeguide.app.personal', 'versionCode': 10, |
| 20 | 'versionName': '0.7.2-recovery-qa.10'}), |
| 21 | ('application', {'label': 'آزمون بازیابی', 'debuggable': True, |
| 22 | 'allowBackup': False, 'usesCleartextTraffic': False}), |
| 23 | ('uses-sdk', {'minSdkVersion': 24, 'targetSdkVersion': 36}), |
| 24 | ('activity', {'name': 'ir.lifeguide.app.MainActivity', 'exported': True}), |
| 25 | ('receiver', {'name': 'ir.lifeguide.app.LocalReminderReceiver', 'exported': False}), |
| 26 | ('meta-data', {'name': 'ir.lifeguide.PERSONAL_RECOVERY_QA', 'value': True}), |
| 27 | ] + [('uses-permission', {'name': 'android.permission.' + name}) for name in |
| 28 | ('POST_NOTIFICATIONS', 'RECEIVE_BOOT_COMPLETED', 'SCHEDULE_EXACT_ALARM')] |
| 29 | |
| 30 | def check(self, code=None): |
| 31 | with patch.object(subject, 'manifest_tags', return_value=self.tags): |
| 32 | return subject.check(self.apk, expected_code=code) |
| 33 | |
| 34 | def test_exact_qa_identity_and_higher_version(self): |
| 35 | self.assertEqual(self.check()['versionCode'], 10) |
| 36 | self.tags[0][1].update(versionCode=11, versionName='0.7.2-recovery-qa.11') |
| 37 | self.assertEqual(self.check()['versionCode'], 11) |
| 38 | with self.assertRaises(ValueError): |
| 39 | self.check(10) |
| 40 | |
| 41 | def test_rejects_product_identity_permissions_and_missing_qa_marker(self): |
| 42 | for index, key, value in ((0, 'package', 'ir.lifeguide.app.device'), |
| 43 | (0, 'versionCode', 12), (1, 'label', 'لایفگاید'), |
| 44 | (1, 'debuggable', False), (1, 'allowBackup', True), |
| 45 | (1, 'usesCleartextTraffic', True), (2, 'targetSdkVersion', 35), |
| 46 | (2, 'minSdkVersion', 23), (3, 'name', '.MainActivity'), |
| 47 | (4, 'exported', True), (5, 'value', False)): |
| 48 | with self.subTest(key=key, value=value): |
| 49 | old = self.tags[index][1][key] |
| 50 | self.tags[index][1][key] = value |
| 51 | with self.assertRaises(ValueError): |
| 52 | self.check() |
| 53 | self.tags[index][1][key] = old |
| 54 | self.tags.append(('uses-permission', {'name': 'android.permission.INTERNET'})) |
| 55 | with self.assertRaises(ValueError): |
| 56 | self.check() |
| 57 | self.tags.pop() |
| 58 | self.tags.pop(5) |
| 59 | with self.assertRaises(ValueError): |
| 60 | self.check() |
| 61 | |
| 62 | def test_duplicate_critical_manifest_tags_refused(self): |
| 63 | self.tags.append(('manifest', self.tags[0][1].copy())) |
| 64 | with self.assertRaises(ValueError): |
| 65 | self.check() |
| 66 | |
| 67 | |
| 68 | def test_existing_profileinstaller_requires_exact_system_permission(self): |
| 69 | # Observed in the exact delivered original APK after baseline SHA check. |
| 70 | protected = {'name': 'androidx.profileinstaller.ProfileInstallReceiver', |
| 71 | 'permission': 'android.permission.DUMP', 'enabled': True, |
| 72 | 'exported': True, 'directBootAware': False} |
| 73 | self.tags.append(('receiver', protected)) |
| 74 | self.assertEqual(self.check()['result'], 'PASS') |
| 75 | for key, value in (('permission', None), ('permission', 'android.permission.INTERNET'), |
| 76 | ('name', 'unexpected.ExportedReceiver')): |
| 77 | original = protected[key] |
| 78 | protected[key] = value |
| 79 | with self.subTest(key=key, value=value), self.assertRaises(ValueError): |
| 80 | self.check() |
| 81 | protected[key] = original |
| 82 | |
| 83 | |
| 84 | if __name__ == '__main__': |
| 85 | unittest.main() |