Skip to content

Commit 6ae4db3

Browse files
authored
tests: add empty domain validation in virtual service
2 parents 28259b1 + 90be072 commit 6ae4db3

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

api/v1alpha1/virtualservice_webhook.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ func (vs *VirtualService) Validate(
6060
return errors.Wrap(err, errors.UnmarshalMessage)
6161
}
6262

63+
if err := vh.ValidateAll(); err != nil {
64+
return errors.WrapUKS(err, errors.CannotValidateCacheResourceMessage)
65+
}
66+
6367
// Check AccessLog spec
6468
if vs.Spec.AccessLog != nil {
6569
al := &accesslogv3.AccessLog{}

test/conformance/tests/virtualService.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ func init() {
2323
VirtualService_SaveSecretWithCertificate_SecretRef,
2424
VirtualService_SaveSecretWithCertificate_SecretRef_DiferentNamespaces,
2525
VirtualService_SaveSecretWithCertificate_AutoDiscovery_DiferentNamespaces,
26+
VirtualService_EmptyDomains,
2627
)
2728
}
2829

@@ -42,6 +43,14 @@ var VirtualService_InvalidVirtualHost = utils.TestCase{
4243
Test: func(t *testing.T, suite *utils.TestSuite) {},
4344
}
4445

46+
var VirtualService_EmptyDomains = utils.TestCase{
47+
ShortName: "VirtualService_EmptyDomains",
48+
Description: "Test that the VirtualService cannot be applied with empty domains in VirtualHost spec",
49+
Manifests: []string{"../testdata/conformance/virtualservice-empty-domains.yaml"},
50+
ApplyErrorContains: fmt.Sprintf("%v%v", ValidationErrorMessage, errors.CannotValidateCacheResourceMessage),
51+
Test: func(t *testing.T, suite *utils.TestSuite) {},
52+
}
53+
4554
var VirtualService_SaveSecretWithCertificate_SecretRef = utils.TestCase{
4655
ShortName: "VirtualService_SaveSecretWithSertificate_SecretRef",
4756
Description: "Test that the secret with sertificate cannot be deleted if used in VirtualService with tlsConfig.SecretRef",
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
apiVersion: envoy.kaasops.io/v1alpha1
2+
kind: VirtualService
3+
metadata:
4+
name: virtual-service-empty-domains
5+
spec:
6+
listener:
7+
name: http
8+
additionalRoutes:
9+
- name: static
10+
virtualHost:
11+
name: test-domain
12+
routes:
13+
- match:
14+
prefix: /
15+
route:
16+
cluster: static

0 commit comments

Comments
 (0)