Skip to content

Commit a9142e9

Browse files
mboersmaarschles
authored andcommitted
fix(_tests): get keys tests working
1 parent ba6049b commit a9142e9

2 files changed

Lines changed: 34 additions & 30 deletions

File tree

_tests/keys_test.go

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package _tests_test
22

33
import (
44
"os"
5+
"os/user"
6+
"path"
57

68
. "github.com/onsi/ginkgo"
79
. "github.com/onsi/gomega"
@@ -10,38 +12,40 @@ import (
1012
var _ = Describe("Keys", func() {
1113
key := testUser
1214

13-
BeforeEach(func() {
14-
addKey(key)
15-
})
16-
17-
AfterEach(func() {
18-
// remove the generated ssh key
19-
key := testUser
20-
execute("deis keys:remove %s", key)
21-
err := os.Remove(key)
22-
Expect(err).NotTo(HaveOccurred())
23-
err = os.Remove(key + ".pub")
24-
Expect(err).NotTo(HaveOccurred())
25-
})
15+
Context("when logged in as a normal user", func() {
16+
BeforeEach(func() {
17+
login(url, testUser, testPassword)
18+
createKey(testUser)
19+
})
2620

27-
Context("with a new key", func() {
21+
AfterEach(func() {
22+
// remove the generated ssh key
23+
var home string
24+
if user, err := user.Current(); err != nil {
25+
home = "~"
26+
} else {
27+
home = user.HomeDir
28+
}
29+
path := path.Join(home, ".ssh", testUser)
30+
err := os.Remove(path)
31+
Expect(err).NotTo(HaveOccurred())
32+
err = os.Remove(path + ".pub")
33+
Expect(err).NotTo(HaveOccurred())
34+
})
2835

29-
It("can add the key", func() {
30-
output, err := execute("deis keys:add %s.pub", key)
36+
It("can add, list, and remove a key", func() {
37+
output, err := execute("deis keys:add ~/.ssh/%s.pub", key)
3138
Expect(err).NotTo(HaveOccurred())
3239
Expect(output).To(ContainSubstring("Uploading %s.pub to deis... done", key))
3340
output, err = execute("deis keys:list")
3441
Expect(err).NotTo(HaveOccurred())
35-
Expect(output).To(ContainSubstring("%s@deis.com", key))
36-
})
37-
38-
It("can remove the key", func() {
39-
output, err := execute("deis keys:remove %s@deis.com", key)
42+
Expect(output).To(ContainSubstring("%s ssh-rsa", key))
43+
output, err = execute("deis keys:remove %s", key)
4044
Expect(err).NotTo(HaveOccurred())
41-
Expect(output).To(ContainSubstring("Removing %s@deis.com SSH Key... done", key))
45+
Expect(output).To(ContainSubstring("Removing %s SSH Key... done", key))
4246
output, err = execute("deis keys")
4347
Expect(err).NotTo(HaveOccurred())
44-
Expect(output).NotTo(ContainSubstring("%s@deis.com", key))
48+
Expect(output).NotTo(ContainSubstring("%s ssh-rsa", key))
4549
})
4650
})
4751
})

_tests/tests_suite_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ var _ = BeforeSuite(func() {
5353

5454
// register the test user and add a key
5555
register(url, testUser, testPassword, testEmail)
56-
addKey("deis-test")
56+
createKey("deis-test")
57+
output, err := execute("deis keys:add ~/.ssh/deis-test.pub")
58+
Expect(err).NotTo(HaveOccurred())
59+
Expect(output).To(ContainSubstring("Uploading deis-test.pub to deis... done"))
5760
})
5861

5962
var _ = AfterSuite(func() {
@@ -108,7 +111,7 @@ func execute(cmdLine string, args ...interface{}) (string, error) {
108111
return stdout.String(), nil
109112
}
110113

111-
func addKey(name string) {
114+
func createKey(name string) {
112115
var home string
113116
if user, err := user.Current(); err != nil {
114117
home = "~"
@@ -118,16 +121,13 @@ func addKey(name string) {
118121
path := path.Join(home, ".ssh", name)
119122
// create the key under ~/.ssh/<name> if it doesn't already exist
120123
if _, err := os.Stat(path); os.IsNotExist(err) {
121-
cmd := "ssh-keygen -q -t rsa -b 4096 -C otto.test@deis.com -f %s -N ''"
122-
_, err := execute(cmd, path)
124+
cmd := "ssh-keygen -q -t rsa -b 4096 -C %s -f %s -N ''"
125+
_, err := execute(cmd, name, path)
123126
Expect(err).NotTo(HaveOccurred())
124127
}
125128
// add the key to ssh-agent
126129
_, err := execute("eval $(ssh-agent) && ssh-add %s", path)
127130
Expect(err).NotTo(HaveOccurred())
128-
// add the public key to deis (assumes the user is logged in)
129-
_, err = execute("deis keys:add %s.pub", path)
130-
Expect(err).NotTo(HaveOccurred())
131131
}
132132

133133
func getController() string {

0 commit comments

Comments
 (0)