Skip to content

Commit

Permalink
Code review: 221880043: Added more formatter tests for issue #99.
Browse files Browse the repository at this point in the history
  • Loading branch information
joachimmetz committed Mar 27, 2015
1 parent 7f20a56 commit 07b3284
Show file tree
Hide file tree
Showing 26 changed files with 495 additions and 64 deletions.
2 changes: 1 addition & 1 deletion config/dpkg/changelog
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ python-plaso (1.2.1-1) unstable; urgency=low

* Auto-generated

-- Log2Timeline <log2timeline-dev@googlegroups.com> Fri, 27 Mar 2015 13:44:09 +0100
-- Log2Timeline <log2timeline-dev@googlegroups.com> Fri, 27 Mar 2015 13:49:39 +0100
2 changes: 1 addition & 1 deletion plaso/formatters/filestat.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def GetSources(self, event_object):
WrongFormatter: if the event object cannot be formatted by the formatter.
"""
if self.DATA_TYPE != event_object.data_type:
raise errors.WrongFormatter('Unsupported data type: {0:s}.'.format(
raise errors.WrongFormatter(u'Unsupported data type: {0:s}.'.format(
event_object.data_type))

fs_type = getattr(event_object, u'fs_type', u'Unknown FS')
Expand Down
6 changes: 4 additions & 2 deletions plaso/formatters/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def _FormatMessage(self, format_string, event_values):
The formatted message string.
"""
# TODO: this does not work in Python 3.
# pylint: disable=logging-format-interpolation
if not isinstance(format_string, unicode):
logging.warning(u'Format string: {0:s} is non-Unicode.'.format(
format_string))
Expand Down Expand Up @@ -162,7 +163,7 @@ def GetSources(self, event_object):
WrongFormatter: if the event object cannot be formatted by the formatter.
"""
if self.DATA_TYPE != event_object.data_type:
raise errors.WrongFormatter('Unsupported data type: {0:s}.'.format(
raise errors.WrongFormatter(u'Unsupported data type: {0:s}.'.format(
event_object.data_type))

return self.SOURCE_SHORT, self.SOURCE_LONG
Expand Down Expand Up @@ -258,6 +259,7 @@ def _ConditionalFormatMessages(self, event_values):
# If an attribute is an int, yet has zero value we want to include
# that in the format string, since that is still potentially valid
# information. Otherwise we would like to skip it.
# pylint: disable=unidiomatic-typecheck
if type(attribute) not in (bool, int, long, float) and not attribute:
continue
string_pieces.append(self.FORMAT_STRING_PIECES[map_index])
Expand All @@ -284,7 +286,7 @@ def GetFormatStringAttributeNames(self):
self._format_string_attribute_names = []
for format_string_piece in self.FORMAT_STRING_PIECES:
attribute_names = self._FORMAT_STRING_ATTRIBUTE_NAME_RE.findall(
format_string_piece)
format_string_piece)

if attribute_names:
self._format_string_attribute_names.extend(attribute_names)
Expand Down
4 changes: 2 additions & 2 deletions plaso/formatters/pcap.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
"""Formatter for PCAP files."""
"""The PCAP event formatter."""

from plaso.formatters import interface
from plaso.formatters import manager
Expand All @@ -9,7 +9,7 @@


class PCAPFormatter(interface.ConditionalEventFormatter):
"""Define the formatting PCAP record."""
"""Formatter for a PCAP event."""

DATA_TYPE = 'metadata:pcap'

Expand Down
44 changes: 44 additions & 0 deletions plaso/formatters/pcap_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""Tests for the PCAP event formatter."""

import unittest

from plaso.formatters import pcap
from plaso.formatters import test_lib


class PCAPFormatterTest(test_lib.EventFormatterTestCase):
"""Tests for the PCAP event formatter."""

def testInitialization(self):
"""Tests the initialization."""
event_formatter = pcap.PCAPFormatter()
self.assertNotEqual(event_formatter, None)

def testGetFormatStringAttributeNames(self):
"""Tests the GetFormatStringAttributeNames function."""
event_formatter = pcap.PCAPFormatter()

