Esempio n. 1
0
    def test_pools_keyed_with_from_host(self):
        """Assert pools are still keyed correctly with connection_from_host."""
        ssl_kw = {
            'key_file': '/root/totally_legit.key',
            'cert_file': '/root/totally_legit.crt',
            'cert_reqs': 'CERT_REQUIRED',
            'ca_certs': '/root/path_to_pem',
            'ssl_version': 'SSLv23_METHOD',
        }
        p = PoolManager(5, **ssl_kw)
        conns = []
        conns.append(
            p.connection_from_host('example.com', 443, scheme='https')
        )

        for k in ssl_kw:
            p.connection_pool_kw[k] = 'newval'
            conns.append(
                p.connection_from_host('example.com', 443, scheme='https')
            )

        assert all(
            x is not y
            for i, x in enumerate(conns)
            for j, y in enumerate(conns)
            if i != j
        )
Esempio n. 2
0
    def test_http_connection_from_host_case_insensitive(self):
        """Assert scheme case is ignored when getting the https key class."""
        p = PoolManager()
        pool = p.connection_from_host('example.com', scheme='http')
        other_pool = p.connection_from_host('EXAMPLE.COM', scheme='HTTP')

        assert 1 == len(p.pools)
        assert pool is other_pool
        assert all(isinstance(key, PoolKey) for key in p.pools.keys())
Esempio n. 3
0
    def test_https_connection_from_host_case_insensitive(self) -> None:
        """Assert scheme case is ignored when getting the https key class."""
        p = PoolManager()
        pool = p.connection_from_host("example.com", scheme="https")
        other_pool = p.connection_from_host("EXAMPLE.COM", scheme="HTTPS")

        assert 1 == len(p.pools)
        assert pool is other_pool
        assert all(isinstance(key, PoolKey) for key in p.pools.keys())
Esempio n. 4
0
    def test_http_connection_from_host_case_insensitive(self):
        """Assert scheme case is ignored when getting the https key class."""
        p = PoolManager()
        self.addCleanup(p.clear)
        pool = p.connection_from_host('example.com', scheme='http')
        other_pool = p.connection_from_host('EXAMPLE.COM', scheme='HTTP')

        self.assertEqual(1, len(p.pools))
        self.assertTrue(pool is other_pool)
        self.assertTrue(all(isinstance(key, HTTPPoolKey) for key in p.pools.keys()))
Esempio n. 5
0
    def test_http_connection_from_host_case_insensitive(self):
        """Assert scheme case is ignored when getting the https key class."""
        p = PoolManager()
        self.addCleanup(p.clear)
        pool = p.connection_from_host('example.com', scheme='http')
        other_pool = p.connection_from_host('EXAMPLE.COM', scheme='HTTP')

        self.assertEqual(1, len(p.pools))
        self.assertTrue(pool is other_pool)
        self.assertTrue(all(isinstance(key, PoolKey) for key in p.pools.keys()))
Esempio n. 6
0
    def test_pool_kwargs_socket_options(self):
        """Assert passing socket options works with connection_from_host"""
        p = PoolManager(socket_options=[])
        override_opts = [(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1),
                         (socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)]
        pool_kwargs = {'socket_options': override_opts}

        default_pool = p.connection_from_host('example.com', scheme='http')
        override_pool = p.connection_from_host('example.com',
                                               scheme='http',
                                               pool_kwargs=pool_kwargs)

        assert default_pool.conn_kw['socket_options'] == []
        assert override_pool.conn_kw['socket_options'] == override_opts
Esempio n. 7
0
    def test_override_pool_kwargs_host(self):
        """Assert overriding pool kwargs works with connection_from_host"""
        p = PoolManager()
        pool_kwargs = {"retries": 100, "block": True}

        default_pool = p.connection_from_host("example.com", scheme="http")
        override_pool = p.connection_from_host("example.com",
                                               scheme="http",
                                               pool_kwargs=pool_kwargs)

        assert retry.Retry.DEFAULT == default_pool.retries
        assert not default_pool.block

        assert 100 == override_pool.retries
        assert override_pool.block
