Chris Sosa | 0356d3b | 2010-09-16 15:46:22 -0700 | [diff] [blame] | 1 | #!/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 Curtis | c9aaf3a | 2011-08-09 15:47:40 -0700 | [diff] [blame] | 9 | import json |
Chris Sosa | 0356d3b | 2010-09-16 15:46:22 -0700 | [diff] [blame] | 10 | import os |
Chris Sosa | 7c93136 | 2010-10-11 19:49:01 -0700 | [diff] [blame] | 11 | import socket |
Chris Sosa | 0356d3b | 2010-09-16 15:46:22 -0700 | [diff] [blame] | 12 | import unittest |
Chris Sosa | 0356d3b | 2010-09-16 15:46:22 -0700 | [diff] [blame] | 13 | |
Gilad Arnold | abb352e | 2012-09-23 01:24:27 -0700 | [diff] [blame] | 14 | import cherrypy |
| 15 | import mox |
| 16 | |
Chris Sosa | 0356d3b | 2010-09-16 15:46:22 -0700 | [diff] [blame] | 17 | import autoupdate |
Gilad Arnold | 55a2a37 | 2012-10-02 09:46:32 -0700 | [diff] [blame] | 18 | import common_util |
Chris Sosa | 0356d3b | 2010-09-16 15:46:22 -0700 | [diff] [blame] | 19 | |
Gilad Arnold | abb352e | 2012-09-23 01:24:27 -0700 | [diff] [blame] | 20 | |
Chris Sosa | 0356d3b | 2010-09-16 15:46:22 -0700 | [diff] [blame] | 21 | _TEST_REQUEST = """ |
| 22 | <client_test xmlns:o="http://www.google.com/update2/request" updaterversion="%(client)s" > |
| 23 | <o:app version="%(version)s" track="%(track)s" board="%(board)s" /> |
Chris Sosa | a387a87 | 2010-09-29 11:51:36 -0700 | [diff] [blame] | 24 | <o:updatecheck /> |
Dale Curtis | c9aaf3a | 2011-08-09 15:47:40 -0700 | [diff] [blame] | 25 | <o:event eventresult="%(event_result)d" eventtype="%(event_type)d" /> |
Chris Sosa | 0356d3b | 2010-09-16 15:46:22 -0700 | [diff] [blame] | 26 | </client_test>""" |
| 27 | |
| 28 | |
| 29 | class AutoupdateTest(mox.MoxTestBase): |
| 30 | def setUp(self): |
| 31 | mox.MoxTestBase.setUp(self) |
Gilad Arnold | 55a2a37 | 2012-10-02 09:46:32 -0700 | [diff] [blame] | 32 | self.mox.StubOutWithMock(common_util, 'GetFileSize') |
| 33 | self.mox.StubOutWithMock(common_util, 'GetFileSha1') |
| 34 | self.mox.StubOutWithMock(common_util, 'GetFileSha256') |
Chris Sosa | 0356d3b | 2010-09-16 15:46:22 -0700 | [diff] [blame] | 35 | self.mox.StubOutWithMock(autoupdate.Autoupdate, 'GetUpdatePayload') |
| 36 | self.mox.StubOutWithMock(autoupdate.Autoupdate, '_GetLatestImageDir') |
Gilad Arnold | 0c9c860 | 2012-10-02 23:58:58 -0700 | [diff] [blame] | 37 | self.mox.StubOutWithMock(autoupdate.Autoupdate, '_GetRemotePayloadAttrs') |
Chris Sosa | 7c93136 | 2010-10-11 19:49:01 -0700 | [diff] [blame] | 38 | self.port = 8080 |
Chris Sosa | 0356d3b | 2010-09-16 15:46:22 -0700 | [diff] [blame] | 39 | self.test_board = 'test-board' |
| 40 | self.build_root = '/src_path/build/images' |
| 41 | self.latest_dir = '12345_af_12-a1' |
| 42 | self.latest_verision = '12345_af_12' |
| 43 | self.static_image_dir = '/tmp/static-dir/' |
Chris Sosa | 7c93136 | 2010-10-11 19:49:01 -0700 | [diff] [blame] | 44 | self.hostname = '%s:%s' % (socket.gethostname(), self.port) |
Dale Curtis | c9aaf3a | 2011-08-09 15:47:40 -0700 | [diff] [blame] | 45 | self.test_dict = { |
| 46 | 'client': 'ChromeOSUpdateEngine-1.0', |
| 47 | 'version': 'ForcedUpdate', |
| 48 | 'track': 'unused_var', |
| 49 | 'board': self.test_board, |
| 50 | 'event_result': 2, |
| 51 | 'event_type': 3 |
| 52 | } |
Chris Sosa | 0356d3b | 2010-09-16 15:46:22 -0700 | [diff] [blame] | 53 | self.test_data = _TEST_REQUEST % self.test_dict |
| 54 | self.forced_image_path = '/path_to_force/chromiumos_image.bin' |
Gilad Arnold | 0c9c860 | 2012-10-02 23:58:58 -0700 | [diff] [blame] | 55 | self.sha1 = 12345 |
Chris Sosa | 0356d3b | 2010-09-16 15:46:22 -0700 | [diff] [blame] | 56 | self.size = 54321 |
| 57 | self.url = 'http://%s/static/update.gz' % self.hostname |
| 58 | self.payload = 'My payload' |
Chris Sosa | a387a87 | 2010-09-29 11:51:36 -0700 | [diff] [blame] | 59 | self.sha256 = 'SHA LA LA' |
Chris Sosa | 5455586 | 2010-10-25 17:26:17 -0700 | [diff] [blame] | 60 | cherrypy.request.base = 'http://%s' % self.hostname |
| 61 | |
Gilad Arnold | 0c9c860 | 2012-10-02 23:58:58 -0700 | [diff] [blame] | 62 | def _DummyAutoupdateConstructor(self, **kwargs): |
Chris Sosa | 0356d3b | 2010-09-16 15:46:22 -0700 | [diff] [blame] | 63 | """Creates a dummy autoupdater. Used to avoid using constructor.""" |
| 64 | dummy = autoupdate.Autoupdate(root_dir=None, |
Chris Sosa | 7c93136 | 2010-10-11 19:49:01 -0700 | [diff] [blame] | 65 | static_dir=self.static_image_dir, |
Gilad Arnold | 0c9c860 | 2012-10-02 23:58:58 -0700 | [diff] [blame] | 66 | **kwargs) |
Chris Sosa | 0356d3b | 2010-09-16 15:46:22 -0700 | [diff] [blame] | 67 | return dummy |
| 68 | |
Chris Sosa | 744e147 | 2011-09-07 19:32:50 -0700 | [diff] [blame] | 69 | def testGetRightSignedDeltaPayloadDir(self): |
| 70 | """Test that our directory is what we expect it to be for signed updates.""" |
Gilad Arnold | 55a2a37 | 2012-10-02 09:46:32 -0700 | [diff] [blame] | 71 | self.mox.StubOutWithMock(common_util, 'GetFileMd5') |
Chris Sosa | 744e147 | 2011-09-07 19:32:50 -0700 | [diff] [blame] | 72 | key_path = 'test_key_path' |
| 73 | src_image = 'test_src_image' |
| 74 | target_image = 'test_target_image' |
Gilad Arnold | 55a2a37 | 2012-10-02 09:46:32 -0700 | [diff] [blame] | 75 | src_hash = '12345' |
| 76 | target_hash = '67890' |
| 77 | key_hash = 'abcde' |
Chris Sosa | 744e147 | 2011-09-07 19:32:50 -0700 | [diff] [blame] | 78 | |
Gilad Arnold | 55a2a37 | 2012-10-02 09:46:32 -0700 | [diff] [blame] | 79 | common_util.GetFileMd5(src_image).AndReturn(src_hash) |
| 80 | common_util.GetFileMd5(target_image).AndReturn(target_hash) |
| 81 | common_util.GetFileMd5(key_path).AndReturn(key_hash) |
Chris Sosa | 744e147 | 2011-09-07 19:32:50 -0700 | [diff] [blame] | 82 | |
| 83 | self.mox.ReplayAll() |
| 84 | au_mock = self._DummyAutoupdateConstructor() |
| 85 | au_mock.private_key = key_path |
| 86 | update_dir = au_mock.FindCachedUpdateImageSubDir(src_image, target_image) |
Scott Zawalski | 1695453 | 2012-03-20 15:31:36 -0400 | [diff] [blame] | 87 | self.assertEqual(os.path.basename(update_dir), |
Gilad Arnold | 55a2a37 | 2012-10-02 09:46:32 -0700 | [diff] [blame] | 88 | '%s_%s+%s+patched_kernel' % |
| 89 | (src_hash, target_hash, key_hash)) |
Chris Sosa | 744e147 | 2011-09-07 19:32:50 -0700 | [diff] [blame] | 90 | self.mox.VerifyAll() |
| 91 | |
Chris Sosa | 0356d3b | 2010-09-16 15:46:22 -0700 | [diff] [blame] | 92 | def testGenerateLatestUpdateImageWithForced(self): |
Don Garrett | f90edf0 | 2010-11-16 17:36:14 -0800 | [diff] [blame] | 93 | self.mox.StubOutWithMock(autoupdate.Autoupdate, |
| 94 | 'GenerateUpdateImageWithCache') |
Chris Sosa | 0356d3b | 2010-09-16 15:46:22 -0700 | [diff] [blame] | 95 | autoupdate.Autoupdate._GetLatestImageDir(self.test_board).AndReturn( |
| 96 | '%s/%s/%s' % (self.build_root, self.test_board, self.latest_dir)) |
Don Garrett | f90edf0 | 2010-11-16 17:36:14 -0800 | [diff] [blame] | 97 | autoupdate.Autoupdate.GenerateUpdateImageWithCache( |
Chris Sosa | 0356d3b | 2010-09-16 15:46:22 -0700 | [diff] [blame] | 98 | '%s/%s/%s/chromiumos_image.bin' % (self.build_root, self.test_board, |
| 99 | self.latest_dir), |
Don Garrett | f90edf0 | 2010-11-16 17:36:14 -0800 | [diff] [blame] | 100 | static_image_dir=self.static_image_dir).AndReturn('update.gz') |
Chris Sosa | 0356d3b | 2010-09-16 15:46:22 -0700 | [diff] [blame] | 101 | |
| 102 | self.mox.ReplayAll() |
| 103 | au_mock = self._DummyAutoupdateConstructor() |
| 104 | self.assertTrue(au_mock.GenerateLatestUpdateImage(self.test_board, |
| 105 | 'ForcedUpdate', |
| 106 | self.static_image_dir)) |
| 107 | self.mox.VerifyAll() |
| 108 | |
| 109 | def testHandleUpdatePingForForcedImage(self): |
Don Garrett | f90edf0 | 2010-11-16 17:36:14 -0800 | [diff] [blame] | 110 | self.mox.StubOutWithMock(autoupdate.Autoupdate, |
| 111 | 'GenerateUpdateImageWithCache') |
Chris Sosa | 0356d3b | 2010-09-16 15:46:22 -0700 | [diff] [blame] | 112 | |
| 113 | test_data = _TEST_REQUEST % self.test_dict |
| 114 | |
Don Garrett | f90edf0 | 2010-11-16 17:36:14 -0800 | [diff] [blame] | 115 | autoupdate.Autoupdate.GenerateUpdateImageWithCache( |
Chris Sosa | a387a87 | 2010-09-29 11:51:36 -0700 | [diff] [blame] | 116 | self.forced_image_path, |
Don Garrett | f90edf0 | 2010-11-16 17:36:14 -0800 | [diff] [blame] | 117 | static_image_dir=self.static_image_dir).AndReturn('update.gz') |
Gilad Arnold | 55a2a37 | 2012-10-02 09:46:32 -0700 | [diff] [blame] | 118 | common_util.GetFileSha1(os.path.join( |
Gilad Arnold | 0c9c860 | 2012-10-02 23:58:58 -0700 | [diff] [blame] | 119 | self.static_image_dir, 'update.gz')).AndReturn(self.sha1) |
Gilad Arnold | 55a2a37 | 2012-10-02 09:46:32 -0700 | [diff] [blame] | 120 | common_util.GetFileSha256(os.path.join( |
Chris Sosa | a387a87 | 2010-09-29 11:51:36 -0700 | [diff] [blame] | 121 | self.static_image_dir, 'update.gz')).AndReturn(self.sha256) |
Gilad Arnold | 55a2a37 | 2012-10-02 09:46:32 -0700 | [diff] [blame] | 122 | common_util.GetFileSize(os.path.join( |
Chris Sosa | 0356d3b | 2010-09-16 15:46:22 -0700 | [diff] [blame] | 123 | self.static_image_dir, 'update.gz')).AndReturn(self.size) |
| 124 | autoupdate.Autoupdate.GetUpdatePayload( |
Gilad Arnold | 0c9c860 | 2012-10-02 23:58:58 -0700 | [diff] [blame] | 125 | self.sha1, self.sha256, self.size, self.url, False).AndReturn( |
Dale Curtis | c9aaf3a | 2011-08-09 15:47:40 -0700 | [diff] [blame] | 126 | self.payload) |
Chris Sosa | 0356d3b | 2010-09-16 15:46:22 -0700 | [diff] [blame] | 127 | |
| 128 | self.mox.ReplayAll() |
| 129 | au_mock = self._DummyAutoupdateConstructor() |
| 130 | au_mock.forced_image = self.forced_image_path |
| 131 | self.assertEqual(au_mock.HandleUpdatePing(test_data), self.payload) |
| 132 | self.mox.VerifyAll() |
| 133 | |
| 134 | def testHandleUpdatePingForLatestImage(self): |
| 135 | self.mox.StubOutWithMock(autoupdate.Autoupdate, 'GenerateLatestUpdateImage') |
| 136 | |
| 137 | test_data = _TEST_REQUEST % self.test_dict |
| 138 | |
| 139 | autoupdate.Autoupdate.GenerateLatestUpdateImage( |
Don Garrett | f90edf0 | 2010-11-16 17:36:14 -0800 | [diff] [blame] | 140 | self.test_board, 'ForcedUpdate', self.static_image_dir).AndReturn( |
| 141 | 'update.gz') |
Gilad Arnold | 55a2a37 | 2012-10-02 09:46:32 -0700 | [diff] [blame] | 142 | common_util.GetFileSha1(os.path.join( |
Gilad Arnold | 0c9c860 | 2012-10-02 23:58:58 -0700 | [diff] [blame] | 143 | self.static_image_dir, 'update.gz')).AndReturn(self.sha1) |
Gilad Arnold | 55a2a37 | 2012-10-02 09:46:32 -0700 | [diff] [blame] | 144 | common_util.GetFileSha256(os.path.join( |
Chris Sosa | a387a87 | 2010-09-29 11:51:36 -0700 | [diff] [blame] | 145 | self.static_image_dir, 'update.gz')).AndReturn(self.sha256) |
Gilad Arnold | 55a2a37 | 2012-10-02 09:46:32 -0700 | [diff] [blame] | 146 | common_util.GetFileSize(os.path.join( |
Chris Sosa | 0356d3b | 2010-09-16 15:46:22 -0700 | [diff] [blame] | 147 | self.static_image_dir, 'update.gz')).AndReturn(self.size) |
| 148 | autoupdate.Autoupdate.GetUpdatePayload( |
Gilad Arnold | 0c9c860 | 2012-10-02 23:58:58 -0700 | [diff] [blame] | 149 | self.sha1, self.sha256, self.size, self.url, False).AndReturn( |
Dale Curtis | c9aaf3a | 2011-08-09 15:47:40 -0700 | [diff] [blame] | 150 | self.payload) |
Chris Sosa | 0356d3b | 2010-09-16 15:46:22 -0700 | [diff] [blame] | 151 | |
| 152 | self.mox.ReplayAll() |
| 153 | au_mock = self._DummyAutoupdateConstructor() |
| 154 | self.assertEqual(au_mock.HandleUpdatePing(test_data), self.payload) |
Gilad Arnold | 286a006 | 2012-01-12 13:47:02 -0800 | [diff] [blame] | 155 | curr_host_info = au_mock.host_infos.GetHostInfo('127.0.0.1'); |
| 156 | self.assertEqual(curr_host_info.GetAttr('last_known_version'), |
| 157 | 'ForcedUpdate') |
| 158 | self.assertEqual(curr_host_info.GetAttr('last_event_type'), |
| 159 | self.test_dict['event_type']) |
| 160 | self.assertEqual(curr_host_info.GetAttr('last_event_status'), |
| 161 | self.test_dict['event_result']) |
Chris Sosa | 0356d3b | 2010-09-16 15:46:22 -0700 | [diff] [blame] | 162 | self.mox.VerifyAll() |
| 163 | |
Don Garrett | 0ad0937 | 2010-12-06 16:20:30 -0800 | [diff] [blame] | 164 | def testChangeUrlPort(self): |
| 165 | r = autoupdate._ChangeUrlPort('http://fuzzy:8080/static', 8085) |
| 166 | self.assertEqual(r, 'http://fuzzy:8085/static') |
| 167 | |
| 168 | r = autoupdate._ChangeUrlPort('http://fuzzy/static', 8085) |
| 169 | self.assertEqual(r, 'http://fuzzy:8085/static') |
| 170 | |
| 171 | r = autoupdate._ChangeUrlPort('ftp://fuzzy/static', 8085) |
| 172 | self.assertEqual(r, 'ftp://fuzzy:8085/static') |
| 173 | |
| 174 | r = autoupdate._ChangeUrlPort('ftp://fuzzy', 8085) |
| 175 | self.assertEqual(r, 'ftp://fuzzy:8085') |
| 176 | |
Dale Curtis | c9aaf3a | 2011-08-09 15:47:40 -0700 | [diff] [blame] | 177 | def testHandleHostInfoPing(self): |
| 178 | au_mock = self._DummyAutoupdateConstructor() |
| 179 | self.assertRaises(AssertionError, au_mock.HandleHostInfoPing, None) |
| 180 | |
Gilad Arnold | 286a006 | 2012-01-12 13:47:02 -0800 | [diff] [blame] | 181 | # Setup fake host_infos entry and ensure it comes back to us in one piece. |
Dale Curtis | c9aaf3a | 2011-08-09 15:47:40 -0700 | [diff] [blame] | 182 | test_ip = '1.2.3.4' |
Gilad Arnold | 286a006 | 2012-01-12 13:47:02 -0800 | [diff] [blame] | 183 | au_mock.host_infos.GetInitHostInfo(test_ip).attrs = self.test_dict |
Dale Curtis | c9aaf3a | 2011-08-09 15:47:40 -0700 | [diff] [blame] | 184 | self.assertEqual( |
| 185 | json.loads(au_mock.HandleHostInfoPing(test_ip)), self.test_dict) |
| 186 | |
| 187 | def testHandleSetUpdatePing(self): |
| 188 | au_mock = self._DummyAutoupdateConstructor() |
| 189 | test_ip = '1.2.3.4' |
| 190 | test_label = 'test/old-update' |
| 191 | self.assertRaises( |
| 192 | AssertionError, au_mock.HandleSetUpdatePing, test_ip, None) |
| 193 | self.assertRaises( |
| 194 | AssertionError, au_mock.HandleSetUpdatePing, None, test_label) |
| 195 | self.assertRaises( |
| 196 | AssertionError, au_mock.HandleSetUpdatePing, None, None) |
| 197 | |
| 198 | au_mock.HandleSetUpdatePing(test_ip, test_label) |
| 199 | self.assertEqual( |
Gilad Arnold | 286a006 | 2012-01-12 13:47:02 -0800 | [diff] [blame] | 200 | au_mock.host_infos.GetHostInfo(test_ip).GetAttr('forced_update_label'), |
| 201 | test_label) |
Dale Curtis | c9aaf3a | 2011-08-09 15:47:40 -0700 | [diff] [blame] | 202 | |
| 203 | def testHandleUpdatePingWithSetUpdate(self): |
| 204 | self.mox.StubOutWithMock(autoupdate.Autoupdate, 'GenerateLatestUpdateImage') |
| 205 | |
| 206 | test_data = _TEST_REQUEST % self.test_dict |
| 207 | test_label = 'new_update-test/the-new-update' |
| 208 | new_image_dir = os.path.join(self.static_image_dir, test_label) |
| 209 | new_url = self.url.replace('update.gz', test_label + '/update.gz') |
| 210 | |
| 211 | autoupdate.Autoupdate.GenerateLatestUpdateImage( |
| 212 | self.test_board, 'ForcedUpdate', new_image_dir).AndReturn( |
| 213 | 'update.gz') |
Gilad Arnold | 55a2a37 | 2012-10-02 09:46:32 -0700 | [diff] [blame] | 214 | common_util.GetFileSha1(os.path.join( |
Gilad Arnold | 0c9c860 | 2012-10-02 23:58:58 -0700 | [diff] [blame] | 215 | new_image_dir, 'update.gz')).AndReturn(self.sha1) |
Gilad Arnold | 55a2a37 | 2012-10-02 09:46:32 -0700 | [diff] [blame] | 216 | common_util.GetFileSha256(os.path.join( |
Dale Curtis | c9aaf3a | 2011-08-09 15:47:40 -0700 | [diff] [blame] | 217 | new_image_dir, 'update.gz')).AndReturn(self.sha256) |
Gilad Arnold | 55a2a37 | 2012-10-02 09:46:32 -0700 | [diff] [blame] | 218 | common_util.GetFileSize(os.path.join( |
Dale Curtis | c9aaf3a | 2011-08-09 15:47:40 -0700 | [diff] [blame] | 219 | new_image_dir, 'update.gz')).AndReturn(self.size) |
| 220 | autoupdate.Autoupdate.GetUpdatePayload( |
Gilad Arnold | 0c9c860 | 2012-10-02 23:58:58 -0700 | [diff] [blame] | 221 | self.sha1, self.sha256, self.size, new_url, False).AndReturn( |
Dale Curtis | c9aaf3a | 2011-08-09 15:47:40 -0700 | [diff] [blame] | 222 | self.payload) |
| 223 | |
| 224 | self.mox.ReplayAll() |
| 225 | au_mock = self._DummyAutoupdateConstructor() |
| 226 | au_mock.HandleSetUpdatePing('127.0.0.1', test_label) |
| 227 | self.assertEqual( |
Gilad Arnold | 286a006 | 2012-01-12 13:47:02 -0800 | [diff] [blame] | 228 | au_mock.host_infos.GetHostInfo('127.0.0.1'). |
| 229 | GetAttr('forced_update_label'), |
| 230 | test_label) |
Dale Curtis | c9aaf3a | 2011-08-09 15:47:40 -0700 | [diff] [blame] | 231 | self.assertEqual(au_mock.HandleUpdatePing(test_data), self.payload) |
Gilad Arnold | 286a006 | 2012-01-12 13:47:02 -0800 | [diff] [blame] | 232 | self.assertFalse('forced_update_label' in |
| 233 | au_mock.host_infos.GetHostInfo('127.0.0.1').attrs) |
Dale Curtis | c9aaf3a | 2011-08-09 15:47:40 -0700 | [diff] [blame] | 234 | |
Daniel Erat | 8a0bc4a | 2011-09-30 08:52:52 -0700 | [diff] [blame] | 235 | def testGetVersionFromDir(self): |
| 236 | au = self._DummyAutoupdateConstructor() |
| 237 | |
| 238 | # New-style version number. |
| 239 | self.assertEqual( |
| 240 | au._GetVersionFromDir('/foo/x86-alex/R16-1102.0.2011_09_30_0806-a1'), |
| 241 | '1102.0.2011_09_30_0806') |
| 242 | |
| 243 | # Old-style version number. |
| 244 | self.assertEqual( |
| 245 | au._GetVersionFromDir('/foo/x86-alex/0.15.938.2011_08_23_0941-a1'), |
| 246 | '0.15.938.2011_08_23_0941') |
| 247 | |
| 248 | def testCanUpdate(self): |
| 249 | au = self._DummyAutoupdateConstructor() |
| 250 | |
| 251 | # When both the client and the server have new-style versions, we should |
| 252 | # just compare the tokens directly. |
| 253 | self.assertTrue( |
| 254 | au._CanUpdate('1098.0.2011_09_28_1635', '1098.0.2011_09_30_0806')) |
| 255 | self.assertTrue( |
| 256 | au._CanUpdate('1098.0.2011_09_28_1635', '1100.0.2011_09_26_0000')) |
| 257 | self.assertFalse( |
| 258 | au._CanUpdate('1098.0.2011_09_28_1635', '1098.0.2011_09_26_0000')) |
| 259 | self.assertFalse( |
| 260 | au._CanUpdate('1098.0.2011_09_28_1635', '1096.0.2011_09_30_0000')) |
| 261 | |
| 262 | # When the device has an old four-token version number, we should skip the |
| 263 | # first two tokens and compare the rest. If there's a tie, go with the |
| 264 | # server's version. |
| 265 | self.assertTrue(au._CanUpdate('0.16.892.0', '892.0.1')) |
| 266 | self.assertTrue(au._CanUpdate('0.16.892.0', '892.0.0')) |
| 267 | self.assertFalse(au._CanUpdate('0.16.892.0', '890.0.0')) |
| 268 | |
| 269 | # Test the case where both the client and the server have old-style |
| 270 | # versions. |
| 271 | self.assertTrue(au._CanUpdate('0.16.892.0', '0.16.892.1')) |
| 272 | self.assertFalse(au._CanUpdate('0.16.892.0', '0.16.892.0')) |
| 273 | |
Gilad Arnold | 0c9c860 | 2012-10-02 23:58:58 -0700 | [diff] [blame] | 274 | def testHandleUpdatePingRemotePayload(self): |
| 275 | remote_urlbase = 'http://remotehost:6666' |
| 276 | remote_payload_path = 'static/path/to/update.gz' |
| 277 | remote_url = '/'.join([remote_urlbase, remote_payload_path, 'update.gz']) |
| 278 | |
| 279 | test_data = _TEST_REQUEST % self.test_dict |
| 280 | |
| 281 | autoupdate.Autoupdate._GetRemotePayloadAttrs(remote_url).AndReturn( |
| 282 | (self.sha1, self.sha256, self.size, False)) |
| 283 | autoupdate.Autoupdate.GetUpdatePayload( |
| 284 | self.sha1, self.sha256, self.size, remote_url, False).AndReturn( |
| 285 | self.payload) |
| 286 | |
| 287 | self.mox.ReplayAll() |
| 288 | au_mock = self._DummyAutoupdateConstructor(urlbase=remote_urlbase, |
| 289 | payload_path=remote_payload_path, |
| 290 | remote_payload=True) |
| 291 | self.assertEqual(au_mock.HandleUpdatePing(test_data), self.payload) |
| 292 | self.mox.VerifyAll() |
| 293 | |
Chris Sosa | 0356d3b | 2010-09-16 15:46:22 -0700 | [diff] [blame] | 294 | |
Gilad Arnold | c65330c | 2012-09-20 15:17:48 -0700 | [diff] [blame] | 295 | if __name__ == '__main__': |
| 296 | unittest.main() |