Skip to content

Commit

Permalink
fix: code format
Browse files Browse the repository at this point in the history
  • Loading branch information
nayihz committed Mar 27, 2022
1 parent ab27483 commit a3d43d2
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 28 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions pkg/kube/translation/annotations/forward_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down
1 change: 0 additions & 1 deletion pkg/types/apisix/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

71 changes: 53 additions & 18 deletions test/e2e/annotations/forward_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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{}{
Expand All @@ -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:
Expand All @@ -112,20 +148,19 @@ 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)

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.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{}{
Expand Down

0 comments on commit a3d43d2

Please sign in to comment.