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