def setup_teardown_vars(salt_call_cli): user_name = random_string("RS-", lowercase=False) group_name = random_string("RS-", lowercase=False) try: yield user_name, group_name finally: salt_call_cli.run("user.delete", user_name, True, True) salt_call_cli.run("group.delete", group_name) salt_call_cli.run("lgpo.set", "computer_policy={'Minimum Password Length': 0}")
def setUp(self): """ Get current settings """ self._password = self.run_function("shadow.gen_password", ["Password1234"]) if "ERROR" in self._password: self.fail("Failed to generate password: {}".format(self._password)) super().setUp() self._no_user = random_string("tu-", uppercase=False) self._test_user = random_string("tu-", uppercase=False) self._password = salt.modules.linux_shadow.gen_password("Password1234")
def setUp(self): """ Get current settings """ super(GroupModuleTest, self).setUp() self._user = random_string("tg-", uppercase=False) self._user1 = random_string("tg-", uppercase=False) self._no_user = random_string("tg-", uppercase=False) self._group = random_string("tg-", uppercase=False) self._no_group = random_string("tg-", uppercase=False) _gid = _new_gid = None if not salt.utils.platform.is_windows(): _gid = 64989 _new_gid = 64998 self._gid = _gid self._new_gid = _new_gid
def setUp(self): """ Get current settings """ super(GroupModuleTest, self).setUp() self._user = random_string("tg-", uppercase=False) self._user1 = random_string("tg-", uppercase=False) self._no_user = random_string("tg-", uppercase=False) self._group = random_string("tg-", uppercase=False) self._no_group = random_string("tg-", uppercase=False) self.os_grain = self.run_function("grains.item", ["kernel"]) self._gid = 64989 if "Windows" not in self.os_grain["kernel"] else None self._new_gid = 64998 if "Windows" not in self.os_grain[ "kernel"] else None if self.os_grain["kernel"] not in ("Linux", "Windows"): self.skipTest("Test not applicable to '{kernel}' kernel".format( **self.os_grain))
def instance_name(self): if not hasattr(self, "_instance_name"): # Create the cloud instance name to be used throughout the tests subclass = self.__class__.__name__.strip("Test") # Use the first three letters of the subclass, fill with '-' if too short self._instance_name = random_string("cloud-test-{:-<3}-".format( subclass[:3]), uppercase=False).lower() return self._instance_name
def test_groups_includes_primary(setup_teardown_vars, grains, salt_call_cli): # Let's create a user, which usually creates the group matching the # name uname = random_string("RS-", lowercase=False) ret = salt_call_cli.run("user.add", uname) if ret.json is False: # Skip because creating is not what we're testing here salt_call_cli.run("user.delete", [uname, True, True]) pytest.skip("Failed to create user") try: uinfo = salt_call_cli.run("user.info", uname) if grains["os_family"] in ("Suse", ): assert "users" in uinfo.json["groups"] else: assert uname in uinfo.json["groups"] # This uid is available, store it uid = uinfo.json["uid"] salt_call_cli.run("user.delete", uname, True, True) # Now, a weird group id gname = random_string("RS-", lowercase=False) ret = salt_call_cli.run("group.add", gname) if ret.json is False: salt_call_cli.run("group.delete", gname, True, True) pytest.skip("Failed to create group") ginfo = salt_call_cli.run("group.info", gname) ginfo = ginfo.json # And create the user with that gid ret = salt_call_cli.run("user.add", uname, uid, ginfo["gid"]) if ret.json is False: # Skip because creating is not what we're testing here salt_call_cli.run("user.delete", [uname, True, True]) pytest.skip("Failed to create user") uinfo = salt_call_cli.run("user.info", uname) assert gname in uinfo.json["groups"] except AssertionError: pytest.raises(salt_call_cli.run("user.delete", [uname, True, True]))
def test_groups_includes_primary(self, grains): # Let's create a user, which usually creates the group matching the # name uname = random_string("RS-", lowercase=False) if self.run_function("user.add", [uname]) is not True: # Skip because creating is not what we're testing here self.run_function("user.delete", [uname, True, True]) self.skipTest("Failed to create user") try: uinfo = self.run_function("user.info", [uname]) if grains["os_family"] in ("Suse", ): self.assertIn("users", uinfo["groups"]) else: self.assertIn(uname, uinfo["groups"]) # This uid is available, store it uid = uinfo["uid"] self.run_function("user.delete", [uname, True, True]) # Now, a weird group id gname = random_string("RS-", lowercase=False) if self.run_function("group.add", [gname]) is not True: self.run_function("group.delete", [gname, True, True]) self.skipTest("Failed to create group") ginfo = self.run_function("group.info", [gname]) # And create the user with that gid if self.run_function("user.add", [uname, uid, ginfo["gid"]]) is False: # Skip because creating is not what we're testing here self.run_function("user.delete", [uname, True, True]) self.skipTest("Failed to create user") uinfo = self.run_function("user.info", [uname]) self.assertIn(gname, uinfo["groups"]) except AssertionError: self.run_function("user.delete", [uname, True, True]) raise
def _testSeceditPolicy( self, policy_name, policy_config, expected_regexes, cumulative_rights_assignments=True, ): """ Takes a secedit policy name and config and validates that the expected output is returned from secedit policy_name name of the secedit policy to configure policy_config the configuration of the policy expected_regexes the expected regexes to be found in the secedit output file """ ret = self.run_function( "lgpo.set_computer_policy", (policy_name, policy_config), cumulative_rights_assignments=cumulative_rights_assignments, ) self.assertTrue(ret) secedit_output_file = os.path.join( RUNTIME_VARS.TMP, random_string("secedit-output-") ) secedit_output = self.run_function( "cmd.run", (), cmd="secedit /export /cfg {0}".format(secedit_output_file) ) secedit_file_content = None if secedit_output: with io.open(secedit_output_file, encoding="utf-16") as _reader: secedit_file_content = _reader.read() for expected_regex in expected_regexes: match = re.search( expected_regex, secedit_file_content, re.IGNORECASE | re.MULTILINE ) self.assertIsNotNone( match, 'Failed validating policy "{0}" configuration, regex "{1}" not found in secedit output'.format( policy_name, expected_regex ), )
import salt.utils.win_reg as win_reg from salt.exceptions import CommandExecutionError from tests.support.helpers import TstSuiteLoggingHandler, destructiveTest, random_string from tests.support.mixins import LoaderModuleMockMixin from tests.support.mock import patch from tests.support.unit import TestCase, skipIf try: import pywintypes import win32security HAS_WIN32 = True except ImportError: HAS_WIN32 = False FAKE_KEY = "SOFTWARE\\{}".format(random_string("SaltTesting-", lowercase=False)) @skipIf(not HAS_WIN32, "Requires pywin32") @skipIf(not salt.utils.platform.is_windows(), "System is not Windows") class WinDaclTestCase(TestCase): """ Test cases for salt.utils.win_dacl in the registry """ def test_get_sid_string(self): """ Validate getting a pysid object from a name """ sid_obj = win_dacl.get_sid("Administrators") self.assertTrue(isinstance(sid_obj, pywintypes.SIDType))
from tests.support.case import ModuleCase from tests.support.helpers import ( destructiveTest, flaky, random_string, runs_on, skip_if_binaries_missing, skip_if_not_root, ) from tests.support.unit import skipIf log = logging.getLogger(__name__) SET_COMPUTER_NAME = random_string("RS-", lowercase=False) SET_SUBNET_NAME = random_string("RS-", lowercase=False) @skip_if_not_root @flaky(attempts=10) @runs_on(kernel="Darwin") @skip_if_binaries_missing("systemsetup") class MacSystemModuleTest(ModuleCase): """ Validate the mac_system module """ ATRUN_ENABLED = False REMOTE_LOGIN_ENABLED = False REMOTE_EVENTS_ENABLED = False
""" :codeauthor: Nicole Thomas <*****@*****.**> """ import os import pytest import salt.utils.files from salt.exceptions import CommandExecutionError from tests.support.case import ModuleCase from tests.support.helpers import random_string, runs_on # Create user strings for tests ADD_USER = random_string("RS-", lowercase=False) DEL_USER = random_string("RS-", lowercase=False) PRIMARY_GROUP_USER = random_string("RS-", lowercase=False) CHANGE_USER = random_string("RS-", lowercase=False) @pytest.mark.skip_if_not_root @runs_on(kernel="Darwin") @pytest.mark.destructive_test class MacUserModuleTest(ModuleCase): """ Integration tests for the mac_user module """ def setUp(self): """ Sets up test requirements """
""" integration tests for mac_shadow """ import datetime import pytest from tests.support.case import ModuleCase from tests.support.helpers import random_string, runs_on TEST_USER = random_string("RS-", lowercase=False) NO_USER = random_string("RS-", lowercase=False) @runs_on(kernel="Darwin") @pytest.mark.skip_if_binaries_missing("dscl", "pwpolicy") @pytest.mark.skip_if_not_root class MacShadowModuleTest(ModuleCase): """ Validate the mac_shadow module """ def setUp(self): """ Get current settings """ self.run_function("user.add", [TEST_USER]) def tearDown(self): """ Reset to original settings """
""" :codeauthor: Nicole Thomas <*****@*****.**> """ from salt.exceptions import CommandExecutionError from tests.support.case import ModuleCase from tests.support.helpers import ( destructiveTest, random_string, runs_on, skip_if_not_root, slowTest, ) # Create group name strings for tests ADD_GROUP = random_string("RS-", lowercase=False) DEL_GROUP = random_string("RS-", lowercase=False) CHANGE_GROUP = random_string("RS-", lowercase=False) ADD_USER = random_string("RS-", lowercase=False) REP_USER_GROUP = random_string("RS-", lowercase=False) @destructiveTest @skip_if_not_root @runs_on(kernel="Darwin") class MacGroupModuleTest(ModuleCase): """ Integration tests for the mac_group module """ def setUp(self):
def setUp(self): self.user_name = random_string("RS-", lowercase=False) self.group_name = random_string("RS-", lowercase=False)
from tests.support.mixins import LoaderModuleMockMixin from tests.support.mock import MagicMock, patch from tests.support.unit import TestCase, skipIf try: import win32api HAS_WIN32 = True except ImportError: HAS_WIN32 = False UNICODE_KEY = "Unicode Key \N{TRADE MARK SIGN}" UNICODE_VALUE = ("Unicode Value " "\N{COPYRIGHT SIGN},\N{TRADE MARK SIGN},\N{REGISTERED SIGN}") FAKE_KEY = "SOFTWARE\\{}".format( random_string("HubblestackTesting-", lowercase=False)) @skipIf(not HAS_WIN32, "Tests require win32 libraries") class WinFunctionsTestCase(TestCase, LoaderModuleMockMixin): """ Test cases for hubblestack.modules.reg """ def setup_loader_modules(self): return { reg: { "__utils__": { "reg.read_value": hubblestack.utils.win_reg.read_value, } } }
from tests.support.helpers import destructiveTest, random_string from tests.support.mock import MagicMock, patch from tests.support.unit import TestCase, skipIf try: import win32api HAS_WIN32 = True except ImportError: HAS_WIN32 = False UNICODE_KEY = "Unicode Key \N{TRADE MARK SIGN}" UNICODE_VALUE = ("Unicode Value " "\N{COPYRIGHT SIGN},\N{TRADE MARK SIGN},\N{REGISTERED SIGN}") FAKE_KEY = "SOFTWARE\\{0}".format( random_string("SaltTesting-", lowercase=False)) @skipIf(not HAS_WIN32, "Tests require win32 libraries") class WinFunctionsTestCase(TestCase): """ Test cases for salt.utils.win_reg """ def test_broadcast_change_success(self): """ Tests the broadcast_change function """ with patch("win32gui.SendMessageTimeout", return_value=("", 0)): self.assertTrue(win_reg.broadcast_change()) def test_broadcast_change_fail(self):
# -*- coding: utf-8 -*- """ :codeauthor: Li Kexian <*****@*****.**> """ from __future__ import absolute_import, print_function, unicode_literals import os from salt.config import cloud_providers_config from tests.support.case import ShellCase from tests.support.helpers import expensiveTest, random_string from tests.support.runtests import RUNTIME_VARS # Create the cloud instance name to be used throughout the tests INSTANCE_NAME = random_string("CLOUD-TEST-", lowercase=False) PROVIDER_NAME = "tencentcloud" @expensiveTest class TencentCloudTest(ShellCase): """ Integration tests for the Tencent Cloud cloud provider in Salt-Cloud """ def setUp(self): """ Sets up the test requirements """ super(TencentCloudTest, self).setUp() # check if appropriate cloud provider and profile files are present