Beispiel #1
0
 def test_version_newer_avail(self):
     with GetStorage(get_connection_api()) as storage:
         package_downloader = APKWizard(storage.db_wrapper,
                                        storage.storage_manager)
         gplay_latest = (20201001, "0.123.4")
         latest_supported = {
             APKArch.arm64_v8a: {
                 "versionCode": 20201001,
                 "version": "0.123.4"
             }
         }
         autosearch_latest = {"version": "0.123.4", "url": 20201001}
         package_downloader.get_latest_version = MagicMock(
             return_value=latest_supported)
         storage.storage_manager.get_current_version = MagicMock(
             return_value="0.123.3")
         package_downloader.get_latest = MagicMock(
             return_value=autosearch_latest)
         GPlayConnector.get_latest_version = MagicMock(
             return_value=gplay_latest)
         wizard_latest = package_downloader.find_latest_pogo(
             APKArch.arm64_v8a)
         self.assertTrue(wizard_latest is not None)
         self.assertTrue(latest_supported[APKArch.arm64_v8a]["versionCode"]
                         == wizard_latest["version_code"])
         self.assertTrue(latest_supported[APKArch.arm64_v8a]["version"] ==
                         wizard_latest["version"])
Beispiel #2
0
 def test_version_supported_but_not_gplay(self):
     with GetStorage(get_connection_api()) as storage:
         wizard = APKWizard(storage.db_wrapper, storage.storage_manager)
         gplay_latest = (20200901, "0.123.3")
         latest_supported = {
             APKArch.arm64_v8a: {
                 "versionCode": 20201001,
                 "version": "0.123.4"
             }
         }
         autosearch_latest = {"version": "0.123.4", "url": 20201001}
         wizard.get_latest_version = MagicMock(
             return_value=latest_supported)
         storage.storage_manager.get_current_version = MagicMock(
             return_value="0.123.3")
         wizard.get_latest = MagicMock(return_value=autosearch_latest)
         GPlayConnector.get_latest_version = MagicMock(
             return_value=gplay_latest)
         wizard_latest = wizard.find_latest_pogo(APKArch.arm64_v8a)
         self.assertTrue(wizard_latest is None)
Beispiel #3
0
 def test_valid_version_from_gplay(self, get_apk_info):
     latest_gplay = {"version_code": 20200901, "version": "0.123.4"}
     autosearch_latest = {"version": "0.123.4", "url": 20201001}
     get_apk_info_resp = ("0.123.4", "com.ignored")
     get_apk_info.return_value = get_apk_info_resp
     with GetStorage(get_connection_api()) as storage:
         package_downloader = APKWizard(storage.db_wrapper,
                                        storage.storage_manager)
         package_downloader.find_latest_pogo = MagicMock(
             return_value=latest_gplay)
         storage.storage_manager.get_current_version = MagicMock(
             return_value="0.123.3")
         package_downloader.get_latest = MagicMock(
             return_value=autosearch_latest)
         GPlayConnector.download = MagicMock(
             return_value=TEST_GPLAY_RESPONSE)
         package_downloader.download_pogo(APKArch.arm64_v8a)
Beispiel #4
0
 def test_invalid_version_from_gplay(self, get_apk_info, supported_pogo_version):
     supported_pogo_version.return_value = True
     get_apk_info.return_value = ("0.123.3", "com.ignored")
     latest_gplay = {
         "version_code": 20200901,
         "version": "0.123.4"
     }
     autosearch_latest = {
         "version": "0.123.4",
         "url": 20201001
     }
     with GetStorage(get_connection_api()) as storage:
         package_downloader = APKWizard(storage.db_wrapper, storage.storage_manager)
         package_downloader.find_latest_pogo = MagicMock(return_value=latest_gplay)
         storage.storage_manager.get_current_version = MagicMock(return_value=None)
         package_downloader.get_latest = MagicMock(return_value=autosearch_latest)
         GPlayConnector.download = MagicMock(return_value=TEST_GPLAY_RESPONSE)
         with self.assertRaises(InvalidDownload):
             package_downloader.download_pogo(APKArch.arm64_v8a)
