refac: debt on role backend

This commit is contained in:
Florian Sylvain committed 2026-10-26 23:34:35 +01:00
1 parent de142f6c5f
commit a043f7f41a
130 files changed
+3591 -512

No files matched your search

+9 -5
View File
@@ -18,7 +18,7 @@ func roleWithGrant(key string, scope role.Scope) role.Role {
return role.Role{Name: "Probe", Grants: []role.Grant{{Key: key, Scope: scope}}}
}
func TestRoleAllows(t *testing.T) {
func TestRoleGrantSetDecisions(t *testing.T) {
cases := []struct {
key string
scope role.Scope
@@ -35,14 +35,18 @@ func TestRoleAllows(t *testing.T) {
}
for _, c := range cases {
t.Run(string(c.scope)+" "+c.key, func(t *testing.T) {
if got := roleWithGrant(c.key, c.scope).Allows(c.key, c.owned); got != c.allowed {
createdBy := uint32(2)
if c.owned {
createdBy = 1
}
if got := roleWithGrant(c.key, c.scope).GrantSet().Permits(c.key, "", 1, createdBy); got != c.allowed {
t.Errorf("owned=%v: expected %v, got %v", c.owned, c.allowed, got)
}
})
}
t.Run("A key absent from the role is not allowed", func(t *testing.T) {
if (role.Role{}).Allows("content.read", true) {
if (role.Role{}).GrantSet().Permits("content.read", "", 1, 1) {
t.Errorf("expected false")
}
})
@@ -50,7 +54,7 @@ func TestRoleAllows(t *testing.T) {
t.Run("An unknown key is rejected, never silently allowed", func(t *testing.T) {
everything := role.BuiltInRoles()[0]
everything.Grants = append(everything.Grants, role.Grant{Key: "content.explode", Scope: role.ScopeAll})
if everything.Allows("content.explode", true) {
if everything.GrantSet().Permits("content.explode", "", 1, 1) {
t.Errorf("expected false")
}
if _, err := role.Lookup("content.explode"); !errors.Is(err, role.ErrUnknownPermission) {
@@ -388,7 +392,7 @@ func TestNewArticlesRecordTheirCreator(t *testing.T) {
t.Run("New articles record their creator", func(t *testing.T) {
repo := newMockArticleRepo()
uc := useCases.NewCreateArticleUseCase(repo, &fakeBodyRenderer{}, discardRecorder, plainSites(), plainAuthors())
created, err := uc.CreateArticle(testCtx, useCases.CreateArticleCommand{Title: "Valid Title", Body: "x", CreatedBy: 7})
created, err := uc.CreateArticle(testCtx, useCases.CreateArticleCommand{Title: "Valid Title", Body: "x", Caller: ownerCaller(7)})
if err != nil {
t.Fatal(err)
}