|
1 | 1 | from unittest import mock
|
2 | 2 | import pytest
|
3 |
| -import urllib |
4 | 3 |
|
5 | 4 | from api.base.settings.defaults import API_BASE
|
6 |
| -from api.base.settings import CSRF_COOKIE_NAME |
7 | 5 | from api.base.utils import hashids
|
8 | 6 | from osf_tests.factories import (
|
9 | 7 | AuthUserFactory,
|
10 | 8 | UserFactory,
|
11 | 9 | )
|
12 |
| -from django.middleware import csrf |
13 | 10 | from osf.models import Email, NotableDomain
|
14 | 11 | from framework.auth.views import auth_email_logout
|
15 | 12 |
|
@@ -167,128 +164,6 @@ def test_multiple_errors(self, app, user_one, url, payload):
|
167 | 164 | assert res.json['errors'][1]['detail'] == 'Password should be at least eight characters'
|
168 | 165 |
|
169 | 166 |
|
170 |
| -@pytest.mark.django_db |
171 |
| -@pytest.mark.usefixtures('mock_send_grid') |
172 |
| -class TestResetPassword: |
173 |
| - |
174 |
| - @pytest.fixture() |
175 |
| - def user_one(self): |
176 |
| - user = UserFactory() |
177 |
| - user.set_password('password1') |
178 |
| - user.auth = (user.username, 'password1') |
179 |
| - user.save() |
180 |
| - return user |
181 |
| - |
182 |
| - @pytest.fixture() |
183 |
| - def url(self): |
184 |
| - return f'/{API_BASE}users/reset_password/' |
185 |
| - |
186 |
| - @pytest.fixture |
187 |
| - def csrf_token(self): |
188 |
| - return csrf._mask_cipher_secret(csrf._get_new_csrf_string()) |
189 |
| - |
190 |
| - def test_get(self, mock_send_grid, app, url, user_one): |
191 |
| - encoded_email = urllib.parse.quote(user_one.email) |
192 |
| - url = f'{url}?email={encoded_email}' |
193 |
| - res = app.get(url) |
194 |
| - assert res.status_code == 200 |
195 |
| - |
196 |
| - user_one.reload() |
197 |
| - assert mock_send_grid.call_args[1]['to_addr'] == user_one.username |
198 |
| - |
199 |
| - def test_get_invalid_email(self, mock_send_grid, app, url): |
200 |
| - url = f'{url}?email={'invalid_email'}' |
201 |
| - res = app.get(url) |
202 |
| - assert res.status_code == 200 |
203 |
| - assert not mock_send_grid.called |
204 |
| - |
205 |
| - def test_post(self, app, url, user_one, csrf_token): |
206 |
| - app.set_cookie(CSRF_COOKIE_NAME, csrf_token) |
207 |
| - encoded_email = urllib.parse.quote(user_one.email) |
208 |
| - url = f'{url}?email={encoded_email}' |
209 |
| - res = app.get(url) |
210 |
| - user_one.reload() |
211 |
| - payload = { |
212 |
| - 'data': { |
213 |
| - 'attributes': { |
214 |
| - 'uid': user_one._id, |
215 |
| - 'token': user_one.verification_key_v2['token'], |
216 |
| - 'password': 'password2', |
217 |
| - } |
218 |
| - } |
219 |
| - } |
220 |
| - |
221 |
| - res = app.post_json_api(url, payload, headers={'X-CSRFToken': csrf_token}) |
222 |
| - user_one.reload() |
223 |
| - assert res.status_code == 200 |
224 |
| - assert user_one.check_password('password2') |
225 |
| - |
226 |
| - def test_post_empty_payload(self, app, url, csrf_token): |
227 |
| - app.set_cookie(CSRF_COOKIE_NAME, csrf_token) |
228 |
| - payload = { |
229 |
| - 'data': { |
230 |
| - 'attributes': { |
231 |
| - } |
232 |
| - } |
233 |
| - } |
234 |
| - res = app.post_json_api(url, payload, expect_errors=True, headers={'X-CSRFToken': csrf_token}) |
235 |
| - assert res.status_code == 400 |
236 |
| - |
237 |
| - def test_post_invalid_token(self, app, url, user_one, csrf_token): |
238 |
| - app.set_cookie(CSRF_COOKIE_NAME, csrf_token) |
239 |
| - payload = { |
240 |
| - 'data': { |
241 |
| - 'attributes': { |
242 |
| - 'uid': user_one._id, |
243 |
| - 'token': 'invalid_token', |
244 |
| - 'password': 'password2', |
245 |
| - } |
246 |
| - } |
247 |
| - } |
248 |
| - res = app.post_json_api(url, payload, expect_errors=True, headers={'X-THROTTLE-TOKEN': 'test-token', 'X-CSRFToken': csrf_token}) |
249 |
| - assert res.status_code == 400 |
250 |
| - |
251 |
| - def test_post_invalid_password(self, app, url, user_one, csrf_token): |
252 |
| - app.set_cookie(CSRF_COOKIE_NAME, csrf_token) |
253 |
| - encoded_email = urllib.parse.quote(user_one.email) |
254 |
| - url = f'{url}?email={encoded_email}' |
255 |
| - res = app.get(url) |
256 |
| - user_one.reload() |
257 |
| - payload = { |
258 |
| - 'data': { |
259 |
| - 'attributes': { |
260 |
| - 'uid': user_one._id, |
261 |
| - 'token': user_one.verification_key_v2['token'], |
262 |
| - 'password': user_one.username, |
263 |
| - } |
264 |
| - } |
265 |
| - } |
266 |
| - |
267 |
| - res = app.post_json_api(url, payload, expect_errors=True, headers={'X-THROTTLE-TOKEN': 'test-token', 'X-CSRFToken': csrf_token}) |
268 |
| - assert res.status_code == 400 |
269 |
| - |
270 |
| - def test_throrrle(self, app, url, user_one): |
271 |
| - encoded_email = urllib.parse.quote(user_one.email) |
272 |
| - url = f'{url}?email={encoded_email}' |
273 |
| - res = app.get(url) |
274 |
| - user_one.reload() |
275 |
| - payload = { |
276 |
| - 'data': { |
277 |
| - 'attributes': { |
278 |
| - 'uid': user_one._id, |
279 |
| - 'token': user_one.verification_key_v2['token'], |
280 |
| - 'password': '12345', |
281 |
| - } |
282 |
| - } |
283 |
| - } |
284 |
| - |
285 |
| - res = app.post_json_api(url, payload, expect_errors=True) |
286 |
| - assert res.status_code == 429 |
287 |
| - |
288 |
| - res = app.get(url, expect_errors=True) |
289 |
| - assert res.json['message'] == 'You have recently requested to change your password. Please wait a few minutes before trying again.' |
290 |
| - |
291 |
| - |
292 | 167 | @pytest.mark.django_db
|
293 | 168 | class TestUserEmailsList:
|
294 | 169 |
|
|
0 commit comments