File tree Expand file tree Collapse file tree 2 files changed +28
-1
lines changed
app/artifact-cas/internal/server Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -155,7 +155,9 @@ func requireAuthentication() selector.MatchFunc {
155155// Reflection API is called by clients like grpcurl to list services
156156// and without this selector check it would require authentication
157157func allButReflectionAPI (_ context.Context , callMeta interceptors.CallMeta ) bool {
158- return callMeta .Service != "grpc.reflection.v1alpha.ServerReflection"
158+ const skipRegexp = "(grpc.reflection.*)"
159+ r := regexp .MustCompile (skipRegexp )
160+ return ! r .MatchString (callMeta .Service )
159161}
160162
161163// load key for verification
Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ import (
2626 jwtMiddleware "github.com/go-kratos/kratos/v2/middleware/auth/jwt"
2727 jwt "github.com/golang-jwt/jwt/v4"
2828 "github.com/grpc-ecosystem/go-grpc-middleware/util/metautils"
29+ "github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors"
2930 "github.com/stretchr/testify/assert"
3031
3132 "github.com/stretchr/testify/require"
@@ -156,6 +157,30 @@ func TestRequireAuthentication(t *testing.T) {
156157 }
157158}
158159
160+ func TestAllButReflectionAPI (t * testing.T ) {
161+ testCases := []struct {
162+ callMeta interceptors.CallMeta
163+ expected bool
164+ }{
165+ {
166+ callMeta : interceptors.CallMeta {Service : "grpc.reflection.v1alpha.ServerReflection" },
167+ expected : false ,
168+ },
169+ {
170+ callMeta : interceptors.CallMeta {Service : "grpc.reflection.v1.ServerReflection" },
171+ expected : false ,
172+ },
173+ {
174+ callMeta : interceptors.CallMeta {Service : "grpc.other.service" },
175+ expected : true ,
176+ },
177+ }
178+
179+ for _ , op := range testCases {
180+ assert .Equal (t , allButReflectionAPI (context .TODO (), op .callMeta ), op .expected )
181+ }
182+ }
183+
159184func loadTestPublicKey (path string ) jwt.Keyfunc {
160185 rawKey , _ := os .ReadFile (path )
161186 return func (token * jwt.Token ) (interface {}, error ) {
You can’t perform that action at this time.
0 commit comments