Add unit test for testing intermediate CA
@@ -122,14 +122,37 @@ var _ = Describe("InMemoryGenerator", func() {
}
})
- It("creates a CA", func() {
+ Context("creates a root CA", func() {
+
+ var (
+ cert credsgen.Certificate
+ err error
+ )
+
+ BeforeEach(func() {
request.CommonName = "example.com"
- cert, err := generator.GenerateCertificate("foo", request)
+ cert, err = generator.GenerateCertificate("foo", request)
+ Expect(err).ToNot(HaveOccurred())
+
+ parsedCert, err := parseCert(cert.Certificate)
+ Expect(err).ToNot(HaveOccurred())
+
+ Expect(parsedCert.IsCA).To(BeTrue())
+ Expect(cert.PrivateKey).ToNot(BeEmpty())
+ Expect(parsedCert.Subject.CommonName).To(Equal(request.CommonName))
+ })
+
+ It("creates an intermediate CA", func() {
+
+ request.CommonName = "exampleIntermediate.com"
+ request.CA = cert
+ cert, err = generator.GenerateCertificate("foo", request)
Expect(err).ToNot(HaveOccurred())
parsedCert, err := parseCert(cert.Certificate)
Expect(err).ToNot(HaveOccurred())
+ Expect(parsedCert.Issuer.CommonName).To(Equal("example.com"))
Expect(parsedCert.IsCA).To(BeTrue())
Expect(cert.PrivateKey).ToNot(BeEmpty())
Expect(parsedCert.Subject.CommonName).To(Equal(request.CommonName))
@@ -137,6 +160,7 @@ var _ = Describe("InMemoryGenerator", func() {
})
})
})
+})
func parseCert(certificate []byte) (*x509.Certificate, error) {
certBlob, _ := pem.Decode(certificate)
