blob: bbb4b34461142dbb54f4adf946a50445efda305e [file] [log] [blame]
Don Garrettfb15e322016-06-21 19:12:08 -07001#!/usr/bin/python2
Chris Sosa0356d3b2010-09-16 15:46:22 -07002
3# Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
4# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
6
7"""Unit tests for autoupdate.py."""
8
Don Garrettfb15e322016-06-21 19:12:08 -07009from __future__ import print_function
10
Dale Curtisc9aaf3a2011-08-09 15:47:40 -070011import json
Chris Sosa0356d3b2010-09-16 15:46:22 -070012import os
Chris Sosa6a3697f2013-01-29 16:44:43 -080013import shutil
Chris Sosa7c931362010-10-11 19:49:01 -070014import socket
joychen121fc9b2013-08-02 14:30:30 -070015import tempfile
Chris Sosa0356d3b2010-09-16 15:46:22 -070016import unittest
Chris Sosa0356d3b2010-09-16 15:46:22 -070017
Gilad Arnoldabb352e2012-09-23 01:24:27 -070018import cherrypy
19import mox
20
Chris Sosa0356d3b2010-09-16 15:46:22 -070021import autoupdate
Chris Sosa52148582012-11-15 15:35:58 -080022import autoupdate_lib
Gilad Arnold55a2a372012-10-02 09:46:32 -070023import common_util
joychen7c2054a2013-07-25 11:14:07 -070024import devserver_constants as constants
joychen121fc9b2013-08-02 14:30:30 -070025import xbuddy
Chris Sosa0356d3b2010-09-16 15:46:22 -070026
Gilad Arnoldabb352e2012-09-23 01:24:27 -070027
Chris Sosa0356d3b2010-09-16 15:46:22 -070028_TEST_REQUEST = """
Chris Sosa52148582012-11-15 15:35:58 -080029<client_test xmlns:o="http://www.google.com/update2/request" updaterversion="%(client)s" protocol="3.0">
30 <app version="%(version)s" track="%(track)s" board="%(board)s" />
31 <updatecheck />
32 <event eventresult="%(event_result)d" eventtype="%(event_type)d" />
Chris Sosa0356d3b2010-09-16 15:46:22 -070033</client_test>"""
34
Chris Sosa4b951602014-04-09 20:26:07 -070035# Test request with additional fields needed for full Omaha protocol.
36_FULL_TEST_REQUEST = """
37<client_test xmlns:o="http://www.google.com/update2/request" updaterversion="%(client)s" protocol="3.0">
38 <app version="%(version)s" track="%(track)s" board="%(board)s"
39 hardware_class="Test Device" />
40 <updatecheck />
41 <event eventresult="%(event_result)d" eventtype="%(event_type)d" />
42</client_test>"""
43
Chris Sosa6a3697f2013-01-29 16:44:43 -080044#pylint: disable=W0212
Chris Sosa0356d3b2010-09-16 15:46:22 -070045class AutoupdateTest(mox.MoxTestBase):
Chris Sosa4b951602014-04-09 20:26:07 -070046 """Tests for the autoupdate.Autoupdate class."""
47
Chris Sosa0356d3b2010-09-16 15:46:22 -070048 def setUp(self):
49 mox.MoxTestBase.setUp(self)
Gilad Arnold55a2a372012-10-02 09:46:32 -070050 self.mox.StubOutWithMock(common_util, 'GetFileSize')
51 self.mox.StubOutWithMock(common_util, 'GetFileSha1')
52 self.mox.StubOutWithMock(common_util, 'GetFileSha256')
Chris Sosac4e87842013-08-16 18:04:14 -070053 self.mox.StubOutWithMock(common_util, 'IsInsideChroot')
Chris Sosa52148582012-11-15 15:35:58 -080054 self.mox.StubOutWithMock(autoupdate_lib, 'GetUpdateResponse')
Gilad Arnold0c9c8602012-10-02 23:58:58 -070055 self.mox.StubOutWithMock(autoupdate.Autoupdate, '_GetRemotePayloadAttrs')
Chris Sosa7c931362010-10-11 19:49:01 -070056 self.port = 8080
Chris Sosa0356d3b2010-09-16 15:46:22 -070057 self.test_board = 'test-board'
joychen121fc9b2013-08-02 14:30:30 -070058 self.build_root = tempfile.mkdtemp('autoupdate_build_root')
Chris Sosa0356d3b2010-09-16 15:46:22 -070059 self.latest_dir = '12345_af_12-a1'
60 self.latest_verision = '12345_af_12'
joychen121fc9b2013-08-02 14:30:30 -070061 self.static_image_dir = tempfile.mkdtemp('autoupdate_static_dir')
Chris Sosa7c931362010-10-11 19:49:01 -070062 self.hostname = '%s:%s' % (socket.gethostname(), self.port)
Dale Curtisc9aaf3a2011-08-09 15:47:40 -070063 self.test_dict = {
64 'client': 'ChromeOSUpdateEngine-1.0',
65 'version': 'ForcedUpdate',
Chris Sosa4b951602014-04-09 20:26:07 -070066 'track': 'test-channel',
Dale Curtisc9aaf3a2011-08-09 15:47:40 -070067 'board': self.test_board,
68 'event_result': 2,
69 'event_type': 3
70 }
Chris Sosa0356d3b2010-09-16 15:46:22 -070071 self.test_data = _TEST_REQUEST % self.test_dict
Gilad Arnold0c9c8602012-10-02 23:58:58 -070072 self.sha1 = 12345
Chris Sosa0356d3b2010-09-16 15:46:22 -070073 self.size = 54321
74 self.url = 'http://%s/static/update.gz' % self.hostname
75 self.payload = 'My payload'
Chris Sosaa387a872010-09-29 11:51:36 -070076 self.sha256 = 'SHA LA LA'
Chris Sosa54555862010-10-25 17:26:17 -070077 cherrypy.request.base = 'http://%s' % self.hostname
joychen121fc9b2013-08-02 14:30:30 -070078 common_util.MkDirP(self.static_image_dir)
79 self._xbuddy = xbuddy.XBuddy(False,
joychen121fc9b2013-08-02 14:30:30 -070080 static_dir=self.static_image_dir)
81 self.mox.StubOutWithMock(xbuddy.XBuddy, '_GetArtifact')
Chris Sosa6a3697f2013-01-29 16:44:43 -080082
83 def tearDown(self):
joychen121fc9b2013-08-02 14:30:30 -070084 shutil.rmtree(self.build_root)
Chris Sosa6a3697f2013-01-29 16:44:43 -080085 shutil.rmtree(self.static_image_dir)
Chris Sosa54555862010-10-25 17:26:17 -070086
Gilad Arnold0c9c8602012-10-02 23:58:58 -070087 def _DummyAutoupdateConstructor(self, **kwargs):
Chris Sosa0356d3b2010-09-16 15:46:22 -070088 """Creates a dummy autoupdater. Used to avoid using constructor."""
joychen121fc9b2013-08-02 14:30:30 -070089 dummy = autoupdate.Autoupdate(self._xbuddy,
Chris Sosa7c931362010-10-11 19:49:01 -070090 static_dir=self.static_image_dir,
Gilad Arnold0c9c8602012-10-02 23:58:58 -070091 **kwargs)
Chris Sosa0356d3b2010-09-16 15:46:22 -070092 return dummy
93
Chris Sosa744e1472011-09-07 19:32:50 -070094 def testGetRightSignedDeltaPayloadDir(self):
95 """Test that our directory is what we expect it to be for signed updates."""
Gilad Arnold55a2a372012-10-02 09:46:32 -070096 self.mox.StubOutWithMock(common_util, 'GetFileMd5')
Chris Sosa744e1472011-09-07 19:32:50 -070097 key_path = 'test_key_path'
98 src_image = 'test_src_image'
99 target_image = 'test_target_image'
Gilad Arnold55a2a372012-10-02 09:46:32 -0700100 src_hash = '12345'
101 target_hash = '67890'
102 key_hash = 'abcde'
Chris Sosa744e1472011-09-07 19:32:50 -0700103
Gilad Arnold55a2a372012-10-02 09:46:32 -0700104 common_util.GetFileMd5(src_image).AndReturn(src_hash)
105 common_util.GetFileMd5(target_image).AndReturn(target_hash)
106 common_util.GetFileMd5(key_path).AndReturn(key_hash)
Chris Sosa744e1472011-09-07 19:32:50 -0700107
108 self.mox.ReplayAll()
109 au_mock = self._DummyAutoupdateConstructor()
110 au_mock.private_key = key_path
111 update_dir = au_mock.FindCachedUpdateImageSubDir(src_image, target_image)
Scott Zawalski16954532012-03-20 15:31:36 -0400112 self.assertEqual(os.path.basename(update_dir),
Gabe Black70994862014-09-05 00:50:58 -0700113 '%s_%s+%s' % (src_hash, target_hash, key_hash))
Chris Sosa744e1472011-09-07 19:32:50 -0700114 self.mox.VerifyAll()
115
joychen121fc9b2013-08-02 14:30:30 -0700116 def testGenerateLatestUpdateImage(self):
117 """Test default behavior in response to plain update call."""
118 latest_label = os.path.join(self.test_board, self.latest_dir)
119 # Generate a fake latest image
120 latest_image_dir = os.path.join(self.static_image_dir, latest_label)
121 common_util.MkDirP(latest_image_dir)
122 image = os.path.join(latest_image_dir, constants.TEST_IMAGE_FILE)
123 with open(image, 'w') as fh:
124 fh.write('')
125
Don Garrettf90edf02010-11-16 17:36:14 -0800126 self.mox.StubOutWithMock(autoupdate.Autoupdate,
127 'GenerateUpdateImageWithCache')
Chris Sosa6a3697f2013-01-29 16:44:43 -0800128 au_mock = self._DummyAutoupdateConstructor()
joychen121fc9b2013-08-02 14:30:30 -0700129
Chris Sosac4e87842013-08-16 18:04:14 -0700130 common_util.IsInsideChroot().AndReturn(True)
Bertrand SIMONNETb3ddc292015-04-30 17:26:02 -0700131 self._xbuddy._GetArtifact(
132 [''], board=self.test_board, lookup_only=True, image_dir=None,
133 version=None).AndReturn((latest_label, constants.TEST_IMAGE_FILE))
joychen121fc9b2013-08-02 14:30:30 -0700134
Chris Sosa6a3697f2013-01-29 16:44:43 -0800135 au_mock.GenerateUpdateImageWithCache(
joychen121fc9b2013-08-02 14:30:30 -0700136 os.path.join(self.static_image_dir, self.test_board, self.latest_dir,
Chris Sosa75490802013-09-30 17:21:45 -0700137 constants.TEST_IMAGE_FILE)).AndReturn('update.gz')
Chris Sosa0356d3b2010-09-16 15:46:22 -0700138
139 self.mox.ReplayAll()
joychen121fc9b2013-08-02 14:30:30 -0700140 test_data = _TEST_REQUEST % self.test_dict
141 self.assertTrue(au_mock.HandleUpdatePing(test_data))
Chris Sosa0356d3b2010-09-16 15:46:22 -0700142 self.mox.VerifyAll()
143
144 def testHandleUpdatePingForForcedImage(self):
joychen121fc9b2013-08-02 14:30:30 -0700145 """Test update response to having a forced image."""
Don Garrettf90edf02010-11-16 17:36:14 -0800146 self.mox.StubOutWithMock(autoupdate.Autoupdate,
147 'GenerateUpdateImageWithCache')
Chris Sosa6a3697f2013-01-29 16:44:43 -0800148 self.mox.StubOutWithMock(autoupdate.Autoupdate, '_StoreMetadataToFile')
149 au_mock = self._DummyAutoupdateConstructor()
Chris Sosa0356d3b2010-09-16 15:46:22 -0700150 test_data = _TEST_REQUEST % self.test_dict
151
joychen121fc9b2013-08-02 14:30:30 -0700152 # Generate a fake image
153 forced_image_dir = '/tmp/path_to_force/'
154 forced_image = forced_image_dir + constants.IMAGE_FILE
155 common_util.MkDirP(forced_image_dir)
156 with open(forced_image, 'w') as fh:
Chris Sosa6a3697f2013-01-29 16:44:43 -0800157 fh.write('')
158
joychen18737f32013-08-16 17:18:12 -0700159 cache_image_dir = os.path.join(self.static_image_dir, 'cache')
joychen121fc9b2013-08-02 14:30:30 -0700160
161 # Mock out GenerateUpdateImageWithCache to make an update file in cache
Chris Sosa75490802013-09-30 17:21:45 -0700162 def mock_fn(_image):
Don Garrettfb15e322016-06-21 19:12:08 -0700163 print('mock_fn')
joychen121fc9b2013-08-02 14:30:30 -0700164 # No good way to introduce an update file during execution.
Chris Sosa75490802013-09-30 17:21:45 -0700165 cache_dir = os.path.join(self.static_image_dir, 'cache')
joychen121fc9b2013-08-02 14:30:30 -0700166 common_util.MkDirP(cache_dir)
167 update_image = os.path.join(cache_dir, constants.UPDATE_FILE)
168 with open(update_image, 'w') as fh:
169 fh.write('')
David Zeuthen52ccd012013-10-31 12:58:26 -0700170 metadata_hash = os.path.join(cache_dir, constants.METADATA_HASH_FILE)
171 with open(metadata_hash, 'w') as fh:
172 fh.write('')
joychen121fc9b2013-08-02 14:30:30 -0700173
Chris Sosac4e87842013-08-16 18:04:14 -0700174 common_util.IsInsideChroot().AndReturn(True)
Chris Sosa75490802013-09-30 17:21:45 -0700175 au_mock.GenerateUpdateImageWithCache(forced_image).WithSideEffects(
joychen121fc9b2013-08-02 14:30:30 -0700176 mock_fn).AndReturn('cache')
177
Gilad Arnold55a2a372012-10-02 09:46:32 -0700178 common_util.GetFileSha1(os.path.join(
joychen121fc9b2013-08-02 14:30:30 -0700179 cache_image_dir, 'update.gz')).AndReturn(self.sha1)
Gilad Arnold55a2a372012-10-02 09:46:32 -0700180 common_util.GetFileSha256(os.path.join(
joychen121fc9b2013-08-02 14:30:30 -0700181 cache_image_dir, 'update.gz')).AndReturn(self.sha256)
Gilad Arnold55a2a372012-10-02 09:46:32 -0700182 common_util.GetFileSize(os.path.join(
joychen121fc9b2013-08-02 14:30:30 -0700183 cache_image_dir, 'update.gz')).AndReturn(self.size)
184 au_mock._StoreMetadataToFile(cache_image_dir,
Chris Sosa6a3697f2013-01-29 16:44:43 -0800185 mox.IsA(autoupdate.UpdateMetadata))
joychen121fc9b2013-08-02 14:30:30 -0700186 forced_url = 'http://%s/static/%s/update.gz' % (self.hostname,
joychen18737f32013-08-16 17:18:12 -0700187 'cache')
Chris Sosa52148582012-11-15 15:35:58 -0800188 autoupdate_lib.GetUpdateResponse(
David Zeuthen52ccd012013-10-31 12:58:26 -0700189 self.sha1, self.sha256, self.size, forced_url, False, 0, None, None,
190 '3.0', False).AndReturn(self.payload)
Chris Sosa0356d3b2010-09-16 15:46:22 -0700191
192 self.mox.ReplayAll()
joychen121fc9b2013-08-02 14:30:30 -0700193 au_mock.forced_image = forced_image
Chris Sosa0356d3b2010-09-16 15:46:22 -0700194 self.assertEqual(au_mock.HandleUpdatePing(test_data), self.payload)
195 self.mox.VerifyAll()
196
joychendbfe6c92013-08-16 20:03:49 -0700197 def testHandleForcePregenerateXBuddy(self):
198 """Check pregenerating an xbuddy path.
199
200 A forced image that starts with 'xbuddy:' uses the following path to
201 obtain an update.
202 """
203 self.mox.StubOutWithMock(autoupdate.Autoupdate,
204 'GetUpdateForLabel')
205 au_mock = self._DummyAutoupdateConstructor()
206 au_mock.forced_image = "xbuddy:b/v/a"
207
Don Garrettfb15e322016-06-21 19:12:08 -0700208 self._xbuddy._GetArtifact(
209 ['b', 'v', 'a'],
Gabe Black77f3c202014-09-05 00:43:36 -0700210 image_dir=None).AndReturn(('label', constants.TEST_IMAGE_FILE))
joychen365a5742013-08-21 10:41:18 -0700211
joychendbfe6c92013-08-16 20:03:49 -0700212 au_mock.GetUpdateForLabel(
213 autoupdate.FORCED_UPDATE, 'b/v/a').AndReturn('p')
214 self.mox.ReplayAll()
215
216 au_mock.PreGenerateUpdate()
217 self.mox.VerifyAll()
218
Don Garrett0ad09372010-12-06 16:20:30 -0800219 def testChangeUrlPort(self):
220 r = autoupdate._ChangeUrlPort('http://fuzzy:8080/static', 8085)
221 self.assertEqual(r, 'http://fuzzy:8085/static')
222
223 r = autoupdate._ChangeUrlPort('http://fuzzy/static', 8085)
224 self.assertEqual(r, 'http://fuzzy:8085/static')
225
226 r = autoupdate._ChangeUrlPort('ftp://fuzzy/static', 8085)
227 self.assertEqual(r, 'ftp://fuzzy:8085/static')
228
229 r = autoupdate._ChangeUrlPort('ftp://fuzzy', 8085)
230 self.assertEqual(r, 'ftp://fuzzy:8085')
231
Dale Curtisc9aaf3a2011-08-09 15:47:40 -0700232 def testHandleHostInfoPing(self):
233 au_mock = self._DummyAutoupdateConstructor()
234 self.assertRaises(AssertionError, au_mock.HandleHostInfoPing, None)
235
Gilad Arnold286a0062012-01-12 13:47:02 -0800236 # Setup fake host_infos entry and ensure it comes back to us in one piece.
Dale Curtisc9aaf3a2011-08-09 15:47:40 -0700237 test_ip = '1.2.3.4'
Gilad Arnold286a0062012-01-12 13:47:02 -0800238 au_mock.host_infos.GetInitHostInfo(test_ip).attrs = self.test_dict
Dale Curtisc9aaf3a2011-08-09 15:47:40 -0700239 self.assertEqual(
240 json.loads(au_mock.HandleHostInfoPing(test_ip)), self.test_dict)
241
242 def testHandleSetUpdatePing(self):
243 au_mock = self._DummyAutoupdateConstructor()
244 test_ip = '1.2.3.4'
245 test_label = 'test/old-update'
246 self.assertRaises(
247 AssertionError, au_mock.HandleSetUpdatePing, test_ip, None)
248 self.assertRaises(
249 AssertionError, au_mock.HandleSetUpdatePing, None, test_label)
250 self.assertRaises(
251 AssertionError, au_mock.HandleSetUpdatePing, None, None)
252
253 au_mock.HandleSetUpdatePing(test_ip, test_label)
254 self.assertEqual(
Chris Sosa1885d032012-11-29 17:07:27 -0800255 au_mock.host_infos.GetHostInfo(test_ip).attrs['forced_update_label'],
Gilad Arnold286a0062012-01-12 13:47:02 -0800256 test_label)
Dale Curtisc9aaf3a2011-08-09 15:47:40 -0700257
258 def testHandleUpdatePingWithSetUpdate(self):
joychen7c2054a2013-07-25 11:14:07 -0700259 """If update is set, it should use the update found in that directory."""
Chris Sosa6a3697f2013-01-29 16:44:43 -0800260 self.mox.StubOutWithMock(autoupdate.Autoupdate, '_StoreMetadataToFile')
261 au_mock = self._DummyAutoupdateConstructor()
Dale Curtisc9aaf3a2011-08-09 15:47:40 -0700262
263 test_data = _TEST_REQUEST % self.test_dict
264 test_label = 'new_update-test/the-new-update'
265 new_image_dir = os.path.join(self.static_image_dir, test_label)
266 new_url = self.url.replace('update.gz', test_label + '/update.gz')
267
Chris Sosa6a3697f2013-01-29 16:44:43 -0800268 # Generate a fake payload.
joychen121fc9b2013-08-02 14:30:30 -0700269 common_util.MkDirP(new_image_dir)
joychen7c2054a2013-07-25 11:14:07 -0700270 update_gz = os.path.join(new_image_dir, constants.UPDATE_FILE)
Chris Sosa6a3697f2013-01-29 16:44:43 -0800271 with open(update_gz, 'w') as fh:
272 fh.write('')
David Zeuthen52ccd012013-10-31 12:58:26 -0700273 metadata_hash = os.path.join(new_image_dir, constants.METADATA_HASH_FILE)
274 with open(metadata_hash, 'w') as fh:
275 fh.write('')
Chris Sosa6a3697f2013-01-29 16:44:43 -0800276
Gilad Arnold55a2a372012-10-02 09:46:32 -0700277 common_util.GetFileSha1(os.path.join(
Gilad Arnold0c9c8602012-10-02 23:58:58 -0700278 new_image_dir, 'update.gz')).AndReturn(self.sha1)
Gilad Arnold55a2a372012-10-02 09:46:32 -0700279 common_util.GetFileSha256(os.path.join(
Dale Curtisc9aaf3a2011-08-09 15:47:40 -0700280 new_image_dir, 'update.gz')).AndReturn(self.sha256)
Gilad Arnold55a2a372012-10-02 09:46:32 -0700281 common_util.GetFileSize(os.path.join(
Dale Curtisc9aaf3a2011-08-09 15:47:40 -0700282 new_image_dir, 'update.gz')).AndReturn(self.size)
Chris Sosa6a3697f2013-01-29 16:44:43 -0800283 au_mock._StoreMetadataToFile(new_image_dir,
284 mox.IsA(autoupdate.UpdateMetadata))
Chris Sosa52148582012-11-15 15:35:58 -0800285 autoupdate_lib.GetUpdateResponse(
David Zeuthen52ccd012013-10-31 12:58:26 -0700286 self.sha1, self.sha256, self.size, new_url, False, 0, None, None,
287 '3.0', False).AndReturn(self.payload)
Dale Curtisc9aaf3a2011-08-09 15:47:40 -0700288
289 self.mox.ReplayAll()
Dale Curtisc9aaf3a2011-08-09 15:47:40 -0700290 au_mock.HandleSetUpdatePing('127.0.0.1', test_label)
291 self.assertEqual(
Gilad Arnold286a0062012-01-12 13:47:02 -0800292 au_mock.host_infos.GetHostInfo('127.0.0.1').
Chris Sosa1885d032012-11-29 17:07:27 -0800293 attrs['forced_update_label'],
Gilad Arnold286a0062012-01-12 13:47:02 -0800294 test_label)
Dale Curtisc9aaf3a2011-08-09 15:47:40 -0700295 self.assertEqual(au_mock.HandleUpdatePing(test_data), self.payload)
Don Garrettfb15e322016-06-21 19:12:08 -0700296 self.assertFalse(
297 'forced_update_label' in
Gilad Arnold286a0062012-01-12 13:47:02 -0800298 au_mock.host_infos.GetHostInfo('127.0.0.1').attrs)
Dale Curtisc9aaf3a2011-08-09 15:47:40 -0700299
Daniel Erat8a0bc4a2011-09-30 08:52:52 -0700300 def testGetVersionFromDir(self):
301 au = self._DummyAutoupdateConstructor()
302
303 # New-style version number.
304 self.assertEqual(
305 au._GetVersionFromDir('/foo/x86-alex/R16-1102.0.2011_09_30_0806-a1'),
306 '1102.0.2011_09_30_0806')
307
Daniel Erat8a0bc4a2011-09-30 08:52:52 -0700308 def testCanUpdate(self):
309 au = self._DummyAutoupdateConstructor()
310
311 # When both the client and the server have new-style versions, we should
312 # just compare the tokens directly.
313 self.assertTrue(
314 au._CanUpdate('1098.0.2011_09_28_1635', '1098.0.2011_09_30_0806'))
315 self.assertTrue(
316 au._CanUpdate('1098.0.2011_09_28_1635', '1100.0.2011_09_26_0000'))
317 self.assertFalse(
318 au._CanUpdate('1098.0.2011_09_28_1635', '1098.0.2011_09_26_0000'))
319 self.assertFalse(
320 au._CanUpdate('1098.0.2011_09_28_1635', '1096.0.2011_09_30_0000'))
321
Gilad Arnold0c9c8602012-10-02 23:58:58 -0700322 def testHandleUpdatePingRemotePayload(self):
323 remote_urlbase = 'http://remotehost:6666'
324 remote_payload_path = 'static/path/to/update.gz'
325 remote_url = '/'.join([remote_urlbase, remote_payload_path, 'update.gz'])
Chris Sosa6a3697f2013-01-29 16:44:43 -0800326 au_mock = self._DummyAutoupdateConstructor(urlbase=remote_urlbase,
327 payload_path=remote_payload_path,
328 remote_payload=True)
Gilad Arnold0c9c8602012-10-02 23:58:58 -0700329
Chris Sosa4b951602014-04-09 20:26:07 -0700330 incomplete_test_data = _TEST_REQUEST % self.test_dict
331 complete_test_data = _FULL_TEST_REQUEST % self.test_dict
Gilad Arnold0c9c8602012-10-02 23:58:58 -0700332
Chris Sosa6a3697f2013-01-29 16:44:43 -0800333 au_mock._GetRemotePayloadAttrs(remote_url).AndReturn(
David Zeuthen52ccd012013-10-31 12:58:26 -0700334 autoupdate.UpdateMetadata(self.sha1, self.sha256, self.size, False,
335 0, ''))
Chris Sosa52148582012-11-15 15:35:58 -0800336 autoupdate_lib.GetUpdateResponse(
David Zeuthen52ccd012013-10-31 12:58:26 -0700337 self.sha1, self.sha256, self.size, remote_url, False, 0, None, None,
Chris Sosa52148582012-11-15 15:35:58 -0800338 '3.0', False).AndReturn(self.payload)
Gilad Arnold0c9c8602012-10-02 23:58:58 -0700339
340 self.mox.ReplayAll()
Chris Sosa4b951602014-04-09 20:26:07 -0700341 # This should fail because of missing fields.
342 self.assertRaises(common_util.DevServerHTTPError,
343 au_mock.HandleUpdatePing, incomplete_test_data)
344 # This should have enough information.
345 self.assertEqual(au_mock.HandleUpdatePing(complete_test_data), self.payload)
Gilad Arnold0c9c8602012-10-02 23:58:58 -0700346 self.mox.VerifyAll()
347
Chris Sosa0356d3b2010-09-16 15:46:22 -0700348
Gilad Arnoldc65330c2012-09-20 15:17:48 -0700349if __name__ == '__main__':
350 unittest.main()