github.com/makyo/juju@v0.0.0-20160425123129-2608902037e9/apiserver/restricted_root_test.go (about) 1 // Copyright 2014 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 restrictedRootSuite struct { 17 testing.BaseSuite 18 19 root rpc.MethodFinder 20 } 21 22 var _ = gc.Suite(&restrictedRootSuite{}) 23 24 func (r *restrictedRootSuite) SetUpTest(c *gc.C) { 25 r.BaseSuite.SetUpTest(c) 26 r.root = apiserver.TestingRestrictedApiHandler(nil) 27 } 28 29 func (r *restrictedRootSuite) assertMethodAllowed(c *gc.C, rootName string, version int, method string) { 30 caller, err := r.root.FindMethod(rootName, version, method) 31 c.Check(err, jc.ErrorIsNil) 32 c.Check(caller, gc.NotNil) 33 } 34 35 func (r *restrictedRootSuite) TestFindAllowedMethod(c *gc.C) { 36 r.assertMethodAllowed(c, "AllModelWatcher", 2, "Next") 37 r.assertMethodAllowed(c, "AllModelWatcher", 2, "Stop") 38 39 r.assertMethodAllowed(c, "ModelManager", 2, "CreateModel") 40 r.assertMethodAllowed(c, "ModelManager", 2, "ListModels") 41 42 r.assertMethodAllowed(c, "UserManager", 1, "AddUser") 43 r.assertMethodAllowed(c, "UserManager", 1, "SetPassword") 44 r.assertMethodAllowed(c, "UserManager", 1, "UserInfo") 45 46 r.assertMethodAllowed(c, "Controller", 2, "AllModels") 47 r.assertMethodAllowed(c, "Controller", 2, "DestroyController") 48 r.assertMethodAllowed(c, "Controller", 2, "ModelConfig") 49 r.assertMethodAllowed(c, "Controller", 2, "ListBlockedModels") 50 } 51 52 func (r *restrictedRootSuite) TestFindDisallowedMethod(c *gc.C) { 53 caller, err := r.root.FindMethod("Client", 1, "FullStatus") 54 55 c.Assert(err, gc.ErrorMatches, `logged in to server, no model, "Client" not supported`) 56 c.Assert(errors.IsNotSupported(err), jc.IsTrue) 57 c.Assert(caller, gc.IsNil) 58 } 59 60 func (r *restrictedRootSuite) TestNonExistentFacade(c *gc.C) { 61 caller, err := r.root.FindMethod("SomeFacade", 0, "Method") 62 63 c.Assert(err, gc.ErrorMatches, `logged in to server, no model, "SomeFacade" not supported`) 64 c.Assert(caller, gc.IsNil) 65 } 66 67 func (r *restrictedRootSuite) TestFindNonExistentMethod(c *gc.C) { 68 caller, err := r.root.FindMethod("ModelManager", 2, "Bar") 69 70 c.Assert(err, gc.ErrorMatches, `no such request - method ModelManager\(2\).Bar is not implemented`) 71 c.Assert(caller, gc.IsNil) 72 } 73 74 func (r *restrictedRootSuite) TestFindMethodNonExistentVersion(c *gc.C) { 75 caller, err := r.root.FindMethod("UserManager", 99999999, "AddUser") 76 77 c.Assert(err, gc.ErrorMatches, `unknown version \(99999999\) of interface "UserManager"`) 78 c.Assert(caller, gc.IsNil) 79 }