generated from kubernetes/kubernetes-template-project
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1476 from mlavacca/invalid-tls-config
conformance: all cases for which a TLS secret can be invalid are tested
- Loading branch information
Showing
5 changed files
with
174 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
Copyright 2022 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package tests | ||
|
||
import ( | ||
"testing" | ||
|
||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/types" | ||
|
||
"sigs.k8s.io/gateway-api/apis/v1beta1" | ||
"sigs.k8s.io/gateway-api/conformance/utils/kubernetes" | ||
"sigs.k8s.io/gateway-api/conformance/utils/suite" | ||
) | ||
|
||
func init() { | ||
ConformanceTests = append(ConformanceTests, GatewayInvalidTLSConfiguration) | ||
} | ||
|
||
var GatewayInvalidTLSConfiguration = suite.ConformanceTest{ | ||
ShortName: "GatewayInvalidTLSConfiguration", | ||
Description: "A Gateway should fail to become ready if the Gateway has an invalid TLS configuration", | ||
Manifests: []string{"tests/gateway-invalid-tls-certificateref.yaml"}, | ||
Test: func(t *testing.T, s *suite.ConformanceTestSuite) { | ||
listeners := []v1beta1.ListenerStatus{{ | ||
Name: v1beta1.SectionName("https"), | ||
SupportedKinds: []v1beta1.RouteGroupKind{{ | ||
Group: (*v1beta1.Group)(&v1beta1.GroupVersion.Group), | ||
Kind: v1beta1.Kind("HTTPRoute"), | ||
}}, | ||
Conditions: []metav1.Condition{{ | ||
Type: string(v1beta1.ListenerConditionResolvedRefs), | ||
Status: metav1.ConditionFalse, | ||
Reason: string(v1beta1.ListenerReasonInvalidCertificateRef), | ||
}}, | ||
}} | ||
|
||
testCases := []struct { | ||
name string | ||
gatewayNamespacedName types.NamespacedName | ||
}{ | ||
{ | ||
name: "Nonexistent secret referenced as CertificateRef in a Gateway listener", | ||
gatewayNamespacedName: types.NamespacedName{Name: "gateway-certificate-nonexistent-secret", Namespace: "gateway-conformance-infra"}, | ||
}, | ||
{ | ||
name: "Unsupported group resource referenced as CertificateRef in a Gateway listener", | ||
gatewayNamespacedName: types.NamespacedName{Name: "gateway-certificate-unsupported-group", Namespace: "gateway-conformance-infra"}, | ||
}, | ||
{ | ||
name: "Unsupported kind resource referenced as CertificateRef in a Gateway listener", | ||
gatewayNamespacedName: types.NamespacedName{Name: "gateway-certificate-unsupported-kind", Namespace: "gateway-conformance-infra"}, | ||
}, | ||
{ | ||
name: "Malformed secret referenced as CertificateRef in a Gateway listener", | ||
gatewayNamespacedName: types.NamespacedName{Name: "gateway-certificate-malformed-secret", Namespace: "gateway-conformance-infra"}, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
t.Parallel() | ||
kubernetes.GatewayStatusMustHaveListeners(t, s.Client, s.TimeoutConfig, tc.gatewayNamespacedName, listeners) | ||
}) | ||
} | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
apiVersion: gateway.networking.k8s.io/v1beta1 | ||
kind: Gateway | ||
metadata: | ||
name: gateway-certificate-nonexistent-secret | ||
namespace: gateway-conformance-infra | ||
spec: | ||
gatewayClassName: "{GATEWAY_CLASS_NAME}" | ||
listeners: | ||
- name: https | ||
port: 443 | ||
protocol: HTTPS | ||
allowedRoutes: | ||
namespaces: | ||
from: All | ||
tls: | ||
certificateRefs: | ||
- group: "" | ||
kind: Secret | ||
name: nonexistent-certificate | ||
--- | ||
apiVersion: gateway.networking.k8s.io/v1beta1 | ||
kind: Gateway | ||
metadata: | ||
name: gateway-certificate-unsupported-group | ||
namespace: gateway-conformance-infra | ||
spec: | ||
gatewayClassName: "{GATEWAY_CLASS_NAME}" | ||
listeners: | ||
- name: https | ||
port: 443 | ||
protocol: HTTPS | ||
allowedRoutes: | ||
namespaces: | ||
from: All | ||
tls: | ||
certificateRefs: | ||
- group: wrong.group.company.io | ||
kind: Secret | ||
name: tls-validity-checks-certificate | ||
--- | ||
apiVersion: gateway.networking.k8s.io/v1beta1 | ||
kind: Gateway | ||
metadata: | ||
name: gateway-certificate-unsupported-kind | ||
namespace: gateway-conformance-infra | ||
spec: | ||
gatewayClassName: "{GATEWAY_CLASS_NAME}" | ||
listeners: | ||
- name: https | ||
port: 443 | ||
protocol: HTTPS | ||
allowedRoutes: | ||
namespaces: | ||
from: All | ||
tls: | ||
certificateRefs: | ||
- group: "" | ||
kind: WrongKind | ||
name: tls-validity-checks-certificate | ||
--- | ||
apiVersion: gateway.networking.k8s.io/v1beta1 | ||
kind: Gateway | ||
metadata: | ||
name: gateway-certificate-malformed-secret | ||
namespace: gateway-conformance-infra | ||
spec: | ||
gatewayClassName: "{GATEWAY_CLASS_NAME}" | ||
listeners: | ||
- name: https | ||
port: 443 | ||
protocol: HTTPS | ||
allowedRoutes: | ||
namespaces: | ||
from: All | ||
tls: | ||
certificateRefs: | ||
- group: "" | ||
kind: Secret | ||
name: malformed-certificate | ||
--- | ||
apiVersion: v1 | ||
kind: Secret | ||
metadata: | ||
name: malformed-certificate | ||
namespace: gateway-conformance-infra | ||
data: | ||
# this certificate is invalid because contains an invalid pem (base64 of "Hello world"), | ||
# and the certificate and the key are identical | ||
tls.crt: SGVsbG8gd29ybGQK | ||
tls.key: SGVsbG8gd29ybGQK | ||
type: kubernetes.io/tls |
58 changes: 0 additions & 58 deletions
58
conformance/tests/gateway-secret-missing-referenced-secret.go
This file was deleted.
Oops, something went wrong.
19 changes: 0 additions & 19 deletions
19
conformance/tests/gateway-secret-missing-referenced-secret.yaml
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters