Commit 312626c34b901ae2c6b7427e1f2b97e0992bc36d

Authored by Lucas Kanashiro
1 parent a245a038

Finished suite test

Showing 1 changed file with 44 additions and 1 deletions   Show diff stats
spec/omniauth/strategies/remote_user_spec.rb
... ... @@ -68,8 +68,51 @@ describe 'Test Strategy Remote_User' do
68 68 end
69 69  
70 70 context 'With REMOTE_USER, logged in and current user not equals REMOTE_USER' do
71   - #Logout current user and login REMOTE_USER
  71 + before(:each){
  72 + clear_cookies
  73 + set_cookie "_gitlab_session=foobar"
  74 + set_cookie "_remote_user=foobar"
  75 + get '/', {}, { 'HTTP_REMOTE_USER' => 'foobar2' }
  76 + }
72 77  
  78 + it 'Logout current user and login REMOTE_USER' do
  79 + expect(last_request.cookies['_gitlab_session']).to eq('foobar')
  80 + expect(last_request.cookies['_remote_user']).to eq('foobar')
  81 + expect(last_response.status).to eq(302)
  82 + expect(last_response['Set-Cookie']).to eq('_remote_user=foobar2')
  83 + end
  84 + end
  85 +
  86 + context 'Verify omniauth hash with REMOTE_USER_DATA' do
  87 + before(:each){
  88 + clear_cookies
  89 + post '/auth/remoteuser/callback', {}, { 'HTTP_REMOTE_USER' => 'foobar',
  90 + 'HTTP_REMOTE_USER_DATA' => JSON.dump({'name' => 'foobar', 'email' => 'foobar@test.com'})}
  91 + }
  92 +
  93 + it 'Verify uid' do
  94 + expect(last_request.env['omniauth.auth']['uid']).to eq('foobar')
  95 + end
  96 +
  97 + it 'Verify info' do
  98 + expect(last_request.env['omniauth.auth']['info']['nickname']).to eq('foobar')
  99 + expect(last_request.env['omniauth.auth']['info']['email']).to eq('foobar@test.com')
  100 + end
  101 + end
  102 +
  103 + context 'Verify omniauth.auth info without REMOTE_USER_DATA' do
  104 + before(:each){
  105 + clear_cookies
  106 + post '/auth/remoteuser/callback', {}, { 'HTTP_REMOTE_USER' => 'foobar' }
  107 + }
  108 +
  109 + it 'Verify uid' do
  110 + expect(last_request.env['omniauth.auth']['uid']).to eq('foobar')
  111 + end
  112 +
  113 + it 'Verify info' do
  114 + expect(last_request.env['omniauth.auth']['info']).to eq({})
  115 + end
73 116 end
74 117 end
75 118  
... ...