This is an automated email from the ASF dual-hosted git repository.

tianxiaoliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-service-center.git


The following commit(s) were added to refs/heads/master by this push:
     new 635d3c5  SCB-2176 Fix: wildcard bug and service not found in resource 
parser (#1015)
635d3c5 is described below

commit 635d3c5aed5ae2ad59f35a00eb6c6318192ce6a4
Author: little-cui <[email protected]>
AuthorDate: Wed May 26 22:16:05 2021 +0800

    SCB-2176 Fix: wildcard bug and service not found in resource parser (#1015)
---
 pkg/util/wildcard.go                  | 2 +-
 pkg/util/wildcard_test.go             | 2 ++
 server/bootstrap/bootstrap.go         | 2 +-
 server/plugin/auth/buildin/buildin.go | 3 +++
 4 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/pkg/util/wildcard.go b/pkg/util/wildcard.go
index 9983d09..b16ff6f 100644
--- a/pkg/util/wildcard.go
+++ b/pkg/util/wildcard.go
@@ -23,7 +23,7 @@ import (
 )
 
 func WildcardMatch(pattern, dist string) bool {
-       regx := strings.ReplaceAll(regexp.QuoteMeta(pattern), "\\*", ".*")
+       regx := "^" + strings.ReplaceAll(regexp.QuoteMeta(pattern), "\\*", 
".*") + "$"
        matched, _ := regexp.MatchString(regx, dist)
        return matched
 }
diff --git a/pkg/util/wildcard_test.go b/pkg/util/wildcard_test.go
index e660ebf..5b12399 100644
--- a/pkg/util/wildcard_test.go
+++ b/pkg/util/wildcard_test.go
@@ -26,6 +26,8 @@ import (
 func TestWildcardMatch(t *testing.T) {
        t.Run("not regexp should match exactly", func(t *testing.T) {
                assert.True(t, util.WildcardMatch("TestA", "TestA"))
+               assert.False(t, util.WildcardMatch("TestA", "TestAB"))
+               assert.False(t, util.WildcardMatch("TestA", "BTestA"))
        })
 
        t.Run("start with * should match true", func(t *testing.T) {
diff --git a/server/bootstrap/bootstrap.go b/server/bootstrap/bootstrap.go
index 8b68a49..2b4a7ec 100644
--- a/server/bootstrap/bootstrap.go
+++ b/server/bootstrap/bootstrap.go
@@ -88,12 +88,12 @@ func init() {
 
        // handle requests after routing.
        exception.RegisterHandlers()
+       context.RegisterHandlers()
        accesslog.RegisterHandlers()
        maxbody.RegisterHandlers()
        auth.RegisterHandlers()
        metrics.RegisterHandlers()
        tracing.RegisterHandlers()
-       context.RegisterHandlers()
        route.RegisterHandlers()
 
        // init broker
diff --git a/server/plugin/auth/buildin/buildin.go 
b/server/plugin/auth/buildin/buildin.go
index 5476ad7..69001e2 100644
--- a/server/plugin/auth/buildin/buildin.go
+++ b/server/plugin/auth/buildin/buildin.go
@@ -129,5 +129,8 @@ func mustAuth(pattern string) bool {
 }
 
 func (ba *TokenAuthenticator) ResourceScopes(r *http.Request) 
*auth.ResourceScope {
+       if !rbacsvc.Enabled() {
+               return nil
+       }
        return FromRequest(r)
 }

Reply via email to