Page MenuHomePhabricator

test_https_cert_error failed on Travis CI
Closed, ResolvedPublic

Description

________________ HttpsCertificateTestCase.test_https_cert_error ________________
self = <tests.http_tests.HttpsCertificateTestCase testMethod=test_https_cert_error>
    def test_https_cert_error(self):
        """Test if http.fetch respects disable_ssl_certificate_validation."""
        self.assertRaises(pywikibot.FatalServerError,
                          http.fetch,
                          uri='https://testssl-expire-r2i2.disig.sk/index.en.html')
    
        with warnings.catch_warnings(record=True) as warning_log:
            response = http.fetch(
                uri='https://testssl-expire-r2i2.disig.sk/index.en.html',
                disable_ssl_certificate_validation=True)
        r = response.content
        self.assertIsInstance(r, unicode)
        self.assertTrue(re.search(r'<title>.*</title>', r))
    
        # Verify that it now fails again
        http.session.close()  # but first clear the connection
        self.assertRaises(pywikibot.FatalServerError,
                          http.fetch,
                          uri='https://testssl-expire-r2i2.disig.sk/index.en.html')
    
        # Verify that the warning occurred
>       self.assertEqual(len(warning_log), 1)
E       AssertionError: 2 != 1
tests/http_tests.py:150: AssertionError

See: https://travis-ci.org/wikimedia/pywikibot-core/jobs/177771387#L4557-L4585

Event Timeline

print([wl.__dict__ for wl in warning_log])

just before fail in test gave

[
    {
        'category': <class 'ResourceWarning'>,
        'line': None,
        '_category_name': 'ResourceWarning',
        'message': ResourceWarning('unclosed <socket.socket object, fd=7, family=2, type=2049, proto=6>',),
        'file': None,
        'lineno': 1191,
        'filename': '/opt/python/3.3.5/lib/python3.3/http/cookiejar.py'
    }, {
        'category': <class 'requests.packages.urllib3.exceptions.InsecureRequestWarning'>,
        'line': None,
        '_category_name': 'InsecureRequestWarning',
        'message': InsecureRequestWarning('Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings',),
        'file': None, 'lineno': 843,
        'filename': '/home/travis/virtualenv/python3.3.5/lib/python3.3/site-packages/requests/packages/urllib3/connectionpool.py'
    }
]

Change 322866 had a related patch set uploaded (by Magul):
Close connection after every request in test_https_cert_error.

https://gerrit.wikimedia.org/r/322866

Change 322866 merged by jenkins-bot:
Close connection after every request in test_https_cert_error.

https://gerrit.wikimedia.org/r/322866