Skip to content

Commit

Permalink
Merge pull request #1544 from pi-hole/dev
Browse files Browse the repository at this point in the history
Dev -> master
  • Loading branch information
PromoFaux authored Feb 26, 2024
2 parents b9ca401 + b967610 commit 91ff566
Show file tree
Hide file tree
Showing 9 changed files with 496 additions and 111 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/housekeeping.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
password: ${{ secrets.PAT_TOKEN }}
-
name: Delete all containers from repository without tags
uses: Chizkiyahu/delete-untagged-ghcr-action@v2
uses: Chizkiyahu/delete-untagged-ghcr-action@v3
with:
token: ${{ secrets.PAT_TOKEN }}
repository_owner: ${{ github.repository_owner }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/stale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
issues: write

steps:
- uses: actions/stale@v8.0.0
- uses: actions/stale@v9.0.0
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
days-before-stale: 30
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/stale_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
pull-requests: write

steps:
- uses: actions/stale@v8.0.0
- uses: actions/stale@v9.0.0
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
# Do not automatically mark PR/issue as stale
Expand Down
21 changes: 9 additions & 12 deletions src/s6/debian-root/usr/local/bin/bash_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -416,19 +416,16 @@ setup_web_port() {
}

setup_web_theme(){
# Parse the WEBTHEME variable, if it exists, and set the selected theme if it is one of the supported values.
# If an invalid theme name was supplied, setup WEBTHEME to use the default-light theme.
# Parse the WEBTHEME variable, if it exists, and set the selected theme if it is one of the supported values (i.e. it is one of the existing theme
# file names and passes a regexp sanity check). If an invalid theme name was supplied, setup WEBTHEME to use the default-light theme.
if [ -n "${WEBTHEME}" ]; then
case "${WEBTHEME}" in
"default-dark" | "default-darker" | "default-light" | "default-auto" | "high-contrast" | "high-contrast-dark" | "lcars")
echo " [i] Setting Web Theme based on WEBTHEME variable, using value ${WEBTHEME}"
change_setting "WEBTHEME" "${WEBTHEME}"
;;
*)
echo " [!] Invalid theme name supplied: ${WEBTHEME}, falling back to default-light."
change_setting "WEBTHEME" "default-light"
;;
esac
if grep -qf <(find /var/www/html/admin/style/themes/ -type f -printf '%f\n' | sed -ne 's/^\([a-zA-Z0-9_-]\+\)\.css$/\1/gp') -xF - <<< "${WEBTHEME}"; then
echo " [i] Setting Web Theme based on WEBTHEME variable, using value ${WEBTHEME}"
change_setting "WEBTHEME" "${WEBTHEME}"
else
echo " [!] Invalid theme name supplied: ${WEBTHEME}, falling back to default-light."
change_setting "WEBTHEME" "default-light"
fi
fi
}

Expand Down
12 changes: 5 additions & 7 deletions test/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
FROM python:3.10-slim-bullseye

FROM debian:bookworm-slim
# Only works for docker CLIENT (bind mounted socket)
COPY --from=docker:20.10.17 /usr/local/bin/docker /usr/local/bin/

