From 32b038c639cb943d67351964bd5f9007ff3119c0 Mon Sep 17 00:00:00 2001 From: Andrew Keesler Date: Thu, 11 Mar 2021 10:02:28 -0500 Subject: [PATCH] test/integration: add 'kubectl cp' test to TestImpersonationProxy Signed-off-by: Andrew Keesler --- .../concierge_impersonation_proxy_test.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/test/integration/concierge_impersonation_proxy_test.go b/test/integration/concierge_impersonation_proxy_test.go index 520eda31..05d2b3f7 100644 --- a/test/integration/concierge_impersonation_proxy_test.go +++ b/test/integration/concierge_impersonation_proxy_test.go @@ -507,10 +507,22 @@ func TestImpersonationProxy(t *testing.T) { //nolint:gocyclo // yeah, it's compl // Try "kubectl exec" through the impersonation proxy. echoString := "hello world" - stdout, _, err := runKubectl("exec", "--namespace", env.ConciergeNamespace, podName, "--", "echo", echoString) + remoteEchoFile := fmt.Sprintf("/tmp/test-impersonation-proxy-echo-file-%d.txt", time.Now().Unix()) + stdout, _, err := runKubectl("exec", "--namespace", env.ConciergeNamespace, podName, "--", "bash", "-c", fmt.Sprintf(`echo "%s" | tee %s`, echoString, remoteEchoFile)) require.NoError(t, err, `"kubectl exec" failed`) require.Equal(t, echoString+"\n", stdout) + // run the kubectl cp command + localEchoFile := filepath.Join(tempDir, filepath.Base(remoteEchoFile)) + _, _, err = runKubectl("cp", fmt.Sprintf("%s/%s:%s", env.ConciergeNamespace, podName, remoteEchoFile), localEchoFile) + require.NoError(t, err, `"kubectl cp" failed`) + localEchoFileData, err := os.ReadFile(localEchoFile) + require.NoError(t, err) + require.Equal(t, echoString+"\n", string(localEchoFileData)) + defer func() { + _, _, _ = runKubectl("exec", "--namespace", env.ConciergeNamespace, podName, "--", "rm", remoteEchoFile) // cleanup remote echo file + }() + // run the kubectl port-forward command timeout, cancelFunc := context.WithTimeout(ctx, 2*time.Minute) defer cancelFunc()