warden 1.2.3 → 1.2.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +5 -0
  3. data/.rspec +3 -0
  4. data/.travis.yml +7 -0
  5. data/{History.rdoc → CHANGELOG.md} +16 -3
  6. data/Gemfile +3 -2
  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 +3 -3
  12. data/lib/warden/errors.rb +2 -1
  13. data/lib/warden/hooks.rb +10 -9
  14. data/lib/warden/manager.rb +23 -10
  15. data/lib/warden/mixins/common.rb +2 -1
  16. data/lib/warden/proxy.rb +27 -11
  17. data/lib/warden/session_serializer.rb +1 -0
  18. data/lib/warden/strategies/base.rb +14 -8
  19. data/lib/warden/strategies.rb +1 -0
  20. data/lib/warden/test/helpers.rb +3 -2
  21. data/lib/warden/test/mock.rb +69 -0
  22. data/lib/warden/test/warden_helpers.rb +2 -1
  23. data/lib/warden/version.rb +2 -1
  24. data/lib/warden.rb +2 -0
  25. data/warden.gemspec +21 -18
  26. metadata +33 -50
  27. data/README.textile +0 -9
  28. data/spec/helpers/request_helper.rb +0 -51
  29. data/spec/helpers/strategies/failz.rb +0 -8
  30. data/spec/helpers/strategies/invalid.rb +0 -8
  31. data/spec/helpers/strategies/pass.rb +0 -8
  32. data/spec/helpers/strategies/pass_with_message.rb +0 -8
  33. data/spec/helpers/strategies/password.rb +0 -13
  34. data/spec/helpers/strategies/single.rb +0 -12
  35. data/spec/spec_helper.rb +0 -24
  36. data/spec/warden/authenticated_data_store_spec.rb +0 -114
  37. data/spec/warden/config_spec.rb +0 -48
  38. data/spec/warden/errors_spec.rb +0 -47
  39. data/spec/warden/hooks_spec.rb +0 -373
  40. data/spec/warden/manager_spec.rb +0 -316
  41. data/spec/warden/proxy_spec.rb +0 -1041
  42. data/spec/warden/scoped_session_serializer.rb +0 -123
  43. data/spec/warden/session_serializer_spec.rb +0 -53
  44. data/spec/warden/strategies/base_spec.rb +0 -313
  45. data/spec/warden/strategies_spec.rb +0 -93
  46. data/spec/warden/test/helpers_spec.rb +0 -93
  47. data/spec/warden/test/test_mode_spec.rb +0 -76
