Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix client tls tests #9857

Merged
merged 8 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions changelog/v1.18.0-beta13/fix-clienttls.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
changelog:
- type: NON_USER_FACING
description: >-
Ensure resources are deleted before moving on to next test in client tls feature suites.
18 changes: 15 additions & 3 deletions test/kubernetes/e2e/features/client_tls/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,17 @@ func (s *clientTlsTestingSuite) TearDownSuite() {
}

func (s *clientTlsTestingSuite) TestRouteSecureRequestToUpstreamFailsWithoutOneWayTls() {
ns := s.testInstallation.Metadata.InstallNamespace
s.T().Cleanup(func() {
// ordering here matters if strict validation enabled
npolshakova marked this conversation as resolved.
Show resolved Hide resolved
err := s.testInstallation.Actions.Kubectl().DeleteFile(s.ctx, vsTargetingUpstreamManifestFile, "-n", s.testInstallation.Metadata.InstallNamespace)
s.NoError(err, "can delete vs targeting upstream manifest file")
s.testInstallation.Assertions.EventuallyObjectsNotExist(s.ctx, vsTargetingUpstream(ns))
err = s.testInstallation.Actions.Kubectl().DeleteFile(s.ctx, nginxUpstreamManifestFile)
s.NoError(err, "can delete nginx upstream manifest file")
err = s.testInstallation.Actions.Kubectl().DeleteFile(s.ctx, tlsSecretManifestFile)
s.NoError(err, "can delete tls secret manifest file")
s.testInstallation.Assertions.EventuallyObjectsNotExist(s.ctx, tlsSecret)
})

// ordering here matters if strict validation enabled
Expand All @@ -73,14 +76,17 @@ func (s *clientTlsTestingSuite) TestRouteSecureRequestToUpstreamFailsWithoutOneW
}

