CI / validate-monitoring (push) Successful in 9s
CI / lint (push) Successful in 13s
CI / federation-interop (push) Successful in 1m7s
CI / test (push) Successful in 3m3s
CI / images (push) Skipped
CI / assets (push) Skipped
CI / python-package (push) Skipped
CI / notify (push) Successful in 5s
now_playing_field() read core's now_playing table unconditionally, so a user who never turned federation's now-playing feature on at all would still leak what they're currently listening to on their public actor document, since core's now_playing table is populated for every user regardless of federation settings. Found while designing step 3 (the periodic push task): querying only sharing users with now_playing_mode != "off" made me notice build_document() itself had no equivalent guard, and the existing tests happened not to catch it (they only combined "nothing playing" with "mode off", and "something playing" with "mode on"). Added the missing combination - something playing, mode off - to both the actors.py unit tests and the web-level actor route test. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MK52BGoJbPhZ1vSFuKcGUW
50 lines
2.0 KiB
Python
50 lines
2.0 KiB
Python
"""Actor document building (actors.py): shared by the live GET /users/<u> route and the
|
|
now-playing Update(Person) push."""
|
|
|
|
from scrobbler.federation import actors, sharing
|
|
from scrobbler.federation.protocol import vocab
|
|
from scrobbler.services.scrobbles import TrackInput, update_now_playing
|
|
|
|
URLS = vocab.actor_urls(
|
|
"https://scrobble.test", "alice", "https://scrobble.test/profile.html?u=alice"
|
|
)
|
|
|
|
|
|
def test_now_playing_field_is_empty_when_nothing_is_playing(fed_ctx, user):
|
|
assert actors.now_playing_field(user) == []
|
|
|
|
|
|
def test_now_playing_field_shows_the_current_track(fed_ctx, user):
|
|
update_now_playing(user, TrackInput(artist="Radiohead", track="Reckoner"))
|
|
assert actors.now_playing_field(user) == [("Now playing", "Reckoner by Radiohead")]
|
|
|
|
|
|
def test_build_document_includes_the_now_playing_field(fed_ctx, user):
|
|
sharing.update(
|
|
user.id,
|
|
{"enabled": True, "display_name": "Alice", "bio": "Hi.", "now_playing_mode": "profile"},
|
|
)
|
|
update_now_playing(user, TrackInput(artist="Radiohead", track="Reckoner"))
|
|
settings = sharing.settings_for(user.id)
|
|
doc = actors.build_document(URLS, user, settings)
|
|
assert doc["attachment"] == [
|
|
{"type": "PropertyValue", "name": "Now playing", "value": "Reckoner by Radiohead"}
|
|
]
|
|
|
|
|
|
def test_build_document_has_no_now_playing_field_when_idle(fed_ctx, user):
|
|
sharing.update(user.id, {"enabled": True, "now_playing_mode": "profile"})
|
|
settings = sharing.settings_for(user.id)
|
|
doc = actors.build_document(URLS, user, settings)
|
|
assert doc["attachment"] == []
|
|
|
|
|
|
def test_build_document_never_shows_now_playing_when_the_mode_is_off(fed_ctx, user):
|
|
"""now_playing_mode defaults to off; core's now_playing table is populated for every
|
|
user regardless, so a user who's never turned this on must never leak it."""
|
|
sharing.update(user.id, {"enabled": True})
|
|
update_now_playing(user, TrackInput(artist="Radiohead", track="Reckoner"))
|
|
settings = sharing.settings_for(user.id)
|
|
doc = actors.build_document(URLS, user, settings)
|
|
assert doc["attachment"] == []
|