Esempio n. 1
0
    def testHandlerRespectsTimestamp(self):
        archive_path1 = "vfs_C_1000000000000000/fs/os/c/Downloads/a.txt"
        archive_path2 = "vfs_C_1000000000000000/fs/os/c/b.txt"

        result = self.handler.Handle(vfs_plugin.ApiGetVfsFilesArchiveArgs(
            client_id=self.client_id, timestamp=self.time_2),
                                     token=self.token)
        out_fd = StringIO.StringIO()
        for chunk in result.GenerateContent():
            out_fd.write(chunk)
        zip_fd = zipfile.ZipFile(out_fd, "r")

        self.assertItemsEqual(zip_fd.namelist(),
                              [archive_path1, archive_path2])
        self.assertEqual(zip_fd.read(archive_path1), "Goodbye World")
        self.assertEqual(zip_fd.read(archive_path2), "Goodbye World")

        result = self.handler.Handle(vfs_plugin.ApiGetVfsFilesArchiveArgs(
            client_id=self.client_id, timestamp=self.time_1),
                                     token=self.token)
        out_fd = StringIO.StringIO()
        for chunk in result.GenerateContent():
            out_fd.write(chunk)
        zip_fd = zipfile.ZipFile(out_fd, "r")

        self.assertItemsEqual(zip_fd.namelist(),
                              [archive_path1, archive_path2])
        self.assertEqual(zip_fd.read(archive_path1), "Hello World")
        self.assertEqual(zip_fd.read(archive_path2), "Hello World")
    def testVfsMethodsAreAccessChecked(self):
        args = api_vfs.ApiListFilesArgs(client_id=self.client_id)
        self.CheckMethodIsAccessChecked(self.router.ListFiles,
                                        "CheckClientAccess",
                                        args=args)

        args = api_vfs.ApiGetVfsFilesArchiveArgs(client_id=self.client_id)
        self.CheckMethodIsAccessChecked(self.router.GetVfsFilesArchive,
                                        "CheckClientAccess",
                                        args=args)

        args = api_vfs.ApiGetFileDetailsArgs(client_id=self.client_id)
        self.CheckMethodIsAccessChecked(self.router.GetFileDetails,
                                        "CheckClientAccess",
                                        args=args)

        args = api_vfs.ApiGetFileTextArgs(client_id=self.client_id)
        self.CheckMethodIsAccessChecked(self.router.GetFileText,
                                        "CheckClientAccess",
                                        args=args)

        args = api_vfs.ApiGetFileBlobArgs(client_id=self.client_id)
        self.CheckMethodIsAccessChecked(self.router.GetFileBlob,
                                        "CheckClientAccess",
                                        args=args)

        args = api_vfs.ApiGetFileVersionTimesArgs(client_id=self.client_id)
        self.CheckMethodIsAccessChecked(self.router.GetFileVersionTimes,
                                        "CheckClientAccess",
                                        args=args)

        args = api_vfs.ApiGetFileDownloadCommandArgs(client_id=self.client_id)
        self.CheckMethodIsAccessChecked(self.router.GetFileDownloadCommand,
                                        "CheckClientAccess",
                                        args=args)

        args = api_vfs.ApiCreateVfsRefreshOperationArgs(
            client_id=self.client_id)
        self.CheckMethodIsAccessChecked(self.router.CreateVfsRefreshOperation,
                                        "CheckClientAccess",
                                        args=args)

        args = api_vfs.ApiGetVfsTimelineArgs(client_id=self.client_id)
        self.CheckMethodIsAccessChecked(self.router.GetVfsTimeline,
                                        "CheckClientAccess",
                                        args=args)

        args = api_vfs.ApiGetVfsTimelineAsCsvArgs(client_id=self.client_id)
        self.CheckMethodIsAccessChecked(self.router.GetVfsTimelineAsCsv,
                                        "CheckClientAccess",
                                        args=args)

        args = api_vfs.ApiUpdateVfsFileContentArgs(client_id=self.client_id)
        self.CheckMethodIsAccessChecked(self.router.UpdateVfsFileContent,
                                        "CheckClientAccess",
                                        args=args)
