Skip to content

Commit

Permalink
Code review: 331980043: Made Unicode strings the default in parsers t…
Browse files Browse the repository at this point in the history
…ests #1268
  • Loading branch information
joachimmetz committed Oct 20, 2017
1 parent e123f94 commit eaeeab8
Show file tree
Hide file tree
Showing 59 changed files with 1,863 additions and 1,741 deletions.
4 changes: 2 additions & 2 deletions config/dpkg/changelog
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plaso (20171019-1) unstable; urgency=low
plaso (20171020-1) unstable; urgency=low

* Auto-generated

-- Log2Timeline <[email protected]> Thu, 19 Oct 2017 16:16:06 -0700
-- Log2Timeline <[email protected]> Fri, 20 Oct 2017 06:34:17 +0200
2 changes: 1 addition & 1 deletion plaso/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
of log2timeline.
"""

__version__ = '20171019'
__version__ = '20171020'
3 changes: 3 additions & 0 deletions tests/parsers/amcache.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""Tests for the Amcache Registry plugin."""

from __future__ import unicode_literals

import unittest

from plaso.lib import timelib
Expand All @@ -12,6 +13,7 @@

__author__ = 'Ramses de Beer, [email protected]'


class AmcacheParserTest(test_lib.ParserTestCase):
"""Tests for the Amcache Registry plugin."""

Expand Down Expand Up @@ -53,5 +55,6 @@ def testParse(self):
expected_publisher = ('McAfee Inc.')
self.assertEqual(event.publisher, expected_publisher)


if __name__ == '__main__':
unittest.main()
41 changes: 22 additions & 19 deletions tests/parsers/android_app_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
# -*- coding: utf-8 -*-
"""Tests for the Android Application Usage history parsers."""

from __future__ import unicode_literals

import unittest

from plaso.formatters import android_app_usage # pylint: disable=unused-import
# pylint: disable=unused-import
from plaso.formatters import android_app_usage as _
from plaso.lib import timelib
from plaso.parsers import android_app_usage

Expand All @@ -15,12 +18,12 @@
class AndroidAppUsageParserTest(test_lib.ParserTestCase):
"""Tests for the Android Application Usage History parser."""

@shared_test_lib.skipUnlessHasTestFile([u'usage-history.xml'])
@shared_test_lib.skipUnlessHasTestFile(['usage-history.xml'])
def testParse(self):
"""Tests the Parse function."""
parser = android_app_usage.AndroidAppUsageParser()
storage_writer = self._ParseFile(
[u'usage-history.xml'], parser)
['usage-history.xml'], parser)

self.assertEqual(storage_writer.number_of_events, 28)

Expand All @@ -29,38 +32,38 @@ def testParse(self):
event = events[22]

expected_timestamp = timelib.Timestamp.CopyFromString(
u'2013-12-09 19:28:33.047000')
'2013-12-09 19:28:33.047000')
self.assertEqual(event.timestamp, expected_timestamp)
self.assertEqual(
event.component,
u'com.sec.android.widgetapp.ap.hero.accuweather.menu.MenuAdd')
'com.sec.android.widgetapp.ap.hero.accuweather.menu.MenuAdd')

expected_message = (
u'Package: '
u'com.sec.android.widgetapp.ap.hero.accuweather '
u'Component: '
u'com.sec.android.widgetapp.ap.hero.accuweather.menu.MenuAdd')
'Package: '
'com.sec.android.widgetapp.ap.hero.accuweather '
'Component: '
'com.sec.android.widgetapp.ap.hero.accuweather.menu.MenuAdd')
expected_short_message = (
u'Package: com.sec.android.widgetapp.ap.hero.accuweather '
u'Component: com.sec.and...')
'Package: com.sec.android.widgetapp.ap.hero.accuweather '
'Component: com.sec.and...')

self._TestGetMessageStrings(event, expected_message, expected_short_message)

event = events[17]

expected_timestamp = timelib.Timestamp.CopyFromString(
u'2013-09-27 19:45:55.675000')
'2013-09-27 19:45:55.675000')
self.assertEqual(event.timestamp, expected_timestamp)
self.assertEqual(event.package, u'com.google.android.gsf.login')
self.assertEqual(event.package, 'com.google.android.gsf.login')

