This commit is contained in:
2026-10-04 01:42:30 +07:00
parent 921f419cb3
commit 91d9d370ac
2 changed files with 32 additions and 0 deletions
+1
View File
@@ -168,6 +168,7 @@ func main() {
grpc.UnaryInterceptor(
processor_jwt.NewAuthorizationInterceptor(
map[string]bool{
"/crabs.evening_detective_server.EveningDetectiveServer/GetPermissions": true,
"/crabs.evening_detective_server.EveningDetectiveServer/GetParticipation": true,
"/crabs.evening_detective_server.EveningDetectiveServer/GetTicket": true,
"/crabs.evening_detective_server.EveningDetectiveServer/AnswerParticipation": true,
+31
View File
@@ -0,0 +1,31 @@
package app
import (
"context"
"testing"
"evening_detective_server/internal/modules/processor_jwt"
"evening_detective_server/internal/services/ui_service"
proto "evening_detective_server/proto"
)
func TestGetPermissionsAllowsAnonymousUsers(t *testing.T) {
s := &server{uiService: ui_service.NewUIService()}
rsp, err := s.GetPermissions(context.Background(), &proto.GetPermissionsReq{})
if err != nil {
t.Fatalf("GetPermissions() error = %v", err)
}
if len(rsp.GetPermissions()) != 0 {
t.Fatalf("anonymous permissions = %v, want empty", rsp.GetPermissions())
}
ctx := processor_jwt.ContextWithClaims(context.Background(), &processor_jwt.JWTClaims{Roles: []string{"user"}})
rsp, err = s.GetPermissions(ctx, &proto.GetPermissionsReq{})
if err != nil {
t.Fatalf("GetPermissions() with claims error = %v", err)
}
if len(rsp.GetPermissions()) == 0 {
t.Fatal("authenticated permissions are empty")
}
}