Example #1
0
    def testAddDateTimeRange(self):
        """Tests the AddDateTimeRange function."""
        test_filter = image_export.DateTimeFileEntryFilter()

        test_filter.AddDateTimeRange(u'ctime',
                                     end_time_string=u'2012-05-25 15:59:25',
                                     start_time_string=u'2012-05-25 15:59:20')

        with self.assertRaises(ValueError):
            test_filter.AddDateTimeRange(None)

        # Testing adding a badly formatter filter.
        with self.assertRaises(ValueError):
            test_filter.AddDateTimeRange(
                u'foobar', start_time_string=u'2012-02-01 01:01:01')

        with self.assertRaises(ValueError):
            test_filter.AddDateTimeRange(
                u'ctime',
                end_time_string=u'2012-05-25 15:59:20',
                start_time_string=u'2012-05-25 15:59:25')

        # Testing adding a badly formatter filter, no date set.
        with self.assertRaises(ValueError):
            test_filter.AddDateTimeRange(u'atime')
Example #2
0
    def testPrint(self):
        """Tests the Print function."""
        output_writer = cli_test_lib.TestOutputWriter(encoding=u'utf-8')
        test_filter = image_export.DateTimeFileEntryFilter()

        test_filter.AddDateTimeRange(u'ctime',
                                     end_time_string=u'2012-05-25 15:59:25',
                                     start_time_string=u'2012-05-25 15:59:20')

        test_filter.AddDateTimeRange(u'atime',
                                     end_time_string=u'2012-05-25 15:59:25')

        test_filter.AddDateTimeRange(u'mtime',
                                     start_time_string=u'2012-05-25 15:59:20')

        test_filter.Print(output_writer)

        expected_output = [(b'\tctime between 2012-05-25T15:59:20+00:00 and '
                            b'2012-05-25T15:59:25+00:00'),
                           b'\tatime after 2012-05-25T15:59:25+00:00',
                           b'\tmtime before 2012-05-25T15:59:20+00:00', b'']

        output = output_writer.ReadOutput()

        # Compare the output as list of lines which makes it easier to spot
        # differences.
        self.assertEqual(output.split(b'\n'), expected_output)
Example #3
0
  def testMatches(self):
    """Tests the Matches function."""
    test_path = self._GetTestFilePath([u'ímynd.dd'])
    os_path_spec = path_spec_factory.Factory.NewPathSpec(
        dfvfs_definitions.TYPE_INDICATOR_OS, location=test_path)
    tsk_path_spec = path_spec_factory.Factory.NewPathSpec(
        dfvfs_definitions.TYPE_INDICATOR_TSK, inode=16,
        location=u'/a_directory/another_file', parent=os_path_spec)

    file_entry = path_spec_resolver.Resolver.OpenFileEntry(tsk_path_spec)

    # Timestamps of file:
    #   Modified: 2012-05-25T15:59:23+00:00
    #   Accessed: 2012-05-25T15:59:23+00:00
    #    Created: 2012-05-25T15:59:23+00:00

    date_filter = image_export.DateTimeFileEntryFilter()

    # When no date time ranges are specified the filter returns None.
    self.assertEqual(date_filter.Matches(file_entry), None)

    # Add a date to the date filter.
    date_filter.AddDateTimeRange(
        u'ctime', start_time_string=u'2012-05-25 15:59:20',
        end_time_string=u'2012-05-25 15:59:25')
    self.assertTrue(date_filter.Matches(file_entry))

    date_filter = image_export.DateTimeFileEntryFilter()
    date_filter.AddDateTimeRange(
        u'ctime', start_time_string=u'2012-05-25 15:59:24',
        end_time_string=u'2012-05-25 15:59:55')
    self.assertFalse(date_filter.Matches(file_entry))

    # Testing a timestamp that does not exist in the stat object.
    date_filter = image_export.DateTimeFileEntryFilter()
    date_filter.AddDateTimeRange(
        u'bkup', start_time_string=u'2012-02-02 12:12:12')
    self.assertTrue(date_filter.Matches(file_entry))

    # Just end date set.
    date_filter = image_export.DateTimeFileEntryFilter()
    date_filter.AddDateTimeRange(
        u'mtime', end_time_string=u'2012-05-25 15:59:55')
    self.assertTrue(date_filter.Matches(file_entry))

    # Just with a start date but within range.
    date_filter = image_export.DateTimeFileEntryFilter()
    date_filter.AddDateTimeRange(
        u'atime', start_time_string=u'2012-03-25 15:59:55')
    self.assertTrue(date_filter.Matches(file_entry))

    # And now with a start date, but out of range.
    date_filter = image_export.DateTimeFileEntryFilter()
    date_filter.AddDateTimeRange(
        u'ctime', start_time_string=u'2012-05-25 15:59:55')
    self.assertFalse(date_filter.Matches(file_entry))

    # Test with more than one date filter.
    date_filter = image_export.DateTimeFileEntryFilter()
    date_filter.AddDateTimeRange(
        u'ctime', start_time_string=u'2012-05-25 15:59:55',
        end_time_string=u'2012-05-25 17:34:12')
    date_filter.AddDateTimeRange(
        u'atime', start_time_string=u'2012-05-25 15:59:20',
        end_time_string=u'2012-05-25 15:59:25')
    date_filter.AddDateTimeRange(
        u'mtime', start_time_string=u'2012-05-25 15:59:24',
        end_time_string=u'2012-05-25 15:59:55')

    self.assertFalse(date_filter.Matches(file_entry))
    # pylint: disable=protected-access
    self.assertEqual(len(date_filter._date_time_ranges), 3)