expected_attribute_names = [
u'source_ip',
u'dest_ip',
u'source_port',
u'dest_port',
u'protocol',
u'stream_type',
u'size',
u'protocol_data',
u'stream_data',
u'first_packet_id',
u'last_packet_id',
u'packet_count']

self._TestGetFormatStringAttributeNames(
event_formatter, expected_attribute_names)

# TODO: add test for GetMessages.


if __name__ == '__main__':
unittest.main()
4 changes: 2 additions & 2 deletions plaso/formatters/plist.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# -*- coding: utf-8 -*-
"""This file contains a formatter for Plist Events."""
"""The plist event formatter."""

from plaso.formatters import interface
from plaso.formatters import manager


class PlistFormatter(interface.ConditionalEventFormatter):
"""Event Formatter for plist keys."""
"""Formatter for a plist key event."""

DATA_TYPE = 'plist:key'

Expand Down
35 changes: 35 additions & 0 deletions plaso/formatters/plist_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""Tests for the plist event formatter."""

import unittest

from plaso.formatters import plist
from plaso.formatters import test_lib


class PlistFormatterTest(test_lib.EventFormatterTestCase):
"""Tests for the plist event formatter."""

def testInitialization(self):
"""Tests the initialization."""
event_formatter = plist.PlistFormatter()
self.assertNotEqual(event_formatter, None)

def testGetFormatStringAttributeNames(self):
"""Tests the GetFormatStringAttributeNames function."""
event_formatter = plist.PlistFormatter()

expected_attribute_names = [
u'root',
u'key',
u'desc']

self._TestGetFormatStringAttributeNames(
event_formatter, expected_attribute_names)

# TODO: add test for GetMessages.


if __name__ == '__main__':
unittest.main()
6 changes: 3 additions & 3 deletions plaso/formatters/pls_recall.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# -*- coding: utf-8 -*-
"""Formatter for PL-Sql Recall events."""
"""The PL/SQL Recall event formatter."""

from plaso.formatters import interface
from plaso.formatters import manager


class PlsRecallFormatter(interface.EventFormatter):
"""Formatter for a for a PL-Sql Recall file container."""
"""Formatter for a PL/SQL Recall file container event."""
DATA_TYPE = 'PLSRecall:event'
SOURCE_LONG = 'PL-Sql Developer Recall file'
SOURCE_LONG = 'PL/SQL Developer Recall file'
SOURCE_SHORT = 'PLSRecall'

# The format string.
Expand Down
36 changes: 36 additions & 0 deletions plaso/formatters/pls_recall_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""Tests for the PL/SQL Recall event formatter."""

import unittest

from plaso.formatters import pls_recall
from plaso.formatters import test_lib


class PlsRecallFormatterTest(test_lib.EventFormatterTestCase):
"""Tests for the PL/SQL Recall file container event formatter."""

def testInitialization(self):
"""Tests the initialization."""
event_formatter = pls_recall.PlsRecallFormatter()
self.assertNotEqual(event_formatter, None)

def testGetFormatStringAttributeNames(self):
"""Tests the GetFormatStringAttributeNames function."""
event_formatter = pls_recall.PlsRecallFormatter()

expected_attribute_names = [
u'sequence',
u'username',
u'database_name',
u'query']

self._TestGetFormatStringAttributeNames(
event_formatter, expected_attribute_names)

# TODO: add test for GetMessages.


if __name__ == '__main__':
unittest.main()
6 changes: 3 additions & 3 deletions plaso/formatters/popcontest.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# -*- coding: utf-8 -*-
"""Formatter for the Popularity Contest parser events."""
"""The Popularity Contest event formatters."""

from plaso.formatters import interface
from plaso.formatters import manager


class PopularityContestSessionFormatter(interface.ConditionalEventFormatter):
"""Formatter for Popularity Contest Session information."""
"""Formatter for a Popularity Contest Session information event."""

DATA_TYPE = 'popularity_contest:session:event'

Expand All @@ -25,7 +25,7 @@ class PopularityContestSessionFormatter(interface.ConditionalEventFormatter):


class PopularityContestLogFormatter(interface.ConditionalEventFormatter):
"""Formatter for Popularity Contest Log events."""
"""Formatter for a Popularity Contest Log event."""

