mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Fix lint
This commit is contained in:
parent
636eff5fda
commit
1e976cf735
11 changed files with 57 additions and 99 deletions
|
@ -1938,6 +1938,7 @@ def check_perms(
|
|||
deny_perms=deny_perms,
|
||||
inheritance=inheritance,
|
||||
reset=reset,
|
||||
test_mode=__opts__["test"],
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -2349,7 +2349,7 @@ def check_perms(
|
|||
deny_perms=None,
|
||||
inheritance=True,
|
||||
reset=False,
|
||||
test_mode=None,
|
||||
test_mode=False,
|
||||
):
|
||||
"""
|
||||
Check owner and permissions for the passed directory. This function checks
|
||||
|
@ -2429,9 +2429,6 @@ def check_perms(
|
|||
}
|
||||
})
|
||||
"""
|
||||
if test_mode is None:
|
||||
test_mode = __opts__["test"]
|
||||
|
||||
# Validate obj_type
|
||||
if obj_type.lower() not in flags().obj_type:
|
||||
raise SaltInvocationError('Invalid "obj_type" passed: {}'.format(obj_type))
|
||||
|
|
|
@ -21,9 +21,9 @@ def configure_loader_modules():
|
|||
"__utils__": {
|
||||
"dacl.check_perms": win_dacl.check_perms,
|
||||
"dacl.set_perms": win_dacl.set_perms,
|
||||
}
|
||||
},
|
||||
"__opts__": {"test": False},
|
||||
},
|
||||
win_dacl: {"__opts__": {"test": False}},
|
||||
}
|
||||
|
||||
|
||||
|
@ -43,7 +43,7 @@ def test_check_perms_set_owner_test_true(test_file):
|
|||
"name": str(test_file),
|
||||
"result": None,
|
||||
}
|
||||
with patch.dict(win_dacl.__opts__, {"test": True}):
|
||||
with patch.dict(win_file.__opts__, {"test": True}):
|
||||
result = win_file.check_perms(
|
||||
path=str(test_file), owner="Backup Operators", inheritance=None
|
||||
)
|
||||
|
@ -76,7 +76,7 @@ def test_check_perms_deny_test_true(test_file):
|
|||
"name": str(test_file),
|
||||
"result": None,
|
||||
}
|
||||
with patch.dict(win_dacl.__opts__, {"test": True}):
|
||||
with patch.dict(win_file.__opts__, {"test": True}):
|
||||
result = win_file.check_perms(
|
||||
path=str(test_file),
|
||||
deny_perms={"Users": {"perms": "read_execute"}},
|
||||
|
@ -113,7 +113,7 @@ def test_check_perms_grant_test_true(test_file):
|
|||
"name": str(test_file),
|
||||
"result": None,
|
||||
}
|
||||
with patch.dict(win_dacl.__opts__, {"test": True}):
|
||||
with patch.dict(win_file.__opts__, {"test": True}):
|
||||
result = win_file.check_perms(
|
||||
path=str(test_file),
|
||||
grant_perms={"Users": {"perms": "read_execute"}},
|
||||
|
@ -150,7 +150,7 @@ def test_check_perms_inheritance_false_test_true(test_file):
|
|||
"name": str(test_file),
|
||||
"result": None,
|
||||
}
|
||||
with patch.dict(win_dacl.__opts__, {"test": True}):
|
||||
with patch.dict(win_file.__opts__, {"test": True}):
|
||||
result = win_file.check_perms(path=str(test_file), inheritance=False)
|
||||
assert result == expected
|
||||
|
||||
|
@ -214,7 +214,7 @@ def test_check_perms_reset_test_true(test_file):
|
|||
"name": str(test_file),
|
||||
"result": None,
|
||||
}
|
||||
with patch.dict(win_dacl.__opts__, {"test": True}):
|
||||
with patch.dict(win_file.__opts__, {"test": True}):
|
||||
result = win_file.check_perms(
|
||||
path=str(test_file),
|
||||
grant_perms={
|
||||
|
|
|
@ -2,8 +2,6 @@ import os
|
|||
|
||||
import pytest
|
||||
|
||||
import salt.modules.win_file as win_file
|
||||
import salt.states.file as file
|
||||
import salt.utils.win_dacl as win_dacl
|
||||
import salt.utils.win_functions as win_functions
|
||||
|
||||
|
@ -20,28 +18,7 @@ pytestmark = [
|
|||
]
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def configure_loader_modules():
|
||||
return {
|
||||
file: {
|
||||
"__opts__": {"test": False},
|
||||
"__salt__": {
|
||||
"file.mkdir": win_file.mkdir,
|
||||
"file.check_perms": win_file.check_perms,
|
||||
},
|
||||
},
|
||||
win_file: {
|
||||
"__utils__": {
|
||||
"dacl.check_perms": win_dacl.check_perms,
|
||||
"dacl.set_owner": win_dacl.set_owner,
|
||||
"dacl.set_perms": win_dacl.set_perms,
|
||||
},
|
||||
},
|
||||
win_dacl: {"__opts__": {"test": False}},
|
||||
}
|
||||
|
||||
|
||||
def test_directory_new(tmp_path):
|
||||
def test_directory_new(file, tmp_path):
|
||||
"""
|
||||
Test file.directory when the directory does not exist
|
||||
Should just return "New Dir"
|
||||
|
@ -107,7 +84,7 @@ def test_directory_new(tmp_path):
|
|||
assert permissions == expected
|
||||
|
||||
|
||||
def test_directory_new_no_inherit(tmp_path):
|
||||
def test_directory_new_no_inherit(file, tmp_path):
|
||||
"""
|
||||
Test file.directory when the directory does not exist
|
||||
Should just return "New Dir"
|
||||
|
@ -127,7 +104,7 @@ def test_directory_new_no_inherit(tmp_path):
|
|||
assert permissions["Inherited"] == {}
|
||||
|
||||
|
||||
def test_directory_new_reset(tmp_path):
|
||||
def test_directory_new_reset(file, tmp_path):
|
||||
"""
|
||||
Test file.directory when the directory does not exist
|
||||
Should just return "New Dir"
|
||||
|
@ -182,7 +159,7 @@ def test_directory_new_reset(tmp_path):
|
|||
assert permissions == expected
|
||||
|
||||
|
||||
def test_directory_new_reset_no_inherit(tmp_path):
|
||||
def test_directory_new_reset_no_inherit(file, tmp_path):
|
||||
"""
|
||||
Test file.directory when the directory does not exist
|
||||
Should just return "New Dir"
|
||||
|
@ -219,7 +196,7 @@ def test_directory_new_reset_no_inherit(tmp_path):
|
|||
assert permissions == expected
|
||||
|
||||
|
||||
def test_directory_existing(tmp_path):
|
||||
def test_directory_existing(file, tmp_path):
|
||||
path = str(tmp_path)
|
||||
ret = file.directory(
|
||||
name=path,
|
||||
|
@ -293,7 +270,7 @@ def test_directory_existing(tmp_path):
|
|||
assert permissions == expected
|
||||
|
||||
|
||||
def test_directory_existing_existing_user(tmp_path):
|
||||
def test_directory_existing_existing_user(file, tmp_path):
|
||||
path = str(tmp_path)
|
||||
win_dacl.set_permissions(
|
||||
obj_name=path,
|
||||
|
@ -374,7 +351,7 @@ def test_directory_existing_existing_user(tmp_path):
|
|||
assert permissions == expected
|
||||
|
||||
|
||||
def test_directory_existing_no_inherit(tmp_path):
|
||||
def test_directory_existing_no_inherit(file, tmp_path):
|
||||
path = str(tmp_path)
|
||||
ret = file.directory(
|
||||
name=path,
|
||||
|
@ -398,7 +375,7 @@ def test_directory_existing_no_inherit(tmp_path):
|
|||
assert permissions["Inherited"] == {}
|
||||
|
||||
|
||||
def test_directory_existing_reset(tmp_path):
|
||||
def test_directory_existing_reset(file, tmp_path):
|
||||
path = str(tmp_path)
|
||||
win_dacl.set_permissions(
|
||||
obj_name=path,
|
||||
|
@ -462,7 +439,7 @@ def test_directory_existing_reset(tmp_path):
|
|||
assert permissions == expected
|
||||
|
||||
|
||||
def test_directory_existing_reset_no_inherit(tmp_path):
|
||||
def test_directory_existing_reset_no_inherit(file, tmp_path):
|
||||
path = str(tmp_path)
|
||||
ret = file.directory(
|
||||
name=path,
|
||||
|
|
|
@ -49,7 +49,6 @@ def configure_loader_modules():
|
|||
"dacl.check_perms": win_dacl.check_perms,
|
||||
},
|
||||
},
|
||||
win_dacl: {"__opts__": {"test": False}},
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import pytest
|
||||
|
||||
import salt.utils.win_dacl as win_dacl
|
||||
from tests.support.mock import patch
|
||||
|
||||
pytestmark = [
|
||||
pytest.mark.windows_whitelisted,
|
||||
|
@ -819,22 +818,22 @@ def test_check_perms(test_file):
|
|||
|
||||
|
||||
def test_check_perms_test_true(test_file):
|
||||
with patch.dict(win_dacl.__opts__, {"test": True}):
|
||||
result = win_dacl.check_perms(
|
||||
obj_name=str(test_file),
|
||||
obj_type="file",
|
||||
ret=None,
|
||||
owner="Users",
|
||||
grant_perms={"Backup Operators": {"perms": "read"}},
|
||||
deny_perms={
|
||||
"NETWORK SERVICE": {
|
||||
"perms": ["delete", "set_value", "write_dac", "write_owner"]
|
||||
},
|
||||
"Backup Operators": {"perms": ["delete"]},
|
||||
result = win_dacl.check_perms(
|
||||
obj_name=str(test_file),
|
||||
obj_type="file",
|
||||
ret=None,
|
||||
owner="Users",
|
||||
grant_perms={"Backup Operators": {"perms": "read"}},
|
||||
deny_perms={
|
||||
"NETWORK SERVICE": {
|
||||
"perms": ["delete", "set_value", "write_dac", "write_owner"]
|
||||
},
|
||||
inheritance=True,
|
||||
reset=False,
|
||||
)
|
||||
"Backup Operators": {"perms": ["delete"]},
|
||||
},
|
||||
inheritance=True,
|
||||
reset=False,
|
||||
test_mode=True,
|
||||
)
|
||||
|
||||
expected = {
|
||||
"changes": {
|
||||
|
|
|
@ -3,7 +3,6 @@ from saltfactories.utils import random_string
|
|||
|
||||
import salt.utils.win_dacl as win_dacl
|
||||
import salt.utils.win_reg as win_reg
|
||||
from tests.support.mock import patch
|
||||
|
||||
pytestmark = [
|
||||
pytest.mark.windows_whitelisted,
|
||||
|
@ -12,15 +11,6 @@ pytestmark = [
|
|||
]
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def configure_loader_modules(minion_opts):
|
||||
return {
|
||||
win_dacl: {
|
||||
"__opts__": minion_opts,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def fake_key():
|
||||
return "SOFTWARE\\{}".format(random_string("SaltTesting-", lowercase=False))
|
||||
|
@ -433,22 +423,22 @@ def test_check_perms(reg_key):
|
|||
|
||||
|
||||
def test_check_perms_test_true(reg_key):
|
||||
with patch.dict(win_dacl.__opts__, {"test": True}):
|
||||
result = win_dacl.check_perms(
|
||||
obj_name=reg_key,
|
||||
obj_type="registry",
|
||||
ret=None,
|
||||
owner="Users",
|
||||
grant_perms={"Backup Operators": {"perms": "read"}},
|
||||
deny_perms={
|
||||
"NETWORK SERVICE": {
|
||||
"perms": ["delete", "set_value", "write_dac", "write_owner"]
|
||||
},
|
||||
"Backup Operators": {"perms": ["delete"]},
|
||||
result = win_dacl.check_perms(
|
||||
obj_name=reg_key,
|
||||
obj_type="registry",
|
||||
ret=None,
|
||||
owner="Users",
|
||||
grant_perms={"Backup Operators": {"perms": "read"}},
|
||||
deny_perms={
|
||||
"NETWORK SERVICE": {
|
||||
"perms": ["delete", "set_value", "write_dac", "write_owner"]
|
||||
},
|
||||
inheritance=True,
|
||||
reset=False,
|
||||
)
|
||||
"Backup Operators": {"perms": ["delete"]},
|
||||
},
|
||||
inheritance=True,
|
||||
reset=False,
|
||||
test_mode=True,
|
||||
)
|
||||
|
||||
expected = {
|
||||
"changes": {
|
||||
|
|
|
@ -57,7 +57,10 @@ def configure_loader_modules():
|
|||
ret.update(
|
||||
{
|
||||
win_dacl: {"__opts__": opts},
|
||||
win_file: {"__utils__": {"dacl.check_perms": win_dacl.check_perms}},
|
||||
win_file: {
|
||||
"__utils__": {"dacl.check_perms": win_dacl.check_perms},
|
||||
"__opts__": opts,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
|
|
|
@ -97,7 +97,7 @@ def test_get_pgid():
|
|||
something
|
||||
"""
|
||||
result = win_file.get_pgid(os.getenv("COMSPEC"))
|
||||
assert not result == ""
|
||||
assert result != ""
|
||||
|
||||
|
||||
def test_group_to_gid():
|
||||
|
@ -144,7 +144,7 @@ def test_get_uid():
|
|||
something
|
||||
"""
|
||||
result = win_file.get_uid(os.getenv("WINDIR"))
|
||||
assert not result == ""
|
||||
assert result != ""
|
||||
|
||||
|
||||
def test_get_uid_error():
|
||||
|
@ -259,7 +259,7 @@ def test_get_user():
|
|||
something
|
||||
"""
|
||||
result = win_file.get_user(os.getenv("WINDIR"))
|
||||
assert not result == ""
|
||||
assert result != ""
|
||||
|
||||
|
||||
def test_get_user_error():
|
||||
|
|
|
@ -4,7 +4,6 @@ import salt.modules.file as file_
|
|||
import salt.modules.heat as heat
|
||||
import salt.modules.win_file as win_file
|
||||
import salt.utils.platform
|
||||
import salt.utils.win_dacl as dacl
|
||||
from tests.support.mixins import LoaderModuleMockMixin
|
||||
from tests.support.mock import MagicMock, patch
|
||||
from tests.support.runtests import RUNTIME_VARS
|
||||
|
@ -78,10 +77,7 @@ class HeatTestCase(TestCase, LoaderModuleMockMixin):
|
|||
"config.backup_mode": MagicMock(return_value=False),
|
||||
},
|
||||
},
|
||||
win_file: {
|
||||
"__utils__": {"dacl.check_perms": salt.utils.win_dacl.check_perms}
|
||||
},
|
||||
dacl: {"__opts__": {"test": False}},
|
||||
win_file: {"__opts__": {"test": False}},
|
||||
}
|
||||
|
||||
def setUp(self):
|
||||
|
|
|
@ -5,7 +5,6 @@ import salt.modules.heat
|
|||
import salt.modules.win_file as win_file
|
||||
import salt.states.heat as heat
|
||||
import salt.utils.platform
|
||||
import salt.utils.win_dacl as dacl
|
||||
import tests.unit.modules.test_heat
|
||||
from tests.support.mixins import LoaderModuleMockMixin
|
||||
from tests.support.mock import MagicMock, patch
|
||||
|
@ -38,10 +37,7 @@ class HeatTestCase(TestCase, LoaderModuleMockMixin):
|
|||
"config.backup_mode": MagicMock(return_value=False),
|
||||
},
|
||||
},
|
||||
win_file: {
|
||||
"__utils__": {"dacl.check_perms": salt.utils.win_dacl.check_perms}
|
||||
},
|
||||
dacl: {"__opts__": {"test": False}},
|
||||
win_file: {"__opts__": {"test": False}},
|
||||
}
|
||||
|
||||
def setUp(self):
|
||||
|
|
Loading…
Add table
Reference in a new issue