blob: 13c1f2ce259a54644bc87667664c8d8622f584d6 [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),
Gilad Arnold55a2a372012-10-02 09:46:32 -0700111 '%s_%s+%s+patched_kernel' %
112 (src_hash, target_hash, key_hash))
Chris Sosa744e1472011-09-07 19:32:50 -0700113 self.mox.VerifyAll()
114
joychen121fc9b2013-08-02 14:30:30 -0700115 def testGenerateLatestUpdateImage(self):
116 """Test default behavior in response to plain update call."""
117 latest_label = os.path.join(self.test_board, self.latest_dir)
118 # Generate a fake latest image
119 latest_image_dir = os.path.join(self.static_image_dir, latest_label)
120 common_util.MkDirP(latest_image_dir)
121 image = os.path.join(latest_image_dir, constants.TEST_IMAGE_FILE)
122 with open(image, 'w') as fh:
123 fh.write('')
124
Don Garrettf90edf02010-11-16 17:36:14 -0800125 self.mox.StubOutWithMock(autoupdate.Autoupdate,
126 'GenerateUpdateImageWithCache')
Chris Sosa6a3697f2013-01-29 16:44:43 -0800127 au_mock = self._DummyAutoupdateConstructor()
joychen121fc9b2013-08-02 14:30:30 -0700128
Chris Sosac4e87842013-08-16 18:04:14 -0700129 common_util.IsInsideChroot().AndReturn(True)
joychen121fc9b2013-08-02 14:30:30 -0700130 self._xbuddy._GetArtifact(
Chris Sosa75490802013-09-30 17:21:45 -0700131 [''], board=self.test_board, lookup_only=True).AndReturn(
joychen121fc9b2013-08-02 14:30:30 -0700132 (latest_label, constants.TEST_IMAGE_FILE))
133
Chris Sosa6a3697f2013-01-29 16:44:43 -0800134 au_mock.GenerateUpdateImageWithCache(
joychen121fc9b2013-08-02 14:30:30 -0700135 os.path.join(self.static_image_dir, self.test_board, self.latest_dir,
Chris Sosa75490802013-09-30 17:21:45 -0700136 constants.TEST_IMAGE_FILE)).AndReturn('update.gz')
Chris Sosa0356d3b2010-09-16 15:46:22 -0700137
138 self.mox.ReplayAll()
joychen121fc9b2013-08-02 14:30:30 -0700139 test_data = _TEST_REQUEST % self.test_dict
140 self.assertTrue(au_mock.HandleUpdatePing(test_data))
Chris Sosa0356d3b2010-09-16 15:46:22 -0700141 self.mox.VerifyAll()
142
143 def testHandleUpdatePingForForcedImage(self):
joychen121fc9b2013-08-02 14:30:30 -0700144 """Test update response to having a forced image."""
Don Garrettf90edf02010-11-16 17:36:14 -0800145 self.mox.StubOutWithMock(autoupdate.Autoupdate,
146 'GenerateUpdateImageWithCache')
Chris Sosa6a3697f2013-01-29 16:44:43 -0800147 self.mox.StubOutWithMock(autoupdate.Autoupdate, '_StoreMetadataToFile')
148 au_mock = self._DummyAutoupdateConstructor()
Chris Sosa0356d3b2010-09-16 15:46:22 -0700149 test_data = _TEST_REQUEST % self.test_dict
150
joychen121fc9b2013-08-02 14:30:30 -0700151 # Generate a fake image
152 forced_image_dir = '/tmp/path_to_force/'
153 forced_image = forced_image_dir + constants.IMAGE_FILE
154 common_util.MkDirP(forced_image_dir)
155 with open(forced_image, 'w') as fh:
Chris Sosa6a3697f2013-01-29 16:44:43 -0800156 fh.write('')
157
joychen18737f32013-08-16 17:18:12 -0700158 cache_image_dir = os.path.join(self.static_image_dir, 'cache')
joychen121fc9b2013-08-02 14:30:30 -0700159
160 # Mock out GenerateUpdateImageWithCache to make an update file in cache
Chris Sosa75490802013-09-30 17:21:45 -0700161 def mock_fn(_image):
joychen121fc9b2013-08-02 14:30:30 -0700162 print 'mock_fn'
163 # No good way to introduce an update file during execution.
Chris Sosa75490802013-09-30 17:21:45 -0700164 cache_dir = os.path.join(self.static_image_dir, 'cache')
joychen121fc9b2013-08-02 14:30:30 -0700165 common_util.MkDirP(cache_dir)
166 update_image = os.path.join(cache_dir, constants.UPDATE_FILE)
167 with open(update_image, 'w') as fh:
168 fh.write('')
David Zeuthen52ccd012013-10-31 12:58:26 -0700169 metadata_hash = os.path.join(cache_dir, constants.METADATA_HASH_FILE)
170 with open(metadata_hash, 'w') as fh:
171 fh.write('')
joychen121fc9b2013-08-02 14:30:30 -0700172
Chris Sosac4e87842013-08-16 18:04:14 -0700173 common_util.IsInsideChroot().AndReturn(True)
Chris Sosa75490802013-09-30 17:21:45 -0700174 au_mock.GenerateUpdateImageWithCache(forced_image).WithSideEffects(
joychen121fc9b2013-08-02 14:30:30 -0700175 mock_fn).AndReturn('cache')
176
Gilad Arnold55a2a372012-10-02 09:46:32 -0700177 common_util.GetFileSha1(os.path.join(
joychen121fc9b2013-08-02 14:30:30 -0700178 cache_image_dir, 'update.gz')).AndReturn(self.sha1)
Gilad Arnold55a2a372012-10-02 09:46:32 -0700179 common_util.GetFileSha256(os.path.join(
joychen121fc9b2013-08-02 14:30:30 -0700180 cache_image_dir, 'update.gz')).AndReturn(self.sha256)
Gilad Arnold55a2a372012-10-02 09:46:32 -0700181 common_util.GetFileSize(os.path.join(
joychen121fc9b2013-08-02 14:30:30 -0700182 cache_image_dir, 'update.gz')).AndReturn(self.size)
183 au_mock._StoreMetadataToFile(cache_image_dir,
Chris Sosa6a3697f2013-01-29 16:44:43 -0800184 mox.IsA(autoupdate.UpdateMetadata))
joychen121fc9b2013-08-02 14:30:30 -0700185 forced_url = 'http://%s/static/%s/update.gz' % (self.hostname,
joychen18737f32013-08-16 17:18:12 -0700186 'cache')
Chris Sosa52148582012-11-15 15:35:58 -0800187 autoupdate_lib.GetUpdateResponse(
David Zeuthen52ccd012013-10-31 12:58:26 -0700188 self.sha1, self.sha256, self.size, forced_url, False, 0, None, None,
189 '3.0', False).AndReturn(self.payload)
Chris Sosa0356d3b2010-09-16 15:46:22 -0700190
191 self.mox.ReplayAll()
joychen121fc9b2013-08-02 14:30:30 -0700192 au_mock.forced_image = forced_image
Chris Sosa0356d3b2010-09-16 15:46:22 -0700193 self.assertEqual(au_mock.HandleUpdatePing(test_data), self.payload)
194 self.mox.VerifyAll()
195
joychendbfe6c92013-08-16 20:03:49 -0700196 def testHandleForcePregenerateXBuddy(self):
197 """Check pregenerating an xbuddy path.
198
199 A forced image that starts with 'xbuddy:' uses the following path to
200 obtain an update.
201 """
202 self.mox.StubOutWithMock(autoupdate.Autoupdate,
203 'GetUpdateForLabel')
204 au_mock = self._DummyAutoupdateConstructor()
205 au_mock.forced_image = "xbuddy:b/v/a"
206
joychen365a5742013-08-21 10:41:18 -0700207 self._xbuddy._GetArtifact(
Chris Sosa75490802013-09-30 17:21:45 -0700208 ['b', 'v', 'a']).AndReturn(('label', constants.TEST_IMAGE_FILE))
joychen365a5742013-08-21 10:41:18 -0700209
joychendbfe6c92013-08-16 20:03:49 -0700210 au_mock.GetUpdateForLabel(
211 autoupdate.FORCED_UPDATE, 'b/v/a').AndReturn('p')
212 self.mox.ReplayAll()
213
214 au_mock.PreGenerateUpdate()
215 self.mox.VerifyAll()
216
Don Garrett0ad09372010-12-06 16:20:30 -0800217 def testChangeUrlPort(self):
218 r = autoupdate._ChangeUrlPort('http://fuzzy:8080/static', 8085)
219 self.assertEqual(r, 'http://fuzzy:8085/static')
220
221 r = autoupdate._ChangeUrlPort('http://fuzzy/static', 8085)
222 self.assertEqual(r, 'http://fuzzy:8085/static')
223
224 r = autoupdate._ChangeUrlPort('ftp://fuzzy/static', 8085)
225 self.assertEqual(r, 'ftp://fuzzy:8085/static')
226
227 r = autoupdate._ChangeUrlPort('ftp://fuzzy', 8085)
228 self.assertEqual(r, 'ftp://fuzzy:8085')
229
Dale Curtisc9aaf3a2011-08-09 15:47:40 -0700230 def testHandleHostInfoPing(self):
231 au_mock = self._DummyAutoupdateConstructor()
232 self.assertRaises(AssertionError, au_mock.HandleHostInfoPing, None)
233
Gilad Arnold286a0062012-01-12 13:47:02 -0800234 # Setup fake host_infos entry and ensure it comes back to us in one piece.
Dale Curtisc9aaf3a2011-08-09 15:47:40 -0700235 test_ip = '1.2.3.4'
Gilad Arnold286a0062012-01-12 13:47:02 -0800236 au_mock.host_infos.GetInitHostInfo(test_ip).attrs = self.test_dict
Dale Curtisc9aaf3a2011-08-09 15:47:40 -0700237 self.assertEqual(
238 json.loads(au_mock.HandleHostInfoPing(test_ip)), self.test_dict)
239
240 def testHandleSetUpdatePing(self):
241 au_mock = self._DummyAutoupdateConstructor()
242 test_ip = '1.2.3.4'
243 test_label = 'test/old-update'
244 self.assertRaises(
245 AssertionError, au_mock.HandleSetUpdatePing, test_ip, None)
246 self.assertRaises(
247 AssertionError, au_mock.HandleSetUpdatePing, None, test_label)
248 self.assertRaises(
249 AssertionError, au_mock.HandleSetUpdatePing, None, None)
250
251 au_mock.HandleSetUpdatePing(test_ip, test_label)
252 self.assertEqual(
Chris Sosa1885d032012-11-29 17:07:27 -0800253 au_mock.host_infos.GetHostInfo(test_ip).attrs['forced_update_label'],
Gilad Arnold286a0062012-01-12 13:47:02 -0800254 test_label)
Dale Curtisc9aaf3a2011-08-09 15:47:40 -0700255
256 def testHandleUpdatePingWithSetUpdate(self):
joychen7c2054a2013-07-25 11:14:07 -0700257 """If update is set, it should use the update found in that directory."""
Chris Sosa6a3697f2013-01-29 16:44:43 -0800258 self.mox.StubOutWithMock(autoupdate.Autoupdate, '_StoreMetadataToFile')
259 au_mock = self._DummyAutoupdateConstructor()
Dale Curtisc9aaf3a2011-08-09 15:47:40 -0700260
261 test_data = _TEST_REQUEST % self.test_dict
262 test_label = 'new_update-test/the-new-update'
263 new_image_dir = os.path.join(self.static_image_dir, test_label)
264 new_url = self.url.replace('update.gz', test_label + '/update.gz')
265
Chris Sosa6a3697f2013-01-29 16:44:43 -0800266 # Generate a fake payload.
joychen121fc9b2013-08-02 14:30:30 -0700267 common_util.MkDirP(new_image_dir)
joychen7c2054a2013-07-25 11:14:07 -0700268 update_gz = os.path.join(new_image_dir, constants.UPDATE_FILE)
Chris Sosa6a3697f2013-01-29 16:44:43 -0800269 with open(update_gz, 'w') as fh:
270 fh.write('')
David Zeuthen52ccd012013-10-31 12:58:26 -0700271 metadata_hash = os.path.join(new_image_dir, constants.METADATA_HASH_FILE)
272 with open(metadata_hash, 'w') as fh:
273 fh.write('')
Chris Sosa6a3697f2013-01-29 16:44:43 -0800274
Gilad Arnold55a2a372012-10-02 09:46:32 -0700275 common_util.GetFileSha1(os.path.join(
Gilad Arnold0c9c8602012-10-02 23:58:58 -0700276 new_image_dir, 'update.gz')).AndReturn(self.sha1)
Gilad Arnold55a2a372012-10-02 09:46:32 -0700277 common_util.GetFileSha256(os.path.join(
Dale Curtisc9aaf3a2011-08-09 15:47:40 -0700278 new_image_dir, 'update.gz')).AndReturn(self.sha256)
Gilad Arnold55a2a372012-10-02 09:46:32 -0700279 common_util.GetFileSize(os.path.join(
Dale Curtisc9aaf3a2011-08-09 15:47:40 -0700280 new_image_dir, 'update.gz')).AndReturn(self.size)
Chris Sosa6a3697f2013-01-29 16:44:43 -0800281 au_mock._StoreMetadataToFile(new_image_dir,
282 mox.IsA(autoupdate.UpdateMetadata))
Chris Sosa52148582012-11-15 15:35:58 -0800283 autoupdate_lib.GetUpdateResponse(
David Zeuthen52ccd012013-10-31 12:58:26 -0700284 self.sha1, self.sha256, self.size, new_url, False, 0, None, None,
285 '3.0', False).AndReturn(self.payload)
Dale Curtisc9aaf3a2011-08-09 15:47:40 -0700286
287 self.mox.ReplayAll()
Dale Curtisc9aaf3a2011-08-09 15:47:40 -0700288 au_mock.HandleSetUpdatePing('127.0.0.1', test_label)
289 self.assertEqual(
Gilad Arnold286a0062012-01-12 13:47:02 -0800290 au_mock.host_infos.GetHostInfo('127.0.0.1').
Chris Sosa1885d032012-11-29 17:07:27 -0800291 attrs['forced_update_label'],
Gilad Arnold286a0062012-01-12 13:47:02 -0800292 test_label)
Dale Curtisc9aaf3a2011-08-09 15:47:40 -0700293 self.assertEqual(au_mock.HandleUpdatePing(test_data), self.payload)
Gilad Arnold286a0062012-01-12 13:47:02 -0800294 self.assertFalse('forced_update_label' in
295 au_mock.host_infos.GetHostInfo('127.0.0.1').attrs)
Dale Curtisc9aaf3a2011-08-09 15:47:40 -0700296
Daniel Erat8a0bc4a2011-09-30 08:52:52 -0700297 def testGetVersionFromDir(self):
298 au = self._DummyAutoupdateConstructor()
299
300 # New-style version number.
301 self.assertEqual(
302 au._GetVersionFromDir('/foo/x86-alex/R16-1102.0.2011_09_30_0806-a1'),
303 '1102.0.2011_09_30_0806')
304
Daniel Erat8a0bc4a2011-09-30 08:52:52 -0700305 def testCanUpdate(self):
306 au = self._DummyAutoupdateConstructor()
307
308 # When both the client and the server have new-style versions, we should
309 # just compare the tokens directly.
310 self.assertTrue(
311 au._CanUpdate('1098.0.2011_09_28_1635', '1098.0.2011_09_30_0806'))
312 self.assertTrue(
313 au._CanUpdate('1098.0.2011_09_28_1635', '1100.0.2011_09_26_0000'))
314 self.assertFalse(
315 au._CanUpdate('1098.0.2011_09_28_1635', '1098.0.2011_09_26_0000'))
316 self.assertFalse(
317 au._CanUpdate('1098.0.2011_09_28_1635', '1096.0.2011_09_30_0000'))
318
Gilad Arnold0c9c8602012-10-02 23:58:58 -0700319 def testHandleUpdatePingRemotePayload(self):
320 remote_urlbase = 'http://remotehost:6666'
321 remote_payload_path = 'static/path/to/update.gz'
322 remote_url = '/'.join([remote_urlbase, remote_payload_path, 'update.gz'])
Chris Sosa6a3697f2013-01-29 16:44:43 -0800323 au_mock = self._DummyAutoupdateConstructor(urlbase=remote_urlbase,
324 payload_path=remote_payload_path,
325 remote_payload=True)
Gilad Arnold0c9c8602012-10-02 23:58:58 -0700326
Chris Sosa4b951602014-04-09 20:26:07 -0700327 incomplete_test_data = _TEST_REQUEST % self.test_dict
328 complete_test_data = _FULL_TEST_REQUEST % self.test_dict
Gilad Arnold0c9c8602012-10-02 23:58:58 -0700329
Chris Sosa6a3697f2013-01-29 16:44:43 -0800330 au_mock._GetRemotePayloadAttrs(remote_url).AndReturn(
David Zeuthen52ccd012013-10-31 12:58:26 -0700331 autoupdate.UpdateMetadata(self.sha1, self.sha256, self.size, False,
332 0, ''))
Chris Sosa52148582012-11-15 15:35:58 -0800333 autoupdate_lib.GetUpdateResponse(
David Zeuthen52ccd012013-10-31 12:58:26 -0700334 self.sha1, self.sha256, self.size, remote_url, False, 0, None, None,
Chris Sosa52148582012-11-15 15:35:58 -0800335 '3.0', False).AndReturn(self.payload)
Gilad Arnold0c9c8602012-10-02 23:58:58 -0700336
337 self.mox.ReplayAll()
Chris Sosa4b951602014-04-09 20:26:07 -0700338 # This should fail because of missing fields.
339 self.assertRaises(common_util.DevServerHTTPError,
340 au_mock.HandleUpdatePing, incomplete_test_data)
341 # This should have enough information.
342 self.assertEqual(au_mock.HandleUpdatePing(complete_test_data), self.payload)
Gilad Arnold0c9c8602012-10-02 23:58:58 -0700343 self.mox.VerifyAll()
344
Chris Sosa0356d3b2010-09-16 15:46:22 -0700345
Gilad Arnoldc65330c2012-09-20 15:17:48 -0700346if __name__ == '__main__':
347 unittest.main()