Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

940 B
Raw Blame
package auth

import (
	"context"
	"sync"
	"testing"
)

func TestRBACAdminIdentityConcurrentUpdates(t *testing.T) {
	manager, err := NewFileManager(t.TempDir())
	if err != nil {
		t.Fatal(err)
	}
	a := NewRBACAuthorizer(manager)
	var wg sync.WaitGroup
	for worker := 0; worker < 4; worker++ {
		wg.Go(func() {
			for i := 0; i < 100; i++ {
				a.SetAdminUser("configured-admin")
				a.Authorize(WithUser(context.Background(), "configured-admin"), ActionAdmin, ResourceUsers)
				if allowed, err := a.Authorize(WithUser(context.Background(), "outsider"), ActionAdmin, ResourceUsers); allowed || err != nil {
					t.Errorf("outsider allowed=%v err=%v", allowed, err)
				}
				a.SetAdminUser("")
			}
		})
	}
	wg.Wait()
	a.SetAdminUser("")
	if allowed, err := a.Authorize(WithUser(context.Background(), "configured-admin"), ActionAdmin, ResourceUsers); allowed || err != nil {
		t.Fatalf("cleared admin allowed=%v err=%v", allowed, err)
	}
}