Skip to content

Commit

Permalink
Code review: 330570043: Made Unicode strings the default in bencode, …
Browse files Browse the repository at this point in the history
…cookie, ESEDB, OLECF, plist and syslog parser plugins tests #1268
  • Loading branch information
joachimmetz committed Oct 20, 2017
1 parent eaeeab8 commit bd6b721
Show file tree
Hide file tree
Showing 31 changed files with 448 additions and 383 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 @@ plaso (20171020-1) unstable; urgency=low

* Auto-generated

-- Log2Timeline <[email protected]> Fri, 20 Oct 2017 06:34:17 +0200
-- Log2Timeline <[email protected]> Fri, 20 Oct 2017 06:38:54 +0200
2 changes: 2 additions & 0 deletions tests/parsers/bencode_plugins/test_lib.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# -*- coding: utf-8 -*-
"""Bencode plugin related functions and classes for testing."""

from __future__ import unicode_literals

from tests.parsers import test_lib


Expand Down
14 changes: 8 additions & 6 deletions tests/parsers/bencode_plugins/transmission.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
# -*- coding: utf-8 -*-
"""Tests for the bencode parser plugin for Transmission BitTorrent files."""

from __future__ import unicode_literals

import unittest

from plaso.formatters import bencode_parser # pylint: disable=unused-import
from plaso.formatters import bencode_parser as _ # pylint: disable=unused-import
from plaso.lib import definitions
from plaso.lib import timelib
from plaso.parsers import bencode_parser
Expand All @@ -16,11 +18,11 @@
class BencodeTest(test_lib.BencodePluginTestCase):
"""Tests for bencode parser plugin for Transmission BitTorrent files."""

@shared_test_lib.skipUnlessHasTestFile([u'bencode_transmission'])
@shared_test_lib.skipUnlessHasTestFile(['bencode_transmission'])
def testProcess(self):
"""Tests the Process function."""
parser = bencode_parser.BencodeParser()
storage_writer = self._ParseFile([u'bencode_transmission'], parser)
storage_writer = self._ParseFile(['bencode_transmission'], parser)

self.assertEqual(storage_writer.number_of_events, 3)

Expand All @@ -30,7 +32,7 @@ def testProcess(self):

event = events[0]

expected_destination = u'/Users/brian/Downloads'
expected_destination = '/Users/brian/Downloads'
self.assertEqual(event.destination, expected_destination)

self.assertEqual(event.seedtime, 4)
Expand All @@ -39,7 +41,7 @@ def testProcess(self):
self.assertEqual(event.timestamp_desc, expected_description)

expected_timestamp = timelib.Timestamp.CopyFromString(
u'2013-11-08 15:31:20')
'2013-11-08 15:31:20')
self.assertEqual(event.timestamp, expected_timestamp)

# Test on second event of first torrent.
Expand All @@ -51,7 +53,7 @@ def testProcess(self):
self.assertEqual(event.timestamp_desc, expected_description)

expected_timestamp = timelib.Timestamp.CopyFromString(
u'2013-11-08 18:24:24')
'2013-11-08 18:24:24')
self.assertEqual(event.timestamp, expected_timestamp)


Expand Down
21 changes: 12 additions & 9 deletions tests/parsers/bencode_plugins/utorrent.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
# -*- coding: utf-8 -*-
"""Tests for the bencode parser plugin for uTorrent files."""

from __future__ import unicode_literals

import unittest

from plaso.formatters import bencode_parser # pylint: disable=unused-import
# pylint: disable=unused-import
from plaso.formatters import bencode_parser as _
from plaso.lib import definitions
from plaso.lib import timelib
from plaso.parsers import bencode_parser
Expand All @@ -16,20 +19,20 @@
class UTorrentPluginTest(test_lib.BencodePluginTestCase):
"""Tests for bencode parser plugin for uTorrent files."""

@shared_test_lib.skipUnlessHasTestFile([u'bencode_utorrent'])
@shared_test_lib.skipUnlessHasTestFile(['bencode_utorrent'])
def testProcess(self):
"""Tests the Process function."""
parser = bencode_parser.BencodeParser()
storage_writer = self._ParseFile([u'bencode_utorrent'], parser)
storage_writer = self._ParseFile(['bencode_utorrent'], parser)

