Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix test: tests\pytests\functional\modules\win_file\test_check_perms.py #67156

Merged
merged 2 commits into from
Jan 15, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions tests/pytests/functional/modules/win_file/test_check_perms.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
"""

import pytest
from saltfactories.utils import random_string

import salt.modules.cmdmod as cmd
import salt.modules.win_file as win_file
import salt.modules.win_useradd as win_useradd
import salt.utils.win_dacl as win_dacl
from salt.exceptions import CommandExecutionError
from tests.support.mock import patch
Expand All @@ -25,9 +28,22 @@ def configure_loader_modules():
},
"__opts__": {"test": False},
},
win_useradd: {
"__salt__": {
"cmd.run_all": cmd.run_all,
},
},
}


@pytest.fixture
def temp_account():
user_name = random_string("test-account-", uppercase=False)
with pytest.helpers.create_account(username=user_name) as account:
win_useradd.addgroup(account.username, "Users")
yield account.username


@pytest.fixture(scope="function")
def test_file():
with pytest.helpers.temp_file("win_file_test.file") as test_file:
Expand Down Expand Up @@ -184,7 +200,7 @@ def test_check_perms_inheritance_true(test_file):
assert result == expected


def test_check_perms_reset_test_true(test_file):
def test_check_perms_reset_test_true(test_file, temp_account):
"""
Test resetting perms with test=True. This shows minimal changes
"""
Expand All @@ -193,7 +209,7 @@ def test_check_perms_reset_test_true(test_file):
# Set some permissions
win_dacl.set_permissions(
obj_name=str(test_file),
principal="Administrator",
principal=temp_account,
permissions="full_control",
)
expected = {
Expand All @@ -204,7 +220,7 @@ def test_check_perms_reset_test_true(test_file):
"Users": {"permissions": "read_execute"},
},
"remove_perms": {
"Administrator": {
f"{temp_account}": {
"grant": {
"applies to": "This folder only",
"permissions": "Full control",
Expand All @@ -228,7 +244,7 @@ def test_check_perms_reset_test_true(test_file):
assert result == expected


def test_check_perms_reset(test_file):
def test_check_perms_reset(test_file, temp_account):
"""
Test resetting perms on a File
"""
Expand All @@ -237,7 +253,7 @@ def test_check_perms_reset(test_file):
# Set some permissions
win_dacl.set_permissions(
obj_name=str(test_file),
principal="Administrator",
principal=temp_account,
permissions="full_control",
)
expected = {
Expand All @@ -248,7 +264,7 @@ def test_check_perms_reset(test_file):
"Users": {"permissions": "read_execute"},
},
"remove_perms": {
"Administrator": {
f"{temp_account}": {
"grant": {
"applies to": "This folder only",
"permissions": "Full control",
Expand Down
Loading