示例#1
0
  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")
示例#2
0
  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)
示例#3
0
  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)
示例#4
0
  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")
示例#5
0
  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")
示例#6
0
  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)