Skip to content

Commit cf19255

Browse files
Merge pull request #13 from platinummonkey/custom_ssl_options
add custom config options for global ssl verification and certs
2 parents 4954f03 + 5efe3ef commit cf19255

File tree

6 files changed

+54
-4
lines changed

6 files changed

+54
-4
lines changed

docs/changelog.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ ChangeLog
55

66
Changes to the library are recorded here.
77

8+
v1.2.0
9+
------
10+
* Add custom cert/verification options to be passed normally through the singleton config
11+
* Upgrades minimum requests version to 2.20.0 for known CVE-2018-18074
12+
813
v1.1.5
914
------
1015
* Looser requirements everywhere, run free!

docs/quickstart.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
from wiremock.client import *
33

44
Config.base_url = 'https://mockserver.example.com/__admin/'
5+
# Optionally set a custom cert path:
6+
# Config.requests_cert = ... (See requests documentation)
7+
# Optionally disable cert verification
8+
# Config.requests_verify = False
59

610
mapping = Mapping(
711
priority=100,

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
'nose~=1.3.7',
1515
'python-coveralls~=2.9.0',
1616
'responses~=0.5.1',
17-
'requests~=2.13.0',
17+
'requests>=2.20.0',
1818
'six>=1.10.0',
1919
'sphinx-rtd-theme~=0.2.4',
2020
'tox~=2.6.0',
@@ -54,7 +54,7 @@
5454
install_requires=[
5555
'setuptools>=35.0.1',
5656
'six>=1.10.0',
57-
'requests~=2.13.0'
57+
'requests>=2.20.0'
5858
],
5959
extras_require={
6060
'develop': develop_requires,

wiremock/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.1.5
1+
1.2.0

wiremock/base/base_resource.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,24 @@
1212

1313
class RestClient(object):
1414

15-
def __init__(self, timeout=None, base_url=None):
15+
def __init__(self, timeout=None, base_url=None, requests_verify=None, requests_cert=None):
1616
self.timeout = timeout
1717
self.base_url = base_url
18+
self.requests_verify = requests_verify
19+
self.requests_cert = requests_cert
1820

1921
def _base_url(self):
2022
return self.base_url or Config.base_url
2123

2224
def _timeout(self):
2325
return self.timeout or Config.timeout
2426

27+
def _requests_verify(self):
28+
return self.requests_verify or Config.requests_verify
29+
30+
def _requests_cert(self):
31+
return self.requests_cert or Config.requests_cert
32+
2533
def _log(self, action, url, **kwargs):
2634
ctx = {'timeout': kwargs.get('timeout')}
2735
logger.debug(
@@ -32,6 +40,10 @@ def _log(self, action, url, **kwargs):
3240
def post(self, uri, **kwargs):
3341
if 'timeout' not in kwargs:
3442
kwargs['timeout'] = self._timeout()
43+
if 'requests_verify' not in kwargs:
44+
kwargs['verify'] = self._requests_verify()
45+
if 'requests_cert' not in kwargs:
46+
kwargs['cert'] = self._requests_cert()
3547
try:
3648
url = self._base_url() + uri
3749
self._log("POST", url, **kwargs)
@@ -44,6 +56,10 @@ def post(self, uri, **kwargs):
4456
def get(self, uri, **kwargs):
4557
if 'timeout' not in kwargs:
4658
kwargs['timeout'] = self._timeout()
59+
if 'requests_verify' not in kwargs:
60+
kwargs['verify'] = self._requests_verify()
61+
if 'requests_cert' not in kwargs:
62+
kwargs['cert'] = self._requests_cert()
4763
try:
4864
url = self._base_url() + uri
4965
self._log("GET", url, **kwargs)
@@ -56,6 +72,10 @@ def get(self, uri, **kwargs):
5672
def put(self, uri, **kwargs):
5773
if 'timeout' not in kwargs:
5874
kwargs['timeout'] = self._timeout()
75+
if 'requests_verify' not in kwargs:
76+
kwargs['verify'] = self._requests_verify()
77+
if 'requests_cert' not in kwargs:
78+
kwargs['cert'] = self._requests_cert()
5979
try:
6080
url = self._base_url() + uri
6181
self._log("PUT", url, **kwargs)
@@ -68,6 +88,10 @@ def put(self, uri, **kwargs):
6888
def patch(self, uri, **kwargs): # pragma: no cover
6989
if 'timeout' not in kwargs:
7090
kwargs['timeout'] = self._timeout()
91+
if 'requests_verify' not in kwargs:
92+
kwargs['verify'] = self._requests_verify()
93+
if 'requests_cert' not in kwargs:
94+
kwargs['cert'] = self._requests_cert()
7195
try:
7296
url = self._base_url() + uri
7397
self._log("PATCH", url, **kwargs)
@@ -80,6 +104,10 @@ def patch(self, uri, **kwargs): # pragma: no cover
80104
def delete(self, uri, **kwargs):
81105
if 'timeout' not in kwargs:
82106
kwargs['timeout'] = self._timeout()
107+
if 'requests_verify' not in kwargs:
108+
kwargs['verify'] = self._requests_verify()
109+
if 'requests_cert' not in kwargs:
110+
kwargs['cert'] = self._requests_cert()
83111
try:
84112
url = self._base_url() + uri
85113
self._log("DELETE", url, **kwargs)
@@ -92,6 +120,10 @@ def delete(self, uri, **kwargs):
92120
def options(self, uri, **kwargs): # pragma: no cover
93121
if 'timeout' not in kwargs:
94122
kwargs['timeout'] = self._timeout()
123+
if 'requests_verify' not in kwargs:
124+
kwargs['verify'] = self._requests_verify()
125+
if 'requests_cert' not in kwargs:
126+
kwargs['cert'] = self._requests_cert()
95127
try:
96128
url = self._base_url() + uri
97129
self._log("OPTIONS", url, **kwargs)
@@ -104,6 +136,10 @@ def options(self, uri, **kwargs): # pragma: no cover
104136
def head(self, uri, **kwargs): # pragma: no cover
105137
if 'timeout' not in kwargs:
106138
kwargs['timeout'] = self._timeout()
139+
if 'requests_verify' not in kwargs:
140+
kwargs['verify'] = self._requests_verify()
141+
if 'requests_cert' not in kwargs:
142+
kwargs['cert'] = self._requests_cert()
107143
try:
108144
url = self._base_url() + uri
109145
self._log("HEAD", url, **kwargs)

wiremock/constants.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ def __call__(cls, *args, **kwargs):
2323
DEFAULT_BASE_URL = 'http://localhost/__admin'
2424
USER_AGENT = 'python_wiremock/%s'.format(__version__)
2525
DEFAULT_HEADERS = {'Accept': 'application/json', 'Content-Type': 'application/json', 'user-agent': USER_AGENT}
26+
DEFAULT_REQUESTS_VERIFY = True
27+
DEFAULT_REQUESTS_CERT = None
2628

2729

2830
@add_metaclass(Singleton)
@@ -31,6 +33,9 @@ class Config(object):
3133
base_url = DEFAULT_BASE_URL
3234
user_agent = USER_AGENT
3335
headers = DEFAULT_HEADERS
36+
requests_verify = DEFAULT_REQUESTS_VERIFY
37+
requests_cert = DEFAULT_REQUESTS_CERT
38+
3439

3540
Config() # pre-call once
3641

0 commit comments

Comments
 (0)