require 'spec_helper' describe OmniAuth::Strategies::CAS::LogoutRequest do let(:strategy) { double('strategy') } let(:env) do { 'rack.input' => StringIO.new('','r') } end let(:request) { double('request', params:params, env:env) } let(:params) { { 'url' => url, 'logoutRequest' => logoutRequest } } let(:url) { 'http://notes.dev/signed_in' } let(:logoutRequest) do %Q[ @NOT_USED@ ST-123456-123abc456def ] end subject { described_class.new(strategy, request).call(options) } describe 'with no configured SSO callback' do let(:options) { {} } it 'responds with OK' do expect(subject[0]).to eq 200 expect(subject[2].body).to eq ['OK'] end end describe 'SAML attributes' do let(:callback) { Proc.new{} } let(:options) do { on_single_sign_out: callback } end before do @rack_input = nil callback.stub(:call) do |req| @rack_input = req.env['rack.input'].read true end subject end it 'are parsed and injected into the Rack Request parameters' do expect(@rack_input).to eq 'name_id=%40NOT_USED%40&session_index=ST-123456-123abc456def' end context 'that raise when parsed' do let(:env) { { 'rack.input' => nil } } before do strategy.stub :fail! subject end it 'responds with an error' do expect(strategy).to have_received(:fail!) end end end describe 'with a configured callback' do let(:options) do { on_single_sign_out: callback } end context 'that returns TRUE' do let(:callback) { Proc.new{true} } it 'responds with OK' do expect(subject[0]).to eq 200 expect(subject[2].body).to eq ['OK'] end end context 'that returns Nil' do let(:callback) { Proc.new{} } it 'responds with OK' do expect(subject[0]).to eq 200 expect(subject[2].body).to eq ['OK'] end end context 'that returns a tuple' do let(:callback) { Proc.new{ [400,{},'Bad Request'] } } it 'responds with OK' do expect(subject[0]).to eq 400 expect(subject[2].body).to eq ['Bad Request'] end end context 'that raises an error' do let(:exception) { RuntimeError.new('error' )} let(:callback) { Proc.new{raise exception} } before do strategy.stub :fail! subject end it 'responds with an error' do expect(strategy).to have_received(:fail!) .with(:logout_request, exception) end end end end