Last.fm API core: signatures, XML/JSON responses and dispatcher
- /2.0/ dispatcher backed by a method registry that declares each method's params and signature/session requirements - api_sig verification per the Last.fm auth spec - XML (default) and Last.fm-style JSON rendering, including error shapes and HTTP statuses per error code - Last.fm request, error and auth-failure metrics with bounded labels Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ae8d3b65db
commit
9af8a4be8b
11 files changed
+585
No files matched your search
@@ -0,0 +1,29 @@
|
||||
import hashlib
|
||||
|
||||
from scrobbler.lastfm.signature import is_valid, sign
|
||||
|
||||
|
||||
def test_signature_sorts_params_and_appends_secret():
|
||||
params = {"token": "tok", "method": "auth.getSession", "api_key": "key"}
|
||||
expected = hashlib.md5(b"api_keykeymethodauth.getSessiontokentokSECRET").hexdigest()
|
||||
assert sign(params, "SECRET") == expected
|
||||
|
||||
|
||||
def test_format_callback_and_api_sig_are_not_signed():
|
||||
base = {"method": "track.scrobble", "api_key": "key"}
|
||||
extra = {**base, "format": "json", "callback": "cb", "api_sig": "whatever"}
|
||||
assert sign(base, "s") == sign(extra, "s")
|
||||
|
||||
|
||||
def test_signature_uses_utf8():
|
||||
params = {"artist": "Sigur Rós", "api_key": "k"}
|
||||
expected = hashlib.md5("api_keykartistSigur RósS".encode()).hexdigest()
|
||||
assert sign(params, "S") == expected
|
||||
|
||||
|
||||
def test_is_valid_accepts_uppercase_hex_and_rejects_missing():
|
||||
params = {"api_key": "k", "method": "m"}
|
||||
sig = sign(params, "s")
|
||||
assert is_valid({**params, "api_sig": sig.upper()}, "s")
|
||||
assert not is_valid(params, "s")
|
||||
assert not is_valid({**params, "api_sig": sig}, "other-secret")
|
||||
Reference in new issue
Block a user