def setUp(self):
     self.core = MimicCore(Clock(), [])
     self.root = MimicRoot(self.core).app.resource()
     self.eeapi_id = u"some-id"
     self.uri = "/identity/v2.0/services/" + self.eeapi_id
     self.eeapi_name = u"externalServiceName"
     self.eeapi = make_example_external_api(self,
                                            name=self.eeapi_name,
                                            set_enabled=True)
     self.eeapi2 = make_example_external_api(self,
                                             name=self.eeapi_name +
                                             " alternate")
     self.eeapi.uuid_key = self.eeapi_id
     self.headers = {b'X-Auth-Token': [b'ABCDEF987654321']}
     self.verb = b"DELETE"
Beispiel #2
0
    def test_load_duplicate_api_uuid(self):
        """
        Adding an API with the same UUID as an existing API will generate a
        ValueError exception.
        """
        eeapi = make_example_external_api(
            self,
            name=self.eeapi_name,
        )
        eeapi2 = make_example_external_api(self,
                                           name="alternate " + self.eeapi_name)
        eeapi2.uuid_key = eeapi.uuid_key

        with self.assertRaises(ServiceExists):
            MimicCore(Clock(), [eeapi, eeapi2])
    def test_update_endpoint_template_invalid_data(self, invalid_data, expected_exception):
        """
        :obj:`ExternalApiStore` will raise the appropriate exception when
        given fields are missing from the endpoint template during the update.
        """
        new_url = "https://api.new_region.example.com:9090"
        new_region = "NEW_REGION"
        eeapi = make_example_external_api(
            self,
            name=self.eeapi_name,
            set_enabled=True,
        )
        new_id = get_template_id(self, eeapi)
        new_eeapi_template = exampleEndpointTemplate(
            name=self.eeapi_name,
            endpoint_uuid=new_id,
            region=new_region,
            url=new_url
        )
        if invalid_data == 'type':
            new_eeapi_template.type_key = "some-other-type"
        elif invalid_data == 'id':
            eeapi.endpoint_templates[new_id].id_key = \
                u"uuid-alternate-endpoint-template"

        with self.assertRaises(expected_exception):
            eeapi.update_template(new_eeapi_template)
    def test_update_endpoint_template(self):
        """
        Validate that an endpoint template can be updated provided that
        the id field matches.
        """
        eeapi_template_id = u"uuid-alternate-endpoint-template"

        new_url = "https://api.new_region.example.com:9090"
        new_region = "NEW_REGION"
        old_eeapi_template = exampleEndpointTemplate(
            name=self.eeapi_name,
            endpoint_uuid=eeapi_template_id,
            region=new_region,
        )
        new_eeapi_template = exampleEndpointTemplate(
            name=self.eeapi_name,
            endpoint_uuid=eeapi_template_id,
            region=new_region,
            url=new_url
        )
        eeapi = make_example_external_api(
            self,
            name=self.eeapi_name,
            set_enabled=True,
            endpoint_templates=[old_eeapi_template]
        )

        self.assertEqual(eeapi.endpoint_templates[eeapi_template_id],
                         old_eeapi_template)
        eeapi.update_template(new_eeapi_template)
        self.assertEqual(eeapi.endpoint_templates[eeapi_template_id],
                         new_eeapi_template)
    def test_remove_endpoint_template(self, template_is_valid):
        """
        Validate that an endpoint template can be removed from the
        :obj:`ExternalApiStore`.
        """
        eeapi_template_id = u"uuid-alternate-endpoint-template"
        eeapi_template = None
        if template_is_valid:
            eeapi_template = [
                exampleEndpointTemplate(
                    name=self.eeapi_name,
                    endpoint_uuid=eeapi_template_id
                )
            ]
        eeapi = make_example_external_api(
            self,
            name=self.eeapi_name,
            set_enabled=True,
            endpoint_templates=eeapi_template
        )

        if template_is_valid:
            self.assertIn(eeapi_template_id, eeapi.endpoint_templates)
            eeapi.remove_template(eeapi_template_id)
            self.assertNotIn(eeapi_template_id, eeapi.endpoint_templates)
        else:
            with self.assertRaises(InvalidEndpointTemplateId):
                eeapi.remove_template(eeapi_template_id)
    def test_update_endpoint_template_invalid_data(self, invalid_data,
                                                   expected_exception):
        """
        :obj:`ExternalApiStore` will raise the appropriate exception when
        given fields are missing from the endpoint template during the update.
        """
        new_url = "https://api.new_region.example.com:9090"
        new_region = "NEW_REGION"
        eeapi = make_example_external_api(
            self,
            name=self.eeapi_name,
            set_enabled=True,
        )
        new_id = get_template_id(self, eeapi)
        new_eeapi_template = exampleEndpointTemplate(name=self.eeapi_name,
                                                     endpoint_uuid=new_id,
                                                     region=new_region,
                                                     url=new_url)
        if invalid_data == 'type':
            new_eeapi_template.type_key = "some-other-type"
        elif invalid_data == 'id':
            eeapi.endpoint_templates[new_id].id_key = \
                u"uuid-alternate-endpoint-template"

        with self.assertRaises(expected_exception):
            eeapi.update_template(new_eeapi_template)