Esempio n. 3
0
    def testNonExistentPathGeneratesEmptyArchive(self):
        result = self.handler.Handle(vfs_plugin.ApiGetVfsFilesArchiveArgs(
            client_id=self.client_id, file_path="fs/os/blah/blah"),
                                     token=self.token)

        out_fd = StringIO.StringIO()
        for chunk in result.GenerateContent():
            out_fd.write(chunk)

        zip_fd = zipfile.ZipFile(out_fd, "r")
        self.assertEqual(zip_fd.namelist(), [])
Esempio n. 4
0
    def testClickingOnDownloadEverythingButtonStartsDownload(
            self, mock_method):
        # Open VFS view for client 1 on a specific location.
        self.Open("/#c=C.0000000000000001&main=VirtualFileSystemView"
                  "&t=_fs-os-c-proc")

        self.Click("css=grr-vfs-files-archive-button")
        self.Click("css=a[name=downloadEverything]:not([disabled])")
        self.WaitUntilEqual(1, lambda: mock_method.call_count)
        mock_method.assert_called_once_with(
            api_vfs.ApiGetVfsFilesArchiveArgs(client_id="C.0000000000000001"),
            token=mock.ANY)
Esempio n. 5
0
    def testClickingOnDownloadCurrentFolderButtonStartsDownload(
            self, mock_method):
        # Open VFS view for client 1 on a specific location.
        self.Open("/#c=C.0000000000000001&main=VirtualFileSystemView"
                  "&t=_fs-os-c-proc")

        self.Click("css=grr-vfs-files-archive-button")
        self.Click("css=a[name=downloadCurrentFolder]")

        # Mock method will be called twice: once for HEAD request (to check
        # permissions) and once for GET request.
        self.WaitUntil(lambda: mock_method.call_count)
        mock_method.assert_called_with(api_vfs.ApiGetVfsFilesArchiveArgs(
            client_id="C.0000000000000001", file_path="fs/os/c/proc"),
                                       token=mock.ANY)
Esempio n. 6
0
    def testFiltersArchivedFilesByPath(self):
        archive_path = ("vfs_C_1000000000000000_fs_os_c_Downloads/"
                        "fs/os/c/Downloads/a.txt")

        result = self.handler.Handle(vfs_plugin.ApiGetVfsFilesArchiveArgs(
            client_id=self.client_id, file_path="fs/os/c/Downloads"),
                                     token=self.token)

        out_fd = StringIO.StringIO()
        for chunk in result.GenerateContent():
            out_fd.write(chunk)

        zip_fd = zipfile.ZipFile(out_fd, "r")
        self.assertEqual(zip_fd.namelist(), [archive_path])

        contents = zip_fd.read(archive_path)
        self.assertEqual(contents, "Goodbye World")
Esempio n. 7
0
    def testGeneratesZipArchiveWhenPathIsNotPassed(self):
        archive_path1 = "vfs_C_1000000000000000/fs/os/c/Downloads/a.txt"
        archive_path2 = "vfs_C_1000000000000000/fs/os/c/b.txt"

        result = self.handler.Handle(
            vfs_plugin.ApiGetVfsFilesArchiveArgs(client_id=self.client_id),
            token=self.token)

        out_fd = StringIO.StringIO()
        for chunk in result.GenerateContent():
            out_fd.write(chunk)

        zip_fd = zipfile.ZipFile(out_fd, "r")
        self.assertEqual(set(zip_fd.namelist()),
                         set([archive_path1, archive_path2]))

        for path in [archive_path1, archive_path2]:
            contents = zip_fd.read(path)
            self.assertEqual(contents, "Goodbye World")
Esempio n. 8
0
 def testInvalidPathTriggersException(self):
     with self.assertRaises(ValueError):
         self.handler.Handle(vfs_plugin.ApiGetVfsFilesArchiveArgs(
             client_id=self.client_id, file_path="invalid-prefix/path"),
                             token=self.token)