Skip to content

Commit

Permalink
e2e: add openssl e2e test
Browse files Browse the repository at this point in the history
Co-authored-by: Markus Rudy <[email protected]>
  • Loading branch information
msanft and burgerdev committed Feb 22, 2024
1 parent 2f543e3 commit e6e99de
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"gopls": {
"formatting.gofumpt": true,
},
"go.buildTags": "e2e",
"go.lintTool": "golangci-lint",
"go.lintFlags": [
"--fast",
Expand Down
61 changes: 61 additions & 0 deletions e2e/openssl/openssl_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
//go:build e2e
// +build e2e

package openssl

import (
"context"
"os"
"testing"
"time"

"github.com/edgelesssys/nunki/e2e/internal/kubeclient"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

// namespace the tests are executed in.
const namespaceEnv = "K8S_NAMESPACE"

/*
This tests an OpenSSL deployment on Nunki.
It does so by:
- Templating the container image into the deployment YAML.
- Exec'ing into the OpenSSL frontend, opening an OpenSSL server and talking mTLS to the OpenSSL backend, asserting that the connection is successful.
- Exec'ing into the OpenSSL client, talking TLS to the OpenSSL frontend, asserting that the connection is successful.
*/
func TestOpenssl(t *testing.T) {
require := require.New(t)
assert := assert.New(t)

ctx, cancel := context.WithTimeout(context.Background(), 1*time.Minute)
defer cancel()

c := kubeclient.NewForTest(t)

namespace := os.Getenv(namespaceEnv)
require.NotEmpty(namespace, "environment variable %q must be set", namespaceEnv)

frontendPods, err := c.PodsFromDeployment(context.Background(), namespace, "openssl-frontend")
require.NoError(err)
require.Len(frontendPods, 1, "pod not found: %s/%s", namespace, "openssl-frontend")

// Call the backend server from the frontend
stdout, stderr, err := c.Exec(ctx, namespace, frontendPods[0].Name,
[]string{"/bin/bash", "-c", `printf "GET / HTTP/1.0\nHost: openssl-backend\n" | openssl s_client -connect openssl-backend:443 -verify_return_error -CAfile /tls-config/MeshCACert.pem -cert /tls-config/certChain.pem -key /tls-config/key.pem`},
)
t.Log(stdout)
require.NoError(err, "stderr: %q", stderr)

// Call the frontend server from the client
clientPods, err := c.PodsFromDeployment(context.Background(), namespace, "openssl-client")
require.NoError(err)
require.Len(clientPods, 1)

stdout, stderr, err = c.Exec(ctx, namespace, clientPods[0].Name,
[]string{"/bin/bash", "-c", "echo \"THIS IS A TEST MESSAGE\" | openssl s_client -connect openssl-frontend:443 -verify_return_error -CAfile /tls-config/RootCACert.pem"},
)
require.NoError(err, "stdout: %s, stderr: %s", stdout, stderr)
assert.Contains(stdout, "Verification: OK")
}

0 comments on commit e6e99de

Please sign in to comment.