Beispiel #7
0
    def test_entries_for_tenant_external(self):
        """
        Validate that the external API shows up in the service catalog for a
        given tenant.
        """
        eeapi = make_example_external_api(self,
                                          name=self.eeapi_name,
                                          set_enabled=True)

        core = MimicCore(Clock(), [eeapi])

        prefix_map = {}
        base_uri = "http://some/random/prefix"
        catalog_entries = [
            entry for entry in core.entries_for_tenant('some-tenant',
                                                       prefix_map, base_uri)
        ]

        self.assertEqual(len(core._uuid_to_api_internal), 0)
        self.assertEqual(len(core._uuid_to_api_external), 1)
        self.assertEqual(len(catalog_entries), 1)
        self.assertEqual(catalog_entries[0].type, eeapi.type_key)
        self.assertEqual(catalog_entries[0].name, eeapi.name_key)
        self.assertEqual(catalog_entries[0].tenant_id, "some-tenant")
        self.assertEqual(len(catalog_entries[0].endpoints), 1)
    def test_duplicate_api_insertion_fails(self):
        """
        Validate only one template for by a given name (id) can be added at a
        time.
        """
        eeapi = make_example_external_api(
            self,
            name=self.eeapi_name,
            set_enabled=True
        )
        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
        )

        # first time succeeds
        eeapi.add_template(new_eeapi_template)

        # second time fails
        with self.assertRaises(EndpointTemplateAlreadyExists):
            eeapi.add_template(new_eeapi_template)
    def test_multiple_external_apis(self):
        """
        GET will list multiple external APIs.
        """
        api_list = [
            make_example_external_api(
                self,
                name=self.eeapi_name + text_type(uuid.uuid4()),
                service_type='service-' + text_type(uuid.uuid4()),
                set_enabled=True
            )
            for ignored in range(10)
        ]
        # eeapi should be the first entry in the list
        api_list.insert(0, self.eeapi)

        for api in api_list:
            self.core.add_api(api)

        self.assertEqual(len(self.core._uuid_to_api_external),
                         len(api_list))

        (response, json_body) = self.successResultOf(
            json_request(self, self.root, self.verb,
                         self.uri,
                         headers=self.headers))

        def get_header(header_name):
            return response.headers.getRawHeaders(header_name)[0].decode("utf-8")

        self.assertEqual(response.code, 200)

        self.assertEqual(len(json_body['endpoints']),
                         len(api_list))
        self.assertEqual(len(json_body['endpoints_links']), 0)
Beispiel #10
0
    def test_multiple_external_apis(self):
        """
        GET will list multiple external APIs.
        """
        api_list = [
            make_example_external_api(
                self,
                name=self.eeapi_name + text_type(uuid.uuid4()),
                service_type='service-' + text_type(uuid.uuid4()),
                set_enabled=True) for ignored in range(10)
        ]
        # eeapi should be the first entry in the list
        api_list.insert(0, self.eeapi)

        for api in api_list:
            self.core.add_api(api)

        self.assertEqual(len(self.core._uuid_to_api_external), len(api_list))

        (response, json_body) = self.successResultOf(
            json_request(self,
                         self.root,
                         self.verb,
                         self.uri,
                         headers=self.headers))

        def get_header(header_name):
            return response.headers.getRawHeaders(header_name)[0].decode(
                "utf-8")

        self.assertEqual(response.code, 200)

        self.assertEqual(len(json_body['endpoints']), len(api_list))
        self.assertEqual(len(json_body['endpoints_links']), 0)
    def test_invalid_service_id_in_json_body(self):
        """
        POST - Service ID must be valid, otherwise results in 404.
        """
        # Add a second API
        eeapi2 = make_example_external_api(
            self,
            name='d' + self.eeapi_name + text_type(uuid.uuid4()),
            service_type='service-' + text_type(uuid.uuid4()))
        eeapi2.id_key = '0'

        # ensure only one instance of the API has the endpoint template
        eeapi2.remove_template(get_template_id(self, eeapi2))
        self.core.add_api(eeapi2)
        self.core.add_api(self.eeapi)

        data = {
            'id': text_type(uuid.uuid4()),
            'name': 'some-name',
            'type': 'some-type',
            'region': 'some-region'
        }
        (response, json_body) = self.successResultOf(
            json_request(self,
                         self.root,
                         self.verb,
                         self.uri,
                         body=data,
                         headers=self.headers))

        self.assertEqual(response.code, 404)
        self.assertEqual(json_body['itemNotFound']['code'], 404)
        self.assertEqual(json_body['itemNotFound']['message'],
                         "Service API for endoint template not found")
    def test_update_endpoint_template(self):
        """
        Validate that an endpoint template can be updated provided that
        the id field matches.
        """
        eeapi_template_id = u"uuid-alternate-endpoint-template"

        new_url = "https://api.new_region.example.com:9090"
        new_region = "NEW_REGION"
        old_eeapi_template = exampleEndpointTemplate(
            name=self.eeapi_name,
            endpoint_uuid=eeapi_template_id,
            region=new_region,
        )
        new_eeapi_template = exampleEndpointTemplate(
            name=self.eeapi_name,
            endpoint_uuid=eeapi_template_id,
            region=new_region,
            url=new_url)
        eeapi = make_example_external_api(
            self,
            name=self.eeapi_name,
            set_enabled=True,
            endpoint_templates=[old_eeapi_template])

        self.assertEqual(eeapi.endpoint_templates[eeapi_template_id],
                         old_eeapi_template)
        eeapi.update_template(new_eeapi_template)
        self.assertEqual(eeapi.endpoint_templates[eeapi_template_id],
                         new_eeapi_template)
    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_external_apis(self):
        """
        GET can retrieve numerous External APIs that have External API Templates.
        """
        api_list = [
            make_example_external_api(
                self,
                name=self.eeapi_name + text_type(uuid.uuid4()),
                service_type='service-' + text_type(uuid.uuid4())
            )
            for ignored in range(10)
        ]
        #  eeapi needs to be the first in the list
        api_list.insert(0, self.eeapi)
        for api in api_list:
            self.core.add_api(api)

        self.assertEqual(len(self.core._uuid_to_api_external),
                         len(api_list))

        (response, json_body) = self.successResultOf(
            json_request(self, self.root, self.verb,
                         self.uri,
                         headers=self.headers))

        self.assertEqual(response.code, 200)

        self.assertEqual(len(json_body['OS-KSCATALOG']),
                         len(api_list))
        self.assertEqual(
            len(json_body['OS-KSCATALOG:endpointsTemplates_links']),
            0)
    def test_multiple_external_apis(self):
        """
        GET can retrieve numerous External APIs that have External API Templates.
        """
        api_list = [
            make_example_external_api(
                self,
                name=self.eeapi_name + text_type(uuid.uuid4()),
                service_type='service-' + text_type(uuid.uuid4()))
            for ignored in range(10)
        ]
        #  eeapi needs to be the first in the list
        api_list.insert(0, self.eeapi)
        for api in api_list:
            self.core.add_api(api)

        self.assertEqual(len(self.core._uuid_to_api_external), len(api_list))

        (response, json_body) = self.successResultOf(
            json_request(self,
                         self.root,
                         self.verb,
                         self.uri,
                         headers=self.headers))

        self.assertEqual(response.code, 200)

        self.assertEqual(len(json_body['OS-KSCATALOG']), len(api_list))
        self.assertEqual(
            len(json_body['OS-KSCATALOG:endpointsTemplates_links']), 0)
