github.com/juju/juju@v0.0.0-20240430160146-1752b71fcf00/apiserver/restrict_anonymous_test.go (about) 1 // Copyright 2017 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package apiserver_test 5 6 import ( 7 "github.com/juju/errors" 8 jc "github.com/juju/testing/checkers" 9 gc "gopkg.in/check.v1" 10 11 "github.com/juju/juju/apiserver" 12 "github.com/juju/juju/rpc" 13 "github.com/juju/juju/testing" 14 ) 15 16 type restrictAnonymousSuite struct { 17 testing.BaseSuite 18 root rpc.Root 19 } 20 21 var _ = gc.Suite(&restrictAnonymousSuite{}) 22 23 func (s *restrictAnonymousSuite) SetUpSuite(c *gc.C) { 24 s.BaseSuite.SetUpSuite(c) 25 s.root = apiserver.TestingAnonymousRoot() 26 } 27 28 func (s *restrictAnonymousSuite) TestAllowed(c *gc.C) { 29 s.assertMethod(c, "CrossModelRelations", 2, "RegisterRemoteRelations") 30 } 31 32 func (s *restrictAnonymousSuite) TestNotAllowed(c *gc.C) { 33 caller, err := s.root.FindMethod("Client", clientFacadeVersion, "FullStatus") 34 c.Assert(err, gc.ErrorMatches, `facade "Client" not supported for anonymous API connections`) 35 c.Assert(errors.IsNotSupported(err), jc.IsTrue) 36 c.Assert(caller, gc.IsNil) 37 } 38 39 func (s *restrictAnonymousSuite) assertMethod(c *gc.C, facadeName string, version int, method string) { 40 caller, err := s.root.FindMethod(facadeName, version, method) 41 c.Check(err, jc.ErrorIsNil) 42 c.Check(caller, gc.NotNil) 43 }