From 915ead711e8fdac44e057deb18368f9594ae6295 Mon Sep 17 00:00:00 2001
From: Benjamin Bertrand <benjamin.bertrand@esss.se>
Date: Wed, 14 Mar 2018 11:38:16 +0100
Subject: [PATCH] Revert "Use FQDN for cnames"

This reverts commit 920b9bc522f03d2c8eb684110ed8fb3d4131fa64.

Allowing cnames with different domains makes things too complex.
The domain shall be the same as the host.

See INFRA-242
---
 app/network/forms.py          |  7 +++----
 app/validators.py             |  2 --
 tests/unit/test_validators.py | 37 -----------------------------------
 3 files changed, 3 insertions(+), 43 deletions(-)
 delete mode 100644 tests/unit/test_validators.py

diff --git a/app/network/forms.py b/app/network/forms.py
index b5abe36..268bbb3 100644
--- a/app/network/forms.py
+++ b/app/network/forms.py
@@ -15,7 +15,7 @@ from wtforms import (SelectField, StringField, TextAreaField, IntegerField,
                      SelectMultipleField, BooleanField, validators)
 from ..helpers import CSEntryForm
 from ..validators import (Unique, RegexpList, IPNetwork, HOST_NAME_RE,
-                          VLAN_NAME_RE, MAC_ADDRESS_RE, CNAME_RE, CNAME_LEN_RE)
+                          VLAN_NAME_RE, MAC_ADDRESS_RE)
 from .. import utils, models
 
 
@@ -159,10 +159,9 @@ class InterfaceForm(CSEntryForm):
                     validators.Regexp(MAC_ADDRESS_RE, message='Invalid MAC address')])
     cnames_string = StringField(
         'Cnames',
-        description='space separated list of cnames (fully-qualified domain name without the trailing dot)',
+        description='space separated list of cnames (must be 2-20 characters long and contain only letters, numbers and dash)',
         validators=[validators.Optional(),
-                    RegexpList(CNAME_LEN_RE),
-                    RegexpList(CNAME_RE)])
+                    RegexpList(HOST_NAME_RE)])
     tags = SelectMultipleField('Tags', coerce=utils.coerce_to_str_or_none,
                                validators=[validate_tags])
 
diff --git a/app/validators.py b/app/validators.py
index 0ff11b9..6c8ae87 100644
--- a/app/validators.py
+++ b/app/validators.py
@@ -16,8 +16,6 @@ from wtforms import ValidationError
 
 ICS_ID_RE = re.compile('[A-Z]{3}[0-9]{3}')
 HOST_NAME_RE = re.compile('^[a-z0-9\-]{2,20}$')
-CNAME_LEN_RE = re.compile('^[a-z0-9\.\-]{2,252}$')
-CNAME_RE = re.compile('^((?!-)[a-z0-9\-]{1,62}\.)+[a-z]{1,62}$')
 VLAN_NAME_RE = re.compile('^[A-Za-z0-9\-]{3,25}$')
 MAC_ADDRESS_RE = re.compile('^(?:[0-9a-fA-F]{2}[:-]?){5}[0-9a-fA-F]{2}$')
 
diff --git a/tests/unit/test_validators.py b/tests/unit/test_validators.py
deleted file mode 100644
index 447eed8..0000000
--- a/tests/unit/test_validators.py
+++ /dev/null
@@ -1,37 +0,0 @@
-# -*- coding: utf-8 -*-
-"""
-tests.unit.test_validators
-~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-This module defines validators tests.
-
-:copyright: (c) 2018 European Spallation Source ERIC
-:license: BSD 2-Clause, see LICENSE for more details.
-
-"""
-import pytest
-from app import validators
-
-
-@pytest.mark.parametrize('name', [
-    'a.se',
-    'myhost.esss.lu.se',
-    'myhost.tn.esss.lu.se',
-    'myhost-foo.tn.esss.lu.se',
-    'myhost-02.tn.esss.lu.se',
-    'longhostname-100000000000.tn.esss.lu.se',
-    'a' * 62 + '.org',
-])
-def test_cname_re_valid(name):
-    assert validators.CNAME_RE.match(name) is not None
-
-
-@pytest.mark.parametrize('name', [
-    'myhost',
-    'myhost03',
-    'myhost.esss.lu.se.',
-    'myhost_foo.tn.esss.lu.se',
-    'a' * 63 + '.org',
-])
-def test_cname_re_invalid(name):
-    assert validators.CNAME_RE.match(name) is None
-- 
GitLab