@@ -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 == true
35
- end
36
-
37
- it "should respond to :deserialize" do
38
- serializer_respond_to?(:deserialize).should == 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 == 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 == 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 == "user"
70
- end
71
-
72
- it "should not have a {scope}_serialize by default" do
73
- serializer_respond_to?(:admin_serialize).should == 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 == "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 == "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 == "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
- @env['rack.session'].should == { "warden.user.default.key"=>"user" }
14
- end
15
-
16
- it "should check if a data is stored or not" do
17
- @session.should_not be_stored(:default)
18
- @session.store("user", :default)
19
- @session.should be_stored(:default)
20
- end
21
-
22
- it "should load an user from store" do
23
- @session.fetch(:default).should be_nil
24
- @session.store("user", :default)
25
- @session.fetch(:default).should == "user"
26
- end
27
-
28
- it "should store data based on the scope" do
29
- @session.store("user", :default)
30
- @session.fetch(:default).should == "user"
31
- @session.fetch(:another).should be_nil
32
- end
33
-
34
- it "should delete data from store" do
35
- @session.store("user", :default)
36
- @session.fetch(:default).should == "user"
37
- @session.delete(:default)
38
- @session.fetch(:default).should be_nil
39
- end
40
-
41
- it "should delete information from store if user cannot be retrieved" do
42
- @session.store("user", :default)
43
- @env['rack.session'].should have_key("warden.user.default.key")
44
- @session.instance_eval "def deserialize(key); nil; end"
45
- @session.fetch(:default)
46
- @env['rack.session'].should_not have_key("warden.user.default.key")
47
- end
48
-
49
- it "should support a nil session store" do
50
- @env['rack.session'] = nil
51
- @session.fetch(:default).should 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
- strategy.headers["foo"].should == "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
- strategy.headers["foo"].should == "bar"
32
- strategy.headers.clear
33
- strategy.headers.should 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
- strategy.user.should == "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
- strategy.should_not be_performed
54
- strategy._run!
55
- strategy.should be_performed
56
- strategy.clear!
57
- strategy.should_not be_performed
58
- end
59
-
60
- it "should set the scope" do
61
- RAS.add(:foobar) do
62
- def authenticate!
63
- self.scope.should == :user
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
- strategy.message.should == "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
- strategy.errors.on(:foo).should == ["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
- str.should 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
- str.should_not 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
- str.should_not be_halted
128
- str.user.should 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
- str.user.should 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
- str.should 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
- str.headers["Location"].should == "/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
- str.headers["Location"].should == "/foo/bar?foo=bar"
175
- str.message.should == "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
- str.result.should == :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
- @hard.user.should be_nil
211
- end
212
-
213
- it "should halt the strategies when failing hard" do
214
- @hard._run!
215
- @hard.should be_halted
216
- end
217
-
218
- it "should allow you to set a message when failing hard" do
219
- @hard._run!
220
- @hard.message.should == "You are not cool enough"
221
- end
222
-
223
- it "should set the action as :failure when failing hard" do
224
- @hard._run!
225
- @hard.result.should == :failure
226
- end
227
-
228
- it "should allow you to fail soft" do
229
- @soft._run!
230
- @soft.user.should be_nil
231
- end
232
-
233
- it "should not halt the strategies when failing soft" do
234
- @soft._run!
235
- @soft.should_not be_halted
236
- end
237
-
238
- it "should allow you to set a message when failing soft" do
239
- @soft._run!
240
- @soft.message.should == "You are too soft"
241
- end
242
-
243
- it "should set the action as :failure when failing soft" do
244
- @soft._run!
245
- @soft.result.should == :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
- @str.user.should_not be_nil
266
- end
267
-
268
- it "should allow you to set a message when succeeding" do
269
- @str._run!
270
- @str.message.should == "Welcome to the club!"
271
- end
272
-
273
- it "should store the user" do
274
- @str._run!
275
- @str.user.should == "Foo User"
276
- end
277
-
278
- it "should set the action as :success" do
279
- @str._run!
280
- @str.result.should == :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
- @str.user.should be_nil
297
- end
298
-
299
- it "should halt the strategy" do
300
- @str.should be_halted
301
- end
302
-
303
- it "should provide access to the custom rack response" do
304
- @str.custom_response.should == [521, {"foo" => "bar"}, ["BAD"]]
305
- end
306
-
307
- it "should set the action as :custom" do
308
- @str._run!
309
- @str.result.should == :custom
310
- end
311
- end
312
-
313
- end
@@ -1,93 +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
- Warden::Strategies[:strategy1].ancestors.should 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
- lambda do
16
- Warden::Strategies.add(:strategy2) do
17
- end
18
- end.should raise_error
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
- strategy.should_not be_nil
37
- strategy.ancestors.should 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
- lambda do
45
- Warden::Strategies.add(:strategy4, MyStrategy)
46
- end.should_not raise_error
47
- end
48
-
49
- it "should not allow a strategy that does not have an authenticate! method" do
50
- class MyOtherStrategy
51
- end
52
- lambda do
53
- Warden::Strategies.add(:strategy5, MyOtherStrategy)
54
- end.should raise_error
55
- end
56
-
57
- it "should allow me to change a class when providing a block and class" do
58
- class MyStrategy < Warden::Strategies::Base
59
- end
60
-
61
- Warden::Strategies.add(:foo, MyStrategy) do
62
- def authenticate!; end
63
- end
64
-
65
- Warden::Strategies[:foo].ancestors.should include(MyStrategy)
66
- end
67
-
68
- it "should allow me to update a previously given strategy" do
69
- class MyStrategy < Warden::Strategies::Base
70
- def authenticate!; end
71
- end
72
-
73
- Warden::Strategies.add(:strategy6, MyStrategy)
74
-
75
- new_module = Module.new
76
- Warden::Strategies.update(:strategy6) do
77
- include new_module
78
- end
79
-
80
- Warden::Strategies[:strategy6].ancestors.should include(new_module)
81
- end
82
-
83
- it "should allow me to clear the strategies" do
84
- Warden::Strategies.add(:foobar) do
85
- def authenticate!
86
- :foo
87
- end
88
- end
89
- Warden::Strategies[:foobar].should_not be_nil
90
- Warden::Strategies.clear!
91
- Warden::Strategies[:foobar].should be_nil
92
- end
93
- end
@@ -1,93 +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
- e['warden'].should be_authenticated
14
- e['warden'].user.should == "A User"
15
- valid_response
16
- }
17
- setup_rack(app).call(env_with_params)
18
- $captures.should == [: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
- w.should be_authenticated(:foo_scope)
28
- w.user(:foo_scope).should == {:some => "user"}
29
- }
30
- setup_rack(app).call(env_with_params)
31
- $captures.should == [: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
- w.user.should == "A user"
43
- w.user(:foo).should == "A foo user"
44
- w.should be_authenticated
45
- w.should be_authenticated(:foo)
46
- }
47
- setup_rack(app).call(env_with_params)
48
- $captures.should == [: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
- w.user.should == "A user"
60
- w.user(:foo).should == "Foo"
61
- w.logout
62
- w.user.should be_nil
63
- w.user(:foo).should be_nil
64
- w.should_not be_authenticated
65
- w.should_not be_authenticated(:foo)
66
- }
67
- setup_rack(app).call(env_with_params)
68
- $captures.should == [: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
- w.user.should == "A User"
81
- w.user(:foo).should be_nil
82
- w.should_not be_authenticated(:foo)
83
- }
84
- setup_rack(app).call(env_with_params)
85
- $captures.should == [:run]
86
- end
87
-
88
- describe "#asset_paths" do
89
- it "should default asset_paths to anything asset path regex" do
90
- Warden.asset_paths.should == [/^\/assets\//]
91
- end
92
- end
93
- end