1# Copyright 2021 The Chromium OS Authors. All rights reserved. 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5from autotest_lib.client.common_lib import error 6from autotest_lib.server import test 7from autotest_lib.server.hosts.tls_client import connection 8from autotest_lib.server.hosts.tls_client import fake_omaha 9 10 11class infra_TLSFakeOmaha(test.test): 12 """ 13 Start the TLS FakeOmaha service and ensure a URL is returned. 14 15 """ 16 17 version = 1 18 19 def run_once(self, host, case): 20 """ 21 Run the test. 22 23 @param host: A host object representing the DUT. 24 @param case: The case to run. 25 26 """ 27 tlsconn = connection.TLSConnection() 28 self.fake_omaha = fake_omaha.TLSFakeOmaha(tlsconn) 29 self.host = host 30 31 # Run the case 32 eval("self._%s()" % case) 33 34 def _basic(self): 35 """Run the test with the minimum number of flags.""" 36 fake_omaha_url = self.fake_omaha.start_omaha( 37 self.host.hostname, 38 target_build= 39 'gs://chromeos-image-archive/eve-release/R87-13457.0.0', 40 payloads=[{ 41 'payload_id': 'ROOTFS', 42 'payload_type': 'FULL' 43 }]) 44 if fake_omaha_url is None or fake_omaha_url == '': 45 raise error.TestFail("No url returned from fake_omaha") 46 if 'http://' not in fake_omaha_url: 47 raise error.TestFail("fake_omaha returned invalid update url: %s" % 48 fake_omaha_url) 49 50 def _full(self): 51 """Run the test with the none-default flags.""" 52 fake_omaha_url = self.fake_omaha.start_omaha( 53 self.host.hostname, 54 target_build= 55 'gs://chromeos-image-archive/eve-release/R87-13457.0.0', 56 payloads=[{ 57 'payload_id': 'ROOTFS', 58 'payload_type': 'FULL' 59 }], 60 exposed_via_proxy=True, 61 critical_update=True, 62 return_noupdate_starting=1) 63 64 critical_tag = 'critical_update=True' 65 no_update_tag = '&no_update=True' 66 none_proxy_url = 'http://127.0.0.1' 67 if critical_tag not in fake_omaha_url: 68 raise error.TestFail("fake_omaha returned invalid update url: %s" 69 " Expected %s in url." % 70 (fake_omaha_url, critical_tag)) 71 72 if no_update_tag not in fake_omaha_url: 73 raise error.TestFail("fake_omaha returned invalid update url: %s" 74 " Expected %s in url." % 75 (fake_omaha_url, no_update_tag)) 76 77 if none_proxy_url in fake_omaha_url: 78 raise error.TestFail("fake_omaha returned invalid update url: %s" 79 " Expected %s NOT in url." % 80 (fake_omaha_url, none_proxy_url)) 81