Feat v0.7.7 api tokens ext permissions (#61)
All checks were successful
CI/CD / detect-changes (push) Successful in 4s
CI/CD / e2e-smoke (push) Has been skipped
CI/CD / test-frontend (push) Successful in 6s
CI/CD / test-runners (push) Has been skipped
CI/CD / test-go-pg (push) Successful in 2m48s
CI/CD / test-sqlite (push) Successful in 2m49s
CI/CD / build-and-deploy (push) Successful in 28s
All checks were successful
CI/CD / detect-changes (push) Successful in 4s
CI/CD / e2e-smoke (push) Has been skipped
CI/CD / test-frontend (push) Successful in 6s
CI/CD / test-runners (push) Has been skipped
CI/CD / test-go-pg (push) Successful in 2m48s
CI/CD / test-sqlite (push) Successful in 2m49s
CI/CD / build-and-deploy (push) Successful in 28s
Co-authored-by: Jeffrey Smith <jasafpro@gmail.com> Co-committed-by: Jeffrey Smith <jasafpro@gmail.com>
This commit was merged in pull request #61.
This commit is contained in:
81
server/auth/permissions_test.go
Normal file
81
server/auth/permissions_test.go
Normal file
@@ -0,0 +1,81 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestRegisterExtensionPermissions(t *testing.T) {
|
||||
// Clean state
|
||||
extPermsMu.Lock()
|
||||
extPerms = make(map[string][]string)
|
||||
extPermsMu.Unlock()
|
||||
|
||||
RegisterExtensionPermissions("image-gen", []string{"image-gen.use", "image-gen.admin"})
|
||||
|
||||
all := AllPermissionsWithExtensions()
|
||||
found := 0
|
||||
for _, p := range all {
|
||||
if p == "image-gen.use" || p == "image-gen.admin" {
|
||||
found++
|
||||
}
|
||||
}
|
||||
if found != 2 {
|
||||
t.Errorf("expected 2 extension permissions, found %d in %v", found, all)
|
||||
}
|
||||
|
||||
// Kernel permissions should also be present
|
||||
for _, kp := range KernelPermissions {
|
||||
foundKernel := false
|
||||
for _, p := range all {
|
||||
if p == kp {
|
||||
foundKernel = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !foundKernel {
|
||||
t.Errorf("kernel permission %q missing from AllPermissionsWithExtensions()", kp)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnregisterExtensionPermissions(t *testing.T) {
|
||||
extPermsMu.Lock()
|
||||
extPerms = make(map[string][]string)
|
||||
extPermsMu.Unlock()
|
||||
|
||||
RegisterExtensionPermissions("image-gen", []string{"image-gen.use"})
|
||||
UnregisterExtensionPermissions("image-gen")
|
||||
|
||||
all := AllPermissionsWithExtensions()
|
||||
for _, p := range all {
|
||||
if p == "image-gen.use" {
|
||||
t.Error("unregistered permission should not appear")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestAllPermissionsGrouped(t *testing.T) {
|
||||
extPermsMu.Lock()
|
||||
extPerms = make(map[string][]string)
|
||||
extPermsMu.Unlock()
|
||||
|
||||
RegisterExtensionPermissions("chat", []string{"chat.send", "chat.admin"})
|
||||
RegisterExtensionPermissions("notes", []string{"notes.edit"})
|
||||
|
||||
grouped := AllPermissionsGrouped()
|
||||
|
||||
if len(grouped["kernel"]) != len(KernelPermissions) {
|
||||
t.Errorf("expected %d kernel permissions, got %d", len(KernelPermissions), len(grouped["kernel"]))
|
||||
}
|
||||
if len(grouped["chat"]) != 2 {
|
||||
t.Errorf("expected 2 chat permissions, got %d", len(grouped["chat"]))
|
||||
}
|
||||
if len(grouped["notes"]) != 1 {
|
||||
t.Errorf("expected 1 notes permission, got %d", len(grouped["notes"]))
|
||||
}
|
||||
|
||||
// Clean up
|
||||
extPermsMu.Lock()
|
||||
extPerms = make(map[string][]string)
|
||||
extPermsMu.Unlock()
|
||||
}
|
||||
Reference in New Issue
Block a user