Esempio n. 1
0
func newVault() (storage.Vault, error) {
	sk, err := getVaultKey()
	if err != nil {
		return nil, errgo.Mask(err)
	}

	vaultPath := filepath.Join(*homedirFlagVar, "vault")
	db, err := bolt.Open(vaultPath, 0600, nil)
	if err != nil {
		return nil, errgo.WithCausef(nil, err, "cannot open vault %q", vaultPath)
	}
	return sfbolt.NewVault(db, sk), nil
}
Esempio n. 2
0
func (s *vaultSuite) TestVault(c *gc.C) {
	secKey, err := sf.NewSecretKey()
	v := sfbolt.NewVault(s.db, secKey)

	_, err = v.Current()
	c.Assert(err, gc.ErrorMatches, "empty vault")

	var kp *sf.KeyPair

	kp1, err := sf.NewKeyPair()
	c.Assert(err, gc.IsNil)
	err = v.Put(&kp1)
	c.Assert(err, gc.IsNil)
	kp, err = v.Get(kp1.PublicKey)
	c.Assert(err, gc.IsNil)
	c.Assert(kp, gc.DeepEquals, &kp1)
	kp, err = v.Current()
	c.Assert(err, gc.IsNil)
	c.Assert(kp, gc.DeepEquals, &kp1)

	kp2, err := sf.NewKeyPair()
	c.Assert(err, gc.IsNil)
	err = v.Put(&kp2)
	c.Assert(err, gc.IsNil)
	kp, err = v.Get(kp2.PublicKey)
	c.Assert(err, gc.IsNil)
	c.Assert(kp, gc.DeepEquals, &kp2)
	kp, err = v.Current()
	c.Assert(err, gc.IsNil)
	c.Assert(kp, gc.DeepEquals, &kp2)

	// Can still look up prior key pair by public key.
	kp, err = v.Get(kp1.PublicKey)
	c.Assert(err, gc.IsNil)
	c.Assert(kp, gc.DeepEquals, &kp1)
}