Exemplo n.º 1
0
def prepare_cli(temp_dir, path_name):
    conf = {
        "contents": path_name + "/all-xccdf.xml",
        "profile": "xccdf_preupg_profile_default",
        "result_dir": temp_dir,
        "skip_common": True,
        "temp_dir": temp_dir,
        "id": None,
        "quiet": True,
        "debug": True,  # so root check won't fail
    }
    dc = DummyConf(**conf)
    cli = CLI(["--contents", path_name + "/" + settings.xml_result_name])
    a = Application(Conf(dc, settings, cli))
    # Prepare all variables for test
    a.conf.source_dir = os.getcwd()
    a.content = a.conf.contents
    a.basename = os.path.basename(a.content)
    return a
Exemplo n.º 2
0
    def _generate_result(self, content_temp):
        conf = {
            "contents": content_temp,
            "profile": "xccdf_preupg_profile_default",
            "result_dir": os.path.dirname(content_temp),
            "skip_common": True,
            "temp_dir": os.path.dirname(content_temp),
            "id": None,
            "debug": True,  # so root check won't fail
        }

        dc = DummyConf(**conf)
        cli = CLI(["--contents", content_temp])
        a = Application(Conf(dc, settings, cli))
        # Prepare all variables for test
        a.conf.source_dir = os.getcwd()
        a.content = a.conf.contents
        a.basename = os.path.basename(a.content)
        self.assertEqual(a.run_scan(), 0)
Exemplo n.º 3
0
def prepare_cli(temp_dir, path_name):
    conf = {
        "contents": path_name + "/all-xccdf.xml",
        "profile": "xccdf_preupg_profile_default",
        "result_dir": temp_dir,
        "skip_common": True,
        "temp_dir": temp_dir,
        "id": None,
        "quiet": True,
        "debug": True,  # so root check won't fail
    }
    dc = DummyConf(**conf)
    cli = CLI(["--contents", path_name + "/" + settings.xml_result_name])
    a = Application(Conf(dc, settings, cli))
    # Prepare all variables for test
    a.conf.source_dir = os.getcwd()
    a.content = a.conf.contents
    a.basename = os.path.basename(a.content)
    return a
Exemplo n.º 4
0
    def test_wrong_content_scenario(self):
        """
        Basic test for whole program
        """
        conf = {
            "contents": "tests/FOOBAR6_7A/dummy_preupg/all-xccdf.xml",
            "profile": "xccdf_preupg_profile_default",
            "result_dir": self.temp_dir,
            "skip_common": True,
            "temp_dir": self.temp_dir,
            "id": None,
            "debug": True,  # so root check won't fail
        }

        dc = DummyConf(**conf)
        cli = CLI(["--contents", "tests/FOOBAR6_7A/dummy_preupg/all-xccdf.xml"])
        a = Application(Conf(dc, settings, cli))
        # Prepare all variables for test
        a.conf.source_dir = os.getcwd()
        a.content = a.conf.contents
        a.basename = os.path.basename(a.content)
        self.assertEqual(a.get_scenario(), None)
Exemplo n.º 5
0
    def test_wrong_content_scenario(self):
        """
        Basic test for whole program
        """
        conf = {
            "contents": "tests/FOOBAR6_7A/dummy_preupg/all-xccdf.xml",
            "profile": "xccdf_preupg_profile_default",
            "result_dir": self.temp_dir,
            "skip_common": True,
            "temp_dir": self.temp_dir,
            "id": None,
            "debug": True,  # so root check won't fail
        }

        dc = DummyConf(**conf)
        cli = CLI(["--contents", "tests/FOOBAR6_7A/dummy_preupg/all-xccdf.xml"])
        a = Application(Conf(dc, settings, cli))
        # Prepare all variables for test
        a.conf.source_dir = os.getcwd()
        a.content = a.conf.contents
        a.basename = os.path.basename(a.content)
        self.assertEqual(a.get_scenario(), None)
Exemplo n.º 6
0
    def test_upgrade(self):
        """Basic test for whole program"""

        conf = {
            "contents": "tests/FOOBAR6_7/dummy_preupg/all-xccdf.xml",
            "profile": "xccdf_preupg_profile_default",
            "result_dir": self.temp_dir,
            "skip_common": True,
            "temp_dir": self.temp_dir,
            "id": None,
            "debug": True,  # so root check won't fail
            "mode": "upgrade",
        }

        dc = DummyConf(**conf)
        cli = CLI(["--contents", "tests/FOOBAR6_7/dummy_preupg/all-xccdf.xml", "--mode", "upgrade"])
        a = Application(Conf(dc, settings, cli))
        # Prepare all variables for test
        a.conf.source_dir = os.getcwd()
        a.content = a.conf.contents
        a.basename = os.path.basename(a.content)
        self.assertEqual(a.run_scan(), 0)
        rp = ReportParser(os.path.join(self.temp_dir, "result.xml"))
        rp.modify_result_path(self.temp_dir, "FOOBAR6_7", "upgrade")
        found_migrate = 0
        found_upgrade = 0
        for values in rp.get_nodes(rp.target_tree, "Value", ".//"):
            if values.get("id").endswith("_preupg_state_migrate"):
                for value in rp.get_nodes(values, "value"):
                    if int(value.text) == 0:
                        found_migrate = 1
            if values.get("id").endswith("_preupg_state_upgrade"):
                for value in rp.get_nodes(values, "value"):
                    if int(value.text) == 1:
                        found_upgrade = 1
        self.assertEquals(found_migrate, 1)
        self.assertEquals(found_upgrade, 1)
Exemplo n.º 7
0
    def test_upgrade(self):
        """Basic test for whole program"""

        conf = {
            "contents": "tests/FOOBAR6_7/dummy_preupg/all-xccdf.xml",
            "profile": "xccdf_preupg_profile_default",
            "result_dir": self.temp_dir,
            "skip_common": True,
            "temp_dir": self.temp_dir,
            "id": None,
            "debug": True,  # so root check won't fail
            "mode": 'upgrade'
        }

        dc = DummyConf(**conf)
        cli = CLI(["--contents", "tests/FOOBAR6_7/dummy_preupg/all-xccdf.xml", "--mode", "upgrade"])
        a = Application(Conf(dc, settings, cli))
        # Prepare all variables for test
        a.conf.source_dir = os.getcwd()
        a.content = a.conf.contents
        a.basename = os.path.basename(a.content)
        self.assertEqual(a.run_scan(), 0)
        rp = ReportParser(os.path.join(self.temp_dir, "result.xml"))
        rp.modify_result_path(self.temp_dir, "FOOBAR6_7", 'upgrade')
        found_migrate = 0
        found_upgrade = 0
        for values in rp.get_nodes(rp.target_tree, "Value", ".//"):
            if values.get("id").endswith("_preupg_state_migrate"):
                for value in rp.get_nodes(values, "value"):
                    if int(value.text) == 0:
                        found_migrate = 1
            if values.get("id").endswith("_preupg_state_upgrade"):
                for value in rp.get_nodes(values, "value"):
                    if int(value.text) == 1:
                        found_upgrade = 1
        self.assertEquals(found_migrate, 1)
        self.assertEquals(found_upgrade, 1)