Beispiel #16
0
    def test_load_duplicate_api_name(self):
        """
        Adding an API with the same Name as an existing API will generate a
        ValueError exception.
        """
        eeapi = make_example_external_api(
            self,
            name=self.eeapi_name,
        )
        eeapi2 = make_example_external_api(self, name=self.eeapi_name)
        # .. note:: make_example_external_api makes the UUID
        # to be uuid-<name> so we need to change it for eeapi2
        eeapi2.uuid_key = str(uuid.uuid4())

        with self.assertRaises(ServiceNameExists):
            MimicCore(Clock(), [eeapi, eeapi2])
    def test_json_body_id_value_not_matching_url(self):
        """
        PUT requires that the endpoint template id in the URL and JSON data
        match, otherwise results in 409.
        """
        self.core.add_api(self.eeapi)

        eeapi2 = make_example_external_api(
            self,
            name=self.eeapi_name + text_type(uuid.uuid4()),
            service_type='service-' + text_type(uuid.uuid4()))
        eeapi2.remove_template(get_template_id(self, eeapi2))
        self.core.add_api(eeapi2)

        data = {
            'id': 'some-random-key',
            'name': self.eeapi_name,
            'type': self.eeapi.type_key,
            'region': 'some-region'
        }

        (response, json_body) = self.successResultOf(
            json_request(self,
                         self.root,
                         self.verb,
                         self.uri,
                         body=data,
                         headers=self.headers))

        self.assertEqual(response.code, 409)
        self.assertEqual(json_body['conflict']['code'], 409)
        self.assertEqual(
            json_body['conflict']['message'],
            "Template ID in URL does not match that of the JSON body")
