mirror of
https://github.com/mudler/LocalAI.git
synced 2026-04-01 13:42:20 -04:00
* feat(ui): add users and authentication support Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * feat: allow the admin user to impersonificate users Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * chore: ui improvements, disable 'Users' button in navbar when no auth is configured Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * feat: add OIDC support Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * fix: gate models Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * chore: cache requests to optimize speed Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * small UI enhancements Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * chore(ui): style improvements Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * fix: cover other paths by auth Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * chore: separate local auth, refactor Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * security hardening, approval mode Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * fix: fix tests and expectations Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * chore: update localagi/localrecall Signed-off-by: Ettore Di Giacinto <mudler@localai.io> --------- Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
54 lines
1.6 KiB
Go
54 lines
1.6 KiB
Go
//go:build auth
|
|
|
|
package auth_test
|
|
|
|
import (
|
|
"github.com/mudler/LocalAI/core/http/auth"
|
|
. "github.com/onsi/ginkgo/v2"
|
|
. "github.com/onsi/gomega"
|
|
)
|
|
|
|
var _ = Describe("InitDB", func() {
|
|
Context("SQLite", func() {
|
|
It("creates all tables with in-memory SQLite", func() {
|
|
db, err := auth.InitDB(":memory:")
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(db).ToNot(BeNil())
|
|
|
|
// Verify tables exist
|
|
Expect(db.Migrator().HasTable(&auth.User{})).To(BeTrue())
|
|
Expect(db.Migrator().HasTable(&auth.Session{})).To(BeTrue())
|
|
Expect(db.Migrator().HasTable(&auth.UserAPIKey{})).To(BeTrue())
|
|
})
|
|
|
|
It("is idempotent - running twice does not error", func() {
|
|
db, err := auth.InitDB(":memory:")
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
// Re-migrate on same DB should succeed
|
|
err = db.AutoMigrate(&auth.User{}, &auth.Session{}, &auth.UserAPIKey{})
|
|
Expect(err).ToNot(HaveOccurred())
|
|
})
|
|
|
|
It("creates composite index on users(provider, subject)", func() {
|
|
db, err := auth.InitDB(":memory:")
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
// Insert a user to verify the index doesn't prevent normal operations
|
|
user := &auth.User{
|
|
ID: "test-1",
|
|
Provider: auth.ProviderGitHub,
|
|
Subject: "12345",
|
|
Role: "admin",
|
|
Status: auth.StatusActive,
|
|
}
|
|
Expect(db.Create(user).Error).ToNot(HaveOccurred())
|
|
|
|
// Query using the indexed columns should work
|
|
var found auth.User
|
|
Expect(db.Where("provider = ? AND subject = ?", auth.ProviderGitHub, "12345").First(&found).Error).ToNot(HaveOccurred())
|
|
Expect(found.ID).To(Equal("test-1"))
|
|
})
|
|
})
|
|
})
|