forked from juju/juju
-
Notifications
You must be signed in to change notification settings - Fork 0
/
controlleruser_test.go
83 lines (69 loc) · 2.67 KB
/
controlleruser_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Copyright 2016 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package state_test
import (
"github.com/juju/errors"
"github.com/juju/names/v4"
jc "github.com/juju/testing/checkers"
gc "gopkg.in/check.v1"
"github.com/juju/juju/core/permission"
"github.com/juju/juju/testing/factory"
)
type ControllerUserSuite struct {
ConnSuite
}
var _ = gc.Suite(&ControllerUserSuite{})
func (s *ControllerUserSuite) TestDefaultAccessControllerUser(c *gc.C) {
user := s.Factory.MakeUser(c,
&factory.UserParams{
Name: "validusername",
})
_ = s.Factory.MakeUser(c, &factory.UserParams{Name: "createdby"})
t := user.Tag()
userTag := t.(names.UserTag)
ctag := names.NewControllerTag(s.State.ControllerUUID())
controllerUser, err := s.State.UserAccess(userTag, ctag)
c.Assert(err, jc.ErrorIsNil)
c.Assert(controllerUser.Access, gc.Equals, permission.LoginAccess)
}
func (s *ControllerUserSuite) TestSetAccessControllerUser(c *gc.C) {
user := s.Factory.MakeUser(c,
&factory.UserParams{
Name: "validusername",
})
_ = s.Factory.MakeUser(c, &factory.UserParams{Name: "createdby"})
t := user.Tag()
userTag := t.(names.UserTag)
ctag := names.NewControllerTag(s.State.ControllerUUID())
controllerUser, err := s.State.UserAccess(userTag, ctag)
c.Assert(err, jc.ErrorIsNil)
c.Assert(controllerUser.Access, gc.Equals, permission.LoginAccess)
s.State.SetUserAccess(userTag, ctag, permission.SuperuserAccess)
controllerUser, err = s.State.UserAccess(user.UserTag(), ctag)
c.Assert(err, jc.ErrorIsNil)
c.Assert(controllerUser.Access, gc.Equals, permission.SuperuserAccess)
}
func (s *ControllerUserSuite) TestRemoveControllerUser(c *gc.C) {
user := s.Factory.MakeUser(c, &factory.UserParams{Name: "validUsername"})
ctag := names.NewControllerTag(s.State.ControllerUUID())
_, err := s.State.UserAccess(user.UserTag(), ctag)
c.Assert(err, jc.ErrorIsNil)
err = s.State.RemoveUserAccess(user.UserTag(), ctag)
c.Assert(err, jc.ErrorIsNil)
_, err = s.State.UserAccess(user.UserTag(), ctag)
c.Assert(err, jc.Satisfies, errors.IsNotFound)
}
func (s *ControllerUserSuite) TestRemoveControllerUserSucceeds(c *gc.C) {
user := s.Factory.MakeUser(c, &factory.UserParams{})
ctag := names.NewControllerTag(s.State.ControllerUUID())
err := s.State.RemoveUserAccess(user.UserTag(), ctag)
c.Assert(err, jc.ErrorIsNil)
}
func (s *ControllerUserSuite) TestRemoveControllerUserFails(c *gc.C) {
user := s.Factory.MakeUser(c, &factory.UserParams{})
ctag := names.NewControllerTag(s.State.ControllerUUID())
err := s.State.RemoveUserAccess(user.UserTag(), ctag)
c.Assert(err, jc.ErrorIsNil)
err = s.State.RemoveUserAccess(user.UserTag(), ctag)
c.Assert(err, jc.Satisfies, errors.IsNotFound)
}