def testHashEntryFromSimpleFile(self): client_urn = self.SetupClient(0) with self._Aff4Open(client_urn.Add("fs/os").Add("foo")) as fd: hash_entry = rdf_crypto.Hash(md5=b"bar", sha256=b"baz") fd.Set(fd.Schema.HASH, hash_entry) data_migration.MigrateClientVfs(client_urn) path_info = data_store.REL_DB.ReadPathInfo( client_id=client_urn.Basename(), path_type=rdf_objects.PathInfo.PathType.OS, components=("foo",)) self.assertEqual(path_info.hash_entry.md5, b"bar") self.assertEqual(path_info.hash_entry.sha256, b"baz")
def testStatEntryFromSimpleFile(self): client_urn = self.SetupClient(0) with self._Aff4Open(client_urn.Add("fs/os").Add("foo")) as fd: stat_entry = rdf_client.StatEntry(st_mode=1337, st_size=42) fd.Set(fd.Schema.STAT, stat_entry) data_migration.MigrateClientVfs(client_urn) path_info = data_store.REL_DB.ReadPathInfo( client_id=client_urn.Basename(), path_type=rdf_objects.PathInfo.PathType.OS, components=("foo",)) self.assertEqual(path_info.stat_entry.st_mode, 1337) self.assertEqual(path_info.stat_entry.st_size, 42)
def testStatFromTree(self): client_urn = self.SetupClient(0) with self._Aff4Open(client_urn.Add("fs/os").Add("foo/bar/baz")) as fd: stat_entry = rdf_client.StatEntry(st_mtime=101) fd.Set(fd.Schema.STAT, stat_entry) data_migration.MigrateClientVfs(client_urn) path_infos = data_store.REL_DB.ReadPathInfos( client_id=client_urn.Basename(), path_type=rdf_objects.PathInfo.PathType.OS, components_list=[("foo",), ("foo", "bar"), ("foo", "bar", "baz")]) self.assertEqual(path_infos[("foo",)].stat_entry.st_mtime, None) self.assertEqual(path_infos[("foo", "bar")].stat_entry.st_mtime, None) self.assertEqual(path_infos[("foo", "bar", "baz")].stat_entry.st_mtime, 101)
def testStatAndHashEntryFromSimpleFile(self): client_urn = self.SetupClient(0) with self._Aff4Open(client_urn.Add("fs/os").Add("foo")) as fd: stat_entry = rdf_client.StatEntry(st_mode=108) fd.Set(fd.Schema.STAT, stat_entry) hash_entry = rdf_crypto.Hash(sha256=b"quux") fd.Set(fd.Schema.HASH, hash_entry) data_migration.MigrateClientVfs(client_urn) path_info = data_store.REL_DB.ReadPathInfo( client_id=client_urn.Basename(), path_type=rdf_objects.PathInfo.PathType.OS, components=("foo",)) self.assertEqual(path_info.stat_entry.st_mode, 108) self.assertEqual(path_info.hash_entry.sha256, b"quux")
def testHashHistory(self): datetime = rdfvalue.RDFDatetime.FromHumanReadable client_urn = self.SetupClient(0) file_urn = client_urn.Add("fs/os").Add("bar") with test_lib.FakeTime(datetime("2010-01-01")): with self._Aff4Open(file_urn) as fd: fd.Set(fd.Schema.HASH, rdf_crypto.Hash(md5=b"quux")) with test_lib.FakeTime(datetime("2020-01-01")): with self._Aff4Open(file_urn) as fd: fd.Set(fd.Schema.HASH, rdf_crypto.Hash(md5=b"norf")) with test_lib.FakeTime(datetime("2030-01-01")): with self._Aff4Open(file_urn) as fd: fd.Set(fd.Schema.HASH, rdf_crypto.Hash(md5=b"blargh")) data_migration.MigrateClientVfs(client_urn) path_info = data_store.REL_DB.ReadPathInfo( client_id=client_urn.Basename(), path_type=rdf_objects.PathInfo.PathType.OS, components=("bar",), timestamp=datetime("2010-12-31")) self.assertEqual(path_info.hash_entry.md5, b"quux") path_info = data_store.REL_DB.ReadPathInfo( client_id=client_urn.Basename(), path_type=rdf_objects.PathInfo.PathType.OS, components=("bar",), timestamp=datetime("2020-12-31")) self.assertEqual(path_info.hash_entry.md5, b"norf") path_info = data_store.REL_DB.ReadPathInfo( client_id=client_urn.Basename(), path_type=rdf_objects.PathInfo.PathType.OS, components=("bar",), timestamp=datetime("2030-12-31")) self.assertEqual(path_info.hash_entry.md5, b"blargh")
def testStatHistory(self): datetime = rdfvalue.RDFDatetime.FromHumanReadable client_urn = self.SetupClient(0) file_urn = client_urn.Add("fs/os").Add("foo") with test_lib.FakeTime(datetime("2000-01-01")): with self._Aff4Open(file_urn) as fd: fd.Set(fd.Schema.STAT, rdf_client.StatEntry(st_size=10)) with test_lib.FakeTime(datetime("2000-02-02")): with self._Aff4Open(file_urn) as fd: fd.Set(fd.Schema.STAT, rdf_client.StatEntry(st_size=20)) with test_lib.FakeTime(datetime("2000-03-03")): with self._Aff4Open(file_urn) as fd: fd.Set(fd.Schema.STAT, rdf_client.StatEntry(st_size=30)) data_migration.MigrateClientVfs(client_urn) path_info = data_store.REL_DB.ReadPathInfo( client_id=client_urn.Basename(), path_type=rdf_objects.PathInfo.PathType.OS, components=("foo",), timestamp=datetime("2000-01-10")) self.assertEqual(path_info.stat_entry.st_size, 10) path_info = data_store.REL_DB.ReadPathInfo( client_id=client_urn.Basename(), path_type=rdf_objects.PathInfo.PathType.OS, components=("foo",), timestamp=datetime("2000-02-20")) self.assertEqual(path_info.stat_entry.st_size, 20) path_info = data_store.REL_DB.ReadPathInfo( client_id=client_urn.Basename(), path_type=rdf_objects.PathInfo.PathType.OS, components=("foo",), timestamp=datetime("2000-03-30")) self.assertEqual(path_info.stat_entry.st_size, 30)