Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
csentry
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ICS Control System Infrastructure
csentry
Commits
920b9bc5
Commit
920b9bc5
authored
7 years ago
by
Benjamin Bertrand
Browse files
Options
Downloads
Patches
Plain Diff
Use FQDN for cnames
Fix INFRA-242
parent
bfb820a6
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
app/network/forms.py
+4
-3
4 additions, 3 deletions
app/network/forms.py
app/validators.py
+2
-0
2 additions, 0 deletions
app/validators.py
tests/unit/test_validators.py
+37
-0
37 additions, 0 deletions
tests/unit/test_validators.py
with
43 additions
and
3 deletions
app/network/forms.py
+
4
−
3
View file @
920b9bc5
...
@@ -15,7 +15,7 @@ from wtforms import (SelectField, StringField, TextAreaField, IntegerField,
...
@@ -15,7 +15,7 @@ from wtforms import (SelectField, StringField, TextAreaField, IntegerField,
SelectMultipleField
,
BooleanField
,
validators
)
SelectMultipleField
,
BooleanField
,
validators
)
from
..helpers
import
CSEntryForm
from
..helpers
import
CSEntryForm
from
..validators
import
(
Unique
,
RegexpList
,
IPNetwork
,
HOST_NAME_RE
,
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
from
..
import
utils
,
models
...
@@ -159,9 +159,10 @@ class InterfaceForm(CSEntryForm):
...
@@ -159,9 +159,10 @@ class InterfaceForm(CSEntryForm):
validators
.
Regexp
(
MAC_ADDRESS_RE
,
message
=
'
Invalid MAC address
'
)])
validators
.
Regexp
(
MAC_ADDRESS_RE
,
message
=
'
Invalid MAC address
'
)])
cnames_string
=
StringField
(
cnames_string
=
StringField
(
'
Cnames
'
,
'
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
(),
validators
=
[
validators
.
Optional
(),
RegexpList
(
HOST_NAME_RE
)])
RegexpList
(
CNAME_LEN_RE
),
RegexpList
(
CNAME_RE
)])
tags
=
SelectMultipleField
(
'
Tags
'
,
coerce
=
utils
.
coerce_to_str_or_none
,
tags
=
SelectMultipleField
(
'
Tags
'
,
coerce
=
utils
.
coerce_to_str_or_none
,
validators
=
[
validate_tags
])
validators
=
[
validate_tags
])
...
...
This diff is collapsed.
Click to expand it.
app/validators.py
+
2
−
0
View file @
920b9bc5
...
@@ -16,6 +16,8 @@ from wtforms import ValidationError
...
@@ -16,6 +16,8 @@ from wtforms import ValidationError
ICS_ID_RE
=
re
.
compile
(
'
[A-Z]{3}[0-9]{3}
'
)
ICS_ID_RE
=
re
.
compile
(
'
[A-Z]{3}[0-9]{3}
'
)
HOST_NAME_RE
=
re
.
compile
(
'
^[a-z0-9\-]{2,20}$
'
)
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}$
'
)
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}$
'
)
MAC_ADDRESS_RE
=
re
.
compile
(
'
^(?:[0-9a-fA-F]{2}[:-]?){5}[0-9a-fA-F]{2}$
'
)
...
...
This diff is collapsed.
Click to expand it.
tests/unit/test_validators.py
0 → 100644
+
37
−
0
View file @
920b9bc5
# -*- 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
This diff is collapsed.
Click to expand it.
Benjamin Bertrand
@benjaminbertrand
mentioned in commit
915ead71
·
7 years ago
mentioned in commit
915ead71
mentioned in commit 915ead711e8fdac44e057deb18368f9594ae6295
Toggle commit list
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment