1111from  oauth2_provider .oauth2_validators  import  OAuth2Validator 
1212from  oauth2_provider .views .mixins  import  (
1313    OAuthLibMixin ,
14+     OIDCLogoutOnlyMixin ,
1415    OIDCOnlyMixin ,
1516    ProtectedResourceMixin ,
1617    ScopedResourceMixin ,
@@ -145,6 +146,15 @@ def get(self, *args, **kwargs):
145146    return  TView .as_view ()
146147
147148
149+ @pytest .fixture  
150+ def  oidc_logout_only_view ():
151+     class  TView (OIDCLogoutOnlyMixin , View ):
152+         def  get (self , * args , ** kwargs ):
153+             return  HttpResponse ("OK" )
154+ 
155+     return  TView .as_view ()
156+ 
157+ 
148158@pytest .mark .oauth2_settings (presets .OIDC_SETTINGS_RW ) 
149159def  test_oidc_only_mixin_oidc_enabled (oauth2_settings , rf , oidc_only_view ):
150160    assert  oauth2_settings .OIDC_ENABLED 
@@ -153,6 +163,14 @@ def test_oidc_only_mixin_oidc_enabled(oauth2_settings, rf, oidc_only_view):
153163    assert  rsp .content .decode ("utf-8" ) ==  "OK" 
154164
155165
166+ @pytest .mark .oauth2_settings (presets .OIDC_SETTINGS_RP_LOGOUT ) 
167+ def  test_oidc_logout_only_mixin_oidc_enabled (oauth2_settings , rf , oidc_only_view ):
168+     assert  oauth2_settings .OIDC_RP_INITIATED_LOGOUT_ENABLED 
169+     rsp  =  oidc_only_view (rf .get ("/" ))
170+     assert  rsp .status_code  ==  200 
171+     assert  rsp .content .decode ("utf-8" ) ==  "OK" 
172+ 
173+ 
156174def  test_oidc_only_mixin_oidc_disabled_debug (oauth2_settings , rf , settings , oidc_only_view ):
157175    assert  oauth2_settings .OIDC_ENABLED  is  False 
158176    settings .DEBUG  =  True 
@@ -161,6 +179,14 @@ def test_oidc_only_mixin_oidc_disabled_debug(oauth2_settings, rf, settings, oidc
161179    assert  "OIDC views are not enabled"  in  str (exc .value )
162180
163181
182+ def  test_oidc_logout_only_mixin_oidc_disabled_debug (oauth2_settings , rf , settings , oidc_logout_only_view ):
183+     assert  oauth2_settings .OIDC_RP_INITIATED_LOGOUT_ENABLED  is  False 
184+     settings .DEBUG  =  True 
185+     with  pytest .raises (ImproperlyConfigured ) as  exc :
186+         oidc_logout_only_view (rf .get ("/" ))
187+         assert  str (exc .value ) ==  OIDCLogoutOnlyMixin .debug_error_message 
188+ 
189+ 
164190def  test_oidc_only_mixin_oidc_disabled_no_debug (oauth2_settings , rf , settings , oidc_only_view , caplog ):
165191    assert  oauth2_settings .OIDC_ENABLED  is  False 
166192    settings .DEBUG  =  False 
@@ -169,3 +195,15 @@ def test_oidc_only_mixin_oidc_disabled_no_debug(oauth2_settings, rf, settings, o
169195    assert  rsp .status_code  ==  404 
170196    assert  len (caplog .records ) ==  1 
171197    assert  "OIDC views are not enabled"  in  caplog .records [0 ].message 
198+ 
199+ 
200+ def  test_oidc_logout_only_mixin_oidc_disabled_no_debug (
201+     oauth2_settings , rf , settings , oidc_logout_only_view , caplog 
202+ ):
203+     assert  oauth2_settings .OIDC_RP_INITIATED_LOGOUT_ENABLED  is  False 
204+     settings .DEBUG  =  False 
205+     with  caplog .at_level (logging .WARNING , logger = "oauth2_provider" ):
206+         rsp  =  oidc_logout_only_view (rf .get ("/" ))
207+         assert  rsp .status_code  ==  404 
208+         assert  len (caplog .records ) ==  1 
209+         assert  caplog .records [0 ].message  ==  OIDCLogoutOnlyMixin .debug_error_message 
0 commit comments