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')
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()
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)
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)
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)
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)
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)
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)
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)
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)