mirror of
https://github.com/navidrome/navidrome.git
synced 2026-02-14 17:01:17 -05:00
* test(e2e): add comprehensive tests for Subsonic API endpoints Signed-off-by: Deluan <deluan@navidrome.org> * fix(e2e): improve database handling and snapshot restoration in tests Signed-off-by: Deluan <deluan@navidrome.org> * test(e2e): add tests for album sharing and user isolation scenarios Signed-off-by: Deluan <deluan@navidrome.org> * test(e2e): add tests for multi-library support and user access control Signed-off-by: Deluan <deluan@navidrome.org> * test(e2e): tests are fast, no need to skip on -short Signed-off-by: Deluan <deluan@navidrome.org> * address gemini comments Signed-off-by: Deluan <deluan@navidrome.org> * fix(tests): prevent MockDataStore from caching repos with stale context When RealDS is set, MockDataStore previously cached repository instances on first access, binding them to the initial caller's context. This meant repos created with an admin context would skip library filtering for all subsequent non-admin calls, silently masking access control bugs. Changed MockDataStore to delegate to RealDS on every call without caching, so each caller gets a fresh repo with the correct context. Removed the pre-warm calls in e2e setupTestDB that were working around the old caching behavior. * test(e2e): route subsonic tests through full HTTP middleware stack Replace direct router method calls with full HTTP round-trips via router.ServeHTTP(w, r) across all 15 e2e test files. Tests now exercise the complete chi middleware chain including postFormToQueryParams, checkRequiredParameters, authenticate, UpdateLastAccessMiddleware, getPlayer, and sendResponse/sendError serialization. New helpers (doReq, doReqWithUser, doRawReq, buildReq, parseJSONResponse) use plaintext password auth and JSON response format. Old helpers that injected context directly (newReq, newReqWithUser, newRawReq) are removed. Sharing tests now set conf.Server.EnableSharing before router creation to ensure sharing routes are registered. --------- Signed-off-by: Deluan <deluan@navidrome.org>
50 lines
1.4 KiB
Go
50 lines
1.4 KiB
Go
package e2e
|
|
|
|
import (
|
|
"github.com/navidrome/navidrome/server/subsonic/responses"
|
|
. "github.com/onsi/ginkgo/v2"
|
|
. "github.com/onsi/gomega"
|
|
)
|
|
|
|
var _ = Describe("User Endpoints", func() {
|
|
BeforeEach(func() {
|
|
setupTestDB()
|
|
})
|
|
|
|
It("getUser returns current user info", func() {
|
|
resp := doReq("getUser", "username", adminUser.UserName)
|
|
|
|
Expect(resp.Status).To(Equal(responses.StatusOK))
|
|
Expect(resp.User).ToNot(BeNil())
|
|
Expect(resp.User.Username).To(Equal(adminUser.UserName))
|
|
Expect(resp.User.AdminRole).To(BeTrue())
|
|
Expect(resp.User.StreamRole).To(BeTrue())
|
|
Expect(resp.User.Folder).ToNot(BeEmpty())
|
|
})
|
|
|
|
It("getUser with matching username case-insensitive succeeds", func() {
|
|
resp := doReq("getUser", "username", "Admin")
|
|
|
|
Expect(resp.Status).To(Equal(responses.StatusOK))
|
|
Expect(resp.User).ToNot(BeNil())
|
|
Expect(resp.User.Username).To(Equal(adminUser.UserName))
|
|
})
|
|
|
|
It("getUser with different username returns authorization error", func() {
|
|
resp := doReq("getUser", "username", "otheruser")
|
|
|
|
Expect(resp.Status).To(Equal(responses.StatusFailed))
|
|
Expect(resp.Error).ToNot(BeNil())
|
|
})
|
|
|
|
It("getUsers returns list with current user only", func() {
|
|
resp := doReq("getUsers")
|
|
|
|
Expect(resp.Status).To(Equal(responses.StatusOK))
|
|
Expect(resp.Users).ToNot(BeNil())
|
|
Expect(resp.Users.User).To(HaveLen(1))
|
|
Expect(resp.Users.User[0].Username).To(Equal(adminUser.UserName))
|
|
Expect(resp.Users.User[0].AdminRole).To(BeTrue())
|
|
})
|
|
})
|