Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fba41f5da7 | ||
|
|
ec7fef42df | ||
|
|
d4869064e6 | ||
|
|
711dd000a5 | ||
|
|
97e30ebf06 | ||
|
|
bde49062b9 | ||
|
|
11d84c91c9 | ||
|
|
e84aecaf35 | ||
|
|
4cd835f708 | ||
|
|
9a4930ff4a | ||
|
|
01dbf55e93 | ||
|
|
ec4ef966bf | ||
|
|
9cbdb38547 | ||
|
|
f5c388beeb | ||
|
|
b80f466f35 | ||
|
|
880143c9b8 | ||
|
|
5ebe160ad0 | ||
|
|
48ca7889e3 | ||
|
|
cb94dd0bb9 | ||
|
|
89afe87b47 | ||
|
|
e91bba759b | ||
|
|
b197fd5977 | ||
|
|
13926f2e9f | ||
|
|
ae16862a11 |
No files matched your search
+52
-124
@@ -6,7 +6,8 @@ on:
|
||||
pull_request:
|
||||
branches: [main]
|
||||
schedule:
|
||||
- cron: "0 6 * * 1"
|
||||
# Saturday 05:00 UTC: 06:00 in Paris in winter, 07:00 in summer (Gitea runs cron in UTC).
|
||||
- cron: "0 5 * * 6"
|
||||
|
||||
jobs:
|
||||
build-and-scan:
|
||||
@@ -18,6 +19,21 @@ jobs:
|
||||
fetch-depth: 0
|
||||
persist-credentials: false
|
||||
|
||||
- name: Get shared actions
|
||||
uses: actions/checkout@v7
|
||||
with:
|
||||
repository: labeex/cicdeex
|
||||
ref: 1.1.0
|
||||
token: ${{ secrets.CICDEEX_TOKEN }}
|
||||
path: .cicdeex
|
||||
persist-credentials: false
|
||||
|
||||
- name: Scan for secrets
|
||||
uses: ./.cicdeex/secret-scan
|
||||
|
||||
- name: Lint Dockerfile with hadolint
|
||||
uses: ./.cicdeex/hadolint
|
||||
|
||||
- name: Build Docker image
|
||||
run: |
|
||||
docker build -t adguard-cidre:ci . 2>&1 | tee build.log
|
||||
@@ -42,7 +58,10 @@ jobs:
|
||||
- name: Run unit tests
|
||||
run: |
|
||||
docker build --target test -t adguard-cidre:test .
|
||||
docker run --rm adguard-cidre:test pytest -v
|
||||
docker run --rm adguard-cidre:test pytest -v --cov=. --cov-report=term-missing --cov-fail-under=75
|
||||
|
||||
- name: Lint with ruff
|
||||
run: docker build --target lint -t adguard-cidre:lint .
|
||||
|
||||
- name: Check deprecation warnings
|
||||
run: |
|
||||
@@ -52,131 +71,40 @@ jobs:
|
||||
fi
|
||||
|
||||
- name: Scan with Trivy (critical - blocking)
|
||||
run: |
|
||||
docker run --rm \
|
||||
-e DOCKER_HOST=tcp://dockerhost:2375 \
|
||||
--add-host=dockerhost:host-gateway \
|
||||
aquasec/trivy:0.74.0 image --exit-code 1 --severity CRITICAL adguard-cidre:ci
|
||||
id: trivy_critical
|
||||
continue-on-error: true
|
||||
uses: ./.cicdeex/trivy
|
||||
with:
|
||||
image: adguard-cidre:ci
|
||||
|
||||
- name: Handle CRITICAL findings
|
||||
if: steps.trivy_critical.outcome == 'failure'
|
||||
uses: ./.cicdeex/remediate
|
||||
with:
|
||||
push-token: ${{ secrets.CI_PUSH_TOKEN }}
|
||||
|
||||
- name: Scan with Trivy (high - informative)
|
||||
run: |
|
||||
docker run --rm \
|
||||
-e DOCKER_HOST=tcp://dockerhost:2375 \
|
||||
--add-host=dockerhost:host-gateway \
|
||||
aquasec/trivy:0.74.0 image --exit-code 0 --severity HIGH adguard-cidre:ci
|
||||
uses: ./.cicdeex/trivy
|
||||
with:
|
||||
image: adguard-cidre:ci
|
||||
severity: HIGH
|
||||
exit-code: "0"
|
||||
|
||||
- name: Publish tagged image
|
||||
id: publish
|
||||
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
||||
run: |
|
||||
BEFORE="${{ github.event.before }}"
|
||||
if [ -n "$BEFORE" ] && [ "$BEFORE" != "0000000000000000000000000000000000000000" ] && git cat-file -e "$BEFORE" 2>/dev/null; then
|
||||
CHANGED=$(git diff --name-only "$BEFORE" "${{ github.sha }}")
|
||||
else
|
||||
CHANGED=$(git diff --name-only HEAD~1 HEAD)
|
||||
fi
|
||||
echo "Changed files:"
|
||||
echo "$CHANGED"
|
||||
uses: ./.cicdeex/publish
|
||||
with:
|
||||
image: adguard-cidre:ci
|
||||
paths: '^(Dockerfile|blocklist_scheduler\.py|VERSION)$'
|
||||
push-token: ${{ secrets.CI_PUSH_TOKEN }}
|
||||
registry-token: ${{ secrets.REGISTRY_TOKEN }}
|
||||
github-mirror: "true"
|
||||
github-token: ${{ secrets.GH_TOKEN }}
|
||||
|
||||
if ! echo "$CHANGED" | grep -qE '^(Dockerfile|blocklist_scheduler\.py|VERSION)$'; then
|
||||
echo "No container-relevant file changed, skipping publish."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if echo "$CHANGED" | grep -qE '^VERSION$'; then
|
||||
echo "VERSION was manually edited in this push, using it as-is."
|
||||
else
|
||||
echo "VERSION untouched but container files changed, auto-bumping the build number (Z)."
|
||||
OLD_VERSION=$(tr -d '[:space:]' < VERSION)
|
||||
IFS='.' read -r MAJOR MINOR PATCH <<< "$OLD_VERSION"
|
||||
NEW_VERSION="${MAJOR}.${MINOR}.$((PATCH + 1))"
|
||||
echo "$NEW_VERSION" > VERSION
|
||||
|
||||
git config user.name "adguard-cidre-ci"
|
||||
git config user.email "[email protected]"
|
||||
git add VERSION
|
||||
git commit -m "Bump build version to $NEW_VERSION [skip ci]"
|
||||
|
||||
# Belt and suspenders: actions/checkout can leave its own ephemeral
|
||||
# credential injected as an extraheader, which would silently override
|
||||
# the URL-embedded token below. persist-credentials:false on checkout
|
||||
# should already prevent this, but strip it here too just in case.
|
||||
git config --unset-all http.https://git.djeex.fr/.extraheader || true
|
||||
|
||||
git push "https://Djeex:${{ secrets.CI_PUSH_TOKEN }}@git.djeex.fr/Djeex/adguard-cidre.git" HEAD:main
|
||||
fi
|
||||
|
||||
VERSION=$(tr -d '[:space:]' < VERSION)
|
||||
IFS='.' read -r MAJOR MINOR PATCH <<< "$VERSION"
|
||||
MINOR_TAG="${MAJOR}.${MINOR}"
|
||||
|
||||
IMAGE=git.djeex.fr/djeex/adguard-cidre
|
||||
echo "${{ secrets.REGISTRY_TOKEN }}" | docker login git.djeex.fr -u Djeex --password-stdin
|
||||
|
||||
# Retag the already-built, already-scanned image — never rebuild for publish,
|
||||
# so what ships is byte-for-byte what Trivy just scanned.
|
||||
docker tag adguard-cidre:ci "$IMAGE:latest"
|
||||
docker tag adguard-cidre:ci "$IMAGE:$MINOR_TAG"
|
||||
docker tag adguard-cidre:ci "$IMAGE:$VERSION"
|
||||
docker push "$IMAGE:latest"
|
||||
docker push "$IMAGE:$MINOR_TAG"
|
||||
docker push "$IMAGE:$VERSION"
|
||||
|
||||
TRIGGER_MSG=$(git log -1 --format=%s "${{ github.sha }}")
|
||||
PR_NUM=$(echo "$TRIGGER_MSG" | grep -oE '#[0-9]+' | head -1 | tr -d '#' || true)
|
||||
|
||||
CATEGORY="🔧 Maintenance"
|
||||
CHANGE_TITLE="$TRIGGER_MSG"
|
||||
|
||||
if [ -n "$PR_NUM" ]; then
|
||||
PR_JSON=$(curl -s -H "Authorization: token ${{ secrets.CI_PUSH_TOKEN }}" \
|
||||
"https://git.djeex.fr/api/v1/repos/Djeex/adguard-cidre/pulls/$PR_NUM")
|
||||
PR_TITLE=$(echo "$PR_JSON" | jq -r '.title // empty' 2>/dev/null || true)
|
||||
LABELS=$(echo "$PR_JSON" | jq -r '.labels[]?.name' 2>/dev/null || true)
|
||||
|
||||
if [ -n "$PR_TITLE" ]; then
|
||||
CHANGE_TITLE="$PR_TITLE"
|
||||
fi
|
||||
|
||||
if echo "$LABELS" | grep -qx 'bug'; then
|
||||
CATEGORY="⚠️ Hotfix"
|
||||
elif echo "$LABELS" | grep -qx 'major'; then
|
||||
CATEGORY="💥 Breaking change"
|
||||
elif echo "$LABELS" | grep -qx 'minor'; then
|
||||
CATEGORY="✨ Update"
|
||||
fi
|
||||
fi
|
||||
|
||||
CHANGED_LIST=$(echo "$CHANGED" | sed 's/^/- /')
|
||||
|
||||
REPO_URL="https://git.djeex.fr/Djeex/adguard-cidre"
|
||||
SHORT_SHA=$(echo "${{ github.sha }}" | cut -c1-7)
|
||||
SOURCE_LINE="[${SHORT_SHA}](${REPO_URL}/commit/${{ github.sha }})"
|
||||
if [ -n "$PR_NUM" ]; then
|
||||
SOURCE_LINE="[#${PR_NUM}](${REPO_URL}/pulls/${PR_NUM}) · ${SOURCE_LINE}"
|
||||
fi
|
||||
|
||||
BODY=$(cat <<EOF
|
||||
## Changelog
|
||||
|
||||
### ${CATEGORY}
|
||||
${CHANGE_TITLE}
|
||||
|
||||
**Source:** ${SOURCE_LINE}
|
||||
**Image:** \`${IMAGE}:${VERSION}\`
|
||||
|
||||
**Changed files:**
|
||||
${CHANGED_LIST}
|
||||
EOF
|
||||
)
|
||||
|
||||
JSON_PAYLOAD=$(jq -n \
|
||||
--arg tag "$VERSION" \
|
||||
--arg name "$VERSION" \
|
||||
--arg body "$BODY" \
|
||||
'{tag_name: $tag, name: $name, target_commitish: "main", body: $body}')
|
||||
|
||||
curl -s -o /dev/null -w "Release API response: %{http_code}\n" -X POST \
|
||||
-H "Authorization: token ${{ secrets.CI_PUSH_TOKEN }}" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "$JSON_PAYLOAD" \
|
||||
"https://git.djeex.fr/api/v1/repos/Djeex/adguard-cidre/releases"
|
||||
- name: Notify failures
|
||||
if: always()
|
||||
uses: ./.cicdeex/notify
|
||||
with:
|
||||
webhook-url: ${{ secrets.DISCORD_WEBHOOK_URL }}
|
||||
status: ${{ job.status }}
|
||||
+8
-2
@@ -1,4 +1,4 @@
|
||||
FROM python:3.14.7-alpine AS base
|
||||
FROM python:3.15.2-alpine@sha256:0f9552bb28711333da16915ec146f5e6bb44a7fdac9ced15dc17c2e0206346dd AS base
|
||||
|
||||
ENV TZ=Europe/Paris
|
||||
|
||||
@@ -15,9 +15,15 @@ COPY blocklist_scheduler.py entrypoint.sh VERSION ./
|
||||
RUN chmod +x entrypoint.sh
|
||||
|
||||
FROM base AS test
|
||||
RUN pip install --no-cache-dir pytest==9.1.1
|
||||
RUN pip install --no-cache-dir pytest==9.1.1 pytest-cov==7.1.0
|
||||
COPY tests/ tests/
|
||||
COPY pytest.ini .
|
||||
|
||||
FROM base AS lint
|
||||
RUN pip install --no-cache-dir ruff==0.16.4
|
||||
COPY ruff.toml .
|
||||
COPY tests/ tests/
|
||||
RUN ruff check . && ruff format --check .
|
||||
|
||||
FROM base
|
||||
ENTRYPOINT ["./entrypoint.sh"]
|
||||
+50
-18
@@ -1,14 +1,15 @@
|
||||
#!/usr/bin/env python3
|
||||
import os
|
||||
import sys
|
||||
import logging
|
||||
import requests
|
||||
import yaml
|
||||
import schedule
|
||||
import time
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
import time
|
||||
from pathlib import Path
|
||||
|
||||
import requests
|
||||
import schedule
|
||||
import yaml
|
||||
|
||||
logging.basicConfig(
|
||||
level=logging.INFO,
|
||||
format="%(asctime)s [%(levelname)s] %(message)s",
|
||||
@@ -19,7 +20,9 @@ ADGUARD_YAML = Path("/adguard/AdGuardHome.yaml")
|
||||
TMP_YAML = ADGUARD_YAML.parent / (ADGUARD_YAML.name + ".tmp")
|
||||
MANUAL_IPS_FILE = Path("/adguard/manually_blocked_ips.conf")
|
||||
CIDR_BASE_URL = "https://raw.githubusercontent.com/vulnebify/cidre/main/output/cidr/ipv4"
|
||||
COUNTRY_LIST_URL = "https://raw.githubusercontent.com/vulnebify/cidre/refs/heads/main/cidre/countries.py"
|
||||
COUNTRY_LIST_URL = (
|
||||
"https://raw.githubusercontent.com/vulnebify/cidre/refs/heads/main/cidre/countries.py"
|
||||
)
|
||||
|
||||
FIRST_BACKUP = ADGUARD_YAML.parent / "AdGuardHome.yaml.first-start.bak"
|
||||
LAST_UPDATE_BACKUP = ADGUARD_YAML.parent / "AdGuardHome.yaml.last-update.bak"
|
||||
@@ -32,6 +35,7 @@ BLOCKLIST_CRON_DAY = os.getenv("BLOCKLIST_CRON_DAY", "mon").lower()
|
||||
ADGUARD_CONTAINER_NAME = os.getenv("ADGUARD_CONTAINER_NAME", "adguardhome")
|
||||
DOCKER_API_URL = os.getenv("DOCKER_API_URL", "http://socket-proxy-adguard:2375")
|
||||
|
||||
|
||||
def backup_first_start():
|
||||
if not FIRST_BACKUP.exists():
|
||||
logging.info(f"Creating first start backup: {FIRST_BACKUP}")
|
||||
@@ -39,10 +43,12 @@ def backup_first_start():
|
||||
else:
|
||||
logging.info("First start backup already exists, skipping.")
|
||||
|
||||
|
||||
def backup_last_update():
|
||||
logging.info(f"Creating last update backup: {LAST_UPDATE_BACKUP}")
|
||||
LAST_UPDATE_BACKUP.write_text(ADGUARD_YAML.read_text())
|
||||
|
||||
|
||||
def fetch_all_country_codes():
|
||||
try:
|
||||
resp = requests.get(COUNTRY_LIST_URL, timeout=15)
|
||||
@@ -53,6 +59,7 @@ def fetch_all_country_codes():
|
||||
logging.error(f"Failed to fetch available country codes: {e}")
|
||||
return set()
|
||||
|
||||
|
||||
def get_selected_countries():
|
||||
if not BLOCK_COUNTRIES:
|
||||
logging.error("BLOCK_COUNTRIES is not set. Skipping update.")
|
||||
@@ -67,7 +74,9 @@ def get_selected_countries():
|
||||
is_inclusion = all(not c.startswith("!") for c in raw_codes)
|
||||
|
||||
if not (is_exclusion or is_inclusion):
|
||||
logging.error("Mixed syntax in BLOCK_COUNTRIES. Use only inclusion (e.g. 'fr,de') or only exclusion (e.g. '!fr,!de').")
|
||||
logging.error(
|
||||
"Mixed syntax in BLOCK_COUNTRIES. Use only inclusion (e.g. 'fr,de') or only exclusion (e.g. '!fr,!de')."
|
||||
)
|
||||
sys.exit(1)
|
||||
|
||||
available = fetch_all_country_codes()
|
||||
@@ -81,6 +90,7 @@ def get_selected_countries():
|
||||
else:
|
||||
return sorted(selected & available)
|
||||
|
||||
|
||||
def download_cidr_lists(countries):
|
||||
combined_ips = []
|
||||
for code in countries:
|
||||
@@ -96,6 +106,7 @@ def download_cidr_lists(countries):
|
||||
logging.warning(f"Failed to download {code}: {e}")
|
||||
return combined_ips
|
||||
|
||||
|
||||
def read_manual_ips():
|
||||
if MANUAL_IPS_FILE.exists():
|
||||
logging.info(f"Reading manual IPs from {MANUAL_IPS_FILE}")
|
||||
@@ -103,7 +114,7 @@ def read_manual_ips():
|
||||
with MANUAL_IPS_FILE.open() as f:
|
||||
for line in f:
|
||||
line = line.strip()
|
||||
if line and (line.count('.') == 3 or '/' in line):
|
||||
if line and (line.count(".") == 3 or "/" in line):
|
||||
valid_ips.append(line)
|
||||
logging.info(f"Added {len(valid_ips)} manual IP entries")
|
||||
return valid_ips
|
||||
@@ -111,6 +122,7 @@ def read_manual_ips():
|
||||
logging.info("Manual IPs file does not exist, skipping.")
|
||||
return []
|
||||
|
||||
|
||||
def update_yaml_with_ips(ips):
|
||||
if not ADGUARD_YAML.exists():
|
||||
logging.error(f"{ADGUARD_YAML} does not exist. Cannot update.")
|
||||
@@ -127,15 +139,16 @@ def update_yaml_with_ips(ips):
|
||||
logging.error("Invalid YAML format.")
|
||||
return False
|
||||
|
||||
data['dns']['disallowed_clients'] = ips
|
||||
data["dns"]["disallowed_clients"] = ips
|
||||
|
||||
with TMP_YAML.open('w') as f:
|
||||
with TMP_YAML.open("w") as f:
|
||||
yaml.safe_dump(data, f)
|
||||
|
||||
TMP_YAML.replace(ADGUARD_YAML)
|
||||
logging.info(f"Updated {ADGUARD_YAML} with new disallowed clients list.")
|
||||
return True
|
||||
|
||||
|
||||
def restart_adguard_container():
|
||||
restart_url = f"{DOCKER_API_URL}/containers/{ADGUARD_CONTAINER_NAME}/restart"
|
||||
logging.info(f"Restarting AdGuard container '{ADGUARD_CONTAINER_NAME}'...")
|
||||
@@ -148,6 +161,7 @@ def restart_adguard_container():
|
||||
except Exception as e:
|
||||
logging.error(f"Error restarting container: {e}")
|
||||
|
||||
|
||||
def update_blocklist():
|
||||
countries = get_selected_countries()
|
||||
if not countries:
|
||||
@@ -164,11 +178,14 @@ def update_blocklist():
|
||||
if success:
|
||||
restart_adguard_container()
|
||||
|
||||
|
||||
def schedule_job():
|
||||
try:
|
||||
hour, minute = [int(x) for x in BLOCKLIST_CRON_TIME.split(":")]
|
||||
except Exception:
|
||||
logging.error(f"Invalid BLOCKLIST_CRON_TIME '{BLOCKLIST_CRON_TIME}', must be HH:MM. Defaulting to 06:00.")
|
||||
logging.error(
|
||||
f"Invalid BLOCKLIST_CRON_TIME '{BLOCKLIST_CRON_TIME}', must be HH:MM. Defaulting to 06:00."
|
||||
)
|
||||
hour, minute = 6, 0
|
||||
|
||||
if BLOCKLIST_CRON_TYPE == "daily":
|
||||
@@ -176,20 +193,34 @@ def schedule_job():
|
||||
logging.info(f"Scheduled daily update at {hour:02d}:{minute:02d}")
|
||||
elif BLOCKLIST_CRON_TYPE == "weekly":
|
||||
day_names = {
|
||||
"mon": "monday", "tue": "tuesday", "wed": "wednesday", "thu": "thursday",
|
||||
"fri": "friday", "sat": "saturday", "sun": "sunday",
|
||||
"mon": "monday",
|
||||
"tue": "tuesday",
|
||||
"wed": "wednesday",
|
||||
"thu": "thursday",
|
||||
"fri": "friday",
|
||||
"sat": "saturday",
|
||||
"sun": "sunday",
|
||||
}
|
||||
day = BLOCKLIST_CRON_DAY[:3]
|
||||
if day not in day_names:
|
||||
logging.error(f"Invalid BLOCKLIST_CRON_DAY '{BLOCKLIST_CRON_DAY}', must be one of {list(day_names)}. Defaulting to Monday.")
|
||||
logging.error(
|
||||
f"Invalid BLOCKLIST_CRON_DAY '{BLOCKLIST_CRON_DAY}', must be one of {list(day_names)}. Defaulting to Monday."
|
||||
)
|
||||
day = "mon"
|
||||
getattr(schedule.every(), day_names[day]).at(f"{hour:02d}:{minute:02d}").do(update_blocklist)
|
||||
logging.info(f"Scheduled weekly update on {day_names[day].capitalize()} at {hour:02d}:{minute:02d}")
|
||||
getattr(schedule.every(), day_names[day]).at(f"{hour:02d}:{minute:02d}").do(
|
||||
update_blocklist
|
||||
)
|
||||
logging.info(
|
||||
f"Scheduled weekly update on {day_names[day].capitalize()} at {hour:02d}:{minute:02d}"
|
||||
)
|
||||
else:
|
||||
logging.error(f"Invalid BLOCKLIST_CRON_TYPE '{BLOCKLIST_CRON_TYPE}', must be 'daily' or 'weekly'. Defaulting to daily.")
|
||||
logging.error(
|
||||
f"Invalid BLOCKLIST_CRON_TYPE '{BLOCKLIST_CRON_TYPE}', must be 'daily' or 'weekly'. Defaulting to daily."
|
||||
)
|
||||
schedule.every().day.at(f"{hour:02d}:{minute:02d}").do(update_blocklist)
|
||||
logging.info(f"Scheduled daily update at {hour:02d}:{minute:02d}")
|
||||
|
||||
|
||||
def main():
|
||||
logging.info("Starting blocklist scheduler...")
|
||||
backup_first_start()
|
||||
@@ -199,5 +230,6 @@ def main():
|
||||
schedule.run_pending()
|
||||
time.sleep(10)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
+1
-27
@@ -1,30 +1,4 @@
|
||||
{
|
||||
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
||||
"extends": ["config:recommended"],
|
||||
"timezone": "Europe/Paris",
|
||||
"labels": ["bot"],
|
||||
"packageRules": [
|
||||
{
|
||||
"matchManagers": ["pip_requirements"],
|
||||
"matchUpdateTypes": ["patch", "minor"],
|
||||
"automerge": true
|
||||
},
|
||||
{
|
||||
"matchManagers": ["dockerfile"],
|
||||
"matchUpdateTypes": ["patch"],
|
||||
"automerge": true
|
||||
},
|
||||
{
|
||||
"matchUpdateTypes": ["major"],
|
||||
"addLabels": ["major"]
|
||||
},
|
||||
{
|
||||
"matchUpdateTypes": ["minor"],
|
||||
"addLabels": ["minor"]
|
||||
}
|
||||
],
|
||||
"vulnerabilityAlerts": {
|
||||
"enabled": true,
|
||||
"addLabels": ["bug"]
|
||||
}
|
||||
"extends": ["local>labeex/renovateex"]
|
||||
}
|
||||
+1
-1
@@ -1,3 +1,3 @@
|
||||
requests==2.34.2
|
||||
pyyaml==6.0.3
|
||||
pyyaml==6.0.4
|
||||
schedule==1.2.2
|
||||
@@ -0,0 +1,10 @@
|
||||
line-length = 100
|
||||
|
||||
[lint]
|
||||
select = ["E", "F", "I", "UP", "B"]
|
||||
ignore = ["E501"]
|
||||
|
||||
[lint.isort]
|
||||
# See nvidia-stock-bot's ruff.toml for why this is pinned explicitly rather
|
||||
# than left to auto-detection.
|
||||
known-first-party = ["blocklist_scheduler"]
|
||||
@@ -56,6 +56,7 @@ def test_backup_first_start_raises_if_adguard_yaml_missing(tmp_path, monkeypatch
|
||||
|
||||
# --- update_yaml_with_ips (pyyaml) ---
|
||||
|
||||
|
||||
def test_update_yaml_with_ips_writes_disallowed_clients(tmp_path, monkeypatch):
|
||||
adguard_yaml = tmp_path / "AdGuardHome.yaml"
|
||||
adguard_yaml.write_text("dns:\n bind_hosts:\n - 0.0.0.0\n")
|
||||
@@ -101,8 +102,11 @@ def test_update_yaml_with_ips_missing_dns_key_raises(tmp_path, monkeypatch):
|
||||
|
||||
# --- fetch_all_country_codes / download_cidr_lists / restart_adguard_container (requests) ---
|
||||
|
||||
|
||||
def test_fetch_all_country_codes_parses_codes(monkeypatch):
|
||||
monkeypatch.setattr(bs.requests, "get", lambda *a, **k: FakeResponse(text='COUNTRIES = ["FR", "DE", "US"]\n'))
|
||||
monkeypatch.setattr(
|
||||
bs.requests, "get", lambda *a, **k: FakeResponse(text='COUNTRIES = ["FR", "DE", "US"]\n')
|
||||
)
|
||||
|
||||
assert bs.fetch_all_country_codes() == {"fr", "de", "us"}
|
||||
|
||||
@@ -136,7 +140,9 @@ def test_restart_adguard_container_success_does_not_raise(monkeypatch):
|
||||
|
||||
|
||||
def test_restart_adguard_container_error_status_does_not_raise(monkeypatch):
|
||||
monkeypatch.setattr(bs.requests, "post", lambda *a, **k: FakeResponse(status_code=500, text="err"))
|
||||
monkeypatch.setattr(
|
||||
bs.requests, "post", lambda *a, **k: FakeResponse(status_code=500, text="err")
|
||||
)
|
||||
|
||||
bs.restart_adguard_container()
|
||||
|
||||
@@ -152,6 +158,7 @@ def test_restart_adguard_container_network_error_does_not_raise(monkeypatch):
|
||||
|
||||
# --- schedule_job (schedule) ---
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def clear_schedule():
|
||||
yield
|
||||
|
||||
Reference in new issue
Block a user