def test_CheckApkAndApexKeysAvailable_invalidApexKeys(self):
        input_file = common.MakeTempFile(suffix='.zip')
        with zipfile.ZipFile(input_file, 'w') as input_zip:
            input_zip.writestr('SYSTEM/apex/Apex1.apex', "Apex1-content")
            input_zip.writestr('SYSTEM/apex/Apex2.apex', "Apex2-content")

        apk_key_map = {
            'Apex1.apex': 'key1',
            'Apex2.apex': 'key2',
            'Apex3.apex': 'key3',
        }
        apex_keys = {
            'Apex1.apex': ('payload-key1', 'container-key1'),
            'Apex2.apex': ('payload-key2', 'container-key2'),
        }
        with zipfile.ZipFile(input_file) as input_zip:
            CheckApkAndApexKeysAvailable(input_zip, apk_key_map, None,
                                         apex_keys)

            # Fine to have both keys as PRESIGNED.
            apex_keys['Apex2.apex'] = ('PRESIGNED', 'PRESIGNED')
            CheckApkAndApexKeysAvailable(input_zip, apk_key_map, None,
                                         apex_keys)

            # Having only one of them as PRESIGNED is not allowed.
            apex_keys['Apex2.apex'] = ('payload-key2', 'PRESIGNED')
            self.assertRaises(AssertionError, CheckApkAndApexKeysAvailable,
                              input_zip, apk_key_map, None, apex_keys)

            apex_keys['Apex2.apex'] = ('PRESIGNED', 'container-key1')
            self.assertRaises(AssertionError, CheckApkAndApexKeysAvailable,
                              input_zip, apk_key_map, None, apex_keys)
    def test_CheckApkAndApexKeysAvailable(self):
        input_file = common.MakeTempFile(suffix='.zip')
        with zipfile.ZipFile(input_file, 'w') as input_zip:
            input_zip.writestr('SYSTEM/app/App1.apk', "App1-content")
            input_zip.writestr('SYSTEM/app/App2.apk.gz', "App2-content")

        apk_key_map = {
            'App1.apk': 'key1',
            'App2.apk': 'key2',
            'App3.apk': 'key3',
        }
        with zipfile.ZipFile(input_file) as input_zip:
            CheckApkAndApexKeysAvailable(input_zip, apk_key_map, None, {})
            CheckApkAndApexKeysAvailable(input_zip, apk_key_map, '.gz', {})

            # 'App2.apk.gz' won't be considered as an APK.
            CheckApkAndApexKeysAvailable(input_zip, apk_key_map, None, {})
            CheckApkAndApexKeysAvailable(input_zip, apk_key_map, '.xz', {})

            del apk_key_map['App2.apk']
            self.assertRaises(AssertionError, CheckApkAndApexKeysAvailable,
                              input_zip, apk_key_map, '.gz', {})