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") } }