warden 1.2.5 → 1.2.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +5 -0
  3. data/.rspec +3 -0
  4. data/.travis.yml +7 -0
  5. data/{History.rdoc → CHANGELOG.md} +13 -3
  6. data/Gemfile +2 -1
  7. data/Gemfile.lock +40 -0
  8. data/LICENSE +1 -1
  9. data/README.md +18 -0
  10. data/Rakefile +4 -8
  11. data/lib/warden/config.rb +1 -0
  12. data/lib/warden/errors.rb +2 -1
  13. data/lib/warden/hooks.rb +1 -0
  14. data/lib/warden/manager.rb +2 -1
  15. data/lib/warden/mixins/common.rb +1 -0
  16. data/lib/warden/proxy.rb +15 -3
  17. data/lib/warden/session_serializer.rb +1 -0
  18. data/lib/warden/strategies/base.rb +2 -1
  19. data/lib/warden/strategies.rb +1 -0
  20. data/lib/warden/test/helpers.rb +2 -56
  21. data/lib/warden/test/mock.rb +69 -0
  22. data/lib/warden/test/warden_helpers.rb +1 -0
  23. data/lib/warden/version.rb +2 -1
  24. data/lib/warden.rb +2 -0
  25. data/warden.gemspec +21 -18
  26. metadata +19 -33
  27. data/README.textile +0 -9
  28. data/spec/helpers/request_helper.rb +0 -51
  29. data/spec/helpers/strategies/fail_with_user.rb +0 -10
  30. data/spec/helpers/strategies/failz.rb +0 -8
  31. data/spec/helpers/strategies/invalid.rb +0 -8
  32. data/spec/helpers/strategies/pass.rb +0 -8
  33. data/spec/helpers/strategies/pass_with_message.rb +0 -8
  34. data/spec/helpers/strategies/password.rb +0 -13
  35. data/spec/helpers/strategies/single.rb +0 -12
  36. data/spec/spec_helper.rb +0 -24
  37. data/spec/warden/authenticated_data_store_spec.rb +0 -114
  38. data/spec/warden/config_spec.rb +0 -48
  39. data/spec/warden/errors_spec.rb +0 -47
  40. data/spec/warden/hooks_spec.rb +0 -373
  41. data/spec/warden/manager_spec.rb +0 -340
  42. data/spec/warden/proxy_spec.rb +0 -1050
  43. data/spec/warden/scoped_session_serializer.rb +0 -123
  44. data/spec/warden/session_serializer_spec.rb +0 -53
  45. data/spec/warden/strategies/base_spec.rb +0 -313
  46. data/spec/warden/strategies_spec.rb +0 -94
  47. data/spec/warden/test/helpers_spec.rb +0 -101
  48. data/spec/warden/test/test_mode_spec.rb +0 -75
