放大图形验证码文字

This commit is contained in:
Certificate System
2026-08-13 15:46:50 +08:00
parent f72645225a
commit eac19ea593
3 changed files with 51 additions and 9 deletions

View File

@@ -1,4 +1,16 @@
from app.services.captcha import make_captcha, verify_captcha
import base64
import io
from PIL import Image
from app.services.captcha import (
CAPTCHA_FONT_SIZE,
CAPTCHA_HEIGHT,
CAPTCHA_WIDTH,
load_captcha_font,
make_captcha,
verify_captcha,
)
def test_captcha_can_only_be_used_once():
@@ -7,3 +19,12 @@ def test_captcha_can_only_be_used_once():
# The real code is intentionally not exposed. This test locks in one-time consumption behavior.
assert not verify_captcha(captcha_id, "bad")
assert not verify_captcha(captcha_id, "bad")
def test_captcha_uses_large_font_and_expected_image_size():
captcha = make_captcha()
encoded_image = captcha["image"].split(",", 1)[1]
image = Image.open(io.BytesIO(base64.b64decode(encoded_image)))
assert image.size == (CAPTCHA_WIDTH, CAPTCHA_HEIGHT)
assert getattr(load_captcha_font(), "size", CAPTCHA_FONT_SIZE) == CAPTCHA_FONT_SIZE