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

Side by Side Diff: names/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 | « names/user.go ('k') | provider/azure/environ.go » ('j') | 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 names_test 4 package names_test
5 5
6 import ( 6 import (
7 jc "github.com/juju/testing/checkers"
8 gc "launchpad.net/gocheck" 7 gc "launchpad.net/gocheck"
9 8
10 "launchpad.net/juju-core/names" 9 "launchpad.net/juju-core/names"
11 ) 10 )
12 11
13 type userSuite struct{} 12 type userSuite struct{}
14 13
15 var _ = gc.Suite(&userSuite{}) 14 var _ = gc.Suite(&userSuite{})
16 15
16 var validTests = []struct {
17 string string
18 expect bool
19 }{
20 {"", false},
21 {"bob", true},
22 {"Bob", true},
23 {"bOB", true},
24 {"b^b", false},
25 {"bob1", true},
26 {"bob-1", true},
27 {"bob+1", false},
28 {"bob.1", true},
29 {"1bob", false},
30 {"1-bob", false},
31 {"1+bob", false},
32 {"1.bob", false},
33 {"jim.bob+99-1.", false},
34 {"a", false},
35 {"0foo", false},
36 {"foo bar", false},
37 {"bar{}", false},
38 {"bar+foo", false},
39 {"bar_foo", false},
40 {"bar!", false},
41 {"bar^", false},
42 {"bar*", false},
43 {"foo=bar", false},
44 {"foo?", false},
45 {"[bar]", false},
46 {"'foo'", false},
47 {"%bar", false},
48 {"&bar", false},
49 {"#1foo", false},
50 {"bar@ram.u", false},
51 {"not/valid", false},
52 }
53
17 func (s *userSuite) TestUserTag(c *gc.C) { 54 func (s *userSuite) TestUserTag(c *gc.C) {
18 c.Assert(names.UserTag("admin"), gc.Equals, "user-admin") 55 c.Assert(names.UserTag("admin"), gc.Equals, "user-admin")
19 } 56 }
20 57
21 func (s *userSuite) TestIsUser(c *gc.C) { 58 func (s *userSuite) TestIsUser(c *gc.C) {
22 » c.Assert(names.IsUser("admin"), jc.IsTrue) 59 » for i, t := range validTests {
23 » c.Assert(names.IsUser("foo42"), jc.IsTrue) 60 » » c.Logf("test %d: %s", i, t.string)
24 » c.Assert(names.IsUser("not/valid"), jc.IsFalse) 61 » » c.Assert(names.IsUser(t.string), gc.Equals, t.expect, gc.Comment f("%s", t.string))
25 » c.Assert(names.IsUser(""), jc.IsFalse) 62 » }
26 } 63 }
OLDNEW
« no previous file with comments | « names/user.go ('k') | provider/azure/environ.go » ('j') | no next file with comments »

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