Esempio n. 1
0
 def test_get_all_proxies_osx_fails(self):
     proxy.__grains__['os'] = 'Darwin'
     mock = MagicMock()
     with patch.dict(proxy.__salt__, {'reg.read_value': mock}):
         out = proxy.get_proxy_win()
         assert not mock.called
         self.assertEqual(out, None)
Esempio n. 2
0
 def test_get_all_proxies_windows(self):
     '''
     Test to make sure that we correctly get the current proxy info on
     Windows
     '''
     results = [{'vdata': 'http=192.168.0.1:3128;https=192.168.0.2:3128;ftp=192.168.0.3:3128'},
                {'vdata': 1}]
     mock = MagicMock(side_effect=results)
     expected = {'enabled': True,
                 'http': {'server': '192.168.0.1',
                          'port': '3128'},
                 'https': {'server': '192.168.0.2',
                           'port': '3128'},
                 'ftp': {'server': '192.168.0.3',
                         'port': '3128'}}
     calls = [
         call(hive='HKEY_CURRENT_USER',
              key='SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings',
              vname='ProxyServer'),
         call(hive='HKEY_CURRENT_USER',
              key='SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings',
              vname='ProxyEnable')]
     with patch.dict(proxy.__grains__, {'os': 'Windows'}):
         with patch.dict(proxy.__salt__, {'reg.read_value': mock}):
             out = proxy.get_proxy_win()
             mock.assert_has_calls(calls)
             self.assertEqual(expected, out)
Esempio n. 3
0
 def test_get_all_proxies_windows(self):
     '''
         Test to make sure that we correctly get the current proxy info
         on Windows
     '''
     proxy.__grains__['os'] = 'Windows'
     result = {
         'vdata':
         'http=192.168.0.1:3128;https=192.168.0.2:3128;ftp=192.168.0.3:3128'
     }
     mock = MagicMock(return_value=result)
     expected = {
         'http': {
             'server': '192.168.0.1',
             'port': '3128'
         },
         'https': {
             'server': '192.168.0.2',
             'port': '3128'
         },
         'ftp': {
             'server': '192.168.0.3',
             'port': '3128'
         }
     }
     with patch.dict(proxy.__salt__, {'reg.read_value': mock}):
         out = proxy.get_proxy_win()
         mock.assert_called_once_with(
             'HKEY_CURRENT_USER',
             'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings',
             'ProxyServer')
         self.assertEqual(expected, out)
Esempio n. 4
0
def test_get_all_proxies_windows():
    """
    Test to make sure that we correctly get the current proxy info on
    Windows
    """
    results = [
        {
            "vdata":
            ("http=192.168.0.1:3128;https=192.168.0.2:3128;ftp=192.168.0.3:3128"
             )
        },
        {
            "vdata": 1
        },
    ]
    mock = MagicMock(side_effect=results)
    expected = {
        "enabled": True,
        "http": {
            "server": "192.168.0.1",
            "port": "3128"
        },
        "https": {
            "server": "192.168.0.2",
            "port": "3128"
        },
        "ftp": {
            "server": "192.168.0.3",
            "port": "3128"
        },
    }
    calls = [
        call(
            hive="HKEY_CURRENT_USER",
            key=
            "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings",
            vname="ProxyServer",
        ),
        call(
            hive="HKEY_CURRENT_USER",
            key=
            "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings",
            vname="ProxyEnable",
        ),
    ]
    with patch.dict(proxy.__grains__,
                    {"os": "Windows"}), patch.dict(proxy.__utils__,
                                                   {"reg.read_value": mock}):
        out = proxy.get_proxy_win()
        mock.assert_has_calls(calls)
        assert expected == out
Esempio n. 5
0
 def test_get_all_proxies_windows(self):
     """
     Test to make sure that we correctly get the current proxy info on
     Windows
     """
     results = [
         {
             "vdata":
             "http=192.168.0.1:3128;https=192.168.0.2:3128;ftp=192.168.0.3:3128"
         },
         {
             "vdata": 1
         },
     ]
     mock = MagicMock(side_effect=results)
     expected = {
         "enabled": True,
         "http": {
             "server": "192.168.0.1",
             "port": "3128"
         },
         "https": {
             "server": "192.168.0.2",
             "port": "3128"
         },
         "ftp": {
             "server": "192.168.0.3",
             "port": "3128"
         },
     }
     calls = [
         call(
             hive='HKEY_CURRENT_USER',
             key=
             'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings',
             vname='ProxyServer'),
         call(
             hive='HKEY_CURRENT_USER',
             key=
             'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings',
             vname='ProxyEnable')
     ]
     with patch.dict(proxy.__grains__, {'os': 'Windows'}):
         with patch.dict(proxy.__utils__, {'reg.read_value': mock}):
             out = proxy.get_proxy_win()
             mock.assert_has_calls(calls)
             self.assertEqual(expected, out)
