Commit 616c476146bcfee353110a7ddc62eaa370978376
1 parent
b66c6ef7
Exists in
master
and in
2 other branches
Initial test structure
Showing
2 changed files
with
29 additions
and
17 deletions
Show diff stats
spec/omniauth/strategies/remote_user_spec.rb
@@ -4,30 +4,41 @@ describe 'Test Strategy Remote_User' do | @@ -4,30 +4,41 @@ describe 'Test Strategy Remote_User' do | ||
4 | let(:app) do | 4 | let(:app) do |
5 | Rack::Builder.new do |b| | 5 | Rack::Builder.new do |b| |
6 | b.use Rack::Session::Cookie, :secret => 'abc123' | 6 | b.use Rack::Session::Cookie, :secret => 'abc123' |
7 | - b.use OmniAuth::Strategies::RemoteUser, :fields => [:name, :email], :uid_field => :name | ||
8 | - b.run lambda { |_env| [200, {'HTTP_REMOTE_USER' => 'myuser'}, ['My body']] } | 7 | + b.use OmniAuth::Strategies::RemoteUser |
8 | + b.run lambda { |_env| [200, {}, ['My body']] } | ||
9 | end.to_app | 9 | end.to_app |
10 | end | 10 | end |
11 | 11 | ||
12 | - context 'Response phase' do | ||
13 | - before(:each) { get '/auth/remote_user',{},{'HTTP_COOKIE' => '_gitlab_session=user@myuser','HTTP_REMOTE_USER' => "user@myuser" }} | ||
14 | - it 'check my rack response' do | ||
15 | - expect(last_response.body).to eq('My body') | ||
16 | - expect(last_response.status).to eq(200) | ||
17 | - expect(last_response.original_headers).to eq({'HTTP_REMOTE_USER' => 'myuser' }) | ||
18 | - expect(last_response.errors).to eq('') | 12 | + context 'Without REMOTE_USER and not logged in' do |
13 | + before(:each){get '/', {}, {}} | ||
14 | + | ||
15 | + it 'Do nothing' do | ||
16 | + last_response.status.should == 200 | ||
17 | + last_response.cookies['_remote_user'] == nil | ||
19 | end | 18 | end |
19 | + end | ||
20 | + | ||
21 | + context 'Without REMOTE_USER and logged in' do | ||
22 | + #Logout current user | ||
23 | + | ||
24 | + | ||
25 | + end | ||
20 | 26 | ||
21 | - context 'Request phase' do | ||
22 | - before(:each) { get '/auth/remote_user',{},{'HTTP_COOKIE' => '_gitlab_session=user@myuser','HTTP_REMOTE_USER' => "user@myuser" }} | ||
23 | - it 'check my env request' do | ||
24 | - expect(last_request.env['HTTP_COOKIE']).to eq("_gitlab_session=user@myuser") | ||
25 | - expect(last_request.env['HTTP_REMOTE_USER']).to eq("user@myuser") | ||
26 | - expect(last_request.request_method).to eq("GET") | ||
27 | - expect(last_request.path_info).to eq("/auth/remote_user") | ||
28 | - end | 27 | + context 'With REMOTE_USER and not logged in' do |
28 | + #Login REMOTE_USER | ||
29 | + it 'logs user in' do | ||
30 | + get '/', {}, { 'HTTP_REMOTE_USER' => 'foobar' } | ||
29 | end | 31 | end |
30 | end | 32 | end |
31 | 33 | ||
34 | + context 'With REMOTE_USER, logged in and current user equals REMOTE_USER' do | ||
35 | + #do nothing | ||
32 | 36 | ||
37 | + end | ||
38 | + | ||
39 | + context 'With REMOTE_USER, logged in and current user not equals REMOTE_USER' do | ||
40 | + #Logout current user and login REMOTE_USER | ||
41 | + | ||
42 | + end | ||
33 | end | 43 | end |
44 | + |
spec/spec_helper.rb
@@ -22,4 +22,5 @@ require 'omniauth/remote_user' | @@ -22,4 +22,5 @@ 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 |
25 | + config.extend OmniAuth::Test::StrategyMacros, :type => :strategy | ||
25 | end | 26 | end |