Skip to content
Snippets Groups Projects
Commit 920b9bc5 authored by Benjamin Bertrand's avatar Benjamin Bertrand
Browse files

Use FQDN for cnames

Fix INFRA-242
parent bfb820a6
No related branches found
Tags 2.6.1
No related merge requests found
......@@ -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)
VLAN_NAME_RE, MAC_ADDRESS_RE, CNAME_RE, CNAME_LEN_RE)
from .. import utils, models
......@@ -159,9 +159,10 @@ class InterfaceForm(CSEntryForm):
validators.Regexp(MAC_ADDRESS_RE, message='Invalid MAC address')])
cnames_string = StringField(
'Cnames',
description='space separated list of cnames (must be 2-20 characters long and contain only letters, numbers and dash)',
description='space separated list of cnames (fully-qualified domain name without the trailing dot)',
validators=[validators.Optional(),
RegexpList(HOST_NAME_RE)])
RegexpList(CNAME_LEN_RE),
RegexpList(CNAME_RE)])
tags = SelectMultipleField('Tags', coerce=utils.coerce_to_str_or_none,
validators=[validate_tags])
......
......@@ -16,6 +16,8 @@ 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}$')
......
# -*- 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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment