aboutsummaryrefslogtreecommitdiff
path: root/tests/views/test_admin.py
diff options
context:
space:
mode:
authorDennis Fink2026-11-17 14:44:00 +0100
committerDennis Fink2026-11-17 14:44:00 +0100
commit227092b57acc886469e16bcc4c0d3256e86d3d1e (patch)
treec1de8d5f8f3a37562e482f84e8017213c08a05d6 /tests/views/test_admin.py
parentf98b0e446b41325c494bd97900b7bbf730a7d67e (diff)
downloadwebmentions-ssg-227092b57acc886469e16bcc4c0d3256e86d3d1e.tar.gz
webmentions-ssg-227092b57acc886469e16bcc4c0d3256e86d3d1e.zip
feat(receiver): add source domain access rules
Add persistent source block and allow lists with authenticated management, single-row and bulk blocking actions, and optional fail-closed allowlist mode. Reject disallowed sources before enqueueing and recheck policy in verification workers, while sharing canonical hostname normalization across receiver, sender, and configuration paths.
Diffstat (limited to '')
-rw-r--r--tests/views/test_admin.py40
1 files changed, 28 insertions, 12 deletions
diff --git a/tests/views/test_admin.py b/tests/views/test_admin.py
index a475ad5..175bcfd 100644
--- a/tests/views/test_admin.py
+++ b/tests/views/test_admin.py
@@ -795,11 +795,12 @@ def test_received_bulk_toolbar_and_shared_confirmation_modal(
assert 'id="received-select-all"' in html
assert 'id="received-selected-count"' in html
assert 'data-received-bulk-action="reverify"' in html
+ assert 'data-received-bulk-action="block-sources"' in html
assert 'data-received-bulk-action="delete"' in html
assert 'data-title="Delete all declined webmentions?"' in html
assert html.count('id="confirmation-modal"') == 1
assert 'id="confirmation-modal-form"' in html
- assert 'received-bulk-actions.js' in html
+ assert "received-bulk-actions.js" in html
def test_received_delete_all_declined_available_without_matching_rows(
@@ -815,12 +816,18 @@ def test_received_delete_all_declined_available_without_matching_rows(
assert 'data-title="Delete all declined webmentions?"' in html
assert 'id="confirmation-modal-form"' in html
assert 'data-received-bulk-action="delete"' not in html
+ assert 'data-received-bulk-action="block-sources"' not in html
assert 'id="received-select-all"' not in html
@pytest.mark.parametrize(
"path",
- ["/received/bulk/reverify", "/received/bulk/delete", "/received/declined/delete"],
+ [
+ "/received/bulk/reverify",
+ "/received/bulk/block-sources",
+ "/received/bulk/delete",
+ "/received/declined/delete",
+ ],
)
def test_received_bulk_actions_require_login(client: FlaskClient, path: str) -> None:
response = client.post(path)
@@ -831,7 +838,12 @@ def test_received_bulk_actions_require_login(client: FlaskClient, path: str) ->
@pytest.mark.parametrize(
"path",
- ["/received/bulk/reverify", "/received/bulk/delete", "/received/declined/delete"],
+ [
+ "/received/bulk/reverify",
+ "/received/bulk/block-sources",
+ "/received/bulk/delete",
+ "/received/declined/delete",
+ ],
)
def test_received_bulk_actions_reject_invalid_form(
app: Flask,
@@ -854,7 +866,12 @@ def test_received_bulk_actions_reject_invalid_form(
@pytest.mark.parametrize(
"path",
- ["/received/bulk/reverify", "/received/bulk/delete", "/received/declined/delete"],
+ [
+ "/received/bulk/reverify",
+ "/received/bulk/block-sources",
+ "/received/bulk/delete",
+ "/received/declined/delete",
+ ],
)
def test_received_bulk_actions_reject_invalid_filters_before_mutating(
app: Flask,
@@ -881,7 +898,7 @@ def test_received_bulk_actions_reject_invalid_filters_before_mutating(
verify.assert_not_called()
-@pytest.mark.parametrize("action", ["reverify", "delete"])
+@pytest.mark.parametrize("action", ["reverify", "block-sources", "delete"])
@pytest.mark.parametrize("selection", [[], ["bad-uuid"]])
def test_received_bulk_actions_reject_empty_or_malformed_selection(
app: Flask,
@@ -907,7 +924,7 @@ def test_received_bulk_actions_reject_empty_or_malformed_selection(
verify.assert_not_called()
-@pytest.mark.parametrize("action", ["reverify", "delete"])
+@pytest.mark.parametrize("action", ["reverify", "block-sources", "delete"])
def test_received_bulk_actions_reject_duplicate_oversized_or_stale_selection(
app: Flask,
client: FlaskClient,
@@ -932,9 +949,7 @@ def test_received_bulk_actions_reject_duplicate_oversized_or_stale_selection(
assert stale.status_code == HTTPStatus.NOT_FOUND
app.config["RECEIVED_MAX_PAGE_SIZE"] = 1
- oversized = client.post(
- path, data={"webmention_uuids": [str(first), str(second)]}
- )
+ oversized = client.post(path, data={"webmention_uuids": [str(first), str(second)]})
assert oversized.status_code == HTTPStatus.BAD_REQUEST
with app.app_context():
@@ -1022,7 +1037,9 @@ def test_delete_all_declined_received_webmentions_ignores_age_and_filters(
monkeypatch: pytest.MonkeyPatch,
) -> None:
log_in(app, client)
- failed = create_received_webmention(app, status="failed", updated_at=datetime.now(UTC))
+ failed = create_received_webmention(
+ app, status="failed", updated_at=datetime.now(UTC)
+ )
removed = create_received_webmention(
app,
source="https://other.example/post",
@@ -1086,8 +1103,7 @@ def test_received_bulk_delete_requires_real_csrf_token(
html = client.get("/received").get_data(as_text=True)
match = re.search(
- r'<input\b(?=[^>]*name="csrf_token")(?=[^>]*value="([^"]+)")[^>]*>',
- html,
+ r'<input\b(?=[^>]*name="csrf_token")(?=[^>]*value="([^"]+)")[^>]*>', html
)
assert match is not None
valid = client.post(