Skip to content
Myr

Test security warnings (#3289)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Verify that the expected warnings are emitted with SubjectAltNameWarning emitted on all environments due to the https server provided by httpbin_secure.

authored by John Vandenberg · committed by Ian Cordasco · parent e12ee94 · Browse files · 2 files+56 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+56 added−0 removed

  • tests:+56 added−0 removed

2 files+56 added−0 removed

modified:tests/__init__.py+21 added
1# coding: utf-823"""Requests test package initialisation."""45import warnings67try:8 import urllib3 as urllib3_package9except ImportError:10 urllib3_package = False1112from requests.packages import urllib3 as urllib3_bundle1314if urllib3_package is urllib3_bundle:15 from urllib3.exceptions import SNIMissingWarning16else:17 from requests.packages.urllib3.exceptions import SNIMissingWarning1819# urllib3 sets SNIMissingWarning to only go off once,20# while this test suite requires it to always fire21# so that it occurs during test_requests.test_https_warnings22warnings.simplefilter('always', SNIMissingWarning)
modified:tests/test_requests.py+35 added
7 unmodified lines
8import os9import pickle10import collections11import contextlib12import warnings1314import io15import requests16import pytest
19 unmodified lines
36# Requests to this URL should always fail with a connection timeout (nothing37# listening on that port)38TARPIT = 'http://10.255.255.1'3940try:41 from ssl import SSLContext42 del SSLContext43 HAS_MODERN_SSL = True44except ImportError:45 HAS_MODERN_SSL = False4647try:48 requests.pyopenssl49 HAS_PYOPENSSL = True50except AttributeError:51 HAS_PYOPENSSL = False525354class TestRequests:5556 def test_entry_points(self):57
561 unmodified lines
619620 def test_pyopenssl_redirect(self, httpbin_secure, httpbin_ca_bundle):621 requests.get(httpbin_secure('status', '301'), verify=httpbin_ca_bundle)622623 def test_https_warnings(self, httpbin_secure, httpbin_ca_bundle):624 """warnings are emitted with requests.get"""625 if HAS_MODERN_SSL or HAS_PYOPENSSL:626 warnings_expected = ('SubjectAltNameWarning', )627 else:628 warnings_expected = ('SNIMissingWarning',629 'InsecurePlatformWarning',630 'SubjectAltNameWarning', )631632 with pytest.warns(None) as warning_records:633 warnings.simplefilter('always')634 requests.get(httpbin_secure('status', '200'),635 verify=httpbin_ca_bundle)636637 warning_records = [item for item in warning_records638 if item.category.__name__ != 'ResourceWarning']639640 warnings_category = tuple(641 item.category.__name__ for item in warning_records)642 assert warnings_category == warnings_expected643644 def test_urlencoded_get_query_multivalued_param(self, httpbin):645646 r = requests.get(httpbin('get'), params=dict(test=['foo', 'baz']))647 assert r.status_code == 200
1049 unmodified lines