放大图形验证码文字
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user