Skip to content
This repository was archived by the owner on Jan 13, 2021. It is now read-only.

More informative error message if no protocol found for http2 #305

Merged
merged 1 commit into from
Jan 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion hyper/http20/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,10 @@ def connect(self):
proto = H2C_PROTOCOL

log.debug("Selected NPN protocol: %s", proto)
assert proto in H2_NPN_PROTOCOLS or proto == H2C_PROTOCOL
assert proto in H2_NPN_PROTOCOLS or proto == H2C_PROTOCOL, (
"No suitable protocol found. Supported protocols: %s. "
"Check your OpenSSL version."
) % ','.join(H2_NPN_PROTOCOLS + [H2C_PROTOCOL])

self._sock = BufferedSocket(sock, self.network_buffer_size)

Expand Down
42 changes: 42 additions & 0 deletions test/test_http20.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# -*- coding: utf-8 -*-
"""
test_http20.py
~~~~~~~~~~~~~~

Unit tests for hyper's HTTP/2.0 implementation.
"""
import pytest
from mock import patch

from server import SocketLevelTest


class TestHTTP20Connection(SocketLevelTest):
h2 = True

def test_useful_error_with_no_protocol(self):
self.set_up()

def socket_handler(listener):
sock = listener.accept()[0]
sock.close()

self._start_server(socket_handler)
conn = self.get_connection()

with patch('hyper.http20.connection.wrap_socket') as mock:
mock.return_value = (None, None)
with pytest.raises(AssertionError) as exc_info:
conn.connect()
assert (
"No suitable protocol found."
in
str(exc_info)
)
assert (
"Check your OpenSSL version."
in
str(exc_info)
)

self.tear_down()
7 changes: 5 additions & 2 deletions test/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import hyper
import hyper.http11.connection
import pytest
from mock import patch
from h2.frame_buffer import FrameBuffer
from hyper.compat import ssl
from hyper.contrib import HTTP20Adapter
Expand All @@ -34,8 +35,8 @@
hyper.tls._context.check_hostname = False
hyper.tls._context.verify_mode = ssl.CERT_NONE

# Cover our bases because NPN doesn't yet work on all our test platforms.
hyper.http20.connection.H2_NPN_PROTOCOLS += ['', None]
# Cover our bases because NPN doesn't yet work on all our test platforms.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did this get moved?

PROTOCOLS = hyper.http20.connection.H2_NPN_PROTOCOLS + ['', None]


def decode_frame(frame_data):
Expand Down Expand Up @@ -76,6 +77,7 @@ def receive_preamble(sock):
return


@patch('hyper.http20.connection.H2_NPN_PROTOCOLS', PROTOCOLS)
class TestHyperIntegration(SocketLevelTest):
# These are HTTP/2 tests.
h2 = True
Expand Down Expand Up @@ -1031,6 +1033,7 @@ def socket_handler(listener):
self.tear_down()


@patch('hyper.http20.connection.H2_NPN_PROTOCOLS', PROTOCOLS)
class TestRequestsAdapter(SocketLevelTest):
# This uses HTTP/2.
h2 = True
Expand Down