예제 #1
0
    def testHandlerRespectsTimestamp(self):
        # TODO(hanuszczak): Enable this test in relational database mode once
        # timestamp-specific file listing is supported by the data store.
        if data_store.RelationalDBReadEnabled():
            raise unittest.SkipTest(
                "relational backend does not support timestamp-"
                "specific file listing")

        # file_path is "fs/os/etc", a directory.
        self.CreateFileVersions(self.client_id, self.file_path + "/file")

        args = vfs_plugin.ApiListFilesArgs(client_id=self.client_id,
                                           file_path=self.file_path,
                                           timestamp=self.time_2)
        result = self.handler.Handle(args, token=self.token)
        self.assertEqual(len(result.items), 1)
        self.assertEqual(result.items[0].last_collected_size, 13)

        args = vfs_plugin.ApiListFilesArgs(client_id=self.client_id,
                                           file_path=self.file_path,
                                           timestamp=self.time_1)
        result = self.handler.Handle(args, token=self.token)
        self.assertEqual(len(result.items), 1)
        self.assertEqual(result.items[0].last_collected_size, 11)

        args = vfs_plugin.ApiListFilesArgs(client_id=self.client_id,
                                           file_path=self.file_path,
                                           timestamp=self.time_0)
        result = self.handler.Handle(args, token=self.token)
        self.assertEqual(len(result.items), 0)
예제 #2
0
파일: vfs_test.py 프로젝트: avmi/grr
  def testHandlerRespectsTimestamp(self):
    # file_path is "fs/os/etc", a directory.
    self.CreateFileVersions(self.client_id, self.file_path + "/file")

    args = vfs_plugin.ApiListFilesArgs(
        client_id=self.client_id,
        file_path=self.file_path,
        timestamp=self.time_2)
    result = self.handler.Handle(args, context=self.context)
    self.assertLen(result.items, 1)
    self.assertIsInstance(result.items[0].last_collected_size, int)
    self.assertEqual(result.items[0].last_collected_size, 13)

    args = vfs_plugin.ApiListFilesArgs(
        client_id=self.client_id,
        file_path=self.file_path,
        timestamp=self.time_1)
    result = self.handler.Handle(args, context=self.context)
    self.assertLen(result.items, 1)
    self.assertEqual(result.items[0].last_collected_size, 11)

    args = vfs_plugin.ApiListFilesArgs(
        client_id=self.client_id,
        file_path=self.file_path,
        timestamp=self.time_0)
    result = self.handler.Handle(args, context=self.context)
    self.assertEmpty(result.items)
예제 #3
0
 def Run(self):
     client_id = self.SetupClient(0).Basename()
     fixture_test_lib.ClientFixture(client_id, token=self.token, age=42)
     self.Check(
         "ListFiles",
         vfs_plugin.ApiListFilesArgs(client_id=client_id,
                                     file_path="fs/tsk/c/bin"))
     self.Check(
         "ListFiles",
         vfs_plugin.ApiListFilesArgs(client_id=client_id,
                                     file_path="fs/tsk/c/bin",
                                     timestamp=self.time_2))
예제 #4
0
 def Run(self):
     client_id = self.SetupClient(0)
     with test_lib.FakeTime(42):
         fixture_test_lib.ClientFixture(client_id)
     self.Check(
         "ListFiles",
         vfs_plugin.ApiListFilesArgs(client_id=client_id,
                                     file_path="fs/tsk/c/bin"))
     self.Check(
         "ListFiles",
         vfs_plugin.ApiListFilesArgs(client_id=client_id,
                                     file_path="fs/tsk/c/bin",
                                     timestamp=self.time_2))
예제 #5
0
 def testRoot(self):
     args = vfs_plugin.ApiListFilesArgs(client_id=self.client_id,
                                        file_path="/")
     result = self.handler.Handle(args, context=self.context)
     self.assertSameElements([(item.name, item.path)
                              for item in result.items], [("fs", "fs"),
                                                          ("temp", "temp")])
    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)
예제 #7
0
파일: vfs_test.py 프로젝트: avmi/grr
  def testHandlerListsFilesAndDirectories(self):
    fixture_test_lib.ClientFixture(self.client_id)

    # Fetch all children of a directory.
    args = vfs_plugin.ApiListFilesArgs(
        client_id=self.client_id, file_path=self.file_path)
    result = self.handler.Handle(args, context=self.context)

    self.assertLen(result.items, 4)
    for item in result.items:
      # Check that all files are really in the right directory.
      self.assertIn(self.file_path, item.path)
예제 #8
0
    def testHandlerFiltersDirectoriesIfFlagIsSet(self):
        fixture_test_lib.ClientFixture(self.client_id)

        # Only fetch sub-directories.
        args = vfs_plugin.ApiListFilesArgs(client_id=self.client_id,
                                           file_path=self.file_path,
                                           directories_only=True)
        result = self.handler.Handle(args, context=self.context)

        self.assertLen(result.items, 1)
        self.assertEqual(result.items[0].is_directory, True)
        self.assertIn(self.file_path, result.items[0].path)
예제 #9
0
파일: vfs_test.py 프로젝트: avmi/grr
 def testRaisesIfFirstComponentIsNotAllowlisted(self):
   args = vfs_plugin.ApiListFilesArgs(
       client_id=self.client_id, file_path="/analysis")
   with self.assertRaises(ValueError):
     self.handler.Handle(args, context=self.context)
예제 #10
0
파일: vfs_test.py 프로젝트: avmi/grr
 def testDoesNotRaiseIfPathIsRoot(self):
   args = vfs_plugin.ApiListFilesArgs(client_id=self.client_id, file_path="/")
   self.handler.Handle(args, context=self.context)
예제 #11
0
파일: vfs_test.py 프로젝트: avmi/grr
 def testDoesNotRaiseIfFirstComponentIsEmpty(self):
   args = vfs_plugin.ApiListFilesArgs(client_id=self.client_id, file_path="")
   self.handler.Handle(args, context=self.context)