@@ -83,12 +83,13 @@ class SloLogoutresponseTest < Minitest::Test
8383 assert_match /Destination='http:\/ \/ unauth.com\/ logout\/ return'/ , inflated
8484 end
8585
86- describe "when the settings indicate to sign (embedded) logout response " do
86+ describe "signing with HTTP-POST binding " do
8787
8888 before do
89+ settings . idp_sso_service_binding = :redirect
90+ settings . idp_slo_service_binding = :post
8991 settings . compress_response = false
9092 settings . security [ :logout_responses_signed ] = true
91- settings . security [ :embed_sign ] = true
9293 end
9394
9495 it "doesn't sign through create_xml_document" do
@@ -161,14 +162,14 @@ class SloLogoutresponseTest < Minitest::Test
161162 end
162163 end
163164
164- describe "#create_params when the settings indicate to sign the logout response" do
165-
165+ describe "signing with HTTP-Redirect binding" do
166166 let ( :cert ) { OpenSSL ::X509 ::Certificate . new ( ruby_saml_cert_text ) }
167167
168168 before do
169+ settings . idp_sso_service_binding = :post
170+ settings . idp_slo_service_binding = :redirect
169171 settings . compress_response = false
170172 settings . security [ :logout_responses_signed ] = true
171- settings . security [ :embed_sign ] = false
172173 end
173174
174175 it "create a signature parameter with RSA_SHA1 and validate it" do
@@ -245,7 +246,68 @@ class SloLogoutresponseTest < Minitest::Test
245246 assert_equal signature_algorithm , OpenSSL ::Digest ::SHA512
246247 assert cert . public_key . verify ( signature_algorithm . new , Base64 . decode64 ( params [ 'Signature' ] ) , query_string )
247248 end
249+ end
250+
251+ describe "DEPRECATED: signing with HTTP-POST binding via :embed_sign" do
252+
253+ before do
254+ settings . compress_response = false
255+ settings . security [ :logout_responses_signed ] = true
256+ settings . security [ :embed_sign ] = true
257+ end
258+
259+ it "doesn't sign through create_xml_document" do
260+ unauth_res = OneLogin ::RubySaml ::SloLogoutresponse . new
261+ inflated = unauth_res . create_xml_document ( settings ) . to_s
262+
263+ refute_match %r[<ds:SignatureValue>([a-zA-Z0-9/+=]+)</ds:SignatureValue>] , inflated
264+ refute_match %r[<ds:SignatureMethod Algorithm='http://www.w3.org/2000/09/xmldsig#rsa-sha1'/>] , inflated
265+ refute_match %r[<ds:DigestMethod Algorithm='http://www.w3.org/2000/09/xmldsig#sha1'/>] , inflated
266+ end
267+
268+ it "sign unsigned request" do
269+ unauth_res = OneLogin ::RubySaml ::SloLogoutresponse . new
270+ unauth_res_doc = unauth_res . create_xml_document ( settings )
271+ inflated = unauth_res_doc . to_s
272+
273+ refute_match %r[<ds:SignatureValue>([a-zA-Z0-9/+=]+)</ds:SignatureValue>] , inflated
274+ refute_match %r[<ds:SignatureMethod Algorithm='http://www.w3.org/2000/09/xmldsig#rsa-sha1'/>] , inflated
275+ refute_match %r[<ds:DigestMethod Algorithm='http://www.w3.org/2000/09/xmldsig#sha1'/>] , inflated
276+
277+ inflated = unauth_res . sign_document ( unauth_res_doc , settings ) . to_s
278+
279+ assert_match %r[<ds:SignatureValue>([a-zA-Z0-9/+=]+)</ds:SignatureValue>] , inflated
280+ assert_match %r[<ds:SignatureMethod Algorithm='http://www.w3.org/2000/09/xmldsig#rsa-sha1'/>] , inflated
281+ assert_match %r[<ds:DigestMethod Algorithm='http://www.w3.org/2000/09/xmldsig#sha1'/>] , inflated
282+ end
283+ end
284+
285+ describe "DEPRECATED: signing with HTTP-Redirect binding via :embed_sign" do
286+ let ( :cert ) { OpenSSL ::X509 ::Certificate . new ( ruby_saml_cert_text ) }
287+
288+ before do
289+ settings . compress_response = false
290+ settings . security [ :logout_responses_signed ] = true
291+ settings . security [ :embed_sign ] = false
292+ end
248293
294+ it "create a signature parameter with RSA_SHA1 and validate it" do
295+ settings . security [ :signature_method ] = XMLSecurity ::Document ::RSA_SHA1
296+
297+ params = OneLogin ::RubySaml ::SloLogoutresponse . new . create_params ( settings , logout_request . id , "Custom Logout Message" , :RelayState => 'http://example.com' )
298+ assert params [ 'SAMLResponse' ]
299+ assert params [ :RelayState ]
300+ assert params [ 'Signature' ]
301+ assert_equal params [ 'SigAlg' ] , XMLSecurity ::Document ::RSA_SHA1
302+
303+ query_string = "SAMLResponse=#{ CGI . escape ( params [ 'SAMLResponse' ] ) } "
304+ query_string << "&RelayState=#{ CGI . escape ( params [ :RelayState ] ) } "
305+ query_string << "&SigAlg=#{ CGI . escape ( params [ 'SigAlg' ] ) } "
306+
307+ signature_algorithm = XMLSecurity ::BaseDocument . new . algorithm ( params [ 'SigAlg' ] )
308+ assert_equal signature_algorithm , OpenSSL ::Digest ::SHA1
309+ assert cert . public_key . verify ( signature_algorithm . new , Base64 . decode64 ( params [ 'Signature' ] ) , query_string )
310+ end
249311 end
250312 end
251313end
0 commit comments