Esempio n. 1
0
    def setUp(self):
        super(GRRFuseTest, self).setUp()

        self.client_id = self.SetupClients(1)[0]

        self.client_name = str(self.client_id)[len("aff4:/"):]

        with aff4.FACTORY.Open(self.client_id, token=self.token,
                               mode="rw") as fd:
            fd.Set(fd.Schema.SYSTEM("Linux"))
            kb = fd.Schema.KNOWLEDGE_BASE()
            fd.Set(kb)

        with aff4.FACTORY.Create(self.client_id.Add("fs/os"),
                                 aff4_standard.VFSDirectory,
                                 mode="rw",
                                 token=self.token) as fd:
            fd.Set(fd.Schema.PATHSPEC(path="/", pathtype="OS"))

        # Ignore cache so our tests always get client side updates.
        self.grr_fuse = fuse_mount.GRRFuse(root="/",
                                           token=self.token,
                                           ignore_cache=True)

        self.action_mock = action_mocks.ActionMock(
            admin.GetClientInfo,
            admin.GetConfiguration,
            admin.GetPlatformInfo,
            file_fingerprint.FingerprintFile,
            linux.EnumerateFilesystems,
            linux.EnumerateInterfaces,
            linux.EnumerateUsers,
            linux.GetInstallDate,
            searching.Find,
            standard.HashBuffer,
            standard.ListDirectory,
            standard.StatFile,
            standard.TransferBuffer,
        )

        self.client_mock = flow_test_lib.MockClient(self.client_id,
                                                    self.action_mock,
                                                    token=self.token)

        self.update_stubber = utils.Stubber(self.grr_fuse,
                                            "_RunAndWaitForVFSFileUpdate",
                                            self._RunAndWaitForVFSFileUpdate)
        self.update_stubber.Start()

        self.start_flow_stubber = utils.Stubber(flow_utils, "StartFlowAndWait",
                                                self.StartFlowAndWait)
        self.start_flow_stubber.Start()
Esempio n. 2
0
  def __init__(self, method_name=None):
    super(GRRFuseTest, self).__init__(method_name)

    # Set up just once for the whole test suite, since we don't have any
    # per-test setup to do.
    super(GRRFuseTest, self).setUp()

    self.client_name = str(self.client_id)[len("aff4:/"):]

    with aff4.FACTORY.Open(self.client_id, token=self.token, mode="rw") as fd:
      fd.Set(fd.Schema.SYSTEM("Linux"))
      kb = fd.Schema.KNOWLEDGE_BASE()
      fd.Set(kb)

    # Ignore cache so our tests always get client side updates.
    self.grr_fuse = fuse_mount.GRRFuse(root="/", token=self.token,
                                       ignore_cache=True)

    self.action_mock = test_lib.ActionMock("TransferBuffer", "StatFile", "Find",
                                           "HashFile", "HashBuffer",
                                           "UpdateVFSFile",
                                           "EnumerateInterfaces",
                                           "EnumerateFilesystems",
                                           "GetConfiguration",
                                           "GetConfig", "GetClientInfo",
                                           "GetInstallDate", "GetPlatformInfo",
                                           "EnumerateUsers", "ListDirectory")

    client_mock = test_lib.MockClient(self.client_id, self.action_mock,
                                      token=self.token)

    worker_mock = test_lib.MockWorker(check_flow_errors=True, token=self.token)

    # All the flows we've run so far. We'll check them for errors at the end of
    # each test.
    self.total_flows = set()

    # We add the thread as a class variable since we'll be referring to it in
    # the tearDownClass method, and we want all tests to share it.
    self.__class__.fake_server_thread = threading.Thread(
        target=self.RunFakeWorkerAndClient,
        args=(client_mock,
              worker_mock))
    self.fake_server_thread.start()