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

Side by Side Diff: state/user_test.go

Issue 92560043: Validate usernames
Patch Set: Validate usernames Created 9 years, 10 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:
View unified diff | Download patch
« no previous file with comments | « state/user.go ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 Canonical Ltd. 1 // Copyright 2013 Canonical Ltd.
2 // Licensed under the AGPLv3, see LICENCE file for details. 2 // Licensed under the AGPLv3, see LICENCE file for details.
3 3
4 package state_test 4 package state_test
5 5
6 import ( 6 import (
7 "regexp" 7 "regexp"
8 8
9 jc "github.com/juju/testing/checkers" 9 jc "github.com/juju/testing/checkers"
10 gc "launchpad.net/gocheck" 10 gc "launchpad.net/gocheck"
11 11
12 "launchpad.net/juju-core/state" 12 "launchpad.net/juju-core/state"
13 "launchpad.net/juju-core/utils" 13 "launchpad.net/juju-core/utils"
14 ) 14 )
15 15
16 type UserSuite struct { 16 type UserSuite struct {
17 ConnSuite 17 ConnSuite
18 } 18 }
19 19
20 var _ = gc.Suite(&UserSuite{}) 20 var _ = gc.Suite(&UserSuite{})
21 21
22 func (s *UserSuite) TestAddUserInvalidNames(c *gc.C) { 22 func (s *UserSuite) TestAddUserInvalidNames(c *gc.C) {
23 for _, name := range []string{ 23 for _, name := range []string{
24 "bar@ram.u",
25 "#1foo",
26 "&bar",
27 "%bar",
28 "foo()",
29 "'foo'",
30 "[bar]",
31 "foo?",
32 "foo=bar",
33 "bar*",
34 "bar^",
35 "bar!",
36 "bar_foo",
37 "bar+foo",
38 "bar{}",
39 "foo bar",
40 "", 24 "",
41 » » "0foo", 25 » » "b^b",
42 » » "a",
43 } { 26 } {
44 u, err := s.State.AddUser(name, "password") 27 u, err := s.State.AddUser(name, "password")
45 c.Assert(err, gc.ErrorMatches, `invalid user name "`+regexp.Quot eMeta(name)+`"`) 28 c.Assert(err, gc.ErrorMatches, `invalid user name "`+regexp.Quot eMeta(name)+`"`)
46 c.Assert(u, gc.IsNil) 29 c.Assert(u, gc.IsNil)
47 } 30 }
48 } 31 }
49 32
50 func (s *UserSuite) TestAddUserValidName(c *gc.C) { 33 func (s *UserSuite) TestAddUserValidName(c *gc.C) {
51 name := "f00-Bar.ram77" 34 name := "f00-Bar.ram77"
52 u, err := s.State.AddUser(name, "password") 35 u, err := s.State.AddUser(name, "password")
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 c.Assert(u.PasswordValid(""), gc.Equals, false) 179 c.Assert(u.PasswordValid(""), gc.Equals, false)
197 180
198 } 181 }
199 182
200 func (s *UserSuite) TestCantDeactivateAdminUser(c *gc.C) { 183 func (s *UserSuite) TestCantDeactivateAdminUser(c *gc.C) {
201 u, err := s.State.User(state.AdminUser) 184 u, err := s.State.User(state.AdminUser)
202 c.Assert(err, gc.IsNil) 185 c.Assert(err, gc.IsNil)
203 err = u.Deactivate() 186 err = u.Deactivate()
204 c.Assert(err, gc.ErrorMatches, "Can't deactivate admin user") 187 c.Assert(err, gc.ErrorMatches, "Can't deactivate admin user")
205 } 188 }
OLDNEW
« no previous file with comments | « state/user.go ('k') | no next file » | no next file with comments »

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