warden 1.2.4 → 1.2.9

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 +5 -5
  2. data/.github/workflows/ruby.yml +27 -0
  3. data/.gitignore +6 -0
  4. data/.rspec +3 -0
  5. data/{History.rdoc → CHANGELOG.md} +80 -36
  6. data/Gemfile +3 -2
  7. data/LICENSE +2 -1
  8. data/README.md +18 -0
  9. data/Rakefile +4 -8
  10. data/lib/warden.rb +2 -0
  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 +24 -4
  17. data/lib/warden/session_serializer.rb +1 -0
  18. data/lib/warden/strategies.rb +1 -0
  19. data/lib/warden/strategies/base.rb +3 -1
  20. data/lib/warden/test/helpers.rb +2 -1
  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/warden.gemspec +19 -18
  25. metadata +19 -35
  26. data/README.textile +0 -9
  27. data/spec/helpers/request_helper.rb +0 -51
  28. data/spec/helpers/strategies/fail_with_user.rb +0 -10
  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 -340
  41. data/spec/warden/proxy_spec.rb +0 -1050
  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 -94
  46. data/spec/warden/test/helpers_spec.rb +0 -93
  47. 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