diff --git a/lib/saml2.coffee b/lib/saml2.coffee index 2e1e9b6..c200012 100644 --- a/lib/saml2.coffee +++ b/lib/saml2.coffee @@ -337,7 +337,7 @@ parse_authn_response = (saml_response, sp_private_key, idp_certificates, allow_u assertion = saml_response.getElementsByTagNameNS(XMLNS.SAML, 'Assertion') unless assertion.length is 1 return cb_wf new Error("Expected 1 Assertion or 1 EncryptedAssertion; found #{assertion.length}") - cb_wf null, assertion[0].toString() + cb_wf null, saml_response.toString() (result, cb_wf) -> debug result decrypted_assertion = (new xmldom.DOMParser()).parseFromString(result) @@ -541,4 +541,3 @@ if process.env.NODE_ENV is "test" module.exports.get_session_index = get_session_index module.exports.parse_assertion_attributes = parse_assertion_attributes module.exports.set_option_defaults = set_option_defaults - diff --git a/test/data/post_response_outer_signature.xml b/test/data/post_response_outer_signature.xml new file mode 100644 index 0000000..2ad5801 --- /dev/null +++ b/test/data/post_response_outer_signature.xml @@ -0,0 +1 @@ +PHNhbWxwOlJlc3BvbnNlIHhtbG5zOnNhbWxwPSJ1cm46b2FzaXM6bmFtZXM6dGM6U0FNTDoyLjA6cHJvdG9jb2wiPjxzYW1sOkFzc2VydGlvbiB4bWxuczpzYW1sPSJ1cm46b2FzaXM6bmFtZXM6dGM6U0FNTDoyLjA6YXNzZXJ0aW9uIj48c2FtbDpBdXRoblN0YXRlbWVudCBTZXNzaW9uSW5kZXg9ImIwN2I4MDRjLTdjMjktZWExNi03MzAwLTRmM2Q2Zjc5MjhhYyIvPjxzYW1sOlN1YmplY3Q+PHNhbWw6TmFtZUlEIEZvcm1hdD0idXJuOm9hc2lzOm5hbWVzOnRjOlNBTUw6Mi4wOm5hbWVpZC1mb3JtYXQ6dHJhbnNpZW50Ij5CZW5qYW1pbjwvc2FtbDpOYW1lSUQ+PC9zYW1sOlN1YmplY3Q+PC9zYW1sOkFzc2VydGlvbj48c2FtbHA6U3RhdHVzPjxzYW1scDpTdGF0dXNDb2RlIFZhbHVlPSJ1cm46b2FzaXM6bmFtZXM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09qMDlsRWhuUEFwMDBNNFdsaDY3Y3lyMEF2am9UNkdqdkdoZTVIZ2lXTk5kalU1RDFEamM4d3p6UHRsWE1oWUI3ek9KdUJVNUIxU2pKeVZmL0dEUnZvOEhjUEJTZTJhRDQ1UVZqbDRQVkZtSjRldU5NSlhNSHhZUT09PC9TaWduYXR1cmVWYWx1ZT48L1NpZ25hdHVyZT48L3NhbWxwOlJlc3BvbnNlPg== diff --git a/test/saml2.coffee b/test/saml2.coffee index 444bc41..a9e73ad 100644 --- a/test/saml2.coffee +++ b/test/saml2.coffee @@ -278,6 +278,37 @@ describe 'saml2', -> assert.deepEqual response, expected_response done() + it 'allows the signature to be embedded outside of the assertion', (done) -> + sp_options = + entity_id: 'https://sp.example.com/metadata.xml' + private_key: get_test_file('test.pem') + certificate: get_test_file('test.crt') + assert_endpoint: 'https://sp.example.com/assert' + idp_options = + sso_login_url: 'https://idp.example.com/login' + sso_logout_url: 'https://idp.example.com/logout' + certificates: [ get_test_file('test.crt') ] + request_options = + allow_unencrypted_assertion: true + request_body: + SAMLResponse: get_test_file("post_response_outer_signature.xml") + + sp = new saml2.ServiceProvider sp_options + idp = new saml2.IdentityProvider idp_options + + sp.post_assert idp, request_options, (err, response) -> + assert not err?, "Got error: #{err}" + expected_response = + response_header: {} + type: 'authn_response' + user: + name_id: 'Benjamin', + session_index: 'b07b804c-7c29-ea16-7300-4f3d6f7928ac' + attributes: {} + + assert.deepEqual response, expected_response + done() + it 'errors if passed invalid data', (done) -> sp_options = entity_id: 'https://sp.example.com/metadata.xml' @@ -412,7 +443,7 @@ describe 'saml2', -> sso_login_url: 'https://idp.example.com/login' sso_logout_url: 'https://idp.example.com/logout' certificates: 'other_service_cert' - request_options = + request_options = assert_endpoint: 'https://sp.example.com/assert' relay_state: 'Some Relay State!' nameid_format: "urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress" @@ -438,7 +469,7 @@ describe 'saml2', -> sso_login_url: 'https://idp.example.com/login' sso_logout_url: 'https://idp.example.com/logout' certificates: 'other_service_cert' - request_options = + request_options = assert_endpoint: 'https://sp.example.com/assert' relay_state: 'Some Relay State!' @@ -492,7 +523,7 @@ describe 'saml2', -> name_id: 'name_id' session_index: 'session_index' sign_get_request: true - + sp = new saml2.ServiceProvider sp_options idp = new saml2.IdentityProvider idp_options