Files
memby/server/internal/emby/client_auth_header_test.go
T
ponzischeme89andClaude Opus 5 4a4df7a73c App v0.2.26 and gateway 0.1.20
Client: seek controls, Bazarr subtitle download and cast panel in the
player; MDBList ratings strip; episode and schedule detail pages; series
pace estimate; what's new panel; install-permission onboarding step;
synced per-profile preferences; Emby outage banner.

Gateway: rebuilt admin console (one fragment per page), preference
history and restore, merged Continue Watching, Emby health probe,
subtitle selection and Bazarr download, structured request logging with
per-request identity, and embedded build version.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-06 22:33:56 +12:00

49 lines
1.6 KiB
Go

package emby
import (
"context"
"net/http"
"strings"
"testing"
"time"
)
// The authorisation header is what Emby's dashboard shows for a television, and it is the
// one string the gateway sends to a third party — so both halves are pinned: the client
// name is never the product name, and the version is the set's own build rather than a
// constant that made every device look alike.
func TestAuthHeaderCarriesClientVersion(t *testing.T) {
client := New("http://emby:8096", "https://emby.example", "MbyATV", time.Second)
req, err := client.newRequest(
context.Background(), http.MethodGet, "/Items", nil,
Credentials{DeviceID: "tv-1", DeviceName: `Living "room"`, ClientVersion: "0.2.4"}, nil,
)
if err != nil {
t.Fatal(err)
}
got := req.Header.Get("X-Emby-Authorization")
want := `MediaBrowser Client="MbyATV", Device="Living room", DeviceId="tv-1", Version="0.2.4"`
if got != want {
t.Fatalf("auth header =\n %q\nwant\n %q", got, want)
}
}
func TestAuthHeaderFallsBackToGatewayVersion(t *testing.T) {
client := New("http://emby:8096", "https://emby.example", "MbyATV", time.Second)
req, err := client.newRequest(
context.Background(), http.MethodGet, "/Items", nil, Credentials{}, nil,
)
if err != nil {
t.Fatal(err)
}
got := req.Header.Get("X-Emby-Authorization")
if strings.Contains(got, `Version=""`) || strings.Contains(got, `Version="1.0"`) {
t.Fatalf("gateway request reported no usable version: %q", got)
}
if !strings.Contains(got, `Version="`+client.gatewayVersion+`"`) {
t.Fatalf("auth header %q does not carry the gateway build %q", got, client.gatewayVersion)
}
}