Esempio n. 1
0
  def testParse(self):
    """Tests the Parse function."""
    parser = czip.CompoundZIPParser()
    storage_writer = self._ParseFile(['syslog.zip'], parser)

    number_of_events = storage_writer.GetNumberOfAttributeContainers('event')
    self.assertEqual(number_of_events, 0)

    number_of_warnings = storage_writer.GetNumberOfAttributeContainers(
        'extraction_warning')
    self.assertEqual(number_of_warnings, 0)

    number_of_warnings = storage_writer.GetNumberOfAttributeContainers(
        'recovery_warning')
    self.assertEqual(number_of_warnings, 0)

    # Try parsing a file that is not a ZIP file.
    parser = czip.CompoundZIPParser()

    with self.assertRaises(errors.UnableToParseFile):
      storage_writer = self._ParseFile(['syslog.xz'], parser)

    # Try parsing a file that is not a ZIP file but looks like one.
    parser = czip.CompoundZIPParser()

    with self.assertRaises(errors.UnableToParseFile):
      storage_writer = self._ParseFile(['passes_is_zipfile.bin'], parser)
Esempio n. 2
0
    def testEnablePlugins(self):
        """Tests the EnablePlugins function."""
        parser = czip.CompoundZIPParser()
        parser.EnablePlugins(['oxml'])

        self.assertIsNotNone(parser)
        self.assertIsNone(parser._default_plugin)
        self.assertNotEqual(parser._plugins, [])
        self.assertEqual(len(parser._plugins), 1)
Esempio n. 3
0
  def testParseFileObject(self):
    """Tests the ParseFileObject function."""
    parser = czip.CompoundZIPParser()
    storage_writer = self._ParseFile(['Document.docx'], parser)

    self.assertEqual(storage_writer.number_of_warnings, 0)
    self.assertEqual(storage_writer.number_of_events, 2)

    events = list(storage_writer.GetEvents())

    event = events[0]

    self.CheckTimestamp(event.timestamp, '2012-11-07 23:29:00.000000')
    self.assertEqual(
        event.timestamp_desc, definitions.TIME_DESCRIPTION_CREATION)

    event = events[1]

    self.assertEqual(event.number_of_characters, '13')
    self.assertEqual(event.total_time, '1385')
    self.assertEqual(event.number_of_characters_with_spaces, '14')
    self.assertEqual(event.i4, '1')
    self.assertEqual(event.app_version, '14.0000')
    self.assertEqual(event.number_of_lines, '1')
    self.assertEqual(event.scale_crop, 'false')
    self.assertEqual(event.number_of_pages, '1')
    self.assertEqual(event.number_of_words, '2')
    self.assertEqual(event.links_up_to_date, 'false')
    self.assertEqual(event.number_of_paragraphs, '1')
    self.assertEqual(event.doc_security, '0')
    self.assertEqual(event.hyperlinks_changed, 'false')
    self.assertEqual(event.revision_number, '3')
    self.assertEqual(event.last_saved_by, 'Nides')
    self.assertEqual(event.author, 'Nides')
    self.assertEqual(event.creating_app, 'Microsoft Office Word')
    self.assertEqual(event.template, 'Normal.dotm')

    expected_message = (
        'Creating App: Microsoft Office Word '
        'App version: 14.0000 '
        'Last saved by: Nides '
        'Author: Nides '
        'Revision number: 3 '
        'Template: Normal.dotm '
        'Number of pages: 1 '
        'Number of words: 2 '
        'Number of characters: 13 '
        'Number of characters with spaces: 14 '
        'Number of lines: 1 '
        'Hyperlinks changed: false '
        'Links up to date: false '
        'Scale crop: false')
    expected_short_message = (
        'Author: Nides')

    self._TestGetMessageStrings(event, expected_message, expected_short_message)
Esempio n. 4
0
    def testParse(self):
        """Tests the Parse function."""
        parser = czip.CompoundZIPParser()
        storage_writer = self._ParseFile(['syslog.zip'], parser)

        self.assertEqual(storage_writer.number_of_warnings, 0)
        self.assertEqual(storage_writer.number_of_events, 0)

        # Try parsing a file that is not a ZIP file.
        parser = czip.CompoundZIPParser()

        with self.assertRaises(errors.UnableToParseFile):
            storage_writer = self._ParseFile(['syslog.xz'], parser)

        # Try parsing a file that is not a ZIP file but looks like one.
        parser = czip.CompoundZIPParser()

        with self.assertRaises(errors.UnableToParseFile):
            storage_writer = self._ParseFile(['passes_is_zipfile.bin'], parser)
Esempio n. 5
0
  def testEnablePlugins(self):
    """Tests the EnablePlugins function."""
    parser = czip.CompoundZIPParser()

    number_of_plugins = len(parser._plugin_classes)

    parser.EnablePlugins([])
    self.assertEqual(len(parser._plugins), 0)

    parser.EnablePlugins(parser.ALL_PLUGINS)
    self.assertEqual(len(parser._plugins), number_of_plugins)

    parser.EnablePlugins(['oxml'])
    self.assertEqual(len(parser._plugins), 1)