Exemple #1
0
    def testAuditEntryIsCreatedForEveryClient(self):
        self.renderer.Render(client_plugin.ApiClientsAddLabelsRendererArgs(
            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 = test_lib.MockWorker(token=self.token)
        mock_worker.Simulate()

        parentdir = aff4.FACTORY.Open("aff4:/audit/logs", token=self.token)
        log = list(parentdir.ListChildren())[0]
        fd = aff4.FACTORY.Open(log, token=self.token)

        for client_id in self.client_ids:
            found_event = None
            for event in fd:
                if (event.action == flow.AuditEvent.Action.CLIENT_ADD_LABEL
                        and event.client == rdf_client.ClientURN(client_id)):
                    found_event = event
                    break

            self.assertFalse(found_event is None)

            self.assertEqual(found_event.user, self.token.username)
            self.assertEqual(found_event.description,
                             "test.drei,test.ein,test.zwei")
Exemple #2
0
    def testAddsSingleLabelToSingleClient(self):
        for client_id in self.client_ids:
            self.assertFalse(
                aff4.FACTORY.Open(client_id, token=self.token).GetLabels())

        result = self.renderer.Render(
            client_plugin.ApiClientsAddLabelsRendererArgs(
                client_ids=[self.client_ids[0]], labels=["foo"]),
            token=self.token)
        self.assertEqual(result["status"], "OK")

        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())
Exemple #3
0
    def testAddsTwoLabelsToTwoClients(self):
        for client_id in self.client_ids:
            self.assertFalse(
                aff4.FACTORY.Open(client_id, token=self.token).GetLabels())

        result = self.renderer.Render(
            client_plugin.ApiClientsAddLabelsRendererArgs(
                client_ids=[self.client_ids[0], self.client_ids[1]],
                labels=["foo", "bar"]),
            token=self.token)
        self.assertEqual(result["status"], "OK")

        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())