11from mock import Mock , call , patch
22
33from django .contrib .auth import get_user_model
4- from django .core .urlresolvers import reverse
54from django .test import TestCase , override_settings
65
76from mozilla_django_oidc .auth import OIDCAuthenticationBackend
@@ -28,8 +27,8 @@ def test_invalid_token(self, request_mock, token_mock):
2827 token_mock .return_value = None
2928 get_json_mock = Mock ()
3029 get_json_mock .json .return_value = {
31- 'username ' : 'username' ,
32- 'verified_email ' :
'[email protected] ' 30+ 'nickname ' : 'username' ,
31+ 3332 }
3433 request_mock .get .return_value = get_json_mock
3534 post_json_mock = Mock ()
@@ -53,6 +52,7 @@ def test_get_invalid_user(self):
5352
5453 @patch ('mozilla_django_oidc.auth.requests' )
5554 @patch ('mozilla_django_oidc.auth.OIDCAuthenticationBackend.verify_token' )
55+ @override_settings (SITE_URL = 'http://site-url.com' )
5656 def test_successful_authentication_existing_user (self , token_mock , request_mock ):
5757 """Test successful authentication for existing user."""
5858
@@ -61,8 +61,8 @@ def test_successful_authentication_existing_user(self, token_mock, request_mock)
6161 token_mock .return_value = True
6262 get_json_mock = Mock ()
6363 get_json_mock .json .return_value = {
64- 'username ' : 'a_username' ,
65- 'verified_email ' :
'[email protected] ' 64+ 'nickname ' : 'a_username' ,
65+ 6666 }
6767 request_mock .get .return_value = get_json_mock
6868 post_json_mock = Mock ()
@@ -75,9 +75,9 @@ def test_successful_authentication_existing_user(self, token_mock, request_mock)
7575 post_data = {
7676 'client_id' : 'example_id' ,
7777 'client_secret' : 'example_secret' ,
78- 'grand_type ' : 'authorization_code' ,
78+ 'grant_type ' : 'authorization_code' ,
7979 'code' : 'foo' ,
80- 'redirect_url ' : reverse ( 'oidc_authentication_callback' )
80+ 'redirect_uri ' : 'http://site-url.com/oidc/authentication_callback/'
8181 }
8282 self .assertEqual (self .backend .authenticate (code = 'foo' , state = 'bar' ), user )
8383 token_mock .assert_called_once_with ('id_token' )
@@ -90,14 +90,15 @@ def test_successful_authentication_existing_user(self, token_mock, request_mock)
9090
9191 @patch ('mozilla_django_oidc.auth.requests' )
9292 @patch ('mozilla_django_oidc.auth.OIDCAuthenticationBackend.verify_token' )
93+ @override_settings (SITE_URL = 'http://site-url.com' )
9394 def test_successful_authentication_new_user (self , token_mock , request_mock ):
9495 """Test successful authentication and user creation."""
9596
9697 token_mock .return_value = True
9798 get_json_mock = Mock ()
9899 get_json_mock .json .return_value = {
99- 'username ' : 'a_username' ,
100- 'verified_email ' :
'[email protected] ' 100+ 'nickname ' : 'a_username' ,
101+ 101102 }
102103 request_mock .get .return_value = get_json_mock
103104 post_json_mock = Mock ()
@@ -109,9 +110,9 @@ def test_successful_authentication_new_user(self, token_mock, request_mock):
109110 post_data = {
110111 'client_id' : 'example_id' ,
111112 'client_secret' : 'example_secret' ,
112- 'grand_type ' : 'authorization_code' ,
113+ 'grant_type ' : 'authorization_code' ,
113114 'code' : 'foo' ,
114- 'redirect_url ' : reverse ( 'oidc_authentication_callback' )
115+ 'redirect_uri ' : 'http://site-url.com/oidc/authentication_callback/' ,
115116 }
116117 self .assertEqual (User .objects .all ().count (), 0 )
117118 self .backend .authenticate (code = 'foo' , state = 'bar' )
@@ -143,8 +144,8 @@ def test_jwt_decode_params(self, request_mock, jwt_mock):
143144 }
144145 get_json_mock = Mock ()
145146 get_json_mock .json .return_value = {
146- 'username ' : 'username' ,
147- 'verified_email ' :
'[email protected] ' 147+ 'nickname ' : 'username' ,
148+ 148149 }
149150 request_mock .get .return_value = get_json_mock
150151 post_json_mock = Mock ()
@@ -171,8 +172,8 @@ def test_jwt_decode_params_verify_false(self, request_mock, jwt_mock):
171172 }
172173 get_json_mock = Mock ()
173174 get_json_mock .json .return_value = {
174- 'username ' : 'username' ,
175- 'verified_email ' :
'[email protected] ' 175+ 'nickname ' : 'username' ,
176+ 176177 }
177178 request_mock .get .return_value = get_json_mock
178179 post_json_mock = Mock ()
0 commit comments