@@ -2,6 +2,8 @@ package _tests_test
22
33import (
44 "os"
5+ "os/user"
6+ "path"
57
68 . "github.com/onsi/ginkgo"
79 . "github.com/onsi/gomega"
@@ -10,38 +12,40 @@ import (
1012var _ = 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})
0 commit comments