コード例 #1
0
    def test_external_api_mock_in_service_catalog_with_tenantid(self):
        """
        validate that the external API shows up in the service catalog
        when enabled globally and taht the tenantid will be properly
        in the URL.
        """
        for ept in self.eeapi.endpoint_templates.values():
            ept.internal_url = "http://internal.url/v1/%tenant_id%"
            ept.public_url = "http://public.url/v1/%tenant_id%"

        tenant_data = TenantAuthentication(self, self.root, "other", "other")

        ept_public_url = ("http://public.url/v1/" +
                          tenant_data.get_tenant_id())
        service_endpoint = tenant_data.get_service_endpoint(
            "externalServiceName", "EXTERNAL")
        self.assertEqual(service_endpoint, ept_public_url)
コード例 #2
0
    def test_external_api_mock_in_service_catalog_with_tenantid(self):
        """
        validate that the external API shows up in the service catalog
        when enabled globally and taht the tenantid will be properly
        in the URL.
        """
        for ept in self.eeapi.endpoint_templates.values():
            ept.internal_url = "http://internal.url/v1/%tenant_id%"
            ept.public_url = "http://public.url/v1/%tenant_id%"

        tenant_data = TenantAuthentication(self, self.root, "other", "other")

        ept_public_url = (
            "http://public.url/v1/" + tenant_data.get_tenant_id()
        )
        service_endpoint = tenant_data.get_service_endpoint(
            "externalServiceName", "EXTERNAL")
        self.assertEqual(
            service_endpoint,
            ept_public_url
        )
コード例 #3
0
class TestTenantSpecificAPIs(SynchronousTestCase):
    """
    Test cases where the external API is disabled globally but
    enabled for a specific tenant
    """
    def setUp(self):
        self.eeapi_name = u"externalServiceName"
        self.eeapi_template_id = u"uuid-endpoint-template"
        self.eeapi_template = exampleEndpointTemplate(
            name=self.eeapi_name,
            endpoint_uuid=self.eeapi_template_id
        )
        self.eeapi = make_example_external_api(
            self,
            name=self.eeapi_name,
            endpoint_templates=[self.eeapi_template],
            set_enabled=False
        )
        self.helper = APIMockHelper(self, [make_example_internal_api(self)])
        self.core = self.helper.core
        self.root = self.helper.root
        self.uri = self.helper.uri

        self.tenant_enabled_for = u"tenantWithApi"
        self.tenant_enabled_for_password = "******"
        self.tenant_data = TenantAuthentication(
            self,
            self.root,
            self.tenant_enabled_for,
            self.tenant_enabled_for_password
        )
        self.eeapi.enable_endpoint_for_tenant(
            self.tenant_data.get_tenant_id(),
            self.eeapi_template_id
        )
        self.core.add_api(self.eeapi)

    def test_single_endpoint_enabled_for_tenant(self):
        """
        Validate an endpoint can be enabled for a single tenant
        while being disabled globally for all tenants.
        """
        tenant_data = TenantAuthentication(
            self,
            self.root,
            self.tenant_enabled_for,
            self.tenant_enabled_for_password
        )
        externalService_endpoint = tenant_data.get_service_endpoint(
            "externalServiceName", "EXTERNAL")
        self.assertTrue(
            externalService_endpoint.startswith(
                'https://api.external.example.com:8080'))

    def test_disabled_globally_disabled(self):
        """
        Validate that even though an endpoint is enabled for one
        tenant that it remains globally disabled for all other tenants.
        """
        tenant_data = TenantAuthentication(self, self.root, "other", "other")
        with self.assertRaises(KeyError):
            tenant_data.get_service_endpoint(
                "serviceName", "EXTERNAL")

    def test_multiple_endpoints_enabled_for_tenant(self):
        """
        Validate when there are multiple endpoints enabled for a single
        tenant.
        """
        new_url = "https://api.new_region.example.com:9090"
        new_region = "NEW_REGION"
        new_eeapi_template_id = u"uuid-alternate-endpoint-template"
        new_eeapi_template = exampleEndpointTemplate(
            name=self.eeapi_name,
            endpoint_uuid=new_eeapi_template_id,
            region=new_region,
            url=new_url
        )
        self.eeapi.add_template(new_eeapi_template)
        self.eeapi.enable_endpoint_for_tenant(
            self.tenant_data.get_tenant_id(),
            new_eeapi_template_id
        )

        tenant_data = TenantAuthentication(
            self,
            self.root,
            self.tenant_enabled_for,
            self.tenant_enabled_for_password
        )
        externalService_endpoint = tenant_data.get_service_endpoint(
            "externalServiceName", new_region)
        self.assertTrue(
            externalService_endpoint.startswith(
                new_url))

    def test_multiple_endpoint_templates_only_one_enabled_for_tenant(self):
        """
        Code coverage for multiple templates when a disabled template
        is enabled for a specific tenant while another template remains
        in its default state.
        """
        new_url = "https://api.new_region.example.com:9090"
        new_region = "NEW_REGION"
        new_eeapi_template_id = u"uuid-alternate-endpoint-template"
        new_eeapi_template = exampleEndpointTemplate(
            name=self.eeapi_name,
            endpoint_uuid=new_eeapi_template_id,
            region=new_region,
            url=new_url
        )
        self.eeapi.add_template(new_eeapi_template)

        tenant_data = TenantAuthentication(
            self,
            self.root,
            self.tenant_enabled_for,
            self.tenant_enabled_for_password
        )
        with self.assertRaises(KeyError):
            tenant_data.get_service_endpoint("externalServiceName", new_region)
