Example #1
0
 def test_port_over_1023_available(self, mock_getuid):
     cfile = create_config(('port=1024',))
     conf = Config(cfile).load()
     with mock.patch('socket.socket.bind', return_value=True):
         conf.test_port()
     assert mock_getuid.called is True
     assert mock_getuid.call_count is 1
Example #2
0
 def test_port_under_1024_no_perms(self, mock_getuid):
     cfile = create_config(('port=1023',))
     conf = Config(cfile).load()
     with pytest.raises(ConfigException):
         conf.test_port()
     assert mock_getuid.called is True
     assert mock_getuid.call_count is 1
Example #3
0
 def test_port_over_1023_available(self):
     cfile = create_config(('listen=127.0.0.1:1024', ))
     conf = Config(cfile).load()
     with mock.patch('os.getuid', return_value=9000) as mock_getuid, \
             mock.patch('socket.socket.bind', return_value=True):
         conf.test_port()
     assert mock_getuid.called is True
     assert mock_getuid.call_count is 1
Example #4
0
 def test_port_under_1024_no_perms(self):
     cfile = create_config(('listen=127.0.0.1:1023', ))
     conf = Config(cfile).load()
     with mock.patch('os.getuid', return_value=9000) as mock_getuid, \
             pytest.raises(ConfigException):
         conf.test_port()
     assert mock_getuid.called is True
     assert mock_getuid.call_count is 1
Example #5
0
 def test_port_under_1024_with_perms_available(self):
     cfile = create_config(("listen=127.0.0.1:1024",))
     conf = Config(cfile).load()
     with mock.patch(
         "os.getuid", return_value=0
     ) as mock_getuid, mock.patch("socket.socket.bind", return_value=True):
         conf.test_port()
     assert mock_getuid.called is True
     assert mock_getuid.call_count is 1
Example #6
0
 def test_port_over_1023_available(self):
     cfile = create_config(("listen=127.0.0.1:1024", ))
     conf = Config(cfile).load()
     with mock.patch("os.getuid",
                     return_value=9000) as mock_getuid, mock.patch(
                         "socket.socket.bind", return_value=True):
         conf.test_port()
     assert mock_getuid.called is True
     assert mock_getuid.call_count is 1
Example #7
0
 def test_port_under_1024_no_perms(self):
     cfile = create_config(("listen=127.0.0.1:1023", ))
     conf = Config(cfile).load()
     with mock.patch("os.getuid",
                     return_value=9000) as mock_getuid, pytest.raises(
                         ConfigException):
         conf.test_port()
     assert mock_getuid.called is True
     assert mock_getuid.call_count is 1
Example #8
0
 def test_port_over_1023_unavailable(self, mock_getuid, mock_socket):
     cfile = create_config(('port=1024',))
     conf = Config(cfile).load()
     with pytest.raises(ConfigException):
         conf.test_port()
     assert mock_getuid.called is True
     assert mock_getuid.call_count is 1
     assert mock_socket.called is True
     assert mock_socket.call_count is 1
Example #9
0
 def test_port_over_1023_unavailable(self):
     cfile = create_config(('listen=127.0.0.1:1024', ))
     conf = Config(cfile).load()
     with mock.patch('os.getuid', return_value=9000) as mock_getuid, \
         mock.patch('socket.socket.bind',
                    side_effect=OSError(1, 'none')) as mock_socket, \
             pytest.raises(ConfigException):
         conf.test_port()
     assert mock_getuid.called is True
     assert mock_getuid.call_count is 1
     assert mock_socket.called is True
     assert mock_socket.call_count is 1
Example #10
0
 def test_port_over_1023_unavailable(self):
     cfile = create_config(("listen=127.0.0.1:1024", ))
     conf = Config(cfile).load()
     with mock.patch("os.getuid",
                     return_value=9000) as mock_getuid, mock.patch(
                         "socket.socket.bind",
                         side_effect=OSError(
                             1, "none")) as mock_socket, pytest.raises(
                                 ConfigException):
         conf.test_port()
     assert mock_getuid.called is True
     assert mock_getuid.call_count is 1
     assert mock_socket.called is True
     assert mock_socket.call_count is 1
Example #11
0
 def test_port_under_1024_with_perms_unavailable(self):
     cfile = create_config(("listen=127.0.0.1:1023",))
     conf = Config(cfile).load()
     with mock.patch(
         "os.getuid", return_value=0
     ) as mock_getuid, mock.patch(
         "socket.socket.bind", side_effect=OSError(1, "none")
     ) as mock_socket, pytest.raises(
         ConfigException
     ):
         conf.test_port()
     assert mock_getuid.called is True
     assert mock_getuid.call_count is 1
     assert mock_socket.called is True
     assert mock_socket.call_count is 1
Example #12
0
 def test_tls_larger_than_max(self):
     cfile = create_config(("tls_listen=127.0.0.1:99999",))
     conf = Config(cfile).load()
     with pytest.raises(ConfigException):
         conf.test_port()
Example #13
0
 def test_lower_than_min(self):
     cfile = create_config(("listen=127.0.0.1:0",))
     conf = Config(cfile).load()
     with pytest.raises(ConfigException):
         conf.test_port()
Example #14
0
 def test_tls_larger_than_max(self):
     cfile = create_config(("tls_listen=127.0.0.1:99999", ))
     conf = Config(cfile).load()
     with pytest.raises(ConfigException):
         conf.test_port()
Example #15
0
 def test_lower_than_min(self):
     cfile = create_config(("listen=127.0.0.1:0", ))
     conf = Config(cfile).load()
     with pytest.raises(ConfigException):
         conf.test_port()