Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dwoz committed Aug 13, 2023
1 parent 4919283 commit e6b863b
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 50 deletions.
2 changes: 1 addition & 1 deletion tests/pytests/functional/cli/test_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def returns_for_job(jid):
"extension_modules": "",
"failhard": True,
}
with patch("salt.transport.tcp.TCPPubClient", MockSubscriber):
with patch("salt.transport.tcp.PublishClient", MockSubscriber):
batch = salt.cli.batch.Batch(opts, quiet=True)
with patch.object(batch.local, "pub", Mock(side_effect=mock_pub)):
with patch.object(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ async def handle_stream(self, stream, address):

@pytest.fixture
def client(io_loop, config):
client = salt.transport.tcp.TCPPubClient(
client = salt.transport.tcp.PublishClient(
config.copy(), io_loop, host=config["master_ip"], port=config["publish_port"]
)
try:
Expand Down
81 changes: 34 additions & 47 deletions tests/pytests/unit/transport/test_base.py
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
2 changes: 1 addition & 1 deletion tests/pytests/unit/transport/test_tcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ async def test_async_tcp_pub_channel_connect_publish_port(
future.set_result(True)
with patch("salt.crypt.AsyncAuth.gen_token", patch_auth), patch(
"salt.crypt.AsyncAuth.authenticated", patch_auth
), patch("salt.transport.tcp.TCPPubClient", transport):
), patch("salt.transport.tcp.PublishClient", transport):
channel = salt.channel.client.AsyncPubChannel.factory(opts)
with channel:
# We won't be able to succeed the connection because we're not mocking the tornado coroutine
Expand Down

0 comments on commit e6b863b

Please sign in to comment.