blob: 4261f6f196aa85b4101e8b29c36c5da147e1994c [file] [log] [blame]
Chris Sosa0356d3b2010-09-16 15:46:22 -07001#!/usr/bin/python
2
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
Dale Curtisc9aaf3a2011-08-09 15:47:40 -07009import json
Chris Sosa0356d3b2010-09-16 15:46:22 -070010import os
Chris Sosa6a3697f2013-01-29 16:44:43 -080011import shutil
Chris Sosa7c931362010-10-11 19:49:01 -070012import socket
joychen121fc9b2013-08-02 14:30:30 -070013import tempfile
Chris Sosa0356d3b2010-09-16 15:46:22 -070014import unittest
Chris Sosa0356d3b2010-09-16 15:46:22 -070015
Gilad Arnoldabb352e2012-09-23 01:24:27 -070016import cherrypy
17import mox
18
Chris Sosa0356d3b2010-09-16 15:46:22 -070019import autoupdate
Chris Sosa52148582012-11-15 15:35:58 -080020import autoupdate_lib
Gilad Arnold55a2a372012-10-02 09:46:32 -070021import common_util
joychen7c2054a2013-07-25 11:14:07 -070022import devserver_constants as constants
joychen121fc9b2013-08-02 14:30:30 -070023import xbuddy
Chris Sosa0356d3b2010-09-16 15:46:22 -070024
Gilad Arnoldabb352e2012-09-23 01:24:27 -070025
Chris Sosa0356d3b2010-09-16 15:46:22 -070026_TEST_REQUEST = """
Chris Sosa52148582012-11-15 15:35:58 -080027<client_test xmlns:o="http://www.google.com/update2/request" updaterversion="%(client)s" protocol="3.0">
28 <app version="%(version)s" track="%(track)s" board="%(board)s" />
29 <updatecheck />
30 <event eventresult="%(event_result)d" eventtype="%(event_type)d" />
Chris Sosa0356d3b2010-09-16 15:46:22 -070031</client_test>"""
32
Chris Sosa4b951602014-04-09 20:26:07 -070033# Test request with additional fields needed for full Omaha protocol.
34_FULL_TEST_REQUEST = """
35<client_test xmlns:o="http://www.google.com/update2/request" updaterversion="%(client)s" protocol="3.0">
36 <app version="%(version)s" track="%(track)s" board="%(board)s"
37 hardware_class="Test Device" />
38 <updatecheck />
39 <event eventresult="%(event_result)d" eventtype="%(event_type)d" />
40</client_test>"""
41
Chris Sosa6a3697f2013-01-29 16:44:43 -080042#pylint: disable=W0212
Chris Sosa0356d3b2010-09-16 15:46:22 -070043class AutoupdateTest(mox.MoxTestBase):
Chris Sosa4b951602014-04-09 20:26:07 -070044 """Tests for the autoupdate.Autoupdate class."""
45
Chris Sosa0356d3b2010-09-16 15:46:22 -070046 def setUp(self):
47 mox.MoxTestBase.setUp(self)
Gilad Arnold55a2a372012-10-02 09:46:32 -070048 self.mox.StubOutWithMock(common_util, 'GetFileSize')
49 self.mox.StubOutWithMock(common_util, 'GetFileSha1')
50 self.mox.StubOutWithMock(common_util, 'GetFileSha256')
Chris Sosac4e87842013-08-16 18:04:14 -070051 self.mox.StubOutWithMock(common_util, 'IsInsideChroot')
Chris Sosa52148582012-11-15 15:35:58 -080052 self.mox.StubOutWithMock(autoupdate_lib, 'GetUpdateResponse')
Gilad Arnold0c9c8602012-10-02 23:58:58 -070053 self.mox.StubOutWithMock(autoupdate.Autoupdate, '_GetRemotePayloadAttrs')
Chris Sosa7c931362010-10-11 19:49:01 -070054 self.port = 8080
Chris Sosa0356d3b2010-09-16 15:46:22 -070055 self.test_board = 'test-board'
joychen121fc9b2013-08-02 14:30:30 -070056 self.build_root = tempfile.mkdtemp('autoupdate_build_root')
Chris Sosa0356d3b2010-09-16 15:46:22 -070057 self.latest_dir = '12345_af_12-a1'
58 self.latest_verision = '12345_af_12'
joychen121fc9b2013-08-02 14:30:30 -070059 self.static_image_dir = tempfile.mkdtemp('autoupdate_static_dir')
Chris Sosa7c931362010-10-11 19:49:01 -070060 self.hostname = '%s:%s' % (socket.gethostname(), self.port)
Dale Curtisc9aaf3a2011-08-09 15:47:40 -070061 self.test_dict = {
62 'client': 'ChromeOSUpdateEngine-1.0',
63 'version': 'ForcedUpdate',
Chris Sosa4b951602014-04-09 20:26:07 -070064 'track': 'test-channel',
Dale Curtisc9aaf3a2011-08-09 15:47:40 -070065 'board': self.test_board,
66 'event_result': 2,
67 'event_type': 3
68 }
Chris Sosa0356d3b2010-09-16 15:46:22 -070069 self.test_data = _TEST_REQUEST % self.test_dict
Gilad Arnold0c9c8602012-10-02 23:58:58 -070070 self.sha1 = 12345
Chris Sosa0356d3b2010-09-16 15:46:22 -070071 self.size = 54321
72 self.url = 'http://%s/static/update.gz' % self.hostname
73 self.payload = 'My payload'
Chris Sosaa387a872010-09-29 11:51:36 -070074 self.sha256 = 'SHA LA LA'
Chris Sosa54555862010-10-25 17:26:17 -070075 cherrypy.request.base = 'http://%s' % self.hostname
joychen121fc9b2013-08-02 14:30:30 -070076 common_util.MkDirP(self.static_image_dir)
77 self._xbuddy = xbuddy.XBuddy(False,
joychen121fc9b2013-08-02 14:30:30 -070078 static_dir=self.static_image_dir)
79 self.mox.StubOutWithMock(xbuddy.XBuddy, '_GetArtifact')
Chris Sosa6a3697f2013-01-29 16:44:43 -080080
81 def tearDown(self):
joychen121fc9b2013-08-02 14:30:30 -070082 shutil.rmtree(self.build_root)
Chris Sosa6a3697f2013-01-29 16:44:43 -080083 shutil.rmtree(self.static_image_dir)
Chris Sosa54555862010-10-25 17:26:17 -070084
Gilad Arnold0c9c8602012-10-02 23:58:58 -070085 def _DummyAutoupdateConstructor(self, **kwargs):
Chris Sosa0356d3b2010-09-16 15:46:22 -070086 """Creates a dummy autoupdater. Used to avoid using constructor."""
joychen121fc9b2013-08-02 14:30:30 -070087 dummy = autoupdate.Autoupdate(self._xbuddy,
Chris Sosa7c931362010-10-11 19:49:01 -070088 static_dir=self.static_image_dir,
Gilad Arnold0c9c8602012-10-02 23:58:58 -070089 **kwargs)
Chris Sosa0356d3b2010-09-16 15:46:22 -070090 return dummy
91
Chris Sosa744e1472011-09-07 19:32:50 -070092 def testGetRightSignedDeltaPayloadDir(self):
93 """Test that our directory is what we expect it to be for signed updates."""
Gilad Arnold55a2a372012-10-02 09:46:32 -070094 self.mox.StubOutWithMock(common_util, 'GetFileMd5')
Chris Sosa744e1472011-09-07 19:32:50 -070095 key_path = 'test_key_path'
96 src_image = 'test_src_image'
97 target_image = 'test_target_image'
Gilad Arnold55a2a372012-10-02 09:46:32 -070098 src_hash = '12345'
99 target_hash = '67890'
100 key_hash = 'abcde'
Chris Sosa744e1472011-09-07 19:32:50 -0700101
Gilad Arnold55a2a372012-10-02 09:46:32 -0700102 common_util.GetFileMd5(src_image).AndReturn(src_hash)
103 common_util.GetFileMd5(target_image).AndReturn(target_hash)
104 common_util.GetFileMd5(key_path).AndReturn(key_hash)
Chris Sosa744e1472011-09-07 19:32:50 -0700105
106 self.mox.ReplayAll()
107 au_mock = self._DummyAutoupdateConstructor()
108 au_mock.private_key = key_path
109 update_dir = au_mock.FindCachedUpdateImageSubDir(src_image, target_image)
Scott Zawalski16954532012-03-20 15:31:36 -0400110 self.assertEqual(os.path.basename(update_dir),
Gabe Black70994862014-09-05 00:50:58 -0700111 '%s_%s+%s' % (src_hash, target_hash, key_hash))
Chris Sosa744e1472011-09-07 19:32:50 -0700112 self.mox.VerifyAll()
113
joychen121fc9b2013-08-02 14:30:30 -0700114 def testGenerateLatestUpdateImage(self):
115 """Test default behavior in response to plain update call."""
116 latest_label = os.path.join(self.test_board, self.latest_dir)
117 # Generate a fake latest image
118 latest_image_dir = os.path.join(self.static_image_dir, latest_label)
119 common_util.MkDirP(latest_image_dir)
120 image = os.path.join(latest_image_dir, constants.TEST_IMAGE_FILE)
121 with open(image, 'w') as fh:
122 fh.write('')
123
Don Garrettf90edf02010-11-16 17:36:14 -0800124 self.mox.StubOutWithMock(autoupdate.Autoupdate,
125 'GenerateUpdateImageWithCache')
Chris Sosa6a3697f2013-01-29 16:44:43 -0800126 au_mock = self._DummyAutoupdateConstructor()
joychen121fc9b2013-08-02 14:30:30 -0700127
Chris Sosac4e87842013-08-16 18:04:14 -0700128 common_util.IsInsideChroot().AndReturn(True)
Gabe Black77f3c202014-09-05 00:43:36 -0700129 self._xbuddy._GetArtifact([''], board=self.test_board, lookup_only=True,
130 image_dir=None).AndReturn((latest_label, constants.TEST_IMAGE_FILE))
joychen121fc9b2013-08-02 14:30:30 -0700131
Chris Sosa6a3697f2013-01-29 16:44:43 -0800132 au_mock.GenerateUpdateImageWithCache(
joychen121fc9b2013-08-02 14:30:30 -0700133 os.path.join(self.static_image_dir, self.test_board, self.latest_dir,
Chris Sosa75490802013-09-30 17:21:45 -0700134 constants.TEST_IMAGE_FILE)).AndReturn('update.gz')
Chris Sosa0356d3b2010-09-16 15:46:22 -0700135
136 self.mox.ReplayAll()
joychen121fc9b2013-08-02 14:30:30 -0700137 test_data = _TEST_REQUEST % self.test_dict
138 self.assertTrue(au_mock.HandleUpdatePing(test_data))
Chris Sosa0356d3b2010-09-16 15:46:22 -0700139 self.mox.VerifyAll()
140
141 def testHandleUpdatePingForForcedImage(self):
joychen121fc9b2013-08-02 14:30:30 -0700142 """Test update response to having a forced image."""
Don Garrettf90edf02010-11-16 17:36:14 -0800143 self.mox.StubOutWithMock(autoupdate.Autoupdate,
144 'GenerateUpdateImageWithCache')
Chris Sosa6a3697f2013-01-29 16:44:43 -0800145 self.mox.StubOutWithMock(autoupdate.Autoupdate, '_StoreMetadataToFile')
146 au_mock = self._DummyAutoupdateConstructor()
Chris Sosa0356d3b2010-09-16 15:46:22 -0700147 test_data = _TEST_REQUEST % self.test_dict
148
joychen121fc9b2013-08-02 14:30:30 -0700149 # Generate a fake image
150 forced_image_dir = '/tmp/path_to_force/'
151 forced_image = forced_image_dir + constants.IMAGE_FILE
152 common_util.MkDirP(forced_image_dir)
153 with open(forced_image, 'w') as fh:
Chris Sosa6a3697f2013-01-29 16:44:43 -0800154 fh.write('')
155
joychen18737f32013-08-16 17:18:12 -0700156 cache_image_dir = os.path.join(self.static_image_dir, 'cache')
joychen121fc9b2013-08-02 14:30:30 -0700157
158 # Mock out GenerateUpdateImageWithCache to make an update file in cache
Chris Sosa75490802013-09-30 17:21:45 -0700159 def mock_fn(_image):
joychen121fc9b2013-08-02 14:30:30 -0700160 print 'mock_fn'
161 # No good way to introduce an update file during execution.
Chris Sosa75490802013-09-30 17:21:45 -0700162 cache_dir = os.path.join(self.static_image_dir, 'cache')
joychen121fc9b2013-08-02 14:30:30 -0700163 common_util.MkDirP(cache_dir)
164 update_image = os.path.join(cache_dir, constants.UPDATE_FILE)
165 with open(update_image, 'w') as fh:
166 fh.write('')
David Zeuthen52ccd012013-10-31 12:58:26 -0700167 metadata_hash = os.path.join(cache_dir, constants.METADATA_HASH_FILE)
168 with open(metadata_hash, 'w') as fh:
169 fh.write('')
joychen121fc9b2013-08-02 14:30:30 -0700170
Chris Sosac4e87842013-08-16 18:04:14 -0700171 common_util.IsInsideChroot().AndReturn(True)
Chris Sosa75490802013-09-30 17:21:45 -0700172 au_mock.GenerateUpdateImageWithCache(forced_image).WithSideEffects(
joychen121fc9b2013-08-02 14:30:30 -0700173 mock_fn).AndReturn('cache')
174
Gilad Arnold55a2a372012-10-02 09:46:32 -0700175 common_util.GetFileSha1(os.path.join(
joychen121fc9b2013-08-02 14:30:30 -0700176 cache_image_dir, 'update.gz')).AndReturn(self.sha1)
Gilad Arnold55a2a372012-10-02 09:46:32 -0700177 common_util.GetFileSha256(os.path.join(
joychen121fc9b2013-08-02 14:30:30 -0700178 cache_image_dir, 'update.gz')).AndReturn(self.sha256)
Gilad Arnold55a2a372012-10-02 09:46:32 -0700179 common_util.GetFileSize(os.path.join(
joychen121fc9b2013-08-02 14:30:30 -0700180 cache_image_dir, 'update.gz')).AndReturn(self.size)
181 au_mock._StoreMetadataToFile(cache_image_dir,
Chris Sosa6a3697f2013-01-29 16:44:43 -0800182 mox.IsA(autoupdate.UpdateMetadata))
joychen121fc9b2013-08-02 14:30:30 -0700183 forced_url = 'http://%s/static/%s/update.gz' % (self.hostname,
joychen18737f32013-08-16 17:18:12 -0700184 'cache')
Chris Sosa52148582012-11-15 15:35:58 -0800185 autoupdate_lib.GetUpdateResponse(
David Zeuthen52ccd012013-10-31 12:58:26 -0700186 self.sha1, self.sha256, self.size, forced_url, False, 0, None, None,
187 '3.0', False).AndReturn(self.payload)
Chris Sosa0356d3b2010-09-16 15:46:22 -0700188
189 self.mox.ReplayAll()
joychen121fc9b2013-08-02 14:30:30 -0700190 au_mock.forced_image = forced_image
Chris Sosa0356d3b2010-09-16 15:46:22 -0700191 self.assertEqual(au_mock.HandleUpdatePing(test_data), self.payload)
192 self.mox.VerifyAll()
193
joychendbfe6c92013-08-16 20:03:49 -0700194 def testHandleForcePregenerateXBuddy(self):
195 """Check pregenerating an xbuddy path.
196
197 A forced image that starts with 'xbuddy:' uses the following path to
198 obtain an update.
199 """
200 self.mox.StubOutWithMock(autoupdate.Autoupdate,
201 'GetUpdateForLabel')
202 au_mock = self._DummyAutoupdateConstructor()
203 au_mock.forced_image = "xbuddy:b/v/a"
204
Gabe Black77f3c202014-09-05 00:43:36 -0700205 self._xbuddy._GetArtifact(['b', 'v', 'a'],
206 image_dir=None).AndReturn(('label', constants.TEST_IMAGE_FILE))
joychen365a5742013-08-21 10:41:18 -0700207
joychendbfe6c92013-08-16 20:03:49 -0700208 au_mock.GetUpdateForLabel(
209 autoupdate.FORCED_UPDATE, 'b/v/a').AndReturn('p')
210 self.mox.ReplayAll()
211
212 au_mock.PreGenerateUpdate()
213 self.mox.VerifyAll()
214
Don Garrett0ad09372010-12-06 16:20:30 -0800215 def testChangeUrlPort(self):
216 r = autoupdate._ChangeUrlPort('http://fuzzy:8080/static', 8085)
217 self.assertEqual(r, 'http://fuzzy:8085/static')
218
219 r = autoupdate._ChangeUrlPort('http://fuzzy/static', 8085)
220 self.assertEqual(r, 'http://fuzzy:8085/static')
221
222 r = autoupdate._ChangeUrlPort('ftp://fuzzy/static', 8085)
223 self.assertEqual(r, 'ftp://fuzzy:8085/static')
224
225 r = autoupdate._ChangeUrlPort('ftp://fuzzy', 8085)
226 self.assertEqual(r, 'ftp://fuzzy:8085')
227
Dale Curtisc9aaf3a2011-08-09 15:47:40 -0700228 def testHandleHostInfoPing(self):
229 au_mock = self._DummyAutoupdateConstructor()
230 self.assertRaises(AssertionError, au_mock.HandleHostInfoPing, None)
231
Gilad Arnold286a0062012-01-12 13:47:02 -0800232 # Setup fake host_infos entry and ensure it comes back to us in one piece.
Dale Curtisc9aaf3a2011-08-09 15:47:40 -0700233 test_ip = '1.2.3.4'
Gilad Arnold286a0062012-01-12 13:47:02 -0800234 au_mock.host_infos.GetInitHostInfo(test_ip).attrs = self.test_dict
Dale Curtisc9aaf3a2011-08-09 15:47:40 -0700235 self.assertEqual(
236 json.loads(au_mock.HandleHostInfoPing(test_ip)), self.test_dict)
237
238 def testHandleSetUpdatePing(self):
239 au_mock = self._DummyAutoupdateConstructor()
240 test_ip = '1.2.3.4'
241 test_label = 'test/old-update'
242 self.assertRaises(
243 AssertionError, au_mock.HandleSetUpdatePing, test_ip, None)
244 self.assertRaises(
245 AssertionError, au_mock.HandleSetUpdatePing, None, test_label)
246 self.assertRaises(
247 AssertionError, au_mock.HandleSetUpdatePing, None, None)
248
249 au_mock.HandleSetUpdatePing(test_ip, test_label)
250 self.assertEqual(
Chris Sosa1885d032012-11-29 17:07:27 -0800251 au_mock.host_infos.GetHostInfo(test_ip).attrs['forced_update_label'],
Gilad Arnold286a0062012-01-12 13:47:02 -0800252 test_label)
Dale Curtisc9aaf3a2011-08-09 15:47:40 -0700253
254 def testHandleUpdatePingWithSetUpdate(self):
joychen7c2054a2013-07-25 11:14:07 -0700255 """If update is set, it should use the update found in that directory."""
Chris Sosa6a3697f2013-01-29 16:44:43 -0800256 self.mox.StubOutWithMock(autoupdate.Autoupdate, '_StoreMetadataToFile')
257 au_mock = self._DummyAutoupdateConstructor()
Dale Curtisc9aaf3a2011-08-09 15:47:40 -0700258
259 test_data = _TEST_REQUEST % self.test_dict
260 test_label = 'new_update-test/the-new-update'
261 new_image_dir = os.path.join(self.static_image_dir, test_label)
262 new_url = self.url.replace('update.gz', test_label + '/update.gz')
263
Chris Sosa6a3697f2013-01-29 16:44:43 -0800264 # Generate a fake payload.
joychen121fc9b2013-08-02 14:30:30 -0700265 common_util.MkDirP(new_image_dir)
joychen7c2054a2013-07-25 11:14:07 -0700266 update_gz = os.path.join(new_image_dir, constants.UPDATE_FILE)
Chris Sosa6a3697f2013-01-29 16:44:43 -0800267 with open(update_gz, 'w') as fh:
268 fh.write('')
David Zeuthen52ccd012013-10-31 12:58:26 -0700269 metadata_hash = os.path.join(new_image_dir, constants.METADATA_HASH_FILE)
270 with open(metadata_hash, 'w') as fh:
271 fh.write('')
Chris Sosa6a3697f2013-01-29 16:44:43 -0800272
Gilad Arnold55a2a372012-10-02 09:46:32 -0700273 common_util.GetFileSha1(os.path.join(
Gilad Arnold0c9c8602012-10-02 23:58:58 -0700274 new_image_dir, 'update.gz')).AndReturn(self.sha1)
Gilad Arnold55a2a372012-10-02 09:46:32 -0700275 common_util.GetFileSha256(os.path.join(
Dale Curtisc9aaf3a2011-08-09 15:47:40 -0700276 new_image_dir, 'update.gz')).AndReturn(self.sha256)
Gilad Arnold55a2a372012-10-02 09:46:32 -0700277 common_util.GetFileSize(os.path.join(
Dale Curtisc9aaf3a2011-08-09 15:47:40 -0700278 new_image_dir, 'update.gz')).AndReturn(self.size)
Chris Sosa6a3697f2013-01-29 16:44:43 -0800279 au_mock._StoreMetadataToFile(new_image_dir,
280 mox.IsA(autoupdate.UpdateMetadata))
Chris Sosa52148582012-11-15 15:35:58 -0800281 autoupdate_lib.GetUpdateResponse(
David Zeuthen52ccd012013-10-31 12:58:26 -0700282 self.sha1, self.sha256, self.size, new_url, False, 0, None, None,
283 '3.0', False).AndReturn(self.payload)
Dale Curtisc9aaf3a2011-08-09 15:47:40 -0700284
285 self.mox.ReplayAll()
Dale Curtisc9aaf3a2011-08-09 15:47:40 -0700286 au_mock.HandleSetUpdatePing('127.0.0.1', test_label)
287 self.assertEqual(
Gilad Arnold286a0062012-01-12 13:47:02 -0800288 au_mock.host_infos.GetHostInfo('127.0.0.1').
Chris Sosa1885d032012-11-29 17:07:27 -0800289 attrs['forced_update_label'],
Gilad Arnold286a0062012-01-12 13:47:02 -0800290 test_label)
Dale Curtisc9aaf3a2011-08-09 15:47:40 -0700291 self.assertEqual(au_mock.HandleUpdatePing(test_data), self.payload)
Gilad Arnold286a0062012-01-12 13:47:02 -0800292 self.assertFalse('forced_update_label' in
293 au_mock.host_infos.GetHostInfo('127.0.0.1').attrs)
Dale Curtisc9aaf3a2011-08-09 15:47:40 -0700294
Daniel Erat8a0bc4a2011-09-30 08:52:52 -0700295 def testGetVersionFromDir(self):
296 au = self._DummyAutoupdateConstructor()
297
298 # New-style version number.
299 self.assertEqual(
300 au._GetVersionFromDir('/foo/x86-alex/R16-1102.0.2011_09_30_0806-a1'),
301 '1102.0.2011_09_30_0806')
302
Daniel Erat8a0bc4a2011-09-30 08:52:52 -0700303 def testCanUpdate(self):
304 au = self._DummyAutoupdateConstructor()
305
306 # When both the client and the server have new-style versions, we should
307 # just compare the tokens directly.
308 self.assertTrue(
309 au._CanUpdate('1098.0.2011_09_28_1635', '1098.0.2011_09_30_0806'))
310 self.assertTrue(
311 au._CanUpdate('1098.0.2011_09_28_1635', '1100.0.2011_09_26_0000'))
312 self.assertFalse(
313 au._CanUpdate('1098.0.2011_09_28_1635', '1098.0.2011_09_26_0000'))
314 self.assertFalse(
315 au._CanUpdate('1098.0.2011_09_28_1635', '1096.0.2011_09_30_0000'))
316
Gilad Arnold0c9c8602012-10-02 23:58:58 -0700317 def testHandleUpdatePingRemotePayload(self):
318 remote_urlbase = 'http://remotehost:6666'
319 remote_payload_path = 'static/path/to/update.gz'
320 remote_url = '/'.join([remote_urlbase, remote_payload_path, 'update.gz'])
Chris Sosa6a3697f2013-01-29 16:44:43 -0800321 au_mock = self._DummyAutoupdateConstructor(urlbase=remote_urlbase,
322 payload_path=remote_payload_path,
323 remote_payload=True)
Gilad Arnold0c9c8602012-10-02 23:58:58 -0700324
Chris Sosa4b951602014-04-09 20:26:07 -0700325 incomplete_test_data = _TEST_REQUEST % self.test_dict
326 complete_test_data = _FULL_TEST_REQUEST % self.test_dict
Gilad Arnold0c9c8602012-10-02 23:58:58 -0700327
Chris Sosa6a3697f2013-01-29 16:44:43 -0800328 au_mock._GetRemotePayloadAttrs(remote_url).AndReturn(
David Zeuthen52ccd012013-10-31 12:58:26 -0700329 autoupdate.UpdateMetadata(self.sha1, self.sha256, self.size, False,
330 0, ''))
Chris Sosa52148582012-11-15 15:35:58 -0800331 autoupdate_lib.GetUpdateResponse(
David Zeuthen52ccd012013-10-31 12:58:26 -0700332 self.sha1, self.sha256, self.size, remote_url, False, 0, None, None,
Chris Sosa52148582012-11-15 15:35:58 -0800333 '3.0', False).AndReturn(self.payload)
Gilad Arnold0c9c8602012-10-02 23:58:58 -0700334
335 self.mox.ReplayAll()
Chris Sosa4b951602014-04-09 20:26:07 -0700336 # This should fail because of missing fields.
337 self.assertRaises(common_util.DevServerHTTPError,
338 au_mock.HandleUpdatePing, incomplete_test_data)
339 # This should have enough information.
340 self.assertEqual(au_mock.HandleUpdatePing(complete_test_data), self.payload)
Gilad Arnold0c9c8602012-10-02 23:58:58 -0700341 self.mox.VerifyAll()
342
Chris Sosa0356d3b2010-09-16 15:46:22 -0700343
Gilad Arnoldc65330c2012-09-20 15:17:48 -0700344if __name__ == '__main__':
345 unittest.main()