mirror of
https://github.com/pi-hole/pi-hole.git
synced 2024-12-25 14:20:18 +00:00
Merge pull request #2840 from pi-hole/fix/valid_ip-quote-error
Fix error when checking if IP address is valid
This commit is contained in:
commit
bfe714e985
2 changed files with 40 additions and 1 deletions
|
@ -934,7 +934,7 @@ valid_ip() {
|
||||||
# and set the new one to a dot (period)
|
# and set the new one to a dot (period)
|
||||||
IFS='.'
|
IFS='.'
|
||||||
# Put the IP into an array
|
# Put the IP into an array
|
||||||
ip=("${ip}")
|
read -r -a ip <<< "${ip}"
|
||||||
# Restore the IFS to what it was
|
# Restore the IFS to what it was
|
||||||
IFS=${OIFS}
|
IFS=${OIFS}
|
||||||
## Evaluate each octet by checking if it's less than or equal to 255 (the max for each octet)
|
## Evaluate each octet by checking if it's less than or equal to 255 (the max for each octet)
|
||||||
|
|
|
@ -700,3 +700,42 @@ def test_IPv6_ULA_GUA_test(Pihole):
|
||||||
''')
|
''')
|
||||||
expected_stdout = 'Found IPv6 ULA address, using it for blocking IPv6 ads'
|
expected_stdout = 'Found IPv6 ULA address, using it for blocking IPv6 ads'
|
||||||
assert expected_stdout in detectPlatform.stdout
|
assert expected_stdout in detectPlatform.stdout
|
||||||
|
|
||||||
|
|
||||||
|
def test_validate_ip_valid(Pihole):
|
||||||
|
'''
|
||||||
|
Given a valid IP address, valid_ip returns success
|
||||||
|
'''
|
||||||
|
|
||||||
|
output = Pihole.run('''
|
||||||
|
source /opt/pihole/basic-install.sh
|
||||||
|
valid_ip "192.168.1.1"
|
||||||
|
''')
|
||||||
|
|
||||||
|
assert output.rc == 0
|
||||||
|
|
||||||
|
|
||||||
|
def test_validate_ip_invalid_octet(Pihole):
|
||||||
|
'''
|
||||||
|
Given an invalid IP address (large octet), valid_ip returns an error
|
||||||
|
'''
|
||||||
|
|
||||||
|
output = Pihole.run('''
|
||||||
|
source /opt/pihole/basic-install.sh
|
||||||
|
valid_ip "1092.168.1.1"
|
||||||
|
''')
|
||||||
|
|
||||||
|
assert output.rc == 1
|
||||||
|
|
||||||
|
|
||||||
|
def test_validate_ip_invalid_letters(Pihole):
|
||||||
|
'''
|
||||||
|
Given an invalid IP address (contains letters), valid_ip returns an error
|
||||||
|
'''
|
||||||
|
|
||||||
|
output = Pihole.run('''
|
||||||
|
source /opt/pihole/basic-install.sh
|
||||||
|
valid_ip "not an IP"
|
||||||
|
''')
|
||||||
|
|
||||||
|
assert output.rc == 1
|
||||||
|
|
Loading…
Reference in a new issue