Beispiel #18
0
    def test_entries_for_tenant_external(self):
        """
        Validate that the external API shows up in the service catalog for a
        given tenant.
        """
        eeapi = make_example_external_api(
            self,
            name=self.eeapi_name,
            set_enabled=True
        )

        core = MimicCore(Clock(), [eeapi])

        prefix_map = {}
        base_uri = "http://some/random/prefix"
        catalog_entries = [
            entry
            for entry in core.entries_for_tenant(
                'some-tenant',
                prefix_map,
                base_uri
            )
        ]

        self.assertEqual(len(core._uuid_to_api_internal), 0)
        self.assertEqual(len(core._uuid_to_api_external), 1)
        self.assertEqual(len(catalog_entries), 1)
        self.assertEqual(catalog_entries[0].type, eeapi.type_key)
        self.assertEqual(catalog_entries[0].name, eeapi.name_key)
        self.assertEqual(catalog_entries[0].tenant_id, "some-tenant")
        self.assertEqual(len(catalog_entries[0].endpoints), 1)
    def test_update_endpoint_template(self, has_service_header):
        """
        PUT to update an endpoint template results in 201, service-id
        header is optional.
        """
        self.core.add_api(self.eeapi)
        id_key = get_template_id(self, self.eeapi)

        eeapi2 = make_example_external_api(
            self,
            name=self.eeapi_name + text_type(uuid.uuid4()),
            service_type='service-' + text_type(uuid.uuid4()))
        eeapi2.remove_template(get_template_id(self, eeapi2))
        self.core.add_api(eeapi2)

        data = {
            'id': id_key,
            'name': self.eeapi_name,
            'type': self.eeapi.type_key,
            'region': 'some-region'
        }

        if has_service_header:
            self.headers[b'serviceid'] = [self.eeapi.uuid_key.encode('utf8')]

        req = request(self,
                      self.root,
                      self.verb,
                      self.uri,
                      body=json.dumps(data).encode("utf-8"),
                      headers=self.headers)

        response = self.successResultOf(req)
        self.assertEqual(response.code, 201)
    def test_update_endpoint_template(self, has_service_header):
        """
        PUT to update an endpoint template results in 201, service-id
        header is optional.
        """
        self.core.add_api(self.eeapi)
        id_key = get_template_id(self, self.eeapi)

        eeapi2 = make_example_external_api(
            self,
            name=self.eeapi_name + text_type(uuid.uuid4()),
            service_type='service-' + text_type(uuid.uuid4())
        )
        eeapi2.remove_template(get_template_id(self, eeapi2))
        self.core.add_api(eeapi2)

        data = {
            'id': id_key,
            'name': self.eeapi_name,
            'type': self.eeapi.type_key,
            'region': 'some-region'
        }

        if has_service_header:
            self.headers[b'serviceid'] = [self.eeapi.uuid_key.encode('utf8')]

        req = request(self, self.root, self.verb,
                      self.uri,
                      body=json.dumps(data).encode("utf-8"),
                      headers=self.headers)

        response = self.successResultOf(req)
        self.assertEqual(response.code, 201)
    def test_json_body_id_value_not_matching_url(self):
        """
        PUT requires that the endpoint template id in the URL and JSON data
        match, otherwise results in 409.
        """
        self.core.add_api(self.eeapi)

        eeapi2 = make_example_external_api(
            self,
            name=self.eeapi_name + text_type(uuid.uuid4()),
            service_type='service-' + text_type(uuid.uuid4())
        )
        eeapi2.remove_template(get_template_id(self, eeapi2))
        self.core.add_api(eeapi2)

        data = {
            'id': 'some-random-key',
            'name': self.eeapi_name,
            'type': self.eeapi.type_key,
            'region': 'some-region'
        }

        (response, json_body) = self.successResultOf(
            json_request(self, self.root, self.verb,
                         self.uri,
                         body=data,
                         headers=self.headers))

        self.assertEqual(response.code, 409)
        self.assertEqual(json_body['conflict']['code'], 409)
        self.assertEqual(
            json_body['conflict']['message'],
            "Template ID in URL does not match that of the JSON body"
        )
    def test_remove_endpoint_template_with_user_registration_alternate(self):
        """
        Validate that only the endpoint template that is suppose to be removed
        is removed.
        """
        eeapi_template_id = u"uuid-alternate-endpoint-template"
        alternate_eeapi_template_id = u"uuid-alternate-endpoint-template-alt"
        eeapi_template = exampleEndpointTemplate(
            name=self.eeapi_name, endpoint_uuid=eeapi_template_id)
        alternate_eeapi_template = exampleEndpointTemplate(
            name=self.eeapi_name, endpoint_uuid=alternate_eeapi_template_id)
        eeapi = make_example_external_api(
            self,
            name=self.eeapi_name,
            set_enabled=True,
            endpoint_templates=[eeapi_template, alternate_eeapi_template])
        eeapi.enable_endpoint_for_tenant('some-tenant', eeapi_template_id)
        eeapi.enable_endpoint_for_tenant('some-other-tenant',
                                         alternate_eeapi_template_id)

        self.assertIn(eeapi_template_id, eeapi.endpoint_templates)
        self.assertIn(alternate_eeapi_template_id, eeapi.endpoint_templates)
        eeapi.remove_template(eeapi_template_id)
        self.assertNotIn(eeapi_template_id, eeapi.endpoint_templates)
        self.assertIn(alternate_eeapi_template_id, eeapi.endpoint_templates)
    def test_invalid_service_id_in_json_body(self):
        """
        POST - Service ID must be valid, otherwise results in 404.
        """
        # Add a second API
        eeapi2 = make_example_external_api(
            self,
            name='d' + self.eeapi_name + text_type(uuid.uuid4()),
            service_type='service-' + text_type(uuid.uuid4())
        )
        eeapi2.id_key = '0'

        # ensure only one instance of the API has the endpoint template
        eeapi2.remove_template(get_template_id(self, eeapi2))
        self.core.add_api(eeapi2)
        self.core.add_api(self.eeapi)

        data = {
            'id': text_type(uuid.uuid4()),
            'name': 'some-name',
            'type': 'some-type',
            'region': 'some-region'
        }
        (response, json_body) = self.successResultOf(
            json_request(self, self.root, self.verb,
                         self.uri,
                         body=data,
                         headers=self.headers))

        self.assertEqual(response.code, 404)
        self.assertEqual(json_body['itemNotFound']['code'], 404)
        self.assertEqual(
            json_body['itemNotFound']['message'],
            "Service API for endoint template not found"
        )
