Page the outbox and serve individual posts (phase 3, step 7)
CI / validate-monitoring (push) Successful in 8s
CI / federation-interop (push) Successful in 1m1s
CI / lint (push) Successful in 1m10s
CI / test (push) Successful in 2m47s
CI / images (push) Skipped
CI / assets (push) Skipped
CI / python-package (push) Skipped
CI / notify (push) Successful in 5s
CI / validate-monitoring (push) Successful in 8s
CI / federation-interop (push) Successful in 1m1s
CI / lint (push) Successful in 1m10s
CI / test (push) Successful in 2m47s
CI / images (push) Skipped
CI / assets (push) Skipped
CI / python-package (push) Skipped
CI / notify (push) Successful in 5s
GET /users/<u>/outbox is now a real OrderedCollection pointing at paged OrderedCollectionPages of 20 Creates, newest first - public and unlisted posts only, since it's unauthenticated. Adds publishing.outbox_page() for the query and publishing.find_by_note_id() to look a post up by its Note's id (the two ActivityPub ids a post has - the wrapping Create's and the embedded Note's - were already generated independently in publish(); finding by the Note's id reuses the existing JSONB-path query pattern already established by activities.undo_block(), rather than adding a new column just for this lookup). GET /users/<u>/posts/<uuid> serves that Note for public and unlisted posts; followers-only and deleted posts 404 (they reach followers by delivery instead); a browser without an ActivityPub Accept is redirected to the UI post page unconditionally, before any lookup, matching actor()'s existing reasoning that a 404-vs-302 difference must never be usable to probe which posts exist. Documents both endpoints in federation/openapi.py and regenerates docs/openapi.json (test_every_api_route_is_documented already enforces this on every new federation route, so it can't wait for the docs step at the end of the phase). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MK52BGoJbPhZ1vSFuKcGUW
This commit is contained in:
1 parent
6fd028d108
commit
d4f3607eef
6 files changed
+308
-11
No files matched your search
@@ -3,6 +3,9 @@ from urllib.parse import urlsplit
|
||||
|
||||
import pytest
|
||||
|
||||
from scrobbler.extensions import db
|
||||
from scrobbler.federation import publishing, sharing
|
||||
|
||||
AP = {"Accept": "application/activity+json"}
|
||||
BASE = "https://scrobble.test"
|
||||
|
||||
@@ -79,15 +82,97 @@ def test_browsers_are_sent_to_the_profile_page(fed_client, sharing_user, usernam
|
||||
|
||||
def test_collections(fed_client, sharing_user):
|
||||
outbox = fed_client.get("/users/alice/outbox", headers=AP).get_json()
|
||||
assert (outbox["type"], outbox["totalItems"], outbox["orderedItems"]) == (
|
||||
assert (outbox["type"], outbox["totalItems"], outbox["first"]) == (
|
||||
"OrderedCollection",
|
||||
0,
|
||||
[],
|
||||
f"{BASE}/users/alice/outbox?page=1",
|
||||
)
|
||||
assert "orderedItems" not in outbox # paged: points at the first page instead
|
||||
followers = fed_client.get("/users/alice/followers", headers=AP).get_json()
|
||||
assert followers["totalItems"] == 0 and "orderedItems" not in followers
|
||||
|
||||
|
||||
def test_outbox_paging_lists_public_and_unlisted_but_not_followers_only(
|
||||
fed_client, fed_ctx, sharing_user
|
||||
):
|
||||
sharing.update(sharing_user.id, {"visibility": "public"})
|
||||
publishing.publish(sharing_user.id, "alice", "weekly", "a", text="first", html="<p>first</p>")
|
||||
sharing.update(sharing_user.id, {"visibility": "unlisted"})
|
||||
publishing.publish(sharing_user.id, "alice", "weekly", "b", text="second", html="<p>second</p>")
|
||||
sharing.update(sharing_user.id, {"visibility": "followers"})
|
||||
publishing.publish(sharing_user.id, "alice", "weekly", "c", text="third", html="<p>third</p>")
|
||||
|
||||
root = fed_client.get("/users/alice/outbox", headers=AP).get_json()
|
||||
assert root["totalItems"] == 2 # the followers-only one isn't counted here
|
||||
|
||||
page = fed_client.get("/users/alice/outbox?page=1", headers=AP).get_json()
|
||||
assert page["type"] == "OrderedCollectionPage"
|
||||
assert page["partOf"] == f"{BASE}/users/alice/outbox"
|
||||
# Newest first: "second" (unlisted) was published after "first" (public).
|
||||
assert [item["object"]["content"] for item in page["orderedItems"]] == [
|
||||
"<p>second</p>",
|
||||
"<p>first</p>",
|
||||
]
|
||||
assert "next" not in page
|
||||
assert "prev" not in page
|
||||
|
||||
|
||||
def test_outbox_paging_links(fed_client, fed_ctx, sharing_user, monkeypatch):
|
||||
monkeypatch.setattr(publishing, "OUTBOX_PAGE_SIZE", 1)
|
||||
sharing.update(sharing_user.id, {"visibility": "public"})
|
||||
for key in ("a", "b"):
|
||||
publishing.publish(sharing_user.id, "alice", "weekly", key, text="t", html="<p>t</p>")
|
||||
|
||||
first = fed_client.get("/users/alice/outbox?page=1", headers=AP).get_json()
|
||||
assert len(first["orderedItems"]) == 1
|
||||
assert first["next"] == f"{BASE}/users/alice/outbox?page=2"
|
||||
assert "prev" not in first
|
||||
|
||||
second = fed_client.get("/users/alice/outbox?page=2", headers=AP).get_json()
|
||||
assert len(second["orderedItems"]) == 1
|
||||
assert "next" not in second
|
||||
assert second["prev"] == f"{BASE}/users/alice/outbox?page=1"
|
||||
|
||||
|
||||
def test_outbox_missing_user_is_not_found(fed_client, fed_ctx):
|
||||
assert fed_client.get("/users/nobody/outbox", headers=AP).status_code == 404
|
||||
assert fed_client.get("/users/nobody/outbox?page=1", headers=AP).status_code == 404
|
||||
|
||||
|
||||
def test_post_note_serves_a_public_note(fed_client, fed_ctx, sharing_user):
|
||||
sharing.update(sharing_user.id, {"visibility": "public"})
|
||||
post = publishing.publish(sharing_user.id, "alice", "weekly", "a", text="t", html="<p>t</p>")
|
||||
|
||||
note_uuid = post.activity.document["object"]["id"].rsplit("/", 1)[-1]
|
||||
response = fed_client.get(f"/users/alice/posts/{note_uuid}", headers=AP)
|
||||
assert response.status_code == 200
|
||||
doc = response.get_json()
|
||||
assert (doc["type"], doc["content"]) == ("Note", "<p>t</p>")
|
||||
|
||||
|
||||
def test_post_note_404s_for_followers_only_deleted_or_unknown(fed_client, fed_ctx, sharing_user):
|
||||
post = publishing.publish(sharing_user.id, "alice", "weekly", "a", text="t", html="<p>t</p>")
|
||||
note_uuid = post.activity.document["object"]["id"].rsplit("/", 1)[-1]
|
||||
# followers-only (the default): not listed to an unauthenticated fetch
|
||||
assert fed_client.get(f"/users/alice/posts/{note_uuid}", headers=AP).status_code == 404
|
||||
|
||||
sharing.update(post.user_id, {"visibility": "public"})
|
||||
publishing.delete_post(post.user_id, "alice", post)
|
||||
db.session.commit()
|
||||
assert fed_client.get(f"/users/alice/posts/{note_uuid}", headers=AP).status_code == 404
|
||||
|
||||
assert fed_client.get("/users/alice/posts/not-a-real-uuid", headers=AP).status_code == 404
|
||||
assert fed_client.get("/users/nobody/posts/not-a-real-uuid", headers=AP).status_code == 404
|
||||
|
||||
|
||||
def test_post_note_browser_is_redirected_to_the_ui_page(fed_client, fed_ctx, sharing_user):
|
||||
post = publishing.publish(sharing_user.id, "alice", "weekly", "a", text="t", html="<p>t</p>")
|
||||
note_uuid = post.activity.document["object"]["id"].rsplit("/", 1)[-1]
|
||||
response = fed_client.get(f"/users/alice/posts/{note_uuid}", headers={"Accept": "text/html"})
|
||||
assert response.status_code == 302
|
||||
assert response.headers["Location"] == f"http://localhost:8080/post.html?id={note_uuid}"
|
||||
|
||||
|
||||
def test_nodeinfo(fed_client, sharing_user):
|
||||
link = fed_client.get("/.well-known/nodeinfo").get_json()["links"][0]
|
||||
assert link["href"] == f"{BASE}/nodeinfo/2.1"
|
||||
|
||||
Reference in new issue
Block a user