55 lines
2.2 KiB
Python
55 lines
2.2 KiB
Python
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
"""Eigenes Logo über die Admin-Einstellungen (CI)."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import io
|
|
from typing import Any
|
|
|
|
import pytest
|
|
|
|
pytest.importorskip("fastapi")
|
|
|
|
from helpers import new_client, token_for
|
|
from PIL import Image
|
|
from test_mail import admin
|
|
|
|
pytestmark = pytest.mark.db
|
|
|
|
|
|
def png() -> bytes:
|
|
buf = io.BytesIO()
|
|
Image.new("RGBA", (300, 100), (31, 95, 174, 255)).save(buf, "PNG")
|
|
return buf.getvalue()
|
|
|
|
|
|
def test_upload_show_and_remove_logo(app: Any) -> None:
|
|
root = admin(app)
|
|
guest = new_client(app)
|
|
assert "img/logo.svg" in guest.get("/login").text
|
|
assert guest.get("/favicon.ico", follow_redirects=False).headers["location"].startswith(
|
|
"/static/img/")
|
|
csrf = token_for(root, "/admin/settings")
|
|
resp = root.post("/admin/settings/logo", data={"csrf_token": csrf},
|
|
files={"logo": ("logo.png", png(), "image/png")})
|
|
assert resp.status_code == 303 and "notice=settings_saved" in resp.headers["location"]
|
|
page = guest.get("/login").text
|
|
assert "/branding/logo.png?v=" in page and "/branding/favicon.png?v=" in page
|
|
logo = guest.get("/branding/logo.png")
|
|
assert logo.status_code == 200 and logo.headers["content-type"] == "image/png"
|
|
assert "immutable" in logo.headers["cache-control"]
|
|
assert guest.get("/favicon.ico", follow_redirects=False).headers["location"].startswith(
|
|
"/branding/favicon.png?v=")
|
|
assert guest.get("/branding/branding.json").status_code == 404
|
|
# SVG wird abgelehnt, das bisherige Logo bleibt
|
|
csrf = token_for(root, "/admin/settings")
|
|
resp = root.post("/admin/settings/logo", data={"csrf_token": csrf},
|
|
files={"logo": ("x.svg", b"<svg xmlns='http://www.w3.org/2000/svg'/>",
|
|
"image/svg+xml")})
|
|
assert "error=logo_invalid" in resp.headers["location"]
|
|
assert "/branding/logo.png?v=" in guest.get("/login").text
|
|
csrf = token_for(root, "/admin/settings")
|
|
root.post("/admin/settings/logo/remove", data={"csrf_token": csrf})
|
|
assert "img/logo.svg" in guest.get("/login").text
|
|
assert guest.get("/branding/logo.png").status_code == 404
|