File: test_host_header_ssl_adapter.py

package info (click to toggle)
python-requests-toolbelt 1.0.0-4
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 876 kB
  • sloc: python: 3,653; makefile: 166; sh: 7
file content (48 lines) | stat: -rw-r--r-- 1,572 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import pytest
import requests

from requests_toolbelt.adapters import host_header_ssl as hhssl


@pytest.fixture
def session():
    """Create a session with our adapter mounted."""
    session = requests.Session()
    session.mount('https://', hhssl.HostHeaderSSLAdapter())


@pytest.mark.skip
class TestHostHeaderSSLAdapter(object):
    """Tests for our HostHeaderSNIAdapter."""

    def test_ssladapter(self, session):
        # normal mode
        r = session.get('https://example.org')
        assert r.status_code == 200

        # accessing IP address directly
        r = session.get('https://93.184.216.34',
                        headers={"Host": "example.org"})
        assert r.status_code == 200

        # vHost
        r = session.get('https://93.184.216.34',
                        headers={'Host': 'example.com'})
        assert r.status_code == 200

    def test_stream(self):
        self.session.get('https://54.175.219.8/stream/20',
                         headers={'Host': 'httpbin.org'},
                         stream=True)

    def test_case_insensitive_header(self):
        r = self.session.get('https://93.184.216.34',
                             headers={'hOSt': 'example.org'})
        assert r.status_code == 200

    def test_plain_requests(self):
        # test whether the reason for this adapter remains
        # (may be implemented into requests in the future)
        with pytest.raises(requests.exceptions.SSLError):
            requests.get(url='https://93.184.216.34',
                         headers={'Host': 'example.org'})