summaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
authorMartin Polden <mpolden@mpolden.no>2021-09-01 09:50:26 +0200
committerMartin Polden <mpolden@mpolden.no>2021-09-01 09:50:26 +0200
commita19057840739234484e4e295747d6617b05c302b (patch)
tree0cd6ce0c8172820facd9367841adcb308085acea /client
parentdd6e2c72ae34e2fa79a6fc1c39e88eb7e00a8122 (diff)
Test vespa cert
Diffstat (limited to 'client')
-rw-r--r--client/go/cmd/cert_test.go36
1 files changed, 36 insertions, 0 deletions
diff --git a/client/go/cmd/cert_test.go b/client/go/cmd/cert_test.go
new file mode 100644
index 00000000000..e655f76b0f1
--- /dev/null
+++ b/client/go/cmd/cert_test.go
@@ -0,0 +1,36 @@
+// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+// Author: mpolden
+
+package cmd
+
+import (
+ "fmt"
+ "os"
+ "path/filepath"
+ "strings"
+ "testing"
+
+ "github.com/stretchr/testify/assert"
+)
+
+func TestCert(t *testing.T) {
+ tmpDir := t.TempDir()
+ mockApplicationPackage(t, tmpDir)
+ out := execute(command{args: []string{"cert", "-a", "t1.a1.i1", tmpDir}, configDir: tmpDir}, t, nil)
+
+ pkgCertificate := filepath.Join(tmpDir, "security", "clients.pem")
+ certificate := filepath.Join(tmpDir, ".vespa", "t1.a1.i1", "data-plane-public-cert.pem")
+ privateKey := filepath.Join(tmpDir, ".vespa", "t1.a1.i1", "data-plane-private-key.pem")
+
+ assert.Equal(t, fmt.Sprintf("Success: Certificate written to %s\nSuccess: Certificate written to %s\nSuccess: Private key written to %s\n", pkgCertificate, certificate, privateKey), out)
+
+ out = execute(command{args: []string{"cert", "-a", "t1.a1.i1", tmpDir}, configDir: tmpDir}, t, nil)
+ assert.True(t, strings.HasPrefix(out, "Error: Certificate or private key"))
+}
+
+func mockApplicationPackage(t *testing.T, testDir string) {
+ servicesXML := filepath.Join(testDir, "services.xml")
+ if _, err := os.Create(servicesXML); err != nil {
+ t.Fatal(err)
+ }
+}