summaryrefslogtreecommitdiffstats
path: root/tests/test_content_types.py
diff options
context:
space:
mode:
authorWu Wenxiang <wu.wenxiang@99cloud.net>2013-06-16 04:18:05 +0800
committerWu Wenxiang <wu.wenxiang@99cloud.net>2013-06-16 05:23:50 +0800
commit76e3183ead6ac52fc744f51313bc0fd3b5f4d610 (patch)
tree84f838d62cab03f99cf1b405002f341682292b94 /tests/test_content_types.py
parent3c687d17016cb8efcfdce2de0d2f923121917fcb (diff)
downloadkeystone-76e3183ead6ac52fc744f51313bc0fd3b5f4d610.tar.gz
keystone-76e3183ead6ac52fc744f51313bc0fd3b5f4d610.tar.xz
keystone-76e3183ead6ac52fc744f51313bc0fd3b5f4d610.zip
Http 400 when project enabled is not a boolean
Having enabled="true" in json data when updating tenant will produce 500 When updating a project, no type check was performed on the enabled attribute. Therefore, if enabled value in JSON/XML is not a boolean but a string, keystone responds with an incorrect Http 500 error code and the stacktrace. The change introduces a type validation of the enabled attribute at identity manager. If the type is not a boolean, keystone now returns an appropriate Http 400 error code with a message pointing a bad format for the attribute. Test cases have been added to file test_backend and test_content_types for testing the case when enabled attribute is a string or int when updating project. Fixes bug #1191384 Change-Id: I86dd7e71d4bac1e3fd6fcabaa1a2136a47722e5f
Diffstat (limited to 'tests/test_content_types.py')
-rw-r--r--tests/test_content_types.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/test_content_types.py b/tests/test_content_types.py
index c3b804a7..fd99eae8 100644
--- a/tests/test_content_types.py
+++ b/tests/test_content_types.py
@@ -1059,3 +1059,42 @@ class XmlTestCase(RestfulTestCase, CoreApiTests):
self.assertIsNotNone(r.result.get('tenant'))
self.assertValidTenant(r.result['tenant'])
self.assertEqual(r.result['tenant'].get('description'), "")
+
+ def test_create_project_invalid_enabled_type_string(self):
+ # Forbidden usage of string for 'enabled' field in JSON and XML
+ token = self.get_scoped_token()
+
+ r = self.admin_request(
+ method='POST',
+ path='/v2.0/tenants',
+ body={
+ 'tenant': {
+ 'name': uuid.uuid4().hex,
+ # In XML, only "true|false" are converted to boolean.
+ 'enabled': "False",
+ },
+ },
+ token=token,
+ expected_status=400)
+ self.assertValidErrorResponse(r)
+
+ def test_update_project_invalid_enabled_type_string(self):
+ # Forbidden usage of string for 'enabled' field in JSON and XML
+ token = self.get_scoped_token()
+
+ path = '/v2.0/tenants/%(tenant_id)s' % {
+ 'tenant_id': self.tenant_bar['id'],
+ }
+
+ r = self.admin_request(
+ method='PUT',
+ path=path,
+ body={
+ 'tenant': {
+ # In XML, only "true|false" are converted to boolean.
+ 'enabled': "False",
+ },
+ },
+ token=token,
+ expected_status=400)
+ self.assertValidErrorResponse(r)