From a3d43d21aac739d5ca5d4aee1fa6f4bf7ab9c12f Mon Sep 17 00:00:00 2001 From: cmssczy Date: Sun, 27 Mar 2022 10:26:26 +0800 Subject: [PATCH] fix: code format --- Makefile | 4 +- .../config/v2beta2/zz_generated.deepcopy.go | 1 - .../config/v2beta3/zz_generated.deepcopy.go | 1 - .../translation/annotations/forward_auth.go | 10 +-- pkg/types/apisix/v1/zz_generated.deepcopy.go | 1 - test/e2e/annotations/forward_auth.go | 71 ++++++++++++++----- 6 files changed, 60 insertions(+), 28 deletions(-) diff --git a/Makefile b/Makefile index dc00715b41..10dacf71f6 100644 --- a/Makefile +++ b/Makefile @@ -87,8 +87,8 @@ endif .PHONY: push-images push-images: ifeq ($(E2E_SKIP_BUILD), 0) - docker pull apache/apisix:2.13.0-alpine - docker tag apache/apisix:2.13.0-alpine $(REGISTRY)/apache/apisix:dev + docker pull apache/apisix:2.12.0-alpine + docker tag apache/apisix:2.12.0-alpine $(REGISTRY)/apache/apisix:dev docker push $(REGISTRY)/apache/apisix:dev docker pull bitnami/etcd:3.4.14-debian-10-r0 diff --git a/pkg/kube/apisix/apis/config/v2beta2/zz_generated.deepcopy.go b/pkg/kube/apisix/apis/config/v2beta2/zz_generated.deepcopy.go index bff0c55ba8..825098158b 100644 --- a/pkg/kube/apisix/apis/config/v2beta2/zz_generated.deepcopy.go +++ b/pkg/kube/apisix/apis/config/v2beta2/zz_generated.deepcopy.go @@ -1,4 +1,3 @@ -//go:build !ignore_autogenerated // +build !ignore_autogenerated // Licensed to the Apache Software Foundation (ASF) under one or more diff --git a/pkg/kube/apisix/apis/config/v2beta3/zz_generated.deepcopy.go b/pkg/kube/apisix/apis/config/v2beta3/zz_generated.deepcopy.go index 26eb43668b..27ba4f5b8e 100644 --- a/pkg/kube/apisix/apis/config/v2beta3/zz_generated.deepcopy.go +++ b/pkg/kube/apisix/apis/config/v2beta3/zz_generated.deepcopy.go @@ -1,4 +1,3 @@ -//go:build !ignore_autogenerated // +build !ignore_autogenerated // Licensed to the Apache Software Foundation (ASF) under one or more diff --git a/pkg/kube/translation/annotations/forward_auth.go b/pkg/kube/translation/annotations/forward_auth.go index 794008a1b4..c55016d455 100644 --- a/pkg/kube/translation/annotations/forward_auth.go +++ b/pkg/kube/translation/annotations/forward_auth.go @@ -19,11 +19,11 @@ import ( ) const ( - _forwardAuthURI = AnnotationsPrefix + "uri" - _forwardAuthSSLVerify = AnnotationsPrefix + "ssl-verify" - _forwardAuthRequestHeaders = AnnotationsPrefix + "request-headers" - _forwardAuthUpstreamHeaders = AnnotationsPrefix + "upstream-headers" - _forwardAuthClientHeaders = AnnotationsPrefix + "client-headers" + _forwardAuthURI = AnnotationsPrefix + "auth-uri" + _forwardAuthSSLVerify = AnnotationsPrefix + "auth-ssl-verify" + _forwardAuthRequestHeaders = AnnotationsPrefix + "auth-request-headers" + _forwardAuthUpstreamHeaders = AnnotationsPrefix + "auth-upstream-headers" + _forwardAuthClientHeaders = AnnotationsPrefix + "auth-client-headers" ) type forwardAuth struct{} diff --git a/pkg/types/apisix/v1/zz_generated.deepcopy.go b/pkg/types/apisix/v1/zz_generated.deepcopy.go index f1111aaddf..eabfe8b9ce 100644 --- a/pkg/types/apisix/v1/zz_generated.deepcopy.go +++ b/pkg/types/apisix/v1/zz_generated.deepcopy.go @@ -1,4 +1,3 @@ -//go:build !ignore_autogenerated // +build !ignore_autogenerated // Licensed to the Apache Software Foundation (ASF) under one or more diff --git a/test/e2e/annotations/forward_auth.go b/test/e2e/annotations/forward_auth.go index b7b02231cd..4318c02697 100644 --- a/test/e2e/annotations/forward_auth.go +++ b/test/e2e/annotations/forward_auth.go @@ -19,13 +19,13 @@ import ( "net/http" "time" - "github.com/apache/apisix-ingress-controller/test/e2e/scaffold" "github.com/onsi/ginkgo" - "github.com/stretchr/testify/assert" + + "github.com/apache/apisix-ingress-controller/test/e2e/scaffold" ) -var _ = ginkgo.FDescribe("froward-auth annotations", func() { +var _ = ginkgo.Describe("froward-auth annotations", func() { s := scaffold.NewDefaultScaffold() ginkgo.JustBeforeEach(func() { // create an external auth service @@ -55,10 +55,10 @@ kind: Ingress metadata: annotations: kubernetes.io/ingress.class: apisix - k8s.apisix.apache.org/uri: %s - k8s.apisix.apache.org/request-headers: Authorization - k8s.apisix.apache.org/upstream-headers: X-User-ID - k8s.apisix.apache.org/client-headers: Location + k8s.apisix.apache.org/auth-uri: %s + k8s.apisix.apache.org/auth-request-headers: Authorization + k8s.apisix.apache.org/auth-upstream-headers: X-User-ID + k8s.apisix.apache.org/auth-client-headers: Location name: ingress-v1 spec: rules: @@ -81,9 +81,45 @@ spec: resp.Status(http.StatusOK) resp = s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.org").WithHeader("Authorization", "321").Expect() resp.Status(http.StatusOK) - // resp.Headers().ContainsMap(map[string]interface{}{ - // "X-User-ID": "i-am-user", - // }) + resp = s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.org").Expect() + resp.Status(http.StatusForbidden) + resp.Headers().ContainsMap(map[string]interface{}{ + "Location": []string{"http://example.com/auth"}, + }) + }) + + ginkgo.It("enable in ingress networking/v1", func() { + backendSvc, backendPort := s.DefaultHTTPBackend() + ing := fmt.Sprintf(` +apiVersion: networking.k8s.io/v1beta1 +kind: Ingress +metadata: + annotations: + kubernetes.io/ingress.class: apisix + k8s.apisix.apache.org/auth-uri: %s + k8s.apisix.apache.org/auth-request-headers: Authorization + k8s.apisix.apache.org/auth-upstream-headers: X-User-ID + k8s.apisix.apache.org/auth-client-headers: Location + name: ingress-v1beta1 +spec: + rules: + - host: httpbin.org + http: + paths: + - path: /ip + pathType: Exact + backend: + serviceName: %s + servicePort: %d +`, "http://127.0.0.1:9080/auth", backendSvc, backendPort[0]) + err := s.CreateResourceFromString(ing) + assert.Nil(ginkgo.GinkgoT(), err, "creating ingress") + time.Sleep(5 * time.Second) + + resp := s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.org").WithHeader("Authorization", "123").Expect() + resp.Status(http.StatusOK) + resp = s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.org").WithHeader("Authorization", "321").Expect() + resp.Status(http.StatusOK) resp = s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.org").Expect() resp.Status(http.StatusForbidden) resp.Headers().ContainsMap(map[string]interface{}{ @@ -99,10 +135,10 @@ kind: Ingress metadata: annotations: kubernetes.io/ingress.class: apisix - k8s.apisix.apache.org/uri: %s - k8s.apisix.apache.org/request-headers: Authorization - k8s.apisix.apache.org/upstream-headers: X-User-ID - k8s.apisix.apache.org/client-headers: Location + k8s.apisix.apache.org/auth-uri: %s + k8s.apisix.apache.org/auth-request-headers: Authorization + k8s.apisix.apache.org/auth-upstream-headers: X-User-ID + k8s.apisix.apache.org/auth-client-headers: Location name: ingress-extensions-v1beta1 spec: rules: @@ -112,10 +148,12 @@ spec: - path: /ip pathType: Exact backend: - serviceName: %s + serviceName: %s servicePort: %d `, "http://127.0.0.1:9080/auth", backendSvc, backendPort[0]) err := s.CreateResourceFromString(ing) + ginkgo.GinkgoT().Logf("ingress: %s", ing) + ginkgo.GinkgoT().Logf("create ingress: %v", err) assert.Nil(ginkgo.GinkgoT(), err, "creating ingress") time.Sleep(5 * time.Second) @@ -123,9 +161,6 @@ spec: resp.Status(http.StatusOK) resp = s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.org").WithHeader("Authorization", "321").Expect() resp.Status(http.StatusOK) - // resp.Headers().ContainsMap(map[string]interface{}{ - // "X-User-ID": "i-am-user", - // }) resp = s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.org").Expect() resp.Status(http.StatusForbidden) resp.Headers().ContainsMap(map[string]interface{}{