feat(19-04): user authorizer, user.Deleting and handle backfill

Register lighthouse user:{id} if the namespace is free, fire user.Deleting before unscoped delete, and backfill missing handles.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Jakub Zych
2026-10-17 21:53:21 +02:00
parent 15b19c7021
commit c0770294a5
9 changed files with 190 additions and 5 deletions

View File

@@ -0,0 +1,36 @@
package classes
import (
"context"
"testing"
"git.golem15.com/golem15/summercms/modules/lighthouse"
)
// TestUserAuthorizer: user:9 is allowed only for user 9 (T-19-10).
func TestUserAuthorizer(t *testing.T) {
auth := AuthorizeUser()
ctx := context.Background()
if got := auth.Authorize(ctx, 9, "user:9"); !got.Allowed {
t.Fatalf("user:9 for 9 denied: %s", got.Reason())
}
if got := auth.Authorize(ctx, 9, "presence:user:9"); !got.Allowed {
t.Fatalf("presence:user:9 for 9 denied: %s", got.Reason())
}
if lighthouse.ChannelID("user:9") != 9 {
t.Fatalf("ChannelID(user:9) = %d, want 9", lighthouse.ChannelID("user:9"))
}
for _, channel := range []string{"user:8", "user:9:extra", "chat:9", "user:", "user", "presence:presence:user:9"} {
if got := auth.Authorize(ctx, 9, channel); got.Allowed {
t.Errorf("%q for 9 allowed, want deny", channel)
}
}
if got := auth.Authorize(ctx, 8, "user:9"); got.Allowed {
t.Fatal("user:9 for 8 allowed, want deny")
}
if got := auth.Authorize(ctx, 0, "user:0"); got.Allowed {
t.Fatal("user:0 for 0 allowed, want deny")
}
}