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_existing_endpoint_template(self):
        """
        POST does not overwrite an existing endpoint template, 409 is
        generated instead.
        """
        self.core.add_api(self.eeapi)
        id_key = get_template_id(self, self.eeapi)

        data = {
            'id': id_key,
            'name': self.eeapi_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, 409)
        self.assertEqual(json_body['conflict']['code'], 409)
        self.assertEqual(
            json_body['conflict']['message'],
            "ID value is already assigned to an existing template")
    def test_new_endpoint_template_wrong_service_type(self):
        """
        POST requires that the endpoint template and service have the same
        service types.
        """
        self.core.add_api(self.eeapi)
        id_key = get_template_id(self, self.eeapi)

        data = {
            'id': text_type(uuid.uuid4()),
            'name': self.eeapi_name,
            'type': 'some-type',
            'region': 'some-region'
        }
        self.assertNotEqual(id_key, data['id'])
        (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'],
            "Endpoint already exists or service type does not match.")
    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_invalid_template_id(self):
        """
        PUT requires the endpoint template id to match an existing endpoint
        template, otherwise results in 404.
        """
        self.core.add_api(self.eeapi)
        id_key = get_template_id(self, self.eeapi)
        self.eeapi.remove_template(id_key)

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

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

        (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'],
            "Unable to update non-existent template. Template must "
            "first be added before it can be updated.",
        )
    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_new_endpoint_template_wrong_service_type(self):
        """
        POST requires that the endpoint template and service have the same
        service types.
        """
        self.core.add_api(self.eeapi)
        id_key = get_template_id(self, self.eeapi)

        data = {
            'id': text_type(uuid.uuid4()),
            'name': self.eeapi_name,
            'type': 'some-type',
            'region': 'some-region'
        }
        self.assertNotEqual(id_key, data['id'])
        (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'],
            "Endpoint already exists or service type does not match."
        )
    def test_existing_endpoint_template(self):
        """
        POST does not overwrite an existing endpoint template, 409 is
        generated instead.
        """
        self.core.add_api(self.eeapi)
        id_key = get_template_id(self, self.eeapi)

        data = {
            'id': id_key,
            'name': self.eeapi_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, 409)
        self.assertEqual(json_body['conflict']['code'], 409)
        self.assertEqual(
            json_body['conflict']['message'],
            "ID value is already assigned to an existing template"
        )
    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_invalid_template_id(self):
        """
        PUT requires the endpoint template id to match an existing endpoint
        template, otherwise results in 404.
        """
        self.core.add_api(self.eeapi)
        id_key = get_template_id(self, self.eeapi)
        self.eeapi.remove_template(id_key)

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

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

        (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'],
            "Unable to update non-existent template. Template must "
            "first be added before it can be updated.",
        )
    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_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")
Пример #14
0
    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)
Пример #15
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_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 setUp(self):
     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,
                                            set_enabled=True)
     self.headers = {b'X-Auth-Token': [b'ABCDEF987654321']}
     self.verb = b"DELETE"
     self.ept_template_id = get_template_id(self, self.eeapi)
     self.uri = ("/identity/v2.0/OS-KSCATALOG/endpointTemplates/" +
                 self.ept_template_id)
Пример #18
0
    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_list_template_all_disabled(self):
        """
        GET will not list endpoint templates that are disabled.
        """
        self.core.add_api(self.eeapi)
        id_key = get_template_id(self, self.eeapi)
        self.eeapi.endpoint_templates[id_key].enabled_key = False

        (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['endpoints']), 0)
        self.assertEqual(len(json_body['endpoints_links']), 0)
Пример #20
0
    def test_enable_template(self):
        """
        POST can update an existing endpoint template resulting in a 201.
        """
        self.core.add_api(self.eeapi)
        id_key = get_template_id(self, self.eeapi)
        data = {"OS-KSCATALOG:endpointTemplate": {"id": id_key}}

        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)
Пример #21
0
    def test_list_template_all_disabled(self):
        """
        GET will not list endpoint templates that are disabled.
        """
        self.core.add_api(self.eeapi)
        id_key = get_template_id(self, self.eeapi)
        self.eeapi.endpoint_templates[id_key].enabled_key = False

        (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['endpoints']), 0)
        self.assertEqual(len(json_body['endpoints_links']), 0)
 def setUp(self):
     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,
         set_enabled=True
     )
     self.headers = {
         b'X-Auth-Token': [b'ABCDEF987654321']
     }
     self.verb = b"DELETE"
     self.ept_template_id = get_template_id(self, self.eeapi)
     self.uri = (
         "/identity/v2.0/OS-KSCATALOG/endpointTemplates/" +
         self.ept_template_id
     )
    def test_enable_template(self):
        """
        POST can update an existing endpoint template resulting in a 201.
        """
        self.core.add_api(self.eeapi)
        id_key = get_template_id(self, self.eeapi)
        data = {
            "OS-KSCATALOG:endpointTemplate": {
                "id": id_key
            }
        }

        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)
Пример #24
0
    def test_disable_template(self):
        """
        DELETE for endpoint template enabled for tenant results in 204.
        """
        self.core.add_api(self.eeapi)
        self.eeapi.enable_endpoint_for_tenant(self.tenant_id, self.template_id)
        eeapi2 = make_example_external_api(self,
                                           name="alternate " + self.eeapi_name)
        ept_id2 = get_template_id(self, eeapi2)
        eeapi2.remove_template(ept_id2)
        self.core.add_api(eeapi2)
        req = request(self,
                      self.root,
                      self.verb,
                      self.uri,
                      headers=self.headers)

        response = self.successResultOf(req)
        self.assertEqual(response.code, 204)
 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_disable_template(self):
        """
        DELETE for endpoint template enabled for tenant results in 204.
        """
        self.core.add_api(self.eeapi)
        self.eeapi.enable_endpoint_for_tenant(
            self.tenant_id,
            self.template_id
        )
        eeapi2 = make_example_external_api(
            self,
            name="alternate " + self.eeapi_name
        )
        ept_id2 = get_template_id(self, eeapi2)
        eeapi2.remove_template(ept_id2)
        self.core.add_api(eeapi2)
        req = request(self, self.root, self.verb,
                      self.uri,
                      headers=self.headers)

        response = self.successResultOf(req)
        self.assertEqual(response.code, 204)