Beispiel #1
0
    def testParseWithXMLFileLookupError(self):
        """Tests the Parse function on an XML file that causes a LookupError."""
        parser = plist.PlistParser()
        storage_writer = self._ParseFile(['SAFStore.xml'], parser)

        self.assertEqual(storage_writer.number_of_warnings, 1)
        self.assertEqual(storage_writer.number_of_events, 0)
Beispiel #2
0
  def _ParsePlistFileWithPlugin(
      self, plugin, path_segments, plist_name,
      knowledge_base_values=None):
    """Parses a file using the parser and plugin object.

    Args:
      plugin (PlistPlugin): a plist plugin.
      path_segments (list[str]): the path segments inside the test data
          directory to the test file.
      plist_name (str): name of the plist to parse.
      knowledge_base_values (Optional[dict[str, object]]): knowledge base
          values.

    Returns:
      FakeStorageWriter: a storage writer.
    """
    file_entry = self._GetTestFileEntry(path_segments)
    file_object = file_entry.GetFileObject()

    parser = plist.PlistParser()
    top_level_object = parser.GetTopLevel(file_object)
    self.assertIsNotNone(top_level_object)

    return self._ParsePlistWithPlugin(
        plugin, plist_name, top_level_object,
        knowledge_base_values=knowledge_base_values)
Beispiel #3
0
    def _ParsePlistFileWithPlugin(self,
                                  plugin,
                                  path_segments,
                                  plist_name,
                                  knowledge_base_values=None):
        """Parses a file using the parser and plugin object.

    Args:
      plugin: a plist plugin object (instance of PlistPlugin).
      path_segments: the path segments inside the test data directory to the
                     test file.
      plist_name: the name of the plist to parse.
      knowledge_base_values: optional dict containing the knowledge base
                             values.

    Returns:
      A storage writer object (instance of FakeStorageWriter).
    """
        file_entry = self._GetTestFileEntry(path_segments)
        file_object = file_entry.GetFileObject()

        parser = plist.PlistParser()
        top_level_object = parser.GetTopLevel(file_object)
        self.assertIsNotNone(top_level_object)

        return self._ParsePlistWithPlugin(
            plugin,
            plist_name,
            top_level_object,
            knowledge_base_values=knowledge_base_values)
Beispiel #4
0
    def testParseWithPlistXMLFileNoTopLevel(self):
        """Tests the Parse function on a plist XML file without top level object."""
        parser = plist.PlistParser()
        storage_writer = self._ParseFile(['empty.plist'], parser)

        self.assertEqual(storage_writer.number_of_warnings, 1)
        self.assertEqual(storage_writer.number_of_events, 0)
Beispiel #5
0
    def testParseWithXMLFileLeadingWhitespace(self):
        """Tests the Parse function on an XML file with leading whitespace."""
        parser = plist.PlistParser()
        storage_writer = self._ParseFile(['leading_whitespace.plist'], parser)

        self.assertEqual(storage_writer.number_of_warnings, 1)
        self.assertEqual(storage_writer.number_of_events, 4)
Beispiel #6
0
    def testParse(self):
        """Tests the Parse function."""
        parser = plist.PlistParser()
        storage_writer = self._ParseFile(['plist_binary'], parser)

        self.assertEqual(storage_writer.number_of_events, 12)

        timestamps, roots, keys = zip(
            *[(event.timestamp, event.root, event.key)
              for event in storage_writer.GetEvents()])

        expected_timestamps = frozenset([
            1345251192528750, 1351827808261762, 1345251268370453,
            1351818803000000, 1351819298997672, 1351818797324095,
            1301012201414766, 1302199013524275, 1341957900020116,
            1350666391557044, 1350666385239661, 1341957896010535
        ])

        self.assertTrue(set(expected_timestamps) == set(timestamps))
        self.assertEqual(12, len(set(timestamps)))

        expected_roots = frozenset([
            '/DeviceCache/00-0d-fd-00-00-00', '/DeviceCache/44-00-00-00-00-00',
            '/DeviceCache/44-00-00-00-00-01', '/DeviceCache/44-00-00-00-00-02',
            '/DeviceCache/44-00-00-00-00-03', '/DeviceCache/44-00-00-00-00-04'
        ])
        self.assertTrue(expected_roots == set(roots))
        self.assertEqual(6, len(set(roots)))

        expected_keys = frozenset(
            ['LastInquiryUpdate', 'LastServicesUpdate', 'LastNameUpdate'])
        self.assertTrue(expected_keys == set(keys))
        self.assertEqual(3, len(set(keys)))
Beispiel #7
0
  def testParseWithXMLFileInvalidDate(self):
    """Tests the Parse function on an XML file with an invalid date and time."""
    parser = plist.PlistParser()
    storage_writer = self._ParseFile(['com.apple.security.KCN.plist'], parser)

    self.assertEqual(storage_writer.number_of_events, 0)
    self.assertEqual(storage_writer.number_of_extraction_warnings, 1)
    self.assertEqual(storage_writer.number_of_recovery_warnings, 0)
