fix: adapt to copy-on-write config

This commit is contained in:
Deluan 2026-11-13 11:54:25 -05:00
parent 0e02bced57
commit 7ba2b0e0e6
11 changed files with 21 additions and 27 deletions

View File

@ -3,6 +3,7 @@ package apiauth
import (
"testing"
"github.com/navidrome/navidrome/conf/configtest"
"github.com/navidrome/navidrome/log"
"github.com/navidrome/navidrome/tests"
. "github.com/onsi/ginkgo/v2"
@ -15,3 +16,5 @@ func TestAPIAuth(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "API Auth Suite")
}
var _ = configtest.RestoreAfterEachSpec()

View File

@ -5,7 +5,6 @@ import (
"path/filepath"
"github.com/navidrome/navidrome/conf"
"github.com/navidrome/navidrome/conf/configtest"
"github.com/navidrome/navidrome/db"
"github.com/navidrome/navidrome/model"
"github.com/navidrome/navidrome/model/id"
@ -18,8 +17,9 @@ var realDS model.DataStore
// One database for the whole suite: db.Db() is a process-wide singleton.
var _ = BeforeSuite(func() {
DeferCleanup(configtest.SetupConfig())
conf.Server.DbPath = filepath.Join(GinkgoT().TempDir(), "apiauth.db") + "?_journal_mode=WAL&_foreign_keys=on&_busy_timeout=5000"
conf.Update(func(c *conf.Options) {
c.DbPath = filepath.Join(GinkgoT().TempDir(), "apiauth.db") + "?_journal_mode=WAL&_foreign_keys=on&_busy_timeout=5000"
})
DeferCleanup(db.Init(GinkgoT().Context()))
realDS = persistence.New(db.Db())
})

View File

@ -60,7 +60,7 @@ func New(ds model.DataStore) *Service {
}
func PasswordChangeable(u model.User) bool {
return u.IsAdmin || conf.Server.EnableUserEditing
return u.IsAdmin || conf.Server().EnableUserEditing
}
func (s *Service) Login(ctx context.Context, username, password string, meta ClientMeta, scopes []string) (*Issued, error) {

View File

@ -7,7 +7,6 @@ import (
"time"
"github.com/navidrome/navidrome/conf"
"github.com/navidrome/navidrome/conf/configtest"
"github.com/navidrome/navidrome/core/auth"
"github.com/navidrome/navidrome/model"
"github.com/navidrome/navidrome/model/request"
@ -24,7 +23,6 @@ var _ = Describe("Service", func() {
BeforeEach(func() {
ctx = GinkgoT().Context()
DeferCleanup(configtest.SetupConfig())
now = time.Now().UTC().Truncate(time.Second)
svc = New(realDS)
svc.SetClock(func() time.Time { return now })
@ -331,7 +329,7 @@ var _ = Describe("Service", func() {
})
It("is forbidden for non-admins when user editing is off", func() {
conf.Server.EnableUserEditing = false
conf.Update(func(c *conf.Options) { c.EnableUserEditing = false })
u := createUser(ctx, "pw", false)
_, p := login(ctx, svc, u, "pw", nil)
err := svc.ChangePassword(request.WithUser(ctx, p.User), p, "pw", "pw2", true)
@ -391,10 +389,10 @@ var _ = Describe("Service", func() {
Describe("PasswordChangeable", func() {
It("follows EnableUserEditing for non-admins only", func() {
conf.Server.EnableUserEditing = false
conf.Update(func(c *conf.Options) { c.EnableUserEditing = false })
Expect(PasswordChangeable(model.User{IsAdmin: true})).To(BeTrue())
Expect(PasswordChangeable(model.User{})).To(BeFalse())
conf.Server.EnableUserEditing = true
conf.Update(func(c *conf.Options) { c.EnableUserEditing = true })
Expect(PasswordChangeable(model.User{})).To(BeTrue())
})
})

View File

@ -8,7 +8,6 @@ import (
"time"
"github.com/navidrome/navidrome/conf"
"github.com/navidrome/navidrome/conf/configtest"
"github.com/navidrome/navidrome/core/auth"
"github.com/navidrome/navidrome/db"
"github.com/navidrome/navidrome/model"
@ -22,8 +21,10 @@ var _ = Describe("CreateFirstAdmin", Ordered, func() {
var ds model.DataStore
BeforeAll(func() {
DeferCleanup(configtest.SetupConfig())
conf.Server.DbPath = filepath.Join(GinkgoT().TempDir(), "first-admin.db") + "?_journal_mode=WAL&_foreign_keys=on&_busy_timeout=5000"
DeferCleanup(conf.SnapshotConfig())
conf.Update(func(c *conf.Options) {
c.DbPath = filepath.Join(GinkgoT().TempDir(), "first-admin.db") + "?_journal_mode=WAL&_foreign_keys=on&_busy_timeout=5000"
})
DeferCleanup(db.Init(GinkgoT().Context()))
ds = persistence.New(db.Db())
})

View File

@ -11,7 +11,6 @@ import (
"github.com/Masterminds/squirrel"
"github.com/deluan/rest"
"github.com/navidrome/navidrome/conf"
"github.com/navidrome/navidrome/conf/configtest"
"github.com/navidrome/navidrome/consts"
"github.com/navidrome/navidrome/log"
"github.com/navidrome/navidrome/model"
@ -125,9 +124,8 @@ var _ = Describe("UserRepository", func() {
Describe("initPasswordEncryptionKey", func() {
It("never logs the encryption key checksum, but still logs its property id", func() {
DeferCleanup(configtest.SetupConfig())
conf.Server.PasswordEncryptionKey = "a-new-password-encryption-key"
keySum := fmt.Sprintf("%x", sha256.Sum256(keyTo32Bytes(conf.Server.PasswordEncryptionKey)))
conf.Update(func(c *conf.Options) { c.PasswordEncryptionKey = "a-new-password-encryption-key" })
keySum := fmt.Sprintf("%x", sha256.Sum256(keyTo32Bytes(conf.Server().PasswordEncryptionKey)))
previousKey := encKey
DeferCleanup(func() { encKey = previousKey })
tx, err := GetDBXBuilder().Begin()

View File

@ -9,7 +9,6 @@ import (
"sync"
"github.com/navidrome/navidrome/conf"
"github.com/navidrome/navidrome/conf/configtest"
"github.com/navidrome/navidrome/core/auth"
"github.com/navidrome/navidrome/model"
. "github.com/onsi/ginkgo/v2"
@ -22,8 +21,7 @@ var _ = Describe("auth endpoints", func() {
BeforeEach(func() {
ctx = GinkgoT().Context()
DeferCleanup(configtest.SetupConfig())
conf.Server.AuthRequestLimit = 0
conf.Update(func(c *conf.Options) { c.AuthRequestLimit = 0 })
resetDB()
api = testClient{ctx: ctx, router: New(realDS)}
})

View File

@ -81,8 +81,8 @@ func newGate(doc *openapi3.T, mux chi.Routes, auth authenticator, rules gateRule
if err := rules.check(ids); err != nil {
return nil, err
}
if conf.Server.AuthRequestLimit > 0 {
g.limiter = server.ClientIPRateLimiter(conf.Server.AuthRequestLimit, conf.Server.AuthWindowLength,
if cfg := conf.Server(); cfg.AuthRequestLimit > 0 {
g.limiter = server.ClientIPRateLimiter(cfg.AuthRequestLimit, cfg.AuthWindowLength,
// Counts are per node, so X-RateLimit-Remaining would mislead clients of a scaled-out server.
httprate.WithResponseHeaders(httprate.ResponseHeaders{RetryAfter: "Retry-After"}),
httprate.WithLimitHandler(func(w http.ResponseWriter, r *http.Request) {

View File

@ -12,7 +12,6 @@ import (
"github.com/getkin/kin-openapi/openapi3"
"github.com/go-chi/chi/v5"
"github.com/navidrome/navidrome/conf"
"github.com/navidrome/navidrome/conf/configtest"
"github.com/navidrome/navidrome/core/apiauth"
"github.com/navidrome/navidrome/log"
"github.com/navidrome/navidrome/model"
@ -321,8 +320,7 @@ var _ = Describe("spec gate", func() {
})
It("rate-limits the listed operations with a 429 problem", func() {
DeferCleanup(configtest.SetupConfig())
conf.Server.AuthRequestLimit = 1
conf.Update(func(c *conf.Options) { c.AuthRequestLimit = 1 })
var err error
mux, err = build(gateSpec)
Expect(err).ToNot(HaveOccurred())

View File

@ -8,7 +8,6 @@ import (
"net/http/httptest"
"github.com/navidrome/navidrome/api"
"github.com/navidrome/navidrome/conf/configtest"
"github.com/navidrome/navidrome/consts"
"github.com/navidrome/navidrome/model"
"github.com/navidrome/navidrome/tests"
@ -68,7 +67,6 @@ var _ = Describe("GET /capabilities", func() {
BeforeEach(func() {
ctx = GinkgoT().Context()
DeferCleanup(configtest.SetupConfig())
resetDB()
api = testClient{ctx: ctx, router: New(realDS)}
})

View File

@ -495,7 +495,7 @@ var _ = Describe("middlewares", func() {
var addr, ip string
BeforeEach(func() {
ctx = GinkgoT().Context()
conf.Server.ExtAuth.TrustedSources = "10.0.0.0/8"
conf.Update(func(c *conf.Options) { c.ExtAuth.TrustedSources = "10.0.0.0/8" })
})
call := func(h http.Handler, peer, xff string) {
r := httptest.NewRequestWithContext(ctx, "POST", "/auth/login", nil)