Add configoption to exclude routes from tls upgrading (#2203)
* Add configoption to exclude routes from tls upgrading * Add tests for IsLocationInLocationList * Seperate elements in NoTLSRedirectLocations by comma * Set NoTLSRedirectLocations to "/.well-known/acme-challenge/" by default * Remove trailing slash from "/.well-known/acme-challenge" default
This commit is contained in:
parent
977cfcb4c7
commit
94deb3a01a
5 changed files with 60 additions and 1 deletions
|
|
@ -129,6 +129,7 @@ var (
|
|||
"buildRateLimit": buildRateLimit,
|
||||
"buildResolvers": buildResolvers,
|
||||
"buildUpstreamName": buildUpstreamName,
|
||||
"isLocationInLocationList": isLocationInLocationList,
|
||||
"isLocationAllowed": isLocationAllowed,
|
||||
"buildLogFormatUpstream": buildLogFormatUpstream,
|
||||
"buildDenyVariable": buildDenyVariable,
|
||||
|
|
@ -513,6 +514,28 @@ func buildRateLimit(input interface{}) []string {
|
|||
return limits
|
||||
}
|
||||
|
||||
func isLocationInLocationList(location interface{}, rawLocationList string) bool {
|
||||
loc, ok := location.(*ingress.Location)
|
||||
if !ok {
|
||||
glog.Errorf("expected an '*ingress.Location' type but %T was returned", location)
|
||||
return false
|
||||
}
|
||||
|
||||
locationList := strings.Split(rawLocationList, ",")
|
||||
|
||||
for _, locationListItem := range locationList {
|
||||
locationListItem = strings.Trim(locationListItem, " ")
|
||||
if locationListItem == "" {
|
||||
continue
|
||||
}
|
||||
if strings.HasPrefix(loc.Path, locationListItem) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func isLocationAllowed(input interface{}) bool {
|
||||
loc, ok := input.(*ingress.Location)
|
||||
if !ok {
|
||||
|
|
|
|||
|
|
@ -645,3 +645,26 @@ func TestBuildAuthSignURL(t *testing.T) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsLocationInLocationList(t *testing.T) {
|
||||
|
||||
testCases := []struct {
|
||||
location *ingress.Location
|
||||
rawLocationList string
|
||||
expected bool
|
||||
}{
|
||||
{&ingress.Location{Path: "/match"}, "/match", true},
|
||||
{&ingress.Location{Path: "/match"}, ",/match", true},
|
||||
{&ingress.Location{Path: "/match"}, "/dontmatch", false},
|
||||
{&ingress.Location{Path: "/match"}, ",/dontmatch", false},
|
||||
{&ingress.Location{Path: "/match"}, "/dontmatch,/match", true},
|
||||
{&ingress.Location{Path: "/match"}, "/dontmatch,/dontmatcheither", false},
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
result := isLocationInLocationList(testCase.location, testCase.rawLocationList)
|
||||
if result != testCase.expected {
|
||||
t.Errorf(" expected %v but return %v, path: '%s', rawLocation: '%s'", testCase.expected, result, testCase.location.Path, testCase.rawLocationList)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue