github.com/technosophos/deis@v1.7.1-0.20150915173815-f9005256004b/builder/sshd/sshd_test.go (about) 1 package sshd 2 3 import ( 4 "testing" 5 6 "github.com/Masterminds/cookoo" 7 "golang.org/x/crypto/ssh" 8 ) 9 10 // TestAuthKey tests the AuthKey command for authorizing public keys. 11 func TestAuthKey(t *testing.T) { 12 reg, router, cxt := cookoo.Cookoo() 13 14 key, err := sshTestingClientKey() 15 if err != nil { 16 t.Fatal(err) 17 } 18 19 cxt.Put("cookoo.Router", router) 20 cxt.Put("authorizedKeys", []string{testingClientPubKey}) 21 cxt.Put("key", key.PublicKey()) 22 cxt.Put("metadata", &connMetadata{}) 23 24 reg.AddRoute(cookoo.Route{ 25 Name: "auth", Help: "Authenticate a route.", 26 Does: cookoo.Tasks{ 27 cookoo.Cmd{ 28 Name: "auth", 29 Fn: AuthKey, 30 Using: []cookoo.Param{ 31 {Name: "key", From: "cxt:key"}, 32 {Name: "authorizedKeys", From: "cxt:authorizedKeys"}, 33 {Name: "metadata", From: "cxt:metadata"}, 34 }, 35 }, 36 }, 37 }) 38 if err := router.HandleRequest("auth", cxt, true); err != nil { 39 t.Fatalf("Failed auth run with %s", err) 40 } 41 42 auth := cxt.Get("auth", &ssh.Permissions{}).(*ssh.Permissions) 43 if user, ok := auth.Extensions["user"]; !ok { 44 t.Errorf("Expected a user, but got none.") 45 } else if user != "deis" { 46 t.Errorf("Expected user to be 'deis', got '%s'", user) 47 } 48 } 49 50 func TestFingerprint(t *testing.T) { 51 key, _ := sshTestingClientKey() 52 fp := Fingerprint(key.PublicKey()) 53 if fp != testingClientFingerprint { 54 t.Errorf("Expected fingerprint %s to match %s.", fp, testingClientFingerprint) 55 } 56 }