##// END OF EJS Templates
renamed some leftover name -> firstname
marcink -
r2595:6c83dc02 beta
parent child Browse files
Show More
@@ -1,310 +1,310
1 1 """ this is forms validation classes
2 2 http://formencode.org/module-formencode.validators.html
3 3 for list off all availible validators
4 4
5 5 we can create our own validators
6 6
7 7 The table below outlines the options which can be used in a schema in addition to the validators themselves
8 8 pre_validators [] These validators will be applied before the schema
9 9 chained_validators [] These validators will be applied after the schema
10 10 allow_extra_fields False If True, then it is not an error when keys that aren't associated with a validator are present
11 11 filter_extra_fields False If True, then keys that aren't associated with a validator are removed
12 12 if_key_missing NoDefault If this is given, then any keys that aren't available but are expected will be replaced with this value (and then validated). This does not override a present .if_missing attribute on validators. NoDefault is a special FormEncode class to mean that no default values has been specified and therefore missing keys shouldn't take a default value.
13 13 ignore_key_missing False If True, then missing keys will be missing in the result, if the validator doesn't have .if_missing on it already
14 14
15 15
16 16 <name> = formencode.validators.<name of validator>
17 17 <name> must equal form name
18 18 list=[1,2,3,4,5]
19 19 for SELECT use formencode.All(OneOf(list), Int())
20 20
21 21 """
22 22 import logging
23 23
24 24 import formencode
25 25 from formencode import All
26 26
27 27 from pylons.i18n.translation import _
28 28
29 29 from rhodecode.model import validators as v
30 30 from rhodecode import BACKENDS
31 31
32 32 log = logging.getLogger(__name__)
33 33
34 34
35 35 class LoginForm(formencode.Schema):
36 36 allow_extra_fields = True
37 37 filter_extra_fields = True
38 38 username = v.UnicodeString(
39 39 strip=True,
40 40 min=1,
41 41 not_empty=True,
42 42 messages={
43 43 'empty': _(u'Please enter a login'),
44 44 'tooShort': _(u'Enter a value %(min)i characters long or more')}
45 45 )
46 46
47 47 password = v.UnicodeString(
48 48 strip=False,
49 49 min=3,
50 50 not_empty=True,
51 51 messages={
52 52 'empty': _(u'Please enter a password'),
53 53 'tooShort': _(u'Enter %(min)i characters or more')}
54 54 )
55 55
56 56 remember = v.StringBoolean(if_missing=False)
57 57
58 58 chained_validators = [v.ValidAuth()]
59 59
60 60
61 61 def UserForm(edit=False, old_data={}):
62 62 class _UserForm(formencode.Schema):
63 63 allow_extra_fields = True
64 64 filter_extra_fields = True
65 65 username = All(v.UnicodeString(strip=True, min=1, not_empty=True),
66 66 v.ValidUsername(edit, old_data))
67 67 if edit:
68 68 new_password = All(
69 69 v.ValidPassword(),
70 70 v.UnicodeString(strip=False, min=6, not_empty=False)
71 71 )
72 72 password_confirmation = All(
73 73 v.ValidPassword(),
74 74 v.UnicodeString(strip=False, min=6, not_empty=False),
75 75 )
76 76 admin = v.StringBoolean(if_missing=False)
77 77 else:
78 78 password = All(
79 79 v.ValidPassword(),
80 80 v.UnicodeString(strip=False, min=6, not_empty=True)
81 81 )
82 82 password_confirmation = All(
83 83 v.ValidPassword(),
84 84 v.UnicodeString(strip=False, min=6, not_empty=False)
85 85 )
86 86
87 87 active = v.StringBoolean(if_missing=False)
88 88 firstname = v.UnicodeString(strip=True, min=1, not_empty=False)
89 89 lastname = v.UnicodeString(strip=True, min=1, not_empty=False)
90 90 email = All(v.Email(not_empty=True), v.UniqSystemEmail(old_data))
91 91
92 92 chained_validators = [v.ValidPasswordsMatch()]
93 93
94 94 return _UserForm
95 95
96 96
97 97 def UsersGroupForm(edit=False, old_data={}, available_members=[]):
98 98 class _UsersGroupForm(formencode.Schema):
99 99 allow_extra_fields = True
100 100 filter_extra_fields = True
101 101
102 102 users_group_name = All(
103 103 v.UnicodeString(strip=True, min=1, not_empty=True),
104 104 v.ValidUsersGroup(edit, old_data)
105 105 )
106 106
107 107 users_group_active = v.StringBoolean(if_missing=False)
108 108
109 109 if edit:
110 110 users_group_members = v.OneOf(
111 111 available_members, hideList=False, testValueList=True,
112 112 if_missing=None, not_empty=False
113 113 )
114 114
115 115 return _UsersGroupForm
116 116
117 117
118 118 def ReposGroupForm(edit=False, old_data={}, available_groups=[]):
119 119 class _ReposGroupForm(formencode.Schema):
120 120 allow_extra_fields = True
121 121 filter_extra_fields = False
122 122
123 123 group_name = All(v.UnicodeString(strip=True, min=1, not_empty=True),
124 124 v.SlugifyName())
125 125 group_description = v.UnicodeString(strip=True, min=1,
126 126 not_empty=True)
127 127 group_parent_id = v.OneOf(available_groups, hideList=False,
128 128 testValueList=True,
129 129 if_missing=None, not_empty=False)
130 130
131 131 chained_validators = [v.ValidReposGroup(edit, old_data),
132 132 v.ValidPerms('group')]
133 133
134 134 return _ReposGroupForm
135 135
136 136
137 137 def RegisterForm(edit=False, old_data={}):
138 138 class _RegisterForm(formencode.Schema):
139 139 allow_extra_fields = True
140 140 filter_extra_fields = True
141 141 username = All(
142 142 v.ValidUsername(edit, old_data),
143 143 v.UnicodeString(strip=True, min=1, not_empty=True)
144 144 )
145 145 password = All(
146 146 v.ValidPassword(),
147 147 v.UnicodeString(strip=False, min=6, not_empty=True)
148 148 )
149 149 password_confirmation = All(
150 150 v.ValidPassword(),
151 151 v.UnicodeString(strip=False, min=6, not_empty=True)
152 152 )
153 153 active = v.StringBoolean(if_missing=False)
154 name = v.UnicodeString(strip=True, min=1, not_empty=False)
154 firstname = v.UnicodeString(strip=True, min=1, not_empty=False)
155 155 lastname = v.UnicodeString(strip=True, min=1, not_empty=False)
156 156 email = All(v.Email(not_empty=True), v.UniqSystemEmail(old_data))
157 157
158 158 chained_validators = [v.ValidPasswordsMatch()]
159 159
160 160 return _RegisterForm
161 161
162 162
163 163 def PasswordResetForm():
164 164 class _PasswordResetForm(formencode.Schema):
165 165 allow_extra_fields = True
166 166 filter_extra_fields = True
167 167 email = All(v.ValidSystemEmail(), v.Email(not_empty=True))
168 168 return _PasswordResetForm
169 169
170 170
171 171 def RepoForm(edit=False, old_data={}, supported_backends=BACKENDS.keys(),
172 172 repo_groups=[], landing_revs=[]):
173 173 class _RepoForm(formencode.Schema):
174 174 allow_extra_fields = True
175 175 filter_extra_fields = False
176 176 repo_name = All(v.UnicodeString(strip=True, min=1, not_empty=True),
177 177 v.SlugifyName())
178 178 clone_uri = All(v.UnicodeString(strip=True, min=1, not_empty=False))
179 179 repo_group = v.OneOf(repo_groups, hideList=True)
180 180 repo_type = v.OneOf(supported_backends)
181 181 description = v.UnicodeString(strip=True, min=1, not_empty=False)
182 182 private = v.StringBoolean(if_missing=False)
183 183 enable_statistics = v.StringBoolean(if_missing=False)
184 184 enable_downloads = v.StringBoolean(if_missing=False)
185 185 landing_rev = v.OneOf(landing_revs, hideList=True)
186 186
187 187 if edit:
188 188 #this is repo owner
189 189 user = All(v.UnicodeString(not_empty=True), v.ValidRepoUser())
190 190
191 191 chained_validators = [v.ValidCloneUri(),
192 192 v.ValidRepoName(edit, old_data),
193 193 v.ValidPerms()]
194 194 return _RepoForm
195 195
196 196
197 197 def RepoForkForm(edit=False, old_data={}, supported_backends=BACKENDS.keys(),
198 198 repo_groups=[], landing_revs=[]):
199 199 class _RepoForkForm(formencode.Schema):
200 200 allow_extra_fields = True
201 201 filter_extra_fields = False
202 202 repo_name = All(v.UnicodeString(strip=True, min=1, not_empty=True),
203 203 v.SlugifyName())
204 204 repo_group = v.OneOf(repo_groups, hideList=True)
205 205 repo_type = All(v.ValidForkType(old_data), v.OneOf(supported_backends))
206 206 description = v.UnicodeString(strip=True, min=1, not_empty=True)
207 207 private = v.StringBoolean(if_missing=False)
208 208 copy_permissions = v.StringBoolean(if_missing=False)
209 209 update_after_clone = v.StringBoolean(if_missing=False)
210 210 fork_parent_id = v.UnicodeString()
211 211 chained_validators = [v.ValidForkName(edit, old_data)]
212 212 landing_rev = v.OneOf(landing_revs, hideList=True)
213 213
214 214 return _RepoForkForm
215 215
216 216
217 217 def RepoSettingsForm(edit=False, old_data={},
218 218 supported_backends=BACKENDS.keys(), repo_groups=[],
219 219 landing_revs=[]):
220 220 class _RepoForm(formencode.Schema):
221 221 allow_extra_fields = True
222 222 filter_extra_fields = False
223 223 repo_name = All(v.UnicodeString(strip=True, min=1, not_empty=True),
224 224 v.SlugifyName())
225 225 description = v.UnicodeString(strip=True, min=1, not_empty=True)
226 226 repo_group = v.OneOf(repo_groups, hideList=True)
227 227 private = v.StringBoolean(if_missing=False)
228 228 landing_rev = v.OneOf(landing_revs, hideList=True)
229 229 chained_validators = [v.ValidRepoName(edit, old_data), v.ValidPerms(),
230 230 v.ValidSettings()]
231 231 return _RepoForm
232 232
233 233
234 234 def ApplicationSettingsForm():
235 235 class _ApplicationSettingsForm(formencode.Schema):
236 236 allow_extra_fields = True
237 237 filter_extra_fields = False
238 238 rhodecode_title = v.UnicodeString(strip=True, min=1, not_empty=True)
239 239 rhodecode_realm = v.UnicodeString(strip=True, min=1, not_empty=True)
240 240 rhodecode_ga_code = v.UnicodeString(strip=True, min=1, not_empty=False)
241 241
242 242 return _ApplicationSettingsForm
243 243
244 244
245 245 def ApplicationUiSettingsForm():
246 246 class _ApplicationUiSettingsForm(formencode.Schema):
247 247 allow_extra_fields = True
248 248 filter_extra_fields = False
249 249 web_push_ssl = v.OneOf(['true', 'false'], if_missing='false')
250 250 paths_root_path = All(
251 251 v.ValidPath(),
252 252 v.UnicodeString(strip=True, min=1, not_empty=True)
253 253 )
254 254 hooks_changegroup_update = v.OneOf(['True', 'False'],
255 255 if_missing=False)
256 256 hooks_changegroup_repo_size = v.OneOf(['True', 'False'],
257 257 if_missing=False)
258 258 hooks_changegroup_push_logger = v.OneOf(['True', 'False'],
259 259 if_missing=False)
260 260 hooks_preoutgoing_pull_logger = v.OneOf(['True', 'False'],
261 261 if_missing=False)
262 262
263 263 return _ApplicationUiSettingsForm
264 264
265 265
266 266 def DefaultPermissionsForm(perms_choices, register_choices, create_choices):
267 267 class _DefaultPermissionsForm(formencode.Schema):
268 268 allow_extra_fields = True
269 269 filter_extra_fields = True
270 270 overwrite_default = v.StringBoolean(if_missing=False)
271 271 anonymous = v.OneOf(['True', 'False'], if_missing=False)
272 272 default_perm = v.OneOf(perms_choices)
273 273 default_register = v.OneOf(register_choices)
274 274 default_create = v.OneOf(create_choices)
275 275
276 276 return _DefaultPermissionsForm
277 277
278 278
279 279 def LdapSettingsForm(tls_reqcert_choices, search_scope_choices,
280 280 tls_kind_choices):
281 281 class _LdapSettingsForm(formencode.Schema):
282 282 allow_extra_fields = True
283 283 filter_extra_fields = True
284 284 #pre_validators = [LdapLibValidator]
285 285 ldap_active = v.StringBoolean(if_missing=False)
286 286 ldap_host = v.UnicodeString(strip=True,)
287 287 ldap_port = v.Number(strip=True,)
288 288 ldap_tls_kind = v.OneOf(tls_kind_choices)
289 289 ldap_tls_reqcert = v.OneOf(tls_reqcert_choices)
290 290 ldap_dn_user = v.UnicodeString(strip=True,)
291 291 ldap_dn_pass = v.UnicodeString(strip=True,)
292 292 ldap_base_dn = v.UnicodeString(strip=True,)
293 293 ldap_filter = v.UnicodeString(strip=True,)
294 294 ldap_search_scope = v.OneOf(search_scope_choices)
295 295 ldap_attr_login = All(
296 296 v.AttrLoginValidator(),
297 297 v.UnicodeString(strip=True,)
298 298 )
299 299 ldap_attr_firstname = v.UnicodeString(strip=True,)
300 300 ldap_attr_lastname = v.UnicodeString(strip=True,)
301 301 ldap_attr_email = v.UnicodeString(strip=True,)
302 302
303 303 return _LdapSettingsForm
304 304
305 305
306 306 def UserExtraEmailForm():
307 307 class _UserExtraEmailForm(formencode.Schema):
308 308 email = All(v.UniqSystemEmail(), v.Email)
309 309
310 310 return _UserExtraEmailForm
@@ -1,100 +1,100
1 1 ## -*- coding: utf-8 -*-
2 2 <%inherit file="/base/base.html"/>
3 3
4 4 <%def name="title()">
5 5 ${_('Add user')} - ${c.rhodecode_name}
6 6 </%def>
7 7 <%def name="breadcrumbs_links()">
8 8 ${h.link_to(_('Admin'),h.url('admin_home'))}
9 9 &raquo;
10 10 ${h.link_to(_('Users'),h.url('users'))}
11 11 &raquo;
12 12 ${_('add new user')}
13 13 </%def>
14 14
15 15 <%def name="page_nav()">
16 16 ${self.menu('admin')}
17 17 </%def>
18 18
19 19 <%def name="main()">
20 20 <div class="box">
21 21 <!-- box / title -->
22 22 <div class="title">
23 23 ${self.breadcrumbs()}
24 24 </div>
25 25 <!-- end box / title -->
26 26 ${h.form(url('users'))}
27 27 <div class="form">
28 28 <!-- fields -->
29 29 <div class="fields">
30 30 <div class="field">
31 31 <div class="label">
32 32 <label for="username">${_('Username')}:</label>
33 33 </div>
34 34 <div class="input">
35 35 ${h.text('username',class_='small')}
36 36 </div>
37 37 </div>
38 38
39 39 <div class="field">
40 40 <div class="label">
41 41 <label for="password">${_('Password')}:</label>
42 42 </div>
43 43 <div class="input">
44 44 ${h.password('password',class_='small')}
45 45 </div>
46 46 </div>
47 47
48 48 <div class="field">
49 49 <div class="label">
50 50 <label for="password_confirmation">${_('Password confirmation')}:</label>
51 51 </div>
52 52 <div class="input">
53 53 ${h.password('password_confirmation',class_="small",autocomplete="off")}
54 54 </div>
55 55 </div>
56 56
57 57 <div class="field">
58 58 <div class="label">
59 <label for="name">${_('First Name')}:</label>
59 <label for="firstname">${_('First Name')}:</label>
60 60 </div>
61 61 <div class="input">
62 ${h.text('name',class_='small')}
62 ${h.text('firstname',class_='small')}
63 63 </div>
64 64 </div>
65 65
66 66 <div class="field">
67 67 <div class="label">
68 68 <label for="lastname">${_('Last Name')}:</label>
69 69 </div>
70 70 <div class="input">
71 71 ${h.text('lastname',class_='small')}
72 72 </div>
73 73 </div>
74 74
75 75 <div class="field">
76 76 <div class="label">
77 77 <label for="email">${_('Email')}:</label>
78 78 </div>
79 79 <div class="input">
80 80 ${h.text('email',class_='small')}
81 81 </div>
82 82 </div>
83 83
84 84 <div class="field">
85 85 <div class="label label-checkbox">
86 86 <label for="active">${_('Active')}:</label>
87 87 </div>
88 88 <div class="checkboxes">
89 89 ${h.checkbox('active',value=True,checked='checked')}
90 90 </div>
91 91 </div>
92 92
93 93 <div class="buttons">
94 94 ${h.submit('save',_('save'),class_="ui-button")}
95 95 </div>
96 96 </div>
97 97 </div>
98 98 ${h.end_form()}
99 99 </div>
100 100 </%def>
@@ -1,91 +1,91
1 1 ## -*- coding: utf-8 -*-
2 2 <%inherit file="base/root.html"/>
3 3
4 4 <%def name="title()">
5 5 ${_('Sign Up')} - ${c.rhodecode_name}
6 6 </%def>
7 7
8 8 <div id="register">
9 9
10 10 <div class="title top-left-rounded-corner top-right-rounded-corner">
11 11 <h5>${_('Sign Up to')} ${c.rhodecode_name}</h5>
12 12 </div>
13 13 <div class="inner">
14 14 ${h.form(url('register'))}
15 15 <div class="form">
16 16 <!-- fields -->
17 17 <div class="fields">
18 18 <div class="field">
19 19 <div class="label">
20 20 <label for="username">${_('Username')}:</label>
21 21 </div>
22 22 <div class="input">
23 23 ${h.text('username',class_="medium")}
24 24 </div>
25 25 </div>
26 26
27 27 <div class="field">
28 28 <div class="label">
29 29 <label for="password">${_('Password')}:</label>
30 30 </div>
31 31 <div class="input">
32 32 ${h.password('password',class_="medium")}
33 33 </div>
34 34 </div>
35 35
36 36 <div class="field">
37 37 <div class="label">
38 38 <label for="password">${_('Re-enter password')}:</label>
39 39 </div>
40 40 <div class="input">
41 41 ${h.password('password_confirmation',class_="medium")}
42 42 </div>
43 43 </div>
44 44
45 45 <div class="field">
46 46 <div class="label">
47 <label for="name">${_('First Name')}:</label>
47 <label for="firstname">${_('First Name')}:</label>
48 48 </div>
49 49 <div class="input">
50 ${h.text('name',class_="medium")}
50 ${h.text('firstname',class_="medium")}
51 51 </div>
52 52 </div>
53 53
54 54 <div class="field">
55 55 <div class="label">
56 56 <label for="lastname">${_('Last Name')}:</label>
57 57 </div>
58 58 <div class="input">
59 59 ${h.text('lastname',class_="medium")}
60 60 </div>
61 61 </div>
62 62
63 63 <div class="field">
64 64 <div class="label">
65 65 <label for="email">${_('Email')}:</label>
66 66 </div>
67 67 <div class="input">
68 68 ${h.text('email',class_="medium")}
69 69 </div>
70 70 </div>
71 71
72 72 <div class="buttons">
73 73 <div class="nohighlight">
74 74 ${h.submit('sign_up',_('Sign Up'),class_="ui-button")}
75 75 %if c.auto_active:
76 76 <div class="activation_msg">${_('Your account will be activated right after registration')}</div>
77 77 %else:
78 78 <div class="activation_msg">${_('Your account must wait for activation by administrator')}</div>
79 79 %endif
80 80 </div>
81 81 </div>
82 82 </div>
83 83 </div>
84 84 ${h.end_form()}
85 85 <script type="text/javascript">
86 86 YUE.onDOMReady(function(){
87 87 YUD.get('username').focus();
88 88 })
89 89 </script>
90 90 </div>
91 91 </div>
@@ -1,272 +1,272
1 1 # -*- coding: utf-8 -*-
2 2 from rhodecode.tests import *
3 3 from rhodecode.model.db import User, Notification
4 4 from rhodecode.lib.utils2 import generate_api_key
5 5 from rhodecode.lib.auth import check_password
6 6 from rhodecode.lib import helpers as h
7 7 from rhodecode.model import validators
8 8
9 9
10 10 class TestLoginController(TestController):
11 11
12 12 def tearDown(self):
13 13 for n in Notification.query().all():
14 14 self.Session().delete(n)
15 15
16 16 self.Session().commit()
17 17 self.assertEqual(Notification.query().all(), [])
18 18
19 19 def test_index(self):
20 20 response = self.app.get(url(controller='login', action='index'))
21 21 self.assertEqual(response.status, '200 OK')
22 22 # Test response...
23 23
24 24 def test_login_admin_ok(self):
25 25 response = self.app.post(url(controller='login', action='index'),
26 26 {'username': 'test_admin',
27 27 'password': 'test12'})
28 28 self.assertEqual(response.status, '302 Found')
29 29 self.assertEqual(response.session['rhodecode_user'].get('username'),
30 30 'test_admin')
31 31 response = response.follow()
32 32 self.assertTrue('%s repository' % HG_REPO in response.body)
33 33
34 34 def test_login_regular_ok(self):
35 35 response = self.app.post(url(controller='login', action='index'),
36 36 {'username': 'test_regular',
37 37 'password': 'test12'})
38 38
39 39 self.assertEqual(response.status, '302 Found')
40 40 self.assertEqual(response.session['rhodecode_user'].get('username'),
41 41 'test_regular')
42 42 response = response.follow()
43 43 self.assertTrue('%s repository' % HG_REPO in response.body)
44 44 self.assertTrue('<a title="Admin" href="/_admin">' not in response.body)
45 45
46 46 def test_login_ok_came_from(self):
47 47 test_came_from = '/_admin/users'
48 48 response = self.app.post(url(controller='login', action='index',
49 49 came_from=test_came_from),
50 50 {'username': 'test_admin',
51 51 'password': 'test12'})
52 52 self.assertEqual(response.status, '302 Found')
53 53 response = response.follow()
54 54
55 55 self.assertEqual(response.status, '200 OK')
56 56 self.assertTrue('Users administration' in response.body)
57 57
58 58 def test_login_short_password(self):
59 59 response = self.app.post(url(controller='login', action='index'),
60 60 {'username': 'test_admin',
61 61 'password': 'as'})
62 62 self.assertEqual(response.status, '200 OK')
63 63
64 64 self.assertTrue('Enter 3 characters or more' in response.body)
65 65
66 66 def test_login_wrong_username_password(self):
67 67 response = self.app.post(url(controller='login', action='index'),
68 68 {'username': 'error',
69 69 'password': 'test12'})
70 70
71 71 self.assertTrue('invalid user name' in response.body)
72 72 self.assertTrue('invalid password' in response.body)
73 73
74 74 #==========================================================================
75 75 # REGISTRATIONS
76 76 #==========================================================================
77 77 def test_register(self):
78 78 response = self.app.get(url(controller='login', action='register'))
79 79 self.assertTrue('Sign Up to RhodeCode' in response.body)
80 80
81 81 def test_register_err_same_username(self):
82 82 uname = 'test_admin'
83 83 response = self.app.post(url(controller='login', action='register'),
84 84 {'username': uname,
85 85 'password': 'test12',
86 86 'password_confirmation': 'test12',
87 87 'email': 'goodmail@domain.com',
88 'name': 'test',
88 'firstname': 'test',
89 89 'lastname': 'test'})
90 90
91 91 msg = validators.ValidUsername()._messages['username_exists']
92 92 msg = h.html_escape(msg % {'username': uname})
93 93 response.mustcontain(msg)
94 94
95 95 def test_register_err_same_email(self):
96 96 response = self.app.post(url(controller='login', action='register'),
97 97 {'username': 'test_admin_0',
98 98 'password': 'test12',
99 99 'password_confirmation': 'test12',
100 100 'email': 'test_admin@mail.com',
101 'name': 'test',
101 'firstname': 'test',
102 102 'lastname': 'test'})
103 103
104 104 msg = validators.UniqSystemEmail()()._messages['email_taken']
105 105 response.mustcontain(msg)
106 106
107 107 def test_register_err_same_email_case_sensitive(self):
108 108 response = self.app.post(url(controller='login', action='register'),
109 109 {'username': 'test_admin_1',
110 110 'password': 'test12',
111 111 'password_confirmation': 'test12',
112 112 'email': 'TesT_Admin@mail.COM',
113 'name': 'test',
113 'firstname': 'test',
114 114 'lastname': 'test'})
115 115 msg = validators.UniqSystemEmail()()._messages['email_taken']
116 116 response.mustcontain(msg)
117 117
118 118 def test_register_err_wrong_data(self):
119 119 response = self.app.post(url(controller='login', action='register'),
120 120 {'username': 'xs',
121 121 'password': 'test',
122 122 'password_confirmation': 'test',
123 123 'email': 'goodmailm',
124 'name': 'test',
124 'firstname': 'test',
125 125 'lastname': 'test'})
126 126 self.assertEqual(response.status, '200 OK')
127 127 response.mustcontain('An email address must contain a single @')
128 128 response.mustcontain('Enter a value 6 characters long or more')
129 129
130 130 def test_register_err_username(self):
131 131 response = self.app.post(url(controller='login', action='register'),
132 132 {'username': 'error user',
133 133 'password': 'test12',
134 134 'password_confirmation': 'test12',
135 135 'email': 'goodmailm',
136 'name': 'test',
136 'firstname': 'test',
137 137 'lastname': 'test'})
138 138
139 139 response.mustcontain('An email address must contain a single @')
140 140 response.mustcontain('Username may only contain '
141 141 'alphanumeric characters underscores, '
142 142 'periods or dashes and must begin with '
143 143 'alphanumeric character')
144 144
145 145 def test_register_err_case_sensitive(self):
146 146 usr = 'Test_Admin'
147 147 response = self.app.post(url(controller='login', action='register'),
148 148 {'username': usr,
149 149 'password': 'test12',
150 150 'password_confirmation': 'test12',
151 151 'email': 'goodmailm',
152 'name': 'test',
152 'firstname': 'test',
153 153 'lastname': 'test'})
154 154
155 155 response.mustcontain('An email address must contain a single @')
156 156 msg = validators.ValidUsername()._messages['username_exists']
157 157 msg = h.html_escape(msg % {'username': usr})
158 158 response.mustcontain(msg)
159 159
160 160 def test_register_special_chars(self):
161 161 response = self.app.post(url(controller='login', action='register'),
162 162 {'username': 'xxxaxn',
163 163 'password': 'Δ…Δ‡ΕΊΕΌΔ…Ε›Ε›Ε›Ε›',
164 164 'password_confirmation': 'Δ…Δ‡ΕΊΕΌΔ…Ε›Ε›Ε›Ε›',
165 165 'email': 'goodmailm@test.plx',
166 'name': 'test',
166 'firstname': 'test',
167 167 'lastname': 'test'})
168 168
169 169 msg = validators.ValidPassword()._messages['invalid_password']
170 170 response.mustcontain(msg)
171 171
172 172 def test_register_password_mismatch(self):
173 173 response = self.app.post(url(controller='login', action='register'),
174 174 {'username': 'xs',
175 175 'password': '123qwe',
176 176 'password_confirmation': 'qwe123',
177 177 'email': 'goodmailm@test.plxa',
178 'name': 'test',
178 'firstname': 'test',
179 179 'lastname': 'test'})
180 180 msg = validators.ValidPasswordsMatch()._messages['password_mismatch']
181 181 response.mustcontain(msg)
182 182
183 183 def test_register_ok(self):
184 184 username = 'test_regular4'
185 185 password = 'qweqwe'
186 186 email = 'marcin@test.com'
187 187 name = 'testname'
188 188 lastname = 'testlastname'
189 189
190 190 response = self.app.post(url(controller='login', action='register'),
191 191 {'username': username,
192 192 'password': password,
193 193 'password_confirmation': password,
194 194 'email': email,
195 'name': name,
195 'firstname': name,
196 196 'lastname': lastname,
197 197 'admin': True}) # This should be overriden
198 198 self.assertEqual(response.status, '302 Found')
199 199 self.checkSessionFlash(response, 'You have successfully registered into rhodecode')
200 200
201 201 ret = self.Session().query(User).filter(User.username == 'test_regular4').one()
202 202 self.assertEqual(ret.username, username)
203 203 self.assertEqual(check_password(password, ret.password), True)
204 204 self.assertEqual(ret.email, email)
205 205 self.assertEqual(ret.name, name)
206 206 self.assertEqual(ret.lastname, lastname)
207 207 self.assertNotEqual(ret.api_key, None)
208 208 self.assertEqual(ret.admin, False)
209 209
210 210 def test_forgot_password_wrong_mail(self):
211 211 bad_email = 'marcin@wrongmail.org'
212 212 response = self.app.post(
213 213 url(controller='login', action='password_reset'),
214 214 {'email': bad_email, }
215 215 )
216 216
217 217 msg = validators.ValidSystemEmail()._messages['non_existing_email']
218 218 msg = h.html_escape(msg % {'email': bad_email})
219 219 response.mustcontain()
220 220
221 221 def test_forgot_password(self):
222 222 response = self.app.get(url(controller='login',
223 223 action='password_reset'))
224 224 self.assertEqual(response.status, '200 OK')
225 225
226 226 username = 'test_password_reset_1'
227 227 password = 'qweqwe'
228 228 email = 'marcin@python-works.com'
229 229 name = 'passwd'
230 230 lastname = 'reset'
231 231
232 232 new = User()
233 233 new.username = username
234 234 new.password = password
235 235 new.email = email
236 236 new.name = name
237 237 new.lastname = lastname
238 238 new.api_key = generate_api_key(username)
239 239 self.Session().add(new)
240 240 self.Session().commit()
241 241
242 242 response = self.app.post(url(controller='login',
243 243 action='password_reset'),
244 244 {'email': email, })
245 245
246 246 self.checkSessionFlash(response, 'Your password reset link was sent')
247 247
248 248 response = response.follow()
249 249
250 250 # BAD KEY
251 251
252 252 key = "bad"
253 253 response = self.app.get(url(controller='login',
254 254 action='password_reset_confirmation',
255 255 key=key))
256 256 self.assertEqual(response.status, '302 Found')
257 257 self.assertTrue(response.location.endswith(url('reset_password')))
258 258
259 259 # GOOD KEY
260 260
261 261 key = User.get_by_username(username).api_key
262 262 response = self.app.get(url(controller='login',
263 263 action='password_reset_confirmation',
264 264 key=key))
265 265 self.assertEqual(response.status, '302 Found')
266 266 self.assertTrue(response.location.endswith(url('login_home')))
267 267
268 268 self.checkSessionFlash(response,
269 269 ('Your password reset was successful, '
270 270 'new password has been sent to your email'))
271 271
272 272 response = response.follow()
General Comments 0
You need to be logged in to leave comments. Login now