def test_compose(self):
     expected_contents = ["failed", "fixed", "needs_action", "needs_inspection", "not_applicable", "pass"]
     for content in expected_contents:
         compose_xml = ComposeXML()
         result_dir = os.path.join(self.result_dir, content)
         compose_xml.collect_group_xmls(self.dir_name, content=content)
         self.assertTrue(os.path.exists(os.path.join(result_dir, "group.xml")))
         self.assertFalse(os.path.exists(os.path.join(result_dir, "all-xccdf.xml")))
    def test_final_compose(self):
        expected_contents = ["failed", "fixed", "needs_action", "needs_inspection", "not_applicable", "pass"]
        for content in expected_contents:
            compose_xml = ComposeXML()
            dir_name = os.path.join(self.temp_dir, FOO_DIR, "dummy")
            compose_xml.collect_group_xmls(dir_name, content=content)

        xccdf_compose = XCCDFCompose(os.path.join(self.temp_dir, FOO_DIR))
        xccdf_compose.generate_xml()
        all_xccdf = os.path.join(self.result_dir, settings.content_file)
        self.assertTrue(os.path.exists(all_xccdf))
        dummy_lines = utils.get_file_content(all_xccdf, "rb")
 def test_compose(self):
     expected_contents = [
         'failed', 'fixed', 'needs_action', 'needs_inspection',
         'not_applicable', 'pass'
     ]
     for content in expected_contents:
         compose_xml = ComposeXML()
         result_dir = os.path.join(self.result_dir, content)
         compose_xml.collect_group_xmls(self.dir_name, content=content)
         self.assertTrue(
             os.path.exists(os.path.join(result_dir, 'group.xml')))
         self.assertFalse(
             os.path.exists(os.path.join(result_dir, 'all-xccdf.xml')))
    def test_final_compose(self):
        expected_contents = [
            'failed', 'fixed', 'needs_action', 'needs_inspection',
            'not_applicable', 'pass'
        ]
        for content in expected_contents:
            compose_xml = ComposeXML()
            dir_name = os.path.join(self.temp_dir, FOO_DIR, 'dummy')
            compose_xml.collect_group_xmls(dir_name, content=content)

        xccdf_compose = XCCDFCompose(os.path.join(self.temp_dir, FOO_DIR))
        xccdf_compose.generate_xml()
        all_xccdf = os.path.join(self.result_dir, settings.content_file)
        self.assertTrue(os.path.exists(all_xccdf))
        dummy_lines = utils.get_file_content(all_xccdf, 'rb')
Пример #5
0
    def setUp(self):
        dir_name = os.path.join(os.getcwd(), 'tests', 'FOOBAR6_7')
        self.result_dir = os.path.join(dir_name+variables.result_prefix)
        dir_name = os.path.join(dir_name, 'dummy')
        if os.path.exists(self.result_dir):
            shutil.rmtree(self.result_dir)
        shutil.copytree(dir_name, self.result_dir)
        template_file = ComposeXML.get_template_file()
        self.tree = None
        try:
            self.tree = ElementTree.parse(template_file).getroot()
        except IOError:
            assert False

        settings.autocomplete = False
        self.target_tree = ComposeXML.run_compose(self.tree, self.result_dir)
        self.assertTrue(self.target_tree)
Пример #6
0
def prepare_xml(path_name):
    settings.autocomplete = False
    template_file = ComposeXML.get_template_file()
    tree = None
    try:
        f = open(template_file, "r")
        tree = ElementTree.fromstring(f.read())
        f.close()
    except IOError:
        assert False
    tree = ComposeXML.run_compose(tree,
                                  os.path.dirname(path_name),
                                  content=os.path.basename(path_name))
    try:
        file = open(os.path.join(path_name, 'all-xccdf.xml'), "w")
        file.write(ElementTree.tostring(tree, encoding="utf-8").decode('utf-8'))
        file.close()
    except IOError as e:
        raise
Пример #7
0
def prepare_xml(path_name):
    settings.autocomplete = False
    template_file = ComposeXML.get_template_file()
    tree = None
    try:
        f = open(template_file, "r")
        tree = ElementTree.fromstring(f.read())
        f.close()
    except IOError:
        assert False
    tree = ComposeXML.run_compose(tree,
                                  os.path.dirname(path_name),
                                  content=os.path.basename(path_name))
    try:
        file = open(os.path.join(path_name, 'all-xccdf.xml'), "w")
        file.write(
            ElementTree.tostring(tree, encoding="utf-8").decode('utf-8'))
        file.close()
    except IOError as e:
        raise
Пример #8
0
 def test_unicode_script_author(self):
     """Test processing of non-ascii characters for author section"""
     u_author = b'Petr Stod\xc5\xaflka'.decode(settings.defenc)
     script_file = os.path.join(self.result_dir, "unicode", "dummy_unicode.sh")
     settings.autocomplete = True
     self.target_tree = ComposeXML.run_compose(self.tree, self.result_dir)
     self.assertTrue(self.target_tree)
     try:
         lines = get_file_content(script_file, "rb", True)
     except IOError:
         assert False
     author = filter(lambda x: u_author in x, lines)
     self.assertTrue(author)