1
// Copyright 2014 Canonical Ltd.
2
// Licensed under the AGPLv3, see LICENCE file for details.
7
"github.com/juju/errors"
8
jc "github.com/juju/testing/checkers"
11
"github.com/juju/juju/apiserver"
12
"github.com/juju/juju/rpc"
13
"github.com/juju/juju/testing"
16
type restrictedRootSuite struct {
22
var _ = gc.Suite(&restrictedRootSuite{})
24
func (r *restrictedRootSuite) SetUpTest(c *gc.C) {
25
r.BaseSuite.SetUpTest(c)
26
r.root = apiserver.TestingRestrictedApiHandler(nil)
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)
35
func (r *restrictedRootSuite) TestFindAllowedMethod(c *gc.C) {
36
r.assertMethodAllowed(c, "AllModelWatcher", 2, "Next")
37
r.assertMethodAllowed(c, "AllModelWatcher", 2, "Stop")
39
r.assertMethodAllowed(c, "ModelManager", 2, "CreateModel")
40
r.assertMethodAllowed(c, "ModelManager", 2, "ListModels")
42
r.assertMethodAllowed(c, "UserManager", 1, "AddUser")
43
r.assertMethodAllowed(c, "UserManager", 1, "SetPassword")
44
r.assertMethodAllowed(c, "UserManager", 1, "UserInfo")
46
r.assertMethodAllowed(c, "Controller", 3, "AllModels")
47
r.assertMethodAllowed(c, "Controller", 3, "DestroyController")
48
r.assertMethodAllowed(c, "Controller", 3, "ModelConfig")
49
r.assertMethodAllowed(c, "Controller", 3, "ListBlockedModels")
52
func (r *restrictedRootSuite) TestFindDisallowedMethod(c *gc.C) {
53
caller, err := r.root.FindMethod("Client", 1, "FullStatus")
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)
60
func (r *restrictedRootSuite) TestNonExistentFacade(c *gc.C) {
61
caller, err := r.root.FindMethod("SomeFacade", 0, "Method")
63
c.Assert(err, gc.ErrorMatches, `logged in to server, no model, "SomeFacade" not supported`)
64
c.Assert(caller, gc.IsNil)
67
func (r *restrictedRootSuite) TestFindNonExistentMethod(c *gc.C) {
68
caller, err := r.root.FindMethod("ModelManager", 2, "Bar")
70
c.Assert(err, gc.ErrorMatches, `no such request - method ModelManager\(2\).Bar is not implemented`)
71
c.Assert(caller, gc.IsNil)
74
func (r *restrictedRootSuite) TestFindMethodNonExistentVersion(c *gc.C) {
75
caller, err := r.root.FindMethod("UserManager", 99999999, "AddUser")
77
c.Assert(err, gc.ErrorMatches, `unknown version \(99999999\) of interface "UserManager"`)
78
c.Assert(caller, gc.IsNil)