Skip to content
Prev Previous commit
Next Next commit
Fix unit tests by passing conf we already had, not sure why get_confi…
…g fails there otherwise.
  • Loading branch information
Reece authored and Reece committed Apr 12, 2017
commit bd44fc050244d80d8df5bbc3cd7fa6d0dd10550e
12 changes: 7 additions & 5 deletions djangosaml2/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,18 @@ def available_idps(config, langpref=None):
return dict([(idp, config.metadata.name(idp, langpref)) for idp in idps])


def get_idp_sso_supported_bindings(idp_entity_id=None):
def get_idp_sso_supported_bindings(idp_entity_id=None, config=None):
"""Returns the list of bindings supported by an IDP
This is not clear in the pysaml2 code, so wrapping it in a util"""
# avoid circular import
from djangosaml2.conf import get_config
if config is None:
# avoid circular import
from djangosaml2.conf import get_config
config = get_config()
# load metadata store from config
config = get_config()
meta = getattr(config, 'metadata', {})
# if idp is None, assume only one exists so just use that
idp_entity_id = available_idps(config).keys().pop()
if idp_entity_id is None:
idp_entity_id = available_idps(config).keys().pop()
try:
return meta.service(idp_entity_id, 'idpsso_descriptor', 'single_sign_on_service').keys()
except UnknownSystemEntity:
Expand Down
2 changes: 1 addition & 1 deletion djangosaml2/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def login(request,
binding = BINDING_HTTP_POST if sign_requests else BINDING_HTTP_REDIRECT

# ensure our selected binding is supported by the IDP
supported_bindings = get_idp_sso_supported_bindings(selected_idp)
supported_bindings = get_idp_sso_supported_bindings(selected_idp, config=conf)
if binding not in supported_bindings:
logger.debug('Binding %s not in IDP %s supported bindings: %s',
binding, selected_idp, supported_bindings)
Expand Down