Beispiel #24
0
 def test_load_external_api(self):
     """
     Validate loading a valid external API object.
     """
     eeapi = make_example_external_api(self,
                                       name=self.eeapi_name,
                                       set_enabled=True)
     APIMockHelper(self, [eeapi])
Beispiel #25
0
    def test_load_duplicate_api_uuid(self):
        """
        Adding an API with the same UUID as an existing API will generate a
        ValueError exception.
        """
        eeapi = make_example_external_api(
            self,
            name=self.eeapi_name,
        )
        eeapi2 = make_example_external_api(
            self,
            name="alternate " + self.eeapi_name
        )
        eeapi2.uuid_key = eeapi.uuid_key

        with self.assertRaises(ServiceExists):
            MimicCore(Clock(), [eeapi, eeapi2])
 def setUp(self):
     self.eeapi_name = u"externalServiceName"
     self.eeapi = make_example_external_api(self,
                                            name=self.eeapi_name,
                                            set_enabled=True)
     self.helper = APIMockHelper(self, [self.eeapi])
     self.root = self.helper.root
     self.uri = self.helper.uri
 def setUp(self):
     self.core = MimicCore(Clock(), [])
     self.root = MimicRoot(self.core).app.resource()
     self.uri = "/identity/v2.0/OS-KSCATALOG/endpointTemplates"
     self.eeapi_name = u"externalServiceName"
     self.eeapi = make_example_external_api(self,
                                            name=self.eeapi_name,
                                            set_enabled=True)
     self.headers = {b'X-Auth-Token': [b'ABCDEF987654321']}
     self.verb = b"GET"
 def setUp(self):
     self.eeapi_name = u"externalServiceName"
     self.eeapi = make_example_external_api(
         self,
         name=self.eeapi_name,
         set_enabled=True
     )
     self.helper = APIMockHelper(self, [self.eeapi])
     self.root = self.helper.root
     self.uri = self.helper.uri
Beispiel #29
0
 def test_load_external_api(self):
     """
     Validate loading a valid external API object.
     """
     eeapi = make_example_external_api(
         self,
         name=self.eeapi_name,
         set_enabled=True
     )
     APIMockHelper(self, [eeapi])
Beispiel #30
0
    def test_load_duplicate_api_name(self):
        """
        Adding an API with the same Name as an existing API will generate a
        ValueError exception.
        """
        eeapi = make_example_external_api(
            self,
            name=self.eeapi_name,
        )
        eeapi2 = make_example_external_api(
            self,
            name=self.eeapi_name
        )
        # .. note:: make_example_external_api makes the UUID
        # to be uuid-<name> so we need to change it for eeapi2
        eeapi2.uuid_key = str(uuid.uuid4())

        with self.assertRaises(ServiceNameExists):
            MimicCore(Clock(), [eeapi, eeapi2])
Beispiel #31
0
    def test_get_external_api(self):
        """
        Validate retrieving an external API.
        """
        eeapi = make_example_external_api(self,
                                          name=self.eeapi_name,
                                          set_enabled=True)

        core = MimicCore(Clock(), [eeapi])
        api_from_core = core.get_external_api(eeapi.uuid_key)
        self.assertEqual(eeapi, api_from_core)
 def setUp(self):
     self.core = MimicCore(Clock(), [])
     self.root = MimicRoot(self.core).app.resource()
     self.eeapi_id = u"some-id"
     self.uri = "/identity/v2.0/services/" + self.eeapi_id
     self.eeapi_name = u"externalServiceName"
     self.eeapi = make_example_external_api(
         self,
         name=self.eeapi_name,
         set_enabled=True
     )
     self.eeapi2 = make_example_external_api(
         self,
         name=self.eeapi_name + " alternate"
     )
     self.eeapi.uuid_key = self.eeapi_id
     self.headers = {
         b'X-Auth-Token': [b'ABCDEF987654321']
     }
     self.verb = b"DELETE"
    def test_has_endpoint_template(self, should_have_template):
        """
        Validate that :obj:`ExternalApiStore` will return True if it
        does have the template id
        """
        eeapi = make_example_external_api(self)
        ept_template_id = 'some-template-id'
        if should_have_template:
            ept_template_id = get_template_id(self, eeapi)

        self.assertEqual(eeapi.has_template(ept_template_id),
                         should_have_template)
Beispiel #34
0
 def setUp(self):
     self.tenant_id = 'some_tenant'
     self.core = MimicCore(Clock(), [])
     self.root = MimicRoot(self.core).app.resource()
     self.uri = ("/identity/v2.0/tenants/" + self.tenant_id +
                 "/OS-KSCATALOG/endpoints")
     self.eeapi_name = u"externalServiceName"
     self.eeapi = make_example_external_api(self,
                                            name=self.eeapi_name,
                                            set_enabled=False)
     self.headers = {b'X-Auth-Token': [b'ABCDEF987654321']}
     self.verb = b"POST"
Beispiel #35
0
 def setUp(self):
     self.tenant_id = 'some_tenant'
     self.core = MimicCore(Clock(), [])
     self.root = MimicRoot(self.core).app.resource()
     self.eeapi_name = u"externalServiceName"
     self.eeapi = make_example_external_api(self, name=self.eeapi_name)
     self.template_id = get_template_id(self, self.eeapi)
     self.assertIsNotNone(self.template_id)
     self.uri = ("/identity/v2.0/tenants/" + self.tenant_id +
                 "/OS-KSCATALOG/endpoints/" + self.template_id)
     self.headers = {b'X-Auth-Token': [b'ABCDEF987654321']}
     self.verb = b"DELETE"
