forked from juju/juju
-
Notifications
You must be signed in to change notification settings - Fork 0
/
adminv3_test.go
91 lines (78 loc) · 2.32 KB
/
adminv3_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
84
85
86
87
88
89
90
91
// Copyright 2015 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package apiserver_test
import (
"github.com/juju/errors"
jc "github.com/juju/testing/checkers"
gc "gopkg.in/check.v1"
"gopkg.in/juju/names.v2"
"github.com/juju/juju/api"
"github.com/juju/juju/apiserver"
"github.com/juju/juju/rpc"
"github.com/juju/juju/testing/factory"
)
type loginV3Suite struct {
loginSuite
}
var _ = gc.Suite(&loginV3Suite{
loginSuite{
baseLoginSuite{
setAdminAPI: func(srv *apiserver.Server) {
apiserver.SetAdminAPIVersions(srv, 3)
},
},
},
})
func (s *loginV3Suite) TestClientLoginToEnvironment(c *gc.C) {
info := s.APIInfo(c)
apiState, err := api.Open(info, api.DialOpts{})
c.Assert(err, jc.ErrorIsNil)
defer apiState.Close()
client := apiState.Client()
_, err = client.GetModelConstraints()
c.Assert(err, jc.ErrorIsNil)
}
func (s *loginV3Suite) TestClientLoginToServer(c *gc.C) {
info := s.APIInfo(c)
info.ModelTag = names.ModelTag{}
apiState, err := api.Open(info, api.DialOpts{})
c.Assert(err, jc.ErrorIsNil)
defer apiState.Close()
client := apiState.Client()
_, err = client.GetModelConstraints()
c.Assert(errors.Cause(err), gc.DeepEquals, &rpc.RequestError{
Message: `facade "Client" not supported for controller API connection`,
Code: "not supported",
})
}
func (s *loginV3Suite) TestClientLoginToServerNoAccessToControllerEnv(c *gc.C) {
password := "shhh..."
user := s.Factory.MakeUser(c, &factory.UserParams{
NoModelUser: true,
Password: password,
})
info := s.APIInfo(c)
info.Tag = user.Tag()
info.Password = password
info.ModelTag = names.ModelTag{}
apiState, err := api.Open(info, api.DialOpts{})
c.Assert(err, jc.ErrorIsNil)
defer apiState.Close()
// The user now has last login updated.
err = user.Refresh()
c.Assert(err, jc.ErrorIsNil)
lastLogin, err := user.LastLogin()
c.Assert(err, jc.ErrorIsNil)
c.Assert(lastLogin, gc.NotNil)
}
func (s *loginV3Suite) TestClientLoginToRootOldClient(c *gc.C) {
info := s.APIInfo(c)
info.Tag = nil
info.Password = ""
info.ModelTag = names.ModelTag{}
info.SkipLogin = true
apiState, err := api.Open(info, api.DialOpts{})
c.Assert(err, jc.ErrorIsNil)
err = apiState.APICall("Admin", 2, "", "Login", struct{}{}, nil)
c.Assert(err, gc.ErrorMatches, ".*this version of Juju does not support login from old clients.*")
}