Skip to content

Commit 501b4e8

Browse files
authored
test: add e2e test case for webhook (#2585)
Signed-off-by: Ashing Zheng <[email protected]>
1 parent fe5c135 commit 501b4e8

File tree

14 files changed

+1052
-16
lines changed

14 files changed

+1052
-16
lines changed

test/e2e/apisix/e2e_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
_ "github.com/apache/apisix-ingress-controller/test/e2e/gatewayapi"
3131
_ "github.com/apache/apisix-ingress-controller/test/e2e/ingress"
3232
"github.com/apache/apisix-ingress-controller/test/e2e/scaffold"
33+
_ "github.com/apache/apisix-ingress-controller/test/e2e/webhook"
3334
)
3435

3536
// TestAPISIXE2E runs e2e tests using the APISIX standalone mode

test/e2e/framework/manifests/webhook.yaml

Lines changed: 181 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,174 @@ kind: ValidatingWebhookConfiguration
2020
metadata:
2121
name: test-webhook-{{ .Namespace }}
2222
webhooks:
23+
- name: vapisixconsumer-v2.kb.io
24+
clientConfig:
25+
service:
26+
name: webhook-service
27+
namespace: {{ .Namespace }}
28+
path: /validate-apisix-apache-org-v2-apisixconsumer
29+
caBundle: {{ .CABundle }}
30+
admissionReviewVersions:
31+
- v1
32+
rules:
33+
- operations:
34+
- CREATE
35+
- UPDATE
36+
apiGroups:
37+
- apisix.apache.org
38+
apiVersions:
39+
- v2
40+
resources:
41+
- apisixconsumers
42+
failurePolicy: Fail
43+
sideEffects: None
44+
- name: vapisixroute-v2.kb.io
45+
clientConfig:
46+
service:
47+
name: webhook-service
48+
namespace: {{ .Namespace }}
49+
path: /validate-apisix-apache-org-v2-apisixroute
50+
caBundle: {{ .CABundle }}
51+
admissionReviewVersions:
52+
- v1
53+
rules:
54+
- operations:
55+
- CREATE
56+
- UPDATE
57+
apiGroups:
58+
- apisix.apache.org
59+
apiVersions:
60+
- v2
61+
resources:
62+
- apisixroutes
63+
failurePolicy: Fail
64+
sideEffects: None
65+
- name: vapisixtls-v2.kb.io
66+
clientConfig:
67+
service:
68+
name: webhook-service
69+
namespace: {{ .Namespace }}
70+
path: /validate-apisix-apache-org-v2-apisixtls
71+
caBundle: {{ .CABundle }}
72+
admissionReviewVersions:
73+
- v1
74+
rules:
75+
- operations:
76+
- CREATE
77+
- UPDATE
78+
apiGroups:
79+
- apisix.apache.org
80+
apiVersions:
81+
- v2
82+
resources:
83+
- apisixtlses
84+
failurePolicy: Fail
85+
sideEffects: None
86+
- name: vconsumer-v1alpha1.kb.io
87+
clientConfig:
88+
service:
89+
name: webhook-service
90+
namespace: {{ .Namespace }}
91+
path: /validate-apisix-apache-org-v1alpha1-consumer
92+
caBundle: {{ .CABundle }}
93+
admissionReviewVersions:
94+
- v1
95+
rules:
96+
- operations:
97+
- CREATE
98+
- UPDATE
99+
apiGroups:
100+
- apisix.apache.org
101+
apiVersions:
102+
- v1alpha1
103+
resources:
104+
- consumers
105+
failurePolicy: Fail
106+
sideEffects: None
107+
- name: vgateway-v1.kb.io
108+
clientConfig:
109+
service:
110+
name: webhook-service
111+
namespace: {{ .Namespace }}
112+
path: /validate-gateway-networking-k8s-io-v1-gateway
113+
caBundle: {{ .CABundle }}
114+
admissionReviewVersions:
115+
- v1
116+
rules:
117+
- operations:
118+
- CREATE
119+
- UPDATE
120+
apiGroups:
121+
- gateway.networking.k8s.io
122+
apiVersions:
123+
- v1
124+
resources:
125+
- gateways
126+
failurePolicy: Fail
127+
sideEffects: None
128+
- name: vgatewayproxy-v1alpha1.kb.io
129+
clientConfig:
130+
service:
131+
name: webhook-service
132+
namespace: {{ .Namespace }}
133+
path: /validate-apisix-apache-org-v1alpha1-gatewayproxy
134+
caBundle: {{ .CABundle }}
135+
admissionReviewVersions:
136+
- v1
137+
rules:
138+
- operations:
139+
- CREATE
140+
- UPDATE
141+
apiGroups:
142+
- apisix.apache.org
143+
apiVersions:
144+
- v1alpha1
145+
resources:
146+
- gatewayproxies
147+
failurePolicy: Fail
148+
sideEffects: None
149+
- name: vgrpcroute-v1.kb.io
150+
clientConfig:
151+
service:
152+
name: webhook-service
153+
namespace: {{ .Namespace }}
154+
path: /validate-gateway-networking-k8s-io-v1-grpcroute
155+
caBundle: {{ .CABundle }}
156+
admissionReviewVersions:
157+
- v1
158+
rules:
159+
- operations:
160+
- CREATE
161+
- UPDATE
162+
apiGroups:
163+
- gateway.networking.k8s.io
164+
apiVersions:
165+
- v1
166+
resources:
167+
- grpcroutes
168+
failurePolicy: Fail
169+
sideEffects: None
170+
- name: vhttproute-v1.kb.io
171+
clientConfig:
172+
service:
173+
name: webhook-service
174+
namespace: {{ .Namespace }}
175+
path: /validate-gateway-networking-k8s-io-v1-httproute
176+
caBundle: {{ .CABundle }}
177+
admissionReviewVersions:
178+
- v1
179+
rules:
180+
- operations:
181+
- CREATE
182+
- UPDATE
183+
apiGroups:
184+
- gateway.networking.k8s.io
185+
apiVersions:
186+
- v1
187+
resources:
188+
- httproutes
189+
failurePolicy: Fail
190+
sideEffects: None
23191
- name: vingress-v1.kb.io
24192
clientConfig:
25193
service:
@@ -30,15 +198,15 @@ webhooks:
30198
admissionReviewVersions:
31199
- v1
32200
rules:
33-
- operations:
34-
- CREATE
35-
- UPDATE
36-
apiGroups:
37-
- networking.k8s.io
38-
apiVersions:
39-
- v1
40-
resources:
41-
- ingresses
201+
- operations:
202+
- CREATE
203+
- UPDATE
204+
apiGroups:
205+
- networking.k8s.io
206+
apiVersions:
207+
- v1
208+
resources:
209+
- ingresses
42210
failurePolicy: Fail
43211
sideEffects: None
44212
- name: vingressclass-v1.kb.io
@@ -62,12 +230,12 @@ webhooks:
62230
- ingressclasses
63231
failurePolicy: Fail
64232
sideEffects: None
65-
- name: vgateway-v1.kb.io
233+
- name: vtcproute-v1alpha2.kb.io
66234
clientConfig:
67235
service:
68236
name: webhook-service
69237
namespace: {{ .Namespace }}
70-
path: /validate-gateway-networking-k8s-io-v1-gateway
238+
path: /validate-gateway-networking-k8s-io-v1alpha2-tcproute
71239
caBundle: {{ .CABundle }}
72240
admissionReviewVersions:
73241
- v1
@@ -78,8 +246,8 @@ webhooks:
78246
apiGroups:
79247
- gateway.networking.k8s.io
80248
apiVersions:
81-
- v1
249+
- v1alpha2
82250
resources:
83-
- gateways
251+
- tcproutes
84252
failurePolicy: Fail
85253
sideEffects: None

