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

test_urllib2_localnet.ProxyAuthTests fails with no_proxy and NO_PROXY env #72621

Closed
PiotrSzczepaniak mannequin opened this issue Oct 13, 2016 · 4 comments
Closed

test_urllib2_localnet.ProxyAuthTests fails with no_proxy and NO_PROXY env #72621

PiotrSzczepaniak mannequin opened this issue Oct 13, 2016 · 4 comments
Labels
3.7 (EOL) end of life tests Tests in the Lib/test dir type-feature A feature request or enhancement

Comments

@PiotrSzczepaniak
Copy link
Mannequin

PiotrSzczepaniak mannequin commented Oct 13, 2016

BPO 28435
Nosy @orsenthil, @ambv, @vadmium
Files
  • cpython.diff
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2016-10-22.04:18:40.188>
    created_at = <Date 2016-10-13.20:07:06.403>
    labels = ['3.7', 'type-feature', 'tests']
    title = 'test_urllib2_localnet.ProxyAuthTests fails with no_proxy and NO_PROXY env'
    updated_at = <Date 2016-10-22.04:18:40.186>
    user = 'https://bugs.python.org/PiotrSzczepaniak'

    bugs.python.org fields:

    activity = <Date 2016-10-22.04:18:40.186>
    actor = 'martin.panter'
    assignee = 'none'
    closed = True
    closed_date = <Date 2016-10-22.04:18:40.188>
    closer = 'martin.panter'
    components = ['Tests']
    creation = <Date 2016-10-13.20:07:06.403>
    creator = 'Piotr Szczepaniak'
    dependencies = []
    files = ['45084']
    hgrepos = []
    issue_num = 28435
    keywords = ['patch']
    message_count = 4.0
    messages = ['278600', '278677', '279177', '279179']
    nosy_count = 5.0
    nosy_names = ['orsenthil', 'lukasz.langa', 'python-dev', 'martin.panter', 'Piotr Szczepaniak']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue28435'
    versions = ['Python 2.7', 'Python 3.5', 'Python 3.6', 'Python 3.7']

    @PiotrSzczepaniak
    Copy link
    Mannequin Author

    PiotrSzczepaniak mannequin commented Oct 13, 2016

    test_urllib2_localnet.ProxyAuthTests fails with no_proxy and NO_PROXY env set:
    NO_PROXY=localhost,127.0.0.0/8,::1
    no_proxy=localhost,127.0.0.0/8,::1

    Patch attached.

    Run:
    ./python -m unittest test.test_urllib2_localnet.ProxyAuthTests -v
    test_proxy_qop_auth_int_works_or_throws_urlerror (test.test_urllib2_localnet.ProxyAuthTests) ... ok
    test_proxy_qop_auth_works (test.test_urllib2_localnet.ProxyAuthTests) ... ERROR
    test_proxy_with_bad_password_raises_httperror (test.test_urllib2_localnet.ProxyAuthTests) ... ERROR
    test_proxy_with_no_password_raises_httperror (test.test_urllib2_localnet.ProxyAuthTests) ... ERROR

    ======================================================================
    ERROR: test_proxy_qop_auth_works (test.test_urllib2_localnet.ProxyAuthTests)
    ----------------------------------------------------------------------

    Traceback (most recent call last):
      File "/home/d0han/cpython/cpython/Lib/urllib/request.py", line 1318, in do_open
        encode_chunked=req.has_header('Transfer-encoding'))
      File "/home/d0han/cpython/cpython/Lib/http/client.py", line 1239, in request
        self._send_request(method, url, body, headers, encode_chunked)
      File "/home/d0han/cpython/cpython/Lib/http/client.py", line 1285, in _send_request
        self.endheaders(body, encode_chunked=encode_chunked)
      File "/home/d0han/cpython/cpython/Lib/http/client.py", line 1234, in endheaders
        self._send_output(message_body, encode_chunked=encode_chunked)
      File "/home/d0han/cpython/cpython/Lib/http/client.py", line 1026, in _send_output
        self.send(msg)
      File "/home/d0han/cpython/cpython/Lib/http/client.py", line 964, in send
        self.connect()
      File "/home/d0han/cpython/cpython/Lib/http/client.py", line 936, in connect
        (self.host,self.port), self.timeout, self.source_address)
      File "/home/d0han/cpython/cpython/Lib/socket.py", line 722, in create_connection
        raise err
      File "/home/d0han/cpython/cpython/Lib/socket.py", line 713, in create_connection
        sock.connect(sa)
    ConnectionRefusedError: [Errno 111] Connection refused
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "/home/d0han/cpython/cpython/Lib/test/test_urllib2_localnet.py", line 372, in test_proxy_qop_auth_works
        result = self.opener.open(self.URL)
      File "/home/d0han/cpython/cpython/Lib/urllib/request.py", line 526, in open
        response = self._open(req, data)
      File "/home/d0han/cpython/cpython/Lib/urllib/request.py", line 544, in _open
        '_open', req)
      File "/home/d0han/cpython/cpython/Lib/urllib/request.py", line 504, in _call_chain
        result = func(*args)
      File "/home/d0han/cpython/cpython/Lib/urllib/request.py", line 1346, in http_open
        return self.do_open(http.client.HTTPConnection, req)
      File "/home/d0han/cpython/cpython/Lib/urllib/request.py", line 1320, in do_open
        raise URLError(err)
    urllib.error.URLError: <urlopen error [Errno 111] Connection refused>

    ======================================================================
    ERROR: test_proxy_with_bad_password_raises_httperror (test.test_urllib2_localnet.ProxyAuthTests)
    ----------------------------------------------------------------------

    Traceback (most recent call last):
      File "/home/d0han/cpython/cpython/Lib/urllib/request.py", line 1318, in do_open
        encode_chunked=req.has_header('Transfer-encoding'))
      File "/home/d0han/cpython/cpython/Lib/http/client.py", line 1239, in request
        self._send_request(method, url, body, headers, encode_chunked)
      File "/home/d0han/cpython/cpython/Lib/http/client.py", line 1285, in _send_request
        self.endheaders(body, encode_chunked=encode_chunked)
      File "/home/d0han/cpython/cpython/Lib/http/client.py", line 1234, in endheaders
        self._send_output(message_body, encode_chunked=encode_chunked)
      File "/home/d0han/cpython/cpython/Lib/http/client.py", line 1026, in _send_output
        self.send(msg)
      File "/home/d0han/cpython/cpython/Lib/http/client.py", line 964, in send
        self.connect()
      File "/home/d0han/cpython/cpython/Lib/http/client.py", line 936, in connect
        (self.host,self.port), self.timeout, self.source_address)
      File "/home/d0han/cpython/cpython/Lib/socket.py", line 722, in create_connection
        raise err
      File "/home/d0han/cpython/cpython/Lib/socket.py", line 713, in create_connection
        sock.connect(sa)
    ConnectionRefusedError: [Errno 111] Connection refused
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "/home/d0han/cpython/cpython/Lib/test/test_urllib2_localnet.py", line 360, in test_proxy_with_bad_password_raises_httperror
        self.URL)
      File "/home/d0han/cpython/cpython/Lib/unittest/case.py", line 728, in assertRaises
        return context.handle('assertRaises', args, kwargs)
      File "/home/d0han/cpython/cpython/Lib/unittest/case.py", line 177, in handle
        callable_obj(*args, **kwargs)
      File "/home/d0han/cpython/cpython/Lib/urllib/request.py", line 526, in open
        response = self._open(req, data)
      File "/home/d0han/cpython/cpython/Lib/urllib/request.py", line 544, in _open
        '_open', req)
      File "/home/d0han/cpython/cpython/Lib/urllib/request.py", line 504, in _call_chain
        result = func(*args)
      File "/home/d0han/cpython/cpython/Lib/urllib/request.py", line 1346, in http_open
        return self.do_open(http.client.HTTPConnection, req)
      File "/home/d0han/cpython/cpython/Lib/urllib/request.py", line 1320, in do_open
        raise URLError(err)
    urllib.error.URLError: <urlopen error [Errno 111] Connection refused>

    ======================================================================
    ERROR: test_proxy_with_no_password_raises_httperror (test.test_urllib2_localnet.ProxyAuthTests)
    ----------------------------------------------------------------------

    Traceback (most recent call last):
      File "/home/d0han/cpython/cpython/Lib/urllib/request.py", line 1318, in do_open
        encode_chunked=req.has_header('Transfer-encoding'))
      File "/home/d0han/cpython/cpython/Lib/http/client.py", line 1239, in request
        self._send_request(method, url, body, headers, encode_chunked)
      File "/home/d0han/cpython/cpython/Lib/http/client.py", line 1285, in _send_request
        self.endheaders(body, encode_chunked=encode_chunked)
      File "/home/d0han/cpython/cpython/Lib/http/client.py", line 1234, in endheaders
        self._send_output(message_body, encode_chunked=encode_chunked)
      File "/home/d0han/cpython/cpython/Lib/http/client.py", line 1026, in _send_output
        self.send(msg)
      File "/home/d0han/cpython/cpython/Lib/http/client.py", line 964, in send
        self.connect()
      File "/home/d0han/cpython/cpython/Lib/http/client.py", line 936, in connect
        (self.host,self.port), self.timeout, self.source_address)
      File "/home/d0han/cpython/cpython/Lib/socket.py", line 722, in create_connection
        raise err
      File "/home/d0han/cpython/cpython/Lib/socket.py", line 713, in create_connection
        sock.connect(sa)
    ConnectionRefusedError: [Errno 111] Connection refused
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "/home/d0han/cpython/cpython/Lib/test/test_urllib2_localnet.py", line 366, in test_proxy_with_no_password_raises_httperror
        self.URL)
      File "/home/d0han/cpython/cpython/Lib/unittest/case.py", line 728, in assertRaises
        return context.handle('assertRaises', args, kwargs)
      File "/home/d0han/cpython/cpython/Lib/unittest/case.py", line 177, in handle
        callable_obj(*args, **kwargs)
      File "/home/d0han/cpython/cpython/Lib/urllib/request.py", line 526, in open
        response = self._open(req, data)
      File "/home/d0han/cpython/cpython/Lib/urllib/request.py", line 544, in _open
        '_open', req)
      File "/home/d0han/cpython/cpython/Lib/urllib/request.py", line 504, in _call_chain
        result = func(*args)
      File "/home/d0han/cpython/cpython/Lib/urllib/request.py", line 1346, in http_open
        return self.do_open(http.client.HTTPConnection, req)
      File "/home/d0han/cpython/cpython/Lib/urllib/request.py", line 1320, in do_open
        raise URLError(err)
    urllib.error.URLError: <urlopen error [Errno 111] Connection refused>

    Ran 4 tests in 3.024s

    FAILED (errors=3)

    @PiotrSzczepaniak PiotrSzczepaniak mannequin added 3.7 (EOL) end of life tests Tests in the Lib/test dir type-feature A feature request or enhancement labels Oct 13, 2016
    @vadmium
    Copy link
    Member

    vadmium commented Oct 15, 2016

    The test tries using ProxyHandler directly. It looks like that handler intentionally ignores the request if it matches no_proxies (bpo-6894), so I think Piotr’s approach of adjusting the tests is correct. The patch looks good to me, though I would drop that blank line in test_proxy_qop_auth_works().

    It looks like setting a temporary environment variable should disable any settings from Windows registry or OS X config, so this patch should even help in those cases.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Oct 22, 2016

    New changeset 8f4424bdeadc by Martin Panter in branch '2.7':
    Issue bpo-28435: Avoid no_proxy environment variable interfering with tests
    https://hg.python.org/cpython/rev/8f4424bdeadc

    New changeset dc9ad44125de by Martin Panter in branch '3.5':
    Issue bpo-28435: Avoid no_proxy environment variable interfering with tests
    https://hg.python.org/cpython/rev/dc9ad44125de

    New changeset 05c3fbaa8fcf by Martin Panter in branch '3.6':
    Issue bpo-28435: Merge urllib test fixes from 3.5 into 3.6
    https://hg.python.org/cpython/rev/05c3fbaa8fcf

    New changeset 4b6e6a77e501 by Martin Panter in branch 'default':
    Issue bpo-28435: Merge urllib test fixes from 3.6
    https://hg.python.org/cpython/rev/4b6e6a77e501

    @vadmium
    Copy link
    Member

    vadmium commented Oct 22, 2016

    I altered the comment (looks like it was a copy from code forcing proxies to be bypassed). Also, I didn’t port the second no_proxy fix to 2.7; it looks like there is a different workaround there which is not affected by the environment.

    @vadmium vadmium closed this as completed Oct 22, 2016
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 (EOL) end of life tests Tests in the Lib/test dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant