Skip to content

Commit

Permalink
e2e: add test case for basic auth (#5003)
Browse files Browse the repository at this point in the history
Add test case for basic auth

Signed-off-by: Huabing Zhao <[email protected]>
  • Loading branch information
zhaohuabing authored Jan 6, 2025
1 parent 072153a commit a6bcc1b
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
17 changes: 17 additions & 0 deletions test/e2e/testdata/basic-auth.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,23 @@ spec:
- name: infra-backend-v1
port: 8080
---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: http-no-basic-auth
namespace: gateway-conformance-infra
spec:
parentRefs:
- name: same-namespace
rules:
- matches:
- path:
type: Exact
value: /no-basic-auth
backendRefs:
- name: infra-backend-v1
port: 8080
---
apiVersion: gateway.envoyproxy.io/v1alpha1
kind: SecurityPolicy
metadata:
Expand Down
30 changes: 30 additions & 0 deletions test/e2e/tests/basic_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,5 +179,35 @@ var BasicAuthTest = suite.ConformanceTest{

http.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, suite.TimeoutConfig, gwAddr, expectedResponse)
})

// This test is to ensure that the BasicAuth filter is not applied to routes that under the same gateway but
// do not have the BasicAuth policy applied.
t.Run("request to an HTTP route without BasicAuth", func(t *testing.T) {
ns := "gateway-conformance-infra"
routeNN := types.NamespacedName{Name: "http-no-basic-auth", Namespace: ns}
gwNN := types.NamespacedName{Name: "same-namespace", Namespace: ns}
gwAddr := kubernetes.GatewayAndHTTPRoutesMustBeAccepted(t, suite.Client, suite.TimeoutConfig, suite.ControllerName, kubernetes.NewGatewayRef(gwNN), routeNN)

ancestorRef := gwapiv1a2.ParentReference{
Group: gatewayapi.GroupPtr(gwapiv1.GroupName),
Kind: gatewayapi.KindPtr(resource.KindGateway),
Namespace: gatewayapi.NamespacePtr(gwNN.Namespace),
Name: gwapiv1.ObjectName(gwNN.Name),
}
SecurityPolicyMustBeAccepted(t, suite.Client, types.NamespacedName{Name: "basic-auth-1", Namespace: ns}, suite.ControllerName, ancestorRef)
SecurityPolicyMustBeAccepted(t, suite.Client, types.NamespacedName{Name: "basic-auth-2", Namespace: ns}, suite.ControllerName, ancestorRef)

expectedResponse := http.ExpectedResponse{
Request: http.Request{
Path: "/no-basic-auth",
},
Response: http.Response{
StatusCode: 200,
},
Namespace: ns,
}

http.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, suite.TimeoutConfig, gwAddr, expectedResponse)
})
},
}

0 comments on commit a6bcc1b

Please sign in to comment.