def testExtAttrsCollection(self): with test_lib.AutoTempDirPath(remove_non_empty=True) as temp_dirpath: foo_filepath = test_lib.TempFilePath(dir=temp_dirpath) self._Setfattr(foo_filepath, name="user.quux", value="foo") bar_filepath = test_lib.TempFilePath(dir=temp_dirpath) self._Setfattr(bar_filepath, name="user.quux", value="bar") baz_filepath = test_lib.TempFilePath(dir=temp_dirpath) self._Setfattr(baz_filepath, name="user.quux", value="baz") request = rdf_client.FindSpec(pathspec=rdf_paths.PathSpec( path=temp_dirpath, pathtype=rdf_paths.PathSpec.PathType.OS), path_glob="*", collect_ext_attrs=True) request.iterator.number = 100 hits = [] for response in self.RunAction(searching.Find, request): if isinstance(response, rdf_client.FindSpec): hits.append(response.hit) self.assertEqual(len(hits), 3) values = [] for hit in hits: self.assertEqual(len(hit.ext_attrs), 1) values.append(hit.ext_attrs[0].value) self.assertItemsEqual(values, ["foo", "bar", "baz"])
def testHashFilePart(self): tmp_path = test_lib.TempFilePath() with open(tmp_path, "wb") as tmp_file: tmp_file.write("foobar") hasher = client_utils_common.MultiHasher(["md5", "sha1"]) hasher.HashFilePath(tmp_path, len("foo")) hash_object = hasher.GetHashObject() self.assertEqual(hash_object.num_bytes, len("foo")) self.assertEqual(hash_object.md5, self._GetHash(hashlib.md5, "foo")) self.assertEqual(hash_object.sha1, self._GetHash(hashlib.sha1, "foo")) self.assertFalse(hash_object.sha256) os.remove(tmp_path)
def testFileFinderStatExtFlags(self): temp_filepath = test_lib.TempFilePath() if subprocess.call(["which", "chattr"]) != 0: raise unittest.SkipTest("`chattr` command is not available") if subprocess.call(["chattr", "+d", temp_filepath]) != 0: raise unittest.SkipTest( "extended attributes not supported by filesystem") action = rdf_file_finder.FileFinderAction.Stat() results = self.RunFlow(action=action, paths=[temp_filepath]) self.assertEqual(len(results), 1) stat_entry = results[0][1].stat_entry self.assertTrue(stat_entry.st_flags_linux & self.FS_NODUMP_FL) self.assertFalse(stat_entry.st_flags_linux & self.FS_UNRM_FL) os.remove(temp_filepath)
def testStatExtFlags(self): temp_filepath = test_lib.TempFilePath() if subprocess.call(["which", "chattr"]) != 0: raise unittest.SkipTest("`chattr` command is not available") if subprocess.call(["chattr", "+c", temp_filepath]) != 0: raise unittest.SkipTest( "extended attributes not supported by filesystem") action_type = rdf_file_finder.FileFinderAction.Action.STAT action = rdf_file_finder.FileFinderAction(action_type=action_type) results = self._RunFileFinder([temp_filepath], action) self.assertEqual(len(results), 1) stat_entry = results[0].stat_entry self.assertTrue(stat_entry.st_flags_linux & self.EXT2_COMPR_FL) self.assertFalse(stat_entry.st_flags_linux & self.EXT2_IMMUTABLE_FL) os.remove(temp_filepath)
def testGetAllFiles(self): with test_lib.AutoTempDirPath(remove_non_empty=True) as tmpdir_path: foo_path = test_lib.TempFilePath(suffix="foo.yaml") bar_path = test_lib.TempFilePath(suffix="bar.json") baz_path = test_lib.TempFilePath(suffix="baz.yaml") quux_path = test_lib.TempFilePath(dir=tmpdir_path, suffix="quux.yaml") norf_path = test_lib.TempFilePath(dir=tmpdir_path, suffix="norf.json") thud_path = test_lib.TempFilePath(dir=tmpdir_path, suffix="thud.xml") self.sources.AddFile(foo_path) self.sources.AddFile(bar_path) self.sources.AddDir(tmpdir_path) files = list(self.sources.GetAllFiles()) self.assertIn(foo_path, files) self.assertIn(bar_path, files) self.assertIn(quux_path, files) self.assertIn(norf_path, files) self.assertNotIn(baz_path, files) self.assertNotIn(thud_path, files)
def setUp(self): self.temp_filepath = test_lib.TempFilePath()
def setUp(self): super(FileReaderTest, self).setUp() self.temp_filepath = test_lib.TempFilePath()
def setUp(self): super(StreamFilePathTest, self).setUp() self.temp_filepath = test_lib.TempFilePath()
def setUp(self): super(ConditionTestMixin, self).setUp() self.temp_filepath = test_lib.TempFilePath()