@@ -324,7 +324,7 @@ def test_valid_registration(self):
324
324
response .status_code ,
325
325
rest_framework .status .HTTP_200_OK ,
326
326
)
327
- self .assertIn ('token ' , response .data )
327
+ self .assertIn ('access ' , response .data )
328
328
self .assertTrue (
329
329
user .models .User .objects .filter (
330
330
@@ -391,7 +391,7 @@ def test_signin_success(self):
391
391
392
392
class JWTTests (rest_framework .test .APITestCase ):
393
393
def setUp (self ):
394
-
394
+ self . signup_url = django . urls . reverse ( 'api-user:sign-up' )
395
395
self .signin_url = django .urls .reverse ('api-user:sign-in' )
396
396
self .protected_url = django .urls .reverse ('api-core:protected' )
397
397
self .refresh_url = django .urls .reverse ('api-user:token_refresh' )
@@ -428,6 +428,47 @@ def test_access_protected_view_with_valid_token(self):
428
428
self .assertEqual (response .status_code , 200 )
429
429
self .assertEqual (response .data ['status' ], 'request was permitted' )
430
430
431
+ def test_registration_token_invalid_after_login (self ):
432
+ data = {
433
+
434
+ 'password' : 'StrongPass123!cd' ,
435
+ 'name' : 'John' ,
436
+ 'surname' : 'Doe' ,
437
+ 'other' : {'age' : 22 , 'country' : 'us' },
438
+ }
439
+ response = self .client .post (
440
+ self .signup_url ,
441
+ data ,
442
+ format = 'json' ,
443
+ )
444
+ reg_access_token = response .data ['access' ]
445
+
446
+ self .client .credentials (
447
+ HTTP_AUTHORIZATION = f'Bearer { reg_access_token } ' ,
448
+ )
449
+ response = self .client .get (self .protected_url )
450
+ self .assertEqual (response .status_code , 200 )
451
+
452
+ login_data = {'email' : data ['email' ], 'password' : data ['password' ]}
453
+ response = self .client .post (
454
+ self .signin_url ,
455
+ login_data ,
456
+ format = 'json' ,
457
+ )
458
+ login_access_token = response .data ['access' ]
459
+
460
+ self .client .credentials (
461
+ HTTP_AUTHORIZATION = f'Bearer { reg_access_token } ' ,
462
+ )
463
+ response = self .client .get (self .protected_url )
464
+ self .assertEqual (response .status_code , 401 )
465
+
466
+ self .client .credentials (
467
+ HTTP_AUTHORIZATION = f'Bearer { login_access_token } ' ,
468
+ )
469
+ response = self .client .get (self .protected_url )
470
+ self .assertEqual (response .status_code , 200 )
471
+
431
472
def test_refresh_token_invalidation_after_new_login (self ):
432
473
433
474
first_login_response = self .client .post (
0 commit comments