diff --git a/src/Dockerfile b/src/Dockerfile index 81f88d9cf..fdc4b7239 100644 --- a/src/Dockerfile +++ b/src/Dockerfile @@ -65,7 +65,18 @@ RUN cd /etc/.pihole && \ install -T -m 0755 ./advanced/Templates/pihole-FTL-prestart.sh /opt/pihole/pihole-FTL-prestart.sh && \ install -T -m 0755 ./advanced/Templates/pihole-FTL-poststop.sh /opt/pihole/pihole-FTL-poststop.sh && \ addgroup -S pihole && adduser -S pihole -G pihole && \ - echo "${PIHOLE_DOCKER_TAG}" > /pihole.docker.tag + echo "${PIHOLE_DOCKER_TAG}" > /pihole.docker.tag && \ + # sed a new function into the `pihole` script just above the `helpFunc()` function for later use. + sed -i $'s/helpFunc() {/unsupportedFunc() {\\\n echo "Function not supported in Docker images"\\\n exit 0\\\n}\\\n\\\nhelpFunc() {/g' /usr/local/bin/pihole && \ + # Replace a few of the `pihole` options with calls to `unsupportedFunc`: + # pihole -up / pihole updatePihole + sed -i $'s/)\s*updatePiholeFunc/) unsupportedFunc/g' /usr/local/bin/pihole && \ + # pihole uninstall + sed -i $'s/)\s*uninstallFunc/) unsupportedFunc/g' /usr/local/bin/pihole && \ + # pihole -r / pihole reconfigure + sed -i $'s/)\s*reconfigurePiholeFunc/) unsupportedFunc/g' /usr/local/bin/pihole && \ + # pihole checkout + sed -i $'s/)\s*piholeCheckoutFunc/) unsupportedFunc/g' /usr/local/bin/pihole COPY --chmod=0755 bash_functions.sh /usr/bin/bash_functions.sh COPY --chmod=0755 start.sh /usr/bin/start.sh diff --git a/test/tests/test_general.py b/test/tests/test_general.py index a0f539831..36cbee253 100644 --- a/test/tests/test_general.py +++ b/test/tests/test_general.py @@ -28,3 +28,17 @@ def test_pihole_ftl_clean_shutdown(docker): ) assert "INFO: Shutting down... // exit code 0 // jmpret 0" in func.stdout assert "INFO: ########## FTL terminated after" in func.stdout + + +# Ensure the unsupportedFunc monkeypatch is working +@pytest.mark.parametrize("test_args", ['-e "PH_VERBOSE=1"']) +def test_unsupported_monkeypatch(docker): + output = "Function not supported in Docker images" + checkout = docker.run("pihole checkout core dev") + update = docker.run("pihole -up") + uninstall = docker.run("pihole uninstall") + reconfigure = docker.run("pihole reconfigure") + assert output in checkout.stdout + assert output in update.stdout + assert output in uninstall.stdout + assert output in reconfigure.stdout