|
7 | 7 | AuthUserFactory, |
8 | 8 | UserFactory, |
9 | 9 | ) |
10 | | -<<<<<<< HEAD |
11 | 10 | from osf.models import Email, NotableDomain, NotificationType |
12 | 11 | from framework.auth.views import auth_email_logout |
13 | 12 | from tests.utils import capture_notifications |
14 | | -======= |
15 | | -from django.middleware import csrf |
16 | | -from django.core.cache import cache |
17 | | -from osf.models import Email, NotableDomain |
18 | | -from framework.auth.views import auth_email_logout |
19 | | -from website import mails, settings |
20 | | ->>>>>>> upstream/develop |
21 | 13 |
|
22 | 14 | @pytest.fixture() |
23 | 15 | def user_one(): |
@@ -177,141 +169,6 @@ def test_multiple_errors(self, app, user_one, url, payload): |
177 | 169 |
|
178 | 170 |
|
179 | 171 | @pytest.mark.django_db |
180 | | -<<<<<<< HEAD |
181 | | -======= |
182 | | -@pytest.mark.usefixtures('mock_send_grid') |
183 | | -class TestResetPassword: |
184 | | - |
185 | | - @pytest.fixture() |
186 | | - def user_one(self): |
187 | | - user = UserFactory() |
188 | | - user.set_password('password1') |
189 | | - user.auth = (user.username, 'password1') |
190 | | - user.save() |
191 | | - return user |
192 | | - |
193 | | - @pytest.fixture() |
194 | | - def url(self): |
195 | | - return f'/{API_BASE}users/reset_password/' |
196 | | - |
197 | | - @pytest.fixture |
198 | | - def csrf_token(self): |
199 | | - return csrf._mask_cipher_secret(csrf._get_new_csrf_string()) |
200 | | - |
201 | | - @pytest.fixture(autouse=True) |
202 | | - def clear_throttle_cache(self): |
203 | | - cache.clear() |
204 | | - |
205 | | - def test_get(self, app, url, user_one): |
206 | | - encoded_email = urllib.parse.quote(user_one.email) |
207 | | - url = f'{url}?email={encoded_email}' |
208 | | - with mock.patch.object(mails, 'send_mail', return_value=None) as mock_send_mail: |
209 | | - res = app.get(url) |
210 | | - assert res.status_code == 200 |
211 | | - |
212 | | - user_one.reload() |
213 | | - mock_send_mail.assert_called_with( |
214 | | - to_addr=user_one.username, |
215 | | - mail=mails.FORGOT_PASSWORD, |
216 | | - reset_link=f'{settings.DOMAIN}resetpassword/{user_one._id}/{user_one.verification_key_v2['token']}', |
217 | | - can_change_preferences=False, |
218 | | - ) |
219 | | - |
220 | | - def test_get_invalid_email(self, mock_send_grid, app, url): |
221 | | - url = f'{url}?email={'invalid_email'}' |
222 | | - res = app.get(url) |
223 | | - assert res.status_code == 200 |
224 | | - assert not mock_send_grid.called |
225 | | - |
226 | | - def test_post(self, app, url, user_one): |
227 | | - encoded_email = urllib.parse.quote(user_one.email) |
228 | | - url = f'{url}?email={encoded_email}' |
229 | | - res = app.get(url) |
230 | | - user_one.reload() |
231 | | - payload = { |
232 | | - 'data': { |
233 | | - 'attributes': { |
234 | | - 'uid': user_one._id, |
235 | | - 'token': user_one.verification_key_v2['token'], |
236 | | - 'password': 'password2', |
237 | | - } |
238 | | - } |
239 | | - } |
240 | | - |
241 | | - res = app.post_json_api(url, payload) |
242 | | - user_one.reload() |
243 | | - assert res.status_code == 200 |
244 | | - assert user_one.check_password('password2') |
245 | | - |
246 | | - def test_post_empty_payload(self, app, url, csrf_token): |
247 | | - app.set_cookie(CSRF_COOKIE_NAME, csrf_token) |
248 | | - payload = { |
249 | | - 'data': { |
250 | | - 'attributes': { |
251 | | - } |
252 | | - } |
253 | | - } |
254 | | - res = app.post_json_api(url, payload, expect_errors=True, headers={'X-CSRFToken': csrf_token}) |
255 | | - assert res.status_code == 400 |
256 | | - |
257 | | - def test_post_invalid_token(self, app, url, user_one, csrf_token): |
258 | | - app.set_cookie(CSRF_COOKIE_NAME, csrf_token) |
259 | | - payload = { |
260 | | - 'data': { |
261 | | - 'attributes': { |
262 | | - 'uid': user_one._id, |
263 | | - 'token': 'invalid_token', |
264 | | - 'password': 'password2', |
265 | | - } |
266 | | - } |
267 | | - } |
268 | | - res = app.post_json_api(url, payload, expect_errors=True, headers={'X-THROTTLE-TOKEN': 'test-token', 'X-CSRFToken': csrf_token}) |
269 | | - assert res.status_code == 400 |
270 | | - |
271 | | - def test_post_invalid_password(self, app, url, user_one, csrf_token): |
272 | | - app.set_cookie(CSRF_COOKIE_NAME, csrf_token) |
273 | | - encoded_email = urllib.parse.quote(user_one.email) |
274 | | - url = f'{url}?email={encoded_email}' |
275 | | - res = app.get(url) |
276 | | - user_one.reload() |
277 | | - payload = { |
278 | | - 'data': { |
279 | | - 'attributes': { |
280 | | - 'uid': user_one._id, |
281 | | - 'token': user_one.verification_key_v2['token'], |
282 | | - 'password': user_one.username, |
283 | | - } |
284 | | - } |
285 | | - } |
286 | | - |
287 | | - res = app.post_json_api(url, payload, expect_errors=True, headers={'X-THROTTLE-TOKEN': 'test-token', 'X-CSRFToken': csrf_token}) |
288 | | - assert res.status_code == 400 |
289 | | - |
290 | | - def test_throttle(self, app, url, user_one): |
291 | | - encoded_email = urllib.parse.quote(user_one.email) |
292 | | - url = f'{url}?email={encoded_email}' |
293 | | - app.get(url) |
294 | | - user_one.reload() |
295 | | - payload = { |
296 | | - 'data': { |
297 | | - 'attributes': { |
298 | | - 'uid': user_one._id, |
299 | | - 'token': user_one.verification_key_v2['token'], |
300 | | - 'password': '12345', |
301 | | - } |
302 | | - } |
303 | | - } |
304 | | - |
305 | | - res = app.post_json_api(url, payload, expect_errors=False) |
306 | | - assert res.status_code == 200 |
307 | | - |
308 | | - res = app.get(url, expect_errors=True) |
309 | | - assert res.status_code == 429 |
310 | | - assert res.json['message'] == 'You have recently requested to change your password. Please wait a few minutes before trying again.' |
311 | | - |
312 | | - |
313 | | -@pytest.mark.django_db |
314 | | ->>>>>>> upstream/develop |
315 | 172 | class TestUserEmailsList: |
316 | 173 |
|
317 | 174 | @pytest.fixture(autouse=True) |
|
0 commit comments