Example #1
0
    def testInitialize(self):
        """Tests the path specification initialization."""
        path_spec = gzip_path_spec.GzipPathSpec(parent=self._path_spec)

        self.assertIsNotNone(path_spec)

        with self.assertRaises(ValueError):
            gzip_path_spec.GzipPathSpec(parent=None)

        with self.assertRaises(ValueError):
            gzip_path_spec.GzipPathSpec(parent=self._path_spec, bogus='BOGUS')
Example #2
0
  def testReadMultipleMembers(self):
    """Tests reading a file that contains multiple gzip members."""
    test_file = self._GetTestFilePath(['fsevents_000000000000b208'])
    parent_path_spec = os_path_spec.OSPathSpec(location=test_file)
    path_spec = gzip_path_spec.GzipPathSpec(parent=parent_path_spec)
    file_object = gzip_file_io.GzipFile(self._resolver_context)
    file_object.open(path_spec=path_spec)

    self.assertEqual(file_object.uncompressed_data_size, 506631)
    self.assertEqual(file_object.modification_times, [0, 0])
    self.assertEqual(file_object.operating_systems, [3, 3])
    self.assertEqual(file_object.original_filenames, [None, None])
    self.assertEqual(file_object.comments, [None, None])

    file_start = file_object.read(4)
    self.assertEqual(file_start, b'1SLD')

    # Read the end of the second member
    file_object.seek(506631 - 4)
    file_end = file_object.read(4)
    self.assertEqual(file_end, b'\x02\x00\x80\x00')

    # Seek backwards, and read across a member boundary.
    file_object.seek(28530)
    self.assertEqual(file_object.read(6), b'OS\x00P\x07\x00')

    file_object.close()
Example #3
0
    def GetRootFileEntry(self):
        """Retrieves the root file entry.

    Returns:
      A file entry (instance of vfs.FileEntry) or None.
    """
        path_spec = gzip_path_spec.GzipPathSpec(parent=self._path_spec.parent)
        return self.GetFileEntryByPathSpec(path_spec)
Example #4
0
    def GetRootFileEntry(self):
        """Retrieves the root file entry.

    Returns:
      GzipFileEntry: a file entry or None if not available.
    """
        path_spec = gzip_path_spec.GzipPathSpec(parent=self._path_spec.parent)
        return self.GetFileEntryByPathSpec(path_spec)
Example #5
0
    def setUp(self):
        """Sets up the needed objects used throughout the test."""
        self._resolver_context = context.Context()
        test_file = self._GetTestFilePath(['syslog.gz'])
        self._SkipIfPathNotExists(test_file)

        path_spec = os_path_spec.OSPathSpec(location=test_file)
        self._gzip_path_spec = gzip_path_spec.GzipPathSpec(parent=path_spec)
Example #6
0
  def setUp(self):
    """Sets up the needed objects used throughout the test."""
    self._resolver_context = context.Context()
    test_file = self._GetTestFilePath([u'syslog.gz'])
    path_spec = os_path_spec.OSPathSpec(location=test_file)
    self._gzip_path_spec = gzip_path_spec.GzipPathSpec(parent=path_spec)

    self._file_system = gzip_file_system.GzipFileSystem(self._resolver_context)
    self._file_system.Open(self._gzip_path_spec)
Example #7
0
    def testComparable(self):
        """Tests the path specification comparable property."""
        path_spec = gzip_path_spec.GzipPathSpec(parent=self._path_spec)

        self.assertIsNotNone(path_spec)

        expected_comparable = '\n'.join(['type: TEST', 'type: GZIP', ''])

        self.assertEqual(path_spec.comparable, expected_comparable)
Example #8
0
    def testGetCompressedArchiveTypeIndicators(self):
        """Function to test the get compressed archive type indicators function."""
        test_file = os.path.join(u'test_data', u'syslog.tgz')
        path_spec = os_path_spec.OSPathSpec(location=test_file)

        expected_type_indicators = [definitions.TYPE_INDICATOR_GZIP]
        type_indicators = analyzer.Analyzer.GetCompressedStreamTypeIndicators(
            path_spec)
        self.assertEqual(type_indicators, expected_type_indicators)

        path_spec = gzip_path_spec.GzipPathSpec(parent=path_spec)

        expected_type_indicators = [definitions.TYPE_INDICATOR_TAR]
        type_indicators = analyzer.Analyzer.GetArchiveTypeIndicators(path_spec)
        self.assertEqual(type_indicators, expected_type_indicators)
Example #9
0
    def testGetCompressedArchiveTypeIndicators(self):
        """Tests the GetCompressedStreamTypeIndicators function on a .tgz file."""
        test_file = self._GetTestFilePath(['syslog.tgz'])
        path_spec = os_path_spec.OSPathSpec(location=test_file)

        expected_type_indicators = [definitions.TYPE_INDICATOR_GZIP]
        type_indicators = analyzer.Analyzer.GetCompressedStreamTypeIndicators(
            path_spec)
        self.assertEqual(type_indicators, expected_type_indicators)

        path_spec = gzip_path_spec.GzipPathSpec(parent=path_spec)

        expected_type_indicators = [definitions.TYPE_INDICATOR_TAR]
        type_indicators = analyzer.Analyzer.GetArchiveTypeIndicators(path_spec)
        self.assertEqual(type_indicators, expected_type_indicators)
Example #10
0
 def setUp(self):
     """Sets up the needed objects used throughout the test."""
     self._resolver_context = context.Context()
     test_file = os.path.join(u'test_data', u'syslog.gz')
     path_spec = os_path_spec.OSPathSpec(location=test_file)
     self._gzip_path_spec = gzip_path_spec.GzipPathSpec(parent=path_spec)