This repository was archived by the owner on Jan 13, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +51
-3
lines changed Expand file tree Collapse file tree 3 files changed +51
-3
lines changed Original file line number Diff line number Diff line change @@ -375,7 +375,10 @@ def connect(self):
375375 proto = H2C_PROTOCOL
376376
377377 log .debug ("Selected NPN protocol: %s" , proto )
378- assert proto in H2_NPN_PROTOCOLS or proto == H2C_PROTOCOL
378+ assert proto in H2_NPN_PROTOCOLS or proto == H2C_PROTOCOL , (
379+ "No suitable protocol found. Supported protocols: %s. "
380+ "Check your OpenSSL version."
381+ ) % ',' .join (H2_NPN_PROTOCOLS + [H2C_PROTOCOL ])
379382
380383 self ._sock = BufferedSocket (sock , self .network_buffer_size )
381384
Original file line number Diff line number Diff line change 1+ # -*- coding: utf-8 -*-
2+ """
3+ test_http20.py
4+ ~~~~~~~~~~~~~~
5+
6+ Unit tests for hyper's HTTP/2.0 implementation.
7+ """
8+ import pytest
9+ from mock import patch
10+
11+ from server import SocketLevelTest
12+
13+
14+ class TestHTTP20Connection (SocketLevelTest ):
15+ h2 = True
16+
17+ def test_useful_error_with_no_protocol (self ):
18+ self .set_up ()
19+
20+ def socket_handler (listener ):
21+ sock = listener .accept ()[0 ]
22+ sock .close ()
23+
24+ self ._start_server (socket_handler )
25+ conn = self .get_connection ()
26+
27+ with patch ('hyper.http20.connection.wrap_socket' ) as mock :
28+ mock .return_value = (None , None )
29+ with pytest .raises (AssertionError ) as exc_info :
30+ conn .connect ()
31+ assert (
32+ "No suitable protocol found."
33+ in
34+ str (exc_info )
35+ )
36+ assert (
37+ "Check your OpenSSL version."
38+ in
39+ str (exc_info )
40+ )
41+
42+ self .tear_down ()
Original file line number Diff line number Diff line change 1212import hyper
1313import hyper .http11 .connection
1414import pytest
15+ from mock import patch
1516from h2 .frame_buffer import FrameBuffer
1617from hyper .compat import ssl
1718from hyper .contrib import HTTP20Adapter
3435 hyper .tls ._context .check_hostname = False
3536 hyper .tls ._context .verify_mode = ssl .CERT_NONE
3637
37- # Cover our bases because NPN doesn't yet work on all our test platforms.
38- hyper .http20 .connection .H2_NPN_PROTOCOLS += ['' , None ]
38+ # Cover our bases because NPN doesn't yet work on all our test platforms.
39+ PROTOCOLS = hyper .http20 .connection .H2_NPN_PROTOCOLS + ['' , None ]
3940
4041
4142def decode_frame (frame_data ):
@@ -76,6 +77,7 @@ def receive_preamble(sock):
7677 return
7778
7879
80+ @patch ('hyper.http20.connection.H2_NPN_PROTOCOLS' , PROTOCOLS )
7981class TestHyperIntegration (SocketLevelTest ):
8082 # These are HTTP/2 tests.
8183 h2 = True
@@ -1031,6 +1033,7 @@ def socket_handler(listener):
10311033 self .tear_down ()
10321034
10331035
1036+ @patch ('hyper.http20.connection.H2_NPN_PROTOCOLS' , PROTOCOLS )
10341037class TestRequestsAdapter (SocketLevelTest ):
10351038 # This uses HTTP/2.
10361039 h2 = True
You can’t perform that action at this time.
0 commit comments