github.com/cloudfoundry-attic/ltc@v0.0.0-20151123212628-098adc7919fc/ssh/keygen/keygen_test.go (about) 1 package keygen_test 2 3 import ( 4 "bytes" 5 "io" 6 7 . "github.com/onsi/ginkgo" 8 . "github.com/onsi/gomega" 9 10 keygen_package "github.com/cloudfoundry-incubator/ltc/ssh/keygen" 11 ) 12 13 var _ = Describe("KeyGenerator", func() { 14 var fakeReader io.Reader 15 16 BeforeEach(func() { 17 fakeReader = bytes.NewReader([]byte{0xc3, 0x4b, 0x57, 0xf5, 0xf1, 0xb8, 0x10, 0x5e, 0x05, 0x2e, 0xbd, 0x86, 0xc8, 0x66, 0x72, 0xaf}) 18 }) 19 20 Describe("#GenerateRSAPRivateKey", func() { 21 It("generates a pem-encoded RSA key", func() { 22 keygen := &keygen_package.KeyGenerator{fakeReader} 23 private, err := keygen.GenerateRSAPrivateKey(40) 24 Expect(err).NotTo(HaveOccurred()) 25 Expect(private).To(Equal("-----BEGIN RSA PRIVATE KEY-----\nMDACAQACBgCsdAECKwIDAQABAgUOJiA6aQIDDfG9AgMMXgcCAwvHrQIDAr8jAgML\nej0=\n-----END RSA PRIVATE KEY-----\n")) 26 }) 27 }) 28 29 Describe("#GenerateRSAKeyPair", func() { 30 It("generates a pem-encoded RSA key and an ssh authorized key", func() { 31 keygen := &keygen_package.KeyGenerator{fakeReader} 32 private, public, err := keygen.GenerateRSAKeyPair(40) 33 Expect(err).NotTo(HaveOccurred()) 34 Expect(public).To(Equal("ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAABgCsdAECKw==")) 35 Expect(private).To(Equal("-----BEGIN RSA PRIVATE KEY-----\nMDACAQACBgCsdAECKwIDAQABAgUOJiA6aQIDDfG9AgMMXgcCAwvHrQIDAr8jAgML\nej0=\n-----END RSA PRIVATE KEY-----\n")) 36 }) 37 }) 38 // TODO: test errors 39 })