-
Notifications
You must be signed in to change notification settings - Fork 265
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
6 changed files
with
209 additions
and
65 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,5 +27,5 @@ __pycache__ | |
*~ | ||
|
||
/winrm/tests/config.json | ||
|
||
|
||
.pytest_cache | ||
venv |
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
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,62 +1,176 @@ | ||
# coding=utf-8 | ||
import os | ||
from winrm.transport import Transport | ||
|
||
|
||
def test_build_session_cert_validate(): | ||
t_default = Transport(endpoint="Endpoint", | ||
server_cert_validation='validate', | ||
username='test', | ||
password='test', | ||
auth_method='basic', | ||
) | ||
t_ca_override = Transport(endpoint="Endpoint", | ||
server_cert_validation='validate', | ||
username='test', | ||
password='test', | ||
auth_method='basic', | ||
ca_trust_path='overridepath', | ||
) | ||
try: | ||
import unittest | ||
|
||
from winrm import transport | ||
|
||
|
||
class TestTransport(unittest.TestCase): | ||
maxDiff = 2048 | ||
_old_env = None | ||
|
||
def setUp(self): | ||
super(TestTransport, self).setUp() | ||
self._old_env = {} | ||
os.environ.pop('REQUESTS_CA_BUNDLE', None) | ||
os.environ.pop('TRAVIS_APT_PROXY', None) | ||
os.environ.pop('CURL_CA_BUNDLE', None) | ||
os.environ.pop('HTTPS_PROXY', None) | ||
os.environ.pop('HTTP_PROXY', None) | ||
os.environ.pop('NO_PROXY', None) | ||
transport.DISPLAYED_PROXY_WARNING = False | ||
|
||
def tearDown(self): | ||
super(TestTransport, self).tearDown() | ||
os.environ.pop('REQUESTS_CA_BUNDLE', None) | ||
os.environ.pop('TRAVIS_APT_PROXY', None) | ||
os.environ.pop('CURL_CA_BUNDLE', None) | ||
os.environ.pop('HTTPS_PROXY', None) | ||
os.environ.pop('HTTP_PROXY', None) | ||
os.environ.pop('NO_PROXY', None) | ||
|
||
def test_build_session_cert_validate_1(self): | ||
os.environ['REQUESTS_CA_BUNDLE'] = 'path_to_REQUESTS_CA_CERT' | ||
|
||
t_default = transport.Transport(endpoint="https://example.com", | ||
server_cert_validation='validate', | ||
username='test', | ||
password='test', | ||
auth_method='basic', | ||
) | ||
t_default.build_session() | ||
self.assertEqual('path_to_REQUESTS_CA_CERT', t_default.session.verify) | ||
|
||
def test_build_session_cert_validate_2(self): | ||
os.environ['CURL_CA_BUNDLE'] = 'path_to_CURL_CA_CERT' | ||
|
||
t_default = transport.Transport(endpoint="https://example.com", | ||
server_cert_validation='validate', | ||
username='test', | ||
password='test', | ||
auth_method='basic', | ||
) | ||
t_default.build_session() | ||
self.assertEqual('path_to_CURL_CA_CERT', t_default.session.verify) | ||
|
||
def test_build_session_cert_override_1(self): | ||
os.environ['REQUESTS_CA_BUNDLE'] = 'path_to_REQUESTS_CA_CERT' | ||
|
||
t_default = transport.Transport(endpoint="https://example.com", | ||
server_cert_validation='validate', | ||
username='test', | ||
password='test', | ||
auth_method='basic', | ||
ca_trust_path='overridepath', | ||
) | ||
t_default.build_session() | ||
t_ca_override.build_session() | ||
assert(t_default.session.verify == 'path_to_REQUESTS_CA_CERT') | ||
assert(t_ca_override.session.verify == 'overridepath') | ||
finally: | ||
del os.environ['REQUESTS_CA_BUNDLE'] | ||
self.assertEqual('overridepath', t_default.session.verify) | ||
|
||
try: | ||
def test_build_session_cert_override_2(self): | ||
os.environ['CURL_CA_BUNDLE'] = 'path_to_CURL_CA_CERT' | ||
|
||
t_default = transport.Transport(endpoint="https://example.com", | ||
server_cert_validation='validate', | ||
username='test', | ||
password='test', | ||
auth_method='basic', | ||
ca_trust_path='overridepath', | ||
) | ||
t_default.build_session() | ||
self.assertEqual('overridepath', t_default.session.verify) | ||
|
||
def test_build_session_cert_ignore_1(self): | ||
os.environ['REQUESTS_CA_BUNDLE'] = 'path_to_REQUESTS_CA_CERT' | ||
os.environ['CURL_CA_BUNDLE'] = 'path_to_CURL_CA_CERT' | ||
|
||
t_default = transport.Transport(endpoint="https://example.com", | ||
server_cert_validation='ignore', | ||
username='test', | ||
password='test', | ||
auth_method='basic', | ||
) | ||
|
||
t_default.build_session() | ||
t_ca_override.build_session() | ||
assert(t_default.session.verify == 'path_to_CURL_CA_CERT') | ||
assert (t_ca_override.session.verify == 'overridepath') | ||
finally: | ||
del os.environ['CURL_CA_BUNDLE'] | ||
|
||
|
||
def test_build_session_cert_ignore(): | ||
t_default = Transport(endpoint="Endpoint", | ||
server_cert_validation='ignore', | ||
username='test', | ||
password='test', | ||
auth_method='basic', | ||
) | ||
t_ca_override = Transport(endpoint="Endpoint", | ||
server_cert_validation='ignore', | ||
username='test', | ||
password='test', | ||
auth_method='basic', | ||
ca_trust_path='boguspath' | ||
) | ||
try: | ||
self.assertIs(False, t_default.session.verify) | ||
|
||
def test_build_session_cert_ignore_2(self): | ||
os.environ['REQUESTS_CA_BUNDLE'] = 'path_to_REQUESTS_CA_CERT' | ||
os.environ['CURL_CA_BUNDLE'] = 'path_to_CURL_CA_CERT' | ||
|
||
t_default = transport.Transport(endpoint="https://example.com", | ||
server_cert_validation='ignore', | ||
username='test', | ||
password='test', | ||
auth_method='basic', | ||
ca_trust_path='boguspath' | ||
) | ||
|
||
t_default.build_session() | ||
self.assertIs(False, t_default.session.verify) | ||
|
||
def test_build_session_proxy_none(self): | ||
os.environ['HTTP_PROXY'] = 'random_proxy' | ||
os.environ['HTTPS_PROXY'] = 'random_proxy_2' | ||
|
||
t_default = transport.Transport(endpoint="https://example.com", | ||
server_cert_validation='validate', | ||
username='test', | ||
password='test', | ||
auth_method='basic', | ||
proxy=None | ||
) | ||
|
||
t_default.build_session() | ||
self.assertEqual({'no_proxy': '*'}, t_default.session.proxies) | ||
|
||
def test_build_session_proxy_defined(self): | ||
t_default = transport.Transport(endpoint="https://example.com", | ||
server_cert_validation='validate', | ||
username='test', | ||
password='test', | ||
auth_method='basic', | ||
proxy='test_proxy' | ||
) | ||
|
||
t_default.build_session() | ||
self.assertEqual({'http': 'test_proxy', 'https': 'test_proxy'}, t_default.session.proxies) | ||
|
||
def test_build_session_proxy_defined_and_env(self): | ||
os.environ['HTTPS_PROXY'] = 'random_proxy' | ||
|
||
t_default = transport.Transport(endpoint="https://example.com", | ||
server_cert_validation='validate', | ||
username='test', | ||
password='test', | ||
auth_method='basic', | ||
proxy='test_proxy' | ||
) | ||
|
||
t_default.build_session() | ||
self.assertEqual({'http': 'test_proxy', 'https': 'test_proxy'}, t_default.session.proxies) | ||
|
||
def test_build_session_proxy_with_env_https(self): | ||
os.environ['HTTPS_PROXY'] = 'random_proxy' | ||
|
||
t_default = transport.Transport(endpoint="https://example.com", | ||
server_cert_validation='validate', | ||
username='test', | ||
password='test', | ||
auth_method='basic', | ||
) | ||
|
||
t_default.build_session() | ||
self.assertEqual({'https': 'random_proxy'}, t_default.session.proxies) | ||
|
||
def test_build_session_proxy_with_env_http(self): | ||
os.environ['HTTP_PROXY'] = 'random_proxy' | ||
|
||
t_default = transport.Transport(endpoint="https://example.com", | ||
server_cert_validation='validate', | ||
username='test', | ||
password='test', | ||
auth_method='basic', | ||
) | ||
|
||
t_default.build_session() | ||
t_ca_override.build_session() | ||
assert(isinstance(t_default.session.verify, bool) and not t_default.session.verify) | ||
assert (isinstance(t_ca_override.session.verify, bool) and not t_ca_override.session.verify) | ||
finally: | ||
del os.environ['REQUESTS_CA_BUNDLE'] | ||
del os.environ['CURL_CA_BUNDLE'] | ||
self.assertEqual({'http': 'random_proxy'}, t_default.session.proxies) |
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