omniauth 1.1.4 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of omniauth might be problematic. Click here for more details.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/.gemtest +0 -0
- data/.gitignore +11 -0
- data/.rspec +2 -0
- data/.rubocop.yml +82 -0
- data/.travis.yml +42 -0
- data/Gemfile +37 -0
- data/Gemfile.rack-1.3.x +24 -0
- data/Guardfile +10 -0
- data/README.md +4 -4
- data/Rakefile +12 -1
- data/certs/sferik.pem +20 -0
- data/lib/omniauth.rb +51 -33
- data/lib/omniauth/auth_hash.rb +9 -6
- data/lib/omniauth/builder.rb +12 -2
- data/lib/omniauth/failure_endpoint.rb +5 -5
- data/lib/omniauth/form.css +81 -0
- data/lib/omniauth/form.rb +11 -95
- data/lib/omniauth/strategies/developer.rb +3 -5
- data/lib/omniauth/strategy.rb +61 -47
- data/lib/omniauth/test.rb +0 -4
- data/lib/omniauth/test/phony_session.rb +4 -1
- data/lib/omniauth/test/strategy_macros.rb +1 -6
- data/lib/omniauth/test/strategy_test_case.rb +9 -14
- data/lib/omniauth/version.rb +1 -1
- data/omniauth.gemspec +5 -7
- data/spec/helper.rb +15 -6
- data/spec/omniauth/auth_hash_spec.rb +42 -39
- data/spec/omniauth/builder_spec.rb +13 -13
- data/spec/omniauth/failure_endpoint_spec.rb +22 -17
- data/spec/omniauth/form_spec.rb +8 -8
- data/spec/omniauth/strategies/developer_spec.rb +29 -25
- data/spec/omniauth/strategy_spec.rb +300 -219
- data/spec/omniauth_spec.rb +65 -31
- metadata +30 -20
- metadata.gz.sig +0 -0
data/spec/omniauth/form_spec.rb
CHANGED
@@ -1,22 +1,22 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
3
|
describe OmniAuth::Form do
|
4
|
-
describe
|
5
|
-
it
|
6
|
-
OmniAuth::Form.build{|f| expect(f).to be_kind_of(OmniAuth::Form)}
|
4
|
+
describe '.build' do
|
5
|
+
it 'yields the instance when called with a block and argument' do
|
6
|
+
OmniAuth::Form.build { |f| expect(f).to be_kind_of(OmniAuth::Form) }
|
7
7
|
end
|
8
8
|
|
9
|
-
it
|
10
|
-
OmniAuth::Form.build{|f| expect(f.class).to eq(OmniAuth::Form)}
|
9
|
+
it 'evaluates in the instance when called with a block and no argument' do
|
10
|
+
OmniAuth::Form.build { |f| expect(f.class).to eq(OmniAuth::Form) }
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
describe
|
15
|
-
it
|
14
|
+
describe '#initialize' do
|
15
|
+
it 'sets the form action to the passed :url option' do
|
16
16
|
expect(OmniAuth::Form.new(:url => '/awesome').to_html).to be_include("action='/awesome'")
|
17
17
|
end
|
18
18
|
|
19
|
-
it
|
19
|
+
it 'sets an H1 tag from the passed :title option' do
|
20
20
|
expect(OmniAuth::Form.new(:title => 'Something Cool').to_html).to be_include('<h1>Something Cool</h1>')
|
21
21
|
end
|
22
22
|
end
|
@@ -1,67 +1,71 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
3
|
describe OmniAuth::Strategies::Developer do
|
4
|
-
let(:app)
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
let(:app) do
|
5
|
+
Rack::Builder.new do |b|
|
6
|
+
b.use Rack::Session::Cookie, :secret => 'abc123'
|
7
|
+
b.use OmniAuth::Strategies::Developer
|
8
|
+
b.run lambda { |env| [200, {}, ['Not Found']] }
|
9
|
+
end.to_app
|
10
|
+
end
|
9
11
|
|
10
|
-
context
|
11
|
-
before(:each){ get '/auth/developer' }
|
12
|
+
context 'request phase' do
|
13
|
+
before(:each) { get '/auth/developer' }
|
12
14
|
|
13
|
-
it
|
15
|
+
it 'displays a form' do
|
14
16
|
expect(last_response.status).to eq(200)
|
15
|
-
expect(last_response.body).to be_include(
|
17
|
+
expect(last_response.body).to be_include('<form')
|
16
18
|
end
|
17
19
|
|
18
|
-
it
|
20
|
+
it 'has the callback as the action for the form' do
|
19
21
|
expect(last_response.body).to be_include("action='/auth/developer/callback'")
|
20
22
|
end
|
21
23
|
|
22
|
-
it
|
24
|
+
it 'has a text field for each of the fields' do
|
23
25
|
expect(last_response.body.scan('<input').size).to eq(2)
|
24
26
|
end
|
25
27
|
end
|
26
28
|
|
27
|
-
context
|
28
|
-
let(:auth_hash){ last_request.env['omniauth.auth'] }
|
29
|
+
context 'callback phase' do
|
30
|
+
let(:auth_hash) { last_request.env['omniauth.auth'] }
|
29
31
|
|
30
|
-
context
|
32
|
+
context 'with default options' do
|
31
33
|
before do
|
32
34
|
post '/auth/developer/callback', :name => 'Example User', :email => 'user@example.com'
|
33
35
|
end
|
34
36
|
|
35
|
-
it
|
37
|
+
it 'sets the name in the auth hash' do
|
36
38
|
expect(auth_hash.info.name).to eq('Example User')
|
37
39
|
end
|
38
40
|
|
39
|
-
it
|
41
|
+
it 'sets the email in the auth hash' do
|
40
42
|
expect(auth_hash.info.email).to eq('user@example.com')
|
41
43
|
end
|
42
44
|
|
43
|
-
it
|
45
|
+
it 'sets the uid to the email' do
|
44
46
|
expect(auth_hash.uid).to eq('user@example.com')
|
45
47
|
end
|
46
48
|
end
|
47
49
|
|
48
|
-
context
|
49
|
-
let(:app)
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
50
|
+
context 'with custom options' do
|
51
|
+
let(:app) do
|
52
|
+
Rack::Builder.new do |b|
|
53
|
+
b.use Rack::Session::Cookie, :secret => 'abc123'
|
54
|
+
b.use OmniAuth::Strategies::Developer, :fields => [:first_name, :last_name], :uid_field => :last_name
|
55
|
+
b.run lambda { |env| [200, {}, ['Not Found']] }
|
56
|
+
end.to_app
|
57
|
+
end
|
54
58
|
|
55
59
|
before do
|
56
60
|
@options = {:uid_field => :last_name, :fields => [:first_name, :last_name]}
|
57
61
|
post '/auth/developer/callback', :first_name => 'Example', :last_name => 'User'
|
58
62
|
end
|
59
63
|
|
60
|
-
it
|
64
|
+
it 'sets info fields properly' do
|
61
65
|
expect(auth_hash.info.name).to eq('Example User')
|
62
66
|
end
|
63
67
|
|
64
|
-
it
|
68
|
+
it 'sets the uid properly' do
|
65
69
|
expect(auth_hash.uid).to eq('User')
|
66
70
|
end
|
67
71
|
end
|
@@ -10,11 +10,17 @@ def make_env(path = '/auth/test', props = {})
|
|
10
10
|
end
|
11
11
|
|
12
12
|
describe OmniAuth::Strategy do
|
13
|
-
let(:app)
|
14
|
-
|
13
|
+
let(:app) do
|
14
|
+
lambda { |env| [404, {}, ['Awesome']] }
|
15
|
+
end
|
16
|
+
|
17
|
+
let(:fresh_strategy) do
|
18
|
+
c = Class.new
|
19
|
+
c.send(:include, OmniAuth::Strategy)
|
20
|
+
end
|
15
21
|
|
16
|
-
describe
|
17
|
-
it
|
22
|
+
describe '.default_options' do
|
23
|
+
it 'is inherited from a parent class' do
|
18
24
|
superklass = Class.new
|
19
25
|
superklass.send :include, OmniAuth::Strategy
|
20
26
|
superklass.configure do |c|
|
@@ -26,14 +32,18 @@ describe OmniAuth::Strategy do
|
|
26
32
|
end
|
27
33
|
end
|
28
34
|
|
29
|
-
describe
|
30
|
-
subject
|
31
|
-
|
32
|
-
|
35
|
+
describe '.configure' do
|
36
|
+
subject do
|
37
|
+
c = Class.new
|
38
|
+
c.send(:include, OmniAuth::Strategy)
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'when block is passed' do
|
42
|
+
it 'allows for default options setting' do
|
33
43
|
subject.configure do |c|
|
34
44
|
c.wakka = 'doo'
|
35
45
|
end
|
36
|
-
expect(subject.default_options[
|
46
|
+
expect(subject.default_options['wakka']).to eq('doo')
|
37
47
|
end
|
38
48
|
|
39
49
|
it "works when block doesn't evaluate to true" do
|
@@ -42,70 +52,88 @@ describe OmniAuth::Strategy do
|
|
42
52
|
c.abc = '123'
|
43
53
|
c.hgi = environment_variable
|
44
54
|
end
|
45
|
-
expect(subject.default_options[
|
55
|
+
expect(subject.default_options['abc']).to eq('123')
|
46
56
|
end
|
47
57
|
end
|
48
58
|
|
49
|
-
it
|
59
|
+
it 'takes a hash and deep merge it' do
|
50
60
|
subject.configure :abc => {:def => 123}
|
51
61
|
subject.configure :abc => {:hgi => 456}
|
52
|
-
expect(subject.default_options['abc']).to eq(
|
62
|
+
expect(subject.default_options['abc']).to eq('def' => 123, 'hgi' => 456)
|
53
63
|
end
|
54
64
|
end
|
55
65
|
|
56
|
-
describe
|
57
|
-
it
|
66
|
+
describe '#skip_info?' do
|
67
|
+
it 'is true if options.skip_info is true' do
|
58
68
|
expect(ExampleStrategy.new(app, :skip_info => true)).to be_skip_info
|
59
69
|
end
|
60
70
|
|
61
|
-
it
|
71
|
+
it 'is false if options.skip_info is false' do
|
62
72
|
expect(ExampleStrategy.new(app, :skip_info => false)).not_to be_skip_info
|
63
73
|
end
|
64
74
|
|
65
|
-
it
|
75
|
+
it 'is false by default' do
|
66
76
|
expect(ExampleStrategy.new(app)).not_to be_skip_info
|
67
77
|
end
|
68
78
|
|
69
|
-
it
|
70
|
-
instance = ExampleStrategy.new(app, :skip_info => lambda{|uid| uid})
|
71
|
-
instance.
|
79
|
+
it 'is true if options.skip_info is a callable that evaluates to truthy' do
|
80
|
+
instance = ExampleStrategy.new(app, :skip_info => lambda { |uid| uid })
|
81
|
+
expect(instance).to receive(:uid).and_return(true)
|
72
82
|
expect(instance).to be_skip_info
|
73
83
|
end
|
74
84
|
end
|
75
85
|
|
76
|
-
describe
|
77
|
-
subject
|
78
|
-
|
86
|
+
describe '.option' do
|
87
|
+
subject do
|
88
|
+
c = Class.new
|
89
|
+
c.send(:include, OmniAuth::Strategy)
|
90
|
+
end
|
91
|
+
it 'sets a default value' do
|
79
92
|
subject.option :abc, 123
|
80
93
|
expect(subject.default_options.abc).to eq(123)
|
81
94
|
end
|
82
95
|
|
83
|
-
it
|
96
|
+
it 'sets the default value to nil if none is provided' do
|
84
97
|
subject.option :abc
|
85
98
|
expect(subject.default_options.abc).to be_nil
|
86
99
|
end
|
87
100
|
end
|
88
101
|
|
89
|
-
describe
|
90
|
-
subject
|
91
|
-
|
102
|
+
describe '.args' do
|
103
|
+
subject do
|
104
|
+
c = Class.new
|
105
|
+
c.send(:include, OmniAuth::Strategy)
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'sets args to the specified argument if there is one' do
|
92
109
|
subject.args [:abc, :def]
|
93
110
|
expect(subject.args).to eq([:abc, :def])
|
94
111
|
end
|
95
112
|
|
96
|
-
it
|
113
|
+
it 'is inheritable' do
|
97
114
|
subject.args [:abc, :def]
|
98
115
|
c = Class.new(subject)
|
99
116
|
expect(c.args).to eq([:abc, :def])
|
100
117
|
end
|
118
|
+
|
119
|
+
it 'accepts corresponding options as default arg values' do
|
120
|
+
subject.args [:a, :b]
|
121
|
+
subject.option :a, '1'
|
122
|
+
subject.option :b, '2'
|
123
|
+
|
124
|
+
expect(subject.new(nil).options.a).to eq '1'
|
125
|
+
expect(subject.new(nil).options.b).to eq '2'
|
126
|
+
expect(subject.new(nil, '3', '4').options.b).to eq '4'
|
127
|
+
expect(subject.new(nil, nil, '4').options.a).to eq nil
|
128
|
+
end
|
101
129
|
end
|
102
130
|
|
103
|
-
context
|
104
|
-
subject{ fresh_strategy }
|
131
|
+
context 'fetcher procs' do
|
132
|
+
subject { fresh_strategy }
|
105
133
|
%w(uid info credentials extra).each do |fetcher|
|
106
134
|
describe ".#{fetcher}" do
|
107
|
-
it
|
108
|
-
proc = lambda{
|
135
|
+
it 'sets and retrieve a proc' do
|
136
|
+
proc = lambda { 'Hello' }
|
109
137
|
subject.send(fetcher, &proc)
|
110
138
|
expect(subject.send(fetcher)).to eq(proc)
|
111
139
|
end
|
@@ -113,14 +141,14 @@ describe OmniAuth::Strategy do
|
|
113
141
|
end
|
114
142
|
end
|
115
143
|
|
116
|
-
context
|
117
|
-
subject{ fresh_strategy }
|
144
|
+
context 'fetcher stacks' do
|
145
|
+
subject { fresh_strategy }
|
118
146
|
%w(uid info credentials extra).each do |fetcher|
|
119
147
|
describe ".#{fetcher}_stack" do
|
120
|
-
it
|
121
|
-
fetchy =
|
148
|
+
it 'is an array of called ancestral procs' do
|
149
|
+
fetchy = proc { 'Hello' }
|
122
150
|
subject.send(fetcher, &fetchy)
|
123
|
-
expect(subject.send("#{fetcher}_stack", subject.new(app))).to eq([
|
151
|
+
expect(subject.send("#{fetcher}_stack", subject.new(app))).to eq(['Hello'])
|
124
152
|
end
|
125
153
|
end
|
126
154
|
end
|
@@ -128,32 +156,32 @@ describe OmniAuth::Strategy do
|
|
128
156
|
|
129
157
|
%w(request_phase).each do |abstract_method|
|
130
158
|
context "#{abstract_method}" do
|
131
|
-
it
|
159
|
+
it 'raises a NotImplementedError' do
|
132
160
|
strat = Class.new
|
133
161
|
strat.send :include, OmniAuth::Strategy
|
134
|
-
expect{strat.new(app).send(abstract_method) }.to raise_error(NotImplementedError)
|
162
|
+
expect { strat.new(app).send(abstract_method) }.to raise_error(NotImplementedError)
|
135
163
|
end
|
136
164
|
end
|
137
165
|
end
|
138
166
|
|
139
|
-
describe
|
167
|
+
describe '#auth_hash' do
|
140
168
|
subject do
|
141
169
|
klass = Class.new
|
142
170
|
klass.send :include, OmniAuth::Strategy
|
143
171
|
klass.option :name, 'auth_hasher'
|
144
172
|
klass
|
145
173
|
end
|
146
|
-
let(:instance){ subject.new(app) }
|
174
|
+
let(:instance) { subject.new(app) }
|
147
175
|
|
148
|
-
it
|
149
|
-
instance.
|
150
|
-
instance.
|
176
|
+
it 'calls through to uid and info' do
|
177
|
+
expect(instance).to receive(:uid)
|
178
|
+
expect(instance).to receive(:info)
|
151
179
|
instance.auth_hash
|
152
180
|
end
|
153
181
|
|
154
|
-
it
|
155
|
-
instance.
|
156
|
-
instance.
|
182
|
+
it 'returns an AuthHash' do
|
183
|
+
allow(instance).to receive(:uid).and_return('123')
|
184
|
+
allow(instance).to receive(:info).and_return(:name => 'Hal Awesome')
|
157
185
|
hash = instance.auth_hash
|
158
186
|
expect(hash).to be_kind_of(OmniAuth::AuthHash)
|
159
187
|
expect(hash.uid).to eq('123')
|
@@ -161,21 +189,25 @@ describe OmniAuth::Strategy do
|
|
161
189
|
end
|
162
190
|
end
|
163
191
|
|
164
|
-
describe
|
165
|
-
context
|
166
|
-
it
|
192
|
+
describe '#initialize' do
|
193
|
+
context 'options extraction' do
|
194
|
+
it 'is the last argument if the last argument is a Hash' do
|
167
195
|
expect(ExampleStrategy.new(app, :abc => 123).options[:abc]).to eq(123)
|
168
196
|
end
|
169
197
|
|
170
|
-
it
|
171
|
-
ExampleStrategy.
|
198
|
+
it 'is the default options if any are provided' do
|
199
|
+
allow(ExampleStrategy).to receive(:default_options).and_return(OmniAuth::Strategy::Options.new(:abc => 123))
|
172
200
|
expect(ExampleStrategy.new(app).options.abc).to eq(123)
|
173
201
|
end
|
174
202
|
end
|
175
203
|
|
176
|
-
context
|
177
|
-
subject
|
178
|
-
|
204
|
+
context 'custom args' do
|
205
|
+
subject do
|
206
|
+
c = Class.new
|
207
|
+
c.send(:include, OmniAuth::Strategy)
|
208
|
+
end
|
209
|
+
|
210
|
+
it 'sets options based on the arguments if they are supplied' do
|
179
211
|
subject.args [:abc, :def]
|
180
212
|
s = subject.new app, 123, 456
|
181
213
|
expect(s.options[:abc]).to eq(123)
|
@@ -184,283 +216,300 @@ describe OmniAuth::Strategy do
|
|
184
216
|
end
|
185
217
|
end
|
186
218
|
|
187
|
-
describe
|
188
|
-
it
|
219
|
+
describe '#call' do
|
220
|
+
it 'duplicates and calls' do
|
189
221
|
klass = Class.new
|
190
222
|
klass.send :include, OmniAuth::Strategy
|
191
223
|
instance = klass.new(app)
|
192
|
-
instance.
|
193
|
-
instance.call(
|
224
|
+
expect(instance).to receive(:dup).and_return(instance)
|
225
|
+
instance.call('rack.session' => {})
|
194
226
|
end
|
195
227
|
end
|
196
228
|
|
197
|
-
describe
|
198
|
-
it
|
229
|
+
describe '#inspect' do
|
230
|
+
it 'returns the class name' do
|
199
231
|
expect(ExampleStrategy.new(app).inspect).to eq('#<ExampleStrategy>')
|
200
232
|
end
|
201
233
|
end
|
202
234
|
|
203
|
-
describe
|
204
|
-
it
|
205
|
-
response = ExampleStrategy.new(app, :iframe => true).redirect(
|
206
|
-
expect(response.last.body.first).to be_include(
|
235
|
+
describe '#redirect' do
|
236
|
+
it 'uses javascript if :iframe is true' do
|
237
|
+
response = ExampleStrategy.new(app, :iframe => true).redirect('http://abc.com')
|
238
|
+
expect(response.last.body.first).to be_include('top.location.href')
|
207
239
|
end
|
208
240
|
end
|
209
241
|
|
210
|
-
describe
|
211
|
-
subject
|
242
|
+
describe '#callback_phase' do
|
243
|
+
subject do
|
244
|
+
c = Class.new
|
245
|
+
c.send(:include, OmniAuth::Strategy)
|
246
|
+
c.new(app)
|
247
|
+
end
|
212
248
|
|
213
|
-
it
|
249
|
+
it 'sets the auth hash' do
|
214
250
|
env = make_env
|
215
|
-
subject.
|
216
|
-
subject.
|
251
|
+
allow(subject).to receive(:env).and_return(env)
|
252
|
+
allow(subject).to receive(:auth_hash).and_return('AUTH HASH')
|
217
253
|
subject.callback_phase
|
218
|
-
expect(env['omniauth.auth']).to eq(
|
254
|
+
expect(env['omniauth.auth']).to eq('AUTH HASH')
|
219
255
|
end
|
220
256
|
end
|
221
257
|
|
222
|
-
describe
|
223
|
-
let(:strategy){ ExampleStrategy.new(app, {}) }
|
224
|
-
it
|
258
|
+
describe '#full_host' do
|
259
|
+
let(:strategy) { ExampleStrategy.new(app, {}) }
|
260
|
+
it 'remains calm when there is a pipe in the URL' do
|
225
261
|
strategy.call!(make_env('/whatever', 'rack.url_scheme' => 'http', 'SERVER_NAME' => 'facebook.lame', 'QUERY_STRING' => 'code=asofibasf|asoidnasd', 'SCRIPT_NAME' => '', 'SERVER_PORT' => 80))
|
226
|
-
expect{strategy.full_host }.not_to raise_error
|
262
|
+
expect { strategy.full_host }.not_to raise_error
|
227
263
|
end
|
228
264
|
end
|
229
265
|
|
230
|
-
describe
|
231
|
-
subject{ fresh_strategy }
|
266
|
+
describe '#uid' do
|
267
|
+
subject { fresh_strategy }
|
232
268
|
it "is the current class's uid if one exists" do
|
233
|
-
subject.uid{
|
234
|
-
expect(subject.new(app).uid).to eq(
|
269
|
+
subject.uid { 'Hi' }
|
270
|
+
expect(subject.new(app).uid).to eq('Hi')
|
235
271
|
end
|
236
272
|
|
237
|
-
it
|
238
|
-
subject.uid{
|
273
|
+
it 'inherits if it can' do
|
274
|
+
subject.uid { 'Hi' }
|
239
275
|
c = Class.new(subject)
|
240
|
-
expect(c.new(app).uid).to eq(
|
276
|
+
expect(c.new(app).uid).to eq('Hi')
|
241
277
|
end
|
242
278
|
end
|
243
279
|
|
244
280
|
%w(info credentials extra).each do |fetcher|
|
245
|
-
subject{ fresh_strategy }
|
281
|
+
subject { fresh_strategy }
|
246
282
|
it "is the current class's proc call if one exists" do
|
247
|
-
subject.send(fetcher){ {:abc => 123} }
|
248
|
-
expect(subject.new(app).send(fetcher)).to eq(
|
283
|
+
subject.send(fetcher) { {:abc => 123} }
|
284
|
+
expect(subject.new(app).send(fetcher)).to eq(:abc => 123)
|
249
285
|
end
|
250
286
|
|
251
|
-
it
|
252
|
-
subject.send(fetcher){ {:abc => 123, :def => 456} }
|
287
|
+
it 'inherits by merging with preference for the latest class' do
|
288
|
+
subject.send(fetcher) { {:abc => 123, :def => 456} }
|
253
289
|
c = Class.new(subject)
|
254
|
-
c.send(fetcher){ {:abc => 789} }
|
255
|
-
expect(c.new(app).send(fetcher)).to eq(
|
290
|
+
c.send(fetcher) { {:abc => 789} }
|
291
|
+
expect(c.new(app).send(fetcher)).to eq(:abc => 789, :def => 456)
|
256
292
|
end
|
257
293
|
end
|
258
294
|
|
259
|
-
describe
|
295
|
+
describe '#call' do
|
260
296
|
before(:all) do
|
261
297
|
@options = nil
|
262
298
|
end
|
263
299
|
|
264
|
-
let(:strategy){ ExampleStrategy.new(app, @options || {}) }
|
300
|
+
let(:strategy) { ExampleStrategy.new(app, @options || {}) }
|
265
301
|
|
266
|
-
context
|
267
|
-
it
|
268
|
-
expect{strategy.call(make_env('/auth/test', 'HTTP_REFERER' => 'http://example.com/origin')) }.to raise_error(
|
302
|
+
context 'omniauth.origin' do
|
303
|
+
it 'is set on the request phase' do
|
304
|
+
expect { strategy.call(make_env('/auth/test', 'HTTP_REFERER' => 'http://example.com/origin')) }.to raise_error('Request Phase')
|
269
305
|
expect(strategy.last_env['rack.session']['omniauth.origin']).to eq('http://example.com/origin')
|
270
306
|
end
|
271
307
|
|
272
|
-
it
|
273
|
-
expect{strategy.call(make_env('/auth/test/callback', 'rack.session' => {'omniauth.origin' => 'http://example.com/origin'})) }.to raise_error(
|
308
|
+
it 'is turned into an env variable on the callback phase' do
|
309
|
+
expect { strategy.call(make_env('/auth/test/callback', 'rack.session' => {'omniauth.origin' => 'http://example.com/origin'})) }.to raise_error('Callback Phase')
|
274
310
|
expect(strategy.last_env['omniauth.origin']).to eq('http://example.com/origin')
|
275
311
|
end
|
276
312
|
|
277
|
-
it
|
278
|
-
expect{strategy.call(make_env('/auth/test', 'QUERY_STRING' => 'origin=/foo')) }.to raise_error('Request Phase')
|
313
|
+
it 'sets from the params if provided' do
|
314
|
+
expect { strategy.call(make_env('/auth/test', 'QUERY_STRING' => 'origin=/foo')) }.to raise_error('Request Phase')
|
279
315
|
expect(strategy.last_env['rack.session']['omniauth.origin']).to eq('/foo')
|
280
316
|
end
|
281
317
|
|
282
|
-
it
|
283
|
-
OmniAuth.config.
|
318
|
+
it 'is set on the failure env' do
|
319
|
+
expect(OmniAuth.config).to receive(:on_failure).and_return(lambda { |env| env })
|
284
320
|
@options = {:failure => :forced_fail}
|
285
321
|
strategy.call(make_env('/auth/test/callback', 'rack.session' => {'omniauth.origin' => '/awesome'}))
|
286
322
|
end
|
287
323
|
|
288
|
-
context
|
289
|
-
it
|
290
|
-
env = {'HTTP_REFERER' => 'http://example.com/sub_uri/origin', 'SCRIPT_NAME' => '/sub_uri'
|
291
|
-
expect{strategy.call(make_env('/auth/test', env)) }.to raise_error(
|
324
|
+
context 'with script_name' do
|
325
|
+
it 'is set on the request phase, containing full path' do
|
326
|
+
env = {'HTTP_REFERER' => 'http://example.com/sub_uri/origin', 'SCRIPT_NAME' => '/sub_uri'}
|
327
|
+
expect { strategy.call(make_env('/auth/test', env)) }.to raise_error('Request Phase')
|
292
328
|
expect(strategy.last_env['rack.session']['omniauth.origin']).to eq('http://example.com/sub_uri/origin')
|
293
329
|
end
|
294
330
|
|
295
|
-
it
|
331
|
+
it 'is turned into an env variable on the callback phase, containing full path' do
|
296
332
|
env = {
|
297
333
|
'rack.session' => {'omniauth.origin' => 'http://example.com/sub_uri/origin'},
|
298
334
|
'SCRIPT_NAME' => '/sub_uri'
|
299
335
|
}
|
300
336
|
|
301
|
-
expect{strategy.call(make_env('/auth/test/callback', env)) }.to raise_error(
|
337
|
+
expect { strategy.call(make_env('/auth/test/callback', env)) }.to raise_error('Callback Phase')
|
302
338
|
expect(strategy.last_env['omniauth.origin']).to eq('http://example.com/sub_uri/origin')
|
303
339
|
end
|
304
340
|
|
305
341
|
end
|
306
342
|
end
|
307
343
|
|
308
|
-
context
|
309
|
-
it
|
310
|
-
expect{strategy.call(make_env) }.to raise_error(
|
344
|
+
context 'default paths' do
|
345
|
+
it 'uses the default request path' do
|
346
|
+
expect { strategy.call(make_env) }.to raise_error('Request Phase')
|
311
347
|
end
|
312
348
|
|
313
|
-
it
|
314
|
-
expect{strategy.call(make_env('/AUTH/Test'))}.to raise_error(
|
349
|
+
it 'is case insensitive on request path' do
|
350
|
+
expect { strategy.call(make_env('/AUTH/Test')) }.to raise_error('Request Phase')
|
315
351
|
end
|
316
352
|
|
317
|
-
it
|
318
|
-
expect{strategy.call(make_env('/AUTH/TeSt/CaLlBAck'))}.to raise_error(
|
353
|
+
it 'is case insensitive on callback path' do
|
354
|
+
expect { strategy.call(make_env('/AUTH/TeSt/CaLlBAck')) }.to raise_error('Callback Phase')
|
319
355
|
end
|
320
356
|
|
321
|
-
it
|
322
|
-
expect{strategy.call(make_env('/auth/test/callback')) }.to raise_error(
|
357
|
+
it 'uses the default callback path' do
|
358
|
+
expect { strategy.call(make_env('/auth/test/callback')) }.to raise_error('Callback Phase')
|
323
359
|
end
|
324
360
|
|
325
|
-
it
|
326
|
-
expect{strategy.call(make_env('/auth/test/')) }.to raise_error(
|
361
|
+
it 'strips trailing spaces on request' do
|
362
|
+
expect { strategy.call(make_env('/auth/test/')) }.to raise_error('Request Phase')
|
327
363
|
end
|
328
364
|
|
329
|
-
it
|
330
|
-
expect{strategy.call(make_env('/auth/test/callback/')) }.to raise_error(
|
365
|
+
it 'strips trailing spaces on callback' do
|
366
|
+
expect { strategy.call(make_env('/auth/test/callback/')) }.to raise_error('Callback Phase')
|
331
367
|
end
|
332
368
|
|
333
|
-
context
|
334
|
-
it
|
335
|
-
strategy.
|
369
|
+
context 'callback_url' do
|
370
|
+
it 'uses the default callback_path' do
|
371
|
+
expect(strategy).to receive(:full_host).and_return('http://example.com')
|
336
372
|
|
337
|
-
expect{strategy.call(make_env) }.to raise_error(
|
373
|
+
expect { strategy.call(make_env) }.to raise_error('Request Phase')
|
338
374
|
|
339
375
|
expect(strategy.callback_url).to eq('http://example.com/auth/test/callback')
|
340
376
|
end
|
341
377
|
|
342
|
-
it
|
343
|
-
strategy.
|
378
|
+
it 'preserves the query parameters' do
|
379
|
+
allow(strategy).to receive(:full_host).and_return('http://example.com')
|
344
380
|
begin
|
345
381
|
strategy.call(make_env('/auth/test', 'QUERY_STRING' => 'id=5'))
|
346
|
-
rescue RuntimeError
|
382
|
+
rescue RuntimeError
|
383
|
+
end
|
347
384
|
expect(strategy.callback_url).to eq('http://example.com/auth/test/callback?id=5')
|
348
385
|
end
|
349
386
|
|
350
|
-
it
|
351
|
-
strategy.
|
387
|
+
it 'consider script name' do
|
388
|
+
allow(strategy).to receive(:full_host).and_return('http://example.com')
|
352
389
|
begin
|
353
390
|
strategy.call(make_env('/auth/test', 'SCRIPT_NAME' => '/sub_uri'))
|
354
|
-
rescue RuntimeError
|
391
|
+
rescue RuntimeError
|
392
|
+
end
|
355
393
|
expect(strategy.callback_url).to eq('http://example.com/sub_uri/auth/test/callback')
|
356
394
|
end
|
357
395
|
end
|
358
396
|
end
|
359
397
|
|
360
|
-
context
|
361
|
-
it
|
362
|
-
strategy.options.form = lambda{|env|
|
363
|
-
expect(strategy.call(make_env('/auth/test'))).to eq(
|
398
|
+
context ':form option' do
|
399
|
+
it 'calls through to the supplied form option if one exists' do
|
400
|
+
strategy.options.form = lambda { |env| 'Called me!' }
|
401
|
+
expect(strategy.call(make_env('/auth/test'))).to eq('Called me!')
|
364
402
|
end
|
365
403
|
|
366
|
-
it
|
404
|
+
it 'calls through to the app if :form => true is set as an option' do
|
367
405
|
strategy.options.form = true
|
368
406
|
expect(strategy.call(make_env('/auth/test'))).to eq(app.call(make_env('/auth/test')))
|
369
407
|
end
|
370
408
|
end
|
371
409
|
|
372
|
-
context
|
373
|
-
it
|
374
|
-
@options = {:request_path => lambda{|env| true}}
|
375
|
-
expect{strategy.call(make_env('/asoufibasfi')) }.to raise_error(
|
410
|
+
context 'dynamic paths' do
|
411
|
+
it 'runs the request phase if the custom request path evaluator is truthy' do
|
412
|
+
@options = {:request_path => lambda { |env| true }}
|
413
|
+
expect { strategy.call(make_env('/asoufibasfi')) }.to raise_error('Request Phase')
|
376
414
|
end
|
377
415
|
|
378
|
-
it
|
379
|
-
@options = {:callback_path => lambda{|env| true}}
|
380
|
-
expect{strategy.call(make_env('/asoufiasod')) }.to raise_error(
|
416
|
+
it 'runs the callback phase if the custom callback path evaluator is truthy' do
|
417
|
+
@options = {:callback_path => lambda { |env| true }}
|
418
|
+
expect { strategy.call(make_env('/asoufiasod')) }.to raise_error('Callback Phase')
|
381
419
|
end
|
382
420
|
|
383
|
-
it
|
384
|
-
strategy_instance = fresh_strategy.new(nil, :request_path => lambda{|env|
|
421
|
+
it 'provides a custom callback path if request_path evals to a string' do
|
422
|
+
strategy_instance = fresh_strategy.new(nil, :request_path => lambda { |env| '/auth/boo/callback/22' })
|
385
423
|
expect(strategy_instance.callback_path).to eq('/auth/boo/callback/22')
|
386
424
|
end
|
425
|
+
|
426
|
+
it 'correctly reports the callback path when the custom callback path evaluator is truthy' do
|
427
|
+
strategy_instance = ExampleStrategy.new(app,
|
428
|
+
:callback_path => lambda { |env| env['PATH_INFO'] == '/auth/bish/bosh/callback' }
|
429
|
+
)
|
430
|
+
|
431
|
+
expect { strategy_instance.call(make_env('/auth/bish/bosh/callback')) }.to raise_error('Callback Phase')
|
432
|
+
expect(strategy_instance.callback_path).to eq('/auth/bish/bosh/callback')
|
433
|
+
end
|
387
434
|
end
|
388
435
|
|
389
|
-
context
|
390
|
-
it
|
436
|
+
context 'custom paths' do
|
437
|
+
it 'uses a custom request_path if one is provided' do
|
391
438
|
@options = {:request_path => '/awesome'}
|
392
|
-
expect{strategy.call(make_env('/awesome')) }.to raise_error(
|
439
|
+
expect { strategy.call(make_env('/awesome')) }.to raise_error('Request Phase')
|
393
440
|
end
|
394
441
|
|
395
|
-
it
|
442
|
+
it 'uses a custom callback_path if one is provided' do
|
396
443
|
@options = {:callback_path => '/radical'}
|
397
|
-
expect{strategy.call(make_env('/radical')) }.to raise_error(
|
444
|
+
expect { strategy.call(make_env('/radical')) }.to raise_error('Callback Phase')
|
398
445
|
end
|
399
446
|
|
400
|
-
context
|
401
|
-
it
|
447
|
+
context 'callback_url' do
|
448
|
+
it 'uses a custom callback_path if one is provided' do
|
402
449
|
@options = {:callback_path => '/radical'}
|
403
|
-
strategy.
|
450
|
+
expect(strategy).to receive(:full_host).and_return('http://example.com')
|
404
451
|
|
405
|
-
expect{strategy.call(make_env('/radical')) }.to raise_error(
|
452
|
+
expect { strategy.call(make_env('/radical')) }.to raise_error('Callback Phase')
|
406
453
|
|
407
454
|
expect(strategy.callback_url).to eq('http://example.com/radical')
|
408
455
|
end
|
409
456
|
|
410
|
-
it
|
457
|
+
it 'preserves the query parameters' do
|
411
458
|
@options = {:callback_path => '/radical'}
|
412
|
-
strategy.
|
459
|
+
allow(strategy).to receive(:full_host).and_return('http://example.com')
|
413
460
|
begin
|
414
461
|
strategy.call(make_env('/auth/test', 'QUERY_STRING' => 'id=5'))
|
415
|
-
rescue RuntimeError
|
462
|
+
rescue RuntimeError
|
463
|
+
end
|
416
464
|
expect(strategy.callback_url).to eq('http://example.com/radical?id=5')
|
417
465
|
end
|
418
466
|
end
|
419
467
|
end
|
420
468
|
|
421
|
-
context
|
469
|
+
context 'custom prefix' do
|
422
470
|
before do
|
423
471
|
@options = {:path_prefix => '/wowzers'}
|
424
472
|
end
|
425
473
|
|
426
|
-
it
|
427
|
-
expect{strategy.call(make_env('/wowzers/test')) }.to raise_error(
|
474
|
+
it 'uses a custom prefix for request' do
|
475
|
+
expect { strategy.call(make_env('/wowzers/test')) }.to raise_error('Request Phase')
|
428
476
|
end
|
429
477
|
|
430
|
-
it
|
431
|
-
expect{strategy.call(make_env('/wowzers/test/callback')) }.to raise_error(
|
478
|
+
it 'uses a custom prefix for callback' do
|
479
|
+
expect { strategy.call(make_env('/wowzers/test/callback')) }.to raise_error('Callback Phase')
|
432
480
|
end
|
433
481
|
|
434
|
-
context
|
435
|
-
it
|
436
|
-
strategy.
|
482
|
+
context 'callback_url' do
|
483
|
+
it 'uses a custom prefix' do
|
484
|
+
expect(strategy).to receive(:full_host).and_return('http://example.com')
|
437
485
|
|
438
|
-
expect{strategy.call(make_env('/wowzers/test')) }.to raise_error(
|
486
|
+
expect { strategy.call(make_env('/wowzers/test')) }.to raise_error('Request Phase')
|
439
487
|
|
440
488
|
expect(strategy.callback_url).to eq('http://example.com/wowzers/test/callback')
|
441
489
|
end
|
442
490
|
|
443
|
-
it
|
444
|
-
strategy.
|
491
|
+
it 'preserves the query parameters' do
|
492
|
+
allow(strategy).to receive(:full_host).and_return('http://example.com')
|
445
493
|
begin
|
446
494
|
strategy.call(make_env('/auth/test', 'QUERY_STRING' => 'id=5'))
|
447
|
-
rescue RuntimeError
|
495
|
+
rescue RuntimeError
|
496
|
+
end
|
448
497
|
expect(strategy.callback_url).to eq('http://example.com/wowzers/test/callback?id=5')
|
449
498
|
end
|
450
499
|
end
|
451
500
|
end
|
452
501
|
|
453
|
-
context
|
502
|
+
context 'request method restriction' do
|
454
503
|
before do
|
455
504
|
OmniAuth.config.allowed_request_methods = [:post]
|
456
505
|
end
|
457
506
|
|
458
|
-
it
|
459
|
-
expect{strategy.call(make_env)}.not_to raise_error
|
507
|
+
it 'does not allow a request method of the wrong type' do
|
508
|
+
expect { strategy.call(make_env) }.not_to raise_error
|
460
509
|
end
|
461
510
|
|
462
|
-
it
|
463
|
-
expect{strategy.call(make_env('/auth/test', 'REQUEST_METHOD' => 'POST'))}.to raise_error(
|
511
|
+
it 'allows a request method of the correct type' do
|
512
|
+
expect { strategy.call(make_env('/auth/test', 'REQUEST_METHOD' => 'POST')) }.to raise_error('Request Phase')
|
464
513
|
end
|
465
514
|
|
466
515
|
after do
|
@@ -468,93 +517,98 @@ describe OmniAuth::Strategy do
|
|
468
517
|
end
|
469
518
|
end
|
470
519
|
|
471
|
-
context
|
472
|
-
shared_examples_for
|
473
|
-
it
|
520
|
+
context 'receiving an OPTIONS request' do
|
521
|
+
shared_examples_for 'an OPTIONS request' do
|
522
|
+
it 'responds with 200' do
|
474
523
|
expect(response[0]).to eq(200)
|
475
524
|
end
|
476
525
|
|
477
|
-
it
|
478
|
-
expect(response[1]['Allow']).to eq(
|
526
|
+
it 'sets the Allow header properly' do
|
527
|
+
expect(response[1]['Allow']).to eq('GET, POST')
|
479
528
|
end
|
480
529
|
end
|
481
530
|
|
482
|
-
context
|
531
|
+
context 'to the request path' do
|
483
532
|
let(:response) { strategy.call(make_env('/auth/test', 'REQUEST_METHOD' => 'OPTIONS')) }
|
484
|
-
it_behaves_like
|
533
|
+
it_behaves_like 'an OPTIONS request'
|
485
534
|
end
|
486
535
|
|
487
|
-
context
|
536
|
+
context 'to the request path' do
|
488
537
|
let(:response) { strategy.call(make_env('/auth/test/callback', 'REQUEST_METHOD' => 'OPTIONS')) }
|
489
|
-
it_behaves_like
|
538
|
+
it_behaves_like 'an OPTIONS request'
|
490
539
|
end
|
491
540
|
|
492
|
-
context
|
493
|
-
it
|
541
|
+
context 'to some other path' do
|
542
|
+
it 'does not short-circuit the request' do
|
494
543
|
env = make_env('/other', 'REQUEST_METHOD' => 'OPTIONS')
|
495
544
|
expect(strategy.call(env)).to eq(app.call(env))
|
496
545
|
end
|
497
546
|
end
|
498
547
|
end
|
499
548
|
|
500
|
-
context
|
549
|
+
context 'test mode' do
|
501
550
|
let(:app) do
|
502
551
|
# In test mode, the underlying app shouldn't be called on request phase.
|
503
|
-
lambda { |env| [404, {
|
552
|
+
lambda { |env| [404, {'Content-Type' => 'text/html'}, []] }
|
504
553
|
end
|
505
554
|
|
506
555
|
before do
|
507
556
|
OmniAuth.config.test_mode = true
|
508
557
|
end
|
509
558
|
|
510
|
-
it
|
559
|
+
it 'short circuits the request phase entirely' do
|
511
560
|
response = strategy.call(make_env)
|
512
561
|
expect(response[0]).to eq(302)
|
513
562
|
expect(response[1]['Location']).to eq('/auth/test/callback')
|
514
563
|
end
|
515
564
|
|
516
|
-
it
|
565
|
+
it 'is case insensitive on request path' do
|
517
566
|
expect(strategy.call(make_env('/AUTH/Test'))[0]).to eq(302)
|
518
567
|
end
|
519
568
|
|
520
|
-
it
|
569
|
+
it 'respects SCRIPT_NAME (a.k.a. BaseURI)' do
|
521
570
|
response = strategy.call(make_env('/auth/test', 'SCRIPT_NAME' => '/sub_uri'))
|
522
571
|
expect(response[1]['Location']).to eq('/sub_uri/auth/test/callback')
|
523
572
|
end
|
524
573
|
|
525
|
-
it
|
574
|
+
it 'redirects on failure' do
|
526
575
|
response = OmniAuth.config.on_failure.call(make_env('/auth/test', 'omniauth.error.type' => 'error'))
|
527
576
|
expect(response[0]).to eq(302)
|
528
577
|
expect(response[1]['Location']).to eq('/auth/failure?message=error')
|
529
578
|
end
|
530
579
|
|
531
|
-
it
|
580
|
+
it 'respects SCRIPT_NAME (a.k.a. BaseURI) on failure' do
|
532
581
|
response = OmniAuth.config.on_failure.call(make_env('/auth/test', 'SCRIPT_NAME' => '/sub_uri', 'omniauth.error.type' => 'error'))
|
533
582
|
expect(response[0]).to eq(302)
|
534
583
|
expect(response[1]['Location']).to eq('/sub_uri/auth/failure?message=error')
|
535
584
|
end
|
536
585
|
|
537
|
-
it
|
586
|
+
it 'is case insensitive on callback path' do
|
538
587
|
expect(strategy.call(make_env('/AUTH/TeSt/CaLlBAck')).first).to eq(strategy.call(make_env('/auth/test/callback')).first)
|
539
588
|
end
|
540
589
|
|
541
|
-
it
|
590
|
+
it 'maintains host and port' do
|
591
|
+
response = strategy.call(make_env('/auth/test', 'rack.url_scheme' => 'http', 'HTTP_HOST' => 'example.org', 'SERVER_PORT' => 3000))
|
592
|
+
expect(response[1]['Location']).to eq('http://example.org:3000/auth/test/callback')
|
593
|
+
end
|
594
|
+
|
595
|
+
it 'maintains query string parameters' do
|
542
596
|
response = strategy.call(make_env('/auth/test', 'QUERY_STRING' => 'cheese=stilton'))
|
543
597
|
expect(response[1]['Location']).to eq('/auth/test/callback?cheese=stilton')
|
544
598
|
end
|
545
599
|
|
546
|
-
it
|
600
|
+
it 'does not short circuit requests outside of authentication' do
|
547
601
|
expect(strategy.call(make_env('/'))).to eq(app.call(make_env('/')))
|
548
602
|
end
|
549
603
|
|
550
|
-
it
|
604
|
+
it 'responds with the default hash if none is set' do
|
551
605
|
OmniAuth.config.mock_auth[:test] = nil
|
552
606
|
|
553
607
|
strategy.call make_env('/auth/test/callback')
|
554
608
|
expect(strategy.env['omniauth.auth']['uid']).to eq('1234')
|
555
609
|
end
|
556
610
|
|
557
|
-
it
|
611
|
+
it 'responds with a provider-specific hash if one is set' do
|
558
612
|
OmniAuth.config.mock_auth[:test] = {
|
559
613
|
'uid' => 'abc'
|
560
614
|
}
|
@@ -563,42 +617,60 @@ describe OmniAuth::Strategy do
|
|
563
617
|
expect(strategy.env['omniauth.auth']['uid']).to eq('abc')
|
564
618
|
end
|
565
619
|
|
566
|
-
it
|
620
|
+
it 'simulates login failure if mocked data is set as a symbol' do
|
567
621
|
OmniAuth.config.mock_auth[:test] = :invalid_credentials
|
568
622
|
|
569
623
|
strategy.call make_env('/auth/test/callback')
|
570
624
|
expect(strategy.env['omniauth.error.type']).to eq(:invalid_credentials)
|
571
625
|
end
|
572
626
|
|
573
|
-
it
|
627
|
+
it 'sets omniauth.origin on the request phase' do
|
574
628
|
strategy.call(make_env('/auth/test', 'HTTP_REFERER' => 'http://example.com/origin'))
|
575
629
|
expect(strategy.env['rack.session']['omniauth.origin']).to eq('http://example.com/origin')
|
576
630
|
end
|
577
631
|
|
578
|
-
it
|
632
|
+
it 'sets omniauth.origin from the params if provided' do
|
579
633
|
strategy.call(make_env('/auth/test', 'QUERY_STRING' => 'origin=/foo'))
|
580
634
|
expect(strategy.env['rack.session']['omniauth.origin']).to eq('/foo')
|
581
635
|
end
|
582
636
|
|
583
|
-
it
|
637
|
+
it 'turns omniauth.origin into an env variable on the callback phase' do
|
584
638
|
OmniAuth.config.mock_auth[:test] = {}
|
585
639
|
|
586
640
|
strategy.call(make_env('/auth/test/callback', 'rack.session' => {'omniauth.origin' => 'http://example.com/origin'}))
|
587
641
|
expect(strategy.env['omniauth.origin']).to eq('http://example.com/origin')
|
588
642
|
end
|
589
643
|
|
590
|
-
it
|
644
|
+
it 'executes callback hook on the callback phase' do
|
645
|
+
OmniAuth.config.mock_auth[:test] = {}
|
646
|
+
OmniAuth.config.before_callback_phase do |env|
|
647
|
+
env['foobar'] = 'baz'
|
648
|
+
end
|
649
|
+
strategy.call(make_env('/auth/test/callback', 'rack.session' => {'omniauth.origin' => 'http://example.com/origin'}))
|
650
|
+
expect(strategy.env['foobar']).to eq('baz')
|
651
|
+
end
|
652
|
+
|
653
|
+
it 'sets omniauth.params on the request phase' do
|
591
654
|
OmniAuth.config.mock_auth[:test] = {}
|
592
655
|
|
593
656
|
strategy.call(make_env('/auth/test', 'QUERY_STRING' => 'foo=bar'))
|
594
|
-
expect(strategy.env['rack.session']['omniauth.params']).to eq(
|
657
|
+
expect(strategy.env['rack.session']['omniauth.params']).to eq('foo' => 'bar')
|
595
658
|
end
|
596
659
|
|
597
|
-
it
|
660
|
+
it 'executes request hook on the request phase' do
|
661
|
+
OmniAuth.config.mock_auth[:test] = {}
|
662
|
+
OmniAuth.config.before_request_phase do |env|
|
663
|
+
env['foobar'] = 'baz'
|
664
|
+
end
|
665
|
+
strategy.call(make_env('/auth/test', 'QUERY_STRING' => 'foo=bar'))
|
666
|
+
expect(strategy.env['foobar']).to eq('baz')
|
667
|
+
end
|
668
|
+
|
669
|
+
it 'turns omniauth.params into an env variable on the callback phase' do
|
598
670
|
OmniAuth.config.mock_auth[:test] = {}
|
599
671
|
|
600
672
|
strategy.call(make_env('/auth/test/callback', 'rack.session' => {'omniauth.params' => {'foo' => 'bar'}}))
|
601
|
-
expect(strategy.env['omniauth.params']).to eq(
|
673
|
+
expect(strategy.env['omniauth.params']).to eq('foo' => 'bar')
|
602
674
|
end
|
603
675
|
|
604
676
|
after do
|
@@ -606,18 +678,18 @@ describe OmniAuth::Strategy do
|
|
606
678
|
end
|
607
679
|
end
|
608
680
|
|
609
|
-
context
|
681
|
+
context 'custom full_host' do
|
610
682
|
before do
|
611
683
|
OmniAuth.config.test_mode = true
|
612
684
|
end
|
613
685
|
|
614
|
-
it
|
686
|
+
it 'is the string when a string is there' do
|
615
687
|
OmniAuth.config.full_host = 'my.host.com'
|
616
688
|
expect(strategy.full_host).to eq('my.host.com')
|
617
689
|
end
|
618
690
|
|
619
|
-
it
|
620
|
-
OmniAuth.config.full_host =
|
691
|
+
it 'runs the proc with the env when it is a proc' do
|
692
|
+
OmniAuth.config.full_host = proc { |env| env['HOST'] }
|
621
693
|
strategy.call(make_env('/auth/test', 'HOST' => 'my.host.net'))
|
622
694
|
expect(strategy.full_host).to eq('my.host.net')
|
623
695
|
end
|
@@ -628,53 +700,62 @@ describe OmniAuth::Strategy do
|
|
628
700
|
expect(strategy.full_host).to eq('http://my.host.net')
|
629
701
|
end
|
630
702
|
|
631
|
-
it
|
703
|
+
it 'honors HTTP_X_FORWARDED_PROTO if present' do
|
632
704
|
OmniAuth.config.full_host = nil
|
633
|
-
strategy.call(make_env('/whatever', 'HTTP_X_FORWARDED_PROTO' => 'https','rack.url_scheme' => 'http', 'SERVER_NAME' => 'my.host.net', 'SERVER_PORT' => 443))
|
705
|
+
strategy.call(make_env('/whatever', 'HTTP_X_FORWARDED_PROTO' => 'https', 'rack.url_scheme' => 'http', 'SERVER_NAME' => 'my.host.net', 'SERVER_PORT' => 443))
|
634
706
|
expect(strategy.full_host).to eq('https://my.host.net')
|
635
707
|
end
|
636
708
|
|
637
709
|
after do
|
710
|
+
OmniAuth.config.full_host = nil
|
638
711
|
OmniAuth.config.test_mode = false
|
639
712
|
end
|
640
713
|
end
|
641
714
|
end
|
642
715
|
|
643
|
-
context
|
716
|
+
context 'setup phase' do
|
644
717
|
before do
|
645
718
|
OmniAuth.config.test_mode = true
|
646
719
|
end
|
647
720
|
|
648
|
-
context
|
649
|
-
let(:strategy)
|
650
|
-
|
721
|
+
context 'when options[:setup] = true' do
|
722
|
+
let(:strategy) do
|
723
|
+
ExampleStrategy.new(app, :setup => true)
|
724
|
+
end
|
725
|
+
|
726
|
+
let(:app) do
|
727
|
+
lambda do |env|
|
728
|
+
env['omniauth.strategy'].options[:awesome] = 'sauce' if env['PATH_INFO'] == '/auth/test/setup'
|
729
|
+
[404, {}, 'Awesome']
|
730
|
+
end
|
731
|
+
end
|
651
732
|
|
652
|
-
it
|
733
|
+
it 'calls through to /auth/:provider/setup' do
|
653
734
|
strategy.call(make_env('/auth/test'))
|
654
735
|
expect(strategy.options[:awesome]).to eq('sauce')
|
655
736
|
end
|
656
737
|
|
657
|
-
it
|
738
|
+
it 'does not call through on a non-omniauth endpoint' do
|
658
739
|
strategy.call(make_env('/somewhere/else'))
|
659
740
|
expect(strategy.options[:awesome]).not_to eq('sauce')
|
660
741
|
end
|
661
742
|
end
|
662
743
|
|
663
|
-
context
|
744
|
+
context 'when options[:setup] is an app' do
|
664
745
|
let(:setup_proc) do
|
665
|
-
|
746
|
+
proc do |env|
|
666
747
|
env['omniauth.strategy'].options[:awesome] = 'sauce'
|
667
748
|
end
|
668
749
|
end
|
669
750
|
|
670
|
-
let(:strategy){ ExampleStrategy.new(app, :setup => setup_proc) }
|
751
|
+
let(:strategy) { ExampleStrategy.new(app, :setup => setup_proc) }
|
671
752
|
|
672
|
-
it
|
753
|
+
it 'does not call the app on a non-omniauth endpoint' do
|
673
754
|
strategy.call(make_env('/somehwere/else'))
|
674
755
|
expect(strategy.options[:awesome]).not_to eq('sauce')
|
675
756
|
end
|
676
757
|
|
677
|
-
it
|
758
|
+
it 'calls the rack app' do
|
678
759
|
strategy.call(make_env('/auth/test'))
|
679
760
|
expect(strategy.options[:awesome]).to eq('sauce')
|
680
761
|
end
|