def test_ApexApkSigner_signApk(self): apex_path = os.path.join(self.testdata_dir, 'has_apk.apex') signer = apex_utils.ApexApkSigner(apex_path, None, None) apk_keys = { 'wifi-service-resources.apk': os.path.join(self.testdata_dir, 'testkey') } self.payload_key = os.path.join(self.testdata_dir, 'testkey_RSA4096.key') payload_pubkey = common.ExtractAvbPublicKey('avbtool', self.payload_key) signer.ProcessApexFile(apk_keys, self.payload_key, payload_pubkey)
def test_ApexApkSigner_noAssetDir(self): no_asset = common.MakeTempFile(suffix='.apex') with zipfile.ZipFile(no_asset, 'w') as output_zip: with zipfile.ZipFile(self.apex_with_apk, 'r') as input_zip: name_list = input_zip.namelist() for name in name_list: if not name.startswith('assets'): output_zip.writestr(name, input_zip.read(name)) signer = apex_utils.ApexApkSigner(no_asset, None, None) apk_keys = { 'wifi-service-resources.apk': os.path.join(self.testdata_dir, 'testkey') } self.payload_key = os.path.join(self.testdata_dir, 'testkey_RSA4096.key') signer.ProcessApexFile(apk_keys, self.payload_key)
def test_ApexApkSigner_invokesCustomSignTool(self): apex_path = common.MakeTempFile(suffix='.apex') shutil.copy(self.apex_with_apk, apex_path) apk_keys = { 'wifi-service-resources.apk': os.path.join(self.testdata_dir, 'testkey') } self.payload_key = os.path.join(self.testdata_dir, 'testkey_RSA4096.key') # pass `false` as a sign_tool to see the invocation error with self.assertRaises(common.ExternalError) as cm: signer = apex_utils.ApexApkSigner(apex_path, None, None, sign_tool='false') signer.ProcessApexFile(apk_keys, self.payload_key) the_exception = cm.exception self.assertIn('Failed to run command \'[\'false\'', str(the_exception))
def test_ApexApkSigner_signApk(self): apex_path = common.MakeTempFile(suffix='.apex') shutil.copy(self.apex_with_apk, apex_path) signer = apex_utils.ApexApkSigner(apex_path, None, None) apk_keys = { 'wifi-service-resources.apk': os.path.join(self.testdata_dir, 'testkey') } self.payload_key = os.path.join(self.testdata_dir, 'testkey_RSA4096.key') apex_file = signer.ProcessApexFile(apk_keys, self.payload_key) package_name_extract_cmd = ['aapt2', 'dump', 'badging', apex_file] output = common.RunAndCheckOutput(package_name_extract_cmd) for line in output.splitlines(): # Sample output from aapt: "package: name='com.google.android.wifi' # versionCode='1' versionName='' platformBuildVersionName='R' # compileSdkVersion='29' compileSdkVersionCodename='R'" match = re.search(r"^package:.* name='([\w|\.]+)'", line, re.IGNORECASE) if match: package_name = match.group(1) self.assertEquals('com.google.android.wifi', package_name)
def test_ApexApkSigner_apkKeyNotPresent(self): apex_path = common.MakeTempFile(suffix='.apex') shutil.copy(self.apex_with_apk, apex_path) signer = apex_utils.ApexApkSigner(apex_path, None, None) self.assertRaises(apex_utils.ApexSigningError, signer.ProcessApexFile, {}, self.payload_key)
def test_ApexApkSigner_noApkPresent(self): apex_path = os.path.join(self.testdata_dir, 'foo.apex') signer = apex_utils.ApexApkSigner(apex_path, None, None) processed_apex = signer.ProcessApexFile({}, self.payload_key) self.assertEqual(apex_path, processed_apex)
def test_ApexApkSigner_apkKeyNotPresent(self): apex_path = os.path.join(self.testdata_dir, 'has_apk.apex') signer = apex_utils.ApexApkSigner(apex_path, None, None) self.assertRaises(apex_utils.ApexSigningError, signer.ProcessApexFile, {}, self.payload_key, None)