Example #1
0
 def test_same_port_tls_port(self):
     cfile = create_config(
         ("listen=127.0.0.1:25", "tls_listen=127.0.0.1:25")
     )
     conf = Config(cfile).load()
     with pytest.raises(ConfigException):
         conf.test_tls_port()
Example #2
0
 def test_tls_under_1024_no_perms(self, mock_getuid):
     cfile = create_config(('tls_port=1023',))
     conf = Config(cfile).load()
     with pytest.raises(ConfigException):
         conf.test_tls_port()
     assert mock_getuid.called is True
     assert mock_getuid.call_count is 1
Example #3
0
 def test_tls_over_1023_available(self, mock_getuid):
     cfile = create_config(('tls_port=1024',))
     conf = Config(cfile).load()
     with mock.patch('socket.socket.bind', return_value=True):
         conf.test_tls_port()
     assert mock_getuid.called is True
     assert mock_getuid.call_count is 1
Example #4
0
 def test_tls_over_1023_available(self):
     cfile = create_config(('tls_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_tls_port()
     assert mock_getuid.called is True
     assert mock_getuid.call_count is 1
Example #5
0
 def test_tls_under_1024_no_perms(self):
     cfile = create_config(('tls_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_tls_port()
     assert mock_getuid.called is True
     assert mock_getuid.call_count is 1
Example #6
0
 def test_tls_under_1024_with_perms_available(self):
     cfile = create_config(("tls_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_tls_port()
     assert mock_getuid.called is True
     assert mock_getuid.call_count is 1
Example #7
0
 def test_tls_over_1023_unavailable(self, mock_getuid, mock_socket):
     cfile = create_config(('tls_port=1024',))
     conf = Config(cfile).load()
     with pytest.raises(ConfigException):
         conf.test_tls_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 #8
0
 def test_tls_over_1023_unavailable(self):
     cfile = create_config(('tls_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_tls_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_tls_under_1024_with_perms_unavailable(self):
     cfile = create_config(("tls_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_tls_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_same_port_tls_port(self):
     cfile = create_config(
         ("listen=127.0.0.1:25", "tls_listen=127.0.0.1:25"))
     conf = Config(cfile).load()
     with pytest.raises(ConfigException):
         conf.test_tls_port()
Example #11
0
 def test_same_port_tls_port(self):
     cfile = create_config(('port=25', 'tls_port=25',))
     conf = Config(cfile).load()
     assert conf._port == conf._tls_port
     with pytest.raises(ConfigException):
         conf.test_tls_port()
Example #12
0
 def test_str_tls_port(self):
     cfile = create_config(('tls_port=xcbsfbsrwgrwgsgrsgsdgrwty4y4fsg',))
     conf = Config(cfile).load()
     with pytest.raises(ConfigException):
         conf.test_tls_port()