@@ -287,46 +287,47 @@ def post_xml(xml = :example_response, opts = {})
287287 expect ( last_response ) . to be_redirect
288288 expect ( last_response . location ) . to match /https:\/ \/ example.com\/ /
289289 end
290- end
291-
292- context "when response relay state is invalid" do
293- before do
294- saml_options [ :slo_default_relay_state ] = "/signed-out"
295- end
296290
297- [
298- "//attacker.test" ,
299- "javascript:alert(1)" ,
300- ] . each do |unsafe_relay_state |
301- it "falls back to the default when the relay state is #{ unsafe_relay_state } " do
302- post "/auth/saml/slo" , {
291+ context "when response relay state is invalid" do
292+ let ( :saml_options ) { super ( ) . merge ( slo_default_relay_state : '/signed-out' ) }
293+ let ( :params ) do
294+ {
303295 SAMLResponse : load_xml ( :example_logout_response ) ,
304- RelayState : unsafe_relay_state ,
305- } , "rack.session" => { "saml_transaction_id" => "_3fef1069-d0c6-418a-b68d-6f008a4787e9" }
296+ RelayState : "https://example.com/" ,
297+ }
298+ end
306299
307- expect ( last_response ) . to be_redirect
308- expect ( last_response . location ) . to eq ( "/signed-out" )
300+ let ( :opts ) do
301+ { "rack.session" => { "saml_transaction_id" => "_3fef1069-d0c6-418a-b68d-6f008a4787e9" } }
309302 end
310- end
311303
312- it "allows absolute https relay states" do
313- post "/auth/saml/slo" , {
314- SAMLResponse : load_xml ( :example_logout_response ) ,
315- RelayState : "https://example.com/logout" ,
316- } , "rack.session" => { "saml_transaction_id" => "_3fef1069-d0c6-418a-b68d-6f008a4787e9" }
304+ subject ( :post_slo_response ) { post "/auth/saml/slo" , params , opts }
317305
318- expect ( last_response . location ) . to eq ( "https://example.com/logout" )
319- end
306+ [
307+ "//attacker.test" ,
308+ "javascript:alert(1)" ,
309+ ] . each do |unsafe_relay_state |
310+ context "#{ unsafe_relay_state } " do
311+ let ( :params ) { super ( ) . merge ( RelayState : unsafe_relay_state ) }
320312
321- it "raises when there is no safe fallback" do
322- saml_options . delete ( :slo_default_relay_state )
313+ it 'falls back to the default' do
314+ is_expected . to be_redirect . and have_attributes ( location : "/signed-out" )
315+ end
316+ end
317+ end
323318
324- expect do
325- post "/auth/saml/slo" , {
326- SAMLResponse : load_xml ( :example_logout_response ) ,
327- RelayState : "javascript:alert(1)" ,
328- } , "rack.session" => { "saml_transaction_id" => "_3fef1069-d0c6-418a-b68d-6f008a4787e9" }
329- end . to raise_error ( OmniAuth ::Strategies ::SAML ::ValidationError , "Invalid RelayState" )
319+ context 'when absolute https relay state' do
320+ let ( :params ) { super ( ) . merge ( RelayState : "https://example.com/logout" ) }
321+
322+ it { is_expected . to be_redirect . and have_attributes ( location : "https://example.com/logout" ) }
323+ end
324+
325+ context 'when there is no safe fallback' do
326+ let ( :saml_options ) { super ( ) . except ( :slo_default_relay_state ) }
327+ let ( :params ) { super ( ) . merge ( RelayState : 'javascript:alert(1)' ) }
328+
329+ it { expect { post_slo_response } . to raise_error ( OmniAuth ::Strategies ::SAML ::ValidationError , "Invalid RelayState" ) }
330+ end
330331 end
331332 end
332333
0 commit comments