expected_message = (
u'Package: '
u'com.google.android.gsf.login '
u'Component: '
u'com.google.android.gsf.login.NameActivity')
'Package: '
'com.google.android.gsf.login '
'Component: '
'com.google.android.gsf.login.NameActivity')
expected_short_message = (
u'Package: com.google.android.gsf.login '
u'Component: com.google.android.gsf.login...')
'Package: com.google.android.gsf.login '
'Component: com.google.android.gsf.login...')

self._TestGetMessageStrings(event, expected_message, expected_short_message)

Expand Down
54 changes: 28 additions & 26 deletions tests/parsers/asl.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
# -*- coding: utf-8 -*-
"""Tests for Apple System Log file parser."""

from __future__ import unicode_literals

import unittest

from plaso.formatters import asl # pylint: disable=unused-import
from plaso.formatters import asl as _ # pylint: disable=unused-import
from plaso.lib import timelib
from plaso.parsers import asl

Expand All @@ -15,12 +17,12 @@
class ASLParserTest(test_lib.ParserTestCase):
"""Tests for Apple System Log file parser."""

@shared_test_lib.skipUnlessHasTestFile([u'applesystemlog.asl'])
@shared_test_lib.skipUnlessHasTestFile(['applesystemlog.asl'])
def testParse(self):
"""Tests the Parse function."""
parser = asl.ASLParser()
storage_writer = self._ParseFile(
[u'applesystemlog.asl'], parser)
['applesystemlog.asl'], parser)

self.assertEqual(storage_writer.number_of_events, 2)

Expand All @@ -29,16 +31,16 @@ def testParse(self):
event = events[0]

expected_timestamp = timelib.Timestamp.CopyFromString(
u'2013-11-25 09:45:35.705481')
'2013-11-25 09:45:35.705481')
self.assertEqual(event.timestamp, expected_timestamp)

self.assertEqual(event.record_position, 442)
self.assertEqual(event.message_id, 101406)
self.assertEqual(event.computer_name, u'DarkTemplar-2.local')
self.assertEqual(event.sender, u'locationd')
self.assertEqual(event.facility, u'com.apple.locationd')
self.assertEqual(event.computer_name, 'DarkTemplar-2.local')
self.assertEqual(event.sender, 'locationd')
self.assertEqual(event.facility, 'com.apple.locationd')
self.assertEqual(event.pid, 69)
self.assertEqual(event.user_sid, u'205')
self.assertEqual(event.user_sid, '205')
self.assertEqual(event.group_id, 205)
self.assertEqual(event.read_uid, 205)
self.assertEqual(event.read_gid, 0xffffffff)
Expand All @@ -47,34 +49,34 @@ def testParse(self):
# Note that "compatiblity" is spelt incorrectly in the actual message being
# tested here.
expected_message = (
u'Incorrect NSStringEncoding value 0x8000100 detected. '
u'Assuming NSASCIIStringEncoding. Will stop this compatiblity '
u'mapping behavior in the near future.')
'Incorrect NSStringEncoding value 0x8000100 detected. '
'Assuming NSASCIIStringEncoding. Will stop this compatiblity '
'mapping behavior in the near future.')

self.assertEqual(event.message, expected_message)

expected_extra = (
u'CFLog Local Time: 2013-11-25 09:45:35.701, '
u'CFLog Thread: 1007, '
u'Sender_Mach_UUID: 50E1F76A-60FF-368C-B74E-EB48F6D98C51')
'CFLog Local Time: 2013-11-25 09:45:35.701, '
'CFLog Thread: 1007, '
'Sender_Mach_UUID: 50E1F76A-60FF-368C-B74E-EB48F6D98C51')

self.assertEqual(event.extra_information, expected_extra)

