def testCalculateHashesFileEntry(self): """Tests the _CalculateHashesFileEntry function.""" path = self._GetTestFilePath(['image.qcow2']) self._SkipIfPathNotExists(path) test_hasher = recursive_hasher.RecursiveHasher() path_spec = path_spec_factory.Factory.NewPathSpec( dfvfs_definitions.TYPE_INDICATOR_OS, location=path) path_spec = path_spec_factory.Factory.NewPathSpec( dfvfs_definitions.TYPE_INDICATOR_QCOW, parent=path_spec) path_spec = path_spec_factory.Factory.NewPathSpec( dfvfs_definitions.TYPE_INDICATOR_TSK, location='/passwords.txt', parent=path_spec) file_system = resolver.Resolver.OpenFileSystem(path_spec) file_entry = resolver.Resolver.OpenFileEntry(path_spec) output_writer = TestOutputWriter() test_hasher._CalculateHashesFileEntry( file_system, file_entry, [''], output_writer) self.assertEqual(len(output_writer.hashes), 1) expected_hashes = [ ('/passwords.txt', '02a2a6af2f1ecf4720d7d49d640f0d0a269a7ec733e41973bdd34f09dad0e252')] self.assertEqual(output_writer.hashes, expected_hashes)
def testGetBasePathSpecs(self): """Tests the GetBasePathSpecs function.""" path = self._GetTestFilePath(['image.qcow2']) self._SkipIfPathNotExists(path) test_hasher = recursive_hasher.RecursiveHasher() expected_path_spec = path_spec_factory.Factory.NewPathSpec( dfvfs_definitions.TYPE_INDICATOR_OS, location=path) expected_path_spec = path_spec_factory.Factory.NewPathSpec( dfvfs_definitions.TYPE_INDICATOR_QCOW, parent=expected_path_spec) expected_path_spec = path_spec_factory.Factory.NewPathSpec( dfvfs_definitions.PREFERRED_EXT_BACK_END, location='/', parent=expected_path_spec) base_path_specs = test_hasher.GetBasePathSpecs(path) self.assertEqual(base_path_specs, [expected_path_spec])
def testGetDisplayPath(self): """Tests the _GetDisplayPath function.""" path = self._GetTestFilePath(['image.qcow2']) self._SkipIfPathNotExists(path) test_hasher = recursive_hasher.RecursiveHasher() path_spec = path_spec_factory.Factory.NewPathSpec( dfvfs_definitions.TYPE_INDICATOR_OS, location=path) path_spec = path_spec_factory.Factory.NewPathSpec( dfvfs_definitions.TYPE_INDICATOR_QCOW, parent=path_spec) path_spec = path_spec_factory.Factory.NewPathSpec( dfvfs_definitions.TYPE_INDICATOR_TSK, location='/passwords.txt', parent=path_spec) display_path = test_hasher._GetDisplayPath( path_spec, ['', 'passwords.txt'], 'stream') self.assertEqual(display_path, '/passwords.txt:stream')
def testCalculateHashes(self): """Tests the CalculateHashes function.""" path = self._GetTestFilePath(['image.qcow2']) self._SkipIfPathNotExists(path) test_hasher = recursive_hasher.RecursiveHasher() base_path_specs = test_hasher.GetBasePathSpecs(path) output_writer = TestOutputWriter() test_hasher.CalculateHashes(base_path_specs, output_writer) self.assertEqual(len(output_writer.hashes), 3) expected_hashes = [ ('/a_directory/another_file', 'c7fbc0e821c0871805a99584c6a384533909f68a6bbe9a2a687d28d9f3b10c16'), ('/a_directory/a_file', '4a49638d0e1055fd9e4c17fef7fdf4d6ccf892b6d9c2f64164203c4bfb0ec92d'), ('/passwords.txt', '02a2a6af2f1ecf4720d7d49d640f0d0a269a7ec733e41973bdd34f09dad0e252')] self.assertEqual(output_writer.hashes, expected_hashes)
def testCalculateHashDataStream(self): """Tests the _CalculateHashDataStream function.""" path = self._GetTestFilePath(['image.qcow2']) self._SkipIfPathNotExists(path) test_hasher = recursive_hasher.RecursiveHasher() path_spec = path_spec_factory.Factory.NewPathSpec( dfvfs_definitions.TYPE_INDICATOR_OS, location=path) path_spec = path_spec_factory.Factory.NewPathSpec( dfvfs_definitions.TYPE_INDICATOR_QCOW, parent=path_spec) path_spec = path_spec_factory.Factory.NewPathSpec( dfvfs_definitions.TYPE_INDICATOR_TSK, location='/passwords.txt', parent=path_spec) file_entry = resolver.Resolver.OpenFileEntry(path_spec) expected_digest_hash = ( '02a2a6af2f1ecf4720d7d49d640f0d0a269a7ec733e41973bdd34f09dad0e252') digest_hash = test_hasher._CalculateHashDataStream(file_entry, '') self.assertEqual(digest_hash, expected_digest_hash)