import at_record_server/discogs_client.{Auth} import at_record_server/discogs_oauth.{TokenPair} import gleam/option.{None, Some} // Golden: the exact header (order, quoting, percent-encoding) is pinned. pub fn auth_header_without_token_test() { let header = discogs_oauth.auth_header( Auth("ckey", "csecret"), None, [#("oauth_callback", "http://localhost:8080/api/discogs/callback")], "nonce123", 1_490_000_000, ) assert header == "OAuth oauth_consumer_key=\"ckey\", oauth_nonce=\"nonce123\", " <> "oauth_callback=\"http%3A%2F%2Flocalhost%3A8080%2Fapi%2Fdiscogs%2Fcallback\", " <> "oauth_signature=\"csecret%26\", oauth_signature_method=\"PLAINTEXT\", " <> "oauth_timestamp=\"1490000000\", oauth_version=\"1.0\"" } pub fn auth_header_with_token_signs_both_secrets_test() { let header = discogs_oauth.auth_header( Auth("ckey", "c&secret"), Some(TokenPair("tok", "t secret")), [], "n", 1, ) assert header == "OAuth oauth_consumer_key=\"ckey\", oauth_nonce=\"n\", " <> "oauth_token=\"tok\", " <> "oauth_signature=\"c%26secret%26t%20secret\", " <> "oauth_signature_method=\"PLAINTEXT\", " <> "oauth_timestamp=\"1\", oauth_version=\"1.0\"" } pub fn parse_token_body_test() { assert discogs_oauth.parse_token_body( "oauth_token=abc&oauth_token_secret=xyz&oauth_callback_confirmed=true", ) == Ok(TokenPair("abc", "xyz")) assert discogs_oauth.parse_token_body("nope=1") == Error("discogs token response missing oauth_token") }