Enable Customization of Auth Request Redirect (#1993)
Adds the 'nginx.ingress.kubernetes.io/auth-request-redirect' annotation, which allows the customization of the 'X-Auth-Request-Redirect' Header. Fixes: #1979
This commit is contained in:
parent
efec983ed4
commit
d1ae7ff29c
7 changed files with 89 additions and 48 deletions
|
|
@ -214,7 +214,6 @@ func buildLocation(input interface{}) string {
|
|||
return path
|
||||
}
|
||||
|
||||
// TODO: Needs Unit Tests
|
||||
func buildAuthLocation(input interface{}) string {
|
||||
location, ok := input.(*ingress.Location)
|
||||
if !ok {
|
||||
|
|
@ -227,7 +226,7 @@ func buildAuthLocation(input interface{}) string {
|
|||
}
|
||||
|
||||
str := base64.URLEncoding.EncodeToString([]byte(location.Path))
|
||||
// avoid locations containing the = char
|
||||
// removes "=" after encoding
|
||||
str = strings.Replace(str, "=", "", -1)
|
||||
return fmt.Sprintf("/_external-auth-%v", str)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,6 +26,8 @@ import (
|
|||
"strings"
|
||||
"testing"
|
||||
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"k8s.io/ingress-nginx/internal/file"
|
||||
"k8s.io/ingress-nginx/internal/ingress"
|
||||
"k8s.io/ingress-nginx/internal/ingress/annotations/authreq"
|
||||
|
|
@ -172,6 +174,26 @@ func TestBuildProxyPass(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestBuildAuthLocation(t *testing.T) {
|
||||
authURL := "foo.com/auth"
|
||||
|
||||
loc := &ingress.Location{
|
||||
ExternalAuth: authreq.Config{
|
||||
URL: authURL,
|
||||
},
|
||||
Path: "/cat",
|
||||
}
|
||||
|
||||
str := buildAuthLocation(loc)
|
||||
|
||||
encodedAuthURL := strings.Replace(base64.URLEncoding.EncodeToString([]byte(loc.Path)), "=", "", -1)
|
||||
expected := fmt.Sprintf("/_external-auth-%v", encodedAuthURL)
|
||||
|
||||
if str != expected {
|
||||
t.Errorf("Expected \n'%v'\nbut returned \n'%v'", expected, str)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildAuthResponseHeaders(t *testing.T) {
|
||||
loc := &ingress.Location{
|
||||
ExternalAuth: authreq.Config{ResponseHeaders: []string{"h1", "H-With-Caps-And-Dashes"}},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue