-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Markus Rudy <[email protected]>
- Loading branch information
Showing
2 changed files
with
62 additions
and
0 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
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,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") | ||
} |