本文整理汇总了Python中src.stonix_resources.CommandHelper.CommandHelper.executeCommand方法的典型用法代码示例。如果您正苦于以下问题:Python CommandHelper.executeCommand方法的具体用法?Python CommandHelper.executeCommand怎么用?Python CommandHelper.executeCommand使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类src.stonix_resources.CommandHelper.CommandHelper
的用法示例。
在下文中一共展示了CommandHelper.executeCommand方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: zzzTestRuleNoDirectRootLogin
# 需要导入模块: from src.stonix_resources.CommandHelper import CommandHelper [as 别名]
# 或者: from src.stonix_resources.CommandHelper.CommandHelper import executeCommand [as 别名]
class zzzTestRuleNoDirectRootLogin(RuleTest):
def setUp(self):
RuleTest.setUp(self)
self.rule = NoDirectRootLogin(self.config,
self.environ,
self.logdispatch,
self.statechglogger)
self.rulename = self.rule.rulename
self.rulenumber = self.rule.rulenumber
self.checkUndo = True
self.ch = CommandHelper(self.logdispatch)
self.securettypath = "/etc/securetty"
def runTest(self):
self.simpleRuleTest()
def setConditionsForRule(self):
'''
Configure system to fail before the unit test
@param self: essential if you override this definition
@return: boolean - If successful True; If failure False
@author: Brandon R. Gonzales
'''
success = True
if os.path.exists(self.securettypath):
cmd = ["rm", self.securettypath]
self.ch.executeCommand(cmd)
return success
示例2: zzzTestRuleEncryptSwap
# 需要导入模块: from src.stonix_resources.CommandHelper import CommandHelper [as 别名]
# 或者: from src.stonix_resources.CommandHelper.CommandHelper import executeCommand [as 别名]
class zzzTestRuleEncryptSwap(RuleTest):
def setUp(self):
RuleTest.setUp(self)
self.rule = EncryptSwap(self.config,
self.environ,
self.logdispatch,
self.statechglogger)
self.rulename = self.rule.rulename
self.rulenumber = self.rule.rulenumber
self.ch = CommandHelper(self.logdispatch)
def tearDown(self):
pass
def runTest(self):
self.simpleRuleTest()
def setConditionsForRule(self):
'''
This method runs the following command to make sure system is in a
non compliant state before rule runs:
sudo defaults write /Library/Preferences/com.apple.virtualMemory
UseEncryptedSwap -bool no
@author: dwalker
@return: bool - True if successful, False if not
'''
cmd = ["/usr/bin/defaults", "write",
"/Library/Preferences/com.apple.virtualMemory", "-bool", "no"]
if self.ch.executeCommand(cmd):
return True
else:
return False
示例3: zzzTestFrameworkCommandHelper
# 需要导入模块: from src.stonix_resources.CommandHelper import CommandHelper [as 别名]
# 或者: from src.stonix_resources.CommandHelper.CommandHelper import executeCommand [as 别名]
class zzzTestFrameworkCommandHelper(unittest.TestCase):
'''
Perform tests on different parts of the functionality for framework CommandHelper
@param unittest.TestCase: unittest TestCase class inheritance object reference
@author: ekkehard
@change: Breen Malmberg - 04/11/2018 - removed assertion tests -
you can't test for exception assertions in code that is wrapped by try
except because the try except intercepts the exception and throws it
and it never gets back to the assertraises call (see tf ticket for documentation)
'''
def setUp(self):
'''
'''
self.enviro = Environment()
self.enviro.setdebugmode(True)
self.logger = LogDispatcher(self.enviro)
self.commandhelper = CommandHelper(self.logger)
def tearDown(self):
'''
'''
pass
def testExecuteValidCommand(self):
'''
'''
self.assertTrue(self.commandhelper.executeCommand("ls -l /"),
"Execute Valid Command string Failed!")
self.assertTrue(self.commandhelper.executeCommand(["ls", "-l", "/"]),
"Execute Valid Command List Failed!")
def testSetLogPriority(self):
'''
'''
self.assertTrue(self.commandhelper.setLogPriority(LogPriority.INFO),
"Execute setLogPriority(0) Command string Failed!")
self.assertTrue(self.commandhelper.executeCommand(["ls", "-l", "/"]),
"Execute commandhelper.executeCommand(['ls','-l','/'])"
+ " Command List Failed!")
示例4: zzzTestFrameworkCommandHelper
# 需要导入模块: from src.stonix_resources.CommandHelper import CommandHelper [as 别名]
# 或者: from src.stonix_resources.CommandHelper.CommandHelper import executeCommand [as 别名]
class zzzTestFrameworkCommandHelper(unittest.TestCase):
def setUp(self):
self.enviro = Environment()
self.enviro.setdebugmode(True)
self.logger = LogDispatcher(self.enviro)
self.commandhelper = CommandHelper(self.logger)
def tearDown(self):
pass
def testBlankCommand(self):
self.assertRaises(ValueError, self.commandhelper.setCommand, "")
self.assertRaises(TypeError, self.commandhelper.executeCommand, None)
self.assertRaises(ValueError, self.commandhelper.executeCommand, "")
self.assertRaises(ValueError, self.commandhelper.setCommand, [])
self.assertRaises(TypeError, self.commandhelper.executeCommand, None)
self.assertRaises(ValueError, self.commandhelper.executeCommand, [])
def testExecuteValidCommand(self):
self.assertTrue(self.commandhelper.executeCommand("ls -l /"),
"Execute Valid Command string Failed!")
self.assertTrue(self.commandhelper.executeCommand(["ls", "-l", "/"]),
"Execute Valid Command List Failed!")
def testExecuteInvalidCommand(self):
self.assertRaises(TypeError, self.commandhelper.executeCommand, 0)
self.assertRaises(TypeError, self.commandhelper.executeCommand,
['ls', 0, '/'])
def testSetLogPriority(self):
self.assertRaises(TypeError, self.commandhelper.setLogPriority, 0)
self.assertTrue(self.commandhelper.setLogPriority(LogPriority.INFO),
"Execute setLogPriority(0) Command string Failed!")
self.assertTrue(self.commandhelper.executeCommand(["ls", "-l", "/"]),
"Execute commandhelper.executeCommand(['ls','-l','/'])"
+ " Command List Failed!")
示例5: zzzTestRuleShowBluetoothIcon
# 需要导入模块: from src.stonix_resources.CommandHelper import CommandHelper [as 别名]
# 或者: from src.stonix_resources.CommandHelper.CommandHelper import executeCommand [as 别名]
class zzzTestRuleShowBluetoothIcon(RuleTest):
def setUp(self):
RuleTest.setUp(self)
self.rule = ShowBluetoothIcon(self.config,
self.environ,
self.logdispatch,
self.statechglogger)
self.rulename = self.rule.rulename
self.rulenumber = self.rule.rulenumber
self.setCheckUndo(True)
self.ch = CommandHelper(self.logdispatch)
self.dc = "/usr/bin/defaults"
def runTest(self):
# This rule is only intended to be ran in user mode
if self.environ.geteuid() != 0:
self.simpleRuleTest()
def setConditionsForRule(self):
'''
This makes sure the initial report fails by executing the following
command:
defaults -currentHost delete /Users/(username)/Library/Preferences/com.apple.systemuiserver menuExtras
@param self: essential if you override this definition
@return: boolean - If successful True; If failure False
@author: Brandon R. Gonzales
'''
success = True
if success:
user = pwd.getpwuid(os.getuid())[0]
self.systemuiserver = "/Users/" + user + "/Library/Preferences/com.apple.systemuiserver"
if os.path.exists(self.systemuiserver):
command = [self.dc, "-currentHost", "delete", self.systemuiserver, "menuExtras"]
success = self.ch.executeCommand(command)
if success:
success = self.checkReportForRule(False, True)
return success
示例6: zzzTestRuleNoCachedFDEKeys
# 需要导入模块: from src.stonix_resources.CommandHelper import CommandHelper [as 别名]
# 或者: from src.stonix_resources.CommandHelper.CommandHelper import executeCommand [as 别名]
class zzzTestRuleNoCachedFDEKeys(RuleTest):
def setUp(self):
RuleTest.setUp(self)
self.rule = NoCachedFDEKeys(self.config,
self.environ,
self.logdispatch,
self.statechglogger)
self.rulename = self.rule.rulename
self.rulenumber = self.rule.rulenumber
self.ch = CommandHelper(self.logdispatch)
def tearDown(self):
pass
def runTest(self):
self.simpleRuleTest()
def setConditionsForRule(self):
'''
Configure system for the unit test
@param self: essential if you override this definition
@return: boolean - If successful True; If failure False
@author: ekkehard j. koch
'''
success = True
cmd = "/usr/bin/pmset -a destroyfvkeyonstandby 0"
if not self.ch.executeCommand(cmd):
success = False
return success
def checkReportForRule(self, pCompliance, pRuleSuccess):
'''
check on whether report was correct
@param self: essential if you override this definition
@param pCompliance: the self.iscompliant value of rule
@param pRuleSuccess: did report run successfully
@return: boolean - If successful True; If failure False
@author: ekkehard j. koch
'''
self.logdispatch.log(LogPriority.DEBUG, "pCompliance = " +
str(pCompliance) + ".")
self.logdispatch.log(LogPriority.DEBUG, "pRuleSuccess = " +
str(pRuleSuccess) + ".")
success = True
return success
def checkFixForRule(self, pRuleSuccess):
'''
check on whether fix was correct
@param self: essential if you override this definition
@param pRuleSuccess: did report run successfully
@return: boolean - If successful True; If failure False
@author: ekkehard j. koch
'''
self.logdispatch.log(LogPriority.DEBUG, "pRuleSuccess = " +
str(pRuleSuccess) + ".")
success = True
return success
def checkUndoForRule(self, pRuleSuccess):
'''
check on whether undo was correct
@param self: essential if you override this definition
@param pRuleSuccess: did report run successfully
@return: boolean - If successful True; If failure False
@author: ekkehard j. koch
'''
self.logdispatch.log(LogPriority.DEBUG, "pRuleSuccess = " +
str(pRuleSuccess) + ".")
success = True
return success
示例7: zzzTestRuleConfigureGatekeeper
# 需要导入模块: from src.stonix_resources.CommandHelper import CommandHelper [as 别名]
# 或者: from src.stonix_resources.CommandHelper.CommandHelper import executeCommand [as 别名]
class zzzTestRuleConfigureGatekeeper(RuleTest):
def setUp(self):
RuleTest.setUp(self)
self.rule = ConfigureGatekeeper(self.config, self.environ,
self.logdispatch,
self.statechglogger)
self.rulename = self.rulename
self.rulenumber = self.rule.rulenumber
self.ch = CommandHelper(self.logdispatch)
def tearDown(self):
pass
def runTest(self):
self.simpleRuleTest()
def setConditionsForRule(self):
success = True
cmd = ["/usr/bin/profiles", "-L"]
#change this to actual gatkeeper profile number
profilenum = "C873806E-E634-4E58-B960-62817F398E11"
if self.ch.executeCommand(cmd):
output = self.ch.getOutput()
if output:
for line in output:
if re.search(profilenum, line):
cmd = ["/usr/bin/profiles", "-r", profilenum]
if not self.ch.executeCommand(cmd):
success = False
return success
def checkReportForRule(self, pCompliance, pRuleSuccess):
'''
check on whether report was correct
@param self: essential if you override this definition
@param pCompliance: the self.iscompliant value of rule
@param pRuleSuccess: did report run successfully
@return: boolean - If successful True; If failure False
@author: ekkehard j. koch
'''
self.logdispatch.log(LogPriority.DEBUG, "pCompliance = " +
str(pCompliance) + ".")
self.logdispatch.log(LogPriority.DEBUG, "pRuleSuccess = " +
str(pRuleSuccess) + ".")
success = True
return success
def checkFixForRule(self, pRuleSuccess):
'''
check on whether fix was correct
@param self: essential if you override this definition
@param pRuleSuccess: did report run successfully
@return: boolean - If successful True; If failure False
@author: ekkehard j. koch
'''
self.logdispatch.log(LogPriority.DEBUG, "pRuleSuccess = " +
str(pRuleSuccess) + ".")
success = True
return success
def checkUndoForRule(self, pRuleSuccess):
'''
check on whether undo was correct
@param self: essential if you override this definition
@param pRuleSuccess: did report run successfully
@return: boolean - If successful True; If failure False
@author: ekkehard j. koch
'''
self.logdispatch.log(LogPriority.DEBUG, "pRuleSuccess = " +
str(pRuleSuccess) + ".")
success = True
return success
示例8: zzzTestRuleDisableCamera
# 需要导入模块: from src.stonix_resources.CommandHelper import CommandHelper [as 别名]
# 或者: from src.stonix_resources.CommandHelper.CommandHelper import executeCommand [as 别名]
class zzzTestRuleDisableCamera(RuleTest):
def setUp(self):
'''
@change: Breen Malmberg - 06102015 - updated self.cmd and paths to work
with updated unit test functionality
'''
RuleTest.setUp(self)
self.rule = DisableCamera(self.config,
self.environ,
self.logdispatch,
self.statechglogger)
self.rulename = self.rule.rulename
self.rulenumber = self.rule.rulenumber
self.ch = CommandHelper(self.logdispatch)
self.cmd = 'chmod a+r '
self.paths = ['/System/Library/QuickTime/QuickTimeUSBVDCDigitizer.component/Contents/MacOS/QuickTimeUSBVDCDigitizer',
'/System/Library/PrivateFrameworks/CoreMediaIOServicesPrivate.framework/Versions/A/Resources/VDC.plugin/Contents/MacOS/VDC',
'/System/Library/PrivateFrameworks/CoreMediaIOServices.framework/Versions/A/Resources/VDC.plugin/Contents/MacOS/VDC',
'/System/Library/Frameworks/CoreMediaIO.framework/Versions/A/Resources/VDC.plugin/Contents/MacOS/VDC',
'/Library/CoreMediaIO/Plug-Ins/DAL/AppleCamera.plugin/Contents/MacOS/AppleCamera']
def tearDown(self):
pass
def runTest(self):
self.simpleRuleTest()
def setConditionsForRule(self):
'''
Configure system for the unit test
@param self: essential if you override this definition
@return: boolean - If successful True; If failure False
@author: ekkehard j. koch
@change: Breen Malmberg - 06102015 - changed this method to reflect
the new functionality of DisableCamera.py
'''
success = True
for path in self.paths:
if os.path.exists(path):
self.ch.executeCommand(self.cmd + path)
error = self.ch.getErrorString()
if error:
success = False
return success
def checkReportForRule(self, pCompliance, pRuleSuccess):
'''
check on whether report was correct
@param self: essential if you override this definition
@param pCompliance: the self.iscompliant value of rule
@param pRuleSuccess: did report run successfully
@return: boolean - If successful True; If failure False
@author: ekkehard j. koch
'''
self.logdispatch.log(LogPriority.DEBUG, "pCompliance = " + \
str(pCompliance) + ".")
self.logdispatch.log(LogPriority.DEBUG, "pRuleSuccess = " + \
str(pRuleSuccess) + ".")
success = True
return success
def checkFixForRule(self, pRuleSuccess):
'''
check on whether fix was correct
@param self: essential if you override this definition
@param pRuleSuccess: did report run successfully
@return: boolean - If successful True; If failure False
@author: ekkehard j. koch
'''
self.logdispatch.log(LogPriority.DEBUG, "pRuleSuccess = " + \
str(pRuleSuccess) + ".")
success = True
return success
def checkUndoForRule(self, pRuleSuccess):
'''
check on whether undo was correct
@param self: essential if you override this definition
@param pRuleSuccess: did report run successfully
@return: boolean - If successful True; If failure False
@author: ekkehard j. koch
'''
self.logdispatch.log(LogPriority.DEBUG, "pRuleSuccess = " + \
str(pRuleSuccess) + ".")
success = True
return success
示例9: MacOSUser
# 需要导入模块: from src.stonix_resources.CommandHelper import CommandHelper [as 别名]
# 或者: from src.stonix_resources.CommandHelper.CommandHelper import executeCommand [as 别名]
class MacOSUser(ManageUser):
"""
Class to manage users on Mac OS.
@method findUniqueUid
@method setUserShell
@method setUserComment
@method setUserUid
@method setUserPriGid
@method setUserHomeDir
@method addUserToGroup
@method rmUserFromGroup
@method setUserPassword
@method setUserLoginKeychainPassword
@method createHomeDirectory
@method rmUser
@method rmUserHome
@author: Roy Nielsen
"""
def __init__(self, userName="", userShell="/bin/bash",
userComment="", userUid=1000, userPriGid=20,
userHomeDir="/tmp", logger=False):
super(MacOSUser, self).__init__(userName, userShell,
userComment, userUid, userPriGid,
userHomeDir, logger)
self.module_version = '20160225.125554.540679'
self.dscl = "/usr/bin/dscl"
self.cmdh = CommandHelper(self.logger)
#----------------------------------------------------------------------
def createStandardUser(self, userName, password):
"""
Creates a user that has the "next" uid in line to be used, then puts
in in a group of the same id. Uses /bin/bash as the standard shell.
The userComment is left empty. Primary use is managing a user
during test automation, when requiring a "user" context.
It does not set a login keychain password as that is created on first
login to the GUI.
@author: Roy Nielsen
"""
self.createBasicUser(userName)
newUserID = self.findUniqueUid()
newUserGID = newUserID
self.setUserUid(userName, newUserID)
self.setUserPriGid(userName, newUserID)
self.setUserHomeDir(userName)
self.setUserShell(userName, "/bin/bash")
self.setUserPassword(userName, password)
#####
# Don't need to set the user login keychain password as it should be
# created on first login.
#----------------------------------------------------------------------
def setDscl(self, directory=".", action="", object="", property="", value=""):
"""
Using dscl to set a value in a directory...
@author: Roy Nielsen
"""
success = False
reterr = ""
if directory and action and object and property and value:
cmd = [self.dscl, directory, action, object, property, value]
self.cmdh.executeCommand(cmd)
output = self.cmdh.getOutput()
reterr = self.cmdh.getErrorString()
if not reterr:
success = True
else:
raise DsclError("Error trying to set a value with dscl (" + \
str(reterr).strip() + ")")
return success
def getDscl(self, directory="", action="", dirobj="", property=""):
"""
Using dscl to retrieve a value from the directory
@author: Roy Nielsen
"""
success = False
reterr = ""
retval = ""
#####
# FIRST VALIDATE INPUT!!
if isinstance(directory, basestring) and re.match("^[/\.][A-Za-z0-9/]*", directory):
success = True
else:
success = False
if isinstance(action, basestring) and re.match("^[-]*[a-z]+", action) and success:
success = True
else:
success = False
#.........这里部分代码省略.........
示例10: zzzTestRuleDisableInactiveAccounts
# 需要导入模块: from src.stonix_resources.CommandHelper import CommandHelper [as 别名]
# 或者: from src.stonix_resources.CommandHelper.CommandHelper import executeCommand [as 别名]
class zzzTestRuleDisableInactiveAccounts(RuleTest):
def setUp(self):
RuleTest.setUp(self)
self.rule = DisableInactiveAccounts(self.config,
self.environ,
self.logdispatch,
self.statechglogger)
self.rulename = self.rule.rulename
self.rulenumber = self.rule.rulenumber
self.ch = CommandHelper(self.logdispatch)
def tearDown(self):
pass
def runTest(self):
self.setConditionsForRule()
self.simpleRuleTest()
def setConditionsForRule(self):
'''
Configure system for the unit test
@param self: essential if you override this definition
@return: boolean - If successful True; If failure False
@author: Breen Malmberg
'''
success = True
return success
def test_dscl_path(self):
'''
test for valid location of dscl command path
@author: Breen Malmberg
'''
found = False
if os.path.exists('/usr/bin/dscl'):
found = True
self.assertTrue(found, True)
def test_get_users(self):
'''
test the command to get the list of users
@author: Breen Malmberg
'''
self.ch.executeCommand('/usr/bin/dscl . -ls /Users')
rc = self.ch.getReturnCode()
# rc should always be 0 after this command is run (means it ran successfully)
# however 0 is interpreted as false by python, so.. assertFalse
self.assertFalse(rc, "The return code for getting the list of users should always be 0 (success)")
def test_pwpolicy_path(self):
'''
test for valid location of pwpolicy command path
@author: Breen Malmberg
'''
found = False
if os.path.exists('/usr/bin/pwpolicy'):
found = True
self.assertTrue(found, True)
def test_initobjs(self):
'''
test whether the private method initobjs works
@author: Breen Malmberg
'''
self.rule.initobjs()
self.assertTrue(self.rule.cmdhelper, "CommandHelper object should always initialize after initobjs() is run")
def checkReportForRule(self, pCompliance, pRuleSuccess):
'''
check on whether report was correct
@param self: essential if you override this definition
@param pCompliance: the self.iscompliant value of rule
@param pRuleSuccess: did report run successfully
@return: boolean - If successful True; If failure False
@author: Breen Malmberg
'''
self.logdispatch.log(LogPriority.DEBUG, "pCompliance = " + \
str(pCompliance) + ".")
self.logdispatch.log(LogPriority.DEBUG, "pRuleSuccess = " + \
str(pRuleSuccess) + ".")
success = True
return success
def checkFixForRule(self, pRuleSuccess):
'''
check on whether fix was correct
@param self: essential if you override this definition
@param pRuleSuccess: did report run successfully
@return: boolean - If successful True; If failure False
@author: Breen Malmberg
'''
self.logdispatch.log(LogPriority.DEBUG, "pRuleSuccess = " + \
str(pRuleSuccess) + ".")
success = True
return success
#.........这里部分代码省略.........
示例11: zzzTestRuleConfigureAppleSoftwareUpdate
# 需要导入模块: from src.stonix_resources.CommandHelper import CommandHelper [as 别名]
# 或者: from src.stonix_resources.CommandHelper.CommandHelper import executeCommand [as 别名]
class zzzTestRuleConfigureAppleSoftwareUpdate(RuleTest):
def setUp(self):
RuleTest.setUp(self)
self.rule = ConfigureAppleSoftwareUpdate(self.config,
self.environ,
self.logdispatch,
self.statechglogger)
self.rulename = self.rule.rulename
self.rulenumber = self.rule.rulenumber
self.ch = CommandHelper(self.logdispatch)
self.dc = "/usr/bin/defaults"
def tearDown(self):
pass
def runTest(self):
self.simpleRuleTest()
def setConditionsForRule(self):
'''
This makes sure the intial report fails by executing the following
commands:
defaults -currentHost delete /Library/Preferences/com.apple.SoftwareUpdate CatalogURL
defaults -currentHost write /Library/Preferences/com.apple.SoftwareUpdate AutomaticDownload -bool yes
defaults -currentHost write /Library/Preferences/com.apple.SoftwareUpdate AutomaticCheckEnabled -bool yes
defaults -currentHost write /Library/Preferences/com.apple.SoftwareUpdate ConfigDataInstall -bool yes
defaults -currentHost write /Library/Preferences/com.apple.SoftwareUpdate DisableCriticalUpdateInstall -bool yes
defaults -currentHost delete /Library/Preferences/com.apple.SoftwareUpdate AllowPreReleaseInstallation
@param self: essential if you override this definition
@return: boolean - If successful True; If failure False
@author: ekkehard j. koch
'''
success = True
if success:
command = [self.dc, "-currentHost", "delete",
"/Library/Preferences/com.apple.SoftwareUpdate",
"CatalogURL"]
self.logdispatch.log(LogPriority.DEBUG, str(command))
success = self.ch.executeCommand(command)
if success:
command = [self.dc, "-currentHost", "write",
"/Library/Preferences/com.apple.SoftwareUpdate",
"AutomaticDownload", "-bool", "yes"]
self.logdispatch.log(LogPriority.DEBUG, str(command))
success = self.ch.executeCommand(command)
if success:
command = [self.dc, "-currentHost", "write",
"/Library/Preferences/com.apple.SoftwareUpdate",
"AutomaticCheckEnabled", "-bool", "yes"]
self.logdispatch.log(LogPriority.DEBUG, str(command))
success = self.ch.executeCommand(command)
if success:
command = [self.dc, "-currentHost", "write",
"/Library/Preferences/com.apple.SoftwareUpdate",
"ConfigDataInstall", "-bool", "yes"]
self.logdispatch.log(LogPriority.DEBUG, str(command))
success = self.ch.executeCommand(command)
if success:
command = [self.dc, "-currentHost", "write",
"/Library/Preferences/com.apple.SoftwareUpdate",
"DisableCriticalUpdateInstall", "-bool", "yes"]
self.logdispatch.log(LogPriority.DEBUG, str(command))
success = self.ch.executeCommand(command)
if success:
command = [self.dc, "-currentHost", "delete",
"/Library/Preferences/com.apple.SoftwareUpdate",
"AllowPreReleaseInstallation"]
self.logdispatch.log(LogPriority.DEBUG, str(command))
success = self.ch.executeCommand(command)
if success:
success = self.checkReportForRule(False, True)
return success
def checkReportForRule(self, pCompliance, pRuleSuccess):
'''
To see what happended run these commans:
defaults -currentHost read /Library/Preferences/com.apple.SoftwareUpdate CatalogURL
defaults -currentHost read /Library/Preferences/com.apple.SoftwareUpdate AutomaticDownload
defaults -currentHost read /Library/Preferences/com.apple.SoftwareUpdate AutomaticCheckEnabled
defaults -currentHost read /Library/Preferences/com.apple.SoftwareUpdate ConfigDataInstall
defaults -currentHost read /Library/Preferences/com.apple.SoftwareUpdate DisableCriticalUpdateInstall
@param self: essential if you override this definition
@return: boolean - If successful True; If failure False
@author: ekkehard j. koch
'''
self.logdispatch.log(LogPriority.DEBUG, "pCompliance = " + \
str(pCompliance) + ".")
self.logdispatch.log(LogPriority.DEBUG, "pRuleSuccess = " + \
str(pRuleSuccess) + ".")
success = True
if success:
command = [self.dc, "-currentHost", "read",
"/Library/Preferences/com.apple.SoftwareUpdate",
"CatalogURL"]
self.logdispatch.log(LogPriority.DEBUG, str(command))
success = self.ch.executeCommand(command)
if success:
command = [self.dc, "-currentHost", "read",
"/Library/Preferences/com.apple.SoftwareUpdate",
#.........这里部分代码省略.........
示例12: zzzTestRuleDisableRoot
# 需要导入模块: from src.stonix_resources.CommandHelper import CommandHelper [as 别名]
# 或者: from src.stonix_resources.CommandHelper.CommandHelper import executeCommand [as 别名]
class zzzTestRuleDisableRoot(RuleTest):
def setUp(self):
RuleTest.setUp(self)
self.rule = DisableRoot(self.config,
self.environ,
self.logdispatch,
self.statechglogger)
self.rulename = self.rule.rulename
self.rulenumber = self.rule.rulenumber
self.ch = CommandHelper(self.logdispatch)
def tearDown(self):
pass
def runTest(self):
self.simpleRuleTest()
def setConditionsForRule(self):
'''
Configure system for the unit test
@param self: essential if you override this definition
@return: boolean - If successful True; If failure False
@author: ekkehard j. koch
'''
success = True
create = ["/usr/bin/dscl",".","-create","/Users/root", "AuthenticationAuthority", "whatever"]
self.ch.executeCommand(create)
return success
def checkReportForRule(self, pCompliance, pRuleSuccess):
'''
check on whether report was correct
@param self: essential if you override this definition
@param pCompliance: the self.iscompliant value of rule
@param pRuleSuccess: did report run successfully
@return: boolean - If successful True; If failure False
@author: ekkehard j. koch
'''
self.logdispatch.log(LogPriority.DEBUG, "pCompliance = " + \
str(pCompliance) + ".")
self.logdispatch.log(LogPriority.DEBUG, "pRuleSuccess = " + \
str(pRuleSuccess) + ".")
success = True
return success
def checkFixForRule(self, pRuleSuccess):
'''
check on whether fix was correct
@param self: essential if you override this definition
@param pRuleSuccess: did report run successfully
@return: boolean - If successful True; If failure False
@author: ekkehard j. koch
'''
self.logdispatch.log(LogPriority.DEBUG, "pRuleSuccess = " + \
str(pRuleSuccess) + ".")
success = True
return success
def checkUndoForRule(self, pRuleSuccess):
'''
check on whether undo was correct
@param self: essential if you override this definition
@param pRuleSuccess: did report run successfully
@return: boolean - If successful True; If failure False
@author: ekkehard j. koch
'''
self.logdispatch.log(LogPriority.DEBUG, "pRuleSuccess = " + \
str(pRuleSuccess) + ".")
success = True
return success
示例13: zzzTestRuleAuditFirefoxUsage
# 需要导入模块: from src.stonix_resources.CommandHelper import CommandHelper [as 别名]
# 或者: from src.stonix_resources.CommandHelper.CommandHelper import executeCommand [as 别名]
class zzzTestRuleAuditFirefoxUsage(RuleTest):
def setUp(self):
RuleTest.setUp(self)
self.rule = AuditFirefoxUsage(self.config,
self.environ,
self.logdispatch,
self.statechglogger)
self.rulename = self.rule.rulename
self.rulenumber = self.rule.rulenumber
self.ch = CommandHelper(self.logdispatch)
self.ph = Pkghelper(self.logdispatch, self.environ)
self.initMozDir = False
self.moveMozDir = False
self.mozPath = "/root/.mozilla/firefox"
self.profilePath = "/root/.mozilla/firefox/profiles.ini"
def tearDown(self):
mozPath = self.mozPath
if self.initMozDir and os.path.exists(mozPath):
shutil.rmtree(mozPath)
elif self.moveMozDir:
if os.path.exists(mozPath):
shutil.rmtree(mozPath)
if os.path.exists(mozPath + ".stonixtmp"):
os.rename(mozPath + ".stonixtmp", mozPath)
def runTest(self):
profilePath = self.profilePath
if self.ph.check("firefox"):
self.browser = "/usr/bin/firefox"
self.setConditionsForRule()
# setConditionsForRule will not work on a remote terminal. If the
# path doesn't exist, we will skip the test.
if os.path.exists(profilePath):
self.assertFalse(self.rule.report(), "Report was not false " +
"after test conditions were set")
else:
self.logdispatch.log(LogPriority.DEBUG,
"Firefox directory was not created. " +
"Skipping test.")
elif self.ph.check("iceweasel"):
self.browser = "/usr/bin/iceweasel"
self.setConditionsForRule()
# setConditionsForRule will not work on a remote terminal. If the
# path doesn't exist, we will skip the test.
if os.path.exists(profilePath):
self.assertFalse(self.rule.report(), "Report was not false " +
"after test conditions were set")
else:
self.logdispatch.log(LogPriority.DEBUG,
"Firefox directory was not created. " +
"Skipping test.")
else:
debug = "Firefox not installed. Unit test will not make " + \
"any changes."
self.logdispatch.log(LogPriority.DEBUG, debug)
return True
def setConditionsForRule(self):
'''
Configure system for the unit test
@param self: essential if you override this definition
@return: boolean - If successful True; If failure False
@author: Eric Ball
'''
success = True
browser = self.browser
mozPath = self.mozPath
if not os.path.exists(mozPath):
self.ch.wait = False
command = [browser, "google.com"]
self.ch.executeCommand(command)
sleep(15)
self.initMozDir = True
else:
self.ch.wait = False
os.rename(mozPath, mozPath + ".stonixtmp")
command = [browser, "google.com"]
self.ch.executeCommand(command)
sleep(15)
self.moveMozDir = True
command = ["/usr/bin/killall", "-q", "-u", "root", browser]
self.ch.executeCommand(command)
return success
def checkReportForRule(self, pCompliance, pRuleSuccess):
'''
check on whether report was correct
@param self: essential if you override this definition
@param pCompliance: the self.iscompliant value of rule
@param pRuleSuccess: did report run successfully
@return: boolean - If successful True; If failure False
@author: ekkehard j. koch
'''
self.logdispatch.log(LogPriority.DEBUG, "pCompliance = " +
str(pCompliance) + ".")
#.........这里部分代码省略.........
示例14: zzzTestRuleConfigureLinuxFirewall
# 需要导入模块: from src.stonix_resources.CommandHelper import CommandHelper [as 别名]
# 或者: from src.stonix_resources.CommandHelper.CommandHelper import executeCommand [as 别名]
class zzzTestRuleConfigureLinuxFirewall(RuleTest):
def setUp(self):
RuleTest.setUp(self)
self.rule = ConfigureLinuxFirewall(self.config,
self.environ,
self.logdispatch,
self.statechglogger)
self.rulename = self.rule.rulename
self.rulenumber = self.rule.rulenumber
self.logger = self.logdispatch
self.ch = CommandHelper(self.logger)
self.servicehelper = ServiceHelper(self.environ, self.logger)
self.checkUndo = True
self.isfirewalld = False
self.isufw = False
if os.path.exists('/bin/firewall-cmd'):
self.isfirewalld = True
if os.path.exists('/usr/sbin/ufw'):
self.isufw = True
# mostly pertains to RHEL6, Centos6
self.iptables = "/usr/sbin/iptables"
if not os.path.exists(self.iptables):
self.iptables = '/sbin/iptables'
self.ip6tables = "/usr/sbin/ip6tables"
if not os.path.exists(self.ip6tables):
self.ip6tables = '/sbin/ip6tables'
if os.path.exists("/usr/sbin/iptables-restore"):
self.iprestore = "/usr/sbin/iptables-restore"
elif os.path.exists("/sbin/iptables-restore"):
self.iprestore = "/sbin/iptables-restore"
if os.path.exists("/usr/sbin/ip6tables-restore"):
self.ip6restore = "/usr/sbin/ip6tables-restore"
elif os.path.exists("/sbin/ip6tables-restore"):
self.ip6restore = "/sbin/ip6tables-restore"
self.scriptType = ""
def tearDown(self):
pass
def runTest(self):
self.simpleRuleTest()
def setConditionsForRule(self):
'''
Configure system for the unit test
@param self: essential if you override this definition
@return: boolean - If successful True; If failure False
@author: ekkehard j. koch
'''
success = True
self.detailedresults = ""
self.iptScriptPath = ""
scriptExists = ""
debug = ""
if self.isfirewalld:
if self.servicehelper.auditService('firewalld.service'):
if not self.servicehelper.disableService('firewalld.service'):
success = False
if self.isufw:
cmdufw = '/usr/sbin/ufw status'
if not self.ch.executeCommand(cmdufw):
debug = "Unable to run ufw status command in unit test\n"
self.logger.log(LogPriority.DEBUG, debug)
success = False
else:
outputufw = self.ch.getOutputString()
if re.search('Status: active', outputufw):
ufwcmd = '/usr/sbin/ufw --force disable'
if not self.ch.executeCommand(ufwcmd):
debug = "Unable to disable firewall for unit test\n"
self.logger.log(LogPriority.DEBUG, debug)
success = False
else:
cmdufw = "/usr/sbin/ufw status verbose"
if not self.ch.executeCommand(cmdufw):
debug = "Unable to get verbose status for unit test\n"
self.logger.log(LogPriority.DEBUG, debug)
success = False
else:
outputfw = self.cmdhelper.getOutputString()
if re.search("Default\:\ deny\ \(incoming\)", outputfw):
ufwcmd = "/usr/sbin/ufw default allow incoming"
if not self.ch.executeCommand(ufwcmd):
debug = "Unable to set allow status for unit test\n"
self.logger.log(LogPriority.DEBUG, debug)
success = False
elif os.path.exists('/usr/bin/system-config-firewall') or \
os.path.exists('/usr/bin/system-config-firewall-tui'):
print "system-config-firewall commands exist\n"
fwpath = '/etc/sysconfig/system-config-firewall'
iptpath = '/etc/sysconfig/iptables'
ip6tpath = '/etc/sysconfig/ip6tables'
if os.path.exists(fwpath):
os.remove(fwpath)
if os.path.exists(iptpath):
os.remove(iptpath)
if os.path.exists(ip6tpath):
#.........这里部分代码省略.........
示例15: zzzTestRuleSetSSCorners
# 需要导入模块: from src.stonix_resources.CommandHelper import CommandHelper [as 别名]
# 或者: from src.stonix_resources.CommandHelper.CommandHelper import executeCommand [as 别名]
class zzzTestRuleSetSSCorners(RuleTest):
def setUp(self):
RuleTest.setUp(self)
self.rule = SetSSCorners(self.config, self.environ, self.logdispatch, self.statechglogger)
self.rulename = self.rule.rulename
self.rulenumber = self.rule.rulenumber
self.ch = CommandHelper(self.logdispatch)
def tearDown(self):
pass
def runTest(self):
self.simpleRuleTest()
def setConditionsForRule(self):
"""
Configure system for the unit test
@param self: essential if you override this definition
@return: boolean - If successful True; If failure False
@author: Breen Malmberg
"""
success = True
self.cmdhelper = CommandHelper(self.logdispatch)
optdict = {"wvous-tr-corner": 6}
cmd = "defaults write " + '"' + self.environ.geteuidhome() + '/Library/Preferences/com.apple.dock.plist" '
for item in optdict:
self.cmdhelper.executeCommand(cmd + item + " -int " + str(optdict[item]))
errout = self.cmdhelper.getErrorString()
if errout:
success = False
return success
def checkReportForRule(self, pCompliance, pRuleSuccess):
"""
check on whether report was correct
@param self: essential if you override this definition
@param pCompliance: the self.iscompliant value of rule
@param pRuleSuccess: did report run successfully
@return: boolean - If successful True; If failure False
@author: Breen Malmberg
"""
self.logdispatch.log(LogPriority.DEBUG, "pCompliance = " + str(pCompliance) + ".")
self.logdispatch.log(LogPriority.DEBUG, "pRuleSuccess = " + str(pRuleSuccess) + ".")
success = True
return success
def checkFixForRule(self, pRuleSuccess):
"""
check on whether fix was correct
@param self: essential if you override this definition
@param pRuleSuccess: did report run successfully
@return: boolean - If successful True; If failure False
@author: Breen Malmberg
"""
self.logdispatch.log(LogPriority.DEBUG, "pRuleSuccess = " + str(pRuleSuccess) + ".")
success = True
return success
def checkUndoForRule(self, pRuleSuccess):
"""
check on whether undo was correct
@param self: essential if you override this definition
@param pRuleSuccess: did report run successfully
@return: boolean - If successful True; If failure False
@author: Breen Malmberg
"""
self.logdispatch.log(LogPriority.DEBUG, "pRuleSuccess = " + str(pRuleSuccess) + ".")
success = True
return success