Example #1
0
 def test_collect_from_localhost(self, path_mock):
     """
     Should initialize collectors for the example file "collect-from-localhost.xml"
     """
     from instructionparsers.xmlparser import XmlParser
     instructions = '../examples/collect-from-localhost.xml'
     try:
         xml_parser = XmlParser(instructionspath=instructions,
                                protocol=None)
         xml_parser._instructionspath = instructions
         xml_parser._init_instructions()
     except Exception:
         self.fail(f"Failed to initialize parser for '{instructions}'.")
Example #2
0
    def test__get_first_instruction_element(self, path_mock):
        """
        Should return the xml element with the title "Root".
        """
        from instructionparsers.xmlparser import XmlParser

        instructions = './instructions/valid_instructions.xml'
        xml_parser = XmlParser(instructionspath=instructions, protocol=None)

        xml_parser._instructionspath = instructions
        element = xml_parser._get_first_instruction_element()

        self.assertIsInstance(element, Element)
        self.assertEqual(element.localName, 'Root')
Example #3
0
    def test__init_instructions_valid_instructions(self, path_mock):
        """
        Should initialize collectors for all XML elements which have the attribute "module".
        """
        from instructionparsers.xmlparser import XmlParser
        from instructionparsers.wrapper import InstructionWrapper

        instructions = './instructions/valid_instructions.xml'
        xml_parser = XmlParser(instructionspath=instructions, protocol=None)

        xml_parser._instructionspath = instructions
        instructionstree = xml_parser._init_instructions()

        self.assertIsInstance(instructionstree, InstructionWrapper)
Example #4
0
    def test__initializemetadata_valid_instructions(self, path_mock):
        """
        Should initialize member 'metadata' with all elements which have the attribute "title".
        """
        metadata = ('Examiner', 'Assignment', 'Client',
                    'Description of Artefact', 'Task Description')
        from instructionparsers.xmlparser import XmlParser

        instructions = './instructions/valid_instructions.xml'
        xml_parser = XmlParser(instructionspath=instructions, protocol=None)
        xml_parser._instructionspath = instructions
        xml_parser._initializemetadata()
        for data in metadata:
            with self.subTest(data):
                self.assertIsNotNone(xml_parser.metadata[data])
Example #5
0
 def test_collect_all(self, path_mock):
     """
     Should initialize collectors for the example file "collect-all.xml"
     """
     from instructionparsers.xmlparser import XmlParser
     instructions = '../examples/collect-all.xml'
     if platform.system() == 'Windows':
         instructions = '..\examples\collect-all-windows.xml'
     try:
         xml_parser = XmlParser(instructionspath=instructions,
                                protocol=None)
         xml_parser._instructionspath = instructions
         xml_parser._init_instructions()
     except Exception:
         self.fail(f"Failed to initialize parser for '{instructions}'.")
Example #6
0
 def test_collect_from_image(self, path_mock):
     """
     Should initialize collectors for the example file "collect-from-image.xml"
     """
     from instructionparsers.xmlparser import XmlParser
     instructions = '../examples/collect-from-image.xml'
     try:
         xml_parser = XmlParser(instructionspath=instructions,
                                protocol=None)
         xml_parser._instructionspath = instructions
         xml_parser._init_instructions()
     except FileNotFoundError:
         # Assume the file not found is from the missing ewf file in the example instructions.
         pass
     except Exception:
         self.fail(f"Failed to initialize parser for '{instructions}'.")
Example #7
0
    def test__init_instructions_valid_instructions(self, path_mock):
        """
        Should return the instruction tree starting with "Root" node.
        """
        from instructionparsers.xmlparser import XmlParser

        instructions = './instructions/valid_instructions.xml'
        xml_parser = XmlParser(instructionspath=instructions, protocol=None)

        xml_parser._instructionspath = instructions
        instructionstree = xml_parser._init_instructions()

        self.assertEqual(instructionstree.instructionname, 'Root')
        self.assertEqual(
            instructionstree.instructionchildren[0].instructionname,
            'LocalHost')
        self.assertEqual(
            instructionstree.instructionchildren[0].instructionchildren[0].
            instructionname, 'MachineName')
        self.assertEqual(
            instructionstree.instructionchildren[1].instructionname,
            'LocalHost')
        self.assertEqual(
            instructionstree.instructionchildren[1].instructionchildren[0].
            instructionname, 'OSName')
        self.assertEqual(
            instructionstree.instructionchildren[1].instructionchildren[1].
            instructionname, 'OSVersion')
        self.assertEqual(
            instructionstree.instructionchildren[1].instructionchildren[2].
            instructionname, 'OSTimezone')
        self.assertEqual(
            instructionstree.instructionchildren[1].instructionchildren[3].
            instructionname, 'AllUsernames')
        self.assertEqual(
            instructionstree.instructionchildren[1].instructionchildren[4].
            instructionname, 'CurrentUser')
        self.assertEqual(
            instructionstree.instructionchildren[1].instructionchildren[5].
            instructionname, 'SudoVersion')
        self.assertEqual(
            instructionstree.instructionchildren[1].instructionchildren[6].
            instructionname, 'FileExistence')
        self.assertEqual(
            instructionstree.instructionchildren[1].instructionchildren[7].
            instructionname, 'FileExistence')
        self.assertEqual(
            instructionstree.instructionchildren[1].instructionchildren[8].
            instructionname, 'FileExistence')
        self.assertEqual(
            instructionstree.instructionchildren[1].instructionchildren[9].
            instructionname, 'FileExistence')
        self.assertEqual(
            instructionstree.instructionchildren[1].instructionchildren[10].
            instructionname, 'FileExistence')
        self.assertEqual(
            instructionstree.instructionchildren[1].instructionchildren[11].
            instructionname, 'ShellHistoryOfAllUsers')
        self.assertEqual(
            instructionstree.instructionchildren[1].instructionchildren[12].
            instructionname, 'NVRAMCollector')
        self.assertEqual(
            instructionstree.instructionchildren[1].instructionchildren[13].
            instructionname, 'TimeFromNTPServer')
        self.assertEqual(
            instructionstree.instructionchildren[1].instructionchildren[14].
            instructionname, 'LocalTime')