self.assertEqual(storage_writer.number_of_events, 4)

# The order in which BencodeParser generates events is nondeterministic
# hence we sort the events.
events = list(storage_writer.GetSortedEvents())

expected_caption = u'plaso test'
expected_path = u'e:\\torrent\\files\\plaso test'
expected_caption = 'plaso test'
expected_path = 'e:\\torrent\\files\\plaso test'

# First test on when the torrent was added to the client.
event = events[0]
Expand All @@ -42,7 +45,7 @@ def testProcess(self):
self.assertEqual(event.timestamp_desc, expected_description)

expected_timestamp = timelib.Timestamp.CopyFromString(
u'2013-08-03 14:52:12')
'2013-08-03 14:52:12')
self.assertEqual(event.timestamp, expected_timestamp)

# Second test on when the torrent file was completely downloaded.
Expand All @@ -56,7 +59,7 @@ def testProcess(self):
self.assertEqual(event.timestamp_desc, expected_description)

expected_timestamp = timelib.Timestamp.CopyFromString(
u'2013-08-03 18:11:35')
'2013-08-03 18:11:35')
self.assertEqual(event.timestamp, expected_timestamp)

# Third test on when the torrent was first modified.
Expand All @@ -70,7 +73,7 @@ def testProcess(self):
self.assertEqual(event.timestamp_desc, expected_description)

expected_timestamp = timelib.Timestamp.CopyFromString(
u'2013-08-03 18:11:34')
'2013-08-03 18:11:34')
self.assertEqual(event.timestamp, expected_timestamp)

# Fourth test on when the torrent was again modified.
Expand All @@ -84,7 +87,7 @@ def testProcess(self):
self.assertEqual(event.timestamp_desc, expected_description)

expected_timestamp = timelib.Timestamp.CopyFromString(
u'2013-08-03 16:27:59')
'2013-08-03 16:27:59')
self.assertEqual(event.timestamp, expected_timestamp)


Expand Down
78 changes: 40 additions & 38 deletions tests/parsers/cookie_plugins/ganalytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
# -*- coding: utf-8 -*-
"""Tests for the Google Analytics cookies."""

from __future__ import unicode_literals

import unittest

