2022-01-31 00:05:28 +01:00
|
|
|
def test_key_val_replacement_works(host):
|
2022-09-19 14:44:10 +02:00
|
|
|
"""Confirms addOrEditKeyValPair either adds or replaces a key value pair in a given file"""
|
|
|
|
host.run(
|
|
|
|
"""
|
2022-01-31 00:05:28 +01:00
|
|
|
source /opt/pihole/utils.sh
|
2022-03-16 21:46:15 +01:00
|
|
|
addOrEditKeyValPair "./testoutput" "KEY_ONE" "value1"
|
|
|
|
addOrEditKeyValPair "./testoutput" "KEY_TWO" "value2"
|
|
|
|
addOrEditKeyValPair "./testoutput" "KEY_ONE" "value3"
|
|
|
|
addOrEditKeyValPair "./testoutput" "KEY_FOUR" "value4"
|
2022-09-19 14:44:10 +02:00
|
|
|
"""
|
|
|
|
)
|
|
|
|
output = host.run(
|
|
|
|
"""
|
2022-01-31 00:05:28 +01:00
|
|
|
cat ./testoutput
|
2022-09-19 14:44:10 +02:00
|
|
|
"""
|
|
|
|
)
|
|
|
|
expected_stdout = "KEY_ONE=value3\nKEY_TWO=value2\nKEY_FOUR=value4\n"
|
2022-03-16 18:42:01 +01:00
|
|
|
assert expected_stdout == output.stdout
|
|
|
|
|
2022-03-16 21:46:15 +01:00
|
|
|
|
2022-04-19 19:35:00 +02:00
|
|
|
def test_key_addition_works(host):
|
2022-09-19 14:44:10 +02:00
|
|
|
"""Confirms addKey adds a key (no value) to a file without duplicating it"""
|
|
|
|
host.run(
|
|
|
|
"""
|
2022-04-19 19:35:00 +02:00
|
|
|
source /opt/pihole/utils.sh
|
|
|
|
addKey "./testoutput" "KEY_ONE"
|
|
|
|
addKey "./testoutput" "KEY_ONE"
|
|
|
|
addKey "./testoutput" "KEY_TWO"
|
|
|
|
addKey "./testoutput" "KEY_TWO"
|
|
|
|
addKey "./testoutput" "KEY_THREE"
|
|
|
|
addKey "./testoutput" "KEY_THREE"
|
2022-09-19 14:44:10 +02:00
|
|
|
"""
|
|
|
|
)
|
|
|
|
output = host.run(
|
|
|
|
"""
|
2022-04-19 19:35:00 +02:00
|
|
|
cat ./testoutput
|
2022-09-19 14:44:10 +02:00
|
|
|
"""
|
|
|
|
)
|
|
|
|
expected_stdout = "KEY_ONE\nKEY_TWO\nKEY_THREE\n"
|
2022-04-19 19:35:00 +02:00
|
|
|
assert expected_stdout == output.stdout
|
|
|
|
|
|
|
|
|
2023-03-17 03:36:22 +01:00
|
|
|
def test_key_addition_substr(host):
|
|
|
|
"""Confirms addKey adds substring keys (no value) to a file"""
|
|
|
|
host.run(
|
|
|
|
"""
|
|
|
|
source /opt/pihole/utils.sh
|
|
|
|
addKey "./testoutput" "KEY_ONE"
|
|
|
|
addKey "./testoutput" "KEY_O"
|
|
|
|
addKey "./testoutput" "KEY_TWO"
|
|
|
|
addKey "./testoutput" "Y_TWO"
|
|
|
|
"""
|
|
|
|
)
|
|
|
|
output = host.run(
|
|
|
|
"""
|
|
|
|
cat ./testoutput
|
|
|
|
"""
|
|
|
|
)
|
|
|
|
expected_stdout = "KEY_ONE\nKEY_O\nKEY_TWO\nY_TWO\n"
|
|
|
|
assert expected_stdout == output.stdout
|
|
|
|
|
|
|
|
|
2022-04-19 19:35:00 +02:00
|
|
|
def test_key_removal_works(host):
|
2022-09-19 14:44:10 +02:00
|
|
|
"""Confirms removeKey removes a key or key/value pair"""
|
|
|
|
host.run(
|
|
|
|
"""
|
2022-03-16 18:42:01 +01:00
|
|
|
source /opt/pihole/utils.sh
|
2022-03-16 21:46:15 +01:00
|
|
|
addOrEditKeyValPair "./testoutput" "KEY_ONE" "value1"
|
|
|
|
addOrEditKeyValPair "./testoutput" "KEY_TWO" "value2"
|
|
|
|
addOrEditKeyValPair "./testoutput" "KEY_THREE" "value3"
|
2022-04-19 19:35:00 +02:00
|
|
|
addKey "./testoutput" "KEY_FOUR"
|
2022-04-04 23:02:26 +02:00
|
|
|
removeKey "./testoutput" "KEY_TWO"
|
2022-04-19 19:35:00 +02:00
|
|
|
removeKey "./testoutput" "KEY_FOUR"
|
2022-09-19 14:44:10 +02:00
|
|
|
"""
|
|
|
|
)
|
|
|
|
output = host.run(
|
|
|
|
"""
|
2022-03-16 18:42:01 +01:00
|
|
|
cat ./testoutput
|
2022-09-19 14:44:10 +02:00
|
|
|
"""
|
|
|
|
)
|
|
|
|
expected_stdout = "KEY_ONE=value1\nKEY_THREE=value3\n"
|
2022-01-31 00:05:28 +01:00
|
|
|
assert expected_stdout == output.stdout
|
2022-02-20 22:24:17 +01:00
|
|
|
|
2022-07-26 19:33:38 +02:00
|
|
|
|
2022-07-26 17:34:42 +02:00
|
|
|
def test_getFTLPID_default(host):
|
2022-09-19 14:44:10 +02:00
|
|
|
"""Confirms getFTLPID returns the default value if FTL is not running"""
|
|
|
|
output = host.run(
|
|
|
|
"""
|
2022-07-26 17:34:42 +02:00
|
|
|
source /opt/pihole/utils.sh
|
|
|
|
getFTLPID
|
2022-09-19 14:44:10 +02:00
|
|
|
"""
|
|
|
|
)
|
|
|
|
expected_stdout = "-1\n"
|
2022-07-26 17:34:42 +02:00
|
|
|
assert expected_stdout == output.stdout
|
|
|
|
|
2022-07-26 19:33:38 +02:00
|
|
|
|
2024-07-27 21:55:18 +02:00
|
|
|
def test_setFTLConfigValue_getFTLConfigValue(host):
|
2023-01-15 00:11:42 +01:00
|
|
|
"""
|
|
|
|
Confirms getFTLConfigValue works (also assumes setFTLConfigValue works)
|
2023-06-02 00:03:22 +02:00
|
|
|
Requires FTL to be installed, so we do that first
|
|
|
|
(taken from test_FTL_development_binary_installed_and_responsive_no_errors)
|
2023-01-15 00:11:42 +01:00
|
|
|
"""
|
|
|
|
host.run(
|
|
|
|
"""
|
|
|
|
source /opt/pihole/basic-install.sh
|
|
|
|
create_pihole_user
|
|
|
|
funcOutput=$(get_binary_name)
|
2023-06-18 19:01:54 +02:00
|
|
|
echo "development-v6" > /etc/pihole/ftlbranch
|
2023-01-15 00:11:42 +01:00
|
|
|
binary="pihole-FTL${funcOutput##*pihole-FTL}"
|
|
|
|
theRest="${funcOutput%pihole-FTL*}"
|
|
|
|
FTLdetect "${binary}" "${theRest}"
|
|
|
|
"""
|
|
|
|
)
|
|
|
|
|
|
|
|
output = host.run(
|
|
|
|
"""
|
|
|
|
source /opt/pihole/utils.sh
|
2023-02-05 22:30:31 +01:00
|
|
|
setFTLConfigValue "dns.upstreams" '["9.9.9.9"]' > /dev/null
|
|
|
|
getFTLConfigValue "dns.upstreams"
|
2023-01-15 00:11:42 +01:00
|
|
|
"""
|
|
|
|
)
|
|
|
|
|
2023-06-01 20:41:54 +02:00
|
|
|
assert "[ 9.9.9.9 ]" in output.stdout
|