本文整理汇总了Python中src.stonix_resources.CommandHelper.CommandHelper.getOutput方法的典型用法代码示例。如果您正苦于以下问题:Python CommandHelper.getOutput方法的具体用法?Python CommandHelper.getOutput怎么用?Python CommandHelper.getOutput使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类src.stonix_resources.CommandHelper.CommandHelper
的用法示例。
在下文中一共展示了CommandHelper.getOutput方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: zzzTestRuleConfigureGatekeeper
# 需要导入模块: from src.stonix_resources.CommandHelper import CommandHelper [as 别名]
# 或者: from src.stonix_resources.CommandHelper.CommandHelper import getOutput [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
示例2: MacOSUser
# 需要导入模块: from src.stonix_resources.CommandHelper import CommandHelper [as 别名]
# 或者: from src.stonix_resources.CommandHelper.CommandHelper import getOutput [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
#.........这里部分代码省略.........
示例3: zzzTestRuleDisableCamera
# 需要导入模块: from src.stonix_resources.CommandHelper import CommandHelper [as 别名]
# 或者: from src.stonix_resources.CommandHelper.CommandHelper import getOutput [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.identifier = "041AD784-F0E2-40F5-9433-08ED6B105DDA"
self.rule.camprofile = "/Users/vagrant/stonix/src/stonix_resources/" + \
"files/stonix4macCameraDisablement.mobileconfig"
self.rule.ci.updatecurrvalue(True)
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
self.detailedresults = ""
cmd = ["/usr/bin/profiles", "-P"]
if not self.ch.executeCommand(cmd):
success = False
self.detailedresults += "Unable to run profiles command\n"
else:
output = self.ch.getOutput()
if output:
for line in output:
if search(escape(self.identifier), line.strip()):
cmd = ["/usr/bin/profiles", "-R", "-p", self.identifier]
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
示例4: zzzTestRuleEnableKernelAuditing
# 需要导入模块: from src.stonix_resources.CommandHelper import CommandHelper [as 别名]
# 或者: from src.stonix_resources.CommandHelper.CommandHelper import getOutput [as 别名]
class zzzTestRuleEnableKernelAuditing(RuleTest):
def setUp(self):
RuleTest.setUp(self)
self.rule = EnableKernelAuditing(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):
# restore backups of original files, made before testing
# if self.environ.getosfamily() == 'darwin':
# auditcontrolbak = '/etc/security/audit_control.stonixbak'
# audituserbak = '/etc/security/audit_user.stonixbak'
# if os.path.exists(auditcontrolbak):
# os.rename(auditcontrolbak, '/etc/security/audit_control')
# if os.path.exists(audituserbak):
# os.rename(audituserbak, '/etc/security/audit_user')
# else:
# auditdbaks =['/etc/audit/auditd.conf.stonixbak', '/etc/auditd.conf.stonixbak']
# auditrulesbaks = ['/etc/audit/audit.rules.stonixbak', '/etc/audit/rules.d/audit.rules.stonixbak']
# for bak in auditdbaks:
# if os.path.exists(bak):
# os.rename(bak, bak[:-10])
# for bak in auditrulesbaks:
# if os.path.exists(bak):
# os.rename(bak, bak[:-10])
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
#
# # make backups of any original files, before testing
# if self.environ.getosfamily() == 'darwin':
# if os.path.exists('/etc/security/audit_control'):
# os.rename('/etc/security/audit_control', '/etc/security/audit_control.stonixbak')
# if os.path.exists('/etc/security/audit_user'):
# os.rename('/etc/security/audit_user', '/etc/security/audit_user.stonixbak')
# else:
# auditdpaths = ['/etc/audit/auditd.conf', '/etc/auditd.conf']
# for path in auditdpaths:
# if os.path.exists(path):
# os.rename(path, path + '.stonixbak')
# if os.path.exists('/etc/audisp/audispd.conf'):
# os.rename('/etc/audisp/audispd.conf', '/etc/audisp/audispd.conf.stonixbak')
# auditruleslocs = ['/etc/audit/audit.rules', '/etc/audit/rules.d/audit.rules']
# for loc in auditruleslocs:
# if os.path.exists(loc):
# os.rename(loc, loc + '.stonixbak')
return success
def test_freqci_in_range(self):
'''
test if the frequency ci value is within range
@author: Breen Malmberg
'''
allowable_freq_range = range(1,100)
self.assertTrue(self.rule.freqci.getcurrvalue() in allowable_freq_range)
def test_flushtype_valid(self):
'''
test if the flush type ci value is a valid flush type
@author: Breen Malmberg
'''
allowable_flush_types = ['data', 'incremental', 'sync']
self.assertTrue(self.rule.flushtypeci.getcurrvalue() in allowable_flush_types)
def test_get_system_arch(self):
'''
test the command to get the system arch
@author: Breen Malmberg
'''
found = False
self.ch.executeCommand('/usr/bin/uname -m')
self.assertEqual(0, self.ch.getReturnCode())
outputlines = self.ch.getOutput()
self.assertFalse(outputlines == '')
for line in outputlines:
if re.search('^x86\_64', line):
found = True
for line in outputlines:
#.........这里部分代码省略.........
示例5: zzzTestRuleSTIGConfigureApplicationRestrictionsPolicy
# 需要导入模块: from src.stonix_resources.CommandHelper import CommandHelper [as 别名]
# 或者: from src.stonix_resources.CommandHelper.CommandHelper import getOutput [as 别名]
class zzzTestRuleSTIGConfigureApplicationRestrictionsPolicy(RuleTest):
def setUp(self):
RuleTest.setUp(self)
self.rule = STIGConfigureApplicationRestrictionsPolicy(self.config,
self.environ,
self.logdispatch,
self.statechglogger)
self.rulename = self.rule.rulename
self.rulenumber = self.rule.rulenumber
self.ch = CommandHelper(self.logdispatch)
self.identifier = "mil.disa.STIG.Application_Restrictions.alacarte"
self.rule.profile = "/Users/vagrant/stonix/src/stonix_resources/files/" + \
"U_Apple_OS_X_10-11_V1R1_STIG_Application_Restrictions_Policy.mobileconfig"
def tearDown(self):
pass
def runTest(self):
self.simpleRuleTest()
def setConditionsForRule(self):
success = True
self.detailedresults = ""
cmd = ["/usr/bin/profiles", "-P"]
if not self.ch.executeCommand(cmd):
success = False
self.detailedresults += "Unable to run profiles command\n"
else:
output = self.ch.getOutput()
if output:
for line in output:
if search("mil\.disa\.STIG\.Application_Restrictions\.alacarte$", line.strip()):
cmd = ["/usr/bin/profiles", "-R", "-p", self.identifier]
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