Ejemplo n.º 1
0
    def testSearchWithBlacklistedClientIdsReturnsNothing(self):
        result = self.handler.Handle(
            client_plugin.ApiSearchClientsArgs(query=self.client_ids[1]),
            token=self.token)
        self.assertFalse(result.items)

        result = self.handler.Handle(
            client_plugin.ApiSearchClientsArgs(query=self.client_ids[2]),
            token=self.token)
        self.assertFalse(result.items)
Ejemplo n.º 2
0
    def testSearchWithWhitelistedClientIdsReturnsSubSet(self):
        result = self.handler.Handle(
            client_plugin.ApiSearchClientsArgs(query=self.client_ids[0]),
            token=self.token)
        self.assertEqual(len(result.items), 1)
        self.assertEqual(result.items[0].client_id, self.client_ids[0])

        result = self.handler.Handle(
            client_plugin.ApiSearchClientsArgs(query=self.client_ids[3]),
            token=self.token)
        self.assertEqual(len(result.items), 1)
        self.assertEqual(result.items[0].client_id, self.client_ids[3])
Ejemplo n.º 3
0
    def testSearchOrder(self):
        self._Setup100Clients()

        result = self.handler.Handle(client_plugin.ApiSearchClientsArgs(
            query="label:foo", offset=0, count=1000),
                                     token=self.token)
        self.assertEqual([str(res.client_id) for res in result.items],
                         self.client_ids)

        result = []
        for offset, count in [(0, 10), (10, 40), (50, 25), (75, 500)]:
            result.extend(
                self.handler.Handle(client_plugin.ApiSearchClientsArgs(
                    query="label:foo", offset=offset, count=count),
                                    token=self.token).items)
        self.assertEqual([str(res.client_id) for res in result],
                         self.client_ids)
Ejemplo n.º 4
0
    def testSearchWithoutArgsReturnsOnlyClientsWithWhitelistedLabels(self):
        result = self.handler.Handle(client_plugin.ApiSearchClientsArgs(),
                                     token=self.token)

        self.assertEqual(len(result.items), 2)
        sorted_items = sorted(result.items, key=lambda r: r.client_id)

        self.assertEqual(sorted_items[0].client_id, self.client_ids[0])
        self.assertEqual(sorted_items[1].client_id, self.client_ids[3])
Ejemplo n.º 5
0
  def Run(self):
    # Fix the time to avoid regressions.
    with test_lib.FakeTime(42):
      if data_store.RelationalDBReadEnabled():
        client_obj = self.SetupTestClientObject(0)
        client_id = client_obj.client_id
      else:
        client_urn = self.SetupClient(0, add_cert=False)
        client_id = client_urn.Basename()

      self.Check(
          "SearchClients",
          args=client_plugin.ApiSearchClientsArgs(query=client_id))
Ejemplo n.º 6
0
 def testSearchWithNonWhitelistedLabelReturnsNothing(self):
     result = self.handler.Handle(
         client_plugin.ApiSearchClientsArgs(query="label:not-foo"),
         token=self.token)
     self.assertFalse(result.items)