Commit a157fa3fb3c10ca784073c087ea28b3235fb29b7
1 parent
a59e035b
Exists in
master
and in
2 other branches
Fixed test for logout instead login
Showing
2 changed files
with
14 additions
and
16 deletions
Show diff stats
spec/omniauth/strategies/remote_user_spec.rb
@@ -23,12 +23,12 @@ describe 'Test Strategy Remote_User' do | @@ -23,12 +23,12 @@ describe 'Test Strategy Remote_User' do | ||
23 | 23 | ||
24 | context 'Without REMOTE_USER and logged in' do | 24 | context 'Without REMOTE_USER and logged in' do |
25 | before(:each){ | 25 | before(:each){ |
26 | - clear_cookies | 26 | + clear_cookies |
27 | set_cookie "_gitlab_session=test" | 27 | set_cookie "_gitlab_session=test" |
28 | set_cookie "_remote_user=test" | 28 | set_cookie "_remote_user=test" |
29 | get '/', {}, {} | 29 | get '/', {}, {} |
30 | } | 30 | } |
31 | - | 31 | + |
32 | it 'Logout curreent user' do | 32 | it 'Logout curreent user' do |
33 | cookie_session_str = "_gitlab_session=; max-age=0; expires=Thu, 01 Jan 1970 00:00:00 -0000" << | 33 | cookie_session_str = "_gitlab_session=; max-age=0; expires=Thu, 01 Jan 1970 00:00:00 -0000" << |
34 | "\n_remote_user=; max-age=0; expires=Thu, 01 Jan 1970 00:00:00 -0000" | 34 | "\n_remote_user=; max-age=0; expires=Thu, 01 Jan 1970 00:00:00 -0000" |
@@ -45,49 +45,48 @@ describe 'Test Strategy Remote_User' do | @@ -45,49 +45,48 @@ describe 'Test Strategy Remote_User' do | ||
45 | } | 45 | } |
46 | 46 | ||
47 | it 'logs REMOTE_USER in' do | 47 | it 'logs REMOTE_USER in' do |
48 | - expect(last_response.status).to eq(302) | 48 | + expect(last_response.status).to eq(302) |
49 | expect(last_response['Set-Cookie']).to eq('_remote_user=foobar') | 49 | expect(last_response['Set-Cookie']).to eq('_remote_user=foobar') |
50 | end | 50 | end |
51 | end | 51 | end |
52 | 52 | ||
53 | context 'With REMOTE_USER, logged in and current user equals REMOTE_USER' do | 53 | context 'With REMOTE_USER, logged in and current user equals REMOTE_USER' do |
54 | before(:each){ | 54 | before(:each){ |
55 | - clear_cookies | 55 | + clear_cookies |
56 | set_cookie "_gitlab_session=foobar" | 56 | set_cookie "_gitlab_session=foobar" |
57 | set_cookie "_remote_user=foobar" | 57 | set_cookie "_remote_user=foobar" |
58 | get '/', {}, { 'HTTP_REMOTE_USER' => 'foobar' } | 58 | get '/', {}, { 'HTTP_REMOTE_USER' => 'foobar' } |
59 | } | 59 | } |
60 | 60 | ||
61 | it 'Do nothing' do | 61 | it 'Do nothing' do |
62 | - cookie_session_str = "_gitlab_session=foobar\n_remote_user=foobar" | ||
63 | expect(last_request.cookies['_gitlab_session']).to eq('foobar') | 62 | expect(last_request.cookies['_gitlab_session']).to eq('foobar') |
64 | expect(last_request.cookies['_remote_user']).to eq('foobar') | 63 | expect(last_request.cookies['_remote_user']).to eq('foobar') |
65 | - expect(last_response.status).to eq(200) | ||
66 | - expect(last_response['Set-Cookie']).to eq(nil) | 64 | + expect(last_response.status).to eq(200) |
65 | + expect(last_response['Set-Cookie']).to eq(nil) | ||
67 | end | 66 | end |
68 | end | 67 | end |
69 | 68 | ||
70 | context 'With REMOTE_USER, logged in and current user not equals REMOTE_USER' do | 69 | context 'With REMOTE_USER, logged in and current user not equals REMOTE_USER' do |
71 | before(:each){ | 70 | before(:each){ |
72 | - clear_cookies | 71 | + clear_cookies |
73 | set_cookie "_gitlab_session=foobar" | 72 | set_cookie "_gitlab_session=foobar" |
74 | set_cookie "_remote_user=foobar" | 73 | set_cookie "_remote_user=foobar" |
75 | get '/', {}, { 'HTTP_REMOTE_USER' => 'foobar2' } | 74 | get '/', {}, { 'HTTP_REMOTE_USER' => 'foobar2' } |
76 | } | 75 | } |
77 | 76 | ||
78 | - it 'Logout current user and login REMOTE_USER' do | 77 | + it 'Logout current user and login REMOTE_USER and no have _gitlab_session' do |
79 | expect(last_request.cookies['_gitlab_session']).to eq('foobar') | 78 | expect(last_request.cookies['_gitlab_session']).to eq('foobar') |
80 | expect(last_request.cookies['_remote_user']).to eq('foobar') | 79 | 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') | 80 | + expect(last_response.status).to eq(302) |
81 | + expect(last_response['Set-Cookie']).to include('_gitlab_session=') | ||
83 | end | 82 | end |
84 | end | 83 | end |
85 | 84 | ||
86 | context 'Verify omniauth hash with REMOTE_USER_DATA' do | 85 | context 'Verify omniauth hash with REMOTE_USER_DATA' do |
87 | before(:each){ | 86 | before(:each){ |
88 | clear_cookies | 87 | clear_cookies |
89 | - post '/auth/remoteuser/callback', {}, { 'HTTP_REMOTE_USER' => 'foobar', | ||
90 | - 'HTTP_REMOTE_USER_DATA' => JSON.dump({'name' => 'foobar', 'email' => 'foobar@test.com'})} | 88 | + post '/auth/remoteuser/callback', {}, { 'HTTP_REMOTE_USER' => 'foobar', |
89 | + 'HTTP_REMOTE_USER_DATA' => JSON.dump({'name' => 'foobar', 'email' => 'foobar@test.com'})} | ||
91 | } | 90 | } |
92 | 91 | ||
93 | it 'Verify uid' do | 92 | it 'Verify uid' do |
@@ -103,7 +102,7 @@ describe 'Test Strategy Remote_User' do | @@ -103,7 +102,7 @@ describe 'Test Strategy Remote_User' do | ||
103 | context 'Verify omniauth.auth info without REMOTE_USER_DATA' do | 102 | context 'Verify omniauth.auth info without REMOTE_USER_DATA' do |
104 | before(:each){ | 103 | before(:each){ |
105 | clear_cookies | 104 | clear_cookies |
106 | - post '/auth/remoteuser/callback', {}, { 'HTTP_REMOTE_USER' => 'foobar' } | 105 | + post '/auth/remoteuser/callback', {}, { 'HTTP_REMOTE_USER' => 'foobar' } |
107 | } | 106 | } |
108 | 107 | ||
109 | it 'Verify uid' do | 108 | it 'Verify uid' do |
@@ -115,4 +114,3 @@ describe 'Test Strategy Remote_User' do | @@ -115,4 +114,3 @@ describe 'Test Strategy Remote_User' do | ||
115 | end | 114 | end |
116 | end | 115 | end |
117 | end | 116 | end |
118 | - |
spec/spec_helper.rb
@@ -18,7 +18,7 @@ require 'omniauth/test' | @@ -18,7 +18,7 @@ require 'omniauth/test' | ||
18 | Bundler.setup :default, :development, :test | 18 | Bundler.setup :default, :development, :test |
19 | 19 | ||
20 | require 'rack/test' | 20 | require 'rack/test' |
21 | -require 'omniauth/remote_user' | 21 | +require 'omniauth/remote-user' |
22 | 22 | ||
23 | RSpec.configure do |config| | 23 | RSpec.configure do |config| |
24 | config.include Rack::Test::Methods | 24 | config.include Rack::Test::Methods |