コード例 #4
0
class TestTenantSpecificAPIs(SynchronousTestCase):
    """
    Test cases where the external API is disabled globally but
    enabled for a specific tenant
    """
    def setUp(self):
        self.eeapi_name = u"externalServiceName"
        self.eeapi_template_id = u"uuid-endpoint-template"
        self.eeapi_template = exampleEndpointTemplate(
            name=self.eeapi_name, endpoint_uuid=self.eeapi_template_id)
        self.eeapi = make_example_external_api(
            self,
            name=self.eeapi_name,
            endpoint_templates=[self.eeapi_template],
            set_enabled=False)
        self.helper = APIMockHelper(self, [make_example_internal_api(self)])
        self.core = self.helper.core
        self.root = self.helper.root
        self.uri = self.helper.uri

        self.tenant_enabled_for = u"tenantWithApi"
        self.tenant_enabled_for_password = "******"
        self.tenant_data = TenantAuthentication(
            self, self.root, self.tenant_enabled_for,
            self.tenant_enabled_for_password)
        self.eeapi.enable_endpoint_for_tenant(self.tenant_data.get_tenant_id(),
                                              self.eeapi_template_id)
        self.core.add_api(self.eeapi)

    def test_single_endpoint_enabled_for_tenant(self):
        """
        Validate an endpoint can be enabled for a single tenant
        while being disabled globally for all tenants.
        """
        tenant_data = TenantAuthentication(self, self.root,
                                           self.tenant_enabled_for,
                                           self.tenant_enabled_for_password)
        externalService_endpoint = tenant_data.get_service_endpoint(
            "externalServiceName", "EXTERNAL")
        self.assertTrue(
            externalService_endpoint.startswith(
                'https://api.external.example.com:8080'))

    def test_disabled_globally_disabled(self):
        """
        Validate that even though an endpoint is enabled for one
        tenant that it remains globally disabled for all other tenants.
        """
        tenant_data = TenantAuthentication(self, self.root, "other", "other")
        with self.assertRaises(KeyError):
            tenant_data.get_service_endpoint("serviceName", "EXTERNAL")

    def test_multiple_endpoints_enabled_for_tenant(self):
        """
        Validate when there are multiple endpoints enabled for a single
        tenant.
        """
        new_url = "https://api.new_region.example.com:9090"
        new_region = "NEW_REGION"
        new_eeapi_template_id = u"uuid-alternate-endpoint-template"
        new_eeapi_template = exampleEndpointTemplate(
            name=self.eeapi_name,
            endpoint_uuid=new_eeapi_template_id,
            region=new_region,
            url=new_url)
        self.eeapi.add_template(new_eeapi_template)
        self.eeapi.enable_endpoint_for_tenant(self.tenant_data.get_tenant_id(),
                                              new_eeapi_template_id)

        tenant_data = TenantAuthentication(self, self.root,
                                           self.tenant_enabled_for,
                                           self.tenant_enabled_for_password)
        externalService_endpoint = tenant_data.get_service_endpoint(
            "externalServiceName", new_region)
        self.assertTrue(externalService_endpoint.startswith(new_url))

    def test_multiple_endpoint_templates_only_one_enabled_for_tenant(self):
        """
        Code coverage for multiple templates when a disabled template
        is enabled for a specific tenant while another template remains
        in its default state.
        """
        new_url = "https://api.new_region.example.com:9090"
        new_region = "NEW_REGION"
        new_eeapi_template_id = u"uuid-alternate-endpoint-template"
        new_eeapi_template = exampleEndpointTemplate(
            name=self.eeapi_name,
            endpoint_uuid=new_eeapi_template_id,
            region=new_region,
            url=new_url)
        self.eeapi.add_template(new_eeapi_template)

        tenant_data = TenantAuthentication(self, self.root,
                                           self.tenant_enabled_for,
                                           self.tenant_enabled_for_password)
        with self.assertRaises(KeyError):
            tenant_data.get_service_endpoint("externalServiceName", new_region)