diff --git a/spec/omniauth/strategies/remote_user_spec.rb b/spec/omniauth/strategies/remote_user_spec.rb index cf42525..41bccf5 100644 --- a/spec/omniauth/strategies/remote_user_spec.rb +++ b/spec/omniauth/strategies/remote_user_spec.rb @@ -9,7 +9,7 @@ describe 'Test Strategy Remote_User' do end.to_app end - context 'Without REMOTE_USER and not logged in' do + context 'Without HTTP_REMOTE_USER and not logged in' do before(:each){ get '/', {}, {} } @@ -17,76 +17,69 @@ describe 'Test Strategy Remote_User' do it 'Do nothing' do expect(last_response.status).to eq(200) expect(last_request.cookies['_remote_user']).to eq(nil) - expect(last_request.cookies['_gitlab_session']).to eq(nil) end end - context 'Without REMOTE_USER and logged in' do + context 'Without HTTP_REMOTE_USER and logged in' do before(:each){ clear_cookies - set_cookie "_gitlab_session=test" set_cookie "_remote_user=test" get '/', {}, {} } it 'Logout curreent user' do - cookie_session_str = "_gitlab_session=; max-age=0; expires=Thu, 01 Jan 1970 00:00:00 -0000" << - "\n_remote_user=; max-age=0; expires=Thu, 01 Jan 1970 00:00:00 -0000" - expect(last_request.cookies['_gitlab_session']).to eq('test') expect(last_request.cookies['_remote_user']).to eq('test') expect(last_response.status).to eq(302) - expect(last_response['Set-Cookie']).to eq(cookie_session_str) + expect(last_response['Set-Cookie']).to include("_remote_user=") + expect(last_response['Set-Cookie']).to include("path=") end end - context 'With REMOTE_USER and not logged in' do + context 'With HTTP_REMOTE_USER and not logged in' do before(:each){ get '/', {}, { 'HTTP_REMOTE_USER' => 'foobar' } } - it 'logs REMOTE_USER in' do + it 'logs HTTP_REMOTE_USER in' do expect(last_response.status).to eq(302) - expect(last_response['Set-Cookie']).to eq('_remote_user=foobar') + expect(last_response['Set-Cookie']).to include('_remote_user=foobar') + expect(last_response['Set-Cookie']).to include('path=') end end - context 'With REMOTE_USER, logged in and current user equals REMOTE_USER' do + context 'With HTTP_REMOTE_USER, logged in and current user equals HTTP_REMOTE_USER' do before(:each){ clear_cookies - set_cookie "_gitlab_session=foobar" set_cookie "_remote_user=foobar" get '/', {}, { 'HTTP_REMOTE_USER' => 'foobar' } } it 'Do nothing' do - expect(last_request.cookies['_gitlab_session']).to eq('foobar') expect(last_request.cookies['_remote_user']).to eq('foobar') expect(last_response.status).to eq(200) expect(last_response['Set-Cookie']).to eq(nil) end end - context 'With REMOTE_USER, logged in and current user not equals REMOTE_USER' do + context 'With HTTP_REMOTE_USER, logged in and current user not equals HTTP_REMOTE_USER' do before(:each){ clear_cookies - set_cookie "_gitlab_session=foobar" set_cookie "_remote_user=foobar" get '/', {}, { 'HTTP_REMOTE_USER' => 'foobar2' } } - it 'Logout current user and login REMOTE_USER and no have _gitlab_session' do - expect(last_request.cookies['_gitlab_session']).to eq('foobar') + it 'Logout current user and login HTTP_REMOTE_USER' do expect(last_request.cookies['_remote_user']).to eq('foobar') expect(last_response.status).to eq(302) - expect(last_response['Set-Cookie']).to include('_gitlab_session=') end end - context 'Verify omniauth hash with REMOTE_USER_DATA' do + context 'Verify omniauth hash with HTTP_REMOTE_USER_DATA' do before(:each){ clear_cookies + set_cookie "_remote_user=foobar" post '/auth/RemoteUser/callback', {}, { 'HTTP_REMOTE_USER' => 'foobar', - 'HTTP_REMOTE_USER_DATA' => JSON.dump({'name' => 'foobar', 'email' => 'foobar@test.com'})} + 'HTTP_REMOTE_USER_DATA' => JSON.dump({'name' => 'foobar barfoo', 'email' => 'foobar@test.com'})} } it 'Verify uid' do @@ -96,12 +89,15 @@ describe 'Test Strategy Remote_User' do it 'Verify info' do expect(last_request.env['omniauth.auth']['info']['nickname']).to eq('foobar') expect(last_request.env['omniauth.auth']['info']['email']).to eq('foobar@test.com') + expect(last_request.env['omniauth.auth']['info']['lastname']).to eq('barfoo') + expect(last_request.env['omniauth.auth']['info']['firstname']).to eq('foobar') end end - context 'Verify omniauth.auth info without REMOTE_USER_DATA' do + context 'Verify omniauth.auth info without HTTP_REMOTE_USER_DATA' do before(:each){ clear_cookies + set_cookie "_remote_user=foobar" post '/auth/RemoteUser/callback', {}, { 'HTTP_REMOTE_USER' => 'foobar' } } @@ -113,4 +109,17 @@ describe 'Test Strategy Remote_User' do expect(last_request.env['omniauth.auth']['info']).to eq({}) end end + + context 'With HTTP_REMOTE_USER and ' do + before(:each){ + set_cookie "_remote_user=foobar" + get "auth/RemoteUser", {}, { 'HTTP_REMOTE_USER' => 'foobar' } + } + + it 'redirect for callback' do + expect(last_response.status).to eq(302) + expect(last_response.location).to eq("/auth/RemoteUser/callback") + end + end + end -- libgit2 0.21.2