def test_set_sp_works_if_sp_defined(self, settings): mixin = IdPHandlerViewMixin() mixin.set_sp('test_generic_sp') assert mixin.sp == { 'id': 'test_generic_sp', 'config': settings.SAML_IDP_SPCONFIG['test_generic_sp'] }
def test_build_authn_response(self): mixin = IdPHandlerViewMixin() try: mixin.dispatch(HttpRequest()) except AttributeError: mixin.set_sp('test_generic_sp') mixin.set_processor() user = User() authn = mixin.get_authn() resp_args = { "in_response_to": "SP_Initiated_Login", "destination": "https://sp.example.com/SAML2", } assert isinstance( mixin.build_authn_response(user, authn, resp_args), Response)
def compile_data_for_render_response(self): mixin = IdPHandlerViewMixin() mixin.set_sp("test_generic_sp") mixin.set_processor() user = User.objects.create() user.email = "*****@*****.**", user.first_name = 'First Name', user.last_name = 'Last Name', user.is_staff = True user.is_superuser = False request = HttpRequest() request.user = user request.session = {} html_response = {"type": "POST", "data": "<html></html>"} return mixin, request, html_response
def test_get_processor_loads_custom_processor(self): mixin = IdPHandlerViewMixin() mixin.set_sp('test_sp_with_custom_processor') mixin.set_processor() assert isinstance(mixin.processor, CustomProcessor)
def test_set_processor_defaults_to_base_processor(self): mixin = IdPHandlerViewMixin() mixin.set_sp('test_sp_with_no_processor') mixin.set_processor() assert isinstance(mixin.processor, BaseProcessor)
def test_set_processor_errors_if_processor_cannot_be_loaded(self): mixin = IdPHandlerViewMixin() mixin.set_sp('test_sp_with_bad_processor') with pytest.raises(Exception): mixin.set_processor()
def test_set_sp_errors_if_sp_not_defined(self): mixin = IdPHandlerViewMixin() with pytest.raises(ImproperlyConfigured): mixin.set_sp('this_sp_does_not_exist')
def test_check_access_fails_when_it_should(self): mixin = IdPHandlerViewMixin() mixin.set_sp('test_sp_with_custom_processor_that_doesnt_allow_access') mixin.set_processor() with pytest.raises(PermissionDenied): mixin.check_access(HttpRequest())
def test_check_access_works(self): mixin = IdPHandlerViewMixin() mixin.set_sp('test_generic_sp') mixin.set_processor() mixin.check_access(HttpRequest())