Esempio n. 1
0
    def test_secured_api_keys(self):
        hosts = F.hosts(self.client.app_id)

        config1 = SearchConfig(F.get_app_id(), F.get_api_key())
        config1.hosts = hosts
        client1 = F.decide(SearchClient.create_with_config(config1))

        index1 = F.index(client1, self._testMethodName)
        index2 = F.index(client1, '{}_dev'.format(self._testMethodName))

        index1.save_object({'objectID': 'one'}).wait()
        index2.save_object({'objectID': 'one'}).wait()

        api_key = self.client.generate_secured_api_key(
            os.environ['ALGOLIA_SEARCH_KEY_1'],
            {
                "validUntil": int(round(time.time())) + (60 * 10),  # + 10 min
                "restrictIndices": index1.name
            })

        config2 = SearchConfig(F.get_app_id(), api_key)
        config2.hosts = hosts
        client2 = F.decide(SearchClient.create_with_config(config2))

        index1_search = client2.init_index(index1.name)
        index2_search = client2.init_index(index2.name)

        index1_search.search('')
        with self.assertRaises(RequestException) as _:
            index2_search.search('')
Esempio n. 2
0
    def test_dns_timeout(self):
        config = SearchConfig(F.get_app_id(), F.get_api_key())

        config.hosts = HostsCollection([
            Host('algolia.biz', 10),
            Host('{}-1.algolianet.com'.format(F.get_app_id())),
            Host('{}-2.algolianet.com'.format(F.get_app_id())),
            Host('{}-3.algolianet.com'.format(F.get_app_id()))
        ])

        client = SearchClient.create_with_config(config)

        client.list_indices()
        # We test that the first Host `algolia.biz` is down.
        self.assertFalse(config.hosts.read()[0].up)
        self.assertTrue(config.hosts.read()[1].up)
        self.assertTrue(config.hosts.read()[2].up)
        self.assertTrue(config.hosts.read()[3].up)
    def test_dns_timeout(self):

        config = SearchConfig(F.get_app_id(), F.get_api_key())

        config.hosts = HostsCollection([
            Host('algolia.biz', 10),
            Host('{}-1.algolianet.com'.format(F.get_app_id())),
            Host('{}-2.algolianet.com'.format(F.get_app_id())),
            Host('{}-3.algolianet.com'.format(F.get_app_id()))
        ])

        client = SearchClient.create_with_config(config)

        client.list_indices()
        # We test that the first Host `algolia.biz` is down.
        self.assertFalse(config.hosts.read()[0].up)
        self.assertTrue(config.hosts.read()[1].up)
        self.assertTrue(config.hosts.read()[2].up)
        self.assertTrue(config.hosts.read()[3].up)