- Jellyfin 12 миграцией выключает legacy-авторизацию, и X-Emby-Token получает 401 — пересканирование медиатеки после раскладки перестаёт работать - схема `MediaBrowser Token="…"` принимается и 10.11, так что деплой можно делать до обновления Jellyfin
76 lines
2.1 KiB
Go
76 lines
2.1 KiB
Go
package jellyfin
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
)
|
|
|
|
func TestRefreshLibraries_OK(t *testing.T) {
|
|
var gotPath, gotAuth, gotLegacy, gotMethod string
|
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
gotMethod = r.Method
|
|
gotPath = r.URL.Path
|
|
gotAuth = r.Header.Get("Authorization")
|
|
gotLegacy = r.Header.Get("X-Emby-Token")
|
|
w.WriteHeader(http.StatusNoContent)
|
|
}))
|
|
defer srv.Close()
|
|
|
|
c, err := New(Config{URL: srv.URL, APIKey: "secret"}, nil)
|
|
if err != nil {
|
|
t.Fatalf("New: %v", err)
|
|
}
|
|
if err := c.RefreshLibraries(context.Background()); err != nil {
|
|
t.Fatalf("RefreshLibraries: %v", err)
|
|
}
|
|
if gotMethod != http.MethodPost {
|
|
t.Errorf("method = %q, want POST", gotMethod)
|
|
}
|
|
if gotPath != "/Library/Refresh" {
|
|
t.Errorf("path = %q, want /Library/Refresh", gotPath)
|
|
}
|
|
if want := `MediaBrowser Token="secret"`; gotAuth != want {
|
|
t.Errorf("Authorization = %q, want %q", gotAuth, want)
|
|
}
|
|
if gotLegacy != "" {
|
|
t.Errorf("X-Emby-Token = %q, want пусто (legacy-заголовок выключен в Jellyfin 12)", gotLegacy)
|
|
}
|
|
}
|
|
|
|
func TestRefreshLibraries_TrimsTrailingSlash(t *testing.T) {
|
|
var gotPath string
|
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
gotPath = r.URL.Path
|
|
w.WriteHeader(http.StatusNoContent)
|
|
}))
|
|
defer srv.Close()
|
|
|
|
c, err := New(Config{URL: srv.URL + "/", APIKey: "k"}, nil)
|
|
if err != nil {
|
|
t.Fatalf("New: %v", err)
|
|
}
|
|
if err := c.RefreshLibraries(context.Background()); err != nil {
|
|
t.Fatalf("RefreshLibraries: %v", err)
|
|
}
|
|
if gotPath != "/Library/Refresh" {
|
|
t.Errorf("path = %q, want /Library/Refresh (без двойного слеша)", gotPath)
|
|
}
|
|
}
|
|
|
|
func TestRefreshLibraries_ErrorStatus(t *testing.T) {
|
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
|
w.WriteHeader(http.StatusUnauthorized)
|
|
}))
|
|
defer srv.Close()
|
|
|
|
c, err := New(Config{URL: srv.URL, APIKey: "bad"}, nil)
|
|
if err != nil {
|
|
t.Fatalf("New: %v", err)
|
|
}
|
|
if err := c.RefreshLibraries(context.Background()); err == nil {
|
|
t.Fatal("ожидали ошибку на 401, получили nil")
|
|
}
|
|
}
|