-
-
Notifications
You must be signed in to change notification settings - Fork 32k
bpo-36019: Use pythontest.net instead of example.com #11941
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
Conversation
Can you add a NEWS entry? |
Sure but only when my PR won’t be in WIP. Thanks 🙏 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great!. It would be great use https on the future :-)
Wait, some tests must not use HTTPS but HTTP. Some tests are written to explicitly test cleartext HTTP (tcp/80). Right now, it seems like: pythontest.net does't redirect to HTTP. Maybe we should use a constant to test.support for HTTP-only URL. |
@vstinner like that?
and where
|
There is no need for HTTPS yet. |
"`from test.support import TEST_HTTP_URL" LGTM. Maybe just add a short comment where you define the constant to explain the purpose of this URL. I understood that it must be a public HTTP server, it must use HTTP (not HTTPS), and it must support at least GET verb. |
ok, I am going to add this "constant" in |
Lib/test/test_codecmaps_cn.py
Outdated
import unittest | ||
|
||
class TestGB2312Map(multibytecodec_support.TestBase_Mapping, | ||
unittest.TestCase): | ||
encoding = 'gb2312' | ||
mapfileurl = 'http://www.pythontest.net/unicode/EUC-CN.TXT' | ||
mapfileurl = f'{support.TEST_HTTP_URL}/unicode/EUC-CN.TXT' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please revert this change. I would like to be able to modify TEST_HTTP_URL without breaking this URL.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just this one? or the complete commit?
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like you misunderstood what I proposed. The idea of a constant is to adding a constant is to allow to use a different URL without having to update tests. Without your current change, if I modify TEST_HTTP_URL to point to google.com, example.com, etc. A lot of tests fail.
Please restrict the change example.com, and only example.com : https://bugs.python.org/issue36019
Lib/test/test_hashlib.py
Outdated
@@ -50,7 +50,7 @@ def hexstr(s): | |||
return r | |||
|
|||
|
|||
URL = "http://www.pythontest.net/hashlib/{}.txt" | |||
URL = f"{TEST_HTTP_URL}/hashlib/{{}}.txt" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't do that. It will break the test if TEST_HTTP_URL is changed to example.com or anything else.
Lib/test/test_urllib.py
Outdated
@@ -712,7 +712,7 @@ def _reporthook(par1, par2, par3): | |||
|
|||
with self.assertRaises(urllib.error.ContentTooShortError): | |||
try: | |||
urllib.request.urlretrieve('http://example.com/', | |||
urllib.request.urlretrieve(f'{support.TEST_HTTP_URL}/', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the point of adding a slash? Why not using TEST_HTTP_URL directly?
urllib.request.urlretrieve(f'{support.TEST_HTTP_URL}/', | |
urllib.request.urlretrieve(support.TEST_HTTP_URL, |
Lib/test/test_urllib2net.py
Outdated
|
||
def test_redirect_url_withfrag(self): | ||
redirect_url_with_frag = "http://www.pythontest.net/redir/with_frag/" | ||
redirect_url_with_frag = f"{support.TEST_HTTP_URL}/redir/with_frag/" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto. Revert such change. The URL becomes wrong if TEST_HTTP_URL becomes example.org, python.org, google.com or whatever else.
Doc/library/test.rst
Outdated
.. data:: TEST_HTTP_URL | ||
|
||
Define the URL of a dedicated HTTP server for the network tests | ||
(http://www.pythontest.net). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove the value of the constant, it must not be documented. The value doesn't matter, and it reduces the maintenance burden to not have to update the doc, each time the URL changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another request for testURLread().
I blocked connections to example.com using:
# I added example.com to localhost
$ sudo head /etc/hosts
127.0.0.1 apu localhost localhost.localdomain localhost4 localhost4.localdomain4 example.com
::1 apu localhost localhost.localdomain localhost6 localhost6.localdomain6 example.com
$ host example.com
example.com has address 93.184.216.34
example.com has IPv6 address 2606:2800:220:1:248:1893:25c8:1946
# Reject all connections to example.com
$ sudo iptables -A OUTPUT -d 93.184.216.34 -j REJECT
$ sudo ip6tables -A OUTPUT -d 2606:2800:220:1:248:1893:25c8:1946 -j REJECT
And I modified transient_internet() to get an error:
diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py
index b442070b35..674195e442 100644
--- a/Lib/test/support/__init__.py
+++ b/Lib/test/support/__init__.py
@@ -1483,22 +1483,8 @@ def transient_internet(resource_name, *, timeout=30.0, errnos=()):
"""Return a context manager that raises ResourceDenied when various issues
with the Internet connection manifest themselves as exceptions."""
default_errnos = [
- ('ECONNREFUSED', 111),
- ('ECONNRESET', 104),
- ('EHOSTUNREACH', 113),
- ('ENETUNREACH', 101),
- ('ETIMEDOUT', 110),
- # socket.create_connection() fails randomly with
- # EADDRNOTAVAIL on Travis CI.
- ('EADDRNOTAVAIL', 99),
]
default_gai_errnos = [
- ('EAI_AGAIN', -3),
- ('EAI_FAIL', -4),
- ('EAI_NONAME', -2),
- ('EAI_NODATA', -5),
- # Encountered when trying to resolve IPv6-only hostnames
- ('WSANO_DATA', 11004),
]
denied = ResourceDenied("Resource %r is not available" % resource_name)
Only test_timeout failed because of my patch. So it's good.
Lib/test/test_urllibnet.py
Outdated
@@ -24,8 +24,8 @@ def tearDown(self): | |||
socket.setdefaulttimeout(None) | |||
|
|||
def testURLread(self): | |||
with support.transient_internet("www.example.com"): | |||
f = urllib.request.urlopen("http://www.example.com/") | |||
with support.transient_internet("www.pythontest.net"): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not using support.TEST_HTTP_URL here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because support.transient_internet
uses a hostname and not scheme+hostname.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for that, I have introduced support.TEST_HOSTNAME
@@ -0,0 +1,2 @@ | |||
Replace http://example.com by http://pythontest.net for some tests. | |||
Contributed by Stéphane Wirtel |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One NEWS entry is enough. Please merge both NEWS entries.
Lib/test/test_urllibnet.py
Outdated
@@ -24,8 +24,8 @@ def tearDown(self): | |||
socket.setdefaulttimeout(None) | |||
|
|||
def testURLread(self): | |||
with support.transient_internet("www.example.com"): | |||
f = urllib.request.urlopen("http://www.example.com/") | |||
with support.transient_internet(support.TEST_HOSTNAME): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be possible to extract the hostname from the URL rather than introducing another constant? It would avoid the risk of avoid 2 constants which would be inconsistent (if 1 is updated but not the other).
urllib.parse has tools for that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep, we can do it. I am going to fix it.
@vstinner updated, when you have time. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
@@ -24,8 +25,9 @@ def tearDown(self): | |||
socket.setdefaulttimeout(None) | |||
|
|||
def testURLread(self): | |||
with support.transient_internet("www.example.com"): | |||
f = urllib.request.urlopen("http://www.example.com/") | |||
domain = urllib.parse.urlparse(support.TEST_HTTP_URL).netloc |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good :-)
Thanks @matrixise for the PR, and @vstinner for merging it 🌮🎉.. I'm working now to backport this PR to: 3.7. |
GH-11989 is a backport of this pull request to the 3.7 branch. |
…pythonGH-11941) (cherry picked from commit a40681d) Co-authored-by: Stéphane Wirtel <[email protected]>
…GH-11941) (cherry picked from commit a40681d) Co-authored-by: Stéphane Wirtel <[email protected]>
GH-12177) Use test_support.TEST_HTTP_URL (pythontest.net) instead of http://www.example.com/.
https://bugs.python.org/issue36019