|
37 | 37 | from djangosaml2.conf import get_config |
38 | 38 | from djangosaml2.signals import post_authenticated |
39 | 39 | from djangosaml2.tests import conf |
| 40 | +from djangosaml2.tests.utils import SAMLPostFormParser |
40 | 41 | from djangosaml2.tests.auth_response import auth_response |
41 | 42 | from djangosaml2.views import finish_logout |
42 | 43 | from saml2.config import SPConfig |
@@ -108,6 +109,35 @@ def render_template(self, text): |
108 | 109 | def b64_for_post(self, xml_text, encoding='utf-8'): |
109 | 110 | return base64.b64encode(xml_text.encode(encoding)).decode('ascii') |
110 | 111 |
|
| 112 | + def test_unsigned_post_authn_request(self): |
| 113 | + """ |
| 114 | + Test that unsigned authentication requests via POST binding |
| 115 | + does not error. |
| 116 | +
|
| 117 | + https://github.com/knaperek/djangosaml2/issues/168 |
| 118 | + """ |
| 119 | + settings.SAML_CONFIG = conf.create_conf( |
| 120 | + sp_host='sp.example.com', |
| 121 | + idp_hosts=['idp.example.com'], |
| 122 | + metadata_file='remote_metadata_post_binding.xml', |
| 123 | + authn_requests_signed=False |
| 124 | + ) |
| 125 | + response = self.client.get(reverse('saml2_login')) |
| 126 | + |
| 127 | + self.assertEqual(response.status_code, 200) |
| 128 | + |
| 129 | + # Using POST-binding returns a page with form containing the SAMLRequest |
| 130 | + response_parser = SAMLPostFormParser() |
| 131 | + response_parser.feed(response.content.decode('utf-8')) |
| 132 | + saml_request = response_parser.saml_request_value |
| 133 | + expected_request = """<samlp:AuthnRequest xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol" AssertionConsumerServiceURL="http://sp.example.com/saml2/acs/" Destination="https://idp.example.com/simplesaml/saml2/idp/SSOService.php" ID="XXXXXXXXXXXXXXXXXXXXXX" IssueInstant="2010-01-01T00:00:00Z" ProtocolBinding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST" Version="2.0"><saml:Issuer Format="urn:oasis:names:tc:SAML:2.0:nameid-format:entity">http://sp.example.com/saml2/metadata/</saml:Issuer><samlp:NameIDPolicy AllowCreate="false" Format="urn:oasis:names:tc:SAML:2.0:nameid-format:persistent" /></samlp:AuthnRequest>""" |
| 134 | + |
| 135 | + self.assertIsNotNone(saml_request) |
| 136 | + self.assertSAMLRequestsEquals( |
| 137 | + base64.b64decode(saml_request).decode('utf-8'), |
| 138 | + expected_request |
| 139 | + ) |
| 140 | + |
111 | 141 | def test_login_evil_redirect(self): |
112 | 142 | """ |
113 | 143 | Make sure that if we give an URL other than our own host as the next |
|
0 commit comments