コード例 #1
0
    def testNotificationIsSent(self):
        fixture_test_lib.ClientFixture(self.client_id, token=self.token)

        args = vfs_plugin.ApiCreateVfsRefreshOperationArgs(
            client_id=self.client_id,
            file_path=self.file_path,
            max_depth=0,
            notify_user=True)
        result = self.handler.Handle(args, token=self.token)

        # Finish flow and check if there are any new notifications.
        flow_urn = rdfvalue.RDFURN(result.operation_id)
        client_mock = action_mocks.ActionMock()
        flow_test_lib.TestFlowHelper(flow_urn,
                                     client_mock,
                                     client_id=self.client_id,
                                     token=self.token,
                                     check_flow_errors=False)

        pending_notifications = self.GetUserNotifications(self.token.username)

        self.assertIn("Recursive Directory Listing complete",
                      pending_notifications[0].message)
        self.assertEqual(pending_notifications[0].subject,
                         self.client_id.Add(self.file_path))
コード例 #2
0
    def Run(self):
        client_urn = self.SetupClient(0)
        client_id = client_urn.Basename()

        # Choose some directory with pathspec in the ClientFixture.
        self.file_path = "fs/os/Users/Shared"

        fixture_test_lib.ClientFixture(client_urn, token=self.token)

        def ReplaceFlowId():
            if data_store.RelationalDBEnabled():
                flows = data_store.REL_DB.ReadAllFlowObjects(
                    client_id=client_id)
                return {flows[0].flow_id: "W:ABCDEF"}
            else:
                flows_dir_fd = aff4.FACTORY.Open(client_urn.Add("flows"),
                                                 token=self.token)
                flow_urn = list(flows_dir_fd.ListChildren())[0]
                return {flow_urn.Basename(): "W:ABCDEF"}

        with test_lib.FakeTime(42):
            self.Check("CreateVfsRefreshOperation",
                       args=vfs_plugin.ApiCreateVfsRefreshOperationArgs(
                           client_id=client_id,
                           file_path=self.file_path,
                           max_depth=1),
                       replace=ReplaceFlowId)
コード例 #3
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)
コード例 #4
0
ファイル: vfs_test.py プロジェクト: avmi/grr
 def _testPathTranslation(self, directory: str,
                          expected_pathspec: rdf_paths.PathSpec) -> None:
   self.CreateFileVersions(self.client_id,
                           os.path.join(directory, "some_file.txt"))
   args = vfs_plugin.ApiCreateVfsRefreshOperationArgs(
       client_id=self.client_id, file_path=directory)
   result = self.handler.Handle(args, context=self.context)
   flow_obj = data_store.REL_DB.ReadFlowObject(self.client_id,
                                               result.operation_id)
   self.assertEqual(flow_obj.args.pathspec, expected_pathspec)
コード例 #5
0
ファイル: vfs_test.py プロジェクト: avmi/grr
  def testHandlerRefreshStartsRecursiveListDirectoryFlow(self):
    fixture_test_lib.ClientFixture(self.client_id)

    args = vfs_plugin.ApiCreateVfsRefreshOperationArgs(
        client_id=self.client_id, file_path=self.file_path, max_depth=5)
    result = self.handler.Handle(args, context=self.context)

    flow_obj = data_store.REL_DB.ReadFlowObject(self.client_id,
                                                result.operation_id)
    self.assertEqual(flow_obj.flow_class_name, "RecursiveListDirectory")
コード例 #6
0
ファイル: vfs_test.py プロジェクト: avmi/grr
  def testRaisesOnNonExistentPath(self):
    args = vfs_plugin.ApiCreateVfsRefreshOperationArgs(
        client_id=self.client_id, file_path="fs/os/foo/bar")
    with self.assertRaises(vfs_plugin.FileNotFoundError) as context:
      self.handler.Handle(args, context=self.context)

    exception = context.exception
    self.assertEqual(exception.client_id, self.client_id)
    self.assertEqual(exception.path_type, rdf_objects.PathInfo.PathType.OS)
    self.assertCountEqual(exception.components, ["foo", "bar"])
