Example #1
0
func (s *certPoolSuite) TestCreateCertPoolEmptyDir(c *gc.C) {
	certDir := c.MkDir()
	s.PatchValue(api.CertDir, certDir)

	pool, err := api.CreateCertPool("")
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(pool.Subjects(), gc.HasLen, 0)
	c.Assert(s.logs.messages, gc.HasLen, 1)
	c.Assert(s.logs.messages[0], gc.Matches, `DEBUG added 0 certs to the pool from .*`)
}
Example #2
0
func (s *certPoolSuite) TestCreateCertPoolLogsBadCerts(c *gc.C) {
	certDir := c.MkDir()
	s.PatchValue(api.CertDir, certDir)
	c.Assert(ioutil.WriteFile(filepath.Join(certDir, "broken.pem"), []byte("blah"), 0644), jc.ErrorIsNil)

	pool, err := api.CreateCertPool("")
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(pool.Subjects(), gc.HasLen, 0)
	c.Assert(s.logs.messages, gc.HasLen, 2)
	c.Assert(s.logs.messages[0], gc.Matches, `INFO error parsing cert ".*broken.pem": .*`)
	c.Assert(s.logs.messages[1], gc.Matches, `DEBUG added 0 certs to the pool from .*`)
}
Example #3
0
func (s *certPoolSuite) TestCreateCertPoolLoadsOnlyPEMFiles(c *gc.C) {
	certDir := c.MkDir()
	s.PatchValue(api.CertDir, certDir)
	s.addCert(c, filepath.Join(certDir, "first.pem"))
	c.Assert(ioutil.WriteFile(filepath.Join(certDir, "second.cert"), []byte("blah"), 0644), jc.ErrorIsNil)

	pool, err := api.CreateCertPool("")
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(pool.Subjects(), gc.HasLen, 1)
	c.Assert(s.logs.messages, gc.HasLen, 1)
	c.Assert(s.logs.messages[0], gc.Matches, `DEBUG added 1 certs to the pool from .*`)
}
Example #4
0
func (s *certPoolSuite) TestCreateCertPoolLoadsPEMFiles(c *gc.C) {
	certDir := c.MkDir()
	s.PatchValue(api.CertDir, certDir)
	s.addCert(c, filepath.Join(certDir, "first.pem"))
	s.addCert(c, filepath.Join(certDir, "second.pem"))
	s.addCert(c, filepath.Join(certDir, "third.pem"))

	pool, err := api.CreateCertPool("")
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(pool.Subjects(), gc.HasLen, 3)
	c.Assert(s.logs.messages, gc.HasLen, 1)
	c.Assert(s.logs.messages[0], gc.Matches, `DEBUG added 3 certs to the pool from .*`)
}
Example #5
0
func (s *certPoolSuite) TestCreateCertPoolNotADir(c *gc.C) {
	certDir := filepath.Join(c.MkDir(), "missing")
	s.PatchValue(api.CertDir, certDir)
	// Make the certDir a file instead...
	c.Assert(ioutil.WriteFile(certDir, []byte("blah"), 0644), jc.ErrorIsNil)

	pool, err := api.CreateCertPool("")
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(pool.Subjects(), gc.HasLen, 0)

	c.Assert(s.logs.messages, gc.HasLen, 1)
	c.Assert(s.logs.messages[0], gc.Matches, `INFO cert dir ".*" is not a directory`)
}
Example #6
0
func (s *certPoolSuite) TestCreateCertPoolNoDir(c *gc.C) {
	certDir := filepath.Join(c.MkDir(), "missing")
	s.PatchValue(api.CertDir, certDir)

	pool, err := api.CreateCertPool("")
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(pool.Subjects(), gc.HasLen, 0)

	c.Assert(s.logs.messages, gc.HasLen, 1)
	// The directory not existing is likely to happen a lot, so it is only
	// logged out at trace to help be explicit in the case where detailed
	// debugging is needed.
	c.Assert(s.logs.messages[0], gc.Matches, `TRACE cert dir ".*" does not exist`)
}
Example #7
0
func (*certPoolSuite) TestCreateCertPoolTestCert(c *gc.C) {
	pool, err := api.CreateCertPool(testing.CACert)
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(pool.Subjects(), gc.HasLen, 1)
}
Example #8
0
func (*certPoolSuite) TestCreateCertPoolNoCert(c *gc.C) {
	pool, err := api.CreateCertPool("")
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(pool.Subjects(), gc.HasLen, 0)
}