Beispiel #8
0
  def testParseWithXMLPlistFileNoTopLevel(self):
    """Tests the Parse function on an XML plist file without top level."""
    parser = plist.PlistParser()
    storage_writer = self._ParseFile(['empty.plist'], parser)

    self.assertEqual(storage_writer.number_of_events, 0)
    self.assertEqual(storage_writer.number_of_extraction_warnings, 1)
    self.assertEqual(storage_writer.number_of_recovery_warnings, 0)
Beispiel #9
0
    def testEnablePlugins(self):
        """Tests the EnablePlugins function."""
        parser = plist.PlistParser()
        parser.EnablePlugins(['airport'])

        self.assertIsNotNone(parser)
        self.assertIsNotNone(parser._default_plugin)
        self.assertNotEqual(parser._plugins, [])
        self.assertEqual(len(parser._plugins), 1)
Beispiel #10
0
  def testParseWithEmptyBinaryPlistFile(self):
    """Tests the Parse function on an empty binary plist file."""
    parser = plist.PlistParser()
    storage_writer = self._ParseFile([
        'com.apple.networkextension.uuidcache.plist'], parser)

    self.assertEqual(storage_writer.number_of_events, 0)
    self.assertEqual(storage_writer.number_of_extraction_warnings, 0)
    self.assertEqual(storage_writer.number_of_recovery_warnings, 0)
Beispiel #11
0
    def testEnablePlugins(self):
        """Tests the EnablePlugins function."""
        parser = plist.PlistParser()

        number_of_plugins = len(parser._plugin_classes)

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

        parser.EnablePlugins(parser.ALL_PLUGINS)
        # Extract 1 for the default plugin.
        self.assertEqual(len(parser._plugins), number_of_plugins - 1)

        parser.EnablePlugins(['airport'])
        self.assertEqual(len(parser._plugins), 1)
Beispiel #12
0
    def testParse(self):
        """Tests the Parse function."""
        parser = plist.PlistParser()
        storage_writer = self._ParseFile(['plist_binary'], parser)

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

        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)

        keys = set()
        roots = set()
        timestamps = set()
        for event in storage_writer.GetEvents():
            event_data = self._GetEventDataOfEvent(storage_writer, event)
            keys.add(event_data.key)
            roots.add(event_data.root)
            timestamps.add(event.timestamp)

        expected_timestamps = frozenset([
            1345251192528750, 1351827808261762, 1345251268370453,
            1351818803000000, 1351819298997673, 1351818797324095,
            1301012201414766, 1302199013524275, 1341957900020117,
            1350666391557044, 1350666385239662, 1341957896010535
        ])

        self.assertEqual(len(timestamps), 12)
        self.assertEqual(timestamps, expected_timestamps)

        expected_roots = frozenset([
            '/DeviceCache/00-0d-fd-00-00-00', '/DeviceCache/44-00-00-00-00-00',
            '/DeviceCache/44-00-00-00-00-01', '/DeviceCache/44-00-00-00-00-02',
            '/DeviceCache/44-00-00-00-00-03', '/DeviceCache/44-00-00-00-00-04'
        ])
        self.assertEqual(len(roots), 6)
        self.assertEqual(roots, expected_roots)

        expected_keys = frozenset(
            ['LastInquiryUpdate', 'LastServicesUpdate', 'LastNameUpdate'])
        self.assertEqual(len(keys), 3)
        self.assertTrue(keys, expected_keys)
Beispiel #13
0
    def testParseWithXMLFileLeadingWhitespace(self):
        """Tests the Parse function on an XML file with leading whitespace."""
        parser = plist.PlistParser()
        storage_writer = self._ParseFile(['leading_whitespace.plist'], parser)

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

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

        number_of_warnings = storage_writer.GetNumberOfAttributeContainers(
            'recovery_warning')
        self.assertEqual(number_of_warnings, 0)
Beispiel #14
0
    def testParseWithXMLPlistFileNoTopLevel(self):
        """Tests the Parse function on an XML plist file without top level."""
        parser = plist.PlistParser()
        storage_writer = self._ParseFile(['empty.plist'], 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, 1)

        number_of_warnings = storage_writer.GetNumberOfAttributeContainers(
            'recovery_warning')
        self.assertEqual(number_of_warnings, 0)
Beispiel #15
0
  def testParseWithXMLFileNoTopLevel(self):
    """Tests the Parse function on an XML file without top level."""
    parser = plist.PlistParser()

    with self.assertRaises(errors.UnableToParseFile):
      test_path_segments = [
          'SettingsPane_{F8B5DB1C-D219-4bf9-A747-A1325024469B}'
          '.settingcontent-ms']
      self._ParseFile(test_path_segments, parser)

    # UTF-8 encoded XML file with byte-order-mark.
    with self.assertRaises(errors.UnableToParseFile):
      self._ParseFile(['ReAgent.xml'], parser)

    # UTF-16 little-endian encoded XML file with byte-order-mark.
    with self.assertRaises(errors.UnableToParseFile):
      self._ParseFile(['SampleMachineList.xml'], parser)
