@@ -573,6 +573,30 @@ spec:
573573 name: httpbin-service-e2e-test
574574 port:
575575 number: 80
576+ `
577+ ingressForwardAuth = `
578+ apiVersion: networking.k8s.io/v1
579+ kind: Ingress
580+ metadata:
581+ name: forward-auth
582+ annotations:
583+ k8s.apisix.apache.org/auth-uri: %s
584+ k8s.apisix.apache.org/auth-request-headers: Authorization
585+ k8s.apisix.apache.org/auth-upstream-headers: X-User-ID
586+ k8s.apisix.apache.org/auth-client-headers: Location
587+ spec:
588+ ingressClassName: %s
589+ rules:
590+ - host: httpbin.example
591+ http:
592+ paths:
593+ - path: /get
594+ pathType: Exact
595+ backend:
596+ service:
597+ name: httpbin-service-e2e-test
598+ port:
599+ number: 80
576600`
577601 )
578602 BeforeEach (func () {
@@ -1017,6 +1041,45 @@ spec:
10171041 Check : scaffold .WithExpectedStatus (http .StatusForbidden ),
10181042 })
10191043 })
1044+ It ("forward-auth" , func () {
1045+ s .DeployNginx (framework.NginxOptions {
1046+ Namespace : s .Namespace (),
1047+ Replicas : ptr .To (int32 (1 )),
1048+ })
1049+
1050+ Expect (s .CreateResourceFromString (fmt .Sprintf (ingressForwardAuth , "http://nginx/auth" , s .Namespace ()))).
1051+ ShouldNot (HaveOccurred (), "creating ApisixConsumer for forwardAuth" )
1052+
1053+ tests := []* scaffold.RequestAssert {
1054+ {
1055+ Method : "GET" ,
1056+ Path : "/get" ,
1057+ Host : "httpbin.example" ,
1058+ Headers : map [string ]string {
1059+ "Authorization" : "123" ,
1060+ },
1061+ Checks : []scaffold.ResponseCheckFunc {
1062+ scaffold .WithExpectedStatus (http .StatusOK ),
1063+ scaffold .WithExpectedBodyContains (`"X-User-Id": "user-123"` ),
1064+ },
1065+ },
1066+ {
1067+ Method : "GET" ,
1068+ Path : "/get" ,
1069+ Host : "httpbin.example" ,
1070+ Headers : map [string ]string {
1071+ "Authorization" : "456" ,
1072+ },
1073+ Checks : []scaffold.ResponseCheckFunc {
1074+ scaffold .WithExpectedStatus (http .StatusUnauthorized ),
1075+ scaffold .WithExpectedHeader ("Location" , "http://example.com/auth" ),
1076+ },
1077+ },
1078+ }
1079+ for _ , test := range tests {
1080+ s .RequestAssert (test )
1081+ }
1082+ })
10201083 })
10211084
10221085 Context ("Service Namespace" , func () {
0 commit comments