Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1248)

Delta Between Two Patch Sets: state/apiserver/common/password_test.go

Issue 9738043: cmd/jujud: do not change password
Left Patch Set: Created 11 years, 10 months ago
Right Patch Set: cmd/jujud: do not change password Created 11 years, 9 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « state/apiserver/common/password.go ('k') | state/apiserver/login_test.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 // Copyright 2013 Canonical Ltd.
2 // Licensed under the AGPLv3, see LICENCE file for details.
3
4 package common_test
5
6 import (
7 "fmt"
8 . "launchpad.net/gocheck"
9 "launchpad.net/juju-core/errors"
10 "launchpad.net/juju-core/state"
11 "launchpad.net/juju-core/state/api"
12 "launchpad.net/juju-core/state/api/params"
13 "launchpad.net/juju-core/state/apiserver/common"
14 stdtesting "testing"
15 )
16
17 type passwordSuite struct{}
18
19 func TestAll(t *stdtesting.T) {
20 TestingT(t)
21 }
22
23 var _ = Suite(passwordSuite{})
24
25 func (passwordSuite) TestSetPasswords(c *C) {
26 st := &fakeState{
27 entities: map[string]state.TaggedAuthenticator{
28 "x0": &fakeAuthenticator{},
29 "x1": &fakeAuthenticator{},
30 "x2": &fakeAuthenticator{
31 err: fmt.Errorf("x2 error"),
32 },
33 "x3": &fakeAuthenticatorWithMongoPass{},
34 },
35 }
36 pc := common.NewMockPasswordChanger(st, func(tag string) bool {
37 return tag != "x0"
38 })
39 var changes []params.PasswordChange
40 for i := 0; i < 4; i++ {
41 tag := fmt.Sprintf("x%d", i)
42 changes = append(changes, params.PasswordChange{
43 Tag: tag,
44 Password: fmt.Sprintf("%spass", tag),
45 })
46 }
47 results := pc.SetPasswords(params.PasswordChanges{
48 Changes: changes,
49 })
50 c.Assert(results, DeepEquals, params.ErrorResults{
51 Errors: []*params.Error{{
52 Message: "permission denied",
53 Code: api.CodeUnauthorized,
54 },
55 nil, {
56 Message: "x2 error",
57 },
58 nil,
59 }})
60 c.Assert(st.entities["x0"].(*fakeAuthenticator).pass, Equals, "")
61 c.Assert(st.entities["x1"].(*fakeAuthenticator).pass, Equals, "x1pass")
62 c.Assert(st.entities["x2"].(*fakeAuthenticator).pass, Equals, "")
63 c.Assert(st.entities["x3"].(*fakeAuthenticatorWithMongoPass).pass, Equal s, "x3pass")
64 c.Assert(st.entities["x3"].(*fakeAuthenticatorWithMongoPass).mongoPass, Equals, "x3pass")
65 }
66
67 type fakeState struct {
68 entities map[string]state.TaggedAuthenticator
69 }
70
71 func (st *fakeState) Authenticator(tag string) (state.TaggedAuthenticator, error ) {
72 if auth, ok := st.entities[tag]; ok {
73 return auth, nil
74 }
75 return nil, errors.NotFoundf("entity %q", tag)
76 }
77
78 type fakeAuthenticator struct {
79 err error
80 pass string
81 }
82
83 func (a *fakeAuthenticator) Tag() string {
84 panic("Tag not implemented")
85 }
86
87 func (a *fakeAuthenticator) Refresh() error {
88 panic("Refresh not implemented")
89 }
90
91 func (a *fakeAuthenticator) PasswordValid(string) bool {
92 panic("PasswordValid not implemented")
93 }
94
95 func (a *fakeAuthenticator) SetPassword(pass string) error {
96 if a.err != nil {
97 return a.err
98 }
99 a.pass = pass
100 return nil
101 }
102
103 type fakeAuthenticatorWithMongoPass struct {
104 fakeAuthenticator
105 mongoPass string
106 }
107
108 func (a *fakeAuthenticatorWithMongoPass) SetMongoPassword(pass string) error {
109 if a.err != nil {
110 return a.err
111 }
112 a.mongoPass = pass
113 return nil
114 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b