1# Copyright (c) 2013 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.client.cros import dhcp_handling_rule 7from autotest_lib.client.cros import dhcp_packet 8from autotest_lib.client.cros import dhcp_test_base 9from autotest_lib.client.cros.networking import shill_proxy 10 11# Length of time the lease from the DHCP server is valid. 12LEASE_TIME_SECONDS = 60 13# We'll fill in the subnet and give this address to the client. 14INTENDED_IP_SUFFIX = "0.0.0.101" 15# We should be able to complete a DHCP negotiation in this amount of time. 16DHCP_NEGOTIATION_TIMEOUT_SECONDS = 10 17 18class network_DhcpWpadNegotiation(dhcp_test_base.DhcpTestBase): 19 """Test implemenation of WPAD negotiation.""" 20 21 def check_wpad_config(self, proxy_auto_config): 22 """Check that the ipconfig in the client shows the the proxy config. 23 24 @param proxy_auto_config string expected value for proxy autoconfig. 25 26 """ 27 proxy = shill_proxy.ShillProxy() 28 device = proxy.find_object( 29 'Device', 30 {'Name': self.ethernet_pair.peer_interface_name}) 31 if device is None: 32 raise error.TestFail('Device was not found.') 33 device_properties = device.GetProperties(utf8_strings=True) 34 ipconfig_path = device_properties['IPConfigs'][0] 35 ipconfig = proxy.get_dbus_object('org.chromium.flimflam.IPConfig', 36 ipconfig_path) 37 ipconfig_properties = ipconfig.GetProperties(utf8_strings=True) 38 ipconfig_proxy_auto_config = ipconfig_properties[ 39 'WebProxyAutoDiscoveryUrl'] 40 if ipconfig_proxy_auto_config != proxy_auto_config: 41 raise error.TestFail('Shill proxy config %s does not match ' 42 'expected %s.' % 43 (proxy_auto_config, 44 ipconfig_proxy_auto_config)) 45 46 47 def test_body(self): 48 """Main body of the test.""" 49 subnet_mask = self.ethernet_pair.interface_subnet_mask 50 intended_ip = dhcp_test_base.DhcpTestBase.rewrite_ip_suffix( 51 subnet_mask, 52 self.server_ip, 53 INTENDED_IP_SUFFIX) 54 # Two real name servers, and a bogus one to be unpredictable. 55 dns_servers = ["8.8.8.8", "8.8.4.4", "192.168.87.88"] 56 proxy_auto_config = "http://server:8080/wpad.dat" 57 # This is the pool of information the server will give out to the client 58 # upon request. 59 dhcp_options = { 60 dhcp_packet.OPTION_SERVER_ID : self.server_ip, 61 dhcp_packet.OPTION_SUBNET_MASK : subnet_mask, 62 dhcp_packet.OPTION_IP_LEASE_TIME : LEASE_TIME_SECONDS, 63 dhcp_packet.OPTION_REQUESTED_IP : intended_ip, 64 dhcp_packet.OPTION_DNS_SERVERS : dns_servers, 65 dhcp_packet.OPTION_WEB_PROXY_AUTO_DISCOVERY : proxy_auto_config 66 } 67 rules = [ 68 dhcp_handling_rule.DhcpHandlingRule_RespondToDiscovery( 69 intended_ip, self.server_ip, dhcp_options, {}), 70 dhcp_handling_rule.DhcpHandlingRule_RespondToRequest( 71 intended_ip, self.server_ip, dhcp_options, {}) 72 ] 73 rules[-1].is_final_handler = True 74 self.server.start_test(rules, DHCP_NEGOTIATION_TIMEOUT_SECONDS) 75 self.server.wait_for_test_to_finish() 76 if not self.server.last_test_passed: 77 raise error.TestFail("Test server didn't get all the messages it " 78 "was told to expect during negotiation.") 79 80 self.wait_for_dhcp_propagation() 81 self.check_wpad_config(proxy_auto_config) 82