Пример #1
0
    def testAddsSingleLabelToSingleClient(self):
        for client_id in self.client_ids:
            self.assertFalse(
                aff4.FACTORY.Open(client_id, token=self.token).GetLabels())
            data_store.REL_DB.WriteClientMetadata(client_id.Basename(),
                                                  fleetspeak_enabled=False)

        self.handler.Handle(client_plugin.ApiAddClientsLabelsArgs(
            client_ids=[self.client_ids[0]], labels=["foo"]),
                            token=self.token)

        # AFF4 labels.
        labels = aff4.FACTORY.Open(self.client_ids[0],
                                   token=self.token).GetLabels()
        self.assertEqual(len(labels), 1)
        self.assertEqual(labels[0].name, "foo")
        self.assertEqual(labels[0].owner, self.token.username)

        for client_id in self.client_ids[1:]:
            self.assertFalse(
                aff4.FACTORY.Open(client_id, token=self.token).GetLabels())

        # Relational DB labels.
        cid = self.client_ids[0].Basename()
        labels = data_store.REL_DB.ReadClientLabels(cid)
        self.assertEqual(len(labels), 1)
        self.assertEqual(labels[0].name, "foo")
        self.assertEqual(labels[0].owner, self.token.username)

        for client_id in self.client_ids[1:]:
            self.assertFalse(
                data_store.REL_DB.ReadClientLabels(client_id.Basename()))
Пример #2
0
    def testAuditEntryIsCreatedForEveryClient(self):
        self.handler.Handle(client_plugin.ApiAddClientsLabelsArgs(
            client_ids=self.client_ids, labels=["drei", "ein", "zwei"]),
                            token=self.token)

        # We need to run .Simulate() so that the appropriate event is fired,
        # collected, and finally written to the logs that we inspect.
        mock_worker = worker_test_lib.MockWorker(token=self.token)
        mock_worker.Simulate()

        event = self._FindAuditEvent()
        self.assertIsNotNone(event)
        self.assertEqual(event.user, self.token.username)
        self.assertEqual(
            event.description, "%s.drei,%s.ein,%s.zwei" %
            (self.token.username, self.token.username, self.token.username))
Пример #3
0
    def testAddsTwoLabelsToTwoClients(self):
        for client_id in self.client_ids:
            self.assertFalse(
                aff4.FACTORY.Open(client_id, token=self.token).GetLabels())
            data_store.REL_DB.WriteClientMetadata(client_id.Basename(),
                                                  fleetspeak_enabled=False)

        self.handler.Handle(client_plugin.ApiAddClientsLabelsArgs(
            client_ids=[self.client_ids[0], self.client_ids[1]],
            labels=["foo", "bar"]),
                            token=self.token)

        # AFF4 labels.
        for client_id in self.client_ids[:2]:
            labels = aff4.FACTORY.Open(client_id, token=self.token).GetLabels()
            self.assertEqual(len(labels), 2)
            self.assertEqual(labels[0].name, "foo")
            self.assertEqual(labels[0].owner, self.token.username)
            self.assertEqual(labels[1].name, "bar")
            self.assertEqual(labels[1].owner, self.token.username)

        self.assertFalse(
            aff4.FACTORY.Open(self.client_ids[2],
                              token=self.token).GetLabels())

        # Relational labels.
        for client_id in self.client_ids[:2]:
            labels = data_store.REL_DB.ReadClientLabels(client_id.Basename())
            self.assertEqual(len(labels), 2)
            self.assertEqual(labels[0].owner, self.token.username)
            self.assertEqual(labels[1].owner, self.token.username)
            self.assertItemsEqual([labels[0].name, labels[1].name],
                                  ["bar", "foo"])

        self.assertFalse(
            data_store.REL_DB.ReadClientLabels(self.client_ids[2].Basename()))