def test_set_https_proxy_windows(self): ''' Test to make sure that we correctly set the proxy info on Windows ''' proxy.__grains__['os'] = 'Windows' mock_reg = MagicMock() mock_cmd = MagicMock() with patch.dict(proxy.__salt__, {'reg.set_value': mock_reg, 'cmd.run': mock_cmd}): out = proxy.set_https_proxy('192.168.0.1', 3128, bypass_hosts=['.moo.com', '.salt.com']) calls = [ call('HKEY_CURRENT_USER', 'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings', 'ProxyServer', 'https=192.168.0.1:3128;'), call('HKEY_CURRENT_USER', 'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings', 'ProxyEnable', 1, vtype='REG_DWORD'), call('HKEY_CURRENT_USER', 'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings', 'ProxyOverride', '<local>;.moo.com;.salt.com') ] mock_reg.assert_has_calls(calls) mock_cmd.assert_called_once_with('netsh winhttp import proxy source=ie') self.assertTrue(out)
def test_set_https_proxy_macos(self): ''' Test to make sure that we correctly set the proxy info on macOS ''' mock = MagicMock() with patch.dict(proxy.__salt__, {'cmd.run': mock}): out = proxy.set_https_proxy('192.168.0.1', 3128, 'frank', 'passw0rd', bypass_hosts='.moo.com,.salt.com') mock.assert_called_once_with('networksetup -setsecurewebproxy Ethernet 192.168.0.1 3128 On frank passw0rd') self.assertTrue(out)
def test_set_https_proxy_osx(self): ''' Test to make sure that we correctly set the proxy info on OSX ''' proxy.__grains__['os'] = 'Darwin' mock = MagicMock() with patch.dict(proxy.__salt__, {'cmd.run': mock}): out = proxy.set_https_proxy('192.168.0.1', 3128, 'frank', 'passw0rd', bypass_hosts='.moo.com,.salt.com') mock.assert_called_once_with('networksetup -setsecurewebproxy Ethernet 192.168.0.1 3128 On frank passw0rd') self.assertTrue(out)
def test_set_https_proxy_windows(self): """ Test to make sure that we correctly set the proxy info on Windows """ calls = [ call( hive="HKEY_CURRENT_USER", key= "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", vname="ProxyServer", vdata="https=192.168.0.1:3128;", ), call( hive="HKEY_CURRENT_USER", key= "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", vname="ProxyEnable", vdata=1, vtype="REG_DWORD", ), call( hive="HKEY_CURRENT_USER", key= "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", vname="ProxyOverride", vdata="<local>;.moo.com;.salt.com", ), ] mock_reg = MagicMock() mock_cmd = MagicMock() with patch.dict(proxy.__grains__, {"os": "Windows"}): with patch.dict(proxy.__salt__, { "reg.set_value": mock_reg, "cmd.run": mock_cmd }): out = proxy.set_https_proxy( server="192.168.0.1", port=3128, bypass_hosts=[".moo.com", ".salt.com"], ) mock_reg.assert_has_calls(calls) mock_cmd.assert_called_once_with( "netsh winhttp import proxy source=ie") self.assertTrue(out)
def test_set_https_proxy_macos(self): """ Test to make sure that we correctly set the proxy info on macOS """ mock = MagicMock() with patch.dict(proxy.__salt__, {"cmd.run": mock}): out = proxy.set_https_proxy( "192.168.0.1", 3128, "frank", "passw0rd", bypass_hosts=".moo.com,.salt.com", ) mock.assert_called_once_with( "networksetup -setsecurewebproxy Ethernet 192.168.0.1 3128 On frank" " passw0rd") self.assertTrue(out)