mirror of
https://github.com/navidrome/navidrome.git
synced 2026-10-29 22:47:48 +01:00
Hardening pass ahead of real client testing: unmatched routes and unsupported methods now return a logged, JSON 404 instead of chi's default plain-text response, so a missing endpoint a client needs is easy to spot in the logs. Internal errors (ffmpeg output, file paths, etc.) no longer leak into 500 response bodies -- a shared internalError helper logs the real error server-side and always returns a generic message. Inbound Jellyfin ratings are clamped to 0-10 before being halved into Navidrome's 0-5 scale, and /System/Ping now replies with a bare plain-text body as real Jellyfin servers do. Adds a README with an enable/curl walkthrough and known limitations.
40 lines
1.2 KiB
Go
40 lines
1.2 KiB
Go
package jellyfin
|
|
|
|
import (
|
|
"net/http"
|
|
"net/http/httptest"
|
|
|
|
"github.com/navidrome/navidrome/tests"
|
|
. "github.com/onsi/ginkgo/v2"
|
|
. "github.com/onsi/gomega"
|
|
)
|
|
|
|
var _ = Describe("Router", func() {
|
|
It("serves the public handshake through the mounted handler", func() {
|
|
ds := &tests.MockDataStore{}
|
|
api := New(ds, nil, nil, nil, nil, nil, nil)
|
|
w := httptest.NewRecorder()
|
|
r := httptest.NewRequest("GET", "/System/Info/Public", nil)
|
|
api.ServeHTTP(w, r)
|
|
Expect(w.Code).To(Equal(http.StatusOK))
|
|
})
|
|
|
|
It("returns 404 JSON for unknown routes", func() {
|
|
api := New(&tests.MockDataStore{}, nil, nil, nil, nil, nil, nil)
|
|
w := httptest.NewRecorder()
|
|
r := httptest.NewRequest("GET", "/Nonexistent/Route", nil)
|
|
api.ServeHTTP(w, r)
|
|
Expect(w.Code).To(Equal(http.StatusNotFound))
|
|
Expect(w.Header().Get("Content-Type")).To(ContainSubstring("application/json"))
|
|
Expect(w.Body.String()).To(Equal("{}"))
|
|
})
|
|
|
|
It("returns 404 JSON for a known path with an unsupported method", func() {
|
|
api := New(&tests.MockDataStore{}, nil, nil, nil, nil, nil, nil)
|
|
w := httptest.NewRecorder()
|
|
r := httptest.NewRequest("PATCH", "/System/Info/Public", nil)
|
|
api.ServeHTTP(w, r)
|
|
Expect(w.Code).To(Equal(http.StatusNotFound))
|
|
Expect(w.Body.String()).To(Equal("{}"))
|
|
})
|
|
})
|