Esempio n. 8
0
    def test_override_pool_kwargs_host(self):
        """Assert overriding pool kwargs works with connection_from_host"""
        p = PoolManager(block=False)
        pool_kwargs = {'retries': 100, 'block': True}

        default_pool = p.connection_from_host('example.com', scheme='http')
        override_pool = p.connection_from_host('example.com',
                                               scheme='http',
                                               pool_kwargs=pool_kwargs)

        assert retry.Retry.DEFAULT == default_pool.retries
        assert not default_pool.block

        assert 100 == override_pool.retries
        assert override_pool.block
    def test_pool_kwargs_socket_options(self):
        """Assert passing socket options works with connection_from_host"""
        p = PoolManager(socket_options=[])
        override_opts = [
            (socket.SOL_SOCKET, socket.SO_REUSEADDR, 1),
            (socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
        ]
        pool_kwargs = {'socket_options': override_opts}

        default_pool = p.connection_from_host('example.com', scheme='http')
        override_pool = p.connection_from_host(
            'example.com', scheme='http', pool_kwargs=pool_kwargs
        )

        assert default_pool.conn_kw['socket_options'] == []
        assert override_pool.conn_kw['socket_options'] == override_opts
Esempio n. 10
0
    def test_override_pool_kwargs_host(self):
        """Assert overriding pool kwargs works with connection_from_host"""
        p = PoolManager(strict=True)
        pool_kwargs = {'strict': False, 'retries': 100, 'block': True}

        default_pool = p.connection_from_host('example.com', scheme='http')
        override_pool = p.connection_from_host('example.com', scheme='http',
                                               pool_kwargs=pool_kwargs)

        assert default_pool.strict
        assert retry.Retry.DEFAULT == default_pool.retries
        assert not default_pool.block

        assert not override_pool.strict
        assert 100 == override_pool.retries
        assert override_pool.block
    def test_override_pool_kwargs_host(self):
        """Assert overriding pool kwargs works with connection_from_host"""
        p = PoolManager(strict=True)
        pool_kwargs = {'strict': False, 'retries': 100, 'block': True}

        default_pool = p.connection_from_host('example.com', scheme='http')
        override_pool = p.connection_from_host('example.com', scheme='http',
                                               pool_kwargs=pool_kwargs)

        self.assertTrue(default_pool.strict)
        self.assertEqual(retry.Retry.DEFAULT, default_pool.retries)
        self.assertFalse(default_pool.block)

        self.assertFalse(override_pool.strict)
        self.assertEqual(100, override_pool.retries)
        self.assertTrue(override_pool.block)
Esempio n. 12
0
    def test_pool_kwargs_socket_options(self) -> None:
        """Assert passing socket options works with connection_from_host"""
        p = PoolManager(socket_options=[])
        override_opts = [
            (socket.SOL_SOCKET, socket.SO_REUSEADDR, 1),
            (socket.IPPROTO_TCP, socket.TCP_NODELAY, 1),
        ]
        pool_kwargs = {"socket_options": override_opts}

        default_pool = p.connection_from_host("example.com", scheme="http")
        override_pool = p.connection_from_host(
            "example.com", scheme="http", pool_kwargs=pool_kwargs
        )

        assert default_pool.conn_kw["socket_options"] == []
        assert override_pool.conn_kw["socket_options"] == override_opts
Esempio n. 13
0
    def test_pools_keyed_with_from_host(self):
        """Assert pools are still keyed correctly with connection_from_host."""
        ssl_kw = {
            "key_file": "/root/totally_legit.key",
            "cert_file": "/root/totally_legit.crt",
            "cert_reqs": "CERT_REQUIRED",
            "ca_certs": "/root/path_to_pem",
            "ssl_version": "SSLv23_METHOD",
        }
        p = PoolManager(5, **ssl_kw)
        conns = [p.connection_from_host("example.com", 443, scheme="https")]

        for k in ssl_kw:
            p.connection_pool_kw[k] = "newval"
            conns.append(
                p.connection_from_host("example.com", 443, scheme="https"))

        assert all(x is not y for i, x in enumerate(conns)
                   for j, y in enumerate(conns) if i != j)
Esempio n. 14
0
    def test_pools_keyed_with_from_host(self):
        """Assert pools are still keyed correctly with connection_from_host."""
        ssl_kw = [
            ('key_file', DEFAULT_CERTS['keyfile']),
            ('cert_file', DEFAULT_CERTS['certfile']),
            ('cert_reqs', 'CERT_REQUIRED'),
            ('ca_certs', DEFAULT_CA),
            ('ca_cert_dir', DEFAULT_CA_DIR),
            ('ssl_version', 'SSLv23'),
            ('ssl_context', ssl_.create_urllib3_context()),
        ]
        p = PoolManager()
        conns = [p.connection_from_host('example.com', 443, scheme='https')]

        for k, v in ssl_kw:
            p.connection_pool_kw[k] = v
            conns.append(
                p.connection_from_host('example.com', 443, scheme='https'))

        assert all(x is not y for i, x in enumerate(conns)
                   for j, y in enumerate(conns) if i != j)
Esempio n. 15
0
    def test_pools_keyed_with_from_host(self):
        """Assert pools are still keyed correctly with connection_from_host."""
        ssl_kw = [
            ("key_file", DEFAULT_CERTS["keyfile"]),
            ("cert_file", DEFAULT_CERTS["certfile"]),
            ("cert_reqs", "CERT_REQUIRED"),
            ("ca_certs", DEFAULT_CA),
            ("ca_cert_dir", DEFAULT_CA_DIR),
            ("ssl_version", "SSLv23"),
            ("ssl_context", ssl_.create_urllib3_context()),
        ]
        p = PoolManager()
        conns = [p.connection_from_host("example.com", 443, scheme="https")]

        for k, v in ssl_kw:
            p.connection_pool_kw[k] = v
            conns.append(p.connection_from_host("example.com", 443, scheme="https"))

        assert all(
            x is not y
            for i, x in enumerate(conns)
            for j, y in enumerate(conns)
            if i != j
        )