blob: eacd8c46d3a5de05e625574d25290aa39a06bb18 [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)
Bertrand SIMONNETb3ddc292015-04-30 17:26:02 -0700129 self._xbuddy._GetArtifact(
130 [''], board=self.test_board, lookup_only=True, image_dir=None,
131 version=None).AndReturn((latest_label, constants.TEST_IMAGE_FILE))
joychen121fc9b2013-08-02 14:30:30 -0700132
Chris Sosa6a3697f2013-01-29 16:44:43 -0800133 au_mock.GenerateUpdateImageWithCache(
joychen121fc9b2013-08-02 14:30:30 -0700134 os.path.join(self.static_image_dir, self.test_board, self.latest_dir,
Chris Sosa75490802013-09-30 17:21:45 -0700135 constants.TEST_IMAGE_FILE)).AndReturn('update.gz')
Chris Sosa0356d3b2010-09-16 15:46:22 -0700136
137 self.mox.ReplayAll()
joychen121fc9b2013-08-02 14:30:30 -0700138 test_data = _TEST_REQUEST % self.test_dict
139 self.assertTrue(au_mock.HandleUpdatePing(test_data))
Chris Sosa0356d3b2010-09-16 15:46:22 -0700140 self.mox.VerifyAll()
141
142 def testHandleUpdatePingForForcedImage(self):
joychen121fc9b2013-08-02 14:30:30 -0700143 """Test update response to having a forced image."""
Don Garrettf90edf02010-11-16 17:36:14 -0800144 self.mox.StubOutWithMock(autoupdate.Autoupdate,
145 'GenerateUpdateImageWithCache')
Chris Sosa6a3697f2013-01-29 16:44:43 -0800146 self.mox.StubOutWithMock(autoupdate.Autoupdate, '_StoreMetadataToFile')
147 au_mock = self._DummyAutoupdateConstructor()
Chris Sosa0356d3b2010-09-16 15:46:22 -0700148 test_data = _TEST_REQUEST % self.test_dict
149
joychen121fc9b2013-08-02 14:30:30 -0700150 # Generate a fake image
151 forced_image_dir = '/tmp/path_to_force/'
152 forced_image = forced_image_dir + constants.IMAGE_FILE
153 common_util.MkDirP(forced_image_dir)
154 with open(forced_image, 'w') as fh:
Chris Sosa6a3697f2013-01-29 16:44:43 -0800155 fh.write('')
156
joychen18737f32013-08-16 17:18:12 -0700157 cache_image_dir = os.path.join(self.static_image_dir, 'cache')
joychen121fc9b2013-08-02 14:30:30 -0700158
159 # Mock out GenerateUpdateImageWithCache to make an update file in cache
Chris Sosa75490802013-09-30 17:21:45 -0700160 def mock_fn(_image):
joychen121fc9b2013-08-02 14:30:30 -0700161 print 'mock_fn'
162 # No good way to introduce an update file during execution.
Chris Sosa75490802013-09-30 17:21:45 -0700163 cache_dir = os.path.join(self.static_image_dir, 'cache')
joychen121fc9b2013-08-02 14:30:30 -0700164 common_util.MkDirP(cache_dir)
165 update_image = os.path.join(cache_dir, constants.UPDATE_FILE)
166 with open(update_image, 'w') as fh:
167 fh.write('')
David Zeuthen52ccd012013-10-31 12:58:26 -0700168 metadata_hash = os.path.join(cache_dir, constants.METADATA_HASH_FILE)
169 with open(metadata_hash, 'w') as fh:
170 fh.write('')
joychen121fc9b2013-08-02 14:30:30 -0700171
Chris Sosac4e87842013-08-16 18:04:14 -0700172 common_util.IsInsideChroot().AndReturn(True)
Chris Sosa75490802013-09-30 17:21:45 -0700173 au_mock.GenerateUpdateImageWithCache(forced_image).WithSideEffects(
joychen121fc9b2013-08-02 14:30:30 -0700174 mock_fn).AndReturn('cache')
175
Gilad Arnold55a2a372012-10-02 09:46:32 -0700176 common_util.GetFileSha1(os.path.join(
joychen121fc9b2013-08-02 14:30:30 -0700177 cache_image_dir, 'update.gz')).AndReturn(self.sha1)
Gilad Arnold55a2a372012-10-02 09:46:32 -0700178 common_util.GetFileSha256(os.path.join(
joychen121fc9b2013-08-02 14:30:30 -0700179 cache_image_dir, 'update.gz')).AndReturn(self.sha256)
Gilad Arnold55a2a372012-10-02 09:46:32 -0700180 common_util.GetFileSize(os.path.join(
joychen121fc9b2013-08-02 14:30:30 -0700181 cache_image_dir, 'update.gz')).AndReturn(self.size)
182 au_mock._StoreMetadataToFile(cache_image_dir,
Chris Sosa6a3697f2013-01-29 16:44:43 -0800183 mox.IsA(autoupdate.UpdateMetadata))
joychen121fc9b2013-08-02 14:30:30 -0700184 forced_url = 'http://%s/static/%s/update.gz' % (self.hostname,
joychen18737f32013-08-16 17:18:12 -0700185 'cache')
Chris Sosa52148582012-11-15 15:35:58 -0800186 autoupdate_lib.GetUpdateResponse(
David Zeuthen52ccd012013-10-31 12:58:26 -0700187 self.sha1, self.sha256, self.size, forced_url, False, 0, None, None,
188 '3.0', False).AndReturn(self.payload)
Chris Sosa0356d3b2010-09-16 15:46:22 -0700189
190 self.mox.ReplayAll()
joychen121fc9b2013-08-02 14:30:30 -0700191 au_mock.forced_image = forced_image
Chris Sosa0356d3b2010-09-16 15:46:22 -0700192 self.assertEqual(au_mock.HandleUpdatePing(test_data), self.payload)
193 self.mox.VerifyAll()
194
joychendbfe6c92013-08-16 20:03:49 -0700195 def testHandleForcePregenerateXBuddy(self):
196 """Check pregenerating an xbuddy path.
197
198 A forced image that starts with 'xbuddy:' uses the following path to
199 obtain an update.
200 """
201 self.mox.StubOutWithMock(autoupdate.Autoupdate,
202 'GetUpdateForLabel')
203 au_mock = self._DummyAutoupdateConstructor()
204 au_mock.forced_image = "xbuddy:b/v/a"
205
Gabe Black77f3c202014-09-05 00:43:36 -0700206 self._xbuddy._GetArtifact(['b', 'v', 'a'],
207 image_dir=None).AndReturn(('label', constants.TEST_IMAGE_FILE))
joychen365a5742013-08-21 10:41:18 -0700208
joychendbfe6c92013-08-16 20:03:49 -0700209 au_mock.GetUpdateForLabel(
210 autoupdate.FORCED_UPDATE, 'b/v/a').AndReturn('p')
211 self.mox.ReplayAll()
212
213 au_mock.PreGenerateUpdate()
214 self.mox.VerifyAll()
215
Don Garrett0ad09372010-12-06 16:20:30 -0800216 def testChangeUrlPort(self):
217 r = autoupdate._ChangeUrlPort('http://fuzzy:8080/static', 8085)
218 self.assertEqual(r, 'http://fuzzy:8085/static')
219
220 r = autoupdate._ChangeUrlPort('http://fuzzy/static', 8085)
221 self.assertEqual(r, 'http://fuzzy:8085/static')
222
223 r = autoupdate._ChangeUrlPort('ftp://fuzzy/static', 8085)
224 self.assertEqual(r, 'ftp://fuzzy:8085/static')
225
226 r = autoupdate._ChangeUrlPort('ftp://fuzzy', 8085)
227 self.assertEqual(r, 'ftp://fuzzy:8085')
228
Dale Curtisc9aaf3a2011-08-09 15:47:40 -0700229 def testHandleHostInfoPing(self):
230 au_mock = self._DummyAutoupdateConstructor()
231 self.assertRaises(AssertionError, au_mock.HandleHostInfoPing, None)
232
Gilad Arnold286a0062012-01-12 13:47:02 -0800233 # Setup fake host_infos entry and ensure it comes back to us in one piece.
Dale Curtisc9aaf3a2011-08-09 15:47:40 -0700234 test_ip = '1.2.3.4'
Gilad Arnold286a0062012-01-12 13:47:02 -0800235 au_mock.host_infos.GetInitHostInfo(test_ip).attrs = self.test_dict
Dale Curtisc9aaf3a2011-08-09 15:47:40 -0700236 self.assertEqual(
237 json.loads(au_mock.HandleHostInfoPing(test_ip)), self.test_dict)
238
239 def testHandleSetUpdatePing(self):
240 au_mock = self._DummyAutoupdateConstructor()
241 test_ip = '1.2.3.4'
242 test_label = 'test/old-update'
243 self.assertRaises(
244 AssertionError, au_mock.HandleSetUpdatePing, test_ip, None)
245 self.assertRaises(
246 AssertionError, au_mock.HandleSetUpdatePing, None, test_label)
247 self.assertRaises(
248 AssertionError, au_mock.HandleSetUpdatePing, None, None)
249
250 au_mock.HandleSetUpdatePing(test_ip, test_label)
251 self.assertEqual(
Chris Sosa1885d032012-11-29 17:07:27 -0800252 au_mock.host_infos.GetHostInfo(test_ip).attrs['forced_update_label'],
Gilad Arnold286a0062012-01-12 13:47:02 -0800253 test_label)
Dale Curtisc9aaf3a2011-08-09 15:47:40 -0700254
255 def testHandleUpdatePingWithSetUpdate(self):
joychen7c2054a2013-07-25 11:14:07 -0700256 """If update is set, it should use the update found in that directory."""
Chris Sosa6a3697f2013-01-29 16:44:43 -0800257 self.mox.StubOutWithMock(autoupdate.Autoupdate, '_StoreMetadataToFile')
258 au_mock = self._DummyAutoupdateConstructor()
Dale Curtisc9aaf3a2011-08-09 15:47:40 -0700259
260 test_data = _TEST_REQUEST % self.test_dict
261 test_label = 'new_update-test/the-new-update'
262 new_image_dir = os.path.join(self.static_image_dir, test_label)
263 new_url = self.url.replace('update.gz', test_label + '/update.gz')
264
Chris Sosa6a3697f2013-01-29 16:44:43 -0800265 # Generate a fake payload.
joychen121fc9b2013-08-02 14:30:30 -0700266 common_util.MkDirP(new_image_dir)
joychen7c2054a2013-07-25 11:14:07 -0700267 update_gz = os.path.join(new_image_dir, constants.UPDATE_FILE)
Chris Sosa6a3697f2013-01-29 16:44:43 -0800268 with open(update_gz, 'w') as fh:
269 fh.write('')
David Zeuthen52ccd012013-10-31 12:58:26 -0700270 metadata_hash = os.path.join(new_image_dir, constants.METADATA_HASH_FILE)
271 with open(metadata_hash, 'w') as fh:
272 fh.write('')
Chris Sosa6a3697f2013-01-29 16:44:43 -0800273
Gilad Arnold55a2a372012-10-02 09:46:32 -0700274 common_util.GetFileSha1(os.path.join(
Gilad Arnold0c9c8602012-10-02 23:58:58 -0700275 new_image_dir, 'update.gz')).AndReturn(self.sha1)
Gilad Arnold55a2a372012-10-02 09:46:32 -0700276 common_util.GetFileSha256(os.path.join(
Dale Curtisc9aaf3a2011-08-09 15:47:40 -0700277 new_image_dir, 'update.gz')).AndReturn(self.sha256)
Gilad Arnold55a2a372012-10-02 09:46:32 -0700278 common_util.GetFileSize(os.path.join(
Dale Curtisc9aaf3a2011-08-09 15:47:40 -0700279 new_image_dir, 'update.gz')).AndReturn(self.size)
Chris Sosa6a3697f2013-01-29 16:44:43 -0800280 au_mock._StoreMetadataToFile(new_image_dir,
281 mox.IsA(autoupdate.UpdateMetadata))
Chris Sosa52148582012-11-15 15:35:58 -0800282 autoupdate_lib.GetUpdateResponse(
David Zeuthen52ccd012013-10-31 12:58:26 -0700283 self.sha1, self.sha256, self.size, new_url, False, 0, None, None,
284 '3.0', False).AndReturn(self.payload)
Dale Curtisc9aaf3a2011-08-09 15:47:40 -0700285
286 self.mox.ReplayAll()
Dale Curtisc9aaf3a2011-08-09 15:47:40 -0700287 au_mock.HandleSetUpdatePing('127.0.0.1', test_label)
288 self.assertEqual(
Gilad Arnold286a0062012-01-12 13:47:02 -0800289 au_mock.host_infos.GetHostInfo('127.0.0.1').
Chris Sosa1885d032012-11-29 17:07:27 -0800290 attrs['forced_update_label'],
Gilad Arnold286a0062012-01-12 13:47:02 -0800291 test_label)
Dale Curtisc9aaf3a2011-08-09 15:47:40 -0700292 self.assertEqual(au_mock.HandleUpdatePing(test_data), self.payload)
Gilad Arnold286a0062012-01-12 13:47:02 -0800293 self.assertFalse('forced_update_label' in
294 au_mock.host_infos.GetHostInfo('127.0.0.1').attrs)
Dale Curtisc9aaf3a2011-08-09 15:47:40 -0700295
Daniel Erat8a0bc4a2011-09-30 08:52:52 -0700296 def testGetVersionFromDir(self):
297 au = self._DummyAutoupdateConstructor()
298
299 # New-style version number.
300 self.assertEqual(
301 au._GetVersionFromDir('/foo/x86-alex/R16-1102.0.2011_09_30_0806-a1'),
302 '1102.0.2011_09_30_0806')
303
Daniel Erat8a0bc4a2011-09-30 08:52:52 -0700304 def testCanUpdate(self):
305 au = self._DummyAutoupdateConstructor()
306
307 # When both the client and the server have new-style versions, we should
308 # just compare the tokens directly.
309 self.assertTrue(
310 au._CanUpdate('1098.0.2011_09_28_1635', '1098.0.2011_09_30_0806'))
311 self.assertTrue(
312 au._CanUpdate('1098.0.2011_09_28_1635', '1100.0.2011_09_26_0000'))
313 self.assertFalse(
314 au._CanUpdate('1098.0.2011_09_28_1635', '1098.0.2011_09_26_0000'))
315 self.assertFalse(
316 au._CanUpdate('1098.0.2011_09_28_1635', '1096.0.2011_09_30_0000'))
317
Gilad Arnold0c9c8602012-10-02 23:58:58 -0700318 def testHandleUpdatePingRemotePayload(self):
319 remote_urlbase = 'http://remotehost:6666'
320 remote_payload_path = 'static/path/to/update.gz'
321 remote_url = '/'.join([remote_urlbase, remote_payload_path, 'update.gz'])
Chris Sosa6a3697f2013-01-29 16:44:43 -0800322 au_mock = self._DummyAutoupdateConstructor(urlbase=remote_urlbase,
323 payload_path=remote_payload_path,
324 remote_payload=True)
Gilad Arnold0c9c8602012-10-02 23:58:58 -0700325
Chris Sosa4b951602014-04-09 20:26:07 -0700326 incomplete_test_data = _TEST_REQUEST % self.test_dict
327 complete_test_data = _FULL_TEST_REQUEST % self.test_dict
Gilad Arnold0c9c8602012-10-02 23:58:58 -0700328
Chris Sosa6a3697f2013-01-29 16:44:43 -0800329 au_mock._GetRemotePayloadAttrs(remote_url).AndReturn(
David Zeuthen52ccd012013-10-31 12:58:26 -0700330 autoupdate.UpdateMetadata(self.sha1, self.sha256, self.size, False,
331 0, ''))
Chris Sosa52148582012-11-15 15:35:58 -0800332 autoupdate_lib.GetUpdateResponse(
David Zeuthen52ccd012013-10-31 12:58:26 -0700333 self.sha1, self.sha256, self.size, remote_url, False, 0, None, None,
Chris Sosa52148582012-11-15 15:35:58 -0800334 '3.0', False).AndReturn(self.payload)
Gilad Arnold0c9c8602012-10-02 23:58:58 -0700335
336 self.mox.ReplayAll()
Chris Sosa4b951602014-04-09 20:26:07 -0700337 # This should fail because of missing fields.
338 self.assertRaises(common_util.DevServerHTTPError,
339 au_mock.HandleUpdatePing, incomplete_test_data)
340 # This should have enough information.
341 self.assertEqual(au_mock.HandleUpdatePing(complete_test_data), self.payload)
Gilad Arnold0c9c8602012-10-02 23:58:58 -0700342 self.mox.VerifyAll()
343
Chris Sosa0356d3b2010-09-16 15:46:22 -0700344
Gilad Arnoldc65330c2012-09-20 15:17:48 -0700345if __name__ == '__main__':
346 unittest.main()