mirror of
https://github.com/navidrome/navidrome.git
synced 2026-11-12 13:18:40 +01:00
Move the end-to-end call/setup/mint helpers to a suite-level test client and the apiauth login/mustMint helpers to package level. Replace the hardcoded vacuum x-scope enum with a Go test that every known scope is a valid spec Scope; the gate already rejects unknown x-scope values.
39 lines
993 B
Go
39 lines
993 B
Go
package apiv1
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
|
|
"github.com/navidrome/navidrome/conf/configtest"
|
|
. "github.com/onsi/ginkgo/v2"
|
|
. "github.com/onsi/gomega"
|
|
)
|
|
|
|
var _ = Describe("GET /capabilities", func() {
|
|
var ctx context.Context
|
|
var api testClient
|
|
|
|
BeforeEach(func() {
|
|
ctx = GinkgoT().Context()
|
|
DeferCleanup(configtest.SetupConfig())
|
|
resetDB()
|
|
api = testClient{ctx: ctx, router: New(realDS)}
|
|
})
|
|
|
|
It("needs a token", func() {
|
|
w := api.call(http.MethodGet, "/api/v1/capabilities", "", nil)
|
|
Expect(w.Code).To(Equal(http.StatusUnauthorized))
|
|
})
|
|
|
|
It("lists core and password for any valid token, even one with no scopes", func() {
|
|
gc := api.setup()
|
|
at := api.mint(gc.Secret, map[string]any{"scopes": []string{}})
|
|
|
|
w := api.call(http.MethodGet, "/api/v1/capabilities", at.AccessToken, nil)
|
|
Expect(w.Code).To(Equal(http.StatusOK))
|
|
var caps Capabilities
|
|
decodeJSON(w, &caps)
|
|
Expect(caps.Core.Version).To(Equal(1))
|
|
Expect(caps.Password.Version).To(Equal(1))
|
|
})
|
|
})
|