コード例 #1
0
    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
        ph = Pkghelper(self.logdispatch, self.environ)
        game = "gnuchess"
        if ph.checkAvailable(game):
            success = ph.install(game)
            if not success:
                error = "Could not install gnuchess. Please check that the " + \
                    "package manager cache is updated and that this PC is " + \
                    "online, and then attempt to run unit test again."
                self.logdispatch.log(LogPriority.ERROR, error)

        return success
コード例 #2
0
    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
        ph = Pkghelper(self.logdispatch, self.environ)
        game = "gnuchess"
        if ph.checkAvailable(game):
            success = ph.install(game)
            if not success:
                error = (
                    "Could not install gnuchess. Please check that the "
                    + "package manager cache is updated and that this PC is "
                    + "online, and then attempt to run unit test again."
                )
                self.logdispatch.log(LogPriority.ERROR, error)

        return success
コード例 #3
0
    def setConditionsForRule(self):
        '''Configure system for the unit test

        :param self: essential if you override this definition
        :returns: boolean - If successful True; If failure False
        @author: Eric Ball

        '''
        success = False
        ph = Pkghelper(self.logdispatch, self.environ)
        gamelist = ['bovo', 'gnuchess']
        for game in gamelist:
            if ph.checkAvailable(game):
                if ph.install(game):
                    success = True
        if not success:
            error = "Could not install any games for presetup in unit test. " + \
                    "Please check that the package manager cache is updated " + \
                    "and that this PC is online, and then attempt to run " + \
                    "unit test again."
            self.logdispatch.log(LogPriority.ERROR, error)

        return success
コード例 #4
0
 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
     if self.environ.getosfamily() == "darwin":
         success = False
         osxversion = str(self.environ.getosver())
         if osxversion.startswith("10.10.0") or \
            osxversion.startswith("10.10.1") or \
            osxversion.startswith("10.10.2") or \
            osxversion.startswith("10.10.3"):
             debug = "Using discoveryd LaunchDaemon"
             self.logdispatch.log(LogPriority.DEBUG, debug)
             service = \
                 "/System/Library/LaunchDaemons/com.apple.discoveryd.plist"
             servicename = "com.apple.networking.discoveryd"
             parameter = "--no-multicast"
             plistText = readFile(service, self.logdispatch)
             newPlistText = re.sub("<string>" + parameter + "</string>",
                                   "", "".join(plistText))
             success = True
         else:
             debug = "Using mDNSResponder LaunchDaemon"
             self.logdispatch.log(LogPriority.DEBUG, debug)
             service = "/System/Library/LaunchDaemons/" + \
                 "com.apple.mDNSResponder.plist"
             if osxversion.startswith("10.10"):
                 servicename = "com.apple.mDNSResponder.reloaded"
                 parameter = "-NoMulticastAdvertisements"
             else:
                 servicename = "com.apple.mDNSResponder"
                 parameter = "-NoMulticastAdvertisements"
             plistText = readFile(service, self.logdispatch)
             newPlistText = re.sub("<string>" + parameter + "</string>",
                                   "", "".join(plistText))
             success = True
         self.service = service
         if success and self.sh.auditService(service, serviceTarget=servicename):
             success = writeFile(service + ".stonixtmp", "".join(plistText),
                                 self.logdispatch)
             success = writeFile(service, newPlistText, self.logdispatch)
         if success and self.sh.auditService(service, serviceTarget=servicename):
             success = self.sh.reloadService(service, serviceTarget=servicename)
     else:
         ph = Pkghelper(self.logdispatch, self.environ)
         package = "avahi-daemon"
         service = "avahi-daemon"
         if (ph.determineMgr() == "yum" or ph.determineMgr() == "dnf"):
             package = "avahi"
             path = "/etc/sysconfig/network"
             if os.path.exists(path):
                 tmppath = path + ".tmp"
                 data = {"NOZEROCONF": "yes"}
                 editor = KVEditorStonix(self.statechglogger,
                                         self.logdispatch, "conf",
                                         path, tmppath, data,
                                         "notpresent", "closedeq")
                 if not editor.report():
                     if editor.fix():
                         if not editor.commit():
                             success = False
                     else:
                         success = False
         elif ph.determineMgr() == "zypper":
             package = "avahi"
         if not ph.check(package) and ph.checkAvailable(package):
             success = ph.install(package)
         if success and not self.sh.auditService(service, serviceTarget=self.serviceTarget):
             self.sh.enableService(service, serviceTarget=self.serviceTarget)
     return success
