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, generate_random_name('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))
def setUp(self): ''' Sets up the test requirements ''' super(GCETest, self).setUp() # check if appropriate cloud provider and profile files are present profile_str = 'gce-config:' provider = 'gce' providers = self.run_cloud('--list-providers') # Create the cloud instance name to be used throughout the tests self.INSTANCE_NAME = generate_random_name('cloud-test-').lower() if profile_str not in providers: self.skipTest( 'Configuration file for {0} was not found. Check {0}.conf files ' 'in tests/integration/files/conf/cloud.*.d/ to run these tests.' .format(provider)) # check if project, service_account_email_address, service_account_private_key # and provider are present path = os.path.join(RUNTIME_VARS.FILES, 'conf', 'cloud.providers.d', provider + '.conf') config = cloud_providers_config(path) project = config['gce-config']['gce']['project'] service_account_email_address = config['gce-config']['gce'][ 'service_account_email_address'] service_account_private_key = config['gce-config']['gce'][ 'service_account_private_key'] conf_items = [ project, service_account_email_address, service_account_private_key ] missing_conf_item = []
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 = generate_random_name( 'cloud-test-{:-<3}-'.format(subclass[:3])).lower() return self._instance_name
from tests.support.paths import FILES from tests.support.unit import skipIf from tests.support.helpers import expensiveTest, generate_random_name # Import Salt Libs from salt.config import cloud_providers_config # Import Third-Party Libs try: from oneandone.client import OneAndOneService # pylint: disable=unused-import HAS_ONEANDONE = True except ImportError: HAS_ONEANDONE = False # Create the cloud instance name to be used throughout the tests INSTANCE_NAME = generate_random_name('CLOUD-TEST-') PROVIDER_NAME = 'oneandone' DRIVER_NAME = 'oneandone' @skipIf(HAS_ONEANDONE is False, 'salt-cloud requires >= 1and1 1.2.0') class OneAndOneTest(ShellCase): ''' Integration tests for the 1and1 cloud provider ''' @expensiveTest def setUp(self): ''' Sets up the test requirements ''' super(OneAndOneTest, self).setUp()
from tests.support.mock import NO_MOCK, NO_MOCK_REASON from tests.support.unit import TestCase, skipIf # Import Salt Libs import salt.utils.platform import salt.utils.win_dacl as win_dacl import salt.utils.win_reg as win_reg try: import pywintypes import win32security HAS_WIN32 = True except ImportError: HAS_WIN32 = False FAKE_KEY = 'SOFTWARE\\{0}'.format(generate_random_name('SaltTesting-')) @skipIf(NO_MOCK, NO_MOCK_REASON) @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))
import salt.utils.win_reg as win_reg # Import Salt Testing Libs from tests.support.helpers import destructiveTest, generate_random_name, patch from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import TestCase, skipIf try: import pywintypes import win32security HAS_WIN32 = True except ImportError: HAS_WIN32 = False FAKE_KEY = "SOFTWARE\\{0}".format(generate_random_name("SaltTesting-")) @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.helpers import destructiveTest, generate_random_name 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 = "\\".join(["SOFTWARE", generate_random_name("SaltTesting-")]) @skipIf(not HAS_WIN32, "Tests require win32 libraries") class WinFunctionsTestCase(TestCase, LoaderModuleMockMixin): """ Test cases for salt.modules.reg """ def setup_loader_modules(self): return { reg: { "__utils__": { "reg.delete_value": salt.utils.win_reg.delete_value, "reg.delete_key_recursive": salt.utils.win_reg.delete_key_recursive, "reg.key_exists": salt.utils.win_reg.key_exists,
# Import Salt Libs import salt.utils.stringutils import salt.utils.win_reg as win_reg from salt.exceptions import CommandExecutionError from salt.ext import six 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 = '\\'.join(['SOFTWARE', generate_random_name('SaltTesting-')]) @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):