Skip to content

Commit

Permalink
Applied klog instead of glog
Browse files Browse the repository at this point in the history
Fixed e2e test
Fixed according to the static-check
  • Loading branch information
okryvoshapka-connyun committed Mar 1, 2019
1 parent 4cc3974 commit 53713fe
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 35 deletions.
6 changes: 3 additions & 3 deletions internal/ingress/annotations/authreq/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ func (a authReq) Parse(ing *extensions.Ingress) (interface{}, error) {
}, nil
}

//
// ParseStringToURL parses the provided string into URL and returns error
// message in case of failure
func ParseStringToURL(input string) (*url.URL, string) {

parsedURL, err := url.Parse(input)
Expand All @@ -187,8 +188,7 @@ func ParseStringToURL(input string) (*url.URL, string) {
return nil, "url host is empty."
} else if strings.Contains(parsedURL.Host, "..") {
return nil, "invalid url host."
} else {
return parsedURL, ""
}
return parsedURL, ""

}
6 changes: 4 additions & 2 deletions internal/ingress/controller/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -761,8 +761,8 @@ type TemplateConfig struct {
StatusSocket string
StatusPath string
StreamSocket string
GlobalExternalAuth *GlobalExternalAuth

GlobalExternalAuth *GlobalExternalAuth
}

// ListenPorts describe the ports required to run the
Expand All @@ -775,6 +775,8 @@ type ListenPorts struct {
SSLProxy int
}

// GlobalExternalAuth describe external authentication configuration for the
// NGINX Ingress controller
type GlobalExternalAuth struct {
URL string `json:"url"`
// Host contains the hostname defined in the URL
Expand Down
2 changes: 1 addition & 1 deletion internal/ingress/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ type Configuration struct {
DynamicCertificatesEnabled bool

DisableCatchAll bool

GlobalExternalAuth *ngx_config.GlobalExternalAuth
}

Expand Down
4 changes: 2 additions & 2 deletions internal/ingress/controller/nginx.go
Original file line number Diff line number Diff line change
Expand Up @@ -606,8 +606,8 @@ func (n *NGINXController) OnUpdate(ingressCfg ingress.Configuration) error {
StatusSocket: nginx.StatusSocket,
StatusPath: nginx.StatusPath,
StreamSocket: nginx.StreamSocket,
GlobalExternalAuth: n.cfg.GlobalExternalAuth,

GlobalExternalAuth: n.cfg.GlobalExternalAuth,
}

tc.Cfg.Checksum = ingressCfg.ConfigurationChecksum
Expand Down
Empty file modified internal/ingress/controller/store/store.go
100644 → 100755
Empty file.
Empty file modified internal/ingress/controller/store/store_test.go
100644 → 100755
Empty file.
4 changes: 2 additions & 2 deletions internal/ingress/controller/template/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ import (
"github.com/mitchellh/mapstructure"

"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/ingress-nginx/internal/ingress/annotations/authreq"
"k8s.io/ingress-nginx/internal/ingress/controller/config"
ing_net "k8s.io/ingress-nginx/internal/net"
"k8s.io/ingress-nginx/internal/runtime"
"k8s.io/ingress-nginx/internal/ingress/annotations/authreq"
)

const (
Expand Down Expand Up @@ -158,7 +158,7 @@ func ReadConfig(src map[string]string) config.Configuration {

authURL, message := authreq.ParseStringToURL(val)
if authURL == nil {
glog.Warningf("Global auth location denied - %v.", message)
klog.Warningf("Global auth location denied - %v.", message)
} else {
to.GlobalExternalAuth.URL = val
to.GlobalExternalAuth.Host = authURL.Hostname()
Expand Down
10 changes: 5 additions & 5 deletions internal/ingress/controller/template/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ var (
"buildLuaSharedDictionaries": buildLuaSharedDictionaries,
"buildLocation": buildLocation,
"buildAuthLocation": buildAuthLocation,
"shouldApplyGlobalAuth": shouldApplyGlobalAuth,
"shouldApplyGlobalAuth": shouldApplyGlobalAuth,
"buildAuthResponseHeaders": buildAuthResponseHeaders,
"buildProxyPass": buildProxyPass,
"filterRateLimits": filterRateLimits,
Expand Down Expand Up @@ -348,7 +348,7 @@ func buildAuthLocation(input interface{}, globalExternalAuthURL string) string {
return ""
}

if ((location.ExternalAuth.URL == "") && (!shouldApplyGlobalAuth(input, globalExternalAuthURL))) {
if (location.ExternalAuth.URL == "") && (!shouldApplyGlobalAuth(input, globalExternalAuthURL)) {
return ""
}

Expand All @@ -358,15 +358,15 @@ func buildAuthLocation(input interface{}, globalExternalAuthURL string) string {
return fmt.Sprintf("/_external-auth-%v", str)
}

// shouldApplyGlobalAuth returns true only in case when ExternalAuth.URL is not set and
// shouldApplyGlobalAuth returns true only in case when ExternalAuth.URL is not set and
// GlobalExternalAuth is set and enabled
func shouldApplyGlobalAuth(input interface{}, globalExternalAuthURL string) bool {
location, ok := input.(*ingress.Location)
if !ok {
glog.Errorf("expected an '*ingress.Location' type but %T was returned", input)
klog.Errorf("expected an '*ingress.Location' type but %T was returned", input)
}

if ((location.ExternalAuth.URL == "") && (globalExternalAuthURL != "") && (location.EnableGlobalAuth)) {
if (location.ExternalAuth.URL == "") && (globalExternalAuthURL != "") && (location.EnableGlobalAuth) {
return true
}

Expand Down
12 changes: 6 additions & 6 deletions internal/ingress/controller/template/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ func TestBuildProxyPass(t *testing.T) {
func TestBuildAuthLocation(t *testing.T) {
invalidType := &ingress.Ingress{}
expected := ""
actual := buildAuthLocation(invalidType)
actual := buildAuthLocation(invalidType, "")

if !reflect.DeepEqual(expected, actual) {
t.Errorf("Expected '%v' but returned '%v'", expected, actual)
Expand All @@ -305,9 +305,9 @@ func TestBuildAuthLocation(t *testing.T) {
externalAuthPath := fmt.Sprintf("/_external-auth-%v", encodedAuthURL)

testCases := []struct {
title string
title string
authURL string
globalAuthURL string
globalAuthURL string
enableglobalExternalAuth bool
expected string
}{
Expand Down Expand Up @@ -346,9 +346,9 @@ func TestShouldApplyGlobalAuth(t *testing.T) {
}

testCases := []struct {
title string
title string
authURL string
globalAuthURL string
globalAuthURL string
enableglobalExternalAuth bool
expected bool
}{
Expand Down Expand Up @@ -883,7 +883,7 @@ func TestOpentracingPropagateContext(t *testing.T) {
&ingress.Location{BackendProtocol: "GRPC"}: "opentracing_grpc_propagate_context",
&ingress.Location{BackendProtocol: "GRPCS"}: "opentracing_grpc_propagate_context",
&ingress.Location{BackendProtocol: "AJP"}: "opentracing_propagate_context",
"not a location": "opentracing_propagate_context",
"not a location": "opentracing_propagate_context",
}

for loc, expectedDirective := range tests {
Expand Down
28 changes: 14 additions & 14 deletions test/e2e/settings/global_auth_url.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ var _ = framework.IngressNginxDescribe("Global External Auth", func() {
noAuthSetting := "no-auth-locations"
noAuthLocations := barPath

enableGlobalExternalAuthAnnotation := "nginx.ingress.kubernetes.io/enable-global-auth"
enableGlobalExternalAuthAnnotation := "nginx.ingress.kubernetes.io/enable-global-auth"

BeforeEach(func() {
f.NewEchoDeployment()
Expand All @@ -55,18 +55,18 @@ var _ = framework.IngressNginxDescribe("Global External Auth", func() {
Context("when global external authentication is configured", func() {

BeforeEach(func() {
globalExternalAuthURL := fmt.Sprintf("http://httpbin.%s.svc.cluster.local:80/status/401", f.IngressController.Namespace)
globalExternalAuthURL := fmt.Sprintf("http://httpbin.%s.svc.cluster.local:80/status/401", f.Namespace)

By("Adding an ingress rule for /foo")
fooIng := framework.NewSingleIngress("foo-ingress", fooPath, host, f.IngressController.Namespace, echoServiceName, 80, nil)
fooIng := framework.NewSingleIngress("foo-ingress", fooPath, host, f.Namespace, echoServiceName, 80, nil)
f.EnsureIngress(fooIng)
f.WaitForNginxServer(host,
func(server string) bool {
return Expect(server).Should(ContainSubstring("location /foo"))
})

By("Adding an ingress rule for /bar")
barIng := framework.NewSingleIngress("bar-ingress", barPath, host, f.IngressController.Namespace, echoServiceName, 80, nil)
barIng := framework.NewSingleIngress("bar-ingress", barPath, host, f.Namespace, echoServiceName, 80, nil)
f.EnsureIngress(barIng)
f.WaitForNginxServer(host,
func(server string) bool {
Expand All @@ -85,14 +85,14 @@ var _ = framework.IngressNginxDescribe("Global External Auth", func() {

By("Sending a request to protected service /foo")
fooResp, _, _ := gorequest.New().
Get(f.IngressController.HTTPURL+fooPath).
Get(f.GetURL(framework.HTTP)+fooPath).
Set("Host", host).
End()
Expect(fooResp.StatusCode).Should(Equal(http.StatusUnauthorized))

By("Sending a request to protected service /bar")
barResp, _, _ := gorequest.New().
Get(f.IngressController.HTTPURL+barPath).
Get(f.GetURL(framework.HTTP)+barPath).
Set("Host", host).
End()
Expect(barResp.StatusCode).Should(Equal(http.StatusUnauthorized))
Expand All @@ -105,14 +105,14 @@ var _ = framework.IngressNginxDescribe("Global External Auth", func() {

By("Sending a request to protected service /foo")
fooResp, _, _ := gorequest.New().
Get(f.IngressController.HTTPURL+fooPath).
Get(f.GetURL(framework.HTTP)+fooPath).
Set("Host", host).
End()
Expect(fooResp.StatusCode).Should(Equal(http.StatusUnauthorized))

By("Sending a request to whitelisted service /bar")
barResp, _, _ := gorequest.New().
Get(f.IngressController.HTTPURL+barPath).
Get(f.GetURL(framework.HTTP)+barPath).
Set("Host", host).
End()
Expect(barResp.StatusCode).Should(Equal(http.StatusOK))
Expand All @@ -122,25 +122,25 @@ var _ = framework.IngressNginxDescribe("Global External Auth", func() {

By("Adding an ingress rule for /bar with annotation enable-global-auth = false")
annotations := map[string]string{
enableGlobalExternalAuthAnnotation : "false",
enableGlobalExternalAuthAnnotation: "false",
}
barIng := framework.NewSingleIngress("bar-ingress", barPath, host, f.IngressController.Namespace, echoServiceName, 80, &annotations)
barIng := framework.NewSingleIngress("bar-ingress", barPath, host, f.Namespace, echoServiceName, 80, &annotations)
f.EnsureIngress(barIng)
f.WaitForNginxServer(host,
func(server string) bool {
return Expect(server).Should(ContainSubstring("location /bar"))
})

By("Sending a request to protected service /foo")
fooResp, _, _ := gorequest.New().
Get(f.IngressController.HTTPURL+fooPath).
Get(f.GetURL(framework.HTTP)+fooPath).
Set("Host", host).
End()
Expect(fooResp.StatusCode).Should(Equal(http.StatusUnauthorized))

By("Sending a request to whitelisted service /bar")
barResp, _, _ := gorequest.New().
Get(f.IngressController.HTTPURL+barPath).
Get(f.GetURL(framework.HTTP)+barPath).
Set("Host", host).
End()
Expect(barResp.StatusCode).Should(Equal(http.StatusOK))
Expand Down

0 comments on commit 53713fe

Please sign in to comment.