コード例 #5
0
class zzzTestRuleForceIdleLogout(RuleTest):
    def setUp(self):
        RuleTest.setUp(self)
        self.rule = ForceIdleLogout(self.config, self.environ,
                                    self.logdispatch, self.statechglogger)
        self.logger = self.logdispatch
        self.rulename = self.rule.rulename
        self.rulenumber = self.rule.rulenumber
        self.rule.filci.updatecurrvalue(True)
        self.checkUndo = True
        self.cmdhelper = CommandHelper(self.logger)
        self.ph = Pkghelper(self.logger, self.environ)
        self.gnomesettingpath = "/etc/dconf/db/local.d/00-autologout"
        self.gnomelockpath = "/etc/dconf/db/local.d/locks/autologout"
        self.undotimeout = ""
        self.undoforcelogout = ""
        self.kdesddm = False
        myos = self.environ.getostype().lower()
        if re.search("red hat", myos) or re.search("centos", myos):
            self.gconf = "GConf2"
        else:
            self.gconf = "gconf2"
        self.timeoutci = self.rule.timeoutci.getcurrvalue()

    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
        :returns: boolean - If successful True; If failure False
        @author: ekkehard j. koch

        '''
        success = True
        if self.environ.osfamily == 'linux':
            try:
                self.seconds = self.timeoutci * 60
            except (TypeError):
                debug = "FORCEIDLELOGOUTTIMEOUT value is not " + \
                                        "valid!\n"
                self.logger.log(LogPriority.DEBUG, debug)
                return False
            self.kdesddm = self.ph.check("sddm")
            self.gnomesettingpath = "/etc/dconf/db/local.d/00-autologout"
            desktopmgr = False
            desktopmgrs = [
                "gdm", "gdm3", "kdm", "kde-workspace", "sddm",
                "patterns-kde-kde_yast"
            ]
            if self.ph.check("gdm") or self.ph.check("gdm3"):
                desktopmgr = True
            if self.ph.check("kdm") or self.ph.check("kde-workspace")or \
                    self.ph.check("sddm") or self.ph.check("patterns-kde-kde_yast"):
                desktopmgr = True
            if not desktopmgr:
                for mgr in desktopmgrs:
                    if self.ph.checkAvailable(mgr):
                        if self.ph.install(mgr):
                            desktopmgr = True
                if not desktopmgr:
                    success = False
                    debug = "Unable to install a desktop manager for testing\n"
                    self.logger.log(LogPriority.DEBUG, debug)
            success = self.setgnome()
            success = self.setkde()
        elif self.environ.getosfamily() == 'darwin':
            if not self.setosx():
                success = False
        return success

    def setgnome(self):
        '''
        @author: dwalker
        @return: bool - success
        '''
        debug = ""
        if self.environ.geteuid() != 0:
            debug = "Unable to set gnome conditions in unit " + \
                "test because user is not root."

        success = True
        if os.path.exists('/etc/dconf/db/local.d'):
            if os.path.exists(self.gnomesettingpath):
                if not os.remove(self.gnomesettingpath):
                    success = False
                    debug = "Unable to remove " + self.gnomesettingpath + \
                        " for unit test preconditions\n"
                    self.logger.log(LogPriority.DEBUG, debug)
        if self.ph.check(self.gconf):
            get = "/usr/bin/gconftool-2 --direct --config-source " + \
                "xml:readwrite:/etc/gconf/gconf.xml.mandatory --get "
            set = "/usr/bin/gconftool-2 --direct --config-source " + \
                "xml:readwrite:/etc/gconf/gconf.xml.mandatory --set "
            unset = "/usr/bin/gconftool-2 --direct --config-source " + \
                "xml/readwrite:/etc/gconf/gconf.xml.mandatory --unset "
            idletimecmd = get + "/desktop/gnome/session/max_idle_time"
            if self.cmdhelper.executeCommand(idletimecmd):
                output = self.cmdhelper.getOutput()
                if output:
                    try:
                        if int(output[0].strip()) == self.seconds:
                            timeout = int(self.seconds) + 5
                            idletimecmd = set + "--type integer /desktop/gnome/session/max_idle_time " + \
                                str(timeout)
                            if not self.cmdhelper.executeCommand(idletimecmd):
                                success = False
                                debug = "Unable to set incorrect timeout value for " + \
                                    "unit test preconditions\n"
                                self.logger.log(LogPriority.DEBUG, debug)
                    except (IndexError):
                        debug = "No output to display timeout value\n"
                        self.logger.log(LogPriority.DEBUG, debug)
            else:
                success = False
                debug = "Unable to obtain the timeout value\n"
                self.logger.log(LogPriority.DEBUG, debug)
            idleactcmd = get + "/desktop/gnome/session/max_idle_action"
            if self.cmdhelper.executeCommand(idleactcmd):
                output = self.cmdhelper.getOutput()
                if output:
                    if re.search("forced-logout", output[0]):
                        idleact = unset + "/desktop/gnome/session/max_idle_action"
                        if not self.cmdhelper.executeCommand(idleact):
                            success = False
                            debug = "Unable to unset max_idle_action for " + \
                                "unit test preconditions\n"
                            self.logger.log(LogPriority.DEBUG, debug)

        return success

    def setkde(self):
        '''
        @author: dwalker
        @return: bool - success
        '''
        success = True
        debug = ""
        if self.kdesddm:
            self.kdecheck = ".config/kdeglobals"
            self.rcpath = ".config/kscreenlockerrc"
            self.kdeprops = {"ScreenSaver": {"Timeout": str(self.seconds)}}
        else:
            self.kdecheck = ".kde"
            self.rcpath = ".kde/share/config/kscreensaverrc"
            self.kdeprops = {
                "ScreenSaver": {
                    "AutoLogout": "true",
                    "AutoLogoutTimeout": str(self.seconds)
                }
            }
        contents = readFile("/etc/passwd", self.logger)
        for line in contents:
            username = ""
            homepath = ""
            temp = line.split(":")
            try:
                username = temp[0]
                homepath = temp[5]
            except (IndexError):
                continue
            kdeparent = os.path.join(homepath, self.kdecheck)
            kdefile = os.path.join(homepath, self.rcpath)
            if not os.path.exists(kdeparent):
                continue
            elif os.path.exists(kdefile):
                if self.searchFile(kdefile):
                    if not self.messFile(kdefile):
                        success = False
                        debug = "Unable to set incorrect values for kde " + \
                                "for user " + username + " in " + \
                                "unit test preconditions\n"
                        self.logger.log(LogPriority.DEBUG, debug)
        return success

    def searchFile(self, filehandle):
        '''temporary method to separate the code to find directives from the
        rest of the code.  Will put back all in one method eventually
        @author: dwalker
        @return: bool
        @param filehandle: string
        '''
        self.editor = ""
        kvt = "tagconf"
        intent = "present"
        tpath = filehandle + ".tmp"
        conftype = "closedeq"
        self.editor = KVEditorStonix(self.statechglogger, self.logger, kvt,
                                     filehandle, tpath, self.kdeprops, intent,
                                     conftype)
        if not self.editor.report():
            return False
        else:
            return True

    def messFile(self, filehandle):
        success = True
        self.editor = ""
        garbagevalue = ""
        while True:
            garbagevalue = randint(0, 200)
            if garbagevalue != self.timeoutci:
                break
        kvt = "tagconf"
        intent = "present"
        tpath = filehandle + ".tmp"
        conftype = "closedeq"
        if self.kdesddm:
            self.kdecheck = ".config/kdeglobals"
            self.rcpath = ".config/kscreenlockerrc"
            self.kdeprops = {"ScreenSaver": {"Timeout": str(garbagevalue)}}
        else:
            self.kdecheck = ".kde"
            self.rcpath = ".kde/share/config/kscreensaverrc"
            self.kdeprops = {
                "ScreenSaver": {
                    "AutoLogout": "true",
                    "AutoLogoutTimeout": str(garbagevalue)
                }
            }
        self.editor = KVEditorStonix(self.statechglogger, self.logger, kvt,
                                     filehandle, tpath, self.kdeprops, intent,
                                     conftype)
        self.editor.report()
        if not self.editor.fix():
            success = False
        elif not self.editor.commit():
            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
        :returns: 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
        :returns: 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
        :returns: boolean - If successful True; If failure False
        @author: ekkehard j. koch

        '''
        self.logdispatch.log(LogPriority.DEBUG,
                             "pRuleSuccess = " + str(pRuleSuccess) + ".")
        success = True
        return success
コード例 #6
0
class zzzTestRuleDisablePrelinking(RuleTest):

    def setUp(self):
        RuleTest.setUp(self)
        self.rule = DisablePrelinking(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.prelinkInstalled = False

    def tearDown(self):
        if not self.prelinkInstalled:
            self.ph.remove("prelink")

    def runTest(self):
        self.simpleRuleTest()

    def setConditionsForRule(self):
        '''Configure system for the unit test

        :param self: essential if you override this definition
        :returns: boolean - If successful True; If failure False
        @author: ekkehard j. koch

        '''
        success = True
        if self.ph.check("prelink"):
            self.prelinkInstalled = True
        elif self.ph.checkAvailable("prelink"):
            self.ph.install("prelink")
        else:
            return True
        path = "/usr/sbin/prelink"
        cmd = [path, "/bin/ls"]
        if os.path.exists(path):
            self.ch.executeCommand(cmd)

        if re.search("debian|ubuntu", self.environ.getostype().lower()):
            path = "/etc/default/prelink"
        else:
            path = "/etc/sysconfig/prelink"
        if os.path.exists(path):
            tmppath = path + ".tmp"
            data = {"PRELINKING": "yes"}
            self.editor = KVEditorStonix(self.statechglogger, self.logdispatch,
                                         "conf", path, tmppath,
                                         data, "present", "closedeq")
            if not self.editor.report():
                if self.editor.fix():
                    if not self.editor.commit():
                        success = False
                        self.logdispatch.log(LogPriority.ERROR,
                                             "KVEditor failed to commit.")
                else:
                    success = False
                    self.logdispatch.log(LogPriority.ERROR,
                                         "KVEditor failed to fix.")
        else:
            writeFile(path, "PRELINKING=yes", self.logdispatch)

        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
        :returns: 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
        :returns: 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
        :returns: boolean - If successful True; If failure False
        @author: ekkehard j. koch

        '''
        self.logdispatch.log(LogPriority.DEBUG, "pRuleSuccess = " +
                             str(pRuleSuccess) + ".")
        success = True
        return success
コード例 #7
0
class zzzTestRuleSecureMTA(RuleTest):
    def setUp(self):
        RuleTest.setUp(self)
        self.rule = SecureMTA(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.logdispatch)
        if self.environ.operatingsystem == "Mac OS X":
            self.isMac = True
        else:
            self.isMac = False

    def tearDown(self):
        pass
#         if not self.isMac:
#             if self.origState[0] is True and not self.ph.check("sendmail"):
#                 self.ph.install("sendmail")
#             elif self.origState[0] is False and self.ph.check("sendmail"):
#                 self.ph.remove("sendmail")
#
#             if self.origState[1] is True and not self.ph.check(self.postfixpkg):
#                 self.ph.install(self.postfixpkg)
#             elif self.origState[1] is False and self.ph.check(self.postfixpkg):
#                 self.ph.remove(self.postfixpkg)
#
#             if self.origState[2] is True and os.path.exists(self.smTmp):
#                 smDir = os.path.split(self.smPath)[0]
#                 if not os.path.exists(smDir):
#                     os.makedirs(smDir)
#                 os.rename(self.smTmp, self.smPath)
#             elif self.origState[2] is False and os.path.exists(self.smPath):
#                 os.remove(self.smPath)
#
#             if self.origState[3] is True and os.path.exists(self.pfTmp):
#                 pfDir = os.path.split(self.pfPath)[0]
#                 if not os.path.exists(pfDir):
#                     os.makedirs(pfDir)
#                 os.rename(self.pfTmp, self.pfPath)
#             elif self.origState[3] is False and os.path.exists(self.pfPath):
#                 os.remove(self.pfPath)

    def runTest(self):
        self.simpleRuleTest()

    def setConditionsForRule(self):
        '''Configure system for the unit test

        :param self: essential if you override this definition
        :returns: boolean - If successful True; If failure False
        @author: dwalker

        '''
        success = True
        pfdata = {
            'inet_interfaces': 'localhost',
            'default_process_limit': '100',
            'smtpd_client_connection_count_limit': '10',
            'smtpd_client_connection_rate_limit': '30',
            'queue_minfree': '20971520',
            'header_size_limit': '51200',
            'message_size_limit': '10485760',
            'smtpd_recipient_limit': '100',
            'smtpd_banner': '$myhostname ESMTP',
            'mynetworks_style': 'host',
            'smtpd_recipient_restrictions':
            'permit_mynetworks, reject_unauth_destination',
            'relayhost': MAILRELAYSERVER
        }
        if not self.isMac:
            smdata = {
                "O SmtpGreetingMessage": "",
                "O PrivacyOptions": "goaway"
            }
            self.ph = Pkghelper(self.logdispatch, self.environ)
            self.origState = [False, False, False, False]
            self.smPath = "/etc/mail/sendmail.cf"
            self.smTmp = self.smPath + ".stonixUT"
            self.pfPathlist = [
                '/etc/postfix/main.cf', '/usr/lib/postfix/main.cf'
            ]
            self.postfixpkg = "postfix"
            self.pfPath = ""
            for path in self.pfPathlist:
                if os.path.exists(path):
                    self.pfPath = path
                    break
            self.pfTmp = self.pfPath + ".stonixUT"
            #if postfix file exists, remove any correct contents
            if self.pfPath:
                self.postfixed = KVEditorStonix(self.statechglogger,
                                                self.logger, "conf",
                                                self.pfPath, self.pfTmp,
                                                pfdata, "notpresent", "openeq")
                if not self.postfixed.report():
                    if self.postfixed.removeables:
                        print("kveditor has removeables\n")
                        if not self.postfixed.fix():
                            success = False
            if os.path.exists(self.smPath):
                self.sndmailed = KVEditorStonix(self.statechglogger,
                                                self.logger, "conf",
                                                self.smPath, self.smTmp,
                                                smdata, "notpresent",
                                                "closedeq")
                if not self.sndmailed.report():
                    if self.postfixed.removeables:
                        if not self.postfixed.fix():
                            success = False

            #remove postfix if installed
            if self.ph.check("postfix"):
                if not self.ph.remove("postfix"):
                    success = False
            #remove sendmail if installed
            if not self.ph.checkAvailable("postfix"):
                if self.ph.check("sendmail"):
                    if not self.ph.remove("sendmail"):
                        success = False
        else:
            self.pfPath = "/private/etc/postfix/main.cf"
            self.pfTmp = self.pfPath + ".stonixUT"
            if os.path.exists(self.pfPath):
                self.postfixed = KVEditorStonix(self.statechglogger,
                                                self.logger, "conf",
                                                self.pfPath, self.pfTmp,
                                                pfdata, "notpresent", "openeq")
                if not self.postfixed.report():
                    if self.postfixed.removeables:
                        if not self.postfixed.fix():
                            success = False
#             if self.ph.check("sendmail"):
#                 self.origState[0] = True
#             if self.ph.check(self.postfixpkg):
#                 self.origState[1] = True
#             if os.path.exists(self.smPath):
#                 self.origState[2] = True
#                 os.rename(self.smPath, self.smTmp)
#             if os.path.exists(self.pfPath):
#                 self.origState[3] = True
#                 os.rename(self.pfPath, self.pfTmp)
        return success


#     def testFalseFalseFalseFalse(self):
#         if not self.isMac:
#             if self.ph.check("sendmail"):
#                 self.ph.remove("sendmail")
#             if self.ph.check(self.postfixpkg):
#                 self.ph.remove(self.postfixpkg)
#             if os.path.exists(self.smPath):
#                 os.remove(self.smPath)
#             if os.path.exists(self.pfPath):
#                 os.remove(self.pfPath)
#             self.simpleRuleTest()
#
#     def testTrueFalseFalseFalse(self):
#         if not self.isMac:
#             if not self.ph.check("sendmail"):
#                 self.ph.install("sendmail")
#             if self.ph.check(self.postfixpkg):
#                 self.ph.remove(self.postfixpkg)
#             if os.path.exists(self.smPath):
#                 os.remove(self.smPath)
#             if os.path.exists(self.pfPath):
#                 os.remove(self.pfPath)
#             self.simpleRuleTest()
#
#     def testTrueTrueFalseFalse(self):
#         if not self.isMac:
#             if not self.ph.check("sendmail"):
#                 self.ph.install("sendmail")
#             if not self.ph.check(self.postfixpkg):
#                 self.ph.install(self.postfixpkg)
#             if os.path.exists(self.smPath):
#                 os.remove(self.smPath)
#             if os.path.exists(self.pfPath):
#                 os.remove(self.pfPath)
#             self.simpleRuleTest()
#
#     def testTrueTrueTrueFalse(self):
#         if not self.isMac:
#             if not self.ph.check("sendmail"):
#                 self.ph.install("sendmail")
#             if not self.ph.check(self.postfixpkg):
#                 self.ph.install(self.postfixpkg)
#             if not os.path.exists(self.smPath):
#                 splitpath = self.smPath.split('/')
#                 del splitpath[-1]
#                 subdir = "/".join(splitpath)
#                 if not os.path.exists(subdir):
#                     os.makedirs(subdir, 0755)
#                 open(self.smPath, "w")
#             if os.path.exists(self.pfPath):
#                 os.remove(self.pfPath)
#             self.simpleRuleTest()
#
#     def testTrueTrueTrueTrue(self):
#         if not self.isMac:
#             if not self.ph.check("sendmail"):
#                 self.ph.install("sendmail")
#             if not self.ph.check(self.postfixpkg):
#                 self.ph.install(self.postfixpkg)
#             if not os.path.exists(self.smPath):
#                 splitpath = self.smPath.split('/')
#                 del splitpath[-1]
#                 subdir = "/".join(splitpath)
#                 if not os.path.exists(subdir):
#                     os.makedirs(subdir, 0755)
#                 open(self.smPath, "w")
#             if not os.path.exists(self.pfPath):
#                 splitpath = self.pfPath.split('/')
#                 del splitpath[-1]
#                 subdir = "/".join(splitpath)
#                 if not os.path.exists(subdir):
#                     os.makedirs(subdir, 0755)
#                 open(self.pfPath, "w")
#             self.simpleRuleTest()
#
#     def testTrueFalseTrueFalse(self):
#         if not self.isMac:
#             if not self.ph.check("sendmail"):
#                 self.ph.install("sendmail")
#             if self.ph.check(self.postfixpkg):
#                 self.ph.remove(self.postfixpkg)
#             if not os.path.exists(self.smPath):
#                 splitpath = self.smPath.split('/')
#                 del splitpath[-1]
#                 subdir = "/".join(splitpath)
#                 if not os.path.exists(subdir):
#                     os.makedirs(subdir, 0755)
#                 open(self.smPath, "w")
#             if os.path.exists(self.pfPath):
#                 os.remove(self.pfPath)
#             self.simpleRuleTest()
#
#     def testFalseTrueFalseFalse(self):
#         if not self.isMac:
#             if self.ph.check("sendmail"):
#                 self.ph.remove("sendmail")
#             if not self.ph.check(self.postfixpkg):
#                 self.ph.install(self.postfixpkg)
#             if os.path.exists(self.smPath):
#                 os.remove(self.smPath)
#             if os.path.exists(self.pfPath):
#                 os.remove(self.pfPath)
#             self.simpleRuleTest()
#
#     def testFalseTrueFalseTrue(self):
#         if not self.isMac:
#             if self.ph.check("sendmail"):
#                 self.ph.remove("sendmail")
#             if not self.ph.check(self.postfixpkg):
#                 self.ph.install(self.postfixpkg)
#             if os.path.exists(self.smPath):
#                 os.remove(self.smPath)
#             if not os.path.exists(self.pfPath):
#                 splitpath = self.pfPath.split('/')
#                 del splitpath[-1]
#                 subdir = "/".join(splitpath)
#                 if not os.path.exists(subdir):
#                     os.makedirs(subdir, 0755)
#                 open(self.pfPath, "w")
#             self.simpleRuleTest()

    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
        :returns: 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
        :returns: 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
        :returns: boolean - If successful True; If failure False
        @author: ekkehard j. koch

        '''
        self.logdispatch.log(LogPriority.DEBUG,
                             "pRuleSuccess = " + str(pRuleSuccess) + ".")
        success = True
        return success
コード例 #8
0
class zzzTestRuleRemoveSoftware(RuleTest):

    def setUp(self):
        RuleTest.setUp(self)
        self.rule = RemoveSoftware(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.checkUndo = True

    def tearDown(self):
        for pkg in self.installed:
            self.ph.install(pkg)

    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: dwalker
        '''
        success = True
        self.rule.ci.updatecurrvalue(True)
        self.installed = []
        default = ["squid",
                   "telnet-server",
                   "rsh-server",
                   "rsh",
                   "rsh-client",
                   "talk",
                   "talk-server",
                   "talkd",
                   "tftp-server",
                   "tftp",
                   "tftpd"]
        for pkg in default:
            if not self.ph.check(pkg) and self.ph.checkAvailable(pkg):
                self.ph.install(pkg)
            elif self.ph.check(pkg) and self.ph.checkAvailable(pkg):
                self.installed.append(pkg)
        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: dwalker
        '''
        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: dwalker
        '''
        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: dwalker
        '''
        self.logdispatch.log(LogPriority.DEBUG, "pRuleSuccess = " +
                             str(pRuleSuccess) + ".")
        success = True
        return success
コード例 #9
0
    def setConditionsForRule(self):
        '''Configure system for the unit test

        :param self: essential if you override this definition
        :returns: boolean - If successful True; If failure False
        @author: ekkehard j. koch

        '''
        success = True
        if self.environ.getosfamily() == "darwin":
            success = False
            osxversion = str(self.environ.getosver())
            if osxversion.startswith("10.10.0") or \
               osxversion.startswith("10.10.1") or \
               osxversion.startswith("10.10.2") or \
               osxversion.startswith("10.10.3"):
                debug = "Using discoveryd LaunchDaemon"
                self.logdispatch.log(LogPriority.DEBUG, debug)
                service = \
                    "/System/Library/LaunchDaemons/com.apple.discoveryd.plist"
                servicename = "com.apple.networking.discoveryd"
                parameter = "--no-multicast"
                plistText = readFile(service, self.logdispatch)
                newPlistText = re.sub("<string>" + parameter + "</string>", "",
                                      "".join(plistText))
                success = True
            else:
                debug = "Using mDNSResponder LaunchDaemon"
                self.logdispatch.log(LogPriority.DEBUG, debug)
                service = "/System/Library/LaunchDaemons/" + \
                    "com.apple.mDNSResponder.plist"
                if osxversion.startswith("10.10"):
                    servicename = "com.apple.mDNSResponder.reloaded"
                    parameter = "-NoMulticastAdvertisements"
                else:
                    servicename = "com.apple.mDNSResponder"
                    parameter = "-NoMulticastAdvertisements"
                plistText = readFile(service, self.logdispatch)
                newPlistText = re.sub("<string>" + parameter + "</string>", "",
                                      "".join(plistText))
                success = True
            self.service = service
            if success and self.sh.auditService(service,
                                                serviceTarget=servicename):
                success = writeFile(service + ".stonixtmp", "".join(plistText),
                                    self.logdispatch)
                success = writeFile(service, newPlistText, self.logdispatch)
            if success and self.sh.auditService(service,
                                                serviceTarget=servicename):
                success = self.sh.reloadService(service,
                                                serviceTarget=servicename)
        else:
            ph = Pkghelper(self.logdispatch, self.environ)
            package = "avahi-daemon"
            service = "avahi-daemon"
            if (ph.determineMgr() == "yum" or ph.determineMgr() == "dnf"):
                package = "avahi"
                path = "/etc/sysconfig/network"
                if os.path.exists(path):
                    tmppath = path + ".tmp"
                    data = {"NOZEROCONF": "yes"}
                    editor = KVEditorStonix(self.statechglogger,
                                            self.logdispatch, "conf", path,
                                            tmppath, data, "notpresent",
                                            "closedeq")
                    if not editor.report():
                        if editor.fix():
                            if not editor.commit():
                                success = False
                        else:
                            success = False
            elif ph.determineMgr() == "zypper":
                package = "avahi"
            if not ph.check(package) and ph.checkAvailable(package):
                success = ph.install(package)
            if success and not self.sh.auditService(
                    service, serviceTarget=self.serviceTarget):
                self.sh.enableService(service,
                                      serviceTarget=self.serviceTarget)
        return success
コード例 #10
0
class zzzTestRuleDisablePrelinking(RuleTest):

    def setUp(self):
        RuleTest.setUp(self)
        self.rule = DisablePrelinking(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.prelinkInstalled = False

    def tearDown(self):
        if not self.prelinkInstalled:
            self.ph.remove("prelink")

    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
        if self.ph.check("prelink"):
            self.prelinkInstalled = True
        elif self.ph.checkAvailable("prelink"):
            self.ph.install("prelink")
        else:
            return True
        path = "/usr/sbin/prelink"
        cmd = [path, "/bin/ls"]
        if os.path.exists(path):
            self.ch.executeCommand(cmd)

        if re.search("debian|ubuntu", self.environ.getostype().lower()):
            path = "/etc/default/prelink"
        else:
            path = "/etc/sysconfig/prelink"
        if os.path.exists(path):
            tmppath = path + ".tmp"
            data = {"PRELINKING": "yes"}
            self.editor = KVEditorStonix(self.statechglogger, self.logdispatch,
                                         "conf", path, tmppath,
                                         data, "present", "closedeq")
            if not self.editor.report():
                if self.editor.fix():
                    if not self.editor.commit():
                        success = False
                        self.logdispatch.log(LogPriority.ERROR,
                                             "KVEditor failed to commit.")
                else:
                    success = False
                    self.logdispatch.log(LogPriority.ERROR,
                                         "KVEditor failed to fix.")
        else:
            writeFile(path, "PRELINKING=yes", self.logdispatch)

        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
コード例 #11
0
class zzzTestRuleSecureMTA(RuleTest):

    def setUp(self):
        RuleTest.setUp(self)
        self.rule = SecureMTA(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.logdispatch)
        if self.environ.operatingsystem == "Mac OS X":
            self.isMac = True
        else:
            self.isMac = False

    def tearDown(self):
        pass
#         if not self.isMac:
#             if self.origState[0] is True and not self.ph.check("sendmail"):
#                 self.ph.install("sendmail")
#             elif self.origState[0] is False and self.ph.check("sendmail"):
#                 self.ph.remove("sendmail")
# 
#             if self.origState[1] is True and not self.ph.check(self.postfixpkg):
#                 self.ph.install(self.postfixpkg)
#             elif self.origState[1] is False and self.ph.check(self.postfixpkg):
#                 self.ph.remove(self.postfixpkg)
# 
#             if self.origState[2] is True and os.path.exists(self.smTmp):
#                 smDir = os.path.split(self.smPath)[0]
#                 if not os.path.exists(smDir):
#                     os.makedirs(smDir)
#                 os.rename(self.smTmp, self.smPath)
#             elif self.origState[2] is False and os.path.exists(self.smPath):
#                 os.remove(self.smPath)
# 
#             if self.origState[3] is True and os.path.exists(self.pfTmp):
#                 pfDir = os.path.split(self.pfPath)[0]
#                 if not os.path.exists(pfDir):
#                     os.makedirs(pfDir)
#                 os.rename(self.pfTmp, self.pfPath)
#             elif self.origState[3] is False and os.path.exists(self.pfPath):
#                 os.remove(self.pfPath)
    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: dwalker
        '''
        success = True
        pfdata = {'inet_interfaces': 'localhost',
                'default_process_limit': '100',
                'smtpd_client_connection_count_limit': '10',
                'smtpd_client_connection_rate_limit': '30',
                'queue_minfree': '20971520',
                'header_size_limit': '51200',
                'message_size_limit': '10485760',
                'smtpd_recipient_limit': '100',
                'smtpd_banner': '$myhostname ESMTP',
                'mynetworks_style': 'host',
                'smtpd_recipient_restrictions':
                'permit_mynetworks, reject_unauth_destination',
                'relayhost': MAILRELAYSERVER}
        if not self.isMac:
            smdata = {"O SmtpGreetingMessage": "",
                      "O PrivacyOptions": "goaway"}
            self.ph = Pkghelper(self.logdispatch, self.environ)
            self.origState = [False, False, False, False]
            self.smPath = "/etc/mail/sendmail.cf"
            self.smTmp = self.smPath + ".stonixUT"
            self.pfPathlist = ['/etc/postfix/main.cf',
                               '/usr/lib/postfix/main.cf']
            self.postfixpkg = "postfix"
            self.pfPath = ""
            for path in self.pfPathlist:
                if os.path.exists(path):
                    self.pfPath = path
                    break
            self.pfTmp = self.pfPath + ".stonixUT"
            #if postfix file exists, remove any correct contents
            if self.pfPath:
                self.postfixed = KVEditorStonix(self.statechglogger,
                    self.logger, "conf", self.pfPath, self.pfTmp,
                    pfdata, "notpresent", "openeq")
                if not self.postfixed.report():
                    if self.postfixed.removeables:
                        print "kveditor has removeables\n"
                        if not self.postfixed.fix():
                            success = False
            if os.path.exists(self.smPath):
                self.sndmailed = KVEditorStonix(self.statechglogger, self.logger,
                    "conf", self.smPath, self.smTmp, smdata, "notpresent",
                    "closedeq")
                if not self.sndmailed.report():
                    if self.postfixed.removeables:
                        if not self.postfixed.fix():
                            success = False

            #remove postfix if installed
            if self.ph.check("postfix"):
                if not self.ph.remove("postfix"):
                    success = False
            #remove sendmail if installed
            if not self.ph.checkAvailable("postfix"):
                if self.ph.check("sendmail"):
                    if not self.ph.remove("sendmail"):
                        success = False
        else:
            self.pfPath = "/private/etc/postfix/main.cf"
            self.pfTmp = self.pfPath + ".stonixUT"
            if os.path.exists(self.pfPath):
                self.postfixed = KVEditorStonix(self.statechglogger,
                    self.logger, "conf", self.pfPath, self.pfTmp,
                    pfdata, "notpresent", "openeq")
                if not self.postfixed.report():
                    if self.postfixed.removeables:
                        if not self.postfixed.fix():
                            success = False
#             if self.ph.check("sendmail"):
#                 self.origState[0] = True
#             if self.ph.check(self.postfixpkg):
#                 self.origState[1] = True
#             if os.path.exists(self.smPath):
#                 self.origState[2] = True
#                 os.rename(self.smPath, self.smTmp)
#             if os.path.exists(self.pfPath):
#                 self.origState[3] = True
#                 os.rename(self.pfPath, self.pfTmp)
        return success
#     def testFalseFalseFalseFalse(self):
#         if not self.isMac:
#             if self.ph.check("sendmail"):
#                 self.ph.remove("sendmail")
#             if self.ph.check(self.postfixpkg):
#                 self.ph.remove(self.postfixpkg)
#             if os.path.exists(self.smPath):
#                 os.remove(self.smPath)
#             if os.path.exists(self.pfPath):
#                 os.remove(self.pfPath)
#             self.simpleRuleTest()
# 
#     def testTrueFalseFalseFalse(self):
#         if not self.isMac:
#             if not self.ph.check("sendmail"):
#                 self.ph.install("sendmail")
#             if self.ph.check(self.postfixpkg):
#                 self.ph.remove(self.postfixpkg)
#             if os.path.exists(self.smPath):
#                 os.remove(self.smPath)
#             if os.path.exists(self.pfPath):
#                 os.remove(self.pfPath)
#             self.simpleRuleTest()
# 
#     def testTrueTrueFalseFalse(self):
#         if not self.isMac:
#             if not self.ph.check("sendmail"):
#                 self.ph.install("sendmail")
#             if not self.ph.check(self.postfixpkg):
#                 self.ph.install(self.postfixpkg)
#             if os.path.exists(self.smPath):
#                 os.remove(self.smPath)
#             if os.path.exists(self.pfPath):
#                 os.remove(self.pfPath)
#             self.simpleRuleTest()
# 
#     def testTrueTrueTrueFalse(self):
#         if not self.isMac:
#             if not self.ph.check("sendmail"):
#                 self.ph.install("sendmail")
#             if not self.ph.check(self.postfixpkg):
#                 self.ph.install(self.postfixpkg)
#             if not os.path.exists(self.smPath):
#                 splitpath = self.smPath.split('/')
#                 del splitpath[-1]
#                 subdir = "/".join(splitpath)
#                 if not os.path.exists(subdir):
#                     os.makedirs(subdir, 0755)
#                 open(self.smPath, "w")
#             if os.path.exists(self.pfPath):
#                 os.remove(self.pfPath)
#             self.simpleRuleTest()
# 
#     def testTrueTrueTrueTrue(self):
#         if not self.isMac:
#             if not self.ph.check("sendmail"):
#                 self.ph.install("sendmail")
#             if not self.ph.check(self.postfixpkg):
#                 self.ph.install(self.postfixpkg)
#             if not os.path.exists(self.smPath):
#                 splitpath = self.smPath.split('/')
#                 del splitpath[-1]
#                 subdir = "/".join(splitpath)
#                 if not os.path.exists(subdir):
#                     os.makedirs(subdir, 0755)
#                 open(self.smPath, "w")
#             if not os.path.exists(self.pfPath):
#                 splitpath = self.pfPath.split('/')
#                 del splitpath[-1]
#                 subdir = "/".join(splitpath)
#                 if not os.path.exists(subdir):
#                     os.makedirs(subdir, 0755)
#                 open(self.pfPath, "w")
#             self.simpleRuleTest()
# 
#     def testTrueFalseTrueFalse(self):
#         if not self.isMac:
#             if not self.ph.check("sendmail"):
#                 self.ph.install("sendmail")
#             if self.ph.check(self.postfixpkg):
#                 self.ph.remove(self.postfixpkg)
#             if not os.path.exists(self.smPath):
#                 splitpath = self.smPath.split('/')
#                 del splitpath[-1]
#                 subdir = "/".join(splitpath)
#                 if not os.path.exists(subdir):
#                     os.makedirs(subdir, 0755)
#                 open(self.smPath, "w")
#             if os.path.exists(self.pfPath):
#                 os.remove(self.pfPath)
#             self.simpleRuleTest()
# 
#     def testFalseTrueFalseFalse(self):
#         if not self.isMac:
#             if self.ph.check("sendmail"):
#                 self.ph.remove("sendmail")
#             if not self.ph.check(self.postfixpkg):
#                 self.ph.install(self.postfixpkg)
#             if os.path.exists(self.smPath):
#                 os.remove(self.smPath)
#             if os.path.exists(self.pfPath):
#                 os.remove(self.pfPath)
#             self.simpleRuleTest()
# 
#     def testFalseTrueFalseTrue(self):
#         if not self.isMac:
#             if self.ph.check("sendmail"):
#                 self.ph.remove("sendmail")
#             if not self.ph.check(self.postfixpkg):
#                 self.ph.install(self.postfixpkg)
#             if os.path.exists(self.smPath):
#                 os.remove(self.smPath)
#             if not os.path.exists(self.pfPath):
#                 splitpath = self.pfPath.split('/')
#                 del splitpath[-1]
#                 subdir = "/".join(splitpath)
#                 if not os.path.exists(subdir):
#                     os.makedirs(subdir, 0755)
#                 open(self.pfPath, "w")
#             self.simpleRuleTest()

    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
コード例 #12
0
class zzzTestRuleRemoveSoftware(RuleTest):
    def setUp(self):
        RuleTest.setUp(self)
        self.rule = RemoveSoftware(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.checkUndo = True

    def tearDown(self):
        for pkg in self.installed:
            self.ph.install(pkg)

    def runTest(self):
        self.simpleRuleTest()

    def setConditionsForRule(self):
        '''Configure system for the unit test

        :param self: essential if you override this definition
        :returns: boolean - If successful True; If failure False
        @author: dwalker

        '''
        success = True
        self.rule.ci.updatecurrvalue(True)
        self.installed = []
        default = [
            "squid", "telnet-server", "rsh-server", "rsh", "rsh-client",
            "talk", "talk-server", "talkd", "tftp-server", "tftp", "tftpd"
        ]
        for pkg in default:
            if not self.ph.check(pkg) and self.ph.checkAvailable(pkg):
                self.ph.install(pkg)
            elif self.ph.check(pkg) and self.ph.checkAvailable(pkg):
                self.installed.append(pkg)
        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
        :returns: boolean - If successful True; If failure False
        @author: dwalker

        '''
        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
        :returns: boolean - If successful True; If failure False
        @author: dwalker

        '''
        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
        :returns: boolean - If successful True; If failure False
        @author: dwalker

        '''
        self.logdispatch.log(LogPriority.DEBUG,
                             "pRuleSuccess = " + str(pRuleSuccess) + ".")
        success = True
        return success