44 def app ; lambda { |env | [ 200 , { } , [ "Hello." ] ] } end
55 let ( :fresh_strategy ) { Class . new ( OmniAuth ::Strategies ::OAuth2 ) }
66
7+ before do
8+ OmniAuth . config . test_mode = true
9+ end
10+
11+ after do
12+ OmniAuth . config . test_mode = false
13+ end
14+
715 describe '#client' do
816 subject { fresh_strategy }
917
@@ -22,13 +30,20 @@ def app; lambda{|env| [200, {}, ["Hello."]]} end
2230 subject { fresh_strategy }
2331
2432 it 'should include any authorize params passed in the :authorize_params option' do
25- instance = subject . new ( 'abc' , 'def' , :authorize_params => { :foo => 'bar' , :baz => 'zip' } )
26- instance . authorize_params . should == { 'foo' => 'bar' , 'baz' => 'zip' }
33+ instance = subject . new ( 'abc' , 'def' , :authorize_params => { :foo => 'bar' , :baz => 'zip' , :state => '123' } )
34+ instance . authorize_params . should == { 'foo' => 'bar' , 'baz' => 'zip' , 'state' => '123' }
2735 end
2836
2937 it 'should include top-level options that are marked as :authorize_options' do
30- instance = subject . new ( 'abc' , 'def' , :authorize_options => [ :scope , :foo ] , :scope => 'bar' , :foo => 'baz' )
31- instance . authorize_params . should == { 'scope' => 'bar' , 'foo' => 'baz' }
38+ instance = subject . new ( 'abc' , 'def' , :authorize_options => [ :scope , :foo ] , :scope => 'bar' , :foo => 'baz' , :authorize_params => { :state => '123' } )
39+ instance . authorize_params . should == { 'scope' => 'bar' , 'foo' => 'baz' , 'state' => '123' }
40+ end
41+
42+ it 'should include random state in the authorize params' do
43+ instance = subject . new ( 'abc' , 'def' )
44+ instance . authorize_params . keys . should == [ 'state' ]
45+ instance . session [ 'omniauth.state' ] . should_not be_empty
46+ instance . session [ 'omniauth.state' ] . should == instance . authorize_params [ 'state' ]
3247 end
3348 end
3449
0 commit comments