Esempio n. 1
0
    def test___init(self):
        """
        Should initialize filepath.
        :return:
        """
        from artefact.localhost.file import FileMetadata

        expected_filepath = "IDoNotExist.txt"
        collector = FileMetadata(parameters={'source_path': expected_filepath},
                                 parent={})
        collector._collect()

        self.assertEqual(expected_filepath, collector.source_path)
Esempio n. 2
0
    def test__collect_file_does_not_exist(self):
        """
        Should store info about not existing file in data.
        :return:
        """
        from artefact.localhost.file import FileMetadata

        expected_filepath = "IDoNotExist.txt"
        expected_data = f"File '{expected_filepath}' does not exist."
        collector = FileMetadata(parameters={}, parent={})
        collector.source_path = expected_filepath
        collector._collect()
        actual_data = collector.data[0].collecteddata

        self.assertEqual(expected_data, actual_data)
Esempio n. 3
0
    def test__collect_extended_attributes_platform_not_darwin(self):
        """
        Should store message in data, that platform is not supported.
        :return:
        """
        from artefact.localhost.file import FileMetadata

        expected_platform = "Windows"
        expected_message = f"Collection of extended attributes on platform '{expected_platform}' is not supported."
        collector = FileMetadata(parameters={}, parent=None)
        with mock.patch('artefact.localhost.file.platform.system',
                        MagicMock(return_value=expected_platform)):
            collector._collect_extended_attributes()
            actual_message = collector.data[-1].collecteddata

        self.assertEqual(expected_message, actual_message)
Esempio n. 4
0
    def test__collect_timestamps_platform_windows(self):
        """
        Should should throw KeyError when accessing 'Birth'
        :param self:
        :return:
        """
        from artefact.localhost.file import FileMetadata

        expected_file = './testfiles/test.txt'
        collector = FileMetadata(parameters={}, parent=None)
        collector.source_path = expected_file
        with mock.patch('artefact.localhost.file.os.path.getmtime',
                        MagicMock(return_value=1622795612.874454)):
            collector._collect_timestamps()
            with self.assertRaises(KeyError):
                collector._metadata['Birth']
Esempio n. 5
0
    def test__collect_extended_attributes_on_windows(self):
        """
        Should return error message stating that this is not supported on windows.
        :return:
        """
        from artefact.localhost.file import FileMetadata

        expected_message = "Collection of extended attributes on platform 'Windows' is not supported."
        collector = FileMetadata(parameters={}, parent=None)
        collector.source_path = "mocked_file_path"
        with mock.patch('artefact.localhost.file.run_terminal_command',
                        MagicMock(return_value="my.extended.attribute")):
            with mock.patch('artefact.localhost.file.platform.system',
                            MagicMock(return_value='Windows')):
                collector._collect_extended_attributes()
                actual_message = collector.data[-1].collecteddata

        self.assertEqual(expected_message, actual_message)
Esempio n. 6
0
    def test__collect_timestamps_created_time(self):
        """
        Should collect used timestamp in data.
        :return:
        """
        from artefact.localhost.file import FileMetadata

        expected_created_time_data = "2021-06-04 08:33:32 UTC"
        expected_file = './testfiles/test.txt'

        collector = FileMetadata(parameters={}, parent=None)
        collector.source_path = expected_file
        with mock.patch('artefact.localhost.file.os.path.getctime',
                        MagicMock(return_value=1622795612.874454)):
            collector._collect_timestamps()

        actual_created_time_data = collector._metadata['Created']

        self.assertEqual(expected_created_time_data, actual_created_time_data)
Esempio n. 7
0
    def test__collect_extended_attributes(self):
        """
        Should store extended attributes in data
        :return:
        """
        from artefact.localhost.file import FileMetadata

        expected_attribute = "my.extended.attribute"
        expected_message = f"Extended Attributes: {expected_attribute}"
        collector = FileMetadata(parameters={}, parent=None)
        collector.source_path = "mocked_file_path"
        with mock.patch('artefact.localhost.file.run_terminal_command',
                        MagicMock(return_value="my.extended.attribute")):
            collector._collect_extended_attributes()
            actual_message = collector.data[-1].collecteddata

        if platform.system() != "Windows":
            self.assertEqual(expected_message, actual_message)
        else:
            pass
Esempio n. 8
0
    def test__collectExtendedAttributes_on_file_with_ext_attribs(self):
        """
        Should store the extended attributes in data
        :return:
        """
        from artefact.localhost.file import FileMetadata

        expected_data = "Extended Attributes: com.apple.FinderInfo\n"
        expected_filepath = "/opt/local/var/macports"
        collector: FileMetadata = FileMetadata(parameters={}, parent=None)
        collector.source_path = expected_filepath
        collector._collect_extended_attributes()

        actual_data = collector.data[-1].collecteddata

        self.assertEqual(expected_data, actual_data)