Show More
@@ -1,146 +1,175 | |||||
1 | from rhodecode.tests import * |
|
1 | from rhodecode.tests import * | |
2 | from rhodecode.model.db import User |
|
2 | from rhodecode.model.db import User | |
3 | from rhodecode.lib.auth import check_password |
|
3 | from rhodecode.lib.auth import check_password | |
4 |
|
4 | |||
5 |
|
5 | |||
6 | class TestLoginController(TestController): |
|
6 | class TestLoginController(TestController): | |
7 |
|
7 | |||
8 | def test_index(self): |
|
8 | def test_index(self): | |
9 | response = self.app.get(url(controller='login', action='index')) |
|
9 | response = self.app.get(url(controller='login', action='index')) | |
10 | assert response.status == '200 OK', 'Wrong response from login page got %s' % response.status |
|
10 | assert response.status == '200 OK', 'Wrong response from login page got %s' % response.status | |
11 | # Test response... |
|
11 | # Test response... | |
12 |
|
12 | |||
13 | def test_login_admin_ok(self): |
|
13 | def test_login_admin_ok(self): | |
14 | response = self.app.post(url(controller='login', action='index'), |
|
14 | response = self.app.post(url(controller='login', action='index'), | |
15 | {'username':'test_admin', |
|
15 | {'username':'test_admin', | |
16 | 'password':'test12'}) |
|
16 | 'password':'test12'}) | |
17 | assert response.status == '302 Found', 'Wrong response code from login got %s' % response.status |
|
17 | assert response.status == '302 Found', 'Wrong response code from login got %s' % response.status | |
18 | assert response.session['rhodecode_user'].username == 'test_admin', 'wrong logged in user' |
|
18 | assert response.session['rhodecode_user'].username == 'test_admin', 'wrong logged in user' | |
19 | response = response.follow() |
|
19 | response = response.follow() | |
20 | assert '%s repository' % HG_REPO in response.body |
|
20 | assert '%s repository' % HG_REPO in response.body | |
21 |
|
21 | |||
22 | def test_login_regular_ok(self): |
|
22 | def test_login_regular_ok(self): | |
23 | response = self.app.post(url(controller='login', action='index'), |
|
23 | response = self.app.post(url(controller='login', action='index'), | |
24 | {'username':'test_regular', |
|
24 | {'username':'test_regular', | |
25 | 'password':'test12'}) |
|
25 | 'password':'test12'}) | |
26 | print response |
|
26 | print response | |
27 | assert response.status == '302 Found', 'Wrong response code from login got %s' % response.status |
|
27 | assert response.status == '302 Found', 'Wrong response code from login got %s' % response.status | |
28 | assert response.session['rhodecode_user'].username == 'test_regular', 'wrong logged in user' |
|
28 | assert response.session['rhodecode_user'].username == 'test_regular', 'wrong logged in user' | |
29 | response = response.follow() |
|
29 | response = response.follow() | |
30 | assert '%s repository' % HG_REPO in response.body |
|
30 | assert '%s repository' % HG_REPO in response.body | |
31 | assert '<a title="Admin" href="/_admin">' not in response.body |
|
31 | assert '<a title="Admin" href="/_admin">' not in response.body | |
32 |
|
32 | |||
33 | def test_login_ok_came_from(self): |
|
33 | def test_login_ok_came_from(self): | |
34 | test_came_from = '/_admin/users' |
|
34 | test_came_from = '/_admin/users' | |
35 | response = self.app.post(url(controller='login', action='index', came_from=test_came_from), |
|
35 | response = self.app.post(url(controller='login', action='index', came_from=test_came_from), | |
36 | {'username':'test_admin', |
|
36 | {'username':'test_admin', | |
37 | 'password':'test12'}) |
|
37 | 'password':'test12'}) | |
38 | assert response.status == '302 Found', 'Wrong response code from came from redirection' |
|
38 | assert response.status == '302 Found', 'Wrong response code from came from redirection' | |
39 | response = response.follow() |
|
39 | response = response.follow() | |
40 |
|
40 | |||
41 | assert response.status == '200 OK', 'Wrong response from login page got %s' % response.status |
|
41 | assert response.status == '200 OK', 'Wrong response from login page got %s' % response.status | |
42 | assert 'Users administration' in response.body, 'No proper title in response' |
|
42 | assert 'Users administration' in response.body, 'No proper title in response' | |
43 |
|
43 | |||
44 |
|
44 | |||
45 | def test_login_short_password(self): |
|
45 | def test_login_short_password(self): | |
46 | response = self.app.post(url(controller='login', action='index'), |
|
46 | response = self.app.post(url(controller='login', action='index'), | |
47 | {'username':'error', |
|
47 | {'username':'error', | |
48 | 'password':'test'}) |
|
48 | 'password':'test'}) | |
49 | assert response.status == '200 OK', 'Wrong response from login page' |
|
49 | assert response.status == '200 OK', 'Wrong response from login page' | |
50 | print response.body |
|
50 | print response.body | |
51 | assert 'Enter 6 characters or more' in response.body, 'No error password message in response' |
|
51 | assert 'Enter 6 characters or more' in response.body, 'No error password message in response' | |
52 |
|
52 | |||
53 | def test_login_wrong_username_password(self): |
|
53 | def test_login_wrong_username_password(self): | |
54 | response = self.app.post(url(controller='login', action='index'), |
|
54 | response = self.app.post(url(controller='login', action='index'), | |
55 | {'username':'error', |
|
55 | {'username':'error', | |
56 | 'password':'test12'}) |
|
56 | 'password':'test12'}) | |
57 | assert response.status == '200 OK', 'Wrong response from login page' |
|
57 | assert response.status == '200 OK', 'Wrong response from login page' | |
58 |
|
58 | |||
59 | assert 'invalid user name' in response.body, 'No error username message in response' |
|
59 | assert 'invalid user name' in response.body, 'No error username message in response' | |
60 | assert 'invalid password' in response.body, 'No error password message in response' |
|
60 | assert 'invalid password' in response.body, 'No error password message in response' | |
61 |
|
61 | |||
62 |
|
62 | #========================================================================== | ||
|
63 | # REGISTRATIONS | |||
|
64 | #========================================================================== | |||
63 | def test_register(self): |
|
65 | def test_register(self): | |
64 | response = self.app.get(url(controller='login', action='register')) |
|
66 | response = self.app.get(url(controller='login', action='register')) | |
65 | assert 'Sign Up to rhodecode' in response.body, 'wrong page for user registration' |
|
67 | assert 'Sign Up to rhodecode' in response.body, 'wrong page for user registration' | |
66 |
|
68 | |||
67 | def test_register_err_same_username(self): |
|
69 | def test_register_err_same_username(self): | |
68 | response = self.app.post(url(controller='login', action='register'), |
|
70 | response = self.app.post(url(controller='login', action='register'), | |
69 | {'username':'test_admin', |
|
71 | {'username':'test_admin', | |
70 | 'password':'test', |
|
72 | 'password':'test12', | |
|
73 | 'password_confirmation':'test12', | |||
71 | 'email':'goodmail@domain.com', |
|
74 | 'email':'goodmail@domain.com', | |
72 | 'name':'test', |
|
75 | 'name':'test', | |
73 | 'lastname':'test'}) |
|
76 | 'lastname':'test'}) | |
74 |
|
77 | |||
75 | assert response.status == '200 OK', 'Wrong response from register page got %s' % response.status |
|
78 | assert response.status == '200 OK', 'Wrong response from register page got %s' % response.status | |
76 | assert 'This username already exists' in response.body |
|
79 | assert 'This username already exists' in response.body | |
77 |
|
80 | |||
78 | def test_register_err_wrong_data(self): |
|
81 | def test_register_err_wrong_data(self): | |
79 | response = self.app.post(url(controller='login', action='register'), |
|
82 | response = self.app.post(url(controller='login', action='register'), | |
80 | {'username':'xs', |
|
83 | {'username':'xs', | |
81 | 'password':'', |
|
84 | 'password':'test', | |
|
85 | 'password_confirmation':'test', | |||
82 | 'email':'goodmailm', |
|
86 | 'email':'goodmailm', | |
83 | 'name':'test', |
|
87 | 'name':'test', | |
84 | 'lastname':'test'}) |
|
88 | 'lastname':'test'}) | |
85 |
|
89 | |||
86 | assert response.status == '200 OK', 'Wrong response from register page got %s' % response.status |
|
90 | assert response.status == '200 OK', 'Wrong response from register page got %s' % response.status | |
87 | assert 'An email address must contain a single @' in response.body |
|
91 | assert 'An email address must contain a single @' in response.body | |
88 | assert 'Please enter a value' in response.body |
|
92 | assert 'Please enter a value' in response.body | |
89 |
|
93 | |||
90 |
|
94 | |||
|
95 | def test_register_special_chars(self): | |||
|
96 | response = self.app.post(url(controller='login', action='register'), | |||
|
97 | {'username':'xxxaxn', | |||
|
98 | 'password':'Δ ΔΕΊΕΌΔ ΕΕΕΕ', | |||
|
99 | 'password_confirmation':'Δ ΔΕΊΕΌΔ ΕΕΕΕ', | |||
|
100 | 'email':'goodmailm', | |||
|
101 | 'name':'test', | |||
|
102 | 'lastname':'test@test.plx'}) | |||
|
103 | ||||
|
104 | assert response.status == '200 OK', 'Wrong response from register page got %s' % response.status | |||
|
105 | assert 'Invalid characters in password' in response.body | |||
|
106 | ||||
|
107 | ||||
|
108 | def test_register_password_mismatch(self): | |||
|
109 | response = self.app.post(url(controller='login', action='register'), | |||
|
110 | {'username':'xs', | |||
|
111 | 'password':'123qwe', | |||
|
112 | 'password_confirmation':'qwe123', | |||
|
113 | 'email':'goodmailm', | |||
|
114 | 'name':'test', | |||
|
115 | 'lastname':'test@test.plxa'}) | |||
|
116 | ||||
|
117 | assert response.status == '200 OK', 'Wrong response from register page got %s' % response.status | |||
|
118 | assert 'Password do not match' in response.body | |||
91 |
|
119 | |||
92 | def test_register_ok(self): |
|
120 | def test_register_ok(self): | |
93 | username = 'test_regular4' |
|
121 | username = 'test_regular4' | |
94 | password = 'qweqwe' |
|
122 | password = 'qweqwe' | |
95 | email = 'marcin@test.com' |
|
123 | email = 'marcin@test.com' | |
96 | name = 'testname' |
|
124 | name = 'testname' | |
97 | lastname = 'testlastname' |
|
125 | lastname = 'testlastname' | |
98 |
|
126 | |||
99 | response = self.app.post(url(controller='login', action='register'), |
|
127 | response = self.app.post(url(controller='login', action='register'), | |
100 | {'username':username, |
|
128 | {'username':username, | |
101 | 'password':password, |
|
129 | 'password':password, | |
|
130 | 'password_confirmation':password, | |||
102 | 'email':email, |
|
131 | 'email':email, | |
103 | 'name':name, |
|
132 | 'name':name, | |
104 | 'lastname':lastname}) |
|
133 | 'lastname':lastname}) | |
105 | assert response.status == '302 Found', 'Wrong response from register page got %s' % response.status |
|
134 | assert response.status == '302 Found', 'Wrong response from register page got %s' % response.status | |
106 | assert 'You have successfully registered into rhodecode' in response.session['flash'][0], 'No flash message about user registration' |
|
135 | assert 'You have successfully registered into rhodecode' in response.session['flash'][0], 'No flash message about user registration' | |
107 |
|
136 | |||
108 | ret = self.sa.query(User).filter(User.username == 'test_regular4').one() |
|
137 | ret = self.sa.query(User).filter(User.username == 'test_regular4').one() | |
109 | assert ret.username == username , 'field mismatch %s %s' % (ret.username, username) |
|
138 | assert ret.username == username , 'field mismatch %s %s' % (ret.username, username) | |
110 | assert check_password(password, ret.password) == True , 'password mismatch' |
|
139 | assert check_password(password, ret.password) == True , 'password mismatch' | |
111 | assert ret.email == email , 'field mismatch %s %s' % (ret.email, email) |
|
140 | assert ret.email == email , 'field mismatch %s %s' % (ret.email, email) | |
112 | assert ret.name == name , 'field mismatch %s %s' % (ret.name, name) |
|
141 | assert ret.name == name , 'field mismatch %s %s' % (ret.name, name) | |
113 | assert ret.lastname == lastname , 'field mismatch %s %s' % (ret.lastname, lastname) |
|
142 | assert ret.lastname == lastname , 'field mismatch %s %s' % (ret.lastname, lastname) | |
114 |
|
143 | |||
115 |
|
144 | |||
116 | def test_forgot_password_wrong_mail(self): |
|
145 | def test_forgot_password_wrong_mail(self): | |
117 | response = self.app.post(url(controller='login', action='password_reset'), |
|
146 | response = self.app.post(url(controller='login', action='password_reset'), | |
118 | {'email':'marcin@wrongmail.org', }) |
|
147 | {'email':'marcin@wrongmail.org', }) | |
119 |
|
148 | |||
120 | assert "That e-mail address doesn't exist" in response.body, 'Missing error message about wrong email' |
|
149 | assert "That e-mail address doesn't exist" in response.body, 'Missing error message about wrong email' | |
121 |
|
150 | |||
122 | def test_forgot_password(self): |
|
151 | def test_forgot_password(self): | |
123 | response = self.app.get(url(controller='login', action='password_reset')) |
|
152 | response = self.app.get(url(controller='login', action='password_reset')) | |
124 | assert response.status == '200 OK', 'Wrong response from login page got %s' % response.status |
|
153 | assert response.status == '200 OK', 'Wrong response from login page got %s' % response.status | |
125 |
|
154 | |||
126 | username = 'test_password_reset_1' |
|
155 | username = 'test_password_reset_1' | |
127 | password = 'qweqwe' |
|
156 | password = 'qweqwe' | |
128 | email = 'marcin@python-works.com' |
|
157 | email = 'marcin@python-works.com' | |
129 | name = 'passwd' |
|
158 | name = 'passwd' | |
130 | lastname = 'reset' |
|
159 | lastname = 'reset' | |
131 |
|
160 | |||
132 | response = self.app.post(url(controller='login', action='register'), |
|
161 | response = self.app.post(url(controller='login', action='register'), | |
133 | {'username':username, |
|
162 | {'username':username, | |
134 | 'password':password, |
|
163 | 'password':password, | |
135 | 'email':email, |
|
164 | 'email':email, | |
136 | 'name':name, |
|
165 | 'name':name, | |
137 | 'lastname':lastname}) |
|
166 | 'lastname':lastname}) | |
138 | #register new user for email test |
|
167 | #register new user for email test | |
139 | response = self.app.post(url(controller='login', action='password_reset'), |
|
168 | response = self.app.post(url(controller='login', action='password_reset'), | |
140 | {'email':email, }) |
|
169 | {'email':email, }) | |
141 | print response.session['flash'] |
|
170 | print response.session['flash'] | |
142 | assert 'You have successfully registered into rhodecode' in response.session['flash'][0], 'No flash message about user registration' |
|
171 | assert 'You have successfully registered into rhodecode' in response.session['flash'][0], 'No flash message about user registration' | |
143 | assert 'Your new password was sent' in response.session['flash'][1], 'No flash message about password reset' |
|
172 | assert 'Your new password was sent' in response.session['flash'][1], 'No flash message about password reset' | |
144 |
|
173 | |||
145 |
|
174 | |||
146 |
|
175 |
General Comments 0
You need to be logged in to leave comments.
Login now