Browse Source

Fix POST /v1/secret/{secret-id}/metadata response

This patch fixes the response to POST requests in the metadata API so it
actually matches the documentation. [1]

Story: 2009247
Task: 43673

[1]
https://docs.openstack.org/barbican/latest/api/reference/secret_metadata.html#post-v1-secrets-uuid-metadata

Change-Id: I5505a8c56ed7274519cac8ad1e6d7adf5086c8d1
(cherry picked from commit 8bd16953eb)
(cherry picked from commit 61aa13e970)
(cherry picked from commit 49f3b2f0d1)
(cherry picked from commit 841973caca)
(cherry picked from commit 07ef50c187)
changes/35/816135/3
Douglas Mendizábal 8 months ago
parent
commit
42feeeaea9
  1. 5
      barbican/api/controllers/secretmeta.py
  2. 23
      barbican/tests/api/controllers/test_secretmeta.py
  3. 6
      releasenotes/notes/fix-story-2009247-18faf4f2b570dfc0.yaml

5
barbican/api/controllers/secretmeta.py

@ -103,9 +103,8 @@ class SecretMetadataController(controllers.ACLMixin):
LOG.debug('URI to secret metadata is %s', url)
pecan.response.status = 201
return {'metadata_ref': url + "/%s {key: %s, value:%s}" % (key,
key,
value)}
pecan.response.headers['Location'] = str(url + '/' + key)
return {'key': key, 'value': value}
class SecretMetadatumController(controllers.ACLMixin):

23
barbican/tests/api/controllers/test_secretmeta.py

@ -35,6 +35,29 @@ class WhenTestingSecretMetadataResource(utils.BarbicanAPIBaseTestCase):
}
}
def test_post_secret_metadata(self):
secret_id, secret_resp = create_secret(self.app)
resp = self.app.post_json(
'/secrets/{}/metadata'.format(secret_id),
{'key': 'foo',
'value': 'bar'}
)
meta = json.loads(resp.body)
self.assertIn('key', meta.keys())
self.assertIn('value', meta.keys())
self.assertEqual('foo', meta['key'])
self.assertEqual('bar', meta['value'])
def test_post_secret_metadata_response_sets_location_header(self):
secret_id, secret_resp = create_secret(self.app)
resp = self.app.post_json(
'/secrets/{}/metadata'.format(secret_id),
{'key': 'foo',
'value': 'bar'}
)
self.assertIn('Location', resp.headers)
self.assertTrue(resp.headers['Location'].endswith('foo'))
def test_create_secret_metadata(self):
secret_resp, secret_uuid = create_secret(self.app)
meta_resp = create_secret_metadata(self.app,

6
releasenotes/notes/fix-story-2009247-18faf4f2b570dfc0.yaml

@ -0,0 +1,6 @@
---
fixes:
- |
Fixed Story #2009247 - Fixed the response for
POST /v1/secrets/{secret-id}/metadata so it matches the documented
behavior.
Loading…
Cancel
Save