func (s *clientTlsTestingSuite) TestRouteSecureRequestToUpstream() {
ns := s.testInstallation.Metadata.InstallNamespace
s.T().Cleanup(func() {
// ordering here matters if strict validation enabled
err := s.testInstallation.Actions.Kubectl().DeleteFile(s.ctx, vsTargetingUpstreamManifestFile, "-n", s.testInstallation.Metadata.InstallNamespace)
jbohanon marked this conversation as resolved.
Show resolved Hide resolved
s.NoError(err, "can delete vs targeting upstream manifest file")
s.testInstallation.Assertions.EventuallyObjectsNotExist(s.ctx, vsTargetingUpstream(ns))
err = s.testInstallation.Actions.Kubectl().DeleteFile(s.ctx, nginxOneWayUpstreamManifestFile)
s.NoError(err, "can delete nginx upstream manifest file")
err = s.testInstallation.Actions.Kubectl().DeleteFile(s.ctx, tlsSecretManifestFile)
s.NoError(err, "can delete tls secret manifest file")
s.testInstallation.Assertions.EventuallyObjectsNotExist(s.ctx, tlsSecret)
})

// ordering here matters if strict validation enabled
Expand All @@ -95,46 +101,52 @@ func (s *clientTlsTestingSuite) TestRouteSecureRequestToUpstream() {
}

func (s *clientTlsTestingSuite) TestRouteSecureRequestToAnnotatedServiceFailsWithoutOneWayTls() {
ns := s.testInstallation.Metadata.InstallNamespace
s.T().Cleanup(func() {
// ordering here matters if strict validation enabled
err := s.testInstallation.Actions.Kubectl().DeleteFile(s.ctx, vsTargetingKubeManifestFile, "-n", s.testInstallation.Metadata.InstallNamespace)
s.NoError(err, "can delete vs targeting upstream manifest file")
s.testInstallation.Assertions.EventuallyObjectsNotExist(s.ctx, vsTargetingKube(ns))
// this is deleted in test cleanup
// err = s.testInstallation.Actions.Kubectl().DeleteFile(s.ctx, annotatedNginxSvcManifestFile)
// s.NoError(err, "can delete nginx upstream manifest file")
err = s.testInstallation.Actions.Kubectl().DeleteFile(s.ctx, tlsSecretManifestFile)
s.NoError(err, "can delete tls secret manifest file")
s.testInstallation.Assertions.EventuallyObjectsNotExist(s.ctx, tlsSecret)
})

// ordering here matters if strict validation enabled
err := s.testInstallation.Actions.Kubectl().ApplyFile(s.ctx, tlsSecretManifestFile)
s.NoError(err, "can apply tls secret manifest file")
err = s.testInstallation.Actions.Kubectl().ApplyFile(s.ctx, annotatedNginxSvcManifestFile)
s.NoError(err, "can apply nginx upstream manifest file")
err = s.testInstallation.Actions.Kubectl().ApplyFile(s.ctx, vsTargetingKubeManifestFile, "-n", s.testInstallation.Metadata.InstallNamespace)
err = s.testInstallation.Actions.Kubectl().ApplyFile(s.ctx, vsTargetingKubeManifestFile, "-n", ns)
s.NoError(err, "can apply vs targeting upstream manifest file")

s.assertEventualResponse(expectedCertVerifyFailedResponse)
}

func (s *clientTlsTestingSuite) TestRouteSecureRequestToAnnotatedService() {
ns := s.testInstallation.Metadata.InstallNamespace
s.T().Cleanup(func() {
// ordering here matters if strict validation enabled
err := s.testInstallation.Actions.Kubectl().DeleteFile(s.ctx, vsTargetingKubeManifestFile, "-n", s.testInstallation.Metadata.InstallNamespace)
err := s.testInstallation.Actions.Kubectl().DeleteFile(s.ctx, vsTargetingKubeManifestFile, "-n", ns)
s.NoError(err, "can delete vs targeting upstream manifest file")
s.testInstallation.Assertions.EventuallyObjectsNotExist(s.ctx, vsTargetingKube(ns))
// this is deleted in test cleanup
// err = s.testInstallation.Actions.Kubectl().DeleteFile(s.ctx, annotatedNginxOneWaySvcManifestFile)
// s.NoError(err, "can delete nginx upstream manifest file")
err = s.testInstallation.Actions.Kubectl().DeleteFile(s.ctx, tlsSecretManifestFile)
s.NoError(err, "can delete tls secret manifest file")
s.testInstallation.Assertions.EventuallyObjectsNotExist(s.ctx, tlsSecret)
})

// ordering here matters if strict validation enabled
err := s.testInstallation.Actions.Kubectl().ApplyFile(s.ctx, tlsSecretManifestFile)
s.NoError(err, "can apply tls secret manifest file")
err = s.testInstallation.Actions.Kubectl().ApplyFile(s.ctx, annotatedNginxOneWaySvcManifestFile)
s.NoError(err, "can apply nginx upstream manifest file")
err = s.testInstallation.Actions.Kubectl().ApplyFile(s.ctx, vsTargetingKubeManifestFile, "-n", s.testInstallation.Metadata.InstallNamespace)
err = s.testInstallation.Actions.Kubectl().ApplyFile(s.ctx, vsTargetingKubeManifestFile, "-n", ns)
s.NoError(err, "can apply vs targeting upstream manifest file")

s.assertEventualResponse(expectedHealthyResponse)
Expand Down
24 changes: 24 additions & 0 deletions test/kubernetes/e2e/features/client_tls/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"path/filepath"

"github.com/onsi/gomega"
kubev1 "github.com/solo-io/gloo/projects/gateway/pkg/api/v1/kube/apis/gateway.solo.io/v1"
"github.com/solo-io/gloo/test/gomega/matchers"
"github.com/solo-io/skv2/codegen/util"
appsv1 "k8s.io/api/apps/v1"
Expand Down Expand Up @@ -35,6 +36,29 @@ var (
return &corev1.Service{ObjectMeta: glooProxyObjectMeta(ns)}
}

vsTargetingKube = func(ns string) *kubev1.VirtualService {
return &kubev1.VirtualService{
ObjectMeta: metav1.ObjectMeta{
Name: "vs-targeting-kube",
Namespace: ns,
},
}
}
vsTargetingUpstream = func(ns string) *kubev1.VirtualService {
return &kubev1.VirtualService{
ObjectMeta: metav1.ObjectMeta{
Name: "vs-targeting-upstream",
Namespace: ns,
},
}
}
tlsSecret = &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: "my-tls",
Namespace: "nginx",
},
}

expectedHealthyResponse = &matchers.HttpResponse{
StatusCode: http.StatusOK,
Body: gomega.ContainSubstring("Welcome to nginx!"),
Expand Down
Loading