Beispiel #5
0
 def test_gplay_between_current_and_supported(self, supported_pogo_version):
     supported_pogo_version.return_value = True
     with GetStorage(get_connection_api()) as storage:
         package_downloader = APKWizard(storage.db_wrapper, storage.storage_manager)
         gplay_latest = (20200901, "0.123.3")
         latest_supported = {
             APKArch.arm64_v8a: {
                 "versionCode": 20201001,
                 "version": "0.123.4"
             }
         }
         autosearch_latest = {
             "version": "0.123.4",
             "url": 20201001
         }
         package_downloader.get_latest_version = MagicMock(return_value=latest_supported)
         package_downloader.get_version_code = MagicMock(return_value=20200801)
         storage.storage_manager.get_current_version = MagicMock(return_value="0.123.2")
         package_downloader.get_latest = MagicMock(return_value=autosearch_latest)
         GPlayConnector.get_latest_version = MagicMock(return_value=gplay_latest)
         wizard_latest = package_downloader.find_latest_pogo(APKArch.arm64_v8a)
         self.assertTrue(wizard_latest is not None)
         self.assertTrue(gplay_latest[0] == wizard_latest["version_code"])
         self.assertTrue(gplay_latest[1] == wizard_latest["version"])
Beispiel #6
0
    def post(self, apk_type: APK_Type, apk_arch: APK_Arch):
        is_upload: bool = False
        apk: io.BytesIO = None
        filename: str = None
        if 'multipart/form-data' in self.api_req.content_type:
            filename = self.api_req.data['data'].get('filename', None)
            try:
                apk = io.BytesIO(self.api_req.data['files'].get('file').read())
            except AttributeError:
                return ('No file present', 406)
            is_upload = True
        if self.api_req.content_type == 'application/octet-stream':
            filename = self.api_req.headers.get('filename', None)
            apk = io.BytesIO(self.api_req.data)
            is_upload = True
        if is_upload:
            if filename is None:
                return ('filename must be specified', 406)
            elems: MAD_APKS = get_apk_status(self.storage_obj)
            try:
                elems[apk_type][apk_arch]
            except KeyError:
                return ('Non-supported Type / Architecture', 406)
            filename_split = filename.rsplit('.', 1)
            if filename_split[1] in ['zip', 'apks']:
                mimetype = 'application/zip'
            elif filename_split[1] == 'apk':
                mimetype = 'application/vnd.android.package-archive'
            else:
                return ('Unsupported extension', 406)
            try:
                PackageImporter(apk_type, apk_arch, self.storage_obj, apk,
                                mimetype)
                if 'multipart/form-data' in self.api_req.content_type:
                    return flask.redirect(None, code=201)
                return (None, 201)
            except (BadZipFile, LargeZipFile) as err:
                return (str(err), 406)
            except WizardError as err:
                self._logger.warning(str(err))
                return (str(err), 406)
            except Exception:
                self._logger.opt(
                    exception=True).critical("An unhanded exception occurred!")
                return (None, 500)
        else:
            try:
                call = self.api_req.data['call']
                wizard = APKWizard(self.dbc, self.storage_obj)
                if call == 'import':
                    thread_args = (apk_type, apk_arch)
                    t = Thread(target=wizard.apk_download, args=thread_args)
                    t.start()
                    return (None, 204)
                elif call == 'search':
                    wizard.apk_search(apk_type, apk_arch)
                    return (None, 204)
                elif call == 'search_download':
                    try:
                        wizard.apk_all_actions()
                        return (None, 204)
                    except TypeError:
                        return (None, 404)
                else:
                    return (call, 501)
            except KeyError:
                import traceback
                traceback.print_exc()
                return (call, 501)

        return (None, 500)