Beispiel #36
0
 def test_remove_api_with_endpoints(self):
     """
     Validate an API cannot be removed if it still has
     endpoints assigned to it
     """
     eeapi = make_example_external_api(self,
                                       name=self.eeapi_name,
                                       set_enabled=True)
     self.assertIsNotNone(eeapi)
     core = MimicCore(Clock(), [eeapi])
     with self.assertRaises(ServiceHasTemplates):
         core.remove_external_api(eeapi.uuid_key)
    def test_invalid_template_endpoint_disable(self):
        """
        Validate disabling an invalid endpoint template for a user raises
        `ValueError`.
        """
        eeapi = make_example_external_api(self,
                                          name=self.eeapi_name,
                                          set_enabled=True)

        with self.assertRaises(EndpointTemplateDisabledForTenant):
            eeapi.disable_endpoint_for_tenant('some_tenant',
                                              'some-invalid-template-id')
    def test_uri_for_service_with_invalid_region(self):
        """
        Validate that the :obj:`ExternalApiStore`'s version of
        `uri_for_service` will raise the `IndexError` exception when it cannot
        find a matching region.
        """
        eeapi = make_example_external_api(self,
                                          name=self.eeapi_name,
                                          set_enabled=True)

        with self.assertRaises(IndexError):
            eeapi.uri_for_service('Open', 'Stack')
    def test_invalid_endpoint_template(self):
        """
        Validate the endpoint template interface gate check
        """
        eeapi = make_example_external_api(self,
                                          name=self.eeapi_name,
                                          set_enabled=True)

        class InvalidTemplate(object):
            pass

        with self.assertRaises(InvalidEndpointTemplateInterface):
            eeapi.add_template(InvalidTemplate())
    def test_uri_for_service_with_invalid_region(self):
        """
        Validate that the :obj:`ExternalApiStore`'s version of
        `uri_for_service` will raise the `IndexError` exception when it cannot
        find a matching region.
        """
        eeapi = make_example_external_api(
            self,
            name=self.eeapi_name,
            set_enabled=True
        )

        with self.assertRaises(IndexError):
            eeapi.uri_for_service('Open', 'Stack')
 def setUp(self):
     self.core = MimicCore(Clock(), [])
     self.root = MimicRoot(self.core).app.resource()
     self.uri = "/identity/v2.0/OS-KSCATALOG/endpointTemplates"
     self.eeapi_name = u"externalServiceName"
     self.eeapi = make_example_external_api(
         self,
         name=self.eeapi_name,
         set_enabled=True
     )
     self.headers = {
         b'X-Auth-Token': [b'ABCDEF987654321']
     }
     self.verb = b"GET"
Beispiel #42
0
    def test_service_with_region_external(self):
        """
        Validate that an external service does not provide an internal
        service resource.
        """
        eeapi = make_example_external_api(self,
                                          name=self.eeapi_name,
                                          set_enabled=True)
        helper = APIMockHelper(self, [eeapi])
        core = helper.core

        self.assertIsNone(
            core.service_with_region(u"EXTERNAL", u"some-region-name",
                                     u"http://some/random/prefix"))
Beispiel #43
0
    def test_get_external_api(self):
        """
        Validate retrieving an external API.
        """
        eeapi = make_example_external_api(
            self,
            name=self.eeapi_name,
            set_enabled=True
        )

        core = MimicCore(Clock(), [eeapi])
        api_from_core = core.get_external_api(
            eeapi.uuid_key
        )
        self.assertEqual(eeapi, api_from_core)
    def test_invalid_endpoint_template(self):
        """
        Validate the endpoint template interface gate check
        """
        eeapi = make_example_external_api(
            self,
            name=self.eeapi_name,
            set_enabled=True
        )

        class InvalidTemplate(object):
            pass

        with self.assertRaises(InvalidEndpointTemplateInterface):
            eeapi.add_template(InvalidTemplate())
Beispiel #45
0
    def test_remove_api(self):
        """
        Removing an API.
        """
        eeapi = make_example_external_api(self,
                                          name=self.eeapi_name,
                                          set_enabled=True)
        self.assertIsNotNone(eeapi)

        template_ids = [ept.id_key for ept in eeapi.list_templates()]
        for template_id in template_ids:
            eeapi.remove_template(template_id)

        core = MimicCore(Clock(), [eeapi])
        core.remove_external_api(eeapi.uuid_key)
Beispiel #46
0
    def test_get_external_apis(self):
        """
        Validate retrieving the list of external APIs
        """
        eeapi = make_example_external_api(self,
                                          name=self.eeapi_name,
                                          set_enabled=True)

        core = MimicCore(Clock(), [])
        self.assertEqual(len(core.get_external_apis()), 0)

        core.add_api(eeapi)
        api_list = core.get_external_apis()
        self.assertEqual(len(api_list), 1)
        self.assertEqual(list(api_list), [eeapi.uuid_key])
