def test_cert_bad_hostname(self): with ServerResource() as server: with pytest.raises(TransportError) as exc: SslSocketTransport('', port=server.port, cert_file=CertFiles.BAD_HOSTNAME) assert 'right hostname' in exc.value.message.lower()
def test_no_ca(self): with ServerResource() as server: with pytest.raises(TransportError) as exc: SslSocketTransport('', port=server.port, cert_file=CertFiles.CERT_AND_KEY) assert 'cert not trusted' in exc.value.message.lower()
def test_with_real_server(self): with ServerResource() as server: sslw = self._working_transport(server) assert not sslw.is_connected sslw.start() assert sslw.is_connected response = sslw.communicate('HELLO') assert response == response_for("HELLO")
def test_stop_real_server(self): with ServerResource() as server: t = self._working_transport(server) t.start() assert not t._ssl_sock._closed, "Shouldn't have closed socket" log.info("Started transport") t.stop() assert not t.is_connected assert t._ssl_sock._closed, "Should have closed socket" log.info("Finished test")
def test_failing_socket_raises_eventually(self): with ServerResource() as server: transport = self._working_transport(server) transport._ssl_sock = FailingSocket() assert transport.is_connected assert transport._MAX_FAILURES == 3 assert not transport.communicate('HELLO') assert not transport.communicate('HELLO?') with pytest.raises(TransportError) as e: transport.communicate('HELLO??') assert "Too many Squeezebox failures" in str(e) assert transport._ssl_sock.closed
def test_with_real_server_failing_socket(self): with ServerResource() as server: transport = self._working_transport(server) transport._ssl_sock = FailingSocket() assert transport.is_connected assert not transport.communicate('HELLO')
def test_with_real_server_no_wait(self): with ServerResource() as server: sslw = self._working_transport(server) assert sslw.communicate('HELLO', wait=False) is None
def test_wrong_port(self): with ServerResource(tls=False) as server: with pytest.raises(TransportError) as exc: SslSocketTransport('localhost', port=server.port) msg = exc.value.message.lower() assert ('not tls on port %d' % server.port) in msg