Skip to content

Commit

Permalink
Check that region ID is not an empty string
Browse files Browse the repository at this point in the history
It generates an ID when a POST request to /regions has an empty string as ID

Change-Id: I49afd1f8c2e09ed31329bd8d1d88ca7f29ef7be9
Closes-Bug: 1322639
  • Loading branch information
BAKFR committed Jul 21, 2014
1 parent f9b4002 commit f9b5eb6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion keystone/catalog/controllers.py
Expand Up @@ -162,7 +162,7 @@ def create_region_with_id(self, context, region_id, region):
def create_region(self, context, region):
ref = self._normalize_dict(region)

if 'id' not in ref:
if not ref.get('id'):
ref = self._assign_unique_id(ref)

ref = self.catalog_api.create_region(ref)
Expand Down
11 changes: 11 additions & 0 deletions keystone/tests/test_v3_catalog.py
Expand Up @@ -78,6 +78,17 @@ def test_create_region(self):
'region_id': ref['id']})
self.assertValidRegionResponse(r, ref)

def test_create_region_with_empty_id(self):
"""Call ``POST /regions`` with an empty ID in the request body."""
ref = self.new_region_ref()
ref['id'] = ''

r = self.post(
'/regions',
body={'region': ref}, expected_status=201)
self.assertValidRegionResponse(r, ref)
self.assertNotEmpty(r.result['region'].get('id'))

def test_create_region_without_id(self):
"""Call ``POST /regions`` without an ID in the request body."""
ref = self.new_region_ref()
Expand Down

0 comments on commit f9b5eb6

Please sign in to comment.