Skip to content

Commit

Permalink
Update FQDN validation (aerleon#300)
Browse files Browse the repository at this point in the history
  • Loading branch information
jtwb committed Jun 20, 2023
1 parent e44374d commit c7a36a8
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion aerleon/lib/fqdn.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class FQDN:

# https://regexr.com/3g5j0
fqdn_re = re.compile(
r'^(?!:\/\/)(?=.{1,255}$)((.{1,63}\.){1,127}(?![0-9]*$)[a-z0-9-]+\.?)$', re.IGNORECASE
r'^(?!.*:\/\/)(?=.{1,255}$)((.{1,63}\.){1,127}(?![0-9]*$)[a-z0-9-]+\.?)$', re.IGNORECASE
)
fqdn: str
text: str
Expand Down
2 changes: 1 addition & 1 deletion aerleon/lib/naming.py
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,7 @@ def _ParseYamlNetworks(self, file_data: Dict[str, Any], file_name: str) -> None:
# 1. A string, understood as a network name reference
# 2. A dictionary, with these fields:
# 'address': A specific IP address or CIDR range
# 'hostname': A FQDN for use in DNS filtering.
# 'fqdn': A FQDN for use in DNS filtering.
# 'name': A network name reference
# 'comment': An optional comment
# 'address' or 'name' must be present in any dictionary item
Expand Down
14 changes: 14 additions & 0 deletions schemas/aerleon-definitions.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
"description": "Specifies an IP address or CIDR IP address range expression.",
"type": "string"
},
"fqdn": {
"description": "Specifies a fully qualified domain name with two or more labels.",
"type": "string",
"pattern": "^(?!.*:https://)(?=.{1,255}$)((.{1,63}\\.){1,127}(?![0-9]*$)[a-z0-9-]+\\.?)$"
},
"port": {
"description": "Specifies a port or port range.",
"oneOf": [
Expand Down Expand Up @@ -77,6 +82,15 @@
},
"additionalProperties": false
},
{
"type": "object",
"required": ["fqdn"],
"properties": {
"fqdn": { "$ref": "#/$defs/fqdn" },
"comment": { "$ref": "#/$defs/comment" }
},
"additionalProperties": false
},
{
"type": "object",
"title": "Network Reference",
Expand Down
1 change: 1 addition & 0 deletions tests/lib/fqdn_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class FQDNTest(parameterized.TestCase):
'',
True,
),
('URL scheme must not be included', 'https://foo.bar', '', '', True),
)
def testFQDNCreation(self, possible_fqdn: str, token: str, comment: str, error: Exception):

Expand Down

0 comments on commit c7a36a8

Please sign in to comment.