Пример #1
0
    def test_disable_synchronized_plugin_configuration(self):
        # Create api_ref
        api_ref = APIReferenceFactory(upstream_url=fake.url(), request_host=fake.domain_name())

        # Mark for auto cleanup
        self._cleanup_afterwards(api_ref)

        # Publish api
        logic.synchronize_api(self.client, api_ref)

        # Create plugin_configuration
        plugin_configuration_ref = PluginConfigurationReferenceFactory(api=api_ref)

        # Publish plugin_configuration
        logic.synchronize_plugin_configuration(self.client, plugin_configuration_ref)

        # Check
        result = self.client.apis.plugins(api_ref.kong_id).retrieve(plugin_configuration_ref.kong_id)
        self.assertIsNotNone(result)
        self.assertEqual(result['name'], Plugins.label(plugin_configuration_ref.plugin))
        self.assertTrue(result['enabled'])

        # Update plugin_configuration
        logic.enable_plugin_configuration(self.client, plugin_configuration_ref, enabled=False)

        # Check
        result = self.client.apis.plugins(api_ref.kong_id).retrieve(plugin_configuration_ref.kong_id)
        self.assertIsNotNone(result)
        self.assertEqual(result['name'], Plugins.label(plugin_configuration_ref.plugin))
        self.assertFalse(result['enabled'])
Пример #2
0
    def test_delete_synchronized_plugin_configuration(self):
        # Create api_ref
        api_ref = APIReferenceFactory(upstream_url=fake.url(),
                                      request_host=fake.domain_name())

        # Mark for auto cleanup
        self._cleanup_afterwards(api_ref)

        # Publish api
        logic.synchronize_api(self.client, api_ref)

        # Create plugin_configuration
        plugin_configuration_ref = PluginConfigurationReferenceFactory(
            api=api_ref)

        # Publish plugin_configuration
        logic.synchronize_plugin_configuration(self.client,
                                               plugin_configuration_ref)

        # Check
        result = self.client.apis.plugins(api_ref.kong_id).retrieve(
            plugin_configuration_ref.kong_id)
        self.assertIsNotNone(result)
        self.assertEqual(result['name'],
                         Plugins.label(plugin_configuration_ref.plugin))

        # Delete plugin_configuration
        plugin_configuration_kong_id = plugin_configuration_ref.kong_id
        plugin_configuration_ref.delete()

        # Check
        with self.assertRaises(ValueError):
            _ = self.client.apis.plugins(
                api_ref.kong_id).retrieve(plugin_configuration_kong_id)
Пример #3
0
    def test_update_synchronized_plugin_configuration(self):
        # Create api_ref
        api_ref = APIReferenceFactory(upstream_url=fake.url(), request_host=fake.domain_name())

        # Mark for auto cleanup
        self._cleanup_afterwards(api_ref)

        # Publish api
        logic.synchronize_api(self.client, api_ref)

        # Create plugin_configuration
        plugin_configuration_ref = PluginConfigurationReferenceFactory(api=api_ref)

        # Publish plugin_configuration
        logic.synchronize_plugin_configuration(self.client, plugin_configuration_ref)

        # Check
        result = self.client.apis.plugins(api_ref.kong_id).retrieve(plugin_configuration_ref.kong_id)
        self.assertIsNotNone(result)
        self.assertEqual(result['name'], Plugins.label(plugin_configuration_ref.plugin))
        self.assertEqual(result['config']['second'], plugin_configuration_ref.config['second'])

        # Update plugin_configuration
        new_value = 5
        self.assertNotEqual(new_value, plugin_configuration_ref.config['second'])
        plugin_configuration_ref.config['second'] = new_value
        plugin_configuration_ref.save()
        logic.publish_plugin_configuration(self.client, plugin_configuration_ref)

        # Check
        result = self.client.apis.plugins(api_ref.kong_id).retrieve(plugin_configuration_ref.kong_id)
        self.assertIsNotNone(result)
        self.assertEqual(result['name'], Plugins.label(plugin_configuration_ref.plugin))
        self.assertEqual(result['config']['second'], plugin_configuration_ref.config['second'])