from plaso.formatters import ganalytics # pylint: disable=unused-import
from plaso.formatters import ganalytics as _ # pylint: disable=unused-import
from plaso.lib import definitions
from plaso.lib import timelib
from plaso.parsers.cookie_plugins import ganalytics
Expand All @@ -26,16 +28,16 @@ def _GetAnalyticsCookieEvents(self, storage_writer):
"""
cookies = []
for event in storage_writer.GetEvents():
if event.data_type.startswith(u'cookie:google:analytics'):
if event.data_type.startswith('cookie:google:analytics'):
cookies.append(event)
return cookies

@shared_test_lib.skipUnlessHasTestFile([u'firefox_cookies.sqlite'])
@shared_test_lib.skipUnlessHasTestFile(['firefox_cookies.sqlite'])
def testParsingFirefox29CookieDatabase(self):
"""Tests the Process function on a Firefox 29 cookie database file."""
plugin = firefox_cookies.FirefoxCookiePlugin()
storage_writer = self._ParseDatabaseFileWithPlugin(
[u'firefox_cookies.sqlite'], plugin)
['firefox_cookies.sqlite'], plugin)
events = self._GetAnalyticsCookieEvents(storage_writer)

self.assertEqual(len(events), 25)
Expand All @@ -44,29 +46,29 @@ def testParsingFirefox29CookieDatabase(self):

self.assertEqual(
event.utmcct,
u'/frettir/erlent/2013/10/30/maelt_med_kerfisbundnum_hydingum/')
'/frettir/erlent/2013/10/30/maelt_med_kerfisbundnum_hydingum/')
expected_timestamp = timelib.Timestamp.CopyFromString(
u'2013-10-30 21:56:06')
'2013-10-30 21:56:06')
self.assertEqual(event.timestamp, expected_timestamp)
self.assertEqual(event.url, u'http://ads.aha.is/')
self.assertEqual(event.utmcsr, u'mbl.is')
self.assertEqual(event.url, 'http://ads.aha.is/')
self.assertEqual(event.utmcsr, 'mbl.is')

expected_message = (
u'http://ads.aha.is/ (__utmz) Sessions: 1 Domain Hash: 137167072 '
u'Sources: 1 Last source used to access: mbl.is Ad campaign '
u'information: (referral) Last type of visit: referral Path to '
u'the page of referring link: /frettir/erlent/2013/10/30/'
u'maelt_med_kerfisbundnum_hydingum/')
expected_short_message = u'http://ads.aha.is/ (__utmz)'
'http://ads.aha.is/ (__utmz) Sessions: 1 Domain Hash: 137167072 '
'Sources: 1 Last source used to access: mbl.is Ad campaign '
'information: (referral) Last type of visit: referral Path to '
'the page of referring link: /frettir/erlent/2013/10/30/'
'maelt_med_kerfisbundnum_hydingum/')
expected_short_message = 'http://ads.aha.is/ (__utmz)'

self._TestGetMessageStrings(event, expected_message, expected_short_message)

@shared_test_lib.skipUnlessHasTestFile([u'cookies.db'])
@shared_test_lib.skipUnlessHasTestFile(['cookies.db'])
def testParsingChromeCookieDatabase(self):
"""Test the process function on a Chrome cookie database."""
plugin = chrome_cookies.ChromeCookiePlugin()
storage_writer = self._ParseDatabaseFileWithPlugin(
[u'cookies.db'], plugin)
['cookies.db'], plugin)
events = self._GetAnalyticsCookieEvents(storage_writer)

# The cookie database contains 560 entries in total. Out of them
Expand All @@ -76,55 +78,55 @@ def testParsingChromeCookieDatabase(self):

# Check an UTMZ Google Analytics event.
event = events[39]
self.assertEqual(event.utmctr, u'enders game')
self.assertEqual(event.domain_hash, u'68898382')
self.assertEqual(event.utmctr, 'enders game')
self.assertEqual(event.domain_hash, '68898382')
self.assertEqual(event.sessions, 1)

expected_message = (
u'http://imdb.com/ (__utmz) Sessions: 1 Domain Hash: 68898382 '
u'Sources: 1 Last source used to access: google Ad campaign '
u'information: (organic) Last type of visit: organic Keywords '
u'used to find site: enders game')
expected_short_message = u'http://imdb.com/ (__utmz)'
'http://imdb.com/ (__utmz) Sessions: 1 Domain Hash: 68898382 '
'Sources: 1 Last source used to access: google Ad campaign '
'information: (organic) Last type of visit: organic Keywords '
'used to find site: enders game')
expected_short_message = 'http://imdb.com/ (__utmz)'

self._TestGetMessageStrings(event, expected_message, expected_short_message)

# Check the UTMA Google Analytics event.
event = events[41]
self.assertEqual(event.timestamp_desc, u'Analytics Previous Time')
self.assertEqual(event.cookie_name, u'__utma')
self.assertEqual(event.visitor_id, u'1827102436')
self.assertEqual(event.timestamp_desc, 'Analytics Previous Time')
self.assertEqual(event.cookie_name, '__utma')
self.assertEqual(event.visitor_id, '1827102436')
self.assertEqual(event.sessions, 2)

expected_timestamp = timelib.Timestamp.CopyFromString(
u'2012-03-22 01:55:29')
'2012-03-22 01:55:29')
self.assertEqual(event.timestamp, expected_timestamp)

expected_message = (
u'http://assets.tumblr.com/ (__utma) '
u'Sessions: 2 '
u'Domain Hash: 151488169 '
u'Visitor ID: 1827102436')
expected_short_message = u'http://assets.tumblr.com/ (__utma)'
'http://assets.tumblr.com/ (__utma) '
'Sessions: 2 '
'Domain Hash: 151488169 '
'Visitor ID: 1827102436')
expected_short_message = 'http://assets.tumblr.com/ (__utma)'

self._TestGetMessageStrings(event, expected_message, expected_short_message)

# Check the UTMB Google Analytics event.
event = events[34]
self.assertEqual(
event.timestamp_desc, definitions.TIME_DESCRIPTION_LAST_VISITED)
self.assertEqual(event.cookie_name, u'__utmb')
self.assertEqual(event.domain_hash, u'154523900')
self.assertEqual(event.cookie_name, '__utmb')
self.assertEqual(event.domain_hash, '154523900')
self.assertEqual(event.pages_viewed, 1)

expected_timestamp = timelib.Timestamp.CopyFromString(
u'2012-03-22 01:48:30')
'2012-03-22 01:48:30')
self.assertEqual(event.timestamp, expected_timestamp)

expected_message = (
u'http://upressonline.com/ (__utmb) Pages Viewed: 1 Domain Hash: '
u'154523900')
expected_short_message = u'http://upressonline.com/ (__utmb)'
'http://upressonline.com/ (__utmb) Pages Viewed: 1 Domain Hash: '
'154523900')
expected_short_message = 'http://upressonline.com/ (__utmb)'

self._TestGetMessageStrings(event, expected_message, expected_short_message)

Expand Down
6 changes: 4 additions & 2 deletions tests/parsers/cookie_plugins/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# -*- coding: utf-8 -*-
"""Tests for the cookie plugins manager."""

from __future__ import unicode_literals

import unittest

from plaso.parsers.cookie_plugins import interface
Expand All @@ -11,8 +13,8 @@
class TestCookiePlugin(interface.BaseCookiePlugin):
"""Test cookie plugin."""

NAME = u'test_cookie_plugin'
DESCRIPTION = u'Test cookie plugin.'
NAME = 'test_cookie_plugin'
DESCRIPTION = 'Test cookie plugin.'

def GetEntries(
self, unused_parser_mediator, cookie_data=None, url=None, **kwargs):
Expand Down
2 changes: 2 additions & 0 deletions tests/parsers/cookie_plugins/test_lib.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# -*- coding: utf-8 -*-
"""Browser cookie plugin related functions and classes for testing."""

from __future__ import unicode_literals

from tests.parsers import test_lib


Expand Down
24 changes: 13 additions & 11 deletions tests/parsers/esedb_plugins/file_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
# -*- coding: utf-8 -*-
"""Tests for the File History ESE database file."""

from __future__ import unicode_literals

import unittest

from plaso.formatters import file_history # pylint: disable=unused-import
from plaso.formatters import file_history as _ # pylint: disable=unused-import
from plaso.lib import definitions
from plaso.lib import timelib
from plaso.parsers.esedb_plugins import file_history
Expand All @@ -16,12 +18,12 @@
class FileHistoryESEDBPluginTest(test_lib.ESEDBPluginTestCase):
"""Tests for the File History ESE database plugin."""

@shared_test_lib.skipUnlessHasTestFile([u'Catalog1.edb'])
@shared_test_lib.skipUnlessHasTestFile(['Catalog1.edb'])
def testProcess(self):
"""Tests the Process function."""
plugin = file_history.FileHistoryESEDBPlugin()
storage_writer = self._ParseESEDBFileWithPlugin(
[u'Catalog1.edb'], plugin)
['Catalog1.edb'], plugin)

self.assertEqual(storage_writer.number_of_events, 2713)

Expand All @@ -33,23 +35,23 @@ def testProcess(self):
self.assertEqual(event.identifier, 356)

expected_timestamp = timelib.Timestamp.CopyFromString(
u'2013-10-12 17:34:36.688580')
'2013-10-12 17:34:36.688580')

self.assertEqual(event.timestamp, expected_timestamp)
self.assertEqual(
event.timestamp_desc, definitions.TIME_DESCRIPTION_MODIFICATION)

filename = u'?UP\\Favorites\\Links\\Lenovo'
filename = '?UP\\Favorites\\Links\\Lenovo'
self.assertEqual(event.original_filename, filename)

expected_message = (
u'Filename: {0:s} '
u'Identifier: 356 '
u'Parent Identifier: 230 '
u'Attributes: 16 '
u'USN number: 9251162904').format(filename)
'Filename: {0:s} '
'Identifier: 356 '
'Parent Identifier: 230 '
'Attributes: 16 '
'USN number: 9251162904').format(filename)

expected_short_message = u'Filename: {0:s}'.format(filename)
expected_short_message = 'Filename: {0:s}'.format(filename)

self._TestGetMessageStrings(event, expected_message, expected_short_message)

Expand Down
Loading

0 comments on commit bd6b721

Please sign in to comment.