expected_message = (
u'MessageID: 101406 '
u'Level: WARNING (4) '
u'User ID: 205 '
u'Group ID: 205 '
u'Read User: 205 '
u'Read Group: ALL '
u'Host: DarkTemplar-2.local '
u'Sender: locationd '
u'Facility: com.apple.locationd '
u'Message: {0:s} {1:s}').format(expected_message, expected_extra)
'MessageID: 101406 '
'Level: WARNING (4) '
'User ID: 205 '
'Group ID: 205 '
'Read User: 205 '
'Read Group: ALL '
'Host: DarkTemplar-2.local '
'Sender: locationd '
'Facility: com.apple.locationd '
'Message: {0:s} {1:s}').format(expected_message, expected_extra)

expected_short_message = (
u'Sender: locationd '
u'Facility: com.apple.locationd')
'Sender: locationd '
'Facility: com.apple.locationd')

self._TestGetMessageStrings(event, expected_message, expected_short_message)

Expand Down
23 changes: 13 additions & 10 deletions tests/parsers/bash_history.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# -*- coding: utf-8 -*- #
"""Tests for the bash history parser."""

from __future__ import unicode_literals

import unittest

from plaso.lib import timelib
Expand All @@ -23,42 +26,42 @@ def _TestEventsFromFile(self, storage_writer):
events = list(storage_writer.GetEvents())

expected_timestamp = timelib.Timestamp.CopyFromString(
u'2013-10-01 12:36:17')
expected_command = u'/usr/lib/plaso'
'2013-10-01 12:36:17')
expected_command = '/usr/lib/plaso'
self.assertEqual(events[0].timestamp, expected_timestamp)
self.assertEqual(events[0].command, expected_command)

expected_timestamp = timelib.Timestamp.CopyFromString(
u'2013-10-01 12:36:18')
expected_command = u'/bin/bash'
'2013-10-01 12:36:18')
expected_command = '/bin/bash'
self.assertEqual(events[1].timestamp, expected_timestamp)
self.assertEqual(events[1].command, expected_command)

expected_timestamp = timelib.Timestamp.CopyFromString(
u'2013-10-01 12:36:19')
expected_command = u'/usr/local/bin/splunk -p 8080'
'2013-10-01 12:36:19')
expected_command = '/usr/local/bin/splunk -p 8080'
self.assertEqual(events[2].timestamp, expected_timestamp)
self.assertEqual(events[2].command, expected_command)

@shared_test_lib.skipUnlessHasTestFile([u'bash_history_desync'])
@shared_test_lib.skipUnlessHasTestFile(['bash_history_desync'])
def testParsingExtractionDesync(self):
"""Tests that the parser correctly handles a desynchronized file.
A desynchronized file is one with half an event at the top. That is, it
starts with a command line instead of a timestamp.
"""
parser = bash_history.BashHistoryParser()
storage_writer = self._ParseFile([u'bash_history_desync'], parser)
storage_writer = self._ParseFile(['bash_history_desync'], parser)
self._TestEventsFromFile(storage_writer)

@shared_test_lib.skipUnlessHasTestFile([u'bash_history'])
@shared_test_lib.skipUnlessHasTestFile(['bash_history'])
def testParsingExtractionSync(self):
"""Tests that the parser correctly handles a synchronized file.
A synchronized file is one that starts with a timestamp line.
"""
parser = bash_history.BashHistoryParser()
storage_writer = self._ParseFile([u'bash_history'], parser)
storage_writer = self._ParseFile(['bash_history'], parser)
self._TestEventsFromFile(storage_writer)


Expand Down
4 changes: 3 additions & 1 deletion tests/parsers/bencode_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# -*- coding: utf-8 -*-
"""Tests for the Bencode file parser."""

from __future__ import unicode_literals

import unittest

from plaso.parsers import bencode_parser
Expand All @@ -19,7 +21,7 @@ class BencodeTest(test_lib.ParserTestCase):
def testEnablePlugins(self):
"""Tests the EnablePlugins function."""
parser = bencode_parser.BencodeParser()
parser.EnablePlugins([u'bencode_transmission'])
parser.EnablePlugins(['bencode_transmission'])

self.assertIsNotNone(parser)
self.assertIsNone(parser._default_plugin)
Expand Down
Loading

0 comments on commit eaeeab8

Please sign in to comment.