@@ -466,17 +466,13 @@ def setUp(self):
466
466
def _create_authorization_header (self , token = None ):
467
467
return "Bearer {0}" .format (token or self .access_token .token )
468
468
469
- def _client_credentials_params (self ):
470
- return {'client_id' : self .CLIENT_ID , 'client_secret' : self .CLIENT_SECRET }
471
-
472
469
@unittest .skipUnless (oauth2_provider , 'django-oauth2-provider not installed' )
473
470
def test_get_form_with_wrong_authorization_header_token_type_failing (self ):
474
471
"""Ensure that a wrong token type lead to the correct HTTP error status code"""
475
472
auth = "Wrong token-type-obsviously"
476
473
response = self .csrf_client .get ('/oauth2-test/' , {}, HTTP_AUTHORIZATION = auth )
477
474
self .assertEqual (response .status_code , 401 )
478
- params = self ._client_credentials_params ()
479
- response = self .csrf_client .get ('/oauth2-test/' , params , HTTP_AUTHORIZATION = auth )
475
+ response = self .csrf_client .get ('/oauth2-test/' , HTTP_AUTHORIZATION = auth )
480
476
self .assertEqual (response .status_code , 401 )
481
477
482
478
@unittest .skipUnless (oauth2_provider , 'django-oauth2-provider not installed' )
@@ -485,8 +481,7 @@ def test_get_form_with_wrong_authorization_header_token_format_failing(self):
485
481
auth = "Bearer wrong token format"
486
482
response = self .csrf_client .get ('/oauth2-test/' , {}, HTTP_AUTHORIZATION = auth )
487
483
self .assertEqual (response .status_code , 401 )
488
- params = self ._client_credentials_params ()
489
- response = self .csrf_client .get ('/oauth2-test/' , params , HTTP_AUTHORIZATION = auth )
484
+ response = self .csrf_client .get ('/oauth2-test/' , HTTP_AUTHORIZATION = auth )
490
485
self .assertEqual (response .status_code , 401 )
491
486
492
487
@unittest .skipUnless (oauth2_provider , 'django-oauth2-provider not installed' )
@@ -495,50 +490,36 @@ def test_get_form_with_wrong_authorization_header_token_failing(self):
495
490
auth = "Bearer wrong-token"
496
491
response = self .csrf_client .get ('/oauth2-test/' , {}, HTTP_AUTHORIZATION = auth )
497
492
self .assertEqual (response .status_code , 401 )
498
- params = self ._client_credentials_params ()
499
- response = self .csrf_client .get ('/oauth2-test/' , params , HTTP_AUTHORIZATION = auth )
500
- self .assertEqual (response .status_code , 401 )
501
-
502
- @unittest .skipUnless (oauth2_provider , 'django-oauth2-provider not installed' )
503
- def test_get_form_with_wrong_client_data_failing_auth (self ):
504
- """Ensure GETing form over OAuth with incorrect client credentials fails"""
505
- auth = self ._create_authorization_header ()
506
- params = self ._client_credentials_params ()
507
- params ['client_id' ] += 'a'
508
- response = self .csrf_client .get ('/oauth2-test/' , params , HTTP_AUTHORIZATION = auth )
493
+ response = self .csrf_client .get ('/oauth2-test/' , HTTP_AUTHORIZATION = auth )
509
494
self .assertEqual (response .status_code , 401 )
510
495
511
496
@unittest .skipUnless (oauth2_provider , 'django-oauth2-provider not installed' )
512
497
def test_get_form_passing_auth (self ):
513
498
"""Ensure GETing form over OAuth with correct client credentials succeed"""
514
499
auth = self ._create_authorization_header ()
515
- params = self ._client_credentials_params ()
516
- response = self .csrf_client .get ('/oauth2-test/' , params , HTTP_AUTHORIZATION = auth )
500
+ response = self .csrf_client .get ('/oauth2-test/' , HTTP_AUTHORIZATION = auth )
517
501
self .assertEqual (response .status_code , 200 )
518
502
519
503
@unittest .skipUnless (oauth2_provider , 'django-oauth2-provider not installed' )
520
504
def test_post_form_passing_auth (self ):
521
505
"""Ensure POSTing form over OAuth with correct credentials passes and does not require CSRF"""
522
506
auth = self ._create_authorization_header ()
523
- params = self ._client_credentials_params ()
524
- response = self .csrf_client .post ('/oauth2-test/' , params , HTTP_AUTHORIZATION = auth )
507
+ response = self .csrf_client .post ('/oauth2-test/' , HTTP_AUTHORIZATION = auth )
525
508
self .assertEqual (response .status_code , 200 )
526
509
527
510
@unittest .skipUnless (oauth2_provider , 'django-oauth2-provider not installed' )
528
511
def test_post_form_token_removed_failing_auth (self ):
529
512
"""Ensure POSTing when there is no OAuth access token in db fails"""
530
513
self .access_token .delete ()
531
514
auth = self ._create_authorization_header ()
532
- params = self ._client_credentials_params ()
533
- response = self .csrf_client .post ('/oauth2-test/' , params , HTTP_AUTHORIZATION = auth )
515
+ response = self .csrf_client .post ('/oauth2-test/' , HTTP_AUTHORIZATION = auth )
534
516
self .assertIn (response .status_code , (status .HTTP_401_UNAUTHORIZED , status .HTTP_403_FORBIDDEN ))
535
517
536
518
@unittest .skipUnless (oauth2_provider , 'django-oauth2-provider not installed' )
537
519
def test_post_form_with_refresh_token_failing_auth (self ):
538
520
"""Ensure POSTing with refresh token instead of access token fails"""
539
521
auth = self ._create_authorization_header (token = self .refresh_token .token )
540
- params = self ._client_credentials_params ()
541
- response = self .csrf_client .post ('/oauth2-test/' , params , HTTP_AUTHORIZATION = auth )
522
+ response = self .csrf_client .post ('/oauth2-test/' , HTTP_AUTHORIZATION = auth )
542
523
self .assertIn (response .status_code , (status .HTTP_401_UNAUTHORIZED , status .HTTP_403_FORBIDDEN ))
543
524
544
525
@unittest .skipUnless (oauth2_provider , 'django-oauth2-provider not installed' )
@@ -547,8 +528,7 @@ def test_post_form_with_expired_access_token_failing_auth(self):
547
528
self .access_token .expires = datetime .datetime .now () - datetime .timedelta (seconds = 10 ) # 10 seconds late
548
529
self .access_token .save ()
549
530
auth = self ._create_authorization_header ()
550
- params = self ._client_credentials_params ()
551
- response = self .csrf_client .post ('/oauth2-test/' , params , HTTP_AUTHORIZATION = auth )
531
+ response = self .csrf_client .post ('/oauth2-test/' , HTTP_AUTHORIZATION = auth )
552
532
self .assertIn (response .status_code , (status .HTTP_401_UNAUTHORIZED , status .HTTP_403_FORBIDDEN ))
553
533
self .assertIn ('Invalid token' , response .content )
554
534
@@ -559,10 +539,9 @@ def test_post_form_with_invalid_scope_failing_auth(self):
559
539
read_only_access_token .scope = oauth2_provider_scope .SCOPE_NAME_DICT ['read' ]
560
540
read_only_access_token .save ()
561
541
auth = self ._create_authorization_header (token = read_only_access_token .token )
562
- params = self ._client_credentials_params ()
563
- response = self .csrf_client .get ('/oauth2-with-scope-test/' , params , HTTP_AUTHORIZATION = auth )
542
+ response = self .csrf_client .get ('/oauth2-with-scope-test/' , HTTP_AUTHORIZATION = auth )
564
543
self .assertEqual (response .status_code , 200 )
565
- response = self .csrf_client .post ('/oauth2-with-scope-test/' , params , HTTP_AUTHORIZATION = auth )
544
+ response = self .csrf_client .post ('/oauth2-with-scope-test/' , HTTP_AUTHORIZATION = auth )
566
545
self .assertEqual (response .status_code , status .HTTP_403_FORBIDDEN )
567
546
568
547
@unittest .skipUnless (oauth2_provider , 'django-oauth2-provider not installed' )
@@ -572,6 +551,5 @@ def test_post_form_with_valid_scope_passing_auth(self):
572
551
read_write_access_token .scope = oauth2_provider_scope .SCOPE_NAME_DICT ['write' ]
573
552
read_write_access_token .save ()
574
553
auth = self ._create_authorization_header (token = read_write_access_token .token )
575
- params = self ._client_credentials_params ()
576
- response = self .csrf_client .post ('/oauth2-with-scope-test/' , params , HTTP_AUTHORIZATION = auth )
554
+ response = self .csrf_client .post ('/oauth2-with-scope-test/' , HTTP_AUTHORIZATION = auth )
577
555
self .assertEqual (response .status_code , 200 )
0 commit comments