DATA_TYPE = 'popularity_contest:log:event'

Expand Down
59 changes: 59 additions & 0 deletions plaso/formatters/popcontest_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""Tests for the Popularity Contest event formatters."""

import unittest

from plaso.formatters import popcontest
from plaso.formatters import test_lib


class PopularityContestSessionFormatterTest(test_lib.EventFormatterTestCase):
"""Tests for the PCAP event formatter."""

def testInitialization(self):
"""Tests the initialization."""
event_formatter = popcontest.PopularityContestSessionFormatter()
self.assertNotEqual(event_formatter, None)

def testGetFormatStringAttributeNames(self):
"""Tests the GetFormatStringAttributeNames function."""
event_formatter = popcontest.PopularityContestSessionFormatter()

expected_attribute_names = [
u'session',
u'status',
u'hostid',
u'details']

self._TestGetFormatStringAttributeNames(
event_formatter, expected_attribute_names)

# TODO: add test for GetMessages.


class PopularityContestLogFormatterTest(test_lib.EventFormatterTestCase):
"""Tests for the PCAP event formatter."""

def testInitialization(self):
"""Tests the initialization."""
event_formatter = popcontest.PopularityContestLogFormatter()
self.assertNotEqual(event_formatter, None)

def testGetFormatStringAttributeNames(self):
"""Tests the GetFormatStringAttributeNames function."""
event_formatter = popcontest.PopularityContestLogFormatter()

expected_attribute_names = [
u'mru',
u'package',
u'record_tag']

self._TestGetFormatStringAttributeNames(
event_formatter, expected_attribute_names)

# TODO: add test for GetMessages.


if __name__ == '__main__':
unittest.main()
58 changes: 29 additions & 29 deletions plaso/formatters/recycler.py
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
# -*- coding: utf-8 -*-
"""Formatter for the Windows recycle files."""
"""The Windows Recycler/Recycle Bin formatter."""

from plaso.formatters import interface
from plaso.formatters import manager
from plaso.lib import errors


class WinRecyclerFormatter(interface.ConditionalEventFormatter):
"""Formatter for Windows recycle bin events."""
"""Formatter for a Windows Recycler/Recycle Bin file event."""

DATA_TYPE = 'windows:metadata:deleted_item'

_DRIVE_LETTER = {
0x00: 'A',
0x01: 'B',
0x02: 'C',
0x03: 'D',
0x04: 'E',
0x05: 'F',
0x06: 'G',
0x07: 'H',
0x08: 'I',
0x09: 'J',
0x0A: 'K',
0x0B: 'L',
0x0C: 'M',
0x0D: 'N',
0x0E: 'O',
0x0F: 'P',
0x10: 'Q',
0x11: 'R',
0x12: 'S',
0x13: 'T',
0x14: 'U',
0x15: 'V',
0x16: 'W',
0x17: 'X',
0x18: 'Y',
0x19: 'Z',
0x00: u'A',
0x01: u'B',
0x02: u'C',
0x03: u'D',
0x04: u'E',
0x05: u'F',
0x06: u'G',
0x07: u'H',
0x08: u'I',
0x09: u'J',
0x0A: u'K',
0x0B: u'L',
0x0C: u'M',
0x0D: u'N',
0x0E: u'O',
0x0F: u'P',
0x10: u'Q',
0x11: u'R',
0x12: u'S',
0x13: u'T',
0x14: u'U',
0x15: u'V',
0x16: u'W',
0x17: u'X',
0x18: u'Y',
0x19: u'Z',
}

# The format string.
Expand Down Expand Up @@ -68,7 +68,7 @@ def GetMessages(self, unused_formatter_mediator, event_object):
WrongFormatter: if the event object cannot be formatted by the formatter.
"""
if self.DATA_TYPE != event_object.data_type:
raise errors.WrongFormatter('Unsupported data type: {0:s}.'.format(
raise errors.WrongFormatter(u'Unsupported data type: {0:s}.'.format(
event_object.data_type))

event_values = event_object.GetValues()
Expand Down
Loading

0 comments on commit 07b3284

Please sign in to comment.