Пример #4
0
    def test_sync_plugin_configuration(self):
        # Create api_ref
        api_ref = APIReferenceFactory(upstream_url=fake.url(),
                                      request_host=fake.domain_name())

        # Mark for auto cleanup
        self._cleanup_afterwards(api_ref)

        # Publish api
        logic.synchronize_api(self.client, api_ref)

        # Check if remote upstream_url matches the locally known upstream_url
        result = self.client.apis.retrieve(api_ref.kong_id)
        self.assertIsNotNone(result)
        self.assertEqual(result['upstream_url'], api_ref.upstream_url)

        # Create plugin_configuration
        plugin_configuration_ref = PluginConfigurationReferenceFactory(
            api=api_ref)

        # Publish plugin_configuration
        logic.synchronize_plugin_configuration(self.client,
                                               plugin_configuration_ref)

        # Check
        result = self.client.apis.plugins(api_ref.kong_id).retrieve(
            plugin_configuration_ref.kong_id)
        self.assertIsNotNone(result)
        self.assertEqual(result['name'],
                         Plugins.label(plugin_configuration_ref.plugin))
Пример #5
0
    def test_delete_synchronized_plugin_configuration(self):
        # Create api_ref
        api_ref = APIReferenceFactory(upstream_url=fake.url(), request_host=fake.domain_name())

        # Mark for auto cleanup
        self._cleanup_afterwards(api_ref)

        # Publish api
        logic.synchronize_api(self.client, api_ref)

        # Create plugin_configuration
        plugin_configuration_ref = PluginConfigurationReferenceFactory(api=api_ref)

        # Publish plugin_configuration
        logic.synchronize_plugin_configuration(self.client, plugin_configuration_ref)

        # Check
        result = self.client.apis.plugins(api_ref.kong_id).retrieve(plugin_configuration_ref.kong_id)
        self.assertIsNotNone(result)
        self.assertEqual(result['name'], Plugins.label(plugin_configuration_ref.plugin))

        # Delete plugin_configuration
        plugin_configuration_kong_id = plugin_configuration_ref.kong_id
        plugin_configuration_ref.delete()

        # Check
        with self.assertRaises(ValueError):
            _ = self.client.apis.plugins(api_ref.kong_id).retrieve(plugin_configuration_kong_id)
Пример #6
0
    def test_sync_plugin_configuration_without_fields(self):
        # Create api_ref
        api_ref = APIReferenceFactory(upstream_url=fake.url(),
                                      request_host=fake.domain_name())

        # Mark for auto cleanup
        self._cleanup_afterwards(api_ref)

        # Publish api
        logic.synchronize_api(self.client, api_ref)

        # Check if remote upstream_url matches the locally known upstream_url
        result = self.client.apis.retrieve(api_ref.kong_id)
        self.assertIsNotNone(result)
        self.assertEqual(result['upstream_url'], api_ref.upstream_url)

        # Create plugin_configuration
        plugin_configuration_ref = PluginConfigurationReferenceFactory(
            api=api_ref, config={})

        # Attempt to publish
        with self.assertRaises(ValueError):
            logic.synchronize_plugin_configuration(self.client,
                                                   plugin_configuration_ref)

        # Make sure we did not get a Kong ID (meaning it did not sync to Kong)
        self.assertIsNone(plugin_configuration_ref.kong_id)
    def test_sync_plugin_configuration(self):
        # Create api_ref
        api_ref = APIReferenceFactory(upstream_url=fake.url(), request_host=fake.domain_name())

        # Mark for auto cleanup
        self._cleanup_afterwards(api_ref)

        # Publish api
        logic.synchronize_api(self.client, api_ref)

        # Check if remote upstream_url matches the locally known upstream_url
        result = self.client.apis.retrieve(api_ref.kong_id)
        self.assertIsNotNone(result)
        self.assertEqual(result['upstream_url'], api_ref.upstream_url)

        # Create plugin_configuration
        plugin_configuration_ref = PluginConfigurationReferenceFactory(api=api_ref)

        # Publish plugin_configuration
        logic.synchronize_plugin_configuration(self.client, plugin_configuration_ref)

        # Check
        result = self.client.apis.plugins(api_ref.kong_id).retrieve(plugin_configuration_ref.kong_id)
        self.assertIsNotNone(result)
        self.assertEqual(result['name'], Plugins.label(plugin_configuration_ref.plugin))
Пример #8
0
    def test_sync_plugin_configuration_before_api(self):
        # Create api_ref
        api_ref = APIReferenceFactory(upstream_url=fake.url(), request_host=fake.domain_name())

        # Mark for auto cleanup
        self._cleanup_afterwards(api_ref)

        # Create plugin_configuration
        plugin_configuration_ref = PluginConfigurationReferenceFactory(api=api_ref)

        # Attempt to publish
        with self.assertRaises(ValueError):
            logic.synchronize_plugin_configuration(self.client, plugin_configuration_ref)
Пример #9
0
    def test_sync_plugin_configuration_before_api(self):
        # Create api_ref
        api_ref = APIReferenceFactory(upstream_url=fake.url(),
                                      request_host=fake.domain_name())

        # Mark for auto cleanup
        self._cleanup_afterwards(api_ref)

        # Create plugin_configuration
        plugin_configuration_ref = PluginConfigurationReferenceFactory(
            api=api_ref)

        # Attempt to publish
        with self.assertRaises(ValueError):
            logic.synchronize_plugin_configuration(self.client,
                                                   plugin_configuration_ref)
Пример #10
0
    def test_update_synchronized_plugin_configuration(self):
        # Create api_ref
        api_ref = APIReferenceFactory(upstream_url=fake.url(),
                                      request_host=fake.domain_name())

        # Mark for auto cleanup
        self._cleanup_afterwards(api_ref)

        # Publish api
        logic.synchronize_api(self.client, api_ref)

        # Create plugin_configuration
        plugin_configuration_ref = PluginConfigurationReferenceFactory(
            api=api_ref)

        # Publish plugin_configuration
        logic.synchronize_plugin_configuration(self.client,
                                               plugin_configuration_ref)

        # Check if remote plugin name matches the locally known plugin, and that the configuration matches the locally
        #   known configuration
        result = self.client.apis.plugins(api_ref.kong_id).retrieve(
            plugin_configuration_ref.kong_id)
        self.assertIsNotNone(result)
        self.assertEqual(result['name'],
                         Plugins.label(plugin_configuration_ref.plugin))
        self.assertEqual(result['config']['second'],
                         plugin_configuration_ref.config['second'])

        # Update plugin_configuration
        new_value = 5
        self.assertNotEqual(new_value,
                            plugin_configuration_ref.config['second'])
        plugin_configuration_ref.config['second'] = new_value
        plugin_configuration_ref.save()
        logic.publish_plugin_configuration(self.client,
                                           plugin_configuration_ref)

        # Check
        result = self.client.apis.plugins(api_ref.kong_id).retrieve(
            plugin_configuration_ref.kong_id)
        self.assertIsNotNone(result)
        self.assertEqual(result['name'],
                         Plugins.label(plugin_configuration_ref.plugin))
        self.assertEqual(result['config']['second'],
                         plugin_configuration_ref.config['second'])
Пример #11
0
    def test_sync_plugin_configuration_without_fields(self):
        # Create api_ref
        api_ref = APIReferenceFactory(upstream_url=fake.url(), request_host=fake.domain_name())

        # Mark for auto cleanup
        self._cleanup_afterwards(api_ref)

        # Publish api
        logic.synchronize_api(self.client, api_ref)

        # Check
        result = self.client.apis.retrieve(api_ref.kong_id)
        self.assertIsNotNone(result)
        self.assertEqual(result['upstream_url'], api_ref.upstream_url)

        # Create plugin_configuration
        plugin_configuration_ref = PluginConfigurationReferenceFactory(api=api_ref, config={})

        # Attempt to publish
        with self.assertRaises(ValueError):
            logic.synchronize_plugin_configuration(self.client, plugin_configuration_ref)
Пример #12
0
    def test_disable_synchronized_plugin_configuration(self):
        # Create api_ref
        api_ref = APIReferenceFactory(upstream_url=fake.url(),
                                      request_host=fake.domain_name())

        # Mark for auto cleanup
        self._cleanup_afterwards(api_ref)

        # Publish api
        logic.synchronize_api(self.client, api_ref)

        # Create plugin_configuration
        plugin_configuration_ref = PluginConfigurationReferenceFactory(
            api=api_ref)

        # Publish plugin_configuration
        logic.synchronize_plugin_configuration(self.client,
                                               plugin_configuration_ref)

        # Check
        result = self.client.apis.plugins(api_ref.kong_id).retrieve(
            plugin_configuration_ref.kong_id)
        self.assertIsNotNone(result)
        self.assertEqual(result['name'],
                         Plugins.label(plugin_configuration_ref.plugin))
        self.assertTrue(result['enabled'])

        # Update plugin_configuration
        logic.enable_plugin_configuration(self.client,
                                          plugin_configuration_ref,
                                          enabled=False)

        # Check
        result = self.client.apis.plugins(api_ref.kong_id).retrieve(
            plugin_configuration_ref.kong_id)
        self.assertIsNotNone(result)
        self.assertEqual(result['name'],
                         Plugins.label(plugin_configuration_ref.plugin))
        self.assertFalse(result['enabled'])