Esempio n. 6
0
 def test_get_proxy_win(self):
     """
     Test to make sure that we correctly get the current proxy info on
     Windows
     """
     result = [
         {
             "vdata":
             "http=192.168.0.1:3128;https=192.168.0.2:3128;ftp=192.168.0.3:3128"
         },
         {
             "vdata": 1
         },
     ]
     mock_reg_read = MagicMock(side_effect=result)
     expected = {
         "enabled": True,
         "http": {
             "server": "192.168.0.1",
             "port": "3128"
         },
         "https": {
             "server": "192.168.0.2",
             "port": "3128"
         },
         "ftp": {
             "server": "192.168.0.3",
             "port": "3128"
         },
     }
     with patch.dict(proxy.__grains__, {"os": "Windows"}), patch.dict(
             proxy.__utils__, {"reg.read_value": mock_reg_read}):
         out = proxy.get_proxy_win()
         self.assertDictEqual(out, expected)
         mock_reg_read.assert_any_call(
             hive="HKEY_CURRENT_USER",
             key=
             "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings",
             vname="ProxyServer",
         )
         mock_reg_read.assert_any_call(
             hive="HKEY_CURRENT_USER",
             key=
             "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings",
             vname="ProxyEnable",
         )
Esempio n. 7
0
    def test_get_all_proxies_windows(self):
        '''
            Test to make sure that we correctly get the current proxy info
            on Windows
        '''
        proxy.__grains__['os'] = 'Windows'
        results = [
            {
                'vdata': 'http=192.168.0.1:3128;https=192.168.0.2:3128;ftp=192.168.0.3:3128'
            },
            {
                'vdata': 1
            }
        ]
        mock = MagicMock(side_effect=results)

        expected = {
            'enabled': True,
            'http': {
                'server': '192.168.0.1',
                'port': '3128'
            },
            'https': {
                'server': '192.168.0.2',
                'port': '3128'
            },
            'ftp': {
                'server': '192.168.0.3',
                'port': '3128'
            }
        }
        with patch.dict(proxy.__salt__, {'reg.read_value': mock}):
            out = proxy.get_proxy_win()
            calls = [
                call('HKEY_CURRENT_USER',
                     'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings',
                     'ProxyServer'),
                call('HKEY_CURRENT_USER',
                     'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings',
                     'ProxyEnable'),
            ]

            mock.assert_has_calls(calls)
            self.assertEqual(expected, out)
Esempio n. 8
0
 def test_get_proxy_win(self):
     '''
     Test to make sure that we correctly get the current proxy info on
     Windows
     '''
     result = [{
         'vdata':
         'http=192.168.0.1:3128;https=192.168.0.2:3128;ftp=192.168.0.3:3128'
     }, {
         'vdata': 1
     }]
     mock_reg_read = MagicMock(side_effect=result)
     expected = {
         'enabled': True,
         'http': {
             'server': '192.168.0.1',
             'port': '3128'
         },
         'https': {
             'server': '192.168.0.2',
             'port': '3128'
         },
         'ftp': {
             'server': '192.168.0.3',
             'port': '3128'
         }
     }
     with patch.dict(proxy.__grains__, {'os': 'Windows'}), \
             patch.dict(proxy.__utils__, {'reg.read_value': mock_reg_read}):
         out = proxy.get_proxy_win()
         self.assertDictEqual(out, expected)
         mock_reg_read.assert_any_call(
             hive='HKEY_CURRENT_USER',
             key=
             'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings',
             vname='ProxyServer')
         mock_reg_read.assert_any_call(
             hive='HKEY_CURRENT_USER',
             key=
             'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings',
             vname='ProxyEnable')
Esempio n. 9
0
 def test_get_all_proxies_macos_fails(self):
     mock = MagicMock()
     with patch.dict(proxy.__salt__, {'reg.read_value': mock}):
         out = proxy.get_proxy_win()
         assert not mock.called
         self.assertEqual(out, None)
Esempio n. 10
0
def test_get_all_proxies_macos_fails():
    mock = MagicMock()
    with patch.dict(proxy.__utils__, {"reg.read_value": mock}):
        out = proxy.get_proxy_win()
        assert not mock.called
        assert out is None