Tao Bao | 481bab8 | 2017-12-21 11:23:09 -0800 | [diff] [blame] | 1 | # |
| 2 | # Copyright (C) 2018 The Android Open Source Project |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | # |
| 16 | |
| 17 | import copy |
Tao Bao | c7b403a | 2018-01-30 18:19:04 -0800 | [diff] [blame] | 18 | import os |
Tao Bao | fabe083 | 2018-01-17 15:52:28 -0800 | [diff] [blame] | 19 | import os.path |
Tao Bao | c7b403a | 2018-01-30 18:19:04 -0800 | [diff] [blame] | 20 | import zipfile |
Tao Bao | 481bab8 | 2017-12-21 11:23:09 -0800 | [diff] [blame] | 21 | |
| 22 | import common |
Tao Bao | 04e1f01 | 2018-02-04 12:13:35 -0800 | [diff] [blame] | 23 | import test_utils |
Tao Bao | 481bab8 | 2017-12-21 11:23:09 -0800 | [diff] [blame] | 24 | from ota_from_target_files import ( |
Tao Bao | 1c320f8 | 2019-10-04 23:25:12 -0700 | [diff] [blame] | 25 | _LoadOemDicts, AbOtaPropertyFiles, FinalizeMetadata, |
Tao Bao | 3bf8c65 | 2018-03-16 12:59:42 -0700 | [diff] [blame] | 26 | GetPackageMetadata, GetTargetFilesZipForSecondaryImages, |
Tao Bao | c0746f4 | 2018-02-21 13:17:22 -0800 | [diff] [blame] | 27 | GetTargetFilesZipWithoutPostinstallConfig, NonAbOtaPropertyFiles, |
Tao Bao | 6920352 | 2018-03-08 16:09:01 -0800 | [diff] [blame] | 28 | Payload, PayloadSigner, POSTINSTALL_CONFIG, PropertyFiles, |
| 29 | StreamingPropertyFiles, WriteFingerprintAssertion) |
Tao Bao | fabe083 | 2018-01-17 15:52:28 -0800 | [diff] [blame] | 30 | |
| 31 | |
Tao Bao | f7140c0 | 2018-01-30 17:09:24 -0800 | [diff] [blame] | 32 | def construct_target_files(secondary=False): |
| 33 | """Returns a target-files.zip file for generating OTA packages.""" |
| 34 | target_files = common.MakeTempFile(prefix='target_files-', suffix='.zip') |
| 35 | with zipfile.ZipFile(target_files, 'w') as target_files_zip: |
| 36 | # META/update_engine_config.txt |
| 37 | target_files_zip.writestr( |
| 38 | 'META/update_engine_config.txt', |
| 39 | "PAYLOAD_MAJOR_VERSION=2\nPAYLOAD_MINOR_VERSION=4\n") |
| 40 | |
Tao Bao | 15a146a | 2018-02-21 16:06:59 -0800 | [diff] [blame] | 41 | # META/postinstall_config.txt |
| 42 | target_files_zip.writestr( |
| 43 | POSTINSTALL_CONFIG, |
| 44 | '\n'.join([ |
| 45 | "RUN_POSTINSTALL_system=true", |
| 46 | "POSTINSTALL_PATH_system=system/bin/otapreopt_script", |
| 47 | "FILESYSTEM_TYPE_system=ext4", |
| 48 | "POSTINSTALL_OPTIONAL_system=true", |
| 49 | ])) |
| 50 | |
Tao Bao | 5277d10 | 2018-04-17 23:47:21 -0700 | [diff] [blame] | 51 | ab_partitions = [ |
| 52 | ('IMAGES', 'boot'), |
| 53 | ('IMAGES', 'system'), |
| 54 | ('IMAGES', 'vendor'), |
| 55 | ('RADIO', 'bootloader'), |
| 56 | ('RADIO', 'modem'), |
| 57 | ] |
Tao Bao | f7140c0 | 2018-01-30 17:09:24 -0800 | [diff] [blame] | 58 | # META/ab_partitions.txt |
Tao Bao | f7140c0 | 2018-01-30 17:09:24 -0800 | [diff] [blame] | 59 | target_files_zip.writestr( |
| 60 | 'META/ab_partitions.txt', |
Tao Bao | 5277d10 | 2018-04-17 23:47:21 -0700 | [diff] [blame] | 61 | '\n'.join([partition[1] for partition in ab_partitions])) |
Tao Bao | f7140c0 | 2018-01-30 17:09:24 -0800 | [diff] [blame] | 62 | |
| 63 | # Create dummy images for each of them. |
Tao Bao | 5277d10 | 2018-04-17 23:47:21 -0700 | [diff] [blame] | 64 | for path, partition in ab_partitions: |
| 65 | target_files_zip.writestr( |
| 66 | '{}/{}.img'.format(path, partition), |
| 67 | os.urandom(len(partition))) |
Tao Bao | f7140c0 | 2018-01-30 17:09:24 -0800 | [diff] [blame] | 68 | |
Tao Bao | 5277d10 | 2018-04-17 23:47:21 -0700 | [diff] [blame] | 69 | # system_other shouldn't appear in META/ab_partitions.txt. |
Tao Bao | f7140c0 | 2018-01-30 17:09:24 -0800 | [diff] [blame] | 70 | if secondary: |
| 71 | target_files_zip.writestr('IMAGES/system_other.img', |
| 72 | os.urandom(len("system_other"))) |
| 73 | |
| 74 | return target_files |
| 75 | |
| 76 | |
Tao Bao | 65b94e9 | 2018-10-11 21:57:26 -0700 | [diff] [blame] | 77 | class LoadOemDictsTest(test_utils.ReleaseToolsTestCase): |
Tao Bao | 481bab8 | 2017-12-21 11:23:09 -0800 | [diff] [blame] | 78 | |
| 79 | def test_NoneDict(self): |
| 80 | self.assertIsNone(_LoadOemDicts(None)) |
| 81 | |
| 82 | def test_SingleDict(self): |
| 83 | dict_file = common.MakeTempFile() |
| 84 | with open(dict_file, 'w') as dict_fp: |
| 85 | dict_fp.write('abc=1\ndef=2\nxyz=foo\na.b.c=bar\n') |
| 86 | |
| 87 | oem_dicts = _LoadOemDicts([dict_file]) |
| 88 | self.assertEqual(1, len(oem_dicts)) |
| 89 | self.assertEqual('foo', oem_dicts[0]['xyz']) |
| 90 | self.assertEqual('bar', oem_dicts[0]['a.b.c']) |
| 91 | |
| 92 | def test_MultipleDicts(self): |
| 93 | oem_source = [] |
| 94 | for i in range(3): |
| 95 | dict_file = common.MakeTempFile() |
| 96 | with open(dict_file, 'w') as dict_fp: |
| 97 | dict_fp.write( |
| 98 | 'ro.build.index={}\ndef=2\nxyz=foo\na.b.c=bar\n'.format(i)) |
| 99 | oem_source.append(dict_file) |
| 100 | |
| 101 | oem_dicts = _LoadOemDicts(oem_source) |
| 102 | self.assertEqual(3, len(oem_dicts)) |
| 103 | for i, oem_dict in enumerate(oem_dicts): |
| 104 | self.assertEqual('2', oem_dict['def']) |
| 105 | self.assertEqual('foo', oem_dict['xyz']) |
| 106 | self.assertEqual('bar', oem_dict['a.b.c']) |
| 107 | self.assertEqual('{}'.format(i), oem_dict['ro.build.index']) |
Tao Bao | df3a48b | 2018-01-10 16:30:43 -0800 | [diff] [blame] | 108 | |
| 109 | |
Tao Bao | 65b94e9 | 2018-10-11 21:57:26 -0700 | [diff] [blame] | 110 | class OtaFromTargetFilesTest(test_utils.ReleaseToolsTestCase): |
Tao Bao | df3a48b | 2018-01-10 16:30:43 -0800 | [diff] [blame] | 111 | |
| 112 | TEST_TARGET_INFO_DICT = { |
| 113 | 'build.prop' : { |
| 114 | 'ro.product.device' : 'product-device', |
| 115 | 'ro.build.fingerprint' : 'build-fingerprint-target', |
| 116 | 'ro.build.version.incremental' : 'build-version-incremental-target', |
Tao Bao | 35dc255 | 2018-02-01 13:18:00 -0800 | [diff] [blame] | 117 | 'ro.build.version.sdk' : '27', |
| 118 | 'ro.build.version.security_patch' : '2017-12-01', |
Tao Bao | df3a48b | 2018-01-10 16:30:43 -0800 | [diff] [blame] | 119 | 'ro.build.date.utc' : '1500000000', |
| 120 | }, |
| 121 | } |
| 122 | |
| 123 | TEST_SOURCE_INFO_DICT = { |
| 124 | 'build.prop' : { |
| 125 | 'ro.product.device' : 'product-device', |
| 126 | 'ro.build.fingerprint' : 'build-fingerprint-source', |
| 127 | 'ro.build.version.incremental' : 'build-version-incremental-source', |
Tao Bao | 35dc255 | 2018-02-01 13:18:00 -0800 | [diff] [blame] | 128 | 'ro.build.version.sdk' : '25', |
| 129 | 'ro.build.version.security_patch' : '2016-12-01', |
Tao Bao | df3a48b | 2018-01-10 16:30:43 -0800 | [diff] [blame] | 130 | 'ro.build.date.utc' : '1400000000', |
| 131 | }, |
| 132 | } |
| 133 | |
Tao Bao | 1c320f8 | 2019-10-04 23:25:12 -0700 | [diff] [blame] | 134 | TEST_INFO_DICT_USES_OEM_PROPS = { |
| 135 | 'build.prop' : { |
| 136 | 'ro.product.name' : 'product-name', |
| 137 | 'ro.build.thumbprint' : 'build-thumbprint', |
| 138 | 'ro.build.bar' : 'build-bar', |
| 139 | }, |
| 140 | 'vendor.build.prop' : { |
| 141 | 'ro.vendor.build.fingerprint' : 'vendor-build-fingerprint', |
| 142 | }, |
| 143 | 'property1' : 'value1', |
| 144 | 'property2' : 4096, |
| 145 | 'oem_fingerprint_properties' : 'ro.product.device ro.product.brand', |
| 146 | } |
| 147 | |
| 148 | TEST_OEM_DICTS = [ |
| 149 | { |
| 150 | 'ro.product.brand' : 'brand1', |
| 151 | 'ro.product.device' : 'device1', |
| 152 | }, |
| 153 | { |
| 154 | 'ro.product.brand' : 'brand2', |
| 155 | 'ro.product.device' : 'device2', |
| 156 | }, |
| 157 | { |
| 158 | 'ro.product.brand' : 'brand3', |
| 159 | 'ro.product.device' : 'device3', |
| 160 | }, |
| 161 | ] |
| 162 | |
Tao Bao | df3a48b | 2018-01-10 16:30:43 -0800 | [diff] [blame] | 163 | def setUp(self): |
Tao Bao | 3bf8c65 | 2018-03-16 12:59:42 -0700 | [diff] [blame] | 164 | self.testdata_dir = test_utils.get_testdata_dir() |
| 165 | self.assertTrue(os.path.exists(self.testdata_dir)) |
| 166 | |
Tao Bao | df3a48b | 2018-01-10 16:30:43 -0800 | [diff] [blame] | 167 | # Reset the global options as in ota_from_target_files.py. |
| 168 | common.OPTIONS.incremental_source = None |
| 169 | common.OPTIONS.downgrade = False |
Tao Bao | 393eeb4 | 2019-03-06 16:00:38 -0800 | [diff] [blame] | 170 | common.OPTIONS.retrofit_dynamic_partitions = False |
Tao Bao | df3a48b | 2018-01-10 16:30:43 -0800 | [diff] [blame] | 171 | common.OPTIONS.timestamp = False |
| 172 | common.OPTIONS.wipe_user_data = False |
Tao Bao | 3bf8c65 | 2018-03-16 12:59:42 -0700 | [diff] [blame] | 173 | common.OPTIONS.no_signing = False |
| 174 | common.OPTIONS.package_key = os.path.join(self.testdata_dir, 'testkey') |
| 175 | common.OPTIONS.key_passwords = { |
| 176 | common.OPTIONS.package_key : None, |
| 177 | } |
| 178 | |
| 179 | common.OPTIONS.search_path = test_utils.get_search_path() |
Tao Bao | df3a48b | 2018-01-10 16:30:43 -0800 | [diff] [blame] | 180 | |
| 181 | def test_GetPackageMetadata_abOta_full(self): |
| 182 | target_info_dict = copy.deepcopy(self.TEST_TARGET_INFO_DICT) |
| 183 | target_info_dict['ab_update'] = 'true' |
Tao Bao | 1c320f8 | 2019-10-04 23:25:12 -0700 | [diff] [blame] | 184 | target_info = common.BuildInfo(target_info_dict, None) |
Tao Bao | df3a48b | 2018-01-10 16:30:43 -0800 | [diff] [blame] | 185 | metadata = GetPackageMetadata(target_info) |
| 186 | self.assertDictEqual( |
| 187 | { |
| 188 | 'ota-type' : 'AB', |
| 189 | 'ota-required-cache' : '0', |
| 190 | 'post-build' : 'build-fingerprint-target', |
| 191 | 'post-build-incremental' : 'build-version-incremental-target', |
Tao Bao | 35dc255 | 2018-02-01 13:18:00 -0800 | [diff] [blame] | 192 | 'post-sdk-level' : '27', |
| 193 | 'post-security-patch-level' : '2017-12-01', |
Tao Bao | df3a48b | 2018-01-10 16:30:43 -0800 | [diff] [blame] | 194 | 'post-timestamp' : '1500000000', |
| 195 | 'pre-device' : 'product-device', |
| 196 | }, |
| 197 | metadata) |
| 198 | |
| 199 | def test_GetPackageMetadata_abOta_incremental(self): |
| 200 | target_info_dict = copy.deepcopy(self.TEST_TARGET_INFO_DICT) |
| 201 | target_info_dict['ab_update'] = 'true' |
Tao Bao | 1c320f8 | 2019-10-04 23:25:12 -0700 | [diff] [blame] | 202 | target_info = common.BuildInfo(target_info_dict, None) |
| 203 | source_info = common.BuildInfo(self.TEST_SOURCE_INFO_DICT, None) |
Tao Bao | df3a48b | 2018-01-10 16:30:43 -0800 | [diff] [blame] | 204 | common.OPTIONS.incremental_source = '' |
| 205 | metadata = GetPackageMetadata(target_info, source_info) |
| 206 | self.assertDictEqual( |
| 207 | { |
| 208 | 'ota-type' : 'AB', |
| 209 | 'ota-required-cache' : '0', |
| 210 | 'post-build' : 'build-fingerprint-target', |
| 211 | 'post-build-incremental' : 'build-version-incremental-target', |
Tao Bao | 35dc255 | 2018-02-01 13:18:00 -0800 | [diff] [blame] | 212 | 'post-sdk-level' : '27', |
| 213 | 'post-security-patch-level' : '2017-12-01', |
Tao Bao | df3a48b | 2018-01-10 16:30:43 -0800 | [diff] [blame] | 214 | 'post-timestamp' : '1500000000', |
| 215 | 'pre-device' : 'product-device', |
| 216 | 'pre-build' : 'build-fingerprint-source', |
| 217 | 'pre-build-incremental' : 'build-version-incremental-source', |
| 218 | }, |
| 219 | metadata) |
| 220 | |
| 221 | def test_GetPackageMetadata_nonAbOta_full(self): |
Tao Bao | 1c320f8 | 2019-10-04 23:25:12 -0700 | [diff] [blame] | 222 | target_info = common.BuildInfo(self.TEST_TARGET_INFO_DICT, None) |
Tao Bao | df3a48b | 2018-01-10 16:30:43 -0800 | [diff] [blame] | 223 | metadata = GetPackageMetadata(target_info) |
| 224 | self.assertDictEqual( |
| 225 | { |
| 226 | 'ota-type' : 'BLOCK', |
| 227 | 'post-build' : 'build-fingerprint-target', |
| 228 | 'post-build-incremental' : 'build-version-incremental-target', |
Tao Bao | 35dc255 | 2018-02-01 13:18:00 -0800 | [diff] [blame] | 229 | 'post-sdk-level' : '27', |
| 230 | 'post-security-patch-level' : '2017-12-01', |
Tao Bao | df3a48b | 2018-01-10 16:30:43 -0800 | [diff] [blame] | 231 | 'post-timestamp' : '1500000000', |
| 232 | 'pre-device' : 'product-device', |
| 233 | }, |
| 234 | metadata) |
| 235 | |
| 236 | def test_GetPackageMetadata_nonAbOta_incremental(self): |
Tao Bao | 1c320f8 | 2019-10-04 23:25:12 -0700 | [diff] [blame] | 237 | target_info = common.BuildInfo(self.TEST_TARGET_INFO_DICT, None) |
| 238 | source_info = common.BuildInfo(self.TEST_SOURCE_INFO_DICT, None) |
Tao Bao | df3a48b | 2018-01-10 16:30:43 -0800 | [diff] [blame] | 239 | common.OPTIONS.incremental_source = '' |
| 240 | metadata = GetPackageMetadata(target_info, source_info) |
| 241 | self.assertDictEqual( |
| 242 | { |
| 243 | 'ota-type' : 'BLOCK', |
| 244 | 'post-build' : 'build-fingerprint-target', |
| 245 | 'post-build-incremental' : 'build-version-incremental-target', |
Tao Bao | 35dc255 | 2018-02-01 13:18:00 -0800 | [diff] [blame] | 246 | 'post-sdk-level' : '27', |
| 247 | 'post-security-patch-level' : '2017-12-01', |
Tao Bao | df3a48b | 2018-01-10 16:30:43 -0800 | [diff] [blame] | 248 | 'post-timestamp' : '1500000000', |
| 249 | 'pre-device' : 'product-device', |
| 250 | 'pre-build' : 'build-fingerprint-source', |
| 251 | 'pre-build-incremental' : 'build-version-incremental-source', |
| 252 | }, |
| 253 | metadata) |
| 254 | |
| 255 | def test_GetPackageMetadata_wipe(self): |
Tao Bao | 1c320f8 | 2019-10-04 23:25:12 -0700 | [diff] [blame] | 256 | target_info = common.BuildInfo(self.TEST_TARGET_INFO_DICT, None) |
Tao Bao | df3a48b | 2018-01-10 16:30:43 -0800 | [diff] [blame] | 257 | common.OPTIONS.wipe_user_data = True |
| 258 | metadata = GetPackageMetadata(target_info) |
| 259 | self.assertDictEqual( |
| 260 | { |
| 261 | 'ota-type' : 'BLOCK', |
| 262 | 'ota-wipe' : 'yes', |
| 263 | 'post-build' : 'build-fingerprint-target', |
| 264 | 'post-build-incremental' : 'build-version-incremental-target', |
Tao Bao | 35dc255 | 2018-02-01 13:18:00 -0800 | [diff] [blame] | 265 | 'post-sdk-level' : '27', |
| 266 | 'post-security-patch-level' : '2017-12-01', |
Tao Bao | df3a48b | 2018-01-10 16:30:43 -0800 | [diff] [blame] | 267 | 'post-timestamp' : '1500000000', |
| 268 | 'pre-device' : 'product-device', |
| 269 | }, |
| 270 | metadata) |
| 271 | |
Tao Bao | 393eeb4 | 2019-03-06 16:00:38 -0800 | [diff] [blame] | 272 | def test_GetPackageMetadata_retrofitDynamicPartitions(self): |
Tao Bao | 1c320f8 | 2019-10-04 23:25:12 -0700 | [diff] [blame] | 273 | target_info = common.BuildInfo(self.TEST_TARGET_INFO_DICT, None) |
Tao Bao | 393eeb4 | 2019-03-06 16:00:38 -0800 | [diff] [blame] | 274 | common.OPTIONS.retrofit_dynamic_partitions = True |
| 275 | metadata = GetPackageMetadata(target_info) |
| 276 | self.assertDictEqual( |
| 277 | { |
| 278 | 'ota-retrofit-dynamic-partitions' : 'yes', |
| 279 | 'ota-type' : 'BLOCK', |
| 280 | 'post-build' : 'build-fingerprint-target', |
| 281 | 'post-build-incremental' : 'build-version-incremental-target', |
| 282 | 'post-sdk-level' : '27', |
| 283 | 'post-security-patch-level' : '2017-12-01', |
| 284 | 'post-timestamp' : '1500000000', |
| 285 | 'pre-device' : 'product-device', |
| 286 | }, |
| 287 | metadata) |
| 288 | |
Tao Bao | df3a48b | 2018-01-10 16:30:43 -0800 | [diff] [blame] | 289 | @staticmethod |
| 290 | def _test_GetPackageMetadata_swapBuildTimestamps(target_info, source_info): |
| 291 | (target_info['build.prop']['ro.build.date.utc'], |
| 292 | source_info['build.prop']['ro.build.date.utc']) = ( |
| 293 | source_info['build.prop']['ro.build.date.utc'], |
| 294 | target_info['build.prop']['ro.build.date.utc']) |
| 295 | |
| 296 | def test_GetPackageMetadata_unintentionalDowngradeDetected(self): |
| 297 | target_info_dict = copy.deepcopy(self.TEST_TARGET_INFO_DICT) |
| 298 | source_info_dict = copy.deepcopy(self.TEST_SOURCE_INFO_DICT) |
| 299 | self._test_GetPackageMetadata_swapBuildTimestamps( |
| 300 | target_info_dict, source_info_dict) |
| 301 | |
Tao Bao | 1c320f8 | 2019-10-04 23:25:12 -0700 | [diff] [blame] | 302 | target_info = common.BuildInfo(target_info_dict, None) |
| 303 | source_info = common.BuildInfo(source_info_dict, None) |
Tao Bao | df3a48b | 2018-01-10 16:30:43 -0800 | [diff] [blame] | 304 | common.OPTIONS.incremental_source = '' |
| 305 | self.assertRaises(RuntimeError, GetPackageMetadata, target_info, |
| 306 | source_info) |
| 307 | |
| 308 | def test_GetPackageMetadata_downgrade(self): |
| 309 | target_info_dict = copy.deepcopy(self.TEST_TARGET_INFO_DICT) |
| 310 | source_info_dict = copy.deepcopy(self.TEST_SOURCE_INFO_DICT) |
| 311 | self._test_GetPackageMetadata_swapBuildTimestamps( |
| 312 | target_info_dict, source_info_dict) |
| 313 | |
Tao Bao | 1c320f8 | 2019-10-04 23:25:12 -0700 | [diff] [blame] | 314 | target_info = common.BuildInfo(target_info_dict, None) |
| 315 | source_info = common.BuildInfo(source_info_dict, None) |
Tao Bao | df3a48b | 2018-01-10 16:30:43 -0800 | [diff] [blame] | 316 | common.OPTIONS.incremental_source = '' |
| 317 | common.OPTIONS.downgrade = True |
| 318 | common.OPTIONS.wipe_user_data = True |
| 319 | metadata = GetPackageMetadata(target_info, source_info) |
| 320 | self.assertDictEqual( |
| 321 | { |
| 322 | 'ota-downgrade' : 'yes', |
| 323 | 'ota-type' : 'BLOCK', |
| 324 | 'ota-wipe' : 'yes', |
| 325 | 'post-build' : 'build-fingerprint-target', |
| 326 | 'post-build-incremental' : 'build-version-incremental-target', |
Tao Bao | 35dc255 | 2018-02-01 13:18:00 -0800 | [diff] [blame] | 327 | 'post-sdk-level' : '27', |
| 328 | 'post-security-patch-level' : '2017-12-01', |
Tao Bao | faa8e0b | 2018-04-12 14:31:43 -0700 | [diff] [blame] | 329 | 'post-timestamp' : '1400000000', |
Tao Bao | df3a48b | 2018-01-10 16:30:43 -0800 | [diff] [blame] | 330 | 'pre-device' : 'product-device', |
| 331 | 'pre-build' : 'build-fingerprint-source', |
| 332 | 'pre-build-incremental' : 'build-version-incremental-source', |
| 333 | }, |
| 334 | metadata) |
Tao Bao | fabe083 | 2018-01-17 15:52:28 -0800 | [diff] [blame] | 335 | |
Tao Bao | 82490d3 | 2019-04-09 00:12:30 -0700 | [diff] [blame] | 336 | @test_utils.SkipIfExternalToolsUnavailable() |
Tao Bao | f7140c0 | 2018-01-30 17:09:24 -0800 | [diff] [blame] | 337 | def test_GetTargetFilesZipForSecondaryImages(self): |
| 338 | input_file = construct_target_files(secondary=True) |
| 339 | target_file = GetTargetFilesZipForSecondaryImages(input_file) |
| 340 | |
| 341 | with zipfile.ZipFile(target_file) as verify_zip: |
| 342 | namelist = verify_zip.namelist() |
Tao Bao | 615b65d | 2019-10-06 22:59:45 -0700 | [diff] [blame] | 343 | ab_partitions = verify_zip.read('META/ab_partitions.txt').decode() |
Tao Bao | f7140c0 | 2018-01-30 17:09:24 -0800 | [diff] [blame] | 344 | |
| 345 | self.assertIn('META/ab_partitions.txt', namelist) |
Tao Bao | f7140c0 | 2018-01-30 17:09:24 -0800 | [diff] [blame] | 346 | self.assertIn('IMAGES/system.img', namelist) |
Tao Bao | 1248980 | 2018-07-12 14:47:38 -0700 | [diff] [blame] | 347 | self.assertIn('RADIO/bootloader.img', namelist) |
Tao Bao | 15a146a | 2018-02-21 16:06:59 -0800 | [diff] [blame] | 348 | self.assertIn(POSTINSTALL_CONFIG, namelist) |
Tao Bao | f7140c0 | 2018-01-30 17:09:24 -0800 | [diff] [blame] | 349 | |
Tao Bao | 3e75946 | 2019-09-17 22:43:11 -0700 | [diff] [blame] | 350 | self.assertNotIn('IMAGES/boot.img', namelist) |
Tao Bao | f7140c0 | 2018-01-30 17:09:24 -0800 | [diff] [blame] | 351 | self.assertNotIn('IMAGES/system_other.img', namelist) |
| 352 | self.assertNotIn('IMAGES/system.map', namelist) |
Tao Bao | 3e75946 | 2019-09-17 22:43:11 -0700 | [diff] [blame] | 353 | self.assertNotIn('RADIO/modem.img', namelist) |
Tao Bao | f7140c0 | 2018-01-30 17:09:24 -0800 | [diff] [blame] | 354 | |
Tao Bao | 3e75946 | 2019-09-17 22:43:11 -0700 | [diff] [blame] | 355 | expected_ab_partitions = ['system', 'bootloader'] |
Tianjie Xu | 1c80800 | 2019-09-11 00:29:26 -0700 | [diff] [blame] | 356 | self.assertEqual('\n'.join(expected_ab_partitions), ab_partitions) |
| 357 | |
Tao Bao | 82490d3 | 2019-04-09 00:12:30 -0700 | [diff] [blame] | 358 | @test_utils.SkipIfExternalToolsUnavailable() |
Tao Bao | 15a146a | 2018-02-21 16:06:59 -0800 | [diff] [blame] | 359 | def test_GetTargetFilesZipForSecondaryImages_skipPostinstall(self): |
| 360 | input_file = construct_target_files(secondary=True) |
| 361 | target_file = GetTargetFilesZipForSecondaryImages( |
| 362 | input_file, skip_postinstall=True) |
| 363 | |
| 364 | with zipfile.ZipFile(target_file) as verify_zip: |
| 365 | namelist = verify_zip.namelist() |
| 366 | |
| 367 | self.assertIn('META/ab_partitions.txt', namelist) |
Tao Bao | 15a146a | 2018-02-21 16:06:59 -0800 | [diff] [blame] | 368 | self.assertIn('IMAGES/system.img', namelist) |
Tao Bao | 1248980 | 2018-07-12 14:47:38 -0700 | [diff] [blame] | 369 | self.assertIn('RADIO/bootloader.img', namelist) |
Tao Bao | 15a146a | 2018-02-21 16:06:59 -0800 | [diff] [blame] | 370 | |
Tao Bao | 3e75946 | 2019-09-17 22:43:11 -0700 | [diff] [blame] | 371 | self.assertNotIn('IMAGES/boot.img', namelist) |
Tao Bao | 15a146a | 2018-02-21 16:06:59 -0800 | [diff] [blame] | 372 | self.assertNotIn('IMAGES/system_other.img', namelist) |
| 373 | self.assertNotIn('IMAGES/system.map', namelist) |
Tao Bao | 3e75946 | 2019-09-17 22:43:11 -0700 | [diff] [blame] | 374 | self.assertNotIn('RADIO/modem.img', namelist) |
Tao Bao | 15a146a | 2018-02-21 16:06:59 -0800 | [diff] [blame] | 375 | self.assertNotIn(POSTINSTALL_CONFIG, namelist) |
| 376 | |
Tao Bao | 82490d3 | 2019-04-09 00:12:30 -0700 | [diff] [blame] | 377 | @test_utils.SkipIfExternalToolsUnavailable() |
Tao Bao | 1248980 | 2018-07-12 14:47:38 -0700 | [diff] [blame] | 378 | def test_GetTargetFilesZipForSecondaryImages_withoutRadioImages(self): |
| 379 | input_file = construct_target_files(secondary=True) |
| 380 | common.ZipDelete(input_file, 'RADIO/bootloader.img') |
| 381 | common.ZipDelete(input_file, 'RADIO/modem.img') |
| 382 | target_file = GetTargetFilesZipForSecondaryImages(input_file) |
| 383 | |
| 384 | with zipfile.ZipFile(target_file) as verify_zip: |
| 385 | namelist = verify_zip.namelist() |
| 386 | |
| 387 | self.assertIn('META/ab_partitions.txt', namelist) |
Tao Bao | 1248980 | 2018-07-12 14:47:38 -0700 | [diff] [blame] | 388 | self.assertIn('IMAGES/system.img', namelist) |
Tao Bao | 1248980 | 2018-07-12 14:47:38 -0700 | [diff] [blame] | 389 | self.assertIn(POSTINSTALL_CONFIG, namelist) |
| 390 | |
Tao Bao | 3e75946 | 2019-09-17 22:43:11 -0700 | [diff] [blame] | 391 | self.assertNotIn('IMAGES/boot.img', namelist) |
Tao Bao | 1248980 | 2018-07-12 14:47:38 -0700 | [diff] [blame] | 392 | self.assertNotIn('IMAGES/system_other.img', namelist) |
| 393 | self.assertNotIn('IMAGES/system.map', namelist) |
| 394 | self.assertNotIn('RADIO/bootloader.img', namelist) |
| 395 | self.assertNotIn('RADIO/modem.img', namelist) |
| 396 | |
Tao Bao | 82490d3 | 2019-04-09 00:12:30 -0700 | [diff] [blame] | 397 | @test_utils.SkipIfExternalToolsUnavailable() |
Tianjie Xu | 1c80800 | 2019-09-11 00:29:26 -0700 | [diff] [blame] | 398 | def test_GetTargetFilesZipForSecondaryImages_dynamicPartitions(self): |
| 399 | input_file = construct_target_files(secondary=True) |
| 400 | misc_info = '\n'.join([ |
| 401 | 'use_dynamic_partition_size=true', |
| 402 | 'use_dynamic_partitions=true', |
| 403 | 'dynamic_partition_list=system vendor product', |
| 404 | 'super_partition_groups=google_dynamic_partitions', |
| 405 | 'super_google_dynamic_partitions_group_size=4873781248', |
| 406 | 'super_google_dynamic_partitions_partition_list=system vendor product', |
| 407 | ]) |
| 408 | dynamic_partitions_info = '\n'.join([ |
| 409 | 'super_partition_groups=google_dynamic_partitions', |
| 410 | 'super_google_dynamic_partitions_group_size=4873781248', |
| 411 | 'super_google_dynamic_partitions_partition_list=system vendor product', |
| 412 | ]) |
| 413 | |
| 414 | with zipfile.ZipFile(input_file, 'a') as append_zip: |
| 415 | common.ZipWriteStr(append_zip, 'META/misc_info.txt', misc_info) |
| 416 | common.ZipWriteStr(append_zip, 'META/dynamic_partitions_info.txt', |
| 417 | dynamic_partitions_info) |
| 418 | |
| 419 | target_file = GetTargetFilesZipForSecondaryImages(input_file) |
| 420 | |
| 421 | with zipfile.ZipFile(target_file) as verify_zip: |
| 422 | namelist = verify_zip.namelist() |
Tao Bao | 615b65d | 2019-10-06 22:59:45 -0700 | [diff] [blame] | 423 | updated_misc_info = verify_zip.read('META/misc_info.txt').decode() |
Tianjie Xu | 1c80800 | 2019-09-11 00:29:26 -0700 | [diff] [blame] | 424 | updated_dynamic_partitions_info = verify_zip.read( |
Tao Bao | 615b65d | 2019-10-06 22:59:45 -0700 | [diff] [blame] | 425 | 'META/dynamic_partitions_info.txt').decode() |
Tianjie Xu | 1c80800 | 2019-09-11 00:29:26 -0700 | [diff] [blame] | 426 | |
| 427 | self.assertIn('META/ab_partitions.txt', namelist) |
Tianjie Xu | 1c80800 | 2019-09-11 00:29:26 -0700 | [diff] [blame] | 428 | self.assertIn('IMAGES/system.img', namelist) |
| 429 | self.assertIn(POSTINSTALL_CONFIG, namelist) |
| 430 | self.assertIn('META/misc_info.txt', namelist) |
| 431 | self.assertIn('META/dynamic_partitions_info.txt', namelist) |
| 432 | |
Tao Bao | 3e75946 | 2019-09-17 22:43:11 -0700 | [diff] [blame] | 433 | self.assertNotIn('IMAGES/boot.img', namelist) |
Tianjie Xu | 1c80800 | 2019-09-11 00:29:26 -0700 | [diff] [blame] | 434 | self.assertNotIn('IMAGES/system_other.img', namelist) |
| 435 | self.assertNotIn('IMAGES/system.map', namelist) |
| 436 | |
| 437 | # Check the vendor & product are removed from the partitions list. |
| 438 | expected_misc_info = misc_info.replace('system vendor product', |
| 439 | 'system') |
| 440 | expected_dynamic_partitions_info = dynamic_partitions_info.replace( |
| 441 | 'system vendor product', 'system') |
| 442 | self.assertEqual(expected_misc_info, updated_misc_info) |
| 443 | self.assertEqual(expected_dynamic_partitions_info, |
| 444 | updated_dynamic_partitions_info) |
| 445 | |
| 446 | @test_utils.SkipIfExternalToolsUnavailable() |
Tao Bao | 15a146a | 2018-02-21 16:06:59 -0800 | [diff] [blame] | 447 | def test_GetTargetFilesZipWithoutPostinstallConfig(self): |
| 448 | input_file = construct_target_files() |
| 449 | target_file = GetTargetFilesZipWithoutPostinstallConfig(input_file) |
| 450 | with zipfile.ZipFile(target_file) as verify_zip: |
| 451 | self.assertNotIn(POSTINSTALL_CONFIG, verify_zip.namelist()) |
| 452 | |
Tao Bao | 82490d3 | 2019-04-09 00:12:30 -0700 | [diff] [blame] | 453 | @test_utils.SkipIfExternalToolsUnavailable() |
Tao Bao | 15a146a | 2018-02-21 16:06:59 -0800 | [diff] [blame] | 454 | def test_GetTargetFilesZipWithoutPostinstallConfig_missingEntry(self): |
| 455 | input_file = construct_target_files() |
| 456 | common.ZipDelete(input_file, POSTINSTALL_CONFIG) |
| 457 | target_file = GetTargetFilesZipWithoutPostinstallConfig(input_file) |
| 458 | with zipfile.ZipFile(target_file) as verify_zip: |
| 459 | self.assertNotIn(POSTINSTALL_CONFIG, verify_zip.namelist()) |
| 460 | |
Tao Bao | 3bf8c65 | 2018-03-16 12:59:42 -0700 | [diff] [blame] | 461 | def _test_FinalizeMetadata(self, large_entry=False): |
| 462 | entries = [ |
| 463 | 'required-entry1', |
| 464 | 'required-entry2', |
| 465 | ] |
| 466 | zip_file = PropertyFilesTest.construct_zip_package(entries) |
| 467 | # Add a large entry of 1 GiB if requested. |
| 468 | if large_entry: |
| 469 | with zipfile.ZipFile(zip_file, 'a') as zip_fp: |
| 470 | zip_fp.writestr( |
| 471 | # Using 'zoo' so that the entry stays behind others after signing. |
| 472 | 'zoo', |
| 473 | 'A' * 1024 * 1024 * 1024, |
| 474 | zipfile.ZIP_STORED) |
| 475 | |
| 476 | metadata = {} |
| 477 | output_file = common.MakeTempFile(suffix='.zip') |
| 478 | needed_property_files = ( |
| 479 | TestPropertyFiles(), |
| 480 | ) |
| 481 | FinalizeMetadata(metadata, zip_file, output_file, needed_property_files) |
| 482 | self.assertIn('ota-test-property-files', metadata) |
| 483 | |
Tao Bao | 82490d3 | 2019-04-09 00:12:30 -0700 | [diff] [blame] | 484 | @test_utils.SkipIfExternalToolsUnavailable() |
Tao Bao | 3bf8c65 | 2018-03-16 12:59:42 -0700 | [diff] [blame] | 485 | def test_FinalizeMetadata(self): |
| 486 | self._test_FinalizeMetadata() |
| 487 | |
Tao Bao | 82490d3 | 2019-04-09 00:12:30 -0700 | [diff] [blame] | 488 | @test_utils.SkipIfExternalToolsUnavailable() |
Tao Bao | 3bf8c65 | 2018-03-16 12:59:42 -0700 | [diff] [blame] | 489 | def test_FinalizeMetadata_withNoSigning(self): |
| 490 | common.OPTIONS.no_signing = True |
| 491 | self._test_FinalizeMetadata() |
| 492 | |
Tao Bao | 82490d3 | 2019-04-09 00:12:30 -0700 | [diff] [blame] | 493 | @test_utils.SkipIfExternalToolsUnavailable() |
Tao Bao | 3bf8c65 | 2018-03-16 12:59:42 -0700 | [diff] [blame] | 494 | def test_FinalizeMetadata_largeEntry(self): |
| 495 | self._test_FinalizeMetadata(large_entry=True) |
| 496 | |
Tao Bao | 82490d3 | 2019-04-09 00:12:30 -0700 | [diff] [blame] | 497 | @test_utils.SkipIfExternalToolsUnavailable() |
Tao Bao | 3bf8c65 | 2018-03-16 12:59:42 -0700 | [diff] [blame] | 498 | def test_FinalizeMetadata_largeEntry_withNoSigning(self): |
| 499 | common.OPTIONS.no_signing = True |
| 500 | self._test_FinalizeMetadata(large_entry=True) |
| 501 | |
Tao Bao | 82490d3 | 2019-04-09 00:12:30 -0700 | [diff] [blame] | 502 | @test_utils.SkipIfExternalToolsUnavailable() |
Tao Bao | 3bf8c65 | 2018-03-16 12:59:42 -0700 | [diff] [blame] | 503 | def test_FinalizeMetadata_insufficientSpace(self): |
| 504 | entries = [ |
| 505 | 'required-entry1', |
| 506 | 'required-entry2', |
| 507 | 'optional-entry1', |
| 508 | 'optional-entry2', |
| 509 | ] |
| 510 | zip_file = PropertyFilesTest.construct_zip_package(entries) |
| 511 | with zipfile.ZipFile(zip_file, 'a') as zip_fp: |
| 512 | zip_fp.writestr( |
| 513 | # 'foo-entry1' will appear ahead of all other entries (in alphabetical |
| 514 | # order) after the signing, which will in turn trigger the |
| 515 | # InsufficientSpaceException and an automatic retry. |
| 516 | 'foo-entry1', |
| 517 | 'A' * 1024 * 1024, |
| 518 | zipfile.ZIP_STORED) |
| 519 | |
| 520 | metadata = {} |
| 521 | needed_property_files = ( |
| 522 | TestPropertyFiles(), |
| 523 | ) |
| 524 | output_file = common.MakeTempFile(suffix='.zip') |
| 525 | FinalizeMetadata(metadata, zip_file, output_file, needed_property_files) |
| 526 | self.assertIn('ota-test-property-files', metadata) |
| 527 | |
Tao Bao | 1c320f8 | 2019-10-04 23:25:12 -0700 | [diff] [blame] | 528 | def test_WriteFingerprintAssertion_without_oem_props(self): |
| 529 | target_info = common.BuildInfo(self.TEST_TARGET_INFO_DICT, None) |
| 530 | source_info_dict = copy.deepcopy(self.TEST_TARGET_INFO_DICT) |
| 531 | source_info_dict['build.prop']['ro.build.fingerprint'] = ( |
| 532 | 'source-build-fingerprint') |
| 533 | source_info = common.BuildInfo(source_info_dict, None) |
| 534 | |
| 535 | script_writer = test_utils.MockScriptWriter() |
| 536 | WriteFingerprintAssertion(script_writer, target_info, source_info) |
| 537 | self.assertEqual( |
| 538 | [('AssertSomeFingerprint', 'source-build-fingerprint', |
| 539 | 'build-fingerprint-target')], |
| 540 | script_writer.lines) |
| 541 | |
| 542 | def test_WriteFingerprintAssertion_with_source_oem_props(self): |
| 543 | target_info = common.BuildInfo(self.TEST_TARGET_INFO_DICT, None) |
| 544 | source_info = common.BuildInfo(self.TEST_INFO_DICT_USES_OEM_PROPS, |
| 545 | self.TEST_OEM_DICTS) |
| 546 | |
| 547 | script_writer = test_utils.MockScriptWriter() |
| 548 | WriteFingerprintAssertion(script_writer, target_info, source_info) |
| 549 | self.assertEqual( |
| 550 | [('AssertFingerprintOrThumbprint', 'build-fingerprint-target', |
| 551 | 'build-thumbprint')], |
| 552 | script_writer.lines) |
| 553 | |
| 554 | def test_WriteFingerprintAssertion_with_target_oem_props(self): |
| 555 | target_info = common.BuildInfo(self.TEST_INFO_DICT_USES_OEM_PROPS, |
| 556 | self.TEST_OEM_DICTS) |
| 557 | source_info = common.BuildInfo(self.TEST_TARGET_INFO_DICT, None) |
| 558 | |
| 559 | script_writer = test_utils.MockScriptWriter() |
| 560 | WriteFingerprintAssertion(script_writer, target_info, source_info) |
| 561 | self.assertEqual( |
| 562 | [('AssertFingerprintOrThumbprint', 'build-fingerprint-target', |
| 563 | 'build-thumbprint')], |
| 564 | script_writer.lines) |
| 565 | |
| 566 | def test_WriteFingerprintAssertion_with_both_oem_props(self): |
| 567 | target_info = common.BuildInfo(self.TEST_INFO_DICT_USES_OEM_PROPS, |
| 568 | self.TEST_OEM_DICTS) |
| 569 | source_info_dict = copy.deepcopy(self.TEST_INFO_DICT_USES_OEM_PROPS) |
| 570 | source_info_dict['build.prop']['ro.build.thumbprint'] = ( |
| 571 | 'source-build-thumbprint') |
| 572 | source_info = common.BuildInfo(source_info_dict, self.TEST_OEM_DICTS) |
| 573 | |
| 574 | script_writer = test_utils.MockScriptWriter() |
| 575 | WriteFingerprintAssertion(script_writer, target_info, source_info) |
| 576 | self.assertEqual( |
| 577 | [('AssertSomeThumbprint', 'build-thumbprint', |
| 578 | 'source-build-thumbprint')], |
| 579 | script_writer.lines) |
| 580 | |
Tao Bao | ae5e4c3 | 2018-03-01 19:30:00 -0800 | [diff] [blame] | 581 | |
Tao Bao | 6920352 | 2018-03-08 16:09:01 -0800 | [diff] [blame] | 582 | class TestPropertyFiles(PropertyFiles): |
| 583 | """A class that extends PropertyFiles for testing purpose.""" |
| 584 | |
| 585 | def __init__(self): |
| 586 | super(TestPropertyFiles, self).__init__() |
| 587 | self.name = 'ota-test-property-files' |
| 588 | self.required = ( |
| 589 | 'required-entry1', |
| 590 | 'required-entry2', |
| 591 | ) |
| 592 | self.optional = ( |
| 593 | 'optional-entry1', |
| 594 | 'optional-entry2', |
| 595 | ) |
| 596 | |
| 597 | |
Tao Bao | 65b94e9 | 2018-10-11 21:57:26 -0700 | [diff] [blame] | 598 | class PropertyFilesTest(test_utils.ReleaseToolsTestCase): |
Tao Bao | ae5e4c3 | 2018-03-01 19:30:00 -0800 | [diff] [blame] | 599 | |
Tao Bao | 3bf8c65 | 2018-03-16 12:59:42 -0700 | [diff] [blame] | 600 | def setUp(self): |
| 601 | common.OPTIONS.no_signing = False |
| 602 | |
Tao Bao | f511049 | 2018-03-02 09:47:43 -0800 | [diff] [blame] | 603 | @staticmethod |
Tao Bao | 3bf8c65 | 2018-03-16 12:59:42 -0700 | [diff] [blame] | 604 | def construct_zip_package(entries): |
Tao Bao | f511049 | 2018-03-02 09:47:43 -0800 | [diff] [blame] | 605 | zip_file = common.MakeTempFile(suffix='.zip') |
| 606 | with zipfile.ZipFile(zip_file, 'w') as zip_fp: |
| 607 | for entry in entries: |
| 608 | zip_fp.writestr( |
| 609 | entry, |
| 610 | entry.replace('.', '-').upper(), |
| 611 | zipfile.ZIP_STORED) |
| 612 | return zip_file |
| 613 | |
| 614 | @staticmethod |
Tao Bao | 6920352 | 2018-03-08 16:09:01 -0800 | [diff] [blame] | 615 | def _parse_property_files_string(data): |
Tao Bao | f511049 | 2018-03-02 09:47:43 -0800 | [diff] [blame] | 616 | result = {} |
| 617 | for token in data.split(','): |
| 618 | name, info = token.split(':', 1) |
| 619 | result[name] = info |
| 620 | return result |
| 621 | |
| 622 | def _verify_entries(self, input_file, tokens, entries): |
| 623 | for entry in entries: |
| 624 | offset, size = map(int, tokens[entry].split(':')) |
| 625 | with open(input_file, 'rb') as input_fp: |
| 626 | input_fp.seek(offset) |
| 627 | if entry == 'metadata': |
| 628 | expected = b'META-INF/COM/ANDROID/METADATA' |
| 629 | else: |
| 630 | expected = entry.replace('.', '-').upper().encode() |
| 631 | self.assertEqual(expected, input_fp.read(size)) |
| 632 | |
Tao Bao | 82490d3 | 2019-04-09 00:12:30 -0700 | [diff] [blame] | 633 | @test_utils.SkipIfExternalToolsUnavailable() |
Tao Bao | ae5e4c3 | 2018-03-01 19:30:00 -0800 | [diff] [blame] | 634 | def test_Compute(self): |
Tao Bao | f511049 | 2018-03-02 09:47:43 -0800 | [diff] [blame] | 635 | entries = ( |
Tao Bao | 6920352 | 2018-03-08 16:09:01 -0800 | [diff] [blame] | 636 | 'required-entry1', |
| 637 | 'required-entry2', |
Tao Bao | f511049 | 2018-03-02 09:47:43 -0800 | [diff] [blame] | 638 | ) |
Tao Bao | 3bf8c65 | 2018-03-16 12:59:42 -0700 | [diff] [blame] | 639 | zip_file = self.construct_zip_package(entries) |
Tao Bao | 6920352 | 2018-03-08 16:09:01 -0800 | [diff] [blame] | 640 | property_files = TestPropertyFiles() |
Tao Bao | f511049 | 2018-03-02 09:47:43 -0800 | [diff] [blame] | 641 | with zipfile.ZipFile(zip_file, 'r') as zip_fp: |
Tao Bao | 6920352 | 2018-03-08 16:09:01 -0800 | [diff] [blame] | 642 | property_files_string = property_files.Compute(zip_fp) |
Tao Bao | f511049 | 2018-03-02 09:47:43 -0800 | [diff] [blame] | 643 | |
Tao Bao | 6920352 | 2018-03-08 16:09:01 -0800 | [diff] [blame] | 644 | tokens = self._parse_property_files_string(property_files_string) |
Tao Bao | f511049 | 2018-03-02 09:47:43 -0800 | [diff] [blame] | 645 | self.assertEqual(3, len(tokens)) |
| 646 | self._verify_entries(zip_file, tokens, entries) |
| 647 | |
Tao Bao | 6920352 | 2018-03-08 16:09:01 -0800 | [diff] [blame] | 648 | def test_Compute_withOptionalEntries(self): |
Tao Bao | f511049 | 2018-03-02 09:47:43 -0800 | [diff] [blame] | 649 | entries = ( |
Tao Bao | 6920352 | 2018-03-08 16:09:01 -0800 | [diff] [blame] | 650 | 'required-entry1', |
| 651 | 'required-entry2', |
| 652 | 'optional-entry1', |
| 653 | 'optional-entry2', |
Tao Bao | f511049 | 2018-03-02 09:47:43 -0800 | [diff] [blame] | 654 | ) |
Tao Bao | 3bf8c65 | 2018-03-16 12:59:42 -0700 | [diff] [blame] | 655 | zip_file = self.construct_zip_package(entries) |
Tao Bao | 6920352 | 2018-03-08 16:09:01 -0800 | [diff] [blame] | 656 | property_files = TestPropertyFiles() |
Tao Bao | f511049 | 2018-03-02 09:47:43 -0800 | [diff] [blame] | 657 | with zipfile.ZipFile(zip_file, 'r') as zip_fp: |
Tao Bao | 6920352 | 2018-03-08 16:09:01 -0800 | [diff] [blame] | 658 | property_files_string = property_files.Compute(zip_fp) |
Tao Bao | f511049 | 2018-03-02 09:47:43 -0800 | [diff] [blame] | 659 | |
Tao Bao | 6920352 | 2018-03-08 16:09:01 -0800 | [diff] [blame] | 660 | tokens = self._parse_property_files_string(property_files_string) |
Tao Bao | f511049 | 2018-03-02 09:47:43 -0800 | [diff] [blame] | 661 | self.assertEqual(5, len(tokens)) |
| 662 | self._verify_entries(zip_file, tokens, entries) |
| 663 | |
Tao Bao | 6920352 | 2018-03-08 16:09:01 -0800 | [diff] [blame] | 664 | def test_Compute_missingRequiredEntry(self): |
| 665 | entries = ( |
| 666 | 'required-entry2', |
| 667 | ) |
Tao Bao | 3bf8c65 | 2018-03-16 12:59:42 -0700 | [diff] [blame] | 668 | zip_file = self.construct_zip_package(entries) |
Tao Bao | 6920352 | 2018-03-08 16:09:01 -0800 | [diff] [blame] | 669 | property_files = TestPropertyFiles() |
| 670 | with zipfile.ZipFile(zip_file, 'r') as zip_fp: |
| 671 | self.assertRaises(KeyError, property_files.Compute, zip_fp) |
| 672 | |
Tao Bao | 82490d3 | 2019-04-09 00:12:30 -0700 | [diff] [blame] | 673 | @test_utils.SkipIfExternalToolsUnavailable() |
Tao Bao | ae5e4c3 | 2018-03-01 19:30:00 -0800 | [diff] [blame] | 674 | def test_Finalize(self): |
Tao Bao | f511049 | 2018-03-02 09:47:43 -0800 | [diff] [blame] | 675 | entries = [ |
Tao Bao | 6920352 | 2018-03-08 16:09:01 -0800 | [diff] [blame] | 676 | 'required-entry1', |
| 677 | 'required-entry2', |
Tao Bao | f511049 | 2018-03-02 09:47:43 -0800 | [diff] [blame] | 678 | 'META-INF/com/android/metadata', |
| 679 | ] |
Tao Bao | 3bf8c65 | 2018-03-16 12:59:42 -0700 | [diff] [blame] | 680 | zip_file = self.construct_zip_package(entries) |
Tao Bao | 6920352 | 2018-03-08 16:09:01 -0800 | [diff] [blame] | 681 | property_files = TestPropertyFiles() |
Tao Bao | f511049 | 2018-03-02 09:47:43 -0800 | [diff] [blame] | 682 | with zipfile.ZipFile(zip_file, 'r') as zip_fp: |
Zhomart Mukhamejanov | 603655f | 2018-05-04 12:35:09 -0700 | [diff] [blame] | 683 | raw_metadata = property_files.GetPropertyFilesString( |
Tao Bao | ae5e4c3 | 2018-03-01 19:30:00 -0800 | [diff] [blame] | 684 | zip_fp, reserve_space=False) |
| 685 | streaming_metadata = property_files.Finalize(zip_fp, len(raw_metadata)) |
Tao Bao | 6920352 | 2018-03-08 16:09:01 -0800 | [diff] [blame] | 686 | tokens = self._parse_property_files_string(streaming_metadata) |
Tao Bao | f511049 | 2018-03-02 09:47:43 -0800 | [diff] [blame] | 687 | |
| 688 | self.assertEqual(3, len(tokens)) |
| 689 | # 'META-INF/com/android/metadata' will be key'd as 'metadata' in the |
| 690 | # streaming metadata. |
| 691 | entries[2] = 'metadata' |
| 692 | self._verify_entries(zip_file, tokens, entries) |
| 693 | |
Tao Bao | 82490d3 | 2019-04-09 00:12:30 -0700 | [diff] [blame] | 694 | @test_utils.SkipIfExternalToolsUnavailable() |
Tao Bao | ae5e4c3 | 2018-03-01 19:30:00 -0800 | [diff] [blame] | 695 | def test_Finalize_assertReservedLength(self): |
Tao Bao | f511049 | 2018-03-02 09:47:43 -0800 | [diff] [blame] | 696 | entries = ( |
Tao Bao | 6920352 | 2018-03-08 16:09:01 -0800 | [diff] [blame] | 697 | 'required-entry1', |
| 698 | 'required-entry2', |
| 699 | 'optional-entry1', |
| 700 | 'optional-entry2', |
Tao Bao | f511049 | 2018-03-02 09:47:43 -0800 | [diff] [blame] | 701 | 'META-INF/com/android/metadata', |
| 702 | ) |
Tao Bao | 3bf8c65 | 2018-03-16 12:59:42 -0700 | [diff] [blame] | 703 | zip_file = self.construct_zip_package(entries) |
Tao Bao | 6920352 | 2018-03-08 16:09:01 -0800 | [diff] [blame] | 704 | property_files = TestPropertyFiles() |
Tao Bao | f511049 | 2018-03-02 09:47:43 -0800 | [diff] [blame] | 705 | with zipfile.ZipFile(zip_file, 'r') as zip_fp: |
| 706 | # First get the raw metadata string (i.e. without padding space). |
Zhomart Mukhamejanov | 603655f | 2018-05-04 12:35:09 -0700 | [diff] [blame] | 707 | raw_metadata = property_files.GetPropertyFilesString( |
Tao Bao | ae5e4c3 | 2018-03-01 19:30:00 -0800 | [diff] [blame] | 708 | zip_fp, reserve_space=False) |
Tao Bao | f511049 | 2018-03-02 09:47:43 -0800 | [diff] [blame] | 709 | raw_length = len(raw_metadata) |
| 710 | |
| 711 | # Now pass in the exact expected length. |
Tao Bao | ae5e4c3 | 2018-03-01 19:30:00 -0800 | [diff] [blame] | 712 | streaming_metadata = property_files.Finalize(zip_fp, raw_length) |
Tao Bao | f511049 | 2018-03-02 09:47:43 -0800 | [diff] [blame] | 713 | self.assertEqual(raw_length, len(streaming_metadata)) |
| 714 | |
| 715 | # Or pass in insufficient length. |
| 716 | self.assertRaises( |
Tao Bao | 3bf8c65 | 2018-03-16 12:59:42 -0700 | [diff] [blame] | 717 | PropertyFiles.InsufficientSpaceException, |
Tao Bao | ae5e4c3 | 2018-03-01 19:30:00 -0800 | [diff] [blame] | 718 | property_files.Finalize, |
Tao Bao | f511049 | 2018-03-02 09:47:43 -0800 | [diff] [blame] | 719 | zip_fp, |
Tao Bao | ae5e4c3 | 2018-03-01 19:30:00 -0800 | [diff] [blame] | 720 | raw_length - 1) |
Tao Bao | f511049 | 2018-03-02 09:47:43 -0800 | [diff] [blame] | 721 | |
| 722 | # Or pass in a much larger size. |
Tao Bao | ae5e4c3 | 2018-03-01 19:30:00 -0800 | [diff] [blame] | 723 | streaming_metadata = property_files.Finalize( |
Tao Bao | f511049 | 2018-03-02 09:47:43 -0800 | [diff] [blame] | 724 | zip_fp, |
Tao Bao | ae5e4c3 | 2018-03-01 19:30:00 -0800 | [diff] [blame] | 725 | raw_length + 20) |
Tao Bao | f511049 | 2018-03-02 09:47:43 -0800 | [diff] [blame] | 726 | self.assertEqual(raw_length + 20, len(streaming_metadata)) |
| 727 | self.assertEqual(' ' * 20, streaming_metadata[raw_length:]) |
| 728 | |
Tao Bao | ae5e4c3 | 2018-03-01 19:30:00 -0800 | [diff] [blame] | 729 | def test_Verify(self): |
| 730 | entries = ( |
Tao Bao | 6920352 | 2018-03-08 16:09:01 -0800 | [diff] [blame] | 731 | 'required-entry1', |
| 732 | 'required-entry2', |
| 733 | 'optional-entry1', |
| 734 | 'optional-entry2', |
| 735 | 'META-INF/com/android/metadata', |
| 736 | ) |
Tao Bao | 3bf8c65 | 2018-03-16 12:59:42 -0700 | [diff] [blame] | 737 | zip_file = self.construct_zip_package(entries) |
Tao Bao | 6920352 | 2018-03-08 16:09:01 -0800 | [diff] [blame] | 738 | property_files = TestPropertyFiles() |
| 739 | with zipfile.ZipFile(zip_file, 'r') as zip_fp: |
| 740 | # First get the raw metadata string (i.e. without padding space). |
Zhomart Mukhamejanov | 603655f | 2018-05-04 12:35:09 -0700 | [diff] [blame] | 741 | raw_metadata = property_files.GetPropertyFilesString( |
Tao Bao | 6920352 | 2018-03-08 16:09:01 -0800 | [diff] [blame] | 742 | zip_fp, reserve_space=False) |
| 743 | |
| 744 | # Should pass the test if verification passes. |
| 745 | property_files.Verify(zip_fp, raw_metadata) |
| 746 | |
| 747 | # Or raise on verification failure. |
| 748 | self.assertRaises( |
| 749 | AssertionError, property_files.Verify, zip_fp, raw_metadata + 'x') |
| 750 | |
| 751 | |
| 752 | class StreamingPropertyFilesTest(PropertyFilesTest): |
| 753 | """Additional sanity checks specialized for StreamingPropertyFiles.""" |
| 754 | |
| 755 | def test_init(self): |
| 756 | property_files = StreamingPropertyFiles() |
| 757 | self.assertEqual('ota-streaming-property-files', property_files.name) |
| 758 | self.assertEqual( |
| 759 | ( |
| 760 | 'payload.bin', |
| 761 | 'payload_properties.txt', |
| 762 | ), |
| 763 | property_files.required) |
| 764 | self.assertEqual( |
| 765 | ( |
Tianjie Xu | 4c05f4a | 2018-09-14 16:24:41 -0700 | [diff] [blame] | 766 | 'care_map.pb', |
Tao Bao | 6920352 | 2018-03-08 16:09:01 -0800 | [diff] [blame] | 767 | 'care_map.txt', |
| 768 | 'compatibility.zip', |
| 769 | ), |
| 770 | property_files.optional) |
| 771 | |
| 772 | def test_Compute(self): |
| 773 | entries = ( |
Tao Bao | ae5e4c3 | 2018-03-01 19:30:00 -0800 | [diff] [blame] | 774 | 'payload.bin', |
| 775 | 'payload_properties.txt', |
| 776 | 'care_map.txt', |
Tao Bao | 6920352 | 2018-03-08 16:09:01 -0800 | [diff] [blame] | 777 | 'compatibility.zip', |
| 778 | ) |
Tao Bao | 3bf8c65 | 2018-03-16 12:59:42 -0700 | [diff] [blame] | 779 | zip_file = self.construct_zip_package(entries) |
Tao Bao | 6920352 | 2018-03-08 16:09:01 -0800 | [diff] [blame] | 780 | property_files = StreamingPropertyFiles() |
| 781 | with zipfile.ZipFile(zip_file, 'r') as zip_fp: |
| 782 | property_files_string = property_files.Compute(zip_fp) |
| 783 | |
| 784 | tokens = self._parse_property_files_string(property_files_string) |
| 785 | self.assertEqual(5, len(tokens)) |
| 786 | self._verify_entries(zip_file, tokens, entries) |
| 787 | |
| 788 | def test_Finalize(self): |
| 789 | entries = [ |
| 790 | 'payload.bin', |
| 791 | 'payload_properties.txt', |
| 792 | 'care_map.txt', |
| 793 | 'compatibility.zip', |
| 794 | 'META-INF/com/android/metadata', |
| 795 | ] |
Tao Bao | 3bf8c65 | 2018-03-16 12:59:42 -0700 | [diff] [blame] | 796 | zip_file = self.construct_zip_package(entries) |
Tao Bao | 6920352 | 2018-03-08 16:09:01 -0800 | [diff] [blame] | 797 | property_files = StreamingPropertyFiles() |
| 798 | with zipfile.ZipFile(zip_file, 'r') as zip_fp: |
Zhomart Mukhamejanov | 603655f | 2018-05-04 12:35:09 -0700 | [diff] [blame] | 799 | raw_metadata = property_files.GetPropertyFilesString( |
Tao Bao | 6920352 | 2018-03-08 16:09:01 -0800 | [diff] [blame] | 800 | zip_fp, reserve_space=False) |
| 801 | streaming_metadata = property_files.Finalize(zip_fp, len(raw_metadata)) |
| 802 | tokens = self._parse_property_files_string(streaming_metadata) |
| 803 | |
| 804 | self.assertEqual(5, len(tokens)) |
| 805 | # 'META-INF/com/android/metadata' will be key'd as 'metadata' in the |
| 806 | # streaming metadata. |
| 807 | entries[4] = 'metadata' |
| 808 | self._verify_entries(zip_file, tokens, entries) |
| 809 | |
| 810 | def test_Verify(self): |
| 811 | entries = ( |
| 812 | 'payload.bin', |
| 813 | 'payload_properties.txt', |
| 814 | 'care_map.txt', |
| 815 | 'compatibility.zip', |
Tao Bao | ae5e4c3 | 2018-03-01 19:30:00 -0800 | [diff] [blame] | 816 | 'META-INF/com/android/metadata', |
| 817 | ) |
Tao Bao | 3bf8c65 | 2018-03-16 12:59:42 -0700 | [diff] [blame] | 818 | zip_file = self.construct_zip_package(entries) |
Tao Bao | ae5e4c3 | 2018-03-01 19:30:00 -0800 | [diff] [blame] | 819 | property_files = StreamingPropertyFiles() |
| 820 | with zipfile.ZipFile(zip_file, 'r') as zip_fp: |
| 821 | # First get the raw metadata string (i.e. without padding space). |
Zhomart Mukhamejanov | 603655f | 2018-05-04 12:35:09 -0700 | [diff] [blame] | 822 | raw_metadata = property_files.GetPropertyFilesString( |
Tao Bao | ae5e4c3 | 2018-03-01 19:30:00 -0800 | [diff] [blame] | 823 | zip_fp, reserve_space=False) |
| 824 | |
| 825 | # Should pass the test if verification passes. |
| 826 | property_files.Verify(zip_fp, raw_metadata) |
| 827 | |
| 828 | # Or raise on verification failure. |
| 829 | self.assertRaises( |
| 830 | AssertionError, property_files.Verify, zip_fp, raw_metadata + 'x') |
| 831 | |
Tao Bao | fabe083 | 2018-01-17 15:52:28 -0800 | [diff] [blame] | 832 | |
Tao Bao | b630467 | 2018-03-08 16:28:33 -0800 | [diff] [blame] | 833 | class AbOtaPropertyFilesTest(PropertyFilesTest): |
| 834 | """Additional sanity checks specialized for AbOtaPropertyFiles.""" |
| 835 | |
| 836 | # The size for payload and metadata signature size. |
| 837 | SIGNATURE_SIZE = 256 |
| 838 | |
| 839 | def setUp(self): |
| 840 | self.testdata_dir = test_utils.get_testdata_dir() |
| 841 | self.assertTrue(os.path.exists(self.testdata_dir)) |
| 842 | |
| 843 | common.OPTIONS.wipe_user_data = False |
| 844 | common.OPTIONS.payload_signer = None |
| 845 | common.OPTIONS.payload_signer_args = None |
| 846 | common.OPTIONS.package_key = os.path.join(self.testdata_dir, 'testkey') |
| 847 | common.OPTIONS.key_passwords = { |
| 848 | common.OPTIONS.package_key : None, |
| 849 | } |
| 850 | |
| 851 | def test_init(self): |
| 852 | property_files = AbOtaPropertyFiles() |
| 853 | self.assertEqual('ota-property-files', property_files.name) |
| 854 | self.assertEqual( |
| 855 | ( |
| 856 | 'payload.bin', |
| 857 | 'payload_properties.txt', |
| 858 | ), |
| 859 | property_files.required) |
| 860 | self.assertEqual( |
| 861 | ( |
Tianjie Xu | 4c05f4a | 2018-09-14 16:24:41 -0700 | [diff] [blame] | 862 | 'care_map.pb', |
Tao Bao | b630467 | 2018-03-08 16:28:33 -0800 | [diff] [blame] | 863 | 'care_map.txt', |
| 864 | 'compatibility.zip', |
| 865 | ), |
| 866 | property_files.optional) |
| 867 | |
Tao Bao | 82490d3 | 2019-04-09 00:12:30 -0700 | [diff] [blame] | 868 | @test_utils.SkipIfExternalToolsUnavailable() |
Tao Bao | b630467 | 2018-03-08 16:28:33 -0800 | [diff] [blame] | 869 | def test_GetPayloadMetadataOffsetAndSize(self): |
| 870 | target_file = construct_target_files() |
| 871 | payload = Payload() |
| 872 | payload.Generate(target_file) |
| 873 | |
| 874 | payload_signer = PayloadSigner() |
| 875 | payload.Sign(payload_signer) |
| 876 | |
| 877 | output_file = common.MakeTempFile(suffix='.zip') |
| 878 | with zipfile.ZipFile(output_file, 'w') as output_zip: |
| 879 | payload.WriteToZip(output_zip) |
| 880 | |
| 881 | # Find out the payload metadata offset and size. |
| 882 | property_files = AbOtaPropertyFiles() |
| 883 | with zipfile.ZipFile(output_file) as input_zip: |
| 884 | # pylint: disable=protected-access |
| 885 | payload_offset, metadata_total = ( |
| 886 | property_files._GetPayloadMetadataOffsetAndSize(input_zip)) |
| 887 | |
| 888 | # Read in the metadata signature directly. |
| 889 | with open(output_file, 'rb') as verify_fp: |
| 890 | verify_fp.seek(payload_offset + metadata_total - self.SIGNATURE_SIZE) |
| 891 | metadata_signature = verify_fp.read(self.SIGNATURE_SIZE) |
| 892 | |
| 893 | # Now we extract the metadata hash via brillo_update_payload script, which |
| 894 | # will serve as the oracle result. |
| 895 | payload_sig_file = common.MakeTempFile(prefix="sig-", suffix=".bin") |
| 896 | metadata_sig_file = common.MakeTempFile(prefix="sig-", suffix=".bin") |
| 897 | cmd = ['brillo_update_payload', 'hash', |
| 898 | '--unsigned_payload', payload.payload_file, |
| 899 | '--signature_size', str(self.SIGNATURE_SIZE), |
| 900 | '--metadata_hash_file', metadata_sig_file, |
| 901 | '--payload_hash_file', payload_sig_file] |
Tao Bao | 73dd4f4 | 2018-10-04 16:25:33 -0700 | [diff] [blame] | 902 | proc = common.Run(cmd) |
Tao Bao | b630467 | 2018-03-08 16:28:33 -0800 | [diff] [blame] | 903 | stdoutdata, _ = proc.communicate() |
| 904 | self.assertEqual( |
| 905 | 0, proc.returncode, |
Tao Bao | 73dd4f4 | 2018-10-04 16:25:33 -0700 | [diff] [blame] | 906 | 'Failed to run brillo_update_payload:\n{}'.format(stdoutdata)) |
Tao Bao | b630467 | 2018-03-08 16:28:33 -0800 | [diff] [blame] | 907 | |
| 908 | signed_metadata_sig_file = payload_signer.Sign(metadata_sig_file) |
| 909 | |
| 910 | # Finally we can compare the two signatures. |
| 911 | with open(signed_metadata_sig_file, 'rb') as verify_fp: |
| 912 | self.assertEqual(verify_fp.read(), metadata_signature) |
| 913 | |
| 914 | @staticmethod |
Tao Bao | 3bf8c65 | 2018-03-16 12:59:42 -0700 | [diff] [blame] | 915 | def construct_zip_package_withValidPayload(with_metadata=False): |
| 916 | # Cannot use construct_zip_package() since we need a "valid" payload.bin. |
Tao Bao | b630467 | 2018-03-08 16:28:33 -0800 | [diff] [blame] | 917 | target_file = construct_target_files() |
| 918 | payload = Payload() |
| 919 | payload.Generate(target_file) |
| 920 | |
| 921 | payload_signer = PayloadSigner() |
| 922 | payload.Sign(payload_signer) |
| 923 | |
| 924 | zip_file = common.MakeTempFile(suffix='.zip') |
| 925 | with zipfile.ZipFile(zip_file, 'w') as zip_fp: |
| 926 | # 'payload.bin', |
| 927 | payload.WriteToZip(zip_fp) |
| 928 | |
| 929 | # Other entries. |
| 930 | entries = ['care_map.txt', 'compatibility.zip'] |
| 931 | |
| 932 | # Put META-INF/com/android/metadata if needed. |
| 933 | if with_metadata: |
| 934 | entries.append('META-INF/com/android/metadata') |
| 935 | |
| 936 | for entry in entries: |
| 937 | zip_fp.writestr( |
| 938 | entry, entry.replace('.', '-').upper(), zipfile.ZIP_STORED) |
| 939 | |
| 940 | return zip_file |
| 941 | |
Tao Bao | 82490d3 | 2019-04-09 00:12:30 -0700 | [diff] [blame] | 942 | @test_utils.SkipIfExternalToolsUnavailable() |
Tao Bao | b630467 | 2018-03-08 16:28:33 -0800 | [diff] [blame] | 943 | def test_Compute(self): |
Tao Bao | 3bf8c65 | 2018-03-16 12:59:42 -0700 | [diff] [blame] | 944 | zip_file = self.construct_zip_package_withValidPayload() |
Tao Bao | b630467 | 2018-03-08 16:28:33 -0800 | [diff] [blame] | 945 | property_files = AbOtaPropertyFiles() |
| 946 | with zipfile.ZipFile(zip_file, 'r') as zip_fp: |
| 947 | property_files_string = property_files.Compute(zip_fp) |
| 948 | |
| 949 | tokens = self._parse_property_files_string(property_files_string) |
| 950 | # "6" indcludes the four entries above, one metadata entry, and one entry |
| 951 | # for payload-metadata.bin. |
| 952 | self.assertEqual(6, len(tokens)) |
| 953 | self._verify_entries( |
| 954 | zip_file, tokens, ('care_map.txt', 'compatibility.zip')) |
| 955 | |
Tao Bao | 82490d3 | 2019-04-09 00:12:30 -0700 | [diff] [blame] | 956 | @test_utils.SkipIfExternalToolsUnavailable() |
Tao Bao | b630467 | 2018-03-08 16:28:33 -0800 | [diff] [blame] | 957 | def test_Finalize(self): |
Tao Bao | 3bf8c65 | 2018-03-16 12:59:42 -0700 | [diff] [blame] | 958 | zip_file = self.construct_zip_package_withValidPayload(with_metadata=True) |
Tao Bao | b630467 | 2018-03-08 16:28:33 -0800 | [diff] [blame] | 959 | property_files = AbOtaPropertyFiles() |
| 960 | with zipfile.ZipFile(zip_file, 'r') as zip_fp: |
Zhomart Mukhamejanov | 603655f | 2018-05-04 12:35:09 -0700 | [diff] [blame] | 961 | raw_metadata = property_files.GetPropertyFilesString( |
Tao Bao | b630467 | 2018-03-08 16:28:33 -0800 | [diff] [blame] | 962 | zip_fp, reserve_space=False) |
| 963 | property_files_string = property_files.Finalize(zip_fp, len(raw_metadata)) |
| 964 | |
| 965 | tokens = self._parse_property_files_string(property_files_string) |
| 966 | # "6" indcludes the four entries above, one metadata entry, and one entry |
| 967 | # for payload-metadata.bin. |
| 968 | self.assertEqual(6, len(tokens)) |
| 969 | self._verify_entries( |
| 970 | zip_file, tokens, ('care_map.txt', 'compatibility.zip')) |
| 971 | |
Tao Bao | 82490d3 | 2019-04-09 00:12:30 -0700 | [diff] [blame] | 972 | @test_utils.SkipIfExternalToolsUnavailable() |
Tao Bao | b630467 | 2018-03-08 16:28:33 -0800 | [diff] [blame] | 973 | def test_Verify(self): |
Tao Bao | 3bf8c65 | 2018-03-16 12:59:42 -0700 | [diff] [blame] | 974 | zip_file = self.construct_zip_package_withValidPayload(with_metadata=True) |
Tao Bao | b630467 | 2018-03-08 16:28:33 -0800 | [diff] [blame] | 975 | property_files = AbOtaPropertyFiles() |
| 976 | with zipfile.ZipFile(zip_file, 'r') as zip_fp: |
Zhomart Mukhamejanov | 603655f | 2018-05-04 12:35:09 -0700 | [diff] [blame] | 977 | raw_metadata = property_files.GetPropertyFilesString( |
Tao Bao | b630467 | 2018-03-08 16:28:33 -0800 | [diff] [blame] | 978 | zip_fp, reserve_space=False) |
| 979 | |
| 980 | property_files.Verify(zip_fp, raw_metadata) |
| 981 | |
| 982 | |
Tao Bao | c0746f4 | 2018-02-21 13:17:22 -0800 | [diff] [blame] | 983 | class NonAbOtaPropertyFilesTest(PropertyFilesTest): |
| 984 | """Additional sanity checks specialized for NonAbOtaPropertyFiles.""" |
| 985 | |
| 986 | def test_init(self): |
| 987 | property_files = NonAbOtaPropertyFiles() |
| 988 | self.assertEqual('ota-property-files', property_files.name) |
| 989 | self.assertEqual((), property_files.required) |
| 990 | self.assertEqual((), property_files.optional) |
| 991 | |
| 992 | def test_Compute(self): |
| 993 | entries = () |
Tao Bao | 3bf8c65 | 2018-03-16 12:59:42 -0700 | [diff] [blame] | 994 | zip_file = self.construct_zip_package(entries) |
Tao Bao | c0746f4 | 2018-02-21 13:17:22 -0800 | [diff] [blame] | 995 | property_files = NonAbOtaPropertyFiles() |
| 996 | with zipfile.ZipFile(zip_file) as zip_fp: |
| 997 | property_files_string = property_files.Compute(zip_fp) |
| 998 | |
| 999 | tokens = self._parse_property_files_string(property_files_string) |
| 1000 | self.assertEqual(1, len(tokens)) |
| 1001 | self._verify_entries(zip_file, tokens, entries) |
| 1002 | |
| 1003 | def test_Finalize(self): |
| 1004 | entries = [ |
| 1005 | 'META-INF/com/android/metadata', |
| 1006 | ] |
Tao Bao | 3bf8c65 | 2018-03-16 12:59:42 -0700 | [diff] [blame] | 1007 | zip_file = self.construct_zip_package(entries) |
Tao Bao | c0746f4 | 2018-02-21 13:17:22 -0800 | [diff] [blame] | 1008 | property_files = NonAbOtaPropertyFiles() |
| 1009 | with zipfile.ZipFile(zip_file) as zip_fp: |
Zhomart Mukhamejanov | 603655f | 2018-05-04 12:35:09 -0700 | [diff] [blame] | 1010 | raw_metadata = property_files.GetPropertyFilesString( |
Tao Bao | c0746f4 | 2018-02-21 13:17:22 -0800 | [diff] [blame] | 1011 | zip_fp, reserve_space=False) |
| 1012 | property_files_string = property_files.Finalize(zip_fp, len(raw_metadata)) |
| 1013 | tokens = self._parse_property_files_string(property_files_string) |
| 1014 | |
| 1015 | self.assertEqual(1, len(tokens)) |
| 1016 | # 'META-INF/com/android/metadata' will be key'd as 'metadata'. |
| 1017 | entries[0] = 'metadata' |
| 1018 | self._verify_entries(zip_file, tokens, entries) |
| 1019 | |
| 1020 | def test_Verify(self): |
| 1021 | entries = ( |
| 1022 | 'META-INF/com/android/metadata', |
| 1023 | ) |
Tao Bao | 3bf8c65 | 2018-03-16 12:59:42 -0700 | [diff] [blame] | 1024 | zip_file = self.construct_zip_package(entries) |
Tao Bao | c0746f4 | 2018-02-21 13:17:22 -0800 | [diff] [blame] | 1025 | property_files = NonAbOtaPropertyFiles() |
| 1026 | with zipfile.ZipFile(zip_file) as zip_fp: |
Zhomart Mukhamejanov | 603655f | 2018-05-04 12:35:09 -0700 | [diff] [blame] | 1027 | raw_metadata = property_files.GetPropertyFilesString( |
Tao Bao | c0746f4 | 2018-02-21 13:17:22 -0800 | [diff] [blame] | 1028 | zip_fp, reserve_space=False) |
| 1029 | |
| 1030 | property_files.Verify(zip_fp, raw_metadata) |
| 1031 | |
| 1032 | |
Tao Bao | 65b94e9 | 2018-10-11 21:57:26 -0700 | [diff] [blame] | 1033 | class PayloadSignerTest(test_utils.ReleaseToolsTestCase): |
Tao Bao | fabe083 | 2018-01-17 15:52:28 -0800 | [diff] [blame] | 1034 | |
| 1035 | SIGFILE = 'sigfile.bin' |
| 1036 | SIGNED_SIGFILE = 'signed-sigfile.bin' |
| 1037 | |
| 1038 | def setUp(self): |
Tao Bao | 04e1f01 | 2018-02-04 12:13:35 -0800 | [diff] [blame] | 1039 | self.testdata_dir = test_utils.get_testdata_dir() |
Tao Bao | fabe083 | 2018-01-17 15:52:28 -0800 | [diff] [blame] | 1040 | self.assertTrue(os.path.exists(self.testdata_dir)) |
| 1041 | |
| 1042 | common.OPTIONS.payload_signer = None |
| 1043 | common.OPTIONS.payload_signer_args = [] |
| 1044 | common.OPTIONS.package_key = os.path.join(self.testdata_dir, 'testkey') |
| 1045 | common.OPTIONS.key_passwords = { |
| 1046 | common.OPTIONS.package_key : None, |
| 1047 | } |
| 1048 | |
Tao Bao | fabe083 | 2018-01-17 15:52:28 -0800 | [diff] [blame] | 1049 | def _assertFilesEqual(self, file1, file2): |
| 1050 | with open(file1, 'rb') as fp1, open(file2, 'rb') as fp2: |
| 1051 | self.assertEqual(fp1.read(), fp2.read()) |
| 1052 | |
| 1053 | def test_init(self): |
| 1054 | payload_signer = PayloadSigner() |
| 1055 | self.assertEqual('openssl', payload_signer.signer) |
xunchang | 376cc7c | 2019-04-08 23:04:58 -0700 | [diff] [blame] | 1056 | self.assertEqual(256, payload_signer.key_size) |
Tao Bao | fabe083 | 2018-01-17 15:52:28 -0800 | [diff] [blame] | 1057 | |
| 1058 | def test_init_withPassword(self): |
| 1059 | common.OPTIONS.package_key = os.path.join( |
| 1060 | self.testdata_dir, 'testkey_with_passwd') |
| 1061 | common.OPTIONS.key_passwords = { |
| 1062 | common.OPTIONS.package_key : 'foo', |
| 1063 | } |
| 1064 | payload_signer = PayloadSigner() |
| 1065 | self.assertEqual('openssl', payload_signer.signer) |
| 1066 | |
| 1067 | def test_init_withExternalSigner(self): |
| 1068 | common.OPTIONS.payload_signer = 'abc' |
| 1069 | common.OPTIONS.payload_signer_args = ['arg1', 'arg2'] |
xunchang | 376cc7c | 2019-04-08 23:04:58 -0700 | [diff] [blame] | 1070 | common.OPTIONS.payload_signer_key_size = '512' |
Tao Bao | fabe083 | 2018-01-17 15:52:28 -0800 | [diff] [blame] | 1071 | payload_signer = PayloadSigner() |
| 1072 | self.assertEqual('abc', payload_signer.signer) |
| 1073 | self.assertEqual(['arg1', 'arg2'], payload_signer.signer_args) |
xunchang | 376cc7c | 2019-04-08 23:04:58 -0700 | [diff] [blame] | 1074 | self.assertEqual(512, payload_signer.key_size) |
| 1075 | |
| 1076 | def test_GetKeySizeInBytes_512Bytes(self): |
| 1077 | signing_key = os.path.join(self.testdata_dir, 'testkey_RSA4096.key') |
Tao Bao | 82490d3 | 2019-04-09 00:12:30 -0700 | [diff] [blame] | 1078 | # pylint: disable=protected-access |
xunchang | 376cc7c | 2019-04-08 23:04:58 -0700 | [diff] [blame] | 1079 | key_size = PayloadSigner._GetKeySizeInBytes(signing_key) |
| 1080 | self.assertEqual(512, key_size) |
Tao Bao | fabe083 | 2018-01-17 15:52:28 -0800 | [diff] [blame] | 1081 | |
| 1082 | def test_Sign(self): |
| 1083 | payload_signer = PayloadSigner() |
| 1084 | input_file = os.path.join(self.testdata_dir, self.SIGFILE) |
| 1085 | signed_file = payload_signer.Sign(input_file) |
| 1086 | |
| 1087 | verify_file = os.path.join(self.testdata_dir, self.SIGNED_SIGFILE) |
| 1088 | self._assertFilesEqual(verify_file, signed_file) |
| 1089 | |
| 1090 | def test_Sign_withExternalSigner_openssl(self): |
| 1091 | """Uses openssl as the external payload signer.""" |
| 1092 | common.OPTIONS.payload_signer = 'openssl' |
| 1093 | common.OPTIONS.payload_signer_args = [ |
| 1094 | 'pkeyutl', '-sign', '-keyform', 'DER', '-inkey', |
| 1095 | os.path.join(self.testdata_dir, 'testkey.pk8'), |
| 1096 | '-pkeyopt', 'digest:sha256'] |
| 1097 | payload_signer = PayloadSigner() |
| 1098 | input_file = os.path.join(self.testdata_dir, self.SIGFILE) |
| 1099 | signed_file = payload_signer.Sign(input_file) |
| 1100 | |
| 1101 | verify_file = os.path.join(self.testdata_dir, self.SIGNED_SIGFILE) |
| 1102 | self._assertFilesEqual(verify_file, signed_file) |
| 1103 | |
| 1104 | def test_Sign_withExternalSigner_script(self): |
| 1105 | """Uses testdata/payload_signer.sh as the external payload signer.""" |
| 1106 | common.OPTIONS.payload_signer = os.path.join( |
| 1107 | self.testdata_dir, 'payload_signer.sh') |
Tao Bao | 30e3114 | 2019-04-09 00:12:30 -0700 | [diff] [blame] | 1108 | os.chmod(common.OPTIONS.payload_signer, 0o700) |
Tao Bao | fabe083 | 2018-01-17 15:52:28 -0800 | [diff] [blame] | 1109 | common.OPTIONS.payload_signer_args = [ |
| 1110 | os.path.join(self.testdata_dir, 'testkey.pk8')] |
| 1111 | payload_signer = PayloadSigner() |
| 1112 | input_file = os.path.join(self.testdata_dir, self.SIGFILE) |
| 1113 | signed_file = payload_signer.Sign(input_file) |
| 1114 | |
| 1115 | verify_file = os.path.join(self.testdata_dir, self.SIGNED_SIGFILE) |
| 1116 | self._assertFilesEqual(verify_file, signed_file) |
Tao Bao | c7b403a | 2018-01-30 18:19:04 -0800 | [diff] [blame] | 1117 | |
| 1118 | |
Tao Bao | 65b94e9 | 2018-10-11 21:57:26 -0700 | [diff] [blame] | 1119 | class PayloadTest(test_utils.ReleaseToolsTestCase): |
Tao Bao | c7b403a | 2018-01-30 18:19:04 -0800 | [diff] [blame] | 1120 | |
| 1121 | def setUp(self): |
Tao Bao | 04e1f01 | 2018-02-04 12:13:35 -0800 | [diff] [blame] | 1122 | self.testdata_dir = test_utils.get_testdata_dir() |
Tao Bao | c7b403a | 2018-01-30 18:19:04 -0800 | [diff] [blame] | 1123 | self.assertTrue(os.path.exists(self.testdata_dir)) |
| 1124 | |
| 1125 | common.OPTIONS.wipe_user_data = False |
| 1126 | common.OPTIONS.payload_signer = None |
| 1127 | common.OPTIONS.payload_signer_args = None |
| 1128 | common.OPTIONS.package_key = os.path.join(self.testdata_dir, 'testkey') |
| 1129 | common.OPTIONS.key_passwords = { |
| 1130 | common.OPTIONS.package_key : None, |
| 1131 | } |
| 1132 | |
Tao Bao | c7b403a | 2018-01-30 18:19:04 -0800 | [diff] [blame] | 1133 | @staticmethod |
Tao Bao | f7140c0 | 2018-01-30 17:09:24 -0800 | [diff] [blame] | 1134 | def _create_payload_full(secondary=False): |
| 1135 | target_file = construct_target_files(secondary) |
Tao Bao | 667ff57 | 2018-02-10 00:02:40 -0800 | [diff] [blame] | 1136 | payload = Payload(secondary) |
Tao Bao | c7b403a | 2018-01-30 18:19:04 -0800 | [diff] [blame] | 1137 | payload.Generate(target_file) |
| 1138 | return payload |
| 1139 | |
Tao Bao | f7140c0 | 2018-01-30 17:09:24 -0800 | [diff] [blame] | 1140 | @staticmethod |
| 1141 | def _create_payload_incremental(): |
| 1142 | target_file = construct_target_files() |
| 1143 | source_file = construct_target_files() |
Tao Bao | c7b403a | 2018-01-30 18:19:04 -0800 | [diff] [blame] | 1144 | payload = Payload() |
| 1145 | payload.Generate(target_file, source_file) |
| 1146 | return payload |
| 1147 | |
Tao Bao | 82490d3 | 2019-04-09 00:12:30 -0700 | [diff] [blame] | 1148 | @test_utils.SkipIfExternalToolsUnavailable() |
Tao Bao | c7b403a | 2018-01-30 18:19:04 -0800 | [diff] [blame] | 1149 | def test_Generate_full(self): |
| 1150 | payload = self._create_payload_full() |
| 1151 | self.assertTrue(os.path.exists(payload.payload_file)) |
| 1152 | |
Tao Bao | 82490d3 | 2019-04-09 00:12:30 -0700 | [diff] [blame] | 1153 | @test_utils.SkipIfExternalToolsUnavailable() |
Tao Bao | c7b403a | 2018-01-30 18:19:04 -0800 | [diff] [blame] | 1154 | def test_Generate_incremental(self): |
| 1155 | payload = self._create_payload_incremental() |
| 1156 | self.assertTrue(os.path.exists(payload.payload_file)) |
| 1157 | |
Tao Bao | 82490d3 | 2019-04-09 00:12:30 -0700 | [diff] [blame] | 1158 | @test_utils.SkipIfExternalToolsUnavailable() |
Tao Bao | c7b403a | 2018-01-30 18:19:04 -0800 | [diff] [blame] | 1159 | def test_Generate_additionalArgs(self): |
Tao Bao | f7140c0 | 2018-01-30 17:09:24 -0800 | [diff] [blame] | 1160 | target_file = construct_target_files() |
| 1161 | source_file = construct_target_files() |
Tao Bao | c7b403a | 2018-01-30 18:19:04 -0800 | [diff] [blame] | 1162 | payload = Payload() |
| 1163 | # This should work the same as calling payload.Generate(target_file, |
| 1164 | # source_file). |
| 1165 | payload.Generate( |
| 1166 | target_file, additional_args=["--source_image", source_file]) |
| 1167 | self.assertTrue(os.path.exists(payload.payload_file)) |
| 1168 | |
Tao Bao | 82490d3 | 2019-04-09 00:12:30 -0700 | [diff] [blame] | 1169 | @test_utils.SkipIfExternalToolsUnavailable() |
Tao Bao | c7b403a | 2018-01-30 18:19:04 -0800 | [diff] [blame] | 1170 | def test_Generate_invalidInput(self): |
Tao Bao | f7140c0 | 2018-01-30 17:09:24 -0800 | [diff] [blame] | 1171 | target_file = construct_target_files() |
Tao Bao | c7b403a | 2018-01-30 18:19:04 -0800 | [diff] [blame] | 1172 | common.ZipDelete(target_file, 'IMAGES/vendor.img') |
| 1173 | payload = Payload() |
Tao Bao | bec89c1 | 2018-10-15 11:53:28 -0700 | [diff] [blame] | 1174 | self.assertRaises(common.ExternalError, payload.Generate, target_file) |
Tao Bao | c7b403a | 2018-01-30 18:19:04 -0800 | [diff] [blame] | 1175 | |
Tao Bao | 82490d3 | 2019-04-09 00:12:30 -0700 | [diff] [blame] | 1176 | @test_utils.SkipIfExternalToolsUnavailable() |
Tao Bao | c7b403a | 2018-01-30 18:19:04 -0800 | [diff] [blame] | 1177 | def test_Sign_full(self): |
| 1178 | payload = self._create_payload_full() |
| 1179 | payload.Sign(PayloadSigner()) |
| 1180 | |
| 1181 | output_file = common.MakeTempFile(suffix='.zip') |
| 1182 | with zipfile.ZipFile(output_file, 'w') as output_zip: |
| 1183 | payload.WriteToZip(output_zip) |
| 1184 | |
| 1185 | import check_ota_package_signature |
| 1186 | check_ota_package_signature.VerifyAbOtaPayload( |
| 1187 | os.path.join(self.testdata_dir, 'testkey.x509.pem'), |
| 1188 | output_file) |
| 1189 | |
Tao Bao | 82490d3 | 2019-04-09 00:12:30 -0700 | [diff] [blame] | 1190 | @test_utils.SkipIfExternalToolsUnavailable() |
Tao Bao | c7b403a | 2018-01-30 18:19:04 -0800 | [diff] [blame] | 1191 | def test_Sign_incremental(self): |
| 1192 | payload = self._create_payload_incremental() |
| 1193 | payload.Sign(PayloadSigner()) |
| 1194 | |
| 1195 | output_file = common.MakeTempFile(suffix='.zip') |
| 1196 | with zipfile.ZipFile(output_file, 'w') as output_zip: |
| 1197 | payload.WriteToZip(output_zip) |
| 1198 | |
| 1199 | import check_ota_package_signature |
| 1200 | check_ota_package_signature.VerifyAbOtaPayload( |
| 1201 | os.path.join(self.testdata_dir, 'testkey.x509.pem'), |
| 1202 | output_file) |
| 1203 | |
Tao Bao | 82490d3 | 2019-04-09 00:12:30 -0700 | [diff] [blame] | 1204 | @test_utils.SkipIfExternalToolsUnavailable() |
Tao Bao | c7b403a | 2018-01-30 18:19:04 -0800 | [diff] [blame] | 1205 | def test_Sign_withDataWipe(self): |
| 1206 | common.OPTIONS.wipe_user_data = True |
| 1207 | payload = self._create_payload_full() |
| 1208 | payload.Sign(PayloadSigner()) |
| 1209 | |
| 1210 | with open(payload.payload_properties) as properties_fp: |
| 1211 | self.assertIn("POWERWASH=1", properties_fp.read()) |
| 1212 | |
Tao Bao | 82490d3 | 2019-04-09 00:12:30 -0700 | [diff] [blame] | 1213 | @test_utils.SkipIfExternalToolsUnavailable() |
Tao Bao | 667ff57 | 2018-02-10 00:02:40 -0800 | [diff] [blame] | 1214 | def test_Sign_secondary(self): |
| 1215 | payload = self._create_payload_full(secondary=True) |
| 1216 | payload.Sign(PayloadSigner()) |
| 1217 | |
| 1218 | with open(payload.payload_properties) as properties_fp: |
| 1219 | self.assertIn("SWITCH_SLOT_ON_REBOOT=0", properties_fp.read()) |
| 1220 | |
Tao Bao | 82490d3 | 2019-04-09 00:12:30 -0700 | [diff] [blame] | 1221 | @test_utils.SkipIfExternalToolsUnavailable() |
Tao Bao | c7b403a | 2018-01-30 18:19:04 -0800 | [diff] [blame] | 1222 | def test_Sign_badSigner(self): |
| 1223 | """Tests that signing failure can be captured.""" |
| 1224 | payload = self._create_payload_full() |
| 1225 | payload_signer = PayloadSigner() |
| 1226 | payload_signer.signer_args.append('bad-option') |
Tao Bao | bec89c1 | 2018-10-15 11:53:28 -0700 | [diff] [blame] | 1227 | self.assertRaises(common.ExternalError, payload.Sign, payload_signer) |
Tao Bao | c7b403a | 2018-01-30 18:19:04 -0800 | [diff] [blame] | 1228 | |
Tao Bao | 82490d3 | 2019-04-09 00:12:30 -0700 | [diff] [blame] | 1229 | @test_utils.SkipIfExternalToolsUnavailable() |
Tao Bao | c7b403a | 2018-01-30 18:19:04 -0800 | [diff] [blame] | 1230 | def test_WriteToZip(self): |
| 1231 | payload = self._create_payload_full() |
| 1232 | payload.Sign(PayloadSigner()) |
| 1233 | |
| 1234 | output_file = common.MakeTempFile(suffix='.zip') |
| 1235 | with zipfile.ZipFile(output_file, 'w') as output_zip: |
| 1236 | payload.WriteToZip(output_zip) |
| 1237 | |
| 1238 | with zipfile.ZipFile(output_file) as verify_zip: |
| 1239 | # First make sure we have the essential entries. |
| 1240 | namelist = verify_zip.namelist() |
| 1241 | self.assertIn(Payload.PAYLOAD_BIN, namelist) |
| 1242 | self.assertIn(Payload.PAYLOAD_PROPERTIES_TXT, namelist) |
| 1243 | |
| 1244 | # Then assert these entries are stored. |
| 1245 | for entry_info in verify_zip.infolist(): |
| 1246 | if entry_info.filename not in (Payload.PAYLOAD_BIN, |
| 1247 | Payload.PAYLOAD_PROPERTIES_TXT): |
| 1248 | continue |
| 1249 | self.assertEqual(zipfile.ZIP_STORED, entry_info.compress_type) |
| 1250 | |
Tao Bao | 82490d3 | 2019-04-09 00:12:30 -0700 | [diff] [blame] | 1251 | @test_utils.SkipIfExternalToolsUnavailable() |
Tao Bao | c7b403a | 2018-01-30 18:19:04 -0800 | [diff] [blame] | 1252 | def test_WriteToZip_unsignedPayload(self): |
| 1253 | """Unsigned payloads should not be allowed to be written to zip.""" |
| 1254 | payload = self._create_payload_full() |
| 1255 | |
| 1256 | output_file = common.MakeTempFile(suffix='.zip') |
| 1257 | with zipfile.ZipFile(output_file, 'w') as output_zip: |
| 1258 | self.assertRaises(AssertionError, payload.WriteToZip, output_zip) |
| 1259 | |
| 1260 | # Also test with incremental payload. |
| 1261 | payload = self._create_payload_incremental() |
| 1262 | |
| 1263 | output_file = common.MakeTempFile(suffix='.zip') |
| 1264 | with zipfile.ZipFile(output_file, 'w') as output_zip: |
| 1265 | self.assertRaises(AssertionError, payload.WriteToZip, output_zip) |
Tao Bao | f7140c0 | 2018-01-30 17:09:24 -0800 | [diff] [blame] | 1266 | |
Tao Bao | 82490d3 | 2019-04-09 00:12:30 -0700 | [diff] [blame] | 1267 | @test_utils.SkipIfExternalToolsUnavailable() |
Tao Bao | f7140c0 | 2018-01-30 17:09:24 -0800 | [diff] [blame] | 1268 | def test_WriteToZip_secondary(self): |
| 1269 | payload = self._create_payload_full(secondary=True) |
| 1270 | payload.Sign(PayloadSigner()) |
| 1271 | |
| 1272 | output_file = common.MakeTempFile(suffix='.zip') |
| 1273 | with zipfile.ZipFile(output_file, 'w') as output_zip: |
Tao Bao | 667ff57 | 2018-02-10 00:02:40 -0800 | [diff] [blame] | 1274 | payload.WriteToZip(output_zip) |
Tao Bao | f7140c0 | 2018-01-30 17:09:24 -0800 | [diff] [blame] | 1275 | |
| 1276 | with zipfile.ZipFile(output_file) as verify_zip: |
| 1277 | # First make sure we have the essential entries. |
| 1278 | namelist = verify_zip.namelist() |
| 1279 | self.assertIn(Payload.SECONDARY_PAYLOAD_BIN, namelist) |
| 1280 | self.assertIn(Payload.SECONDARY_PAYLOAD_PROPERTIES_TXT, namelist) |
| 1281 | |
| 1282 | # Then assert these entries are stored. |
| 1283 | for entry_info in verify_zip.infolist(): |
| 1284 | if entry_info.filename not in ( |
| 1285 | Payload.SECONDARY_PAYLOAD_BIN, |
| 1286 | Payload.SECONDARY_PAYLOAD_PROPERTIES_TXT): |
| 1287 | continue |
| 1288 | self.assertEqual(zipfile.ZIP_STORED, entry_info.compress_type) |