Example #1
0
func MustNew(rootKey []byte, id, loc string) *macaroon.Macaroon {
	m, err := macaroon.New(rootKey, id, loc)
	if err != nil {
		panic(err)
	}
	return m
}
Example #2
0
func (*macaroonSuite) TestMacaroonFieldsTooBig(c *gc.C) {
	rootKey := []byte("secret")
	toobig := make([]byte, macaroon.MaxPacketLen)
	_, err := rand.Reader.Read(toobig)
	c.Assert(err, gc.IsNil)
	_, err = macaroon.New(rootKey, string(toobig), "a location")
	c.Assert(err, gc.ErrorMatches, "macaroon identifier too big")
	_, err = macaroon.New(rootKey, "some id", string(toobig))
	c.Assert(err, gc.ErrorMatches, "macaroon location too big")

	m0 := MustNew(rootKey, "some id", "a location")
	err = m0.AddThirdPartyCaveat(toobig, "3rd party caveat", "remote.com")
	c.Assert(err, gc.ErrorMatches, "caveat verification id too big")
	err = m0.AddThirdPartyCaveat([]byte("shared root key"), string(toobig), "remote.com")
	c.Assert(err, gc.ErrorMatches, "caveat identifier too big")
	err = m0.AddThirdPartyCaveat([]byte("shared root key"), "3rd party caveat", string(toobig))
	c.Assert(err, gc.ErrorMatches, "caveat location too big")
}
Example #3
0
func newMac(w http.ResponseWriter, r *http.Request) {
	m, err := macaroon.New([]byte(secret), "1", "example.com")
	if err != nil {
		w.Write([]byte(err.Error()))
		return
	}
	b, err := m.MarshalJSON()
	if err != nil {
		w.Write([]byte(err.Error()))
		return
	}
	w.Write(b)
}