Skip to content

Commit

Permalink
Merge pull request #717 from eminaktas/overwritable-invalidpattern
Browse files Browse the repository at this point in the history
feat: add overwrite functionality for invalid Pattern
  • Loading branch information
kpacha authored Mar 12, 2024
2 parents 6e9eacf + dc2ba0e commit 75cb2ac
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
5 changes: 5 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,11 @@ func SetSequentialParamsPattern(pattern string) error {
return nil
}

// SetInvalidPattern sets the invalidPattern variable to the provided value.
func SetInvalidPattern(pattern string) {
invalidPattern = pattern
}

func validateAddress(address string) bool {
ip := net.ParseIP(address)
return ip != nil
Expand Down
29 changes: 29 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,3 +309,32 @@ func TestConfig_initKOInvalidDebugPattern(t *testing.T) {

invalidPattern = dp
}

func TestConfig_initKOValidSetinvalidPattern(t *testing.T) {
dp := invalidPattern

invalidPattern = `^[^/]|/__(debug|echo|health)(/.*)?$`
subject := ServiceConfig{
Version: ConfigVersion,
Host: []string{"http://127.0.0.1:8080"},
Endpoints: []*EndpointConfig{
{
Endpoint: "/*",
Method: "GET",
Backend: []*Backend{
{
URLPattern: "/",
Host: []string{"https://api.github.com"},
AllowList: []string{"authorizations_url", "code_search_url"},
},
},
},
},
}

if err := subject.Init(); err != nil {
t.Error(err)
}

invalidPattern = dp
}

0 comments on commit 75cb2ac

Please sign in to comment.