Merge "Add missing validation to consumer controller"

This commit is contained in:
Jenkins 2017-03-27 11:17:09 +00:00 committed by Gerrit Code Review
commit 876e5eb940
3 changed files with 149 additions and 3 deletions

View File

@ -762,8 +762,8 @@ class ContainerConsumerValidator(ValidatorBase):
self.schema = {
"type": "object",
"properties": {
"URL": {"type": "string"},
"name": {"type": "string", "maxLength": 255}
"URL": {"type": "string", "minLength": 1},
"name": {"type": "string", "maxLength": 255, "minLength": 1}
},
"required": ["name", "URL"]
}

View File

@ -263,6 +263,72 @@ class WhenTestingConsumersResource(utils.BarbicanAPIBaseTestCase):
self.assertEqual(404, consumer_del_resp.status_int)
def test_fail_create_no_name(self):
resp, container_uuid = create_container(
self.app,
name=self.container_name,
container_type=self.container_type
)
self.assertEqual(201, resp.status_int)
consumer_resp, consumer = create_consumer(
self.app,
container_id=container_uuid,
url="http://theurl",
expect_errors=True
)
self.assertEqual(400, consumer_resp.status_int)
def test_fail_create_no_url(self):
resp, container_uuid = create_container(
self.app,
name=self.container_name,
container_type=self.container_type
)
self.assertEqual(201, resp.status_int)
consumer_resp, consumer = create_consumer(
self.app,
container_id=container_uuid,
name="thename",
expect_errors=True
)
self.assertEqual(400, consumer_resp.status_int)
def test_fail_create_empty_name(self):
resp, container_uuid = create_container(
self.app,
name=self.container_name,
container_type=self.container_type
)
self.assertEqual(201, resp.status_int)
consumer_resp, consumer = create_consumer(
self.app,
container_id=container_uuid,
name="",
url="http://theurl",
expect_errors=True
)
self.assertEqual(400, consumer_resp.status_int)
def test_fail_create_empty_url(self):
resp, container_uuid = create_container(
self.app,
name=self.container_name,
container_type=self.container_type
)
self.assertEqual(201, resp.status_int)
consumer_resp, consumer = create_consumer(
self.app,
container_id=container_uuid,
name="thename",
url="",
expect_errors=True
)
self.assertEqual(400, consumer_resp.status_int)
# ----------------------- Helper Functions ---------------------------
def create_container(app, name=None, container_type=None, expect_errors=False,

View File

@ -239,7 +239,7 @@ class ConsumersCertContainerTestCase(ConsumersBaseTestCase):
class ConsumersAuthedTestCase(ConsumersBaseTestCase):
@testcase.attr('negative', 'security')
@testcase.attr('security')
def test_consumer_create_authed(self):
"""Create a consumer as an authenticated user
@ -343,3 +343,83 @@ class ConsumersUnauthedTestCase(ConsumersBaseTestCase):
)
self.assertEqual(401, resp.status_code)
class ConsumersValidationTestCase(ConsumersBaseTestCase):
def test_consumer_create_pass(self):
"""Create a valid consumer
Should return 200
"""
data = {
"name": "consumername",
"URL": "consumerURL"
}
model = consumer_model.ConsumerModel(**data)
resp, consumer_dat = self.consumer_behaviors.create_consumer(
model, self.generic_container_ref, use_auth=True
)
self.assertEqual(200, resp.status_code)
@testcase.attr('negative')
def test_consumer_create_fail_no_name(self):
"""Attempt to create invalid consumer (Missing name)
Should return 400
"""
data = {
"URL": "consumerURL"
}
model = consumer_model.ConsumerModel(**data)
resp, consumer_dat = self.consumer_behaviors.create_consumer(
model, self.generic_container_ref, use_auth=True
)
self.assertEqual(400, resp.status_code)
@testcase.attr('negative')
def test_consumer_create_fail_no_url(self):
"""Attempt to create invalid consumer (Missing URL)
Should return 400
"""
data = {
"name": "consumername"
}
model = consumer_model.ConsumerModel(**data)
resp, consumer_dat = self.consumer_behaviors.create_consumer(
model, self.generic_container_ref, use_auth=True
)
self.assertEqual(400, resp.status_code)
@testcase.attr('negative')
def test_consumer_create_fail_empty_name(self):
"""Attempt to create invalid consumer (Empty name)
Should return 400
"""
data = {
"name": "",
"URL": "consumerURL"
}
model = consumer_model.ConsumerModel(**data)
resp, consumer_dat = self.consumer_behaviors.create_consumer(
model, self.generic_container_ref, use_auth=True
)
self.assertEqual(400, resp.status_code)
@testcase.attr('negative')
def test_consumer_create_fail_empty_url(self):
"""Attempt to create invalid consumer (Empty URL)
Should return 400
"""
data = {
"name": "consumername",
"URL": ""
}
model = consumer_model.ConsumerModel(**data)
resp, consumer_dat = self.consumer_behaviors.create_consumer(
model, self.generic_container_ref, use_auth=True
)
self.assertEqual(400, resp.status_code)