Beispiel #47
0
    def test_entries_for_tenant_combined(self):
        """
        Validate that both internal and external APIs show up in the service
        catalog for a given tenant.
        """
        eeapi = make_example_external_api(
            self,
            name=self.eeapi_name,
            set_enabled=True
        )

        core = MimicCore(Clock(), [eeapi, make_example_internal_api(self)])

        prefix_map = {}
        base_uri = "http://some/random/prefix"
        catalog_entries = [
            entry
            for entry in core.entries_for_tenant(
                'some-tenant',
                prefix_map,
                base_uri
            )
        ]

        self.assertEqual(len(core._uuid_to_api_internal), 1)
        self.assertEqual(len(core._uuid_to_api_external), 1)
        self.assertEqual(len(catalog_entries), 2)

        found_internal = False
        found_external = False

        for catalog_entry in catalog_entries:
            if catalog_entry.name == eeapi.name_key:
                found_external = True
                self.assertEqual(catalog_entry.type, eeapi.type_key)
                self.assertEqual(catalog_entry.name, eeapi.name_key)
                self.assertEqual(catalog_entry.tenant_id, "some-tenant")
                self.assertEqual(len(catalog_entry.endpoints), 1)

            elif catalog_entry.name == "serviceName":
                found_internal = True
                self.assertEqual(catalog_entry.type, "serviceType")
                self.assertEqual(catalog_entry.name, "serviceName")
                self.assertEqual(catalog_entry.tenant_id, "some-tenant")
                self.assertEqual(len(catalog_entry.endpoints), 1)

        self.assertTrue(found_internal)
        self.assertTrue(found_external)
    def test_update_with_invalid_template(self):
        """
        Validate that an endpoint template must provide the correct
        interfaces, namely :obj:`IEndpointTemplate`.
        """
        class InvalidTemplate(object):
            pass

        eeapi = make_example_external_api(
            self,
            name=self.eeapi_name,
            set_enabled=True,
        )

        with self.assertRaises(InvalidEndpointTemplateInterface):
            eeapi.update_template(InvalidTemplate())
    def test_has_endpoint_template(self, should_have_template):
        """
        Validate that :obj:`ExternalApiStore` will return True if it
        does have the template id
        """
        eeapi = make_example_external_api(
            self
        )
        ept_template_id = 'some-template-id'
        if should_have_template:
            ept_template_id = get_template_id(self, eeapi)

        self.assertEqual(
            eeapi.has_template(ept_template_id),
            should_have_template
        )
    def test_invalid_template_endpoint_disable(self):
        """
        Validate disabling an invalid endpoint template for a user raises
        `ValueError`.
        """
        eeapi = make_example_external_api(
            self,
            name=self.eeapi_name,
            set_enabled=True
        )

        with self.assertRaises(EndpointTemplateDisabledForTenant):
            eeapi.disable_endpoint_for_tenant(
                'some_tenant',
                'some-invalid-template-id'
            )
Beispiel #51
0
 def test_remove_api_with_endpoints(self):
     """
     Validate an API cannot be removed if it still has
     endpoints assigned to it
     """
     eeapi = make_example_external_api(
         self,
         name=self.eeapi_name,
         set_enabled=True
     )
     self.assertIsNotNone(eeapi)
     core = MimicCore(Clock(), [eeapi])
     with self.assertRaises(ServiceHasTemplates):
         core.remove_external_api(
             eeapi.uuid_key
         )
    def test_update_with_invalid_template(self):
        """
        Validate that an endpoint template must provide the correct
        interfaces, namely :obj:`IEndpointTemplate`.
        """
        class InvalidTemplate(object):
            pass

        eeapi = make_example_external_api(
            self,
            name=self.eeapi_name,
            set_enabled=True,
        )

        with self.assertRaises(InvalidEndpointTemplateInterface):
            eeapi.update_template(InvalidTemplate())
Beispiel #53
0
    def test_entries_for_tenant_external_with_tenantid_replacement(self):
        """
        Validate that the external API shows up in the service catalog for a
        given tenant and the tenant id is in the URL.
        """
        eeapi = make_example_external_api(
            self,
            name=self.eeapi_name,
            set_enabled=True
        )

        tenant_id = 'some-tenant-other'

        ept_internal_url = "http://internal.url/v1/" + tenant_id
        ept_public_url = "http://public.url/v1/" + tenant_id
        for ept in eeapi.endpoint_templates.values():
            ept.internal_url = "http://internal.url/v1/%tenant_id%"
            ept.public_url = "http://public.url/v1/%tenant_id%"

        core = MimicCore(Clock(), [eeapi])

        prefix_map = {}
        base_uri = "http://some/random/prefix"
        catalog_entries = [
            entry
            for entry in core.entries_for_tenant(
                tenant_id,
                prefix_map,
                base_uri
            )
        ]

        self.assertEqual(len(core._uuid_to_api_internal), 0)
        self.assertEqual(len(core._uuid_to_api_external), 1)
        self.assertEqual(len(catalog_entries), 1)
        self.assertEqual(catalog_entries[0].type, eeapi.type_key)
        self.assertEqual(catalog_entries[0].name, eeapi.name_key)
        self.assertEqual(catalog_entries[0].tenant_id, tenant_id)
        self.assertEqual(len(catalog_entries[0].endpoints), 1)
        self.assertEqual(
            catalog_entries[0].endpoints[0].internal_url,
            ept_internal_url
        )
        self.assertEqual(
            catalog_entries[0].endpoints[0].complete_url,
            ept_public_url
        )
