|
| 1 | +from contextlib import closing |
| 2 | +from saml2.client import Saml2Client |
| 3 | +from saml2.server import Server |
| 4 | + |
| 5 | + |
| 6 | +def test_authn_request_with_acs_by_index(): |
| 7 | + # ACS index and location from SP metadata in servera.xml. |
| 8 | + ACS_INDEX = '4' |
| 9 | + ACS_LOCATION = 'http://lingon.catalogix.se:8087/another/path' |
| 10 | + |
| 11 | + # Create SP using the configuration found in servera_conf.py. |
| 12 | + sp = Saml2Client(config_file="servera_conf") |
| 13 | + |
| 14 | + # Generate an authn request object that uses AssertionConsumerServiceIndex |
| 15 | + # instead of AssertionConsumerServiceURL. The index with label ACS_INDEX |
| 16 | + # exists in the SP metadata in servera.xml. |
| 17 | + request_id, authn_request = sp.create_authn_request( |
| 18 | + sp.config.entityid, |
| 19 | + assertion_consumer_service_index=ACS_INDEX) |
| 20 | + |
| 21 | + # Make sure the authn_request contains AssertionConsumerServiceIndex. |
| 22 | + acs_index = getattr(authn_request, |
| 23 | + 'assertion_consumer_service_index', None) |
| 24 | + |
| 25 | + assert acs_index == ACS_INDEX |
| 26 | + |
| 27 | + # Create IdP. |
| 28 | + with closing(Server(config_file="idp_all_conf")) as idp: |
| 29 | + |
| 30 | + # Ask the IdP to pick out the binding and destination from the |
| 31 | + # authn_request. |
| 32 | + binding, destination = idp.pick_binding("assertion_consumer_service", |
| 33 | + request=authn_request) |
| 34 | + |
| 35 | + # Make sure the IdP pick_binding method picks the correct location |
| 36 | + # or destination based on the ACS index in the authn request. |
| 37 | + assert destination == ACS_LOCATION |
0 commit comments