本文整理匯總了Golang中github.com/juju/juju/apiserver.ServerMacaroon函數的典型用法代碼示例。如果您正苦於以下問題:Golang ServerMacaroon函數的具體用法?Golang ServerMacaroon怎麽用?Golang ServerMacaroon使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了ServerMacaroon函數的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestServerBakery
func (s *macaroonServerSuite) TestServerBakery(c *gc.C) {
srv := newServer(c, s.State)
defer srv.Stop()
m, err := apiserver.ServerMacaroon(srv)
c.Assert(err, gc.IsNil)
bsvc, err := apiserver.ServerBakeryService(srv)
c.Assert(err, gc.IsNil)
// Check that we can add a third party caveat addressed to the
// discharger, which indirectly ensures that the discharger's public
// key has been added to the bakery service's locator.
m = m.Clone()
err = bsvc.AddCaveat(m, checkers.Caveat{
Location: s.discharger.Location(),
Condition: "true",
})
c.Assert(err, jc.ErrorIsNil)
// Check that we can discharge the macaroon and check it with
// the service.
client := httpbakery.NewClient()
ms, err := client.DischargeAll(m)
c.Assert(err, jc.ErrorIsNil)
err = bsvc.Check(ms, checkers.New())
c.Assert(err, gc.IsNil)
}
示例2: TestNoBakeryWhenNoIdentityURL
func (s *serverSuite) TestNoBakeryWhenNoIdentityURL(c *gc.C) {
srv := newServer(c, s.State)
defer srv.Stop()
// By default, when there is no identity location, no
// bakery service or macaroon is created.
_, err := apiserver.ServerMacaroon(srv)
c.Assert(err, gc.ErrorMatches, "macaroon authentication is not configured")
_, err = apiserver.ServerBakeryService(srv)
c.Assert(err, gc.ErrorMatches, "macaroon authentication is not configured")
}
示例3: TestDischargeFailsWithWrongPublicKey
func (s *macaroonServerWrongPublicKeySuite) TestDischargeFailsWithWrongPublicKey(c *gc.C) {
srv := newServer(c, s.State)
defer srv.Stop()
m, err := apiserver.ServerMacaroon(srv)
c.Assert(err, gc.IsNil)
m = m.Clone()
bsvc, err := apiserver.ServerBakeryService(srv)
c.Assert(err, gc.IsNil)
err = bsvc.AddCaveat(m, checkers.Caveat{
Location: s.discharger.Location(),
Condition: "true",
})
c.Assert(err, gc.IsNil)
client := httpbakery.NewClient()
_, err = client.DischargeAll(m)
c.Assert(err, gc.ErrorMatches, `cannot get discharge from ".*": third party refused discharge: cannot discharge: discharger cannot decode caveat id: public key mismatch`)
}