fbde4d6aca
Provide a zero-dependency Python tool that races multiple public paste providers and documents safe AI-tool usage through a project skill.
43 lines
1.3 KiB
Python
43 lines
1.3 KiB
Python
from __future__ import annotations
|
|
|
|
import pytest
|
|
|
|
from publicpaste.validation import ValidationError, body_contains_text_fragment, validate_url
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
("provider", "url"),
|
|
[
|
|
("paste.rs", "https://paste.rs/abc123"),
|
|
("dpaste.org", "https://dpaste.org/ABC123"),
|
|
("0x0.st", "https://0x0.st/abcd.txt"),
|
|
("snippet.host", "https://snippet.host/abcdef"),
|
|
("paste.centos.org", "https://paste.centos.org/view/12345"),
|
|
("termbin.com", "http://termbin.com/abc"),
|
|
],
|
|
)
|
|
def test_validate_url_accepts_provider_urls(provider: str, url: str) -> None:
|
|
assert validate_url(provider, url) == url
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
("provider", "url"),
|
|
[
|
|
("paste.rs", "ftp://paste.rs/abc"),
|
|
("paste.rs", "https://example.com/abc"),
|
|
("0x0.st", "https://0x0.st/"),
|
|
("dpaste.org", "https://dpaste.org/a b"),
|
|
],
|
|
)
|
|
def test_validate_url_rejects_bad_urls(provider: str, url: str) -> None:
|
|
with pytest.raises(ValidationError):
|
|
validate_url(provider, url)
|
|
|
|
|
|
def test_body_contains_text_fragment_tolerates_html_escape() -> None:
|
|
assert body_contains_text_fragment(b"<pre>hello & goodbye</pre>", "hello & goodbye")
|
|
|
|
|
|
def test_body_contains_text_fragment_rejects_missing_text() -> None:
|
|
assert not body_contains_text_fragment("something else", "hello world")
|