1# Lint as: python2, python3 2# Copyright 2018 The Chromium OS Authors. All rights reserved. 3# Use of this source code is governed by a BSD-style license that can be 4# found in the LICENSE file. 5 6import logging 7 8from autotest_lib.client.common_lib import error 9from autotest_lib.client.cros.update_engine import nebraska_wrapper 10from autotest_lib.client.cros.update_engine import update_engine_test 11 12class autoupdate_BadMetadata(update_engine_test.UpdateEngineTest): 13 """Tests updates fail when the metadata in the omaha response is invalid.""" 14 version = 1 15 16 _SHA256_ERROR = 'Updating payload state for error code: 10 (' \ 17 'ErrorCode::kPayloadHashMismatchError)' 18 _METADATA_SIZE_ERROR = 'Updating payload state for error code: 32 (' \ 19 'ErrorCode::kDownloadInvalidMetadataSize)' 20 21 22 def run_once(self, payload_url, bad_metadata_size=False, bad_sha256=False): 23 """ 24 Tests update_engine can deal with invalid data in the omaha response. 25 26 @param payload_url: The payload url. 27 @param bad_metadata_size: True if we want to test bad metadata size. 28 @param bad_sha256: True if we want to test bad sha256. 29 30 """ 31 props_to_override = {} 32 error_string = None 33 if bad_sha256: 34 props_to_override[nebraska_wrapper.KEY_SHA256] = 'blahblah' 35 error_string = self._SHA256_ERROR 36 if bad_metadata_size: 37 props_to_override[nebraska_wrapper.KEY_METADATA_SIZE] = 123 38 props_to_override[ 39 nebraska_wrapper.KEY_PUBLIC_KEY] = self._IMAGE_PUBLIC_KEY 40 error_string = self._METADATA_SIZE_ERROR 41 42 with nebraska_wrapper.NebraskaWrapper( 43 log_dir=self.resultsdir, payload_url=payload_url, 44 **props_to_override) as nebraska: 45 46 try: 47 self._check_for_update( 48 nebraska.get_update_url(critical_update=True), 49 wait_for_completion=True) 50 raise error.TestFail('Update completed when it should have ' 51 'failed. Check the update_engine log.') 52 except error.CmdError as e: 53 logging.error(e) 54 self._check_update_engine_log_for_entry(error_string, 55 raise_error=True) 56