Beispiel #54
0
    def test_get_external_apis(self):
        """
        Validate retrieving the list of external APIs
        """
        eeapi = make_example_external_api(
            self,
            name=self.eeapi_name,
            set_enabled=True
        )

        core = MimicCore(Clock(), [])
        self.assertEqual(len(core.get_external_apis()), 0)

        core.add_api(eeapi)
        api_list = core.get_external_apis()
        self.assertEqual(len(api_list), 1)
        self.assertEqual(list(api_list), [eeapi.uuid_key])
    def test_listing_templates(self):
        """
        Listing templates provides entries and changes as expected.
        Template status is not dependant on whether or not the template is enabled.
        """
        eeapi_template_id = 'some-template-id'
        eeapi_template = exampleEndpointTemplate(
            name=self.eeapi_name,
            endpoint_uuid=eeapi_template_id,
        )
        eeapi = make_example_external_api(self,
                                          name=self.eeapi_name,
                                          endpoint_templates=[eeapi_template])

        self.assertEqual(len(eeapi.list_templates()), 1)
        eeapi.remove_template(eeapi_template_id)
        self.assertEqual(len(eeapi.list_templates()), 0)
    def test_remove_endpoint_template_with_user_registration(self):
        """
        Validate that an endpoint template can be removed even if it enabled
        for a specific tenant.
        """
        eeapi_template_id = u"uuid-alternate-endpoint-template"
        eeapi_template = exampleEndpointTemplate(
            name=self.eeapi_name, endpoint_uuid=eeapi_template_id)
        eeapi = make_example_external_api(self,
                                          name=self.eeapi_name,
                                          set_enabled=True,
                                          endpoint_templates=[eeapi_template])
        eeapi.enable_endpoint_for_tenant('some-tenant', eeapi_template_id)

        self.assertIn(eeapi_template_id, eeapi.endpoint_templates)
        eeapi.remove_template(eeapi_template_id)
        self.assertNotIn(eeapi_template_id, eeapi.endpoint_templates)
 def setUp(self):
     self.tenant_id = 'some_tenant'
     self.core = MimicCore(Clock(), [])
     self.root = MimicRoot(self.core).app.resource()
     self.uri = (
         "/identity/v2.0/tenants/" + self.tenant_id +
         "/OS-KSCATALOG/endpoints"
     )
     self.eeapi_name = u"externalServiceName"
     self.eeapi = make_example_external_api(
         self,
         name=self.eeapi_name,
         set_enabled=False
     )
     self.headers = {
         b'X-Auth-Token': [b'ABCDEF987654321']
     }
     self.verb = b"POST"
    def test_disable_endpoint_template_for_tenant(self):
        """
        Validate that an endpoint template can be enabled and disabled for a
        given 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
        )
        eeapi = make_example_external_api(
            self,
            name=self.eeapi_name,
            set_enabled=False,
            endpoint_templates=[new_eeapi_template]
        )

        ept_for_tenant = eeapi.list_tenant_endpoints('some-tenant')
        self.assertEqual(len(ept_for_tenant), 0)

        eeapi.enable_endpoint_for_tenant(
            'some-tenant',
            new_eeapi_template_id
        )
        ept_for_tenant = eeapi.list_tenant_endpoints('some-tenant')
        self.assertEqual(len(ept_for_tenant), 1)
        self.assertEqual(ept_for_tenant[0].tenant_id, 'some-tenant')
        self.assertEqual(ept_for_tenant[0].region, new_region)
        self.assertEqual(ept_for_tenant[0].endpoint_id, new_eeapi_template_id)
        self.assertEqual(ept_for_tenant[0].prefix, "v1")
        self.assertTrue(ept_for_tenant[0].external)
        self.assertIsNotNone(ept_for_tenant[0].complete_url)
        self.assertEqual(ept_for_tenant[0].complete_url, new_url)

        eeapi.disable_endpoint_for_tenant(
            'some-tenant',
            new_eeapi_template_id
        )
        ept_for_tenant = eeapi.list_tenant_endpoints('some-tenant')
        self.assertEqual(len(ept_for_tenant), 0)
 def setUp(self):
     self.tenant_id = 'some_tenant'
     self.core = MimicCore(Clock(), [])
     self.root = MimicRoot(self.core).app.resource()
     self.eeapi_name = u"externalServiceName"
     self.eeapi = make_example_external_api(
         self,
         name=self.eeapi_name
     )
     self.template_id = get_template_id(self, self.eeapi)
     self.assertIsNotNone(self.template_id)
     self.uri = (
         "/identity/v2.0/tenants/" + self.tenant_id +
         "/OS-KSCATALOG/endpoints/" + self.template_id
     )
     self.headers = {
         b'X-Auth-Token': [b'ABCDEF987654321']
     }
     self.verb = b"DELETE"
    def test_add_template_with_mismatching_service_type(self):
        """
        Validate that adding a template the service type must match
        """
        eeapi = make_example_external_api(self,
                                          name=self.eeapi_name,
                                          set_enabled=True)
        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)
        new_eeapi_template.type_key = "random-type"

        with self.assertRaises(InvalidEndpointTemplateServiceType):
            eeapi.add_template(new_eeapi_template)