def testSwitchingBetweenFilesRefreshesFileHashes(self): vfs_test_lib.CreateFile(db.ClientPath.OS(self.client_id, ["c", "Downloads", "a.txt"]), content=self.content_1, token=self.token) vfs_test_lib.CreateFile(db.ClientPath.OS(self.client_id, ["c", "Downloads", "b.txt"]), content=self.content_2, token=self.token) # Open a URL pointing to file "a". self.Open("/#/clients/%s/vfs/fs/os/c/Downloads/a.txt?tab=download" % self.client_id) self.WaitUntil( self.IsElementPresent, "css=tr:contains('Sha256') td:contains('%s')" % self.content_1_hash.encode("hex")) # Click on a file table row with file "b". Information in the download # tab should get rerendered and we should see Sha256 value corresponding # to file "b". self.Click("css=tr:contains(\"b.txt\")") self.WaitUntil( self.IsElementPresent, "css=tr:contains('Sha256') td:contains('%s')" % self.content_2_hash.encode("hex"))
def testSwitchingBetweenFileVersionsRefreshesDownloadTab(self): with test_lib.FakeTime(gui_test_lib.TIME_0): vfs_test_lib.CreateFile(db.ClientPath.OS( self.client_id, ["c", "Downloads", "a.txt"]), content=self.content_1) with test_lib.FakeTime(gui_test_lib.TIME_1): vfs_test_lib.CreateFile(db.ClientPath.OS( self.client_id, ["c", "Downloads", "a.txt"]), content=self.content_2) # Open a URL corresponding to a HEAD version of the file. self.Open("/#/clients/%s/vfs/fs/os/c/Downloads/a.txt?tab=download" % self.client_id) # Make sure displayed hash value is correct. self.WaitUntil( self.IsElementPresent, "css=tr:contains('Sha256') td:contains('%s')" % binascii.hexlify(self.content_2_hash).decode("ascii")) # Select the previous file version. self.Click("css=select.version-dropdown > option:contains(\"%s\")" % gui_test_lib.DateString(gui_test_lib.TIME_0)) # Make sure displayed hash value gets updated. self.WaitUntil( self.IsElementPresent, "css=tr:contains('Sha256') td:contains('%s')" % binascii.hexlify(self.content_1_hash).decode("ascii"))
def CreateFileVersions(self, client_id, file_path): """Add a new version for a file.""" path_type, components = rdf_objects.ParseCategorizedPath(file_path) client_path = db.ClientPath(client_id, path_type, components) with test_lib.FakeTime(self.time_1): vfs_test_lib.CreateFile(client_path, "Hello World".encode("utf-8")) with test_lib.FakeTime(self.time_2): vfs_test_lib.CreateFile(client_path, "Goodbye World".encode("utf-8"))
def CreateFileVersions(self, client_id, file_path): """Add a new version for a file.""" path_type, components = rdf_objects.ParseCategorizedPath(file_path) client_path = db.ClientPath(client_id.Basename(), path_type, components) token = access_control.ACLToken(username="******") with test_lib.FakeTime(self.time_1): vfs_test_lib.CreateFile( client_path, "Hello World".encode("utf-8"), token=token) with test_lib.FakeTime(self.time_2): vfs_test_lib.CreateFile( client_path, "Goodbye World".encode("utf-8"), token=token)
def testHexViewer(self): content = b"ls\000hello world\'\000-l" vfs_test_lib.CreateFile(db.ClientPath.OS(self.client_id, ["proc", "10", "cmdline"]), content=content) self.Open("/#clients/%s/vfs/fs/os/proc/10/" % self.client_id) self.Click("css=td:contains(\"cmdline\")") self.Click("css=li[heading=HexView]:not(.disabled)") self.WaitUntilEqual( binascii.hexlify(content).decode("ascii"), self.GetText, "css=table.hex-area tr:first td") # The string inside the file is null-character-delimited. The way # a null character is displayed depends on Angular # version. I.e. it was ignored in version 1.6.5 and is displayed # as a square in version 1.6.6. Making the checks in a # null-character-presentation-independent way. self.WaitUntil(self.IsElementPresent, "css=table.content-area td.data:contains('ls')") self.WaitUntil( self.IsElementPresent, "css=table.content-area td.data:contains('hello world')") self.WaitUntil(self.IsElementPresent, "css=table.content-area td.data:contains('-l')")
def Touch(self, vfs_path, content=b""): path_type, components = rdf_objects.ParseCategorizedPath(vfs_path) client_path = db.ClientPath( client_id=self.client_id.Basename(), path_type=path_type, components=components) vfs_test_lib.CreateFile(client_path, content=content)
def setUp(self): super(FlowArchiveGeneratorTest, self).setUp() self.client_id = self.SetupClient(0) self.flow_id = flow_test_lib.StartFlow( flow_test_lib.DummyFlow, client_id=self.client_id) self.flow = data_store.REL_DB.ReadFlowObject(self.client_id, self.flow_id) self.path1 = db.ClientPath.OS(self.client_id, ["foo", "bar", "hello1.txt"]) self.path1_content = "hello1".encode("utf-8") self.path2 = db.ClientPath.TSK( self.client_id, ["foo", "bar", "中国新闻网新闻中.txt"]) self.path2_content = "hello2".encode("utf-8") vfs_test_lib.CreateFile(self.path1, self.path1_content) vfs_test_lib.CreateFile(self.path2, self.path2_content)
def CreateFileVersion(client_id, path, content=b"", timestamp=None): """Add a new version for a file.""" if timestamp is None: timestamp = rdfvalue.RDFDatetime.Now() with test_lib.FakeTime(timestamp): path_type, components = rdf_objects.ParseCategorizedPath(path) client_path = db.ClientPath(client_id, path_type, components) vfs_test_lib.CreateFile(client_path, content=content)
def testGetBlobUnicode(self): vfs_test_lib.CreateFile( db.ClientPath.TSK("C.1000000000000000", ["c", "bin", "中国新闻网新闻中"]), b"Hello world") out = io.BytesIO() self.api.Client(client_id=self.client_id).File( u"fs/tsk/c/bin/中国新闻网新闻中").GetBlob().WriteToStream(out) self.assertEqual(out.getvalue(), "Hello world")
def testGetBlobWithOffsetUnicode(self): tsk = db.ClientPath.TSK("C.1000000000000000", ["c", "bin", "中"]) vfs_test_lib.CreateFile(tsk, b"Hello world") out = io.BytesIO() client = self.api.Client(client_id=self.client_id) f = client.File("fs/tsk/c/bin/中") f.GetBlobWithOffset(6).WriteToStream(out) self.assertEqual(out.getvalue(), b"world")
def testLargeFileIsReturnedInMultipleChunks(self): chars = [b"a", b"b", b"x"] # Overwrite CHUNK_SIZE in handler for smaller test streams. self.handler.CHUNK_SIZE = 5 client_path = db.ClientPath.OS(self.client_id, ["c", "Downloads", "huge.txt"]) vfs_test_lib.CreateFile( client_path, content=b"".join([c * self.handler.CHUNK_SIZE for c in chars])) args = vfs_plugin.ApiGetFileBlobArgs( client_id=self.client_id, file_path="fs/os/c/Downloads/huge.txt") result = self.handler.Handle(args, context=self.context) self.assertTrue(hasattr(result, "GenerateContent")) for chunk, char in zip(result.GenerateContent(), chars): self.assertEqual(chunk, char * self.handler.CHUNK_SIZE)
def setUp(self): super().setUp() self.handler = vfs_plugin.ApiBrowseFilesystemHandler() self.client_id = self.SetupClient(0) with test_lib.FakeTime(rdfvalue.RDFDatetime.FromSecondsSinceEpoch(1)): vfs_test_lib.CreateFile( db.ClientPath.NTFS(self.client_id, ["mixeddir", "ntfs-then-os"]), b"NTFS") vfs_test_lib.CreateFile( db.ClientPath.OS(self.client_id, ["mixeddir", "os-then-ntfs"]), b"OS") vfs_test_lib.CreateFile( db.ClientPath.TSK(self.client_id, ["mixeddir", "tsk-only"]), b"TSK") with test_lib.FakeTime(rdfvalue.RDFDatetime.FromSecondsSinceEpoch(2)): vfs_test_lib.CreateFile( db.ClientPath.OS(self.client_id, ["mixeddir", "ntfs-then-os"]), b"OS") vfs_test_lib.CreateFile( db.ClientPath.NTFS(self.client_id, ["mixeddir", "os-then-ntfs"]), b"NTFS") vfs_test_lib.CreateFile( db.ClientPath.OS(self.client_id, ["mixeddir", "os-only"]), b"OS")