Merge "Validate provider_location while managing snapshot"

This commit is contained in:
Zuul 2023-09-14 20:35:55 +00:00 committed by Gerrit Code Review
commit 65f1bb8f08
3 changed files with 11 additions and 1 deletions

View File

@ -182,6 +182,9 @@ class ShareSnapshotsController(share_snapshots.ShareSnapshotMixin,
if not data.get(parameter):
msg = _("Required parameter %s is empty.") % parameter
raise exc_response(explanation=msg)
if not isinstance(data[parameter], str):
msg = _("Parameter %s must be a string.") % parameter
raise exc_response(explanation=msg)
def _check_if_share_share_network_is_active(self, context, snapshot):
share_network_id = snapshot['share'].get('share_network_id')

View File

@ -777,7 +777,8 @@ class ShareSnapshotAdminActionsAPITest(test.TestCase):
{},
{'snapshots': {}},
{'snapshot': get_fake_manage_body(share_id='xxxxxxxx')},
{'snapshot': get_fake_manage_body(provider_location='xxxxxxxx')}
{'snapshot': get_fake_manage_body(provider_location='xxxxxxxx')},
{'snapshot': {'provider_location': {'x': 'y'}, 'share_id': 'xyzzy'}},
)
def test_snapshot_manage_invalid_body(self, body):
self.mock_policy_check = self.mock_object(

View File

@ -0,0 +1,6 @@
---
fixes:
- |
The "manage" API for snapshots now validates the format of
"provider_location" and "share_id" fields and handles errors
appropriately. These fields are expected to contain string values.