warden 1.2.7 → 1.2.8

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