Add content_types to the response dict
This change adds content_types to the consumers responses returning a secret. Change-Id: I7d0cd4d00244a3dc791b35f112e3689c2b6dd790
This commit is contained in:
parent
659ea4c5c7
commit
f848fa9b4a
@ -23,6 +23,7 @@ from barbican.common import validators
|
|||||||
from barbican import i18n as u
|
from barbican import i18n as u
|
||||||
from barbican.model import models
|
from barbican.model import models
|
||||||
from barbican.model import repositories as repo
|
from barbican.model import repositories as repo
|
||||||
|
from barbican.plugin import util as putil
|
||||||
|
|
||||||
LOG = utils.getLogger(__name__)
|
LOG = utils.getLogger(__name__)
|
||||||
|
|
||||||
@ -390,8 +391,7 @@ class SecretConsumersController(controllers.ACLMixin):
|
|||||||
def _return_secret_data(self, secret_id):
|
def _return_secret_data(self, secret_id):
|
||||||
secret = self._get_secret(secret_id)
|
secret = self._get_secret(secret_id)
|
||||||
|
|
||||||
dict_fields = secret.to_dict_fields()
|
secret_fields = putil.mime_types.augment_fields_with_content_types(
|
||||||
|
secret)
|
||||||
|
|
||||||
return hrefs.convert_to_hrefs(
|
return hrefs.convert_to_hrefs(secret_fields)
|
||||||
hrefs.convert_to_hrefs(dict_fields)
|
|
||||||
)
|
|
||||||
|
@ -1262,6 +1262,7 @@ class WhenCreatingSecretConsumersUsingResource(FunctionalTest):
|
|||||||
return RootController()
|
return RootController()
|
||||||
|
|
||||||
def _init(self):
|
def _init(self):
|
||||||
|
self.name = 'test container name'
|
||||||
self.external_project_id = 'keystoneid1234'
|
self.external_project_id = 'keystoneid1234'
|
||||||
self.project_internal_id = 'projectid1234'
|
self.project_internal_id = 'projectid1234'
|
||||||
|
|
||||||
@ -1271,8 +1272,35 @@ class WhenCreatingSecretConsumersUsingResource(FunctionalTest):
|
|||||||
self.project.external_id = self.external_project_id
|
self.project.external_id = self.external_project_id
|
||||||
|
|
||||||
# Set up mocked secret
|
# Set up mocked secret
|
||||||
self.secret = models.Secret()
|
secret_id = utils.generate_test_valid_uuid()
|
||||||
self.secret.id = utils.generate_test_valid_uuid()
|
datum_id = "iddatum1"
|
||||||
|
kek_id = "idkek1"
|
||||||
|
|
||||||
|
self.secret_algorithm = "AES"
|
||||||
|
self.secret_bit_length = 256
|
||||||
|
self.secret_mode = "CBC"
|
||||||
|
|
||||||
|
self.kek_project = models.KEKDatum()
|
||||||
|
self.kek_project.id = kek_id
|
||||||
|
self.kek_project.active = True
|
||||||
|
self.kek_project.bind_completed = False
|
||||||
|
self.kek_project.kek_label = "kek_label"
|
||||||
|
|
||||||
|
self.datum = models.EncryptedDatum()
|
||||||
|
self.datum.id = datum_id
|
||||||
|
self.datum.secret_id = secret_id
|
||||||
|
self.datum.kek_id = kek_id
|
||||||
|
self.datum.kek_meta_project = self.kek_project
|
||||||
|
self.datum.content_type = "text/plain"
|
||||||
|
self.datum.cypher_text = "aaaa" # base64 value.
|
||||||
|
|
||||||
|
self.secret = create_secret(id_ref=secret_id,
|
||||||
|
name=self.name,
|
||||||
|
algorithm=self.secret_algorithm,
|
||||||
|
bit_length=self.secret_bit_length,
|
||||||
|
mode=self.secret_mode,
|
||||||
|
encrypted_datum=self.datum,
|
||||||
|
content_type=self.datum.content_type)
|
||||||
self.secret.project = self.project
|
self.secret.project = self.project
|
||||||
self.secret.project_id = self.project_internal_id
|
self.secret.project_id = self.project_internal_id
|
||||||
|
|
||||||
@ -1320,6 +1348,7 @@ class WhenCreatingSecretConsumersUsingResource(FunctionalTest):
|
|||||||
args, kwargs = self.consumer_repo.create_or_update_from.call_args
|
args, kwargs = self.consumer_repo.create_or_update_from.call_args
|
||||||
consumer = args[0]
|
consumer = args[0]
|
||||||
self.assertIsInstance(consumer, models.SecretConsumerMetadatum)
|
self.assertIsInstance(consumer, models.SecretConsumerMetadatum)
|
||||||
|
self.assertIn('content_types', resp.namespace)
|
||||||
|
|
||||||
def test_should_fail_consumer_bad_json(self):
|
def test_should_fail_consumer_bad_json(self):
|
||||||
resp = self.app.post(
|
resp = self.app.post(
|
||||||
@ -1357,6 +1386,7 @@ class WhenGettingOrDeletingSecretConsumersUsingResource(FunctionalTest):
|
|||||||
return RootController()
|
return RootController()
|
||||||
|
|
||||||
def _init(self):
|
def _init(self):
|
||||||
|
self.name = 'test container name'
|
||||||
self.external_project_id = 'keystoneid1234'
|
self.external_project_id = 'keystoneid1234'
|
||||||
self.project_internal_id = 'projectid1234'
|
self.project_internal_id = 'projectid1234'
|
||||||
|
|
||||||
@ -1366,8 +1396,35 @@ class WhenGettingOrDeletingSecretConsumersUsingResource(FunctionalTest):
|
|||||||
self.project.external_id = self.external_project_id
|
self.project.external_id = self.external_project_id
|
||||||
|
|
||||||
# Set up mocked secret
|
# Set up mocked secret
|
||||||
self.secret = models.Secret()
|
secret_id = utils.generate_test_valid_uuid()
|
||||||
self.secret.id = utils.generate_test_valid_uuid()
|
datum_id = "iddatum1"
|
||||||
|
kek_id = "idkek1"
|
||||||
|
|
||||||
|
self.secret_algorithm = "AES"
|
||||||
|
self.secret_bit_length = 256
|
||||||
|
self.secret_mode = "CBC"
|
||||||
|
|
||||||
|
self.kek_project = models.KEKDatum()
|
||||||
|
self.kek_project.id = kek_id
|
||||||
|
self.kek_project.active = True
|
||||||
|
self.kek_project.bind_completed = False
|
||||||
|
self.kek_project.kek_label = "kek_label"
|
||||||
|
|
||||||
|
self.datum = models.EncryptedDatum()
|
||||||
|
self.datum.id = datum_id
|
||||||
|
self.datum.secret_id = secret_id
|
||||||
|
self.datum.kek_id = kek_id
|
||||||
|
self.datum.kek_meta_project = self.kek_project
|
||||||
|
self.datum.content_type = "text/plain"
|
||||||
|
self.datum.cypher_text = "aaaa" # base64 value.
|
||||||
|
|
||||||
|
self.secret = create_secret(id_ref=secret_id,
|
||||||
|
name=self.name,
|
||||||
|
algorithm=self.secret_algorithm,
|
||||||
|
bit_length=self.secret_bit_length,
|
||||||
|
mode=self.secret_mode,
|
||||||
|
encrypted_datum=self.datum,
|
||||||
|
content_type=self.datum.content_type)
|
||||||
self.secret.project = self.project
|
self.secret.project = self.project
|
||||||
self.secret.project_id = self.project_internal_id
|
self.secret.project_id = self.project_internal_id
|
||||||
|
|
||||||
@ -1464,12 +1521,13 @@ class WhenGettingOrDeletingSecretConsumersUsingResource(FunctionalTest):
|
|||||||
self.assertEqual(200, resp.status_int)
|
self.assertEqual(200, resp.status_int)
|
||||||
|
|
||||||
def test_should_delete_consumer(self):
|
def test_should_delete_consumer(self):
|
||||||
self.app.delete_json('/secrets/{0}/consumers/'.format(
|
resp = self.app.delete_json('/secrets/{0}/consumers/'.format(
|
||||||
self.secret.id
|
self.secret.id
|
||||||
), self.consumer_ref)
|
), self.consumer_ref)
|
||||||
|
|
||||||
self.consumer_repo.delete_entity_by_id.assert_called_once_with(
|
self.consumer_repo.delete_entity_by_id.assert_called_once_with(
|
||||||
self.consumer.id, self.external_project_id)
|
self.consumer.id, self.external_project_id)
|
||||||
|
self.assertIn('content_types', resp.namespace)
|
||||||
|
|
||||||
def test_should_fail_deleting_consumer_bad_json(self):
|
def test_should_fail_deleting_consumer_bad_json(self):
|
||||||
resp = self.app.delete(
|
resp = self.app.delete(
|
||||||
|
Loading…
Reference in New Issue
Block a user