Exemple #1
0
 def setUp(self):
     # Start both an HTTP and an HTTPS server running.  The former is for
     # the zip files and the latter is for everything else.  Vend them out
     # of a temporary directory which we load up with the right files.
     self._stack = ExitStack()
     try:
         self._serverdir = self._stack.enter_context(temporary_directory())
         copy('winner.channels_01.json', self._serverdir, 'channels.json')
         sign(os.path.join(self._serverdir, 'channels.json'),
              'image-signing.gpg')
         # Path B will win, with no bootme flags.
         self._indexpath = os.path.join('stable', 'nexus7', 'index.json')
         copy('winner.index_02.json', self._serverdir, self._indexpath)
         sign(os.path.join(self._serverdir, self._indexpath),
              'image-signing.gpg')
         # Create every file in path B.  The file contents will be the
         # checksum value.  We need to create the signatures on the fly.
         setup_index('winner.index_02.json', self._serverdir,
                     'image-signing.gpg')
         self._stack.push(
             make_http_server(self._serverdir, 8943, 'cert.pem', 'key.pem'))
         self._stack.push(make_http_server(self._serverdir, 8980))
     except:
         self._stack.close()
         raise
Exemple #2
0
 def test_download_winners_signed_by_wrong_key(self):
     # There is a device key, but the image files are signed by the image
     # signing key, which according to the spec means the files are not
     # signed correctly.
     setup_keyrings()
     # To set up the device signing key, we need to load this channels.json
     # file and copy the device keyring to the server.
     copy('winner.channels_02.json', self._serverdir, 'channels.json')
     sign(os.path.join(self._serverdir, 'channels.json'),
          'image-signing.gpg')
     setup_keyring_txz(
         'device-signing.gpg', 'image-signing.gpg',
         dict(type='device-signing'),
         os.path.join(self._serverdir, 'stable', 'nexus7', 'device.tar.xz'))
     sign(os.path.join(self._serverdir, self._indexpath),
          'device-signing.gpg')
     # All the downloadable files are now signed with a bogus key.
     setup_index('winner.index_02.json', self._serverdir, 'spare.gpg')
     touch_build(100)
     # Run the state machine until just before we download the files.
     state = State()
     state.run_until('download_files')
     # The next state transition will fail because of the missing signature.
     self.assertRaises(SignatureError, next, state)
     # There are no downloaded files.
     txtfiles = set(filename for filename in os.listdir(config.tempdir)
                    if os.path.splitext(filename)[1] == '.txt')
     self.assertEqual(len(txtfiles), 0)
Exemple #3
0
 def test_download_winners_bad_checksums(self):
     # Similar to the various good paths, except because the checksums are
     # wrong in this index.json file, we'll get a error when downloading.
     copy('winner.index_01.json', self._serverdir, self._indexpath)
     sign(os.path.join(self._serverdir, self._indexpath),
          'image-signing.gpg')
     setup_index('winner.index_01.json', self._serverdir,
                 'image-signing.gpg')
     setup_keyrings()
     state = State()
     touch_build(100)
     # Run the state machine until we're prepped to download
     state.run_until('download_files')
     # Now try to download the files and get the error.
     with self.assertRaises(FileNotFoundError) as cm:
         next(state)
     self.assertIn('HASH ERROR', str(cm.exception))
Exemple #4
0
    def test_download_winners_signed_by_device_key(self):
        # Check that all the winning path's files are downloaded, even when
        # they are signed by the device key instead of the image signing
        # master.
        setup_keyrings()
        # To set up the device signing key, we need to load channels_03.json
        # and copy the device keyring to the server.
        copy('winner.channels_02.json', self._serverdir, 'channels.json')
        sign(os.path.join(self._serverdir, 'channels.json'),
             'image-signing.gpg')
        setup_keyring_txz(
            'device-signing.gpg', 'image-signing.gpg',
            dict(type='device-signing'),
            os.path.join(self._serverdir, 'stable', 'nexus7', 'device.tar.xz'))
        # The index.json file and all the downloadable files must now be
        # signed with the device key.
        sign(os.path.join(self._serverdir, self._indexpath),
             'device-signing.gpg')
        setup_index('winner.index_02.json', self._serverdir,
                    'device-signing.gpg')
        touch_build(100)
        # Run the state machine until we download the files.
        state = State()
        state.run_thru('download_files')

        # The B path files contain their checksums.
        def assert_file_contains(filename, contents):
            path = os.path.join(config.updater.cache_partition, filename)
            with open(path, encoding='utf-8') as fp:
                self.assertEqual(fp.read(), contents)

        assert_file_contains('5.txt', '345')
        assert_file_contains('6.txt', '456')
        assert_file_contains('7.txt', '567')
        # Delta B.1 files.
        assert_file_contains('8.txt', '678')
        assert_file_contains('9.txt', '789')
        assert_file_contains('a.txt', '89a')
        # Delta B.2 files.
        assert_file_contains('b.txt', '9ab')
        assert_file_contains('d.txt', 'fed')
        assert_file_contains('c.txt', 'edc')
 def test_get_details(self):
     # Get the details of an available update.
     self._setup_server_keyrings()
     # Index 14 has a more interesting upgrade path, and will yield a
     # richer description set.
     index_dir = Path(self._serverdir) / self.CHANNEL / self.DEVICE
     index_path = index_dir / 'index.json'
     copy('api.index_02.json', index_dir, 'index.json')
     sign(index_path, 'device-signing.gpg')
     setup_index('api.index_02.json', self._serverdir, 'device-signing.gpg')
     # Get the descriptions.
     update = Mediator().check_for_update()
     self.assertTrue(update.is_available)
     self.assertEqual(update.size, 180009)
     self.assertEqual(len(update.descriptions), 3)
     # The first contains the descriptions for the full update.
     self.assertEqual(update.descriptions[0], {
         'description': 'Full B',
         'description-en': 'The full B',
     })
     # The first delta.
     self.assertEqual(
         update.descriptions[1], {
             'description': 'Delta B.1',
             'description-en_US': 'This is the delta B.1',
             'description-xx': 'XX This is the delta B.1',
             'description-yy': 'YY This is the delta B.1',
             'description-yy_ZZ': 'YY-ZZ This is the delta B.1',
         })
     # The second delta.
     self.assertEqual(
         update.descriptions[2], {
             'description': 'Delta B.2',
             'description-xx': 'Oh delta, my delta',
             'description-xx_CC': 'This hyar is the delta B.2',
         })