Beispiel #16
0
    def testParseWithXMLFileInvalidDate(self):
        """Tests the Parse function on an XML file with an invalid date and time."""
        parser = plist.PlistParser()
        storage_writer = self._ParseFile(['com.apple.security.KCN.plist'],
                                         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, 1)

        number_of_warnings = storage_writer.GetNumberOfAttributeContainers(
            'recovery_warning')
        self.assertEqual(number_of_warnings, 0)
Beispiel #17
0
    def testParseWithEmptyBinaryPlistFile(self):
        """Tests the Parse function on an empty binary plist file."""
        parser = plist.PlistParser()
        storage_writer = self._ParseFile(
            ['com.apple.networkextension.uuidcache.plist'], 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)
Beispiel #18
0
    def testParse(self):
        """Tests the Parse function."""
        parser_object = plist.PlistParser()

        test_file = self._GetTestFilePath([u'plist_binary'])
        event_queue_consumer = self._ParseFile(parser_object, test_file)
        event_objects = self._GetEventObjectsFromQueue(event_queue_consumer)

        self.assertEqual(len(event_objects), 12)

        timestamps, roots, keys = zip(*[(evt.timestamp, evt.root, evt.key)
                                        for evt in event_objects])

        expected_timestamps = frozenset([
            1345251192528750, 1351827808261762, 1345251268370453,
            1351818803000000, 1351819298997672, 1351818797324095,
            1301012201414766, 1302199013524275, 1341957900020116,
            1350666391557044, 1350666385239661, 1341957896010535
        ])

        self.assertTrue(set(expected_timestamps) == set(timestamps))
        self.assertEqual(12, len(set(timestamps)))

        expected_roots = frozenset([
            u'/DeviceCache/00-0d-fd-00-00-00',
            u'/DeviceCache/44-00-00-00-00-00',
            u'/DeviceCache/44-00-00-00-00-01',
            u'/DeviceCache/44-00-00-00-00-02',
            u'/DeviceCache/44-00-00-00-00-03',
            u'/DeviceCache/44-00-00-00-00-04'
        ])
        self.assertTrue(expected_roots == set(roots))
        self.assertEqual(6, len(set(roots)))

        expected_keys = frozenset(
            [u'LastInquiryUpdate', u'LastServicesUpdate', u'LastNameUpdate'])
        self.assertTrue(expected_keys == set(keys))
        self.assertEqual(3, len(set(keys)))
Beispiel #19
0
 def setUp(self):
     """Makes preparations before running an individual test."""
     self._plugin = ipod.IPodPlugin()
     self._parser = plist.PlistParser()
Beispiel #20
0
 def setUp(self):
     """Sets up the needed objects used throughout the test."""
     self._plugin = ipod.IPodPlugin()
     self._parser = plist.PlistParser()
Beispiel #21
0
 def setUp(self):
   """Sets up the needed objects used throughout the test."""
   self._plugin = softwareupdate.SoftwareUpdatePlugin(None)
   self._parser = plist.PlistParser(event.PreprocessObject(), None)
Beispiel #22
0
 def setUp(self):
     """Sets up the needed objects used throughout the test."""
     self._parser = plist.PlistParser()
Beispiel #23
0
 def setUp(self):
     """Makes preparations before running an individual test."""
     self._plugin = spotlight_volume.SpotlightVolumePlugin()
     self._parser = plist.PlistParser()
Beispiel #24
0
 def setUp(self):
     """Sets up the needed objects used throughout the test."""
     self._plugin = bluetooth.BluetoothPlugin()
     self._parser = plist.PlistParser()
Beispiel #25
0
 def setUp(self):
   """Sets up the needed objects used throughout the test."""
   self._plugin = appleaccount.AppleAccountPlugin()
   self._parser = plist.PlistParser()
Beispiel #26
0
 def setUp(self):
     """Sets up the needed objects used throughout the test."""
     self._plugin = ipod.IPodPlugin(None)
     self._parser = plist.PlistParser(event.PreprocessObject(), None)
Beispiel #27
0
    def testParseWithXMLFileExpatError(self):
        """Tests the Parse function on an XML file that causes an ExpatError."""
        parser = plist.PlistParser()

        with self.assertRaises(errors.UnableToParseFile):
            self._ParseFile(['WMSDKNS.DTD'], parser)
Beispiel #28
0
    def testParseWithTruncatedFile(self):
        """Tests the Parse function on a truncated plist file."""
        parser = plist.PlistParser()

        with self.assertRaises(errors.UnableToParseFile):
            self._ParseFile(['truncated.plist'], parser)
Beispiel #29
0
    def testParseWithXMLFileBinASCIIError(self):
        """Tests the Parse function on an XML file that causes a binascii.Error."""
        parser = plist.PlistParser()

        with self.assertRaises(errors.UnableToParseFile):
            self._ParseFile(['manageconsolidatedProviders.aspx.resx'], parser)
Beispiel #30
0
    def testParseWithXMLFileEncodingUnicode(self):
        """Tests the Parse function on an XML file with encoding Unicode."""
        parser = plist.PlistParser()

        with self.assertRaises(errors.UnableToParseFile):
            self._ParseFile(['SAFStore.xml'], parser)