forked from saltstack/salt
-
Notifications
You must be signed in to change notification settings - Fork 0
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
72 additions
and
93 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
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,70 +1,57 @@ | ||
import ssl | ||
import contextlib | ||
|
||
import salt.transport.base | ||
from tests.support.mock import patch | ||
|
||
from tests.support.helpers import dedent | ||
|
||
import pytest | ||
from tests.support.mock import patch, Mock | ||
|
||
|
||
@patch('ssl.SSLContext') | ||
@patch("ssl.SSLContext") | ||
def test_ssl_context_legacy_opts(mock): | ||
ctx = salt.transport.base.ssl_context({ | ||
'certfile': "server.crt", | ||
'keyfile': "server.key", | ||
'cert_reqs': "CERT_NONE", | ||
"ca_certs": "ca.crt", | ||
}) | ||
ctx = salt.transport.base.ssl_context( | ||
{ | ||
"certfile": "server.crt", | ||
"keyfile": "server.key", | ||
"cert_reqs": "CERT_NONE", | ||
"ca_certs": "ca.crt", | ||
} | ||
) | ||
ctx.load_cert_chain.assert_called_with( | ||
"server.crt", | ||
"server.key", | ||
) | ||
ctx.load_verify_locations.assert_called_with( | ||
"ca.crt" | ||
) | ||
ctx.load_verify_locations.assert_called_with("ca.crt") | ||
assert ssl.VerifyMode.CERT_NONE == ctx.verify_mode | ||
assert not ctx.check_hostname | ||
|
||
|
||
@patch('ssl.SSLContext') | ||
@patch("ssl.SSLContext") | ||
def test_ssl_context_opts(mock): | ||
mock.verify_flags = ssl.VerifyFlags.VERIFY_X509_TRUSTED_FIRST | ||
ctx = salt.transport.base.ssl_context({ | ||
'certfile': "server.crt", | ||
'keyfile': "server.key", | ||
'cert_reqs': "CERT_OPTIONAL", | ||
"verify_locations": [ | ||
"ca.crt", | ||
{"cafile": "crl.pem"}, | ||
{"capath": "/tmp/mycapathsdf"}, | ||
{"cadata": "mycadataother"}, | ||
{"CADATA": "mycadatasdf"}, | ||
], | ||
"verify_flags": [ | ||
"VERIFY_CRL_CHECK_CHAIN", | ||
] | ||
}) | ||
ctx = salt.transport.base.ssl_context( | ||
{ | ||
"certfile": "server.crt", | ||
"keyfile": "server.key", | ||
"cert_reqs": "CERT_OPTIONAL", | ||
"verify_locations": [ | ||
"ca.crt", | ||
{"cafile": "crl.pem"}, | ||
{"capath": "/tmp/mycapathsdf"}, | ||
{"cadata": "mycadataother"}, | ||
{"CADATA": "mycadatasdf"}, | ||
], | ||
"verify_flags": [ | ||
"VERIFY_CRL_CHECK_CHAIN", | ||
], | ||
} | ||
) | ||
ctx.load_cert_chain.assert_called_with( | ||
"server.crt", | ||
"server.key", | ||
) | ||
ctx.load_verify_locations.assert_any_call( | ||
cafile="ca.crt" | ||
) | ||
ctx.load_verify_locations.assert_any_call( | ||
cafile="crl.pem" | ||
) | ||
ctx.load_verify_locations.assert_any_call( | ||
capath="/tmp/mycapathsdf" | ||
) | ||
ctx.load_verify_locations.assert_any_call( | ||
cadata="mycadataother" | ||
) | ||
ctx.load_verify_locations.assert_called_with( | ||
cadata="mycadatasdf" | ||
) | ||
ctx.load_verify_locations.assert_any_call(cafile="ca.crt") | ||
ctx.load_verify_locations.assert_any_call(cafile="crl.pem") | ||
ctx.load_verify_locations.assert_any_call(capath="/tmp/mycapathsdf") | ||
ctx.load_verify_locations.assert_any_call(cadata="mycadataother") | ||
ctx.load_verify_locations.assert_called_with(cadata="mycadatasdf") | ||
assert ssl.VerifyMode.CERT_OPTIONAL == ctx.verify_mode | ||
assert ctx.check_hostname | ||
assert ssl.VerifyFlags.VERIFY_CRL_CHECK_CHAIN & ctx.verify_flags |
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