Skip to content

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

Merged
merged 17 commits into from
Feb 22, 2019

Conversation

matrixise
Copy link
Member

@matrixise matrixise commented Feb 19, 2019

@vstinner
Copy link
Member

Can you add a NEWS entry?

@matrixise
Copy link
Member Author

Sure but only when my PR won’t be in WIP. Thanks 🙏

@matrixise matrixise changed the title WIP: bpo-36019: Use pythontest.net instead of example.com bpo-36019: Use pythontest.net instead of example.com Feb 19, 2019
Copy link
Contributor

@eamanu eamanu left a 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 :-)

@vstinner
Copy link
Member

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.

@matrixise
Copy link
Member Author

@vstinner like that?

from test.support import TEST_HTTP_URL
from test.support import TEST_HTTPS_URL

and where

TEST_HTTP_URL='http://www.pythontest.net'
TEST_HTTP_URL='https://www.pythontest.net'

@vstinner
Copy link
Member

There is no need for HTTPS yet.

@vstinner
Copy link
Member

"`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.

@matrixise
Copy link
Member Author

ok, I am going to add this "constant" in test/support/__init__.py

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'
Copy link
Member

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.

Copy link
Member Author

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?

@bedevere-bot
Copy link

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 I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

Copy link
Member

@vstinner vstinner left a 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

@@ -50,7 +50,7 @@ def hexstr(s):
return r


URL = "http://www.pythontest.net/hashlib/{}.txt"
URL = f"{TEST_HTTP_URL}/hashlib/{{}}.txt"
Copy link
Member

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.

@@ -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}/',
Copy link
Member

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?

Suggested change
urllib.request.urlretrieve(f'{support.TEST_HTTP_URL}/',
urllib.request.urlretrieve(support.TEST_HTTP_URL,


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/"
Copy link
Member

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.

.. data:: TEST_HTTP_URL

Define the URL of a dedicated HTTP server for the network tests
(http://www.pythontest.net).
Copy link
Member

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.

Copy link
Member

@vstinner vstinner left a 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.

@@ -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"):
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member Author

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
Copy link
Member

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.

@@ -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):
Copy link
Member

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.

Copy link
Member Author

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.

@matrixise
Copy link
Member Author

@vstinner updated, when you have time.

Copy link
Member

@vstinner vstinner left a 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good :-)

@miss-islington
Copy link
Contributor

Thanks @matrixise for the PR, and @vstinner for merging it 🌮🎉.. I'm working now to backport this PR to: 3.7.
🐍🍒⛏🤖

@bedevere-bot
Copy link

GH-11989 is a backport of this pull request to the 3.7 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Feb 22, 2019
miss-islington added a commit that referenced this pull request Feb 22, 2019
matrixise added a commit to matrixise/cpython that referenced this pull request Mar 5, 2019
vstinner pushed a commit that referenced this pull request Mar 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tests Tests in the Lib/test dir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants