3737from djangosaml2 .middleware import SamlSessionMiddleware
3838from djangosaml2 .signals import post_authenticated , pre_user_save
3939from djangosaml2 .tests import conf
40- from djangosaml2 .tests .auth_response import auth_response
41- from djangosaml2 .tests .utils import SAMLPostFormParser
42- from djangosaml2 .utils import (get_idp_sso_supported_bindings ,
40+ from djangosaml2 .utils import (get_custom_setting ,
41+ get_idp_sso_supported_bindings ,
4342 get_session_id_from_saml2 ,
4443 get_subject_id_from_saml2 ,
4544 saml2_from_httpredirect_request )
4645from djangosaml2 .views import finish_logout
4746from saml2 .config import SPConfig
4847from saml2 .s_utils import decode_base64_and_inflate , deflate_and_base64_encode
4948
49+ from .auth_response import auth_response
50+ from .utils import SAMLPostFormParser
51+
5052User = get_user_model ()
5153
5254PY_VERSION = sys .version_info [:2 ]
@@ -72,7 +74,7 @@ def test_get_config_nonsense_path(self):
7274 get_config ('lalala.nonexisting.blabla' )
7375
7476 def test_get_config_missing_function (self ):
75- with self .assertRaisesMessage (ImproperlyConfigured , 'Module "djangosaml2.tests" does not define a "nonexisting_function" config loader ' ):
77+ with self .assertRaisesMessage (ImproperlyConfigured , 'Module "djangosaml2.tests" does not define a "nonexisting_function" attribute/class ' ):
7678 get_config ('djangosaml2.tests.nonexisting_function' )
7779
7880
@@ -138,7 +140,7 @@ def test_get_idp_sso_supported_bindings_noargs(self):
138140 metadata_file = 'remote_metadata_one_idp.xml' ,
139141 )
140142 idp_id = 'https://idp.example.com/simplesaml/saml2/idp/metadata.php'
141- self .assertEqual (list ( get_idp_sso_supported_bindings () )[0 ], list (settings .SAML_CONFIG ['service' ]['sp' ]['idp' ][idp_id ]['single_sign_on_service' ].keys ())[0 ])
143+ self .assertEqual (get_idp_sso_supported_bindings ()[0 ], list (settings .SAML_CONFIG ['service' ]['sp' ]['idp' ][idp_id ]['single_sign_on_service' ].keys ())[0 ])
142144
143145 def test_get_idp_sso_supported_bindings_unknown_idp (self ):
144146 settings .SAML_CONFIG = conf .create_conf (
@@ -592,7 +594,7 @@ def _test_metadata(self):
592594
593595 expected_metadata = expected_metadata % valid_until
594596
595- response = self .client .get ('/metadata/' )
597+ response = self .client .get (reverse ( 'saml2_metadata' ) )
596598 self .assertEqual (response ['Content-type' ], 'text/xml; charset=utf8' )
597599 self .assertEqual (response .status_code , 200 )
598600 self .assertEqual (response .content , expected_metadata )
@@ -643,33 +645,6 @@ def signal_handler(sender, instance, attributes, user_modified, **kwargs):
643645
644646 pre_user_save .disconnect (dispatch_uid = 'test_signal' )
645647
646- def test_idplist_templatetag (self ):
647- settings .SAML_CONFIG = conf .create_conf (
648- sp_host = 'sp.example.com' ,
649- idp_hosts = ['idp1.example.com' ,
650- 'idp2.example.com' ,
651- 'idp3.example.com' ],
652- metadata_file = 'remote_metadata_three_idps.xml' ,
653- )
654- rendered = self .render_template (
655- '{% load idplist %}'
656- '{% idplist as idps %}'
657- '{% for url, name in idps.items %}'
658- '{{ url }} - {{ name }}; '
659- '{% endfor %}'
660- )
661-
662- # the idplist is unordered, so convert the result into a set.
663- rendered = set (rendered .split ('; ' ))
664- expected = set ([
665- u'https://idp1.example.com/simplesaml/saml2/idp/metadata.php - idp1.example.com IdP' ,
666- u'https://idp2.example.com/simplesaml/saml2/idp/metadata.php - idp2.example.com IdP' ,
667- u'https://idp3.example.com/simplesaml/saml2/idp/metadata.php - idp3.example.com IdP' ,
668- u'' ,
669- ])
670-
671- self .assertEqual (rendered , expected )
672-
673648 def test_sigalg_not_passed_when_not_signing_request (self ):
674649 # monkey patch SAML configuration
675650 settings .SAML_CONFIG = conf .create_conf (
@@ -754,7 +729,7 @@ def test_custom_conf_loader_from_view(self):
754729 saml_session_name = getattr (settings , 'SAML_SESSION_COOKIE_NAME' , 'saml_session' )
755730 getattr (request , saml_session_name ).save ()
756731
757- response = views .login ( request , config_loader_path )
732+ response = views .LoginView . as_view ( config_loader_path = config_loader_path )( request )
758733 self .assertEqual (response .status_code , 302 )
759734 location = response ['Location' ]
760735
0 commit comments