@@ -1,123 +0,0 @@
1
- # encoding: utf-8
2
- require 'spec_helper'
3
-
4
- describe Warden::Manager do
5
- before(:each) do
6
- @env = env_with_params
7
- @env['rack.session'] ||= {}
8
- Warden::Manager.serialize_from_session { |k| k }
9
- Warden::Manager.serialize_into_session { |u| u }
10
- begin
11
- Warden::SessionSerializer.send :remove_method, :admin_serialize
12
- rescue
13
- end
14
- begin
15
- Warden::SessionSerializer.send :remove_method, :admin_deserialize
16
- rescue
17
- end
18
- end
19
- after(:each) do
20
- Warden::Manager.serialize_from_session { |k| k }
21
- Warden::Manager.serialize_into_session { |u| u }
22
- begin
23
- Warden::SessionSerializer.send :remove_method, :admin_deserialize
24
- Warden::SessionSerializer.send :remove_method, :admin_serialize
25
- rescue
26
- end
27
- end
28
-
29
- def serializer_respond_to?(name)
30
- Warden::SessionSerializer.new(@env).respond_to? name
31
- end
32
-
33
- it "should respond to :serialize" do
34
- serializer_respond_to?(:serialize).should be_true
35
- end
36
-
37
- it "should respond to :deserialize" do
38
- serializer_respond_to?(:deserialize).should be_true
39
- end
40
-
41
- it "should respond to {scope}_deserialize if Manager.serialize_from_session is called with scope" do
42
- Rack::Builder.new do
43
- Warden::Manager.serialize_from_session ( :admin ) { |n| n }
44
- end
45
- serializer_respond_to?(:admin_deserialize).should be_true
46
- end
47
-
48
- it "should respond to {scope}_serialize if Manager.serialize_into_session is called with scope" do
49
- Rack::Builder.new do
50
- Warden::Manager.serialize_into_session(:admin) { |n| n }
51
- end
52
- serializer_respond_to?(:admin_serialize).should be_true
53
- end
54
-
55
- def initialize_with_scope(scope, &block)
56
- Rack::Builder.new do
57
- Warden::Manager.serialize_into_session(scope, &block)
58
- end
59
- end
60
-
61
- it "should execute serialize if no {scope}_serialize is present" do
62
- serialized_object = nil
63
- initialize_with_scope(nil) do |user|
64
- serialized_object = user
65
- user
66
- end
67
- serializer = Warden::SessionSerializer.new(@env)
68
- serializer.store("user", :admin)
69
- serialized_object.should eq("user")
70
- end
71
-
72
- it "should not have a {scope}_serialize by default" do
73
- serializer_respond_to?(:admin_serialize).should be_false
74
- end
75
-
76
- it "should execute {scope}_serialize when calling store with a scope" do
77
- serialized_object = nil
78
- initialize_with_scope(:admin) do |user|
79
- serialized_object = user
80
- user
81
- end
82
-
83
- serializer = Warden::SessionSerializer.new(@env)
84
- serializer.store("user", :admin)
85
- serialized_object.should eq("user")
86
- end
87
-
88
-
89
- it "should execute {scope}_deserialize when calling store with a scope" do
90
- serialized_object = nil
91
-
92
- Rack::Builder.new do
93
- Warden::Manager.serialize_from_session(:admin) do |key|
94
- serialized_object = key
95
- key
96
- end
97
- end
98
-
99
- serializer = Warden::SessionSerializer.new(@env)
100
- @env['rack.session'][serializer.key_for(:admin)] = "test"
101
- serializer.fetch(:admin)
102
-
103
- serialized_object.should eq("test")
104
- end
105
-
106
- it "should execute deserialize if {scope}_deserialize is not present" do
107
- serialized_object = nil
108
-
109
- Rack::Builder.new do
110
- Warden::Manager.serialize_from_session do |key|
111
- serialized_object = key
112
- key
113
- end
114
- end
115
-
116
- serializer = Warden::SessionSerializer.new(@env)
117
- @env['rack.session'][serializer.key_for(:admin)] = "test"
118
- serializer.fetch(:admin)
119
-
120
- serialized_object.should eq("test")
121
- end
122
-
123
- end
@@ -1,53 +0,0 @@
1
- # encoding: utf-8
2
- require 'spec_helper'
3
-
4
- describe Warden::SessionSerializer do
5
- before(:each) do
6
- @env = env_with_params
7
- @env['rack.session'] ||= {}
8
- @session = Warden::SessionSerializer.new(@env)
9
- end
10
-
11
- it "should store data for the default scope" do
12
- @session.store("user", :default)
13
- expect(@env['rack.session']).to eq({ "warden.user.default.key"=>"user" })
14
- end
15
-
16
- it "should check if a data is stored or not" do
17
- expect(@session).not_to be_stored(:default)
18
- @session.store("user", :default)
19
- expect(@session).to be_stored(:default)
20
- end
21
-
22
- it "should load an user from store" do
23
- expect(@session.fetch(:default)).to be_nil
24
- @session.store("user", :default)
25
- expect(@session.fetch(:default)).to eq("user")
26
- end
27
-
28
- it "should store data based on the scope" do
29
- @session.store("user", :default)
30
- expect(@session.fetch(:default)).to eq("user")
31
- expect(@session.fetch(:another)).to be_nil
32
- end
33
-
34
- it "should delete data from store" do
35
- @session.store("user", :default)
36
- expect(@session.fetch(:default)).to eq("user")
37
- @session.delete(:default)
38
- expect(@session.fetch(:default)).to be_nil
39
- end
40
-
41
- it "should delete information from store if user cannot be retrieved" do
42
- @session.store("user", :default)
43
- expect(@env['rack.session']).to have_key("warden.user.default.key")
44
- allow(@session).to receive(:deserialize).and_return(nil)
45
- @session.fetch(:default)
46
- expect(@env['rack.session']).not_to have_key("warden.user.default.key")
47
- end
48
-
49
- it "should support a nil session store" do
50
- @env['rack.session'] = nil
51
- expect(@session.fetch(:default)).to be_nil
52
- end
53
- end
@@ -1,313 +0,0 @@
1
- # encoding: utf-8
2
- require 'spec_helper'
3
-
4
- describe Warden::Strategies::Base do
5
-
6
- before(:each) do
7
- RAS = Warden::Strategies unless defined?(RAS)
8
- Warden::Strategies.clear!
9
- end
10
-
11
- describe "headers" do
12
- it "should have headers" do
13
- Warden::Strategies.add(:foo) do
14
- def authenticate!
15
- headers("foo" => "bar")
16
- end
17
- end
18
- strategy = Warden::Strategies[:foo].new(env_with_params)
19
- strategy._run!
20
- expect(strategy.headers["foo"]).to eq("bar")
21
- end
22
-
23
- it "should allow us to clear the headers" do
24
- Warden::Strategies.add(:foo) do
25
- def authenticate!
26
- headers("foo" => "bar")
27
- end
28
- end
29
- strategy = Warden::Strategies[:foo].new(env_with_params)
30
- strategy._run!
31
- expect(strategy.headers["foo"]).to eq("bar")
32
- strategy.headers.clear
33
- expect(strategy.headers).to be_empty
34
- end
35
- end
36
-
37
- it "should have a user object" do
38
- RAS.add(:foobar) do
39
- def authenticate!
40
- success!("foo")
41
- end
42
- end
43
- strategy = RAS[:foobar].new(env_with_params)
44
- strategy._run!
45
- expect(strategy.user).to eq("foo")
46
- end
47
-
48
- it "should be performed after run" do
49
- RAS.add(:foobar) do
50
- def authenticate!; end
51
- end
52
- strategy = RAS[:foobar].new(env_with_params)
53
- expect(strategy).not_to be_performed
54
- strategy._run!
55
- expect(strategy).to be_performed
56
- strategy.clear!
57
- expect(strategy).not_to be_performed
58
- end
59
-
60
- it "should set the scope" do
61
- RAS.add(:foobar) do
62
- def authenticate!
63
- expect(self.scope).to eq(:user) # TODO: Not being called at all. What's this?
64
- end
65
- end
66
- _strategy = RAS[:foobar].new(env_with_params, :user)
67
- end
68
-
69
- it "should allow you to set a message" do
70
- RAS.add(:foobar) do
71
- def authenticate!
72
- self.message = "foo message"
73
- end
74
- end
75
- strategy = RAS[:foobar].new(env_with_params)
76
- strategy._run!
77
- expect(strategy.message).to eq("foo message")
78
- end
79
-
80
- it "should provide access to the errors" do
81
- RAS.add(:foobar) do
82
- def authenticate!
83
- errors.add(:foo, "foo has an error")
84
- end
85
- end
86
- env = env_with_params
87
- env['warden'] = Warden::Proxy.new(env, Warden::Manager.new({}))
88
- strategy = RAS[:foobar].new(env)
89
- strategy._run!
90
- expect(strategy.errors.on(:foo)).to eq(["foo has an error"])
91
- end
92
-
93
- describe "halting" do
94
- it "should allow you to halt a strategy" do
95
- RAS.add(:foobar) do
96
- def authenticate!
97
- halt!
98
- end
99
- end
100
- str = RAS[:foobar].new(env_with_params)
101
- str._run!
102
- expect(str).to be_halted
103
- end
104
-
105
- it "should not be halted if halt was not called" do
106
- RAS.add(:foobar) do
107
- def authenticate!
108
- "foo"
109
- end
110
- end
111
- str = RAS[:foobar].new(env_with_params)
112
- str._run!
113
- expect(str).not_to be_halted
114
- end
115
-
116
- end
117
-
118
- describe "pass" do
119
- it "should allow you to pass" do
120
- RAS.add(:foobar) do
121
- def authenticate!
122
- pass
123
- end
124
- end
125
- str = RAS[:foobar].new(env_with_params)
126
- str._run!
127
- expect(str).not_to be_halted
128
- expect(str.user).to be_nil
129
- end
130
- end
131
-
132
- describe "redirect" do
133
- it "should allow you to set a redirection" do
134
- RAS.add(:foobar) do
135
- def authenticate!
136
- redirect!("/foo/bar")
137
- end
138
- end
139
- str = RAS[:foobar].new(env_with_params)
140
- str._run!
141
- expect(str.user).to be_nil
142
- end
143
-
144
- it "should mark the strategy as halted when redirecting" do
145
- RAS.add(:foobar) do
146
- def authenticate!
147
- redirect!("/foo/bar")
148
- end
149
- end
150
- str = RAS[:foobar].new(env_with_params)
151
- str._run!
152
- expect(str).to be_halted
153
- end
154
-
155
- it "should escape redirected url parameters" do
156
- RAS.add(:foobar) do
157
- def authenticate!
158
- redirect!("/foo/bar", :foo => "bar")
159
- end
160
- end
161
- str = RAS[:foobar].new(env_with_params)
162
- str._run!
163
- expect(str.headers["Location"]).to eq("/foo/bar?foo=bar")
164
- end
165
-
166
- it "should allow you to set a message" do
167
- RAS.add(:foobar) do
168
- def authenticate!
169
- redirect!("/foo/bar", {:foo => "bar"}, :message => "You are being redirected foo")
170
- end
171
- end
172
- str = RAS[:foobar].new(env_with_params)
173
- str._run!
174
- expect(str.headers["Location"]).to eq("/foo/bar?foo=bar")
175
- expect(str.message).to eq("You are being redirected foo")
176
- end
177
-
178
- it "should set the action as :redirect" do
179
- RAS.add(:foobar) do
180
- def authenticate!
181
- redirect!("/foo/bar", {:foo => "bar"}, :message => "foo")
182
- end
183
- end
184
- str = RAS[:foobar].new(env_with_params)
185
- str._run!
186
- expect(str.result).to be(:redirect)
187
- end
188
- end
189
-
190
- describe "failure" do
191
-
192
- before(:each) do
193
- RAS.add(:hard_fail) do
194
- def authenticate!
195
- fail!("You are not cool enough")
196
- end
197
- end
198
-
199
- RAS.add(:soft_fail) do
200
- def authenticate!
201
- fail("You are too soft")
202
- end
203
- end
204
- @hard = RAS[:hard_fail].new(env_with_params)
205
- @soft = RAS[:soft_fail].new(env_with_params)
206
- end
207
-
208
- it "should allow you to fail hard" do
209
- @hard._run!
210
- expect(@hard.user).to be_nil
211
- end
212
-
213
- it "should halt the strategies when failing hard" do
214
- @hard._run!
215
- expect(@hard).to be_halted
216
- end
217
-
218
- it "should allow you to set a message when failing hard" do
219
- @hard._run!
220
- expect(@hard.message).to eq("You are not cool enough")
221
- end
222
-
223
- it "should set the action as :failure when failing hard" do
224
- @hard._run!
225
- expect(@hard.result).to be(:failure)
226
- end
227
-
228
- it "should allow you to fail soft" do
229
- @soft._run!
230
- expect(@soft.user).to be_nil
231
- end
232
-
233
- it "should not halt the strategies when failing soft" do
234
- @soft._run!
235
- expect(@soft).not_to be_halted
236
- end
237
-
238
- it "should allow you to set a message when failing soft" do
239
- @soft._run!
240
- expect(@soft.message).to eq("You are too soft")
241
- end
242
-
243
- it "should set the action as :failure when failing soft" do
244
- @soft._run!
245
- expect(@soft.result).to be(:failure)
246
- end
247
- end
248
-
249
- describe "success" do
250
- before(:each) do
251
- RAS.add(:foobar) do
252
- def authenticate!
253
- success!("Foo User", "Welcome to the club!")
254
- end
255
- end
256
- @str = RAS[:foobar].new(env_with_params)
257
- end
258
-
259
- it "should allow you to succeed" do
260
- @str._run!
261
- end
262
-
263
- it "should be authenticated after success" do
264
- @str._run!
265
- expect(@str.user).not_to be_nil
266
- end
267
-
268
- it "should allow you to set a message when succeeding" do
269
- @str._run!
270
- expect(@str.message).to eq("Welcome to the club!")
271
- end
272
-
273
- it "should store the user" do
274
- @str._run!
275
- expect(@str.user).to eq("Foo User")
276
- end
277
-
278
- it "should set the action as :success" do
279
- @str._run!
280
- expect(@str.result).to be(:success)
281
- end
282
- end
283
-
284
- describe "custom response" do
285
- before(:each) do
286
- RAS.add(:foobar) do
287
- def authenticate!
288
- custom!([521, {"foo" => "bar"}, ["BAD"]])
289
- end
290
- end
291
- @str = RAS[:foobar].new(env_with_params)
292
- @str._run!
293
- end
294
-
295
- it "should allow me to set a custom rack response" do
296
- expect(@str.user).to be_nil
297
- end
298
-
299
- it "should halt the strategy" do
300
- expect(@str).to be_halted
301
- end
302
-
303
- it "should provide access to the custom rack response" do
304
- expect(@str.custom_response).to eq([521, {"foo" => "bar"}, ["BAD"]])
305
- end
306
-
307
- it "should set the action as :custom" do
308
- @str._run!
309
- expect(@str.result).to eq(:custom)
310
- end
311
- end
312
-
313
- end
@@ -1,94 +0,0 @@
1
- # encoding: utf-8
2
- require 'spec_helper'
3
-
4
- describe Warden::Strategies do
5
- it "should let me add a strategy via a block" do
6
- Warden::Strategies.add(:strategy1) do
7
- def authenticate!
8
- success("foo")
9
- end
10
- end
11
- expect(Warden::Strategies[:strategy1].ancestors).to include(Warden::Strategies::Base)
12
- end
13
-
14
- it "should raise an error if I add a strategy via a block, that does not have an authenticate! method" do
15
- expect {
16
- Warden::Strategies.add(:strategy2) do
17
- end
18
- }.to raise_error(NoMethodError)
19
- end
20
-
21
- it "should raise an error if I add a strategy that does not extend Warden::Strategies::Base" do
22
- non_base = Class.new do
23
- def authenticate!
24
- end
25
- end
26
- expect do
27
- Warden::Strategies.add(:strategy_non_base, non_base)
28
- end.to raise_error(/is not a Warden::Strategies::Base/)
29
- end
30
-
31
- it "should allow me to get access to a particular strategy" do
32
- Warden::Strategies.add(:strategy3) do
33
- def authenticate!; end
34
- end
35
- strategy = Warden::Strategies[:strategy3]
36
- expect(strategy).not_to be_nil
37
- expect(strategy.ancestors).to include(Warden::Strategies::Base)
38
- end
39
-
40
- it "should allow me to add a strategy with the required methods" do
41
- class MyStrategy < Warden::Strategies::Base
42
- def authenticate!; end
43
- end
44
-
45
- expect {
46
- Warden::Strategies.add(:strategy4, MyStrategy)
47
- }.not_to raise_error
48
- end
49
-
50
- it "should not allow a strategy that does not have an authenticate! method" do
51
- class MyOtherStrategy
52
- end
53
- expect {
54
- Warden::Strategies.add(:strategy5, MyOtherStrategy)
55
- }.to raise_error(NoMethodError)
56
- end
57
-
58
- it "should allow me to change a class when providing a block and class" do
59
- class MyStrategy < Warden::Strategies::Base
60
- end
61
-
62
- Warden::Strategies.add(:foo, MyStrategy) do
63
- def authenticate!; end
64
- end
65
-
66
- expect(Warden::Strategies[:foo].ancestors).to include(MyStrategy)
67
- end
68
-
69
- it "should allow me to update a previously given strategy" do
70
- class MyStrategy < Warden::Strategies::Base
71
- def authenticate!; end
72
- end
73
-
74
- Warden::Strategies.add(:strategy6, MyStrategy)
75
-
76
- new_module = Module.new
77
- Warden::Strategies.update(:strategy6) do
78
- include new_module
79
- end
80
-
81
- expect(Warden::Strategies[:strategy6].ancestors).to include(new_module)
82
- end
83
-
84
- it "should allow me to clear the strategies" do
85
- Warden::Strategies.add(:foobar) do
86
- def authenticate!
87
- :foo
88
- end
89
- end
90
- expect(Warden::Strategies[:foobar]).not_to be_nil
91
- Warden::Strategies.clear!
92
- expect(Warden::Strategies[:foobar]).to be_nil
93
- end
94
- end
@@ -1,101 +0,0 @@
1
- # encoding: utf-8
2
- require 'spec_helper'
3
-
4
- describe Warden::Test::Helpers do
5
- before{ $captures = [] }
6
- after{ Warden.test_reset! }
7
-
8
- it "should log me in as a user" do
9
- user = "A User"
10
- login_as user
11
- app = lambda{|e|
12
- $captures << :run
13
- expect(e['warden']).to be_authenticated
14
- expect(e['warden'].user).to eq("A User")
15
- valid_response
16
- }
17
- setup_rack(app).call(env_with_params)
18
- expect($captures).to eq([:run])
19
- end
20
-
21
- it "should log me in as a user of a given scope" do
22
- user = {:some => "user"}
23
- login_as user, :scope => :foo_scope
24
- app = lambda{|e|
25
- $captures << :run
26
- w = e['warden']
27
- expect(w).to be_authenticated(:foo_scope)
28
- expect(w.user(:foo_scope)).to eq(some: "user")
29
- }
30
- setup_rack(app).call(env_with_params)
31
- expect($captures).to eq([:run])
32
- end
33
-
34
- it "should login multiple users with different scopes" do
35
- user = "A user"
36
- foo_user = "A foo user"
37
- login_as user
38
- login_as foo_user, :scope => :foo
39
- app = lambda{|e|
40
- $captures << :run
41
- w = e['warden']
42
- expect(w.user).to eq("A user")
43
- expect(w.user(:foo)).to eq("A foo user")
44
- expect(w).to be_authenticated
45
- expect(w).to be_authenticated(:foo)
46
- }
47
- setup_rack(app).call(env_with_params)
48
- expect($captures).to eq([:run])
49
- end
50
-
51
- it "should log out all users" do
52
- user = "A user"
53
- foo = "Foo"
54
- login_as user
55
- login_as foo, :scope => :foo
56
- app = lambda{|e|
57
- $captures << :run
58
- w = e['warden']
59
- expect(w.user).to eq("A user")
60
- expect(w.user(:foo)).to eq("Foo")
61
- w.logout
62
- expect(w.user).to be_nil
63
- expect(w.user(:foo)).to be_nil
64
- expect(w).not_to be_authenticated
65
- expect(w).not_to be_authenticated(:foo)
66
- }
67
- setup_rack(app).call(env_with_params)
68
- expect($captures).to eq([:run])
69
- end
70
-
71
- it "should logout a specific user" do
72
- user = "A User"
73
- foo = "Foo"
74
- login_as user
75
- login_as foo, :scope => :foo
76
- app = lambda{|e|
77
- $captures << :run
78
- w = e['warden']
79
- w.logout :foo
80
- expect(w.user).to eq("A User")
81
- expect(w.user(:foo)).to be_nil
82
- expect(w).not_to be_authenticated(:foo)
83
- }
84
- setup_rack(app).call(env_with_params)
85
- expect($captures).to eq([:run])
86
- end
87
-
88
- it "should return a valid mocked warden" do
89
- user = "A User"
90
- login_as user
91
-
92
- expect(warden.class).to eq(Warden::Proxy)
93
- expect(warden.user).to eq(user)
94
- end
95
-
96
- describe "#asset_paths" do
97
- it "should default asset_paths to anything asset path regex" do
98
- expect(Warden.asset_paths).to eq([/^\/assets\//] )
99
- end
100
- end
101
- end