Validate name during v2 zone create

The name in the v2 zone create is now being checked to see if it is
a valid domain name format.  Previously you could create a zone
with a name like below
{
  "zone" : {
    "name" : "com.com...........",
    "email" : "hs@rs.com"
  }
}

Closes-Bug: #1271665

Change-Id: Ie2481aec5f4a033df64767dfbff30e56e3133e1c
This commit is contained in:
Vinod Mangalpally 2014-01-22 12:05:31 -06:00
parent 3677ea7e7e
commit 4db7981acd
4 changed files with 18 additions and 4 deletions

View File

@ -37,7 +37,7 @@
"name": {
"type": "string",
"description": "Zone name",
"format": "domain-name",
"format": "domainname",
"maxLength": 255,
"immutable": true
},

View File

@ -171,6 +171,7 @@ class TestCase(test.BaseTestCase):
'secret': 'AnotherSecretKey',
}]
# The last domain is invalid
domain_fixtures = [{
'name': 'example.com.',
'email': 'example@example.com',
@ -180,6 +181,9 @@ class TestCase(test.BaseTestCase):
}, {
'name': 'example.org.',
'email': 'example@example.org',
}, {
'name': 'invalid.com.....',
'email': 'example@invalid.com',
}]
recordset_fixtures = {

View File

@ -15,9 +15,9 @@
from designate.tests.test_api.test_v2 import ApiV2TestCase
class ApiV2ZTldsTest(ApiV2TestCase):
class ApiV2TldsTest(ApiV2TestCase):
def setUp(self):
super(ApiV2ZTldsTest, self).setUp()
super(ApiV2TldsTest, self).setUp()
def test_create_tld(self):
self.policy({'create_tld': '@'})

View File

@ -69,7 +69,7 @@ class ApiV2ZonesTest(ApiV2TestCase):
self.assertEqual(fixture[k], response.json['zone'][k])
def test_create_zone_validation(self):
# NOTE: The schemas should be tested separatly to the API. So we
# NOTE: The schemas should be tested separately to the API. So we
# don't need to test every variation via the API itself.
# Fetch a fixture
fixture = self.get_domain_fixture(0)
@ -88,6 +88,16 @@ class ApiV2ZonesTest(ApiV2TestCase):
body = {'zone': fixture}
self.client.post_json('/zones/', body, status=400)
def test_create_zone_invalid_name(self):
# Try to create a zone with an invalid name
fixture = self.get_domain_fixture(-1)
response = self.client.post_json('/zones/',
{'zone': fixture},
status=400)
# Ensure it fails with a 400
self.assertEqual(400, response.status_int)
@patch.object(central_service.Service, 'create_domain',
side_effect=rpc_common.Timeout())
def test_create_zone_timeout(self, _):