"""HTML mail: formatting stays, everything active or loading from outside is removed.""" from __future__ import annotations from app.mailpack import sanitize_html def test_formatting_stays_and_active_content_goes(): cleaned = sanitize_html( '
Hallo' '
x

' '
' ) assert 'style="color: #333; font-size: 14px"' in cleaned assert '' in cleaned assert 'bgcolor="#eee"' in cleaned and "
" in cleaned for forbidden in ("onclick", "script", "iframe", "Text

' ) assert "url" not in cleaned and "position" not in cleaned and "expression" not in cleaned and "behavior" not in cleaned assert "color: red" in cleaned and "margin: 4px" in cleaned def test_links_and_images_are_limited(): cleaned = sanitize_html( 'abc' 'logo' ) assert "javascript" not in cleaned and "data:text" not in cleaned and "track" not in cleaned and "svg" not in cleaned assert 'href="https://ok.example/x"' in cleaned assert 'rel="noreferrer noopener"' in cleaned and 'target="_blank"' in cleaned assert 'src="data:image/png;base64,AAAA"' in cleaned