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