warden 1.2.7 → 1.2.9

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 (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} +74 -39
  6. data/Gemfile +2 -2
  7. data/LICENSE +2 -1
  8. data/README.md +18 -0
  9. data/Rakefile +3 -8
  10. data/lib/warden/config.rb +1 -1
  11. data/lib/warden/errors.rb +2 -2
  12. data/lib/warden/hooks.rb +1 -1
  13. data/lib/warden/manager.rb +2 -2
  14. data/lib/warden/mixins/common.rb +1 -1
  15. data/lib/warden/proxy.rb +24 -5
  16. data/lib/warden/session_serializer.rb +1 -1
  17. data/lib/warden/strategies/base.rb +2 -1
  18. data/lib/warden/test/helpers.rb +2 -2
  19. data/lib/warden/test/mock.rb +5 -5
  20. data/lib/warden/test/warden_helpers.rb +1 -1
  21. data/lib/warden/version.rb +2 -2
  22. data/lib/warden.rb +1 -1
  23. data/warden.gemspec +18 -18
  24. metadata +18 -36
  25. data/README.textile +0 -9
  26. data/spec/helpers/request_helper.rb +0 -52
  27. data/spec/helpers/strategies/fail_with_user.rb +0 -11
  28. data/spec/helpers/strategies/failz.rb +0 -9
  29. data/spec/helpers/strategies/invalid.rb +0 -9
  30. data/spec/helpers/strategies/pass.rb +0 -9
  31. data/spec/helpers/strategies/pass_with_message.rb +0 -9
  32. data/spec/helpers/strategies/password.rb +0 -14
  33. data/spec/helpers/strategies/single.rb +0 -13
  34. data/spec/spec_helper.rb +0 -26
  35. data/spec/warden/authenticated_data_store_spec.rb +0 -115
  36. data/spec/warden/config_spec.rb +0 -49
  37. data/spec/warden/errors_spec.rb +0 -48
  38. data/spec/warden/hooks_spec.rb +0 -374
  39. data/spec/warden/manager_spec.rb +0 -341
  40. data/spec/warden/proxy_spec.rb +0 -1051
  41. data/spec/warden/scoped_session_serializer.rb +0 -124
  42. data/spec/warden/session_serializer_spec.rb +0 -54
  43. data/spec/warden/strategies/base_spec.rb +0 -314
  44. data/spec/warden/strategies_spec.rb +0 -95
  45. data/spec/warden/test/helpers_spec.rb +0 -94
  46. data/spec/warden/test/mock_spec.rb +0 -16
  47. 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
