Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade PyPy to test Python 3.6 #2050

Merged
merged 2 commits into from
Nov 12, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: python
os: linux
dist: xenial
dist: focal

before_install:
- env
Expand Down Expand Up @@ -43,13 +43,13 @@ jobs:
env: NOX_SESSION=test-3.7
- python: 3.8
env: NOX_SESSION=test-3.8
- python: 3.9-dev
- python: 3.9
env: NOX_SESSION=test-3.9
- python: nightly
env: NOX_SESSION=test-3.10
- python: pypy2.7-6.0
- python: pypy2.7-7.3.1
env: NOX_SESSION=test-pypy
- python: pypy3.5-6.0
- python: pypy3.6-7.3.1
env: NOX_SESSION=test-pypy

# Extras
Expand Down
2 changes: 1 addition & 1 deletion src/urllib3/util/ssl_.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ def ssl_wrap_socket(
try:
if hasattr(context, "set_alpn_protocols"):
context.set_alpn_protocols(ALPN_PROTOCOLS)
except NotImplementedError:
except NotImplementedError: # Defensive: in CI, we always have set_alpn_protocols
pass

# If we detect server_hostname is an IP address then the SNI
Expand Down
34 changes: 31 additions & 3 deletions test/contrib/test_socks.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
from __future__ import absolute_import

import socket
import threading
from socket import getaddrinfo as real_getaddrinfo
from test import SHORT_TIMEOUT

import pytest
import socks as py_socks

from dummyserver.server import DEFAULT_CA, DEFAULT_CERTS
from dummyserver.testcase import IPV4SocketDummyServerTestCase
Expand Down Expand Up @@ -87,6 +91,26 @@ def _address_from_socket(sock):
raise RuntimeError("Unexpected addr type: %r" % addr_type)


def _set_up_fake_getaddrinfo(monkeypatch):
# Work around https://github.com/urllib3/urllib3/pull/2034
# Nothing prevents localhost to point to two different IPs. For example, in the
# Ubuntu set up by GitHub Actions, localhost points both to 127.0.0.1 and ::1.
#
# In case of failure, PySocks will try the same request on both IPs, but our
# handle_socks[45]_negotiation functions don't handle retries, which leads either to
# a deadlock or a timeout in case of a failure on the first address.
#
# However, some tests need to exercise failure. We don't want retries there, but
# can't affect PySocks retries via its API. Instead, we monkeypatch PySocks so that
# it only sees a single address, which effectively disables retries.
def fake_getaddrinfo(addr, port, family, socket_type):
gai_list = real_getaddrinfo(addr, port, family, socket_type)
gai_list = [gai for gai in gai_list if gai[0] == socket.AF_INET]
return gai_list[:1]

monkeypatch.setattr(py_socks.socket, "getaddrinfo", fake_getaddrinfo)


def handle_socks5_negotiation(sock, negotiate, username=None, password=None):
"""
Handle the SOCKS5 handshake.
Expand Down Expand Up @@ -334,7 +358,8 @@ def request_handler(listener):
with pytest.raises(NewConnectionError):
pm.request("GET", "http://example.com", retries=False)

def test_proxy_rejection(self):
def test_proxy_rejection(self, monkeypatch):
_set_up_fake_getaddrinfo(monkeypatch)
evt = threading.Event()

def request_handler(listener):
Expand Down Expand Up @@ -429,7 +454,9 @@ def request_handler(listener):
assert response.data == b""
assert response.headers["Server"] == "SocksTestServer"

def test_socks_with_invalid_password(self):
def test_socks_with_invalid_password(self, monkeypatch):
_set_up_fake_getaddrinfo(monkeypatch)

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

Expand Down Expand Up @@ -592,7 +619,8 @@ def request_handler(listener):
response = pm.request("GET", "http://example.com")
assert response.status == 200

def test_proxy_rejection(self):
def test_proxy_rejection(self, monkeypatch):
_set_up_fake_getaddrinfo(monkeypatch)
evt = threading.Event()

def request_handler(listener):
Expand Down