6ede33ccdb
Build and Push Docker Images / create_manifest (web, surfsense-web, , cpu) (push) Has been cancelled
Build and Push Docker Images / finalize_release (push) Has been cancelled
Obsidian Plugin Lint / lint (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_web, cpu, ./surfsense_web/Dockerfile, web, surfsense-web, ubuntu-24.04-arm, linux/arm64, arm64, , runner, false, cpu) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_web, cpu, ./surfsense_web/Dockerfile, web, surfsense-web, ubuntu-latest, linux/amd64, amd64, , runner, false, cpu) (push) Has been cancelled
Build and Push Docker Images / compute_version (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cpu, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-24.04-arm, linux/arm64, arm64, , production, false, cpu) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cpu, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-latest, linux/amd64, amd64, , production, false, cpu) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cu126, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-24.04-arm, linux/arm64, arm64, -cuda126, production, true, cuda126) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cu126, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-latest, linux/amd64, amd64, -cuda126, production, true, cuda126) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cu128, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-24.04-arm, linux/arm64, arm64, -cuda, production, true, cuda) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cu128, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-latest, linux/amd64, amd64, -cuda, production, true, cuda) (push) Has been cancelled
Build and Push Docker Images / verify_digests (push) Has been cancelled
Build and Push Docker Images / create_manifest (backend, surfsense-backend, , cpu) (push) Has been cancelled
Build and Push Docker Images / create_manifest (backend, surfsense-backend, -cuda, cuda) (push) Has been cancelled
Build and Push Docker Images / create_manifest (backend, surfsense-backend, -cuda126, cuda126) (push) Has been cancelled
48 lines
1.9 KiB
Python
48 lines
1.9 KiB
Python
"""Unit tests for the generic captcha config gate (Phase 3d, Apache-2 layer)."""
|
|
|
|
import pytest
|
|
|
|
from app.config import config
|
|
from app.utils.captcha import captcha_enabled, get_captcha_config
|
|
|
|
pytestmark = pytest.mark.unit
|
|
|
|
|
|
class TestCaptchaEnabled:
|
|
def test_off_by_default(self, monkeypatch):
|
|
monkeypatch.setattr(config, "CAPTCHA_SOLVING_ENABLED", False)
|
|
monkeypatch.setattr(config, "CAPTCHA_SOLVER_API_KEY", "key")
|
|
assert captcha_enabled() is False
|
|
|
|
def test_flag_on_but_no_key_is_disabled(self, monkeypatch):
|
|
monkeypatch.setattr(config, "CAPTCHA_SOLVING_ENABLED", True)
|
|
monkeypatch.setattr(config, "CAPTCHA_SOLVER_API_KEY", None)
|
|
assert captcha_enabled() is False
|
|
|
|
def test_flag_on_with_key_is_enabled(self, monkeypatch):
|
|
monkeypatch.setattr(config, "CAPTCHA_SOLVING_ENABLED", True)
|
|
monkeypatch.setattr(config, "CAPTCHA_SOLVER_API_KEY", "key")
|
|
assert captcha_enabled() is True
|
|
|
|
|
|
class TestGetCaptchaConfig:
|
|
def test_snapshot_reflects_config(self, monkeypatch):
|
|
monkeypatch.setattr(config, "CAPTCHA_SOLVING_ENABLED", True)
|
|
monkeypatch.setattr(config, "CAPTCHA_SOLVER_API_KEY", "key")
|
|
monkeypatch.setattr(config, "CAPTCHA_SOLVER_PROVIDER", "2captcha")
|
|
monkeypatch.setattr(config, "CAPTCHA_MAX_ATTEMPTS_PER_URL", 3)
|
|
monkeypatch.setattr(config, "CAPTCHA_SOLVE_TIMEOUT_S", 90)
|
|
monkeypatch.setattr(config, "CAPTCHA_TYPE_DEFAULT", "hcaptcha")
|
|
|
|
cfg = get_captcha_config()
|
|
assert cfg.enabled is True
|
|
assert cfg.solving_site == "2captcha"
|
|
assert cfg.max_attempts_per_url == 3
|
|
assert cfg.timeout_s == 90
|
|
assert cfg.captcha_type_default == "hcaptcha"
|
|
|
|
def test_keyless_config_is_not_enabled(self, monkeypatch):
|
|
monkeypatch.setattr(config, "CAPTCHA_SOLVING_ENABLED", True)
|
|
monkeypatch.setattr(config, "CAPTCHA_SOLVER_API_KEY", None)
|
|
assert get_captcha_config().enabled is False
|