@@ -162,7 +162,7 @@ def test_access_token_azure_guest_but_no_upn_but_no_guest_username_claim(self):
162162 with self .assertRaises (exceptions .AuthenticationFailed ):
163163 self .drf_auth_class .authenticate (request )
164164
165- @mock_adfs ("azure" )
165+ @mock_adfs ("azure" , requires_obo = True )
166166 def test_process_group_claim_from_ms_graph (self ):
167167 access_token_header = "Bearer {}" .format (self .access_token_azure_groups_in_claim_source )
168168 request = RequestFactory ().get ('/api' , HTTP_AUTHORIZATION = access_token_header )
@@ -175,18 +175,61 @@ def test_process_group_claim_from_ms_graph(self):
175175 with patch ('django_auth_adfs.backend.settings' , Settings ()):
176176 with patch ("django_auth_adfs.config.settings" , Settings ()):
177177 with patch ("django_auth_adfs.backend.provider_config" , ProviderConfig ()):
178- with patch (
179- "django_auth_adfs.backend.AdfsBaseBackend.get_obo_access_token" ,
180- return_value = "123456"
181- ):
182- with patch (
183- "django_auth_adfs.backend.AdfsBaseBackend.get_group_memberships_from_ms_graph" ,
184- return_value = ["group1" , "group2" ]
185- ):
186- user , _ = self .drf_auth_class .authenticate (request )
187- self .assertEqual (user .username , "testuser" )
188- self .assertEqual (user .groups .all ()[0 ].name , "group1" )
189- self .assertEqual (user .groups .all ()[1 ].name , "group2" )
178+ user , _ = self .drf_auth_class .authenticate (request )
179+ self .assertEqual (user .username , "testuser" )
180+ self .assertEqual (user .groups .all ()[0 ].name , "group1" )
181+ self .assertEqual (user .groups .all ()[1 ].name , "group2" )
182+
183+ @mock_adfs ("azure" , requires_obo = True , mfa_error = True )
184+ def test_get_obo_access_token_mfa_error (self ):
185+ access_token_header = "Bearer {}" .format (self .access_token_azure_groups_in_claim_source )
186+ request = RequestFactory ().get ('/api' , HTTP_AUTHORIZATION = access_token_header )
187+
188+ from django_auth_adfs .config import django_settings
189+ settings = deepcopy (django_settings )
190+ del settings .AUTH_ADFS ["SERVER" ]
191+ settings .AUTH_ADFS ["TENANT_ID" ] = "dummy_tenant_id"
192+ with patch ("django_auth_adfs.config.django_settings" , settings ):
193+ with patch ('django_auth_adfs.backend.settings' , Settings ()):
194+ with patch ("django_auth_adfs.config.settings" , Settings ()):
195+ with patch ("django_auth_adfs.backend.provider_config" , ProviderConfig ()):
196+ with self .assertRaises (AuthenticationFailed ):
197+ self .drf_auth_class .authenticate (request )
198+
199+ @mock_adfs ("azure" , requires_obo = True , version = 'v2.0' )
200+ def test_get_obo_access_token_version_2 (self ):
201+ access_token_header = "Bearer {}" .format (self .access_token_azure_groups_in_claim_source )
202+ request = RequestFactory ().get ('/api' , HTTP_AUTHORIZATION = access_token_header )
203+
204+ from django_auth_adfs .config import django_settings
205+ settings = deepcopy (django_settings )
206+ del settings .AUTH_ADFS ["SERVER" ]
207+ settings .AUTH_ADFS ["TENANT_ID" ] = "dummy_tenant_id"
208+ settings .AUTH_ADFS ["VERSION" ] = 'v2.0'
209+ with patch ("django_auth_adfs.config.django_settings" , settings ):
210+ with patch ('django_auth_adfs.backend.settings' , Settings ()):
211+ with patch ("django_auth_adfs.config.settings" , Settings ()):
212+ with patch ("django_auth_adfs.backend.provider_config" , ProviderConfig ()):
213+ user , _ = self .drf_auth_class .authenticate (request )
214+ self .assertEqual (user .username , "testuser" )
215+ self .assertEqual (user .groups .all ()[0 ].name , "group1" )
216+ self .assertEqual (user .groups .all ()[1 ].name , "group2" )
217+
218+ @mock_adfs ("azure" , requires_obo = True , missing_graph_group_perm = True )
219+ def test_missing_ms_graph_group_permission (self ):
220+ access_token_header = "Bearer {}" .format (self .access_token_azure_groups_in_claim_source )
221+ request = RequestFactory ().get ('/api' , HTTP_AUTHORIZATION = access_token_header )
222+
223+ from django_auth_adfs .config import django_settings
224+ settings = deepcopy (django_settings )
225+ del settings .AUTH_ADFS ["SERVER" ]
226+ settings .AUTH_ADFS ["TENANT_ID" ] = "dummy_tenant_id"
227+ with patch ("django_auth_adfs.config.django_settings" , settings ):
228+ with patch ('django_auth_adfs.backend.settings' , Settings ()):
229+ with patch ("django_auth_adfs.config.settings" , Settings ()):
230+ with patch ("django_auth_adfs.backend.provider_config" , ProviderConfig ()):
231+ with self .assertRaises (AuthenticationFailed ):
232+ self .drf_auth_class .authenticate (request )
190233
191234 @mock_adfs ("2012" )
192235 def test_access_token_exceptions (self ):
0 commit comments