本文整理汇总了Golang中github.com/juju/juju/apiserver.ServerBakeryService函数的典型用法代码示例。如果您正苦于以下问题:Golang ServerBakeryService函数的具体用法?Golang ServerBakeryService怎么用?Golang ServerBakeryService使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ServerBakeryService函数的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`)
}