Skip to content

Commit f38a312

Browse files
committed
Fix Server Hang in Pypy for Invalid Cert
In pypy, the server was hanging for requests with invalid certs. It looks like this might have been happening in older versions of python 2.7 as well. Anyway, I added a timeout to the socket and that seems to have fixed the issue.
1 parent 9cdb0f8 commit f38a312

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

pytest_httpbin/serve.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ def finish_request(self, request, client_address):
6060
"""
6161
Negotiates SSL and then mimics BaseServer behavior.
6262
"""
63+
request.settimeout(1.0)
6364
ssock = ssl.wrap_socket(
6465
request,
6566
keyfile=os.path.join(CERT_DIR, 'key.pem'),

runtests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/bin/bash
22

3-
py.test
3+
py.test $1

tests/test_server.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# vim: set fileencoding=utf8 :
44

55
import requests
6+
import pytest
67
from util import get_raw_http_response
78

89

@@ -35,3 +36,17 @@ def test_server_should_be_http_1_1(httpbin):
3536
"""
3637
resp = get_raw_http_response(httpbin.host, httpbin.port, '/get')
3738
assert resp.startswith(b'HTTP/1.1')
39+
40+
def test_dont_crash_on_certificate_problems(httpbin_secure):
41+
with pytest.raises(Exception):
42+
# this request used to hang
43+
requests.get(
44+
httpbin_secure + '/get',
45+
verify = True,
46+
cert=__file__
47+
)
48+
# and this request would never happen
49+
requests.get(
50+
httpbin_secure + '/get',
51+
verify = True,
52+
)

0 commit comments

Comments
 (0)