ARG packages
RUN apt-get update && \
apt-get install -y python3-dev curl gcc make \
apt-get --no-install-recommends install -y python3 python3-pip python3-dev pipenv curl gcc make \
libffi-dev libssl-dev ${packages} \
&& rm -rf /var/lib/apt/lists/* \
&& pip3 install --no-cache-dir -U pip pipenv
&& rm -rf /var/lib/apt/lists/*

RUN curl --proto "=https" -L https://github.com/docker/compose/releases/download/2.10.2/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose && \
chmod +x /usr/local/bin/docker-compose
Expand All @@ -17,8 +15,8 @@ COPY ./cmd.sh /usr/local/bin/
COPY Pipfile* /root/
WORKDIR /root

RUN pipenv install --system \
&& sed -i 's|/bin/sh|/bin/bash|g' /usr/local/lib/python3.10/site-packages/testinfra/backend/docker.py
RUN pipenv -v install --system \
&& sed -i 's|/bin/sh|/bin/bash|g' /usr/local/lib/python3.11/dist-packages/testinfra/backend/docker.py

RUN echo "set -ex && cmd.sh && \$@" > /usr/local/bin/entrypoint.sh
RUN chmod +x /usr/local/bin/entrypoint.sh
Expand Down
8 changes: 4 additions & 4 deletions test/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ verify_ssl = true
[dev-packages]

[packages]
pytest = "==7.1.3"
pytest-xdist = "==2.5.0"
pytest-testinfra = "==6.8.0"
black = "==22.8.0"
pytest = "==8.0.0"
pytest-xdist = "==3.5.0"
pytest-testinfra = "==10.0.0"
black = "==24.1.1"

[requires]
python_version = "3"
513 changes: 429 additions & 84 deletions test/Pipfile.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/cmd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ docker build ./src --tag pihole:${GIT_TAG} --no-cache
docker images pihole:${GIT_TAG}

# auto-format the pytest code
python -m black ./test/tests/
python3 -m black ./test/tests/

# TODO: Add junitxml output and have something consume it
# 2 parallel max b/c race condition with docker fixture (I think?)
Expand Down
45 changes: 45 additions & 0 deletions test/tests/test_bash_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,3 +288,48 @@ def test_setup_lighttpd_bind(
assert "server.bind" not in config.stdout
else:
assert f'server.bind = "{expected_bind}"' in config.stdout

@pytest.fixture(autouse=True)
def run_around_test_setup_web_theme(docker):
"""Fixture to execute around test_setup_web_theme"""
docker.run("touch /var/www/html/admin/style/themes/{badtheme,bad.theme.css,goodtheme.css}")

yield

docker.run("rm /var/www/html/admin/style/themes/{badtheme,bad.theme.css,goodtheme.css}")

@pytest.mark.parametrize(
"args_env,test_theme,expected_success",
[
("-e WEBTHEME=asd", "asd", False),
("-e WEBTHEME=default-light", "default-light", True),
#("-e WEBTHEME=", "", False), # the tested function does nothing in this case
("-e WEBTHEME=default-dark", "default-dark", True),
("-e WEBTHEME=efault-dark", "efault-dark", False),
("-e WEBTHEME=efault-dar", "efault-dar", False),
("-e WEBTHEME=default-dar", "default-dar", False),
("-e WEBTHEME=xdefault-dark", "xdefault-dark", False),
("-e WEBTHEME=xdefault-darkx", "xdefault-darkx", False),
("-e WEBTHEME=default-darkx", "default-darkx", False),
("-e WEBTHEME=badtheme", "badtheme", False), # the theme file does not have the right extension
("-e WEBTHEME=badtheme.css", "badtheme.css", False), # hacking attempt ?
("-e WEBTHEME=bad.theme", "bad.theme", False), # invalid name - has dot
("-e WEBTHEME=goodtheme", "goodtheme", True),
("-e WEBTHEME=goodtheme.css", "goodtheme.css", False), # hacking attempt ?
("-e WEBTHEME=+", "+", False),
("-e WEBTHEME=.", ".", False),
],
)
def test_setup_web_theme(
docker, args_env, test_theme, expected_success
):
"""Web theme name validation works"""
DEFAULT_THEME = "default-light"
function = docker.run(". /usr/local/bin/bash_functions.sh ; setup_web_theme")

if expected_success:
assert f' [i] setting web theme based on webtheme variable, using value {test_theme}' in function.stdout.lower()
assert docker.run(_grep(f'^WEBTHEME={test_theme}$', SETUPVARS_LOC)).rc == 0
else:
assert f' [!] invalid theme name supplied: {test_theme}, falling back to {DEFAULT_THEME}.' in function.stdout.lower()
assert docker.run(_grep(f'^WEBTHEME={DEFAULT_THEME}$', SETUPVARS_LOC)).rc == 0

0 comments on commit 91ff566

Please sign in to comment.