1 |
commit: c83238e04752d5b09d12089264b5c9ea6ca861fa |
2 |
Author: Sam James <sam <AT> gentoo <DOT> org> |
3 |
AuthorDate: Wed Dec 23 02:03:36 2020 +0000 |
4 |
Commit: Sam James <sam <AT> gentoo <DOT> org> |
5 |
CommitDate: Wed Dec 23 02:03:36 2020 +0000 |
6 |
URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=c83238e0 |
7 |
|
8 |
dev-python/urllib3: add test_proxy_rejection test hang patch |
9 |
|
10 |
Package-Manager: Portage-3.0.9, Repoman-3.0.2 |
11 |
Signed-off-by: Sam James <sam <AT> gentoo.org> |
12 |
|
13 |
...1.26.2-fix-test_proxy_rejection-test-hang.patch | 87 ++++++++++++++++++++++ |
14 |
dev-python/urllib3/urllib3-1.26.2-r1.ebuild | 4 + |
15 |
dev-python/urllib3/urllib3-1.26.2.ebuild | 4 + |
16 |
3 files changed, 95 insertions(+) |
17 |
|
18 |
diff --git a/dev-python/urllib3/files/urllib3-1.26.2-fix-test_proxy_rejection-test-hang.patch b/dev-python/urllib3/files/urllib3-1.26.2-fix-test_proxy_rejection-test-hang.patch |
19 |
new file mode 100644 |
20 |
index 00000000000..2af65e84f01 |
21 |
--- /dev/null |
22 |
+++ b/dev-python/urllib3/files/urllib3-1.26.2-fix-test_proxy_rejection-test-hang.patch |
23 |
@@ -0,0 +1,87 @@ |
24 |
+Fixes a hang on test_proxy_rejection. |
25 |
+https://github.com/urllib3/urllib3/commit/087d4de8487379033970898866625c00e0d51c85.patch |
26 |
+ |
27 |
+From 087d4de8487379033970898866625c00e0d51c85 Mon Sep 17 00:00:00 2001 |
28 |
+From: Quentin Pradet <quentin.pradet@×××××.com> |
29 |
+Date: Tue, 3 Nov 2020 17:15:50 +0400 |
30 |
+Subject: [PATCH] Fix test_proxy_rejection even with two localhost entries |
31 |
+ |
32 |
+--- |
33 |
+ test/contrib/test_socks.py | 34 +++++++++++++++++++++++++++++++--- |
34 |
+ 1 file changed, 31 insertions(+), 3 deletions(-) |
35 |
+ |
36 |
+diff --git a/test/contrib/test_socks.py b/test/contrib/test_socks.py |
37 |
+index 1966513c1..ed716f188 100644 |
38 |
+--- a/test/contrib/test_socks.py |
39 |
++++ b/test/contrib/test_socks.py |
40 |
+@@ -1,8 +1,12 @@ |
41 |
++from __future__ import absolute_import |
42 |
++ |
43 |
+ import socket |
44 |
+ import threading |
45 |
++from socket import getaddrinfo as real_getaddrinfo |
46 |
+ from test import SHORT_TIMEOUT |
47 |
+ |
48 |
+ import pytest |
49 |
++import socks as py_socks |
50 |
+ |
51 |
+ from dummyserver.server import DEFAULT_CA, DEFAULT_CERTS |
52 |
+ from dummyserver.testcase import IPV4SocketDummyServerTestCase |
53 |
+@@ -87,6 +91,26 @@ def _address_from_socket(sock): |
54 |
+ raise RuntimeError("Unexpected addr type: %r" % addr_type) |
55 |
+ |
56 |
+ |
57 |
++def _set_up_fake_getaddrinfo(monkeypatch): |
58 |
++ # Work around https://github.com/urllib3/urllib3/pull/2034 |
59 |
++ # Nothing prevents localhost to point to two different IPs. For example, in the |
60 |
++ # Ubuntu set up by GitHub Actions, localhost points both to 127.0.0.1 and ::1. |
61 |
++ # |
62 |
++ # In case of failure, PySocks will try the same request on both IPs, but our |
63 |
++ # handle_socks[45]_negotiation functions don't handle retries, which leads either to |
64 |
++ # a deadlock or a timeout in case of a failure on the first address. |
65 |
++ # |
66 |
++ # However, some tests need to exercise failure. We don't want retries there, but |
67 |
++ # can't affect PySocks retries via its API. Instead, we monkeypatch PySocks so that |
68 |
++ # it only sees a single address, which effectively disables retries. |
69 |
++ def fake_getaddrinfo(addr, port, family, socket_type): |
70 |
++ gai_list = real_getaddrinfo(addr, port, family, socket_type) |
71 |
++ gai_list = [gai for gai in gai_list if gai[0] == socket.AF_INET] |
72 |
++ return gai_list[:1] |
73 |
++ |
74 |
++ monkeypatch.setattr(py_socks.socket, "getaddrinfo", fake_getaddrinfo) |
75 |
++ |
76 |
++ |
77 |
+ def handle_socks5_negotiation(sock, negotiate, username=None, password=None): |
78 |
+ """ |
79 |
+ Handle the SOCKS5 handshake. |
80 |
+@@ -334,7 +358,8 @@ def request_handler(listener): |
81 |
+ with pytest.raises(NewConnectionError): |
82 |
+ pm.request("GET", "http://example.com", retries=False) |
83 |
+ |
84 |
+- def test_proxy_rejection(self): |
85 |
++ def test_proxy_rejection(self, monkeypatch): |
86 |
++ _set_up_fake_getaddrinfo(monkeypatch) |
87 |
+ evt = threading.Event() |
88 |
+ |
89 |
+ def request_handler(listener): |
90 |
+@@ -429,7 +454,9 @@ def request_handler(listener): |
91 |
+ assert response.data == b"" |
92 |
+ assert response.headers["Server"] == "SocksTestServer" |
93 |
+ |
94 |
+- def test_socks_with_invalid_password(self): |
95 |
++ def test_socks_with_invalid_password(self, monkeypatch): |
96 |
++ _set_up_fake_getaddrinfo(monkeypatch) |
97 |
++ |
98 |
+ def request_handler(listener): |
99 |
+ sock = listener.accept()[0] |
100 |
+ |
101 |
+@@ -592,7 +619,8 @@ def request_handler(listener): |
102 |
+ response = pm.request("GET", "http://example.com") |
103 |
+ assert response.status == 200 |
104 |
+ |
105 |
+- def test_proxy_rejection(self): |
106 |
++ def test_proxy_rejection(self, monkeypatch): |
107 |
++ _set_up_fake_getaddrinfo(monkeypatch) |
108 |
+ evt = threading.Event() |
109 |
+ |
110 |
+ def request_handler(listener): |
111 |
|
112 |
diff --git a/dev-python/urllib3/urllib3-1.26.2-r1.ebuild b/dev-python/urllib3/urllib3-1.26.2-r1.ebuild |
113 |
index 73147412195..434b386f83d 100644 |
114 |
--- a/dev-python/urllib3/urllib3-1.26.2-r1.ebuild |
115 |
+++ b/dev-python/urllib3/urllib3-1.26.2-r1.ebuild |
116 |
@@ -41,6 +41,10 @@ BDEPEND=" |
117 |
) |
118 |
" |
119 |
|
120 |
+PATCHES=( |
121 |
+ "${FILESDIR}/${P}-fix-test_proxy_rejection-test-hang.patch" |
122 |
+) |
123 |
+ |
124 |
python_prepare_all() { |
125 |
# https://github.com/urllib3/urllib3/issues/1756 |
126 |
sed -e 's:10.255.255.1:240.0.0.0:' \ |
127 |
|
128 |
diff --git a/dev-python/urllib3/urllib3-1.26.2.ebuild b/dev-python/urllib3/urllib3-1.26.2.ebuild |
129 |
index 88cad5ac516..607f7c5c9d8 100644 |
130 |
--- a/dev-python/urllib3/urllib3-1.26.2.ebuild |
131 |
+++ b/dev-python/urllib3/urllib3-1.26.2.ebuild |
132 |
@@ -41,6 +41,10 @@ BDEPEND=" |
133 |
) |
134 |
" |
135 |
|
136 |
+PATCHES=( |
137 |
+ "${FILESDIR}/${P}-fix-test_proxy_rejection-test-hang.patch" |
138 |
+) |
139 |
+ |
140 |
python_prepare_all() { |
141 |
# https://github.com/urllib3/urllib3/issues/1756 |
142 |
sed -e 's:10.255.255.1:240.0.0.0:' \ |