mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Clean the cached file since that will fail when verify_ssl is true
Signed-off-by: Pedro Algarvio <palgarvio@vmware.com>
This commit is contained in:
parent
1882be04ed
commit
eb4aeab301
1 changed files with 86 additions and 48 deletions
|
@ -1,6 +1,8 @@
|
|||
"""
|
||||
Tests for the file state
|
||||
"""
|
||||
import os
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
|
@ -13,13 +15,20 @@ def test_get_source_sum_verify_ssl_false(
|
|||
test verify_ssl with get_source_sum
|
||||
"""
|
||||
web_file = ssl_webserver.url("this.txt")
|
||||
if verify_ssl:
|
||||
# Clean the cached this.txt if it exists as it will fail the test
|
||||
# because it won't fetch it again
|
||||
ret = salt_call_cli.run("cp.is_cached", web_file, saltenv="base")
|
||||
assert ret.returncode == 0
|
||||
if ret.data:
|
||||
os.unlink(ret.data)
|
||||
ret = salt_call_cli.run(
|
||||
"--local",
|
||||
"file.get_source_sum",
|
||||
str(tmp_path / "test_source_sum.txt"),
|
||||
web_file,
|
||||
web_file + ".sha256",
|
||||
"verify_ssl={}".format(verify_ssl),
|
||||
source=web_file,
|
||||
source_hash=web_file + ".sha256",
|
||||
verify_ssl=verify_ssl,
|
||||
)
|
||||
if not verify_ssl:
|
||||
assert ret.data["hsum"] == this_txt_file.sha256
|
||||
|
@ -35,23 +44,30 @@ def test_get_managed_verify_ssl(salt_call_cli, tmp_path, ssl_webserver, verify_s
|
|||
test verify_ssl with get_managed
|
||||
"""
|
||||
web_file = ssl_webserver.url("this.txt")
|
||||
if verify_ssl:
|
||||
# Clean the cached this.txt if it exists as it will fail the test
|
||||
# because it won't fetch it again
|
||||
ret = salt_call_cli.run("cp.is_cached", web_file, saltenv="base")
|
||||
assert ret.returncode == 0
|
||||
if ret.data:
|
||||
os.unlink(ret.data)
|
||||
ret = salt_call_cli.run(
|
||||
"--local",
|
||||
"file.get_managed",
|
||||
str(tmp_path / "test_managed.txt"),
|
||||
"",
|
||||
web_file,
|
||||
web_file + ".sha256",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"base",
|
||||
"{}",
|
||||
"",
|
||||
"True",
|
||||
"verify_ssl={}".format(verify_ssl),
|
||||
template="",
|
||||
source=web_file,
|
||||
source_hash=web_file + ".sha256",
|
||||
source_hash_name="",
|
||||
user="",
|
||||
group="",
|
||||
mode="",
|
||||
attrs="",
|
||||
saltenv="base",
|
||||
context={},
|
||||
defaults="",
|
||||
skip_verify=True,
|
||||
verify_ssl=verify_ssl,
|
||||
)
|
||||
if not verify_ssl:
|
||||
assert "this.txt" in ret.data[0]
|
||||
|
@ -68,21 +84,29 @@ def test_manage_file_verify_ssl(
|
|||
test verify_ssl with manage_file
|
||||
"""
|
||||
test_file = tmp_path / "test_manage_file.txt"
|
||||
web_file = ssl_webserver.url("this.txt")
|
||||
if verify_ssl:
|
||||
# Clean the cached this.txt if it exists as it will fail the test
|
||||
# because it won't fetch it again
|
||||
ret = salt_call_cli.run("cp.is_cached", web_file, saltenv="base")
|
||||
assert ret.returncode == 0
|
||||
if ret.data:
|
||||
os.unlink(ret.data)
|
||||
ret = salt_call_cli.run(
|
||||
"--local",
|
||||
"file.manage_file",
|
||||
str(test_file),
|
||||
"",
|
||||
"",
|
||||
ssl_webserver.url("this.txt"),
|
||||
"{hash_type: 'sha256', 'hsum': '" + this_txt_file.sha256 + "'}",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"base",
|
||||
"",
|
||||
"verify_ssl={}".format(verify_ssl),
|
||||
sfn="",
|
||||
ret="",
|
||||
source=web_file,
|
||||
source_sum={"hash_type": "sha256", "hsum": this_txt_file.sha256},
|
||||
user="",
|
||||
group="",
|
||||
mode="",
|
||||
attrs="",
|
||||
saltenv="base",
|
||||
backup="",
|
||||
verify_ssl=verify_ssl,
|
||||
)
|
||||
if not verify_ssl:
|
||||
assert ret.data["changes"] == {"diff": "New file", "mode": "0000"}
|
||||
|
@ -101,22 +125,29 @@ def test_check_managed_changes_verify_ssl(
|
|||
"""
|
||||
test_file = tmp_path / "test_managed_changes.txt"
|
||||
web_url = ssl_webserver.url("this.txt")
|
||||
if verify_ssl:
|
||||
# Clean the cached this.txt if it exists as it will fail the test
|
||||
# because it won't fetch it again
|
||||
ret = salt_call_cli.run("cp.is_cached", web_url, saltenv="base")
|
||||
assert ret.returncode == 0
|
||||
if ret.data:
|
||||
os.unlink(ret.data)
|
||||
ret = salt_call_cli.run(
|
||||
"--local",
|
||||
"file.check_managed_changes",
|
||||
str(test_file),
|
||||
web_url,
|
||||
web_url + ".sha256",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"jinja",
|
||||
"",
|
||||
"",
|
||||
"base",
|
||||
"verify_ssl={}".format(verify_ssl),
|
||||
source=web_url,
|
||||
source_hash=web_url + ".sha256",
|
||||
source_hash_name="",
|
||||
user="",
|
||||
group="",
|
||||
mode="",
|
||||
attrs="",
|
||||
template="jinja",
|
||||
context="",
|
||||
defaults="",
|
||||
saltenv="base",
|
||||
verify_ssl=verify_ssl,
|
||||
)
|
||||
|
||||
if not verify_ssl:
|
||||
|
@ -136,19 +167,26 @@ def test_check_file_meta_verify_ssl(
|
|||
test_file = tmp_path / "test_check_file_meta.txt"
|
||||
test_file.write_text("test check_file_meta")
|
||||
web_url = ssl_webserver.url("this.txt")
|
||||
if verify_ssl:
|
||||
# Clean the cached this.txt if it exists as it will fail the test
|
||||
# because it won't fetch it again
|
||||
ret = salt_call_cli.run("cp.is_cached", web_url, saltenv="base")
|
||||
assert ret.returncode == 0
|
||||
if ret.data:
|
||||
os.unlink(ret.data)
|
||||
ret = salt_call_cli.run(
|
||||
"--local",
|
||||
"file.check_file_meta",
|
||||
str(test_file),
|
||||
"",
|
||||
web_url,
|
||||
"{hash_type: 'sha256', 'hsum': '" + this_txt_file.sha256 + "'}",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"base",
|
||||
"verify_ssl={}".format(verify_ssl),
|
||||
sfn="",
|
||||
source=web_url,
|
||||
source_sum={"hash_type": "sha256", "hsum": this_txt_file.sha256},
|
||||
user="",
|
||||
mode="",
|
||||
group="",
|
||||
attrs="",
|
||||
saltenv="base",
|
||||
verify_ssl=verify_ssl,
|
||||
)
|
||||
|
||||
if not verify_ssl:
|
||||
|
|
Loading…
Add table
Reference in a new issue