Пример #1
0
    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)
Пример #2
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]")
    self.WaitUntilEqual(1, lambda: mock_method.call_count)
    mock_method.assert_called_once_with(
        api_vfs.ApiGetVfsFilesArchiveArgs(client_id="C.0000000000000001"),
        token=mock.ANY)
Пример #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(), [])
Пример #4
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")
Пример #5
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")
Пример #6
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)