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)
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_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_external_api_mock_in_service_catalog(self): """ """ tenant_data = TenantAuthentication(self, self.root, "other", "other") service_endpoint = tenant_data.get_service_endpoint( "externalServiceName", "EXTERNAL") self.assertTrue( service_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_external_api_mock_in_service_catalog(self): """ Validate that the external API shows up in the service catalog when enabled globally for all tenants. """ tenant_data = TenantAuthentication(self, self.root, "other", "other") service_endpoint = tenant_data.get_service_endpoint( "externalServiceName", "EXTERNAL") self.assertEqual(service_endpoint, 'https://api.external.example.com:8080')
def test_external_api_mock_in_service_catalog(self): """ Validate that the external API shows up in the service catalog when enabled globally for all tenants. """ tenant_data = TenantAuthentication(self, self.root, "other", "other") service_endpoint = tenant_data.get_service_endpoint( "externalServiceName", "EXTERNAL") self.assertEqual( service_endpoint, 'https://api.external.example.com:8080' )
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_different_tenants_same_region(self): """ Creating a server for one tenant in a particular region should not create it for other tenants in the same region. """ other_tenant = TenantAuthentication(self, self.root, "other", "other") response, response_body = self.successResultOf( json_request(self, self.root, "GET", other_tenant.nth_endpoint_public(0) + '/servers')) self.assertEqual(response.code, 200) self.assertEqual(response_body, {'servers': []})
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 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_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)
def test_different_tenants_same_region_different_lbs(self): """ Creating a LB for one tenant in a particular region should not create it for other tenants in the same region. """ self._create_loadbalancer() other_tenant = TenantAuthentication(self, self.root, "other", "other") list_lb_response, list_lb_response_body = self.successResultOf( request_with_content( self, self.root, "GET", other_tenant.nth_endpoint_public(0) + "/loadbalancers")) self.assertEqual(list_lb_response.code, 200) list_lb_response_body = json.loads(list_lb_response_body) self.assertEqual(list_lb_response_body, {"loadBalancers": []})
def test_internal_vs_external_api_in_service_catalog(self): """ Check both :obj:`IAPIMock` and :obj:`IExternalAPIMock` exist in the same service catalog. """ tenant_data = TenantAuthentication(self, self.root, "other", "other") # there shouldn't an internal entry in the external region with self.assertRaises(KeyError): tenant_data.get_service_endpoint( "serviceName", "EXTERNAL") # pull both regions and verify they don't match externalService_endpoint = tenant_data.get_service_endpoint( "externalServiceName", "EXTERNAL") internalService_endpoint = tenant_data.get_service_endpoint( "serviceName", "ORD") self.assertNotEqual(externalService_endpoint, internalService_endpoint)
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 )
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)
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_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_internal_vs_external_api_in_service_catalog(self): """ Check both :obj:`IAPIMock` and :obj:`IExternalAPIMock` exist in the same service catalog. """ tenant_data = TenantAuthentication(self, self.root, "other", "other") # there shouldn't an internal entry in the external region with self.assertRaises(KeyError): tenant_data.get_service_endpoint("serviceName", "EXTERNAL") # pull both regions and verify they don't match externalService_endpoint = tenant_data.get_service_endpoint( "externalServiceName", "EXTERNAL") internalService_endpoint = tenant_data.get_service_endpoint( "serviceName", "ORD") self.assertNotEqual(externalService_endpoint, internalService_endpoint)
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)
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)