-
Notifications
You must be signed in to change notification settings - Fork 462
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
64 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import responses | ||
import pytest | ||
import re | ||
|
||
from requests.compat import urlencode | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import ssl | ||
import sure # noqa | ||
import urllib3 | ||
|
||
from cfscrape import CloudflareAdapter | ||
|
||
|
||
class TestCloudflareAdapter: | ||
|
||
def test_create_adapter(self): | ||
adapter = CloudflareAdapter() | ||
adapter.should.be.a("requests.adapters.HTTPAdapter") | ||
adapter.close() | ||
|
||
def test_get_connection(self): | ||
adapter = CloudflareAdapter() | ||
|
||
conn = adapter.get_connection("https://127.0.0.1", None) | ||
|
||
conn.conn_kw.should.be.a("dict") | ||
conn.conn_kw.should.have.key("ssl_context") | ||
ssl_context = conn.conn_kw["ssl_context"] | ||
|
||
# This should be ssl.SSLContext unless pyOpenSSL is installed. | ||
# If pyOpenSSL is injected into urllib3, this should still work. | ||
try: | ||
assert isinstance(ssl_context, urllib3.contrib.pyopenssl.PyOpenSSLContext) | ||
except: | ||
assert isinstance(ssl_context, ssl.SSLContext) | ||
|
||
adapter.close() | ||
|
||
def test_set_ciphers(self): | ||
adapter = CloudflareAdapter() | ||
|
||
# Reinitialize the pool manager with a different context | ||
ctx = ssl.create_default_context() | ||
adapter.init_poolmanager(1, 1, ssl_context=ctx) | ||
# Check to see if the context remains the same without error | ||
conn = adapter.get_connection('https://127.0.0.1', None) | ||
conn.conn_kw.should.be.a("dict") | ||
assert conn.conn_kw["ssl_context"] is ctx | ||
|
||
adapter.close() |