@@ -1,95 +0,0 @@
1
- # encoding: utf-8
2
- # frozen_string_literal: true
3
- require 'spec_helper'
4
-
5
- describe Warden::Strategies do
6
- it "should let me add a strategy via a block" do
7
- Warden::Strategies.add(:strategy1) do
8
- def authenticate!
9
- success("foo")
10
- end
11
- end
12
- expect(Warden::Strategies[:strategy1].ancestors).to include(Warden::Strategies::Base)
13
- end
14
-
15
- it "should raise an error if I add a strategy via a block, that does not have an authenticate! method" do
16
- expect {
17
- Warden::Strategies.add(:strategy2) do
18
- end
19
- }.to raise_error(NoMethodError)
20
- end
21
-
22
- it "should raise an error if I add a strategy that does not extend Warden::Strategies::Base" do
23
- non_base = Class.new do
24
- def authenticate!
25
- end
26
- end
27
- expect do
28
- Warden::Strategies.add(:strategy_non_base, non_base)
29
- end.to raise_error(/is not a Warden::Strategies::Base/)
30
- end
31
-
32
- it "should allow me to get access to a particular strategy" do
33
- Warden::Strategies.add(:strategy3) do
34
- def authenticate!; end
35
- end
36
- strategy = Warden::Strategies[:strategy3]
37
- expect(strategy).not_to be_nil
38
- expect(strategy.ancestors).to include(Warden::Strategies::Base)
39
- end
40
-
41
- it "should allow me to add a strategy with the required methods" do
42
- class MyStrategy < Warden::Strategies::Base
43
- def authenticate!; end
44
- end
45
-
46
- expect {
47
- Warden::Strategies.add(:strategy4, MyStrategy)
48
- }.not_to raise_error
49
- end
50
-
51
- it "should not allow a strategy that does not have an authenticate! method" do
52
- class MyOtherStrategy
53
- end
54
- expect {
55
- Warden::Strategies.add(:strategy5, MyOtherStrategy)
56
- }.to raise_error(NoMethodError)
57
- end
58
-
59
- it "should allow me to change a class when providing a block and class" do
60
- class MyStrategy < Warden::Strategies::Base
61
- end
62
-
63
- Warden::Strategies.add(:foo, MyStrategy) do
64
- def authenticate!; end
65
- end
66
-
67
- expect(Warden::Strategies[:foo].ancestors).to include(MyStrategy)
68
- end
69
-
70
- it "should allow me to update a previously given strategy" do
71
- class MyStrategy < Warden::Strategies::Base
72
- def authenticate!; end
73
- end
74
-
75
- Warden::Strategies.add(:strategy6, MyStrategy)
76
-
77
- new_module = Module.new
78
- Warden::Strategies.update(:strategy6) do
79
- include new_module
80
- end
81
-
82
- expect(Warden::Strategies[:strategy6].ancestors).to include(new_module)
83
- end
84
-
85
- it "should allow me to clear the strategies" do
86
- Warden::Strategies.add(:foobar) do
87
- def authenticate!
88
- :foo
89
- end
90
- end
91
- expect(Warden::Strategies[:foobar]).not_to be_nil
92
- Warden::Strategies.clear!
93
- expect(Warden::Strategies[:foobar]).to be_nil
94
- end
95
- end
@@ -1,94 +0,0 @@
1
- # encoding: utf-8
2
- # frozen_string_literal: true
3
- require 'spec_helper'
4
-
5
- describe Warden::Test::Helpers do
6
- before{ $captures = [] }
7
- after{ Warden.test_reset! }
8
-
9
- it "should log me in as a user" do
10
- user = "A User"
11
- login_as user
12
- app = lambda{|e|
13
- $captures << :run
14
- expect(e['warden']).to be_authenticated
15
- expect(e['warden'].user).to eq("A User")
16
- valid_response
17
- }
18
- setup_rack(app).call(env_with_params)
19
- expect($captures).to eq([:run])
20
- end
21
-
22
- it "should log me in as a user of a given scope" do
23
- user = {:some => "user"}
24
- login_as user, :scope => :foo_scope
25
- app = lambda{|e|
26
- $captures << :run
27
- w = e['warden']
28
- expect(w).to be_authenticated(:foo_scope)
29
- expect(w.user(:foo_scope)).to eq(some: "user")
30
- }
31
- setup_rack(app).call(env_with_params)
32
- expect($captures).to eq([:run])
33
- end
34
-
35
- it "should login multiple users with different scopes" do
36
- user = "A user"
37
- foo_user = "A foo user"
38
- login_as user
39
- login_as foo_user, :scope => :foo
40
- app = lambda{|e|
41
- $captures << :run
42
- w = e['warden']
43
- expect(w.user).to eq("A user")
44
- expect(w.user(:foo)).to eq("A foo user")
45
- expect(w).to be_authenticated
46
- expect(w).to be_authenticated(:foo)
47
- }
48
- setup_rack(app).call(env_with_params)
49
- expect($captures).to eq([:run])
50
- end
51
-
52
- it "should log out all users" do
53
- user = "A user"
54
- foo = "Foo"
55
- login_as user
56
- login_as foo, :scope => :foo
57
- app = lambda{|e|
58
- $captures << :run
59
- w = e['warden']
60
- expect(w.user).to eq("A user")
61
- expect(w.user(:foo)).to eq("Foo")
62
- w.logout
63
- expect(w.user).to be_nil
64
- expect(w.user(:foo)).to be_nil
65
- expect(w).not_to be_authenticated
66
- expect(w).not_to be_authenticated(:foo)
67
- }
68
- setup_rack(app).call(env_with_params)
69
- expect($captures).to eq([:run])
70
- end
71
-
72
- it "should logout a specific user" do
73
- user = "A User"
74
- foo = "Foo"
75
- login_as user
76
- login_as foo, :scope => :foo
77
- app = lambda{|e|
78
- $captures << :run
79
- w = e['warden']
80
- w.logout :foo
81
- expect(w.user).to eq("A User")
82
- expect(w.user(:foo)).to be_nil
83
- expect(w).not_to be_authenticated(:foo)
84
- }
85
- setup_rack(app).call(env_with_params)
86
- expect($captures).to eq([:run])
87
- end
88
-
89
- describe "#asset_paths" do
90
- it "should default asset_paths to anything asset path regex" do
91
- expect(Warden.asset_paths).to eq([/^\/assets\//] )
92
- end
93
- end
94
- end
@@ -1,16 +0,0 @@
1
- # encoding: utf-8
2
- # frozen_string_literal: true
3
- require 'spec_helper'
4
-
5
- describe Warden::Test::Mock do
6
- before{ $captures = [] }
7
- after{ Warden.test_reset! }
8
-
9
- it "should return a valid mocked warden" do
10
- user = "A User"
11
- login_as user
12
-
13
- expect(warden.class).to eq(Warden::Proxy)
14
- expect(warden.user).to eq(user)
15
- end
16
- end