github.com/cloudbase/juju-core@v0.0.0-20140504232958-a7271ac7912f/utils/ssh/fingerprint_test.go (about)

     1  // Copyright 2014 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package ssh_test
     5  
     6  import (
     7  	gc "launchpad.net/gocheck"
     8  
     9  	"launchpad.net/juju-core/testing/testbase"
    10  	"launchpad.net/juju-core/utils/ssh"
    11  	sshtesting "launchpad.net/juju-core/utils/ssh/testing"
    12  )
    13  
    14  type FingerprintSuite struct {
    15  	testbase.LoggingSuite
    16  }
    17  
    18  var _ = gc.Suite(&FingerprintSuite{})
    19  
    20  func (s *FingerprintSuite) TestKeyFingerprint(c *gc.C) {
    21  	keys := []sshtesting.SSHKey{
    22  		sshtesting.ValidKeyOne,
    23  		sshtesting.ValidKeyTwo,
    24  		sshtesting.ValidKeyThree,
    25  	}
    26  	for _, k := range keys {
    27  		fingerprint, _, err := ssh.KeyFingerprint(k.Key)
    28  		c.Assert(err, gc.IsNil)
    29  		c.Assert(fingerprint, gc.Equals, k.Fingerprint)
    30  	}
    31  }
    32  
    33  func (s *FingerprintSuite) TestKeyFingerprintError(c *gc.C) {
    34  	_, _, err := ssh.KeyFingerprint("invalid key")
    35  	c.Assert(err, gc.ErrorMatches, `generating key fingerprint: invalid authorized_key "invalid key"`)
    36  }