Fix Faulty Regex pattern in custom DNS domain validation (#5291)

This commit is contained in:
yubiuser 2023-05-29 09:13:33 +02:00 committed by GitHub
commit fc67de8c19
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 1 deletions

View file

@ -664,7 +664,7 @@ checkDomain()
local domain validDomain local domain validDomain
# Convert to lowercase # Convert to lowercase
domain="${1,,}" domain="${1,,}"
validDomain=$(grep -P "^((-|_)*[a-z0-9]((-|_)*[a-z0-9)*(-|_)*)(\\.(-|_)*([a-z0-9]((-|_)*[a-z0-9])*))*$" <<< "${domain}") # Valid chars check validDomain=$(grep -P "^((-|_)*[a-z0-9]((-|_)*[a-z0-9])*(-|_)*)(\\.(-|_)*([a-z0-9]((-|_)*[a-z0-9])*))*$" <<< "${domain}") # Valid chars check
validDomain=$(grep -P "^[^\\.]{1,63}(\\.[^\\.]{1,63})*$" <<< "${validDomain}") # Length of each label validDomain=$(grep -P "^[^\\.]{1,63}(\\.[^\\.]{1,63})*$" <<< "${validDomain}") # Length of each label
echo "${validDomain}" echo "${validDomain}"
} }

View file

@ -1151,3 +1151,30 @@ def test_package_manager_has_web_deps(host):
assert "No package" not in output.stdout assert "No package" not in output.stdout
assert output.rc == 0 assert output.rc == 0
def test_webpage_sh_valid_domain(host):
"""Confirms checkDomain function in webpage.sh works as expected"""
check1 = host.run(
"""
source /opt/pihole/webpage.sh
checkDomain "pi-hole.net"
"""
)
check2 = host.run(
"""
source /opt/pihole/webpage.sh
checkDomain "ab.pi-hole.net"
"""
)
check3 = host.run(
"""
source /opt/pihole/webpage.sh
checkDomain "abc.pi-hole.net"
"""
)
assert "pi-hole.net" in check1.stdout
assert "ab.pi-hole.net" in check2.stdout
assert "abc.pi-hole.net" in check3.stdout