feat(allowlist): owner allowlist enforcement

This commit is contained in:
Mathias Bergqvist
2026-05-04 21:26:50 +02:00
parent d564cdcae3
commit 4ebb1eef6d
2 changed files with 41 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
package allowlist
import "fmt"
type Allowlist struct {
owners map[string]struct{}
}
func New(owners []string) *Allowlist {
m := make(map[string]struct{}, len(owners))
for _, o := range owners {
m[o] = struct{}{}
}
return &Allowlist{owners: m}
}
func (a *Allowlist) Check(owner string) error {
if owner == "" {
return fmt.Errorf("owner required")
}
if _, ok := a.owners[owner]; !ok {
return fmt.Errorf("owner %q not in allowlist", owner)
}
return nil
}

View File

@@ -0,0 +1,16 @@
package allowlist_test
import (
"testing"
"gitea.d-ma.be/mathias/gitea-mcp/internal/allowlist"
"github.com/stretchr/testify/assert"
)
func TestAllowlistCheck(t *testing.T) {
a := allowlist.New([]string{"mathias", "acme"})
assert.NoError(t, a.Check("mathias"))
assert.NoError(t, a.Check("acme"))
assert.Error(t, a.Check("evil"))
assert.Error(t, a.Check(""))
}