test/e2e/webhook/apisixconsumer.go

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package webhook
19+
20+
import (
21+
"fmt"
22+
"time"
23+
24+
. "github.com/onsi/ginkgo/v2"
25+
. "github.com/onsi/gomega"
26+
27+
"github.com/apache/apisix-ingress-controller/test/e2e/scaffold"
28+
)
29+
30+
var _ = Describe("Test ApisixConsumer Webhook", Label("webhook"), func() {
31+
s := scaffold.NewScaffold(scaffold.Options{
32+
Name: "apisixconsumer-webhook-test",
33+
EnableWebhook: true,
34+
})
35+
36+
BeforeEach(func() {
37+
By("creating GatewayProxy")
38+
err := s.CreateResourceFromString(s.GetGatewayProxySpec())
39+
Expect(err).NotTo(HaveOccurred(), "creating GatewayProxy")
40+
time.Sleep(5 * time.Second)
41+
42+
By("creating IngressClass")
43+
err = s.CreateResourceFromStringWithNamespace(s.GetIngressClassYaml(), "")
44+
Expect(err).NotTo(HaveOccurred(), "creating IngressClass")
45+
time.Sleep(5 * time.Second)
46+
})
47+
48+
It("should warn on missing authentication secrets", func() {
49+
missingSecret := "missing-basic-secret"
50+
consumerName := "webhook-apisixconsumer"
51+
consumerYAML := `
52+
apiVersion: apisix.apache.org/v2
53+
kind: ApisixConsumer
54+
metadata:
55+
name: %s
56+
namespace: %s
57+
spec:
58+
ingressClassName: %s
59+
authParameter:
60+
basicAuth:
61+
secretRef:
62+
name: %s
63+
`
64+
65+
output, err := s.CreateResourceFromStringAndGetOutput(fmt.Sprintf(consumerYAML, consumerName, s.Namespace(), s.Namespace(), missingSecret))
66+
Expect(err).ShouldNot(HaveOccurred())
67+
Expect(output).To(ContainSubstring(fmt.Sprintf("Warning: Referenced Secret '%s/%s' not found", s.Namespace(), missingSecret)))
68+
69+
By("creating referenced secret")
70+
secretYAML := fmt.Sprintf(`
71+
apiVersion: v1
72+
kind: Secret
73+
metadata:
74+
name: %s
75+
stringData:
76+
username: demo
77+
password: demo
78+
`, missingSecret)
79+
err = s.CreateResourceFromString(secretYAML)
80+
Expect(err).NotTo(HaveOccurred(), "creating basic auth secret")
81+
82+
time.Sleep(2 * time.Second)
83+
84+
output, err = s.CreateResourceFromStringAndGetOutput(fmt.Sprintf(consumerYAML, consumerName, s.Namespace(), s.Namespace(), missingSecret))
85+
Expect(err).ShouldNot(HaveOccurred())
86+
Expect(output).NotTo(ContainSubstring(fmt.Sprintf("Warning: Referenced Secret '%s/%s' not found", s.Namespace(), missingSecret)))
87+
})
88+
})

0 commit comments

Comments
 (0)