Skip to content

Commit 6d0b9a3

Browse files
committed
check SSLREQCERT env var for disabling ssl verification
1 parent fe20052 commit 6d0b9a3

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11

22
Unreleased
33
----------
4-
**Changed**
4+
**Improvements**
55
- public_model task also defines methods mapped to MAS module steps when publishing to MAS.
6+
- SSL verification can be disable with `SSLREQCERT` environment variable.
67

78

89
v0.9.6 (2019-07-15)

src/sasctl/core.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,13 @@ class Session(requests.Session):
208208
209209
"""
210210
def __init__(self, host, user=None, password=None, authinfo=None,
211-
protocol=None, port=None, verify_ssl=True):
211+
protocol=None, port=None, verify_ssl=None):
212212
super(Session, self).__init__()
213213

214+
if verify_ssl is None:
215+
verify_ssl = os.environ.get('SSLREQCERT', 'yes')
216+
verify_ssl = str(verify_ssl).lower() not in ('no', 'false')
217+
214218
self._id = uuid4().hex
215219
self.message_log = logger.getChild('session.%s' % self._id)
216220

tests/unit/test_session.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import json
88
import logging
9+
import os
910

1011
import pytest
1112
from six.moves import mock
@@ -200,6 +201,39 @@ def test_ssl_context():
200201
assert not isinstance(s.get_adapter('https://'), SSLContextAdapter)
201202

202203

204+
def test_verify_ssl():
205+
206+
with mock.patch('sasctl.core.Session.get_token', return_value='token'):
207+
# Should verify SSL by default
208+
s = Session('hostname', 'username', 'password')
209+
assert s.verify == True
210+
211+
# Specify true with no issues
212+
s = Session('hostname', 'username', 'password', verify_ssl=True)
213+
assert s.verify == True
214+
215+
# Explicitly disable SSL verification
216+
s = Session('hostname', 'username', 'password', verify_ssl=False)
217+
assert s.verify == False
218+
219+
# Reuse SWAT env variable, if specified
220+
os.environ['SSLREQCERT'] = 'NO'
221+
s = Session('hostname', 'username', 'password')
222+
assert s.verify == False
223+
224+
os.environ['SSLREQCERT'] = 'no'
225+
s = Session('hostname', 'username', 'password')
226+
assert s.verify == False
227+
228+
os.environ['SSLREQCERT'] = 'false'
229+
s = Session('hostname', 'username', 'password')
230+
assert s.verify == False
231+
232+
# Explicit should take precedence over environment variables
233+
s = Session('hostname', 'username', 'password', verify_ssl=True)
234+
assert s.verify == True
235+
236+
203237
def test_kerberos():
204238
with mock.patch('sasctl.core.Session._get_token_with_kerberos',
205239
return_value='token'):

0 commit comments

Comments
 (0)