Beispiel #1
0
func (s *CmdSuite) TestHostCRUD(c *C) {
	host := "localhost"
	c.Assert(s.run("host", "upsert", "-name", host), Matches, OK)

	keyPair := testutils.NewTestKeyPair()

	fKey, err := ioutil.TempFile("", "vulcand")
	c.Assert(err, IsNil)
	defer fKey.Close()
	fKey.Write(keyPair.Key)

	fCert, err := ioutil.TempFile("", "vulcand")
	c.Assert(err, IsNil)
	defer fCert.Close()
	fCert.Write(keyPair.Cert)

	c.Assert(s.run("host", "upsert", "-name", host,
		"-privateKey", fKey.Name(), "-cert", fCert.Name(),
		"-ocsp", "-ocspPeriod", "2h", "-ocspResponder", "http://a.com", "-ocspResponder", "http://b.com", "-ocspSkipCheck"), Matches, OK)

	h, err := s.ng.GetHost(engine.HostKey{Name: host})
	c.Assert(err, IsNil)
	c.Assert(h.Settings.KeyPair, DeepEquals, keyPair)

	c.Assert(h.Settings.OCSP.Enabled, Equals, true)
	c.Assert(h.Settings.OCSP.Period, Equals, "2h0m0s")
	c.Assert(h.Settings.OCSP.Responders, DeepEquals, []string{"http://a.com", "http://b.com"})
	c.Assert(h.Settings.OCSP.SkipSignatureCheck, Equals, true)

	c.Assert(s.run("host", "show", "-name", host), Matches, ".*"+host+".*")
	c.Assert(s.run("host", "rm", "-name", host), Matches, OK)
}
Beispiel #2
0
func (s *ApiSuite) TestHostCRUD(c *C) {
	host := engine.Host{Name: "localhost"}
	c.Assert(s.client.UpsertHost(host), IsNil)

	hosts, _ := s.ng.GetHosts()
	c.Assert(len(hosts), Equals, 1)

	hosts, err := s.client.GetHosts()
	c.Assert(hosts, NotNil)
	c.Assert(err, IsNil)
	c.Assert(hosts[0].Name, Equals, "localhost")

	out, err := s.client.GetHost(engine.HostKey{Name: host.Name})
	c.Assert(err, IsNil)
	c.Assert(out.Name, Equals, host.Name)

	host.Settings.KeyPair = testutils.NewTestKeyPair()
	c.Assert(s.client.UpsertHost(host), IsNil)

	out, err = s.ng.GetHost(engine.HostKey{Name: host.Name})
	c.Assert(out.Settings.KeyPair, DeepEquals, host.Settings.KeyPair)

	err = s.client.DeleteHost(engine.HostKey{Name: host.Name})
	c.Assert(err, IsNil)

	hosts, _ = s.ng.GetHosts()
	c.Assert(len(hosts), Equals, 0)

	hosts, err = s.client.GetHosts()
	c.Assert(len(hosts), Equals, 0)
	c.Assert(err, IsNil)
}
Beispiel #3
0
func (s *CmdSuite) TestReadKeyPair(c *C) {
	keyPair := testutils.NewTestKeyPair()

	key, err := secret.NewKeyString()
	c.Assert(err, IsNil)

	fKey, err := ioutil.TempFile("", "vulcand")
	c.Assert(err, IsNil)
	defer fKey.Close()
	fKey.Write(keyPair.Key)

	fCert, err := ioutil.TempFile("", "vulcand")
	c.Assert(err, IsNil)
	defer fCert.Close()
	fCert.Write(keyPair.Cert)

	fSealed, err := ioutil.TempFile("", "vulcand")
	c.Assert(err, IsNil)
	fSealed.Close()

	s.run("secret", "seal_keypair", "-privateKey", fKey.Name(), "-cert", fCert.Name(), "-sealKey", key, "-f", fSealed.Name())

	bytes, err := ioutil.ReadFile(fSealed.Name())
	c.Assert(err, IsNil)

	box, err := secret.NewBoxFromKeyString(key)
	c.Assert(err, IsNil)

	sealed, err := secret.SealedValueFromJSON(bytes)
	data, err := box.Open(sealed)
	c.Assert(err, IsNil)

	outKeyPair, err := engine.KeyPairFromJSON(data)
	c.Assert(err, IsNil)

	c.Assert(outKeyPair, DeepEquals, keyPair)
}