Пример #1
0
    def test_instructionspath(self, placeholder_mock, xmlparser_mock,
                              isfile_mock, schema_mock, initmetadata_mock):
        """
        Will return the instructions file path set in __init__
        """
        from instructionparsers.xmlparser import XmlParser
        expected_file = 'test_instructions.xml'
        isfile_mock.return_value = True
        xml_parser = XmlParser(instructionspath=expected_file, protocol=None)
        actual_file = xml_parser.instructionspath

        self.assertEqual(expected_file, actual_file)
Пример #2
0
 def get_collector(
         cls,
         instructionsfile: str,
         examiner: str = '',
         placeholderfile: str = Placeholder.get_globalplaceholderfile(),
         protocollogfile: str = ''):
     Placeholder.set_globalplaceholderfile(placeholderfile)
     cls._logger.debug(f"Protocol log file: '{protocollogfile}'")
     protocol = LogFileProtocol(examiner,
                                own_protocol_filename=protocollogfile)
     xmlparser = XmlParser(instructionsfile, protocol)
     collector = cls(parser=xmlparser, protocol=protocol)
     return collector
Пример #3
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}'.")
Пример #4
0
    def test_instructionspath_instruction_file_not_there(
            self, placeholder_mock, xmlparser_mock, isfile_mock, schema_mock,
            initmetadata_mock):
        """
        Will raise FileNotFound exeption.
        """
        from instructionparsers.xmlparser import XmlParser
        expected_file = 'test_instructions.xml'
        isfile_mock.return_value = True
        xml_parser = XmlParser(instructionspath=expected_file, protocol=None)

        isfile_mock.return_value = False
        with self.assertRaises(FileNotFoundError):
            xml_parser.instructionspath = expected_file
Пример #5
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')
Пример #6
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)
Пример #7
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])
Пример #8
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}'.")
Пример #9
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}'.")
Пример #10
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')