コード例 #7
0
    def testHandlerRefreshStartsRecursiveListDirectoryFlow(self):
        fixture_test_lib.ClientFixture(self.client_id, token=self.token)

        args = vfs_plugin.ApiCreateVfsRefreshOperationArgs(
            client_id=self.client_id, file_path=self.file_path, max_depth=5)
        result = self.handler.Handle(args, token=self.token)

        # Check returned operation_id to references a RecursiveListDirectory flow.
        flow_obj = aff4.FACTORY.Open(result.operation_id, token=self.token)
        self.assertEqual(flow_obj.Get(flow_obj.Schema.TYPE),
                         filesystem.RecursiveListDirectory.__name__)
コード例 #8
0
ファイル: vfs_test.py プロジェクト: x35029/grr
  def testHandlerRefreshStartsListDirectoryFlow(self):
    fixture_test_lib.ClientFixture(self.client_id, token=self.token)

    args = vfs_plugin.ApiCreateVfsRefreshOperationArgs(
        client_id=self.client_id, file_path=self.file_path, max_depth=1)
    result = self.handler.Handle(args, token=self.token)

    if data_store.RelationalDBFlowsEnabled():
      flow_obj = data_store.REL_DB.ReadFlowObject(self.client_id.Basename(),
                                                  result.operation_id)
      self.assertEqual(flow_obj.flow_class_name, "ListDirectory")
    else:
      # Check returned operation_id to references a ListDirectory flow.
      flow_urn = self.client_id.Add("flows").Add(result.operation_id)
      flow_obj = aff4.FACTORY.Open(flow_urn, token=self.token)
      self.assertEqual(
          flow_obj.Get(flow_obj.Schema.TYPE), filesystem.ListDirectory.__name__)
コード例 #9
0
  def Run(self):
    client_id = self.SetupClient(0)

    # Choose some directory with pathspec in the ClientFixture.
    self.file_path = "fs/os/Users/Shared"

    fixture_test_lib.ClientFixture(client_id)

    def ReplaceFlowId():
      flows = data_store.REL_DB.ReadAllFlowObjects(client_id=client_id)
      return {flows[0].flow_id: "ABCDEF"}

    with test_lib.FakeTime(42):
      self.Check(
          "CreateVfsRefreshOperation",
          args=vfs_plugin.ApiCreateVfsRefreshOperationArgs(
              client_id=client_id, file_path=self.file_path, max_depth=1),
          replace=ReplaceFlowId)
コード例 #10
0
ファイル: vfs_test.py プロジェクト: avmi/grr
  def testNotificationIsSent(self):
    fixture_test_lib.ClientFixture(self.client_id)

    args = vfs_plugin.ApiCreateVfsRefreshOperationArgs(
        client_id=self.client_id,
        file_path=self.file_path,
        max_depth=0,
        notify_user=True)
    result = self.handler.Handle(args, context=self.context)

    flow_test_lib.RunFlow(
        self.client_id, result.operation_id, check_flow_errors=False)

    pending_notifications = self.GetUserNotifications(self.context.username)

    self.assertIn("Recursive Directory Listing complete",
                  pending_notifications[0].message)

    self.assertEqual(
        pending_notifications[0].reference.vfs_file.path_components,
        ["Users", "Shared"])
コード例 #11
0
ファイル: vfs_test.py プロジェクト: avmi/grr
 def testRaisesIfFirstComponentNotInAllowlist(self):
   args = vfs_plugin.ApiCreateVfsRefreshOperationArgs(
       client_id=self.client_id, file_path="/analysis")
   with self.assertRaises(ValueError):
     self.handler.Handle(args, context=self.context)
コード例 #12
0
ファイル: vfs_test.py プロジェクト: avmi/grr
 def testRaisesOnRootPath(self):
   args = vfs_plugin.ApiCreateVfsRefreshOperationArgs(
       client_id=self.client_id, file_path="/")
   with self.assertRaises(ValueError):
     self.handler.Handle(args, context=self.context)
コード例 #13
0
ファイル: vfs_test.py プロジェクト: x35029/grr
 def testRaisesOnEmptyPath(self):
   args = vfs_plugin.ApiCreateVfsRefreshOperationArgs(
       client_id=self.client_id, file_path="")
   with self.assertRaises(ValueError):
     self.handler.Handle(args, token=self.token)