Skip to content

Commit d837597

Browse files
Move test strcuture
1 parent 5d06805 commit d837597

File tree

1 file changed

+30
-32
lines changed

1 file changed

+30
-32
lines changed

spec/omniauth/strategies/saml_spec.rb

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -289,51 +289,49 @@ def post_xml(xml = :example_response, opts = {})
289289
expect(last_response.location).to match /https:\/\/example.com\//
290290
end
291291

292-
end
293-
294-
context "when response relay state is invalid" do
295-
let(:saml_options) { super().merge(slo_default_relay_state: '/signed-out') }
296-
let(:params) do
297-
{
298-
SAMLResponse: load_xml(:example_logout_response),
299-
RelayState: "https://example.com/",
300-
}
301-
end
292+
context "when response relay state is invalid" do
293+
let(:saml_options) { super().merge(slo_default_relay_state: '/signed-out') }
294+
let(:params) do
295+
{
296+
SAMLResponse: load_xml(:example_logout_response),
297+
RelayState: "https://example.com/",
298+
}
299+
end
302300

303-
let(:opts) do
304-
{ "rack.session" => { "saml_transaction_id" => "_3fef1069-d0c6-418a-b68d-6f008a4787e9" } }
305-
end
301+
let(:opts) do
302+
{ "rack.session" => { "saml_transaction_id" => "_3fef1069-d0c6-418a-b68d-6f008a4787e9" } }
303+
end
306304

307-
subject { post "/auth/saml/slo", params, opts }
305+
subject(:post_slo_response) { post "/auth/saml/slo", params, opts }
308306

309-
[
310-
"//attacker.test",
311-
"javascript:alert(1)",
312-
].each do |unsafe_relay_state|
313-
context "#{unsafe_relay_state}" do
314-
let(:params) { super().merge(RelayState: unsafe_relay_state)}
307+
[
308+
"//attacker.test",
309+
"javascript:alert(1)",
310+
].each do |unsafe_relay_state|
311+
context "#{unsafe_relay_state}" do
312+
let(:params) { super().merge(RelayState: unsafe_relay_state)}
315313

316-
it 'falls back to the default' do
317-
is_expected.to be_redirect.and have_attributes(location: "/signed-out")
314+
it 'falls back to the default' do
315+
is_expected.to be_redirect.and have_attributes(location: "/signed-out")
316+
end
318317
end
319318
end
320-
end
321319

322-
context 'when absolute https relay state' do
323-
let(:params) { super().merge(RelayState: "https://example.com/logout")}
320+
context 'when absolute https relay state' do
321+
let(:params) { super().merge(RelayState: "https://example.com/logout")}
324322

325-
it { is_expected.to be_redirect.and have_attributes(location: "https://example.com/logout") }
326-
end
323+
it { is_expected.to be_redirect.and have_attributes(location: "https://example.com/logout") }
324+
end
327325

328-
context 'when there is no safe fallback' do
329-
let(:saml_options) { super().except(:slo_default_relay_state) }
330-
let(:params) { super().merge(RelayState: 'javascript:alert(1)')}
326+
context 'when there is no safe fallback' do
327+
let(:saml_options) { super().except(:slo_default_relay_state) }
328+
let(:params) { super().merge(RelayState: 'javascript:alert(1)')}
331329

332-
it { expect { subject }.to raise_error(OmniAuth::Strategies::SAML::ValidationError, "Invalid RelayState") }
330+
it { expect { post_slo_response }.to raise_error(OmniAuth::Strategies::SAML::ValidationError, "Invalid RelayState") }
331+
end
333332
end
334333
end
335334

336-
337335
context "when request is a logout request" do
338336
subject { post "/auth/saml/slo", params, "rack.session" => { "saml_uid" => "[email protected]" } }
339337

0 commit comments

Comments
 (0)