diff --git a/cmd/evening_detective_server/main.go b/cmd/evening_detective_server/main.go index 1c0be88..e4ebd4e 100644 --- a/cmd/evening_detective_server/main.go +++ b/cmd/evening_detective_server/main.go @@ -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, diff --git a/internal/app/users_permissions_test.go b/internal/app/users_permissions_test.go new file mode 100644 index 0000000..af96b55 --- /dev/null +++ b/internal/app/users_permissions_test.go @@ -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") + } +}