warden 1.2.7 → 1.2.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +5 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/{History.rdoc → CHANGELOG.md} +7 -3
- data/Gemfile +1 -1
- data/Gemfile.lock +40 -0
- data/LICENSE +1 -1
- data/README.md +18 -0
- data/Rakefile +3 -8
- data/lib/warden.rb +1 -1
- data/lib/warden/config.rb +1 -1
- data/lib/warden/errors.rb +2 -2
- data/lib/warden/hooks.rb +1 -1
- data/lib/warden/manager.rb +2 -2
- data/lib/warden/mixins/common.rb +1 -1
- data/lib/warden/proxy.rb +15 -4
- data/lib/warden/session_serializer.rb +1 -1
- data/lib/warden/strategies/base.rb +1 -1
- data/lib/warden/test/helpers.rb +2 -2
- data/lib/warden/test/mock.rb +5 -5
- data/lib/warden/test/warden_helpers.rb +1 -1
- data/lib/warden/version.rb +2 -2
- data/warden.gemspec +20 -18
- metadata +18 -33
- data/README.textile +0 -9
- data/spec/helpers/request_helper.rb +0 -52
- data/spec/helpers/strategies/fail_with_user.rb +0 -11
- data/spec/helpers/strategies/failz.rb +0 -9
- data/spec/helpers/strategies/invalid.rb +0 -9
- data/spec/helpers/strategies/pass.rb +0 -9
- data/spec/helpers/strategies/pass_with_message.rb +0 -9
- data/spec/helpers/strategies/password.rb +0 -14
- data/spec/helpers/strategies/single.rb +0 -13
- data/spec/spec_helper.rb +0 -26
- data/spec/warden/authenticated_data_store_spec.rb +0 -115
- data/spec/warden/config_spec.rb +0 -49
- data/spec/warden/errors_spec.rb +0 -48
- data/spec/warden/hooks_spec.rb +0 -374
- data/spec/warden/manager_spec.rb +0 -341
- data/spec/warden/proxy_spec.rb +0 -1051
- data/spec/warden/scoped_session_serializer.rb +0 -124
- data/spec/warden/session_serializer_spec.rb +0 -54
- data/spec/warden/strategies/base_spec.rb +0 -314
- data/spec/warden/strategies_spec.rb +0 -95
- data/spec/warden/test/helpers_spec.rb +0 -94
- data/spec/warden/test/mock_spec.rb +0 -16
- data/spec/warden/test/test_mode_spec.rb +0 -76
data/README.textile
DELETED
@@ -1,9 +0,0 @@
|
|
1
|
-
Please see the "Warden Wiki":http://wiki.github.com/hassox/warden for overview documentation.
|
2
|
-
|
3
|
-
h2. Maintainers
|
4
|
-
|
5
|
-
* Daniel Neighman (hassox)
|
6
|
-
* José Valim (josevalim)
|
7
|
-
* Justin Smestad (jsmestad)
|
8
|
-
|
9
|
-
"A list of all contributors is available on Github.":https://github.com/hassox/warden/contributors
|
@@ -1,52 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
# frozen_string_literal: true
|
3
|
-
module Warden::Spec
|
4
|
-
module Helpers
|
5
|
-
FAILURE_APP = lambda{|e|[401, {"Content-Type" => "text/plain"}, ["You Fail!"]] }
|
6
|
-
|
7
|
-
def env_with_params(path = "/", params = {}, env = {})
|
8
|
-
method = params.delete(:method) || "GET"
|
9
|
-
env = { 'HTTP_VERSION' => '1.1', 'REQUEST_METHOD' => "#{method}" }.merge(env)
|
10
|
-
Rack::MockRequest.env_for("#{path}?#{Rack::Utils.build_query(params)}", env)
|
11
|
-
end
|
12
|
-
|
13
|
-
def setup_rack(app = nil, opts = {}, &block)
|
14
|
-
app ||= block if block_given?
|
15
|
-
|
16
|
-
opts[:failure_app] ||= failure_app
|
17
|
-
opts[:default_strategies] ||= [:password]
|
18
|
-
opts[:default_serializers] ||= [:session]
|
19
|
-
blk = opts[:configurator] || proc{}
|
20
|
-
|
21
|
-
Rack::Builder.new do
|
22
|
-
use opts[:session] || Warden::Spec::Helpers::Session unless opts[:nil_session]
|
23
|
-
use Warden::Manager, opts, &blk
|
24
|
-
run app
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def valid_response
|
29
|
-
Rack::Response.new("OK").finish
|
30
|
-
end
|
31
|
-
|
32
|
-
def failure_app
|
33
|
-
Warden::Spec::Helpers::FAILURE_APP
|
34
|
-
end
|
35
|
-
|
36
|
-
def success_app
|
37
|
-
lambda{|e| [200, {"Content-Type" => "text/plain"}, ["You Win"]]}
|
38
|
-
end
|
39
|
-
|
40
|
-
class Session
|
41
|
-
attr_accessor :app
|
42
|
-
def initialize(app,configs = {})
|
43
|
-
@app = app
|
44
|
-
end
|
45
|
-
|
46
|
-
def call(e)
|
47
|
-
e['rack.session'] ||= {}
|
48
|
-
@app.call(e)
|
49
|
-
end
|
50
|
-
end # session
|
51
|
-
end
|
52
|
-
end
|
@@ -1,11 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
# frozen_string_literal: true
|
3
|
-
Warden::Strategies.add(:fail_with_user) do
|
4
|
-
def authenticate!
|
5
|
-
request.env['warden.spec.strategies'] ||= []
|
6
|
-
request.env['warden.spec.strategies'] << :fail_with_user
|
7
|
-
self.user = 'Valid User'
|
8
|
-
fail!
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
@@ -1,9 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
# frozen_string_literal: true
|
3
|
-
Warden::Strategies.add(:pass_with_message) do
|
4
|
-
def authenticate!
|
5
|
-
request.env['warden.spec.strategies'] ||= []
|
6
|
-
request.env['warden.spec.strategies'] << :pass_with_message
|
7
|
-
success!("Valid User", "The Success Strategy Has Accepted You") unless scope == :failz
|
8
|
-
end
|
9
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
# frozen_string_literal: true
|
3
|
-
Warden::Strategies.add(:password) do
|
4
|
-
def authenticate!
|
5
|
-
request.env['warden.spec.strategies'] ||= []
|
6
|
-
request.env['warden.spec.strategies'] << :password
|
7
|
-
if params["password"] || params["username"]
|
8
|
-
params["password"] == "sekrit" && params["username"] == "fred" ?
|
9
|
-
success!("Authenticated User") : fail!("Username or password is incorrect")
|
10
|
-
else
|
11
|
-
pass
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
# frozen_string_literal: true
|
3
|
-
Warden::Strategies.add(:single) do
|
4
|
-
def authenticate!
|
5
|
-
request.env['warden.spec.strategies'] ||= []
|
6
|
-
request.env['warden.spec.strategies'] << :single
|
7
|
-
success!("Valid User")
|
8
|
-
end
|
9
|
-
|
10
|
-
def store?
|
11
|
-
false
|
12
|
-
end
|
13
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
# frozen_string_literal: true
|
3
|
-
$TESTING=true
|
4
|
-
|
5
|
-
$:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
6
|
-
$:.unshift File.expand_path(File.join(File.dirname(__FILE__)))
|
7
|
-
require 'warden'
|
8
|
-
|
9
|
-
require 'rubygems'
|
10
|
-
require 'rack'
|
11
|
-
|
12
|
-
Dir[File.join(File.dirname(__FILE__), "helpers", "**/*.rb")].each do |f|
|
13
|
-
require f
|
14
|
-
end
|
15
|
-
|
16
|
-
RSpec.configure do |config|
|
17
|
-
config.include(Warden::Spec::Helpers)
|
18
|
-
config.include(Warden::Test::Helpers)
|
19
|
-
config.include(Warden::Test::Mock)
|
20
|
-
|
21
|
-
def load_strategies
|
22
|
-
Dir[File.join(File.dirname(__FILE__), "helpers", "strategies", "**/*.rb")].each do |f|
|
23
|
-
load f
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
@@ -1,115 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
# frozen_string_literal: true
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe "authenticated data store" do
|
6
|
-
|
7
|
-
before(:each) do
|
8
|
-
@env = env_with_params
|
9
|
-
@env['rack.session'] = {
|
10
|
-
"warden.user.foo.key" => "foo user",
|
11
|
-
"warden.user.default.key" => "default user",
|
12
|
-
:foo => "bar"
|
13
|
-
}
|
14
|
-
end
|
15
|
-
|
16
|
-
it "should store data for the default scope" do
|
17
|
-
app = lambda do |e|
|
18
|
-
e['warden'].authenticate(:pass)
|
19
|
-
e['warden'].authenticate(:pass, :scope => :foo)
|
20
|
-
expect(e['warden']).to be_authenticated
|
21
|
-
expect(e['warden']).to be_authenticated(:foo)
|
22
|
-
|
23
|
-
# Store the data for :default
|
24
|
-
e['warden'].session[:key] = "value"
|
25
|
-
valid_response
|
26
|
-
end
|
27
|
-
setup_rack(app).call(@env)
|
28
|
-
expect(@env['rack.session']['warden.user.default.session']).to eq(key: "value")
|
29
|
-
expect(@env['rack.session']['warden.user.foo.session']).to be_nil
|
30
|
-
end
|
31
|
-
|
32
|
-
it "should store data for the foo user" do
|
33
|
-
app = lambda do |e|
|
34
|
-
e['warden'].session(:foo)[:key] = "value"
|
35
|
-
valid_response
|
36
|
-
end
|
37
|
-
setup_rack(app).call(@env)
|
38
|
-
expect(@env['rack.session']['warden.user.foo.session']).to eq(key: "value")
|
39
|
-
end
|
40
|
-
|
41
|
-
it "should store the data separately" do
|
42
|
-
app = lambda do |e|
|
43
|
-
e['warden'].session[:key] = "value"
|
44
|
-
e['warden'].session(:foo)[:key] = "another value"
|
45
|
-
valid_response
|
46
|
-
end
|
47
|
-
setup_rack(app).call(@env)
|
48
|
-
expect(@env['rack.session']['warden.user.default.session']).to eq(key: "value")
|
49
|
-
expect(@env['rack.session']['warden.user.foo.session' ]).to eq(key: "another value")
|
50
|
-
end
|
51
|
-
|
52
|
-
it "should clear the foo scoped data when foo logs out" do
|
53
|
-
app = lambda do |e|
|
54
|
-
e['warden'].session[:key] = "value"
|
55
|
-
e['warden'].session(:foo)[:key] = "another value"
|
56
|
-
e['warden'].logout(:foo)
|
57
|
-
valid_response
|
58
|
-
end
|
59
|
-
setup_rack(app).call(@env)
|
60
|
-
expect(@env['rack.session']['warden.user.default.session']).to eq(key: "value")
|
61
|
-
expect(@env['rack.session']['warden.user.foo.session' ]).to be_nil
|
62
|
-
end
|
63
|
-
|
64
|
-
it "should clear out the default data when :default logs out" do
|
65
|
-
app = lambda do |e|
|
66
|
-
e['warden'].session[:key] = "value"
|
67
|
-
e['warden'].session(:foo)[:key] = "another value"
|
68
|
-
e['warden'].logout(:default)
|
69
|
-
valid_response
|
70
|
-
end
|
71
|
-
setup_rack(app).call(@env)
|
72
|
-
expect(@env['rack.session']['warden.user.default.session']).to be_nil
|
73
|
-
expect(@env['rack.session']['warden.user.foo.session' ]).to eq(key: "another value")
|
74
|
-
end
|
75
|
-
|
76
|
-
it "should clear out all data when a general logout is performed" do
|
77
|
-
app = lambda do |e|
|
78
|
-
e['warden'].session[:key] = "value"
|
79
|
-
e['warden'].session(:foo)[:key] = "another value"
|
80
|
-
e['warden'].logout
|
81
|
-
valid_response
|
82
|
-
end
|
83
|
-
setup_rack(app).call(@env)
|
84
|
-
expect(@env['rack.session']['warden.user.default.session']).to be_nil
|
85
|
-
expect(@env['rack.session']['warden.user.foo.session' ]).to be_nil
|
86
|
-
end
|
87
|
-
|
88
|
-
it "should logout multiple persons at once" do
|
89
|
-
@env['rack.session']['warden.user.bar.key'] = "bar user"
|
90
|
-
|
91
|
-
app = lambda do |e|
|
92
|
-
e['warden'].session[:key] = "value"
|
93
|
-
e['warden'].session(:foo)[:key] = "another value"
|
94
|
-
e['warden'].session(:bar)[:key] = "yet another"
|
95
|
-
e['warden'].logout(:bar, :default)
|
96
|
-
valid_response
|
97
|
-
end
|
98
|
-
setup_rack(app).call(@env)
|
99
|
-
expect(@env['rack.session']['warden.user.default.session']).to be_nil
|
100
|
-
expect(@env['rack.session']['warden.user.foo.session' ]).to eq(key: "another value")
|
101
|
-
expect(@env['rack.session']['warden.user.bar.session' ]).to be_nil
|
102
|
-
end
|
103
|
-
|
104
|
-
it "should not store data for a user who is not logged in" do
|
105
|
-
@env['rack.session']
|
106
|
-
app = lambda do |e|
|
107
|
-
e['warden'].session(:not_here)[:key] = "value"
|
108
|
-
valid_response
|
109
|
-
end
|
110
|
-
|
111
|
-
expect {
|
112
|
-
setup_rack(app).call(@env)
|
113
|
-
}.to raise_error(Warden::NotAuthenticated)
|
114
|
-
end
|
115
|
-
end
|
data/spec/warden/config_spec.rb
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
# frozen_string_literal: true
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe Warden::Config do
|
6
|
-
|
7
|
-
before(:each) do
|
8
|
-
@config = Warden::Config.new
|
9
|
-
end
|
10
|
-
|
11
|
-
it "should behave like a hash" do
|
12
|
-
@config[:foo] = :bar
|
13
|
-
expect(@config[:foo]).to eq(:bar)
|
14
|
-
end
|
15
|
-
|
16
|
-
it "should provide hash accessors" do
|
17
|
-
@config.failure_app = :foo
|
18
|
-
expect(@config[:failure_app]).to eq(:foo)
|
19
|
-
@config[:failure_app] = :bar
|
20
|
-
expect(@config.failure_app).to eq(:bar)
|
21
|
-
end
|
22
|
-
|
23
|
-
it "should allow to read and set default strategies" do
|
24
|
-
@config.default_strategies :foo, :bar
|
25
|
-
expect(@config.default_strategies).to eq([:foo, :bar])
|
26
|
-
end
|
27
|
-
|
28
|
-
it "should allow to silence missing strategies" do
|
29
|
-
@config.silence_missing_strategies!
|
30
|
-
expect(@config.silence_missing_strategies?).to eq(true)
|
31
|
-
end
|
32
|
-
|
33
|
-
it "should set the default_scope" do
|
34
|
-
expect(@config.default_scope).to eq(:default)
|
35
|
-
@config.default_scope = :foo
|
36
|
-
expect(@config.default_scope).to eq(:foo)
|
37
|
-
end
|
38
|
-
|
39
|
-
it "should merge given options on initialization" do
|
40
|
-
expect(Warden::Config.new(:foo => :bar)[:foo]).to eq(:bar)
|
41
|
-
end
|
42
|
-
|
43
|
-
it "should setup defaults with the scope_defaults method" do
|
44
|
-
c = Warden::Config.new
|
45
|
-
c.scope_defaults :foo, :strategies => [:foo, :bar], :store => false
|
46
|
-
expect(c.default_strategies(:scope => :foo)).to eq([:foo, :bar])
|
47
|
-
expect(c.scope_defaults(:foo)).to eq(store: false)
|
48
|
-
end
|
49
|
-
end
|
data/spec/warden/errors_spec.rb
DELETED
@@ -1,48 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
# frozen_string_literal: true
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe Warden::Proxy::Errors do
|
6
|
-
|
7
|
-
before(:each) do
|
8
|
-
@errors = Warden::Proxy::Errors.new
|
9
|
-
end
|
10
|
-
|
11
|
-
it "should report that it is empty on first creation" do
|
12
|
-
expect(@errors).to be_empty
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should continue to report that it is empty even after being checked" do
|
16
|
-
@errors.on(:foo)
|
17
|
-
expect(@errors).to be_empty
|
18
|
-
end
|
19
|
-
|
20
|
-
it "should add an error" do
|
21
|
-
@errors.add(:login, "Login or password incorrect")
|
22
|
-
expect(@errors[:login]).to eq(["Login or password incorrect"])
|
23
|
-
end
|
24
|
-
|
25
|
-
it "should allow many errors to be added to the same field" do
|
26
|
-
@errors.add(:login, "bad 1")
|
27
|
-
@errors.add(:login, "bad 2")
|
28
|
-
expect(@errors.on(:login)).to eq(["bad 1", "bad 2"])
|
29
|
-
end
|
30
|
-
|
31
|
-
it "should give the full messages for an error" do
|
32
|
-
@errors.add(:login, "login wrong")
|
33
|
-
@errors.add(:password, "password wrong")
|
34
|
-
["password wrong", "login wrong"].each do |msg|
|
35
|
-
expect(@errors.full_messages).to include(msg)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
it "should return the error for a specific field / label" do
|
40
|
-
@errors.add(:login, "wrong")
|
41
|
-
expect(@errors.on(:login)).to eq(["wrong"])
|
42
|
-
end
|
43
|
-
|
44
|
-
it "should return nil for a specific field if it's not been set" do
|
45
|
-
expect(@errors.on(:not_there)).to be_nil
|
46
|
-
end
|
47
|
-
|
48
|
-
end
|
data/spec/warden/hooks_spec.rb
DELETED
@@ -1,374 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
# frozen_string_literal: true
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe "standard authentication hooks" do
|
6
|
-
|
7
|
-
before(:all) do
|
8
|
-
load_strategies
|
9
|
-
end
|
10
|
-
|
11
|
-
describe "after_set_user" do
|
12
|
-
before(:each) do
|
13
|
-
RAM = Warden::Manager unless defined?(RAM)
|
14
|
-
RAM._after_set_user.clear
|
15
|
-
end
|
16
|
-
|
17
|
-
after(:each) do
|
18
|
-
RAM._after_set_user.clear
|
19
|
-
end
|
20
|
-
|
21
|
-
it "should allow me to add an after_set_user hook" do
|
22
|
-
RAM.after_set_user do |user, auth, opts|
|
23
|
-
"boo"
|
24
|
-
end
|
25
|
-
expect(RAM._after_set_user.length).to eq(1)
|
26
|
-
end
|
27
|
-
|
28
|
-
it "should allow me to add multiple after_set_user hooks" do
|
29
|
-
RAM.after_set_user{|user, auth, opts| "foo"}
|
30
|
-
RAM.after_set_user{|u,a| "bar"}
|
31
|
-
expect(RAM._after_set_user.length).to eq(2)
|
32
|
-
end
|
33
|
-
|
34
|
-
it "should run each after_set_user hook after the user is set" do
|
35
|
-
RAM.after_set_user{|u,a,o| a.env['warden.spec.hook.foo'] = "run foo"}
|
36
|
-
RAM.after_set_user{|u,a,o| a.env['warden.spec.hook.bar'] = "run bar"}
|
37
|
-
RAM.after_set_user{|u,a,o| a.logout}
|
38
|
-
app = lambda do |e|
|
39
|
-
e['warden'].set_user("foo")
|
40
|
-
valid_response
|
41
|
-
end
|
42
|
-
env = env_with_params
|
43
|
-
setup_rack(app).call(env)
|
44
|
-
expect(env['warden'].user).to be_nil
|
45
|
-
expect(env['warden.spec.hook.foo']).to eq("run foo")
|
46
|
-
expect(env['warden.spec.hook.bar']).to eq("run bar")
|
47
|
-
end
|
48
|
-
|
49
|
-
it "should not run the event specified with except" do
|
50
|
-
RAM.after_set_user(:except => :set_user){|u,a,o| fail}
|
51
|
-
app = lambda do |e|
|
52
|
-
e['warden'].set_user("foo")
|
53
|
-
valid_response
|
54
|
-
end
|
55
|
-
env = env_with_params
|
56
|
-
setup_rack(app).call(env)
|
57
|
-
end
|
58
|
-
|
59
|
-
it "should only run the event specified with only" do
|
60
|
-
RAM.after_set_user(:only => :set_user){|u,a,o| fail}
|
61
|
-
app = lambda do |e|
|
62
|
-
e['warden'].authenticate(:pass)
|
63
|
-
valid_response
|
64
|
-
end
|
65
|
-
env = env_with_params
|
66
|
-
setup_rack(app).call(env)
|
67
|
-
end
|
68
|
-
|
69
|
-
it "should run filters in the given order" do
|
70
|
-
RAM.after_set_user{|u,a,o| a.env['warden.spec.order'] << 2}
|
71
|
-
RAM.after_set_user{|u,a,o| a.env['warden.spec.order'] << 3}
|
72
|
-
RAM.prepend_after_set_user{|u,a,o| a.env['warden.spec.order'] << 1}
|
73
|
-
app = lambda do |e|
|
74
|
-
e['warden.spec.order'] = []
|
75
|
-
e['warden'].set_user("foo")
|
76
|
-
valid_response
|
77
|
-
end
|
78
|
-
env = env_with_params
|
79
|
-
setup_rack(app).call(env)
|
80
|
-
expect(env['warden.spec.order']).to eq([1,2,3])
|
81
|
-
end
|
82
|
-
|
83
|
-
context "after_authentication" do
|
84
|
-
it "should be a wrapper to after_set_user behavior" do
|
85
|
-
RAM.after_authentication{|u,a,o| a.env['warden.spec.hook.baz'] = "run baz"}
|
86
|
-
RAM.after_authentication{|u,a,o| a.env['warden.spec.hook.paz'] = "run paz"}
|
87
|
-
RAM.after_authentication{|u,a,o| expect(o[:event]).to eq(:authentication) }
|
88
|
-
app = lambda do |e|
|
89
|
-
e['warden'].authenticate(:pass)
|
90
|
-
valid_response
|
91
|
-
end
|
92
|
-
env = env_with_params
|
93
|
-
setup_rack(app).call(env)
|
94
|
-
expect(env['warden.spec.hook.baz']).to eq('run baz')
|
95
|
-
expect(env['warden.spec.hook.paz']).to eq('run paz')
|
96
|
-
end
|
97
|
-
|
98
|
-
it "should not be invoked on default after_set_user scenario" do
|
99
|
-
RAM.after_authentication{|u,a,o| fail}
|
100
|
-
app = lambda do |e|
|
101
|
-
e['warden'].set_user("foo")
|
102
|
-
valid_response
|
103
|
-
end
|
104
|
-
env = env_with_params
|
105
|
-
setup_rack(app).call(env)
|
106
|
-
end
|
107
|
-
|
108
|
-
it "should run filters in the given order" do
|
109
|
-
RAM.after_authentication{|u,a,o| a.env['warden.spec.order'] << 2}
|
110
|
-
RAM.after_authentication{|u,a,o| a.env['warden.spec.order'] << 3}
|
111
|
-
RAM.prepend_after_authentication{|u,a,o| a.env['warden.spec.order'] << 1}
|
112
|
-
app = lambda do |e|
|
113
|
-
e['warden.spec.order'] = []
|
114
|
-
e['warden'].authenticate(:pass)
|
115
|
-
valid_response
|
116
|
-
end
|
117
|
-
env = env_with_params
|
118
|
-
setup_rack(app).call(env)
|
119
|
-
expect(env['warden.spec.order']).to eq([1,2,3])
|
120
|
-
end
|
121
|
-
|
122
|
-
it "should allow me to log out a user in an after_set_user block" do
|
123
|
-
RAM.after_set_user{|u,a,o| a.logout}
|
124
|
-
|
125
|
-
app = lambda do |e|
|
126
|
-
e['warden'].authenticate(:pass)
|
127
|
-
valid_response
|
128
|
-
end
|
129
|
-
env = env_with_params
|
130
|
-
setup_rack(app).call(env)
|
131
|
-
expect(env['warden']).not_to be_authenticated
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
context "after_fetch" do
|
136
|
-
it "should be a wrapper to after_set_user behavior" do
|
137
|
-
RAM.after_fetch{|u,a,o| a.env['warden.spec.hook.baz'] = "run baz"}
|
138
|
-
RAM.after_fetch{|u,a,o| a.env['warden.spec.hook.paz'] = "run paz"}
|
139
|
-
RAM.after_fetch{|u,a,o| expect(o[:event]).to eq(:fetch) }
|
140
|
-
env = env_with_params
|
141
|
-
setup_rack(lambda { |e| valid_response }).call(env)
|
142
|
-
env['rack.session']['warden.user.default.key'] = "Foo"
|
143
|
-
expect(env['warden'].user).to eq("Foo")
|
144
|
-
expect(env['warden.spec.hook.baz']).to eq('run baz')
|
145
|
-
expect(env['warden.spec.hook.paz']).to eq('run paz')
|
146
|
-
end
|
147
|
-
|
148
|
-
it "should not be invoked on default after_set_user scenario" do
|
149
|
-
RAM.after_fetch{|u,a,o| fail}
|
150
|
-
app = lambda do |e|
|
151
|
-
e['warden'].set_user("foo")
|
152
|
-
valid_response
|
153
|
-
end
|
154
|
-
env = env_with_params
|
155
|
-
setup_rack(app).call(env)
|
156
|
-
end
|
157
|
-
|
158
|
-
it "should not be invoked if fetched user is nil" do
|
159
|
-
RAM.after_fetch{|u,a,o| fail}
|
160
|
-
env = env_with_params
|
161
|
-
setup_rack(lambda { |e| valid_response }).call(env)
|
162
|
-
env['rack.session']['warden.user.default.key'] = nil
|
163
|
-
expect(env['warden'].user).to be_nil
|
164
|
-
end
|
165
|
-
|
166
|
-
it "should run filters in the given order" do
|
167
|
-
RAM.after_fetch{|u,a,o| a.env['warden.spec.order'] << 2}
|
168
|
-
RAM.after_fetch{|u,a,o| a.env['warden.spec.order'] << 3}
|
169
|
-
RAM.prepend_after_fetch{|u,a,o| a.env['warden.spec.order'] << 1}
|
170
|
-
app = lambda do |e|
|
171
|
-
e['warden.spec.order'] = []
|
172
|
-
e['rack.session']['warden.user.default.key'] = "Foo"
|
173
|
-
e['warden'].user
|
174
|
-
valid_response
|
175
|
-
end
|
176
|
-
env = env_with_params
|
177
|
-
setup_rack(app).call(env)
|
178
|
-
expect(env['warden.spec.order']).to eq([1,2,3])
|
179
|
-
end
|
180
|
-
end
|
181
|
-
end
|
182
|
-
|
183
|
-
|
184
|
-
describe "after_failed_fetch" do
|
185
|
-
before(:each) do
|
186
|
-
RAM = Warden::Manager unless defined?(RAM)
|
187
|
-
RAM._after_failed_fetch.clear
|
188
|
-
end
|
189
|
-
|
190
|
-
after(:each) do
|
191
|
-
RAM._after_failed_fetch.clear
|
192
|
-
end
|
193
|
-
|
194
|
-
it "should not be called when user is fetched" do
|
195
|
-
RAM.after_failed_fetch{|u,a,o| fail }
|
196
|
-
env = env_with_params
|
197
|
-
setup_rack(lambda { |e| valid_response }).call(env)
|
198
|
-
env['rack.session']['warden.user.default.key'] = "Foo"
|
199
|
-
expect(env['warden'].user).to eq("Foo")
|
200
|
-
end
|
201
|
-
|
202
|
-
it "should be called if fetched user is nil" do
|
203
|
-
calls = 0
|
204
|
-
RAM.after_failed_fetch{|u,a,o| calls += 1 }
|
205
|
-
env = env_with_params
|
206
|
-
setup_rack(lambda { |e| valid_response }).call(env)
|
207
|
-
expect(env['warden'].user).to be_nil
|
208
|
-
expect(calls).to eq(1)
|
209
|
-
end
|
210
|
-
end
|
211
|
-
|
212
|
-
describe "before_failure" do
|
213
|
-
before(:each) do
|
214
|
-
RAM = Warden::Manager unless defined?(RAM)
|
215
|
-
RAM._before_failure.clear
|
216
|
-
end
|
217
|
-
|
218
|
-
after(:each) do
|
219
|
-
RAM._before_failure.clear
|
220
|
-
end
|
221
|
-
|
222
|
-
it "should allow me to add a before_failure hook" do
|
223
|
-
RAM.before_failure{|env, opts| "foo"}
|
224
|
-
expect(RAM._before_failure.length).to eq(1)
|
225
|
-
end
|
226
|
-
|
227
|
-
it "should allow me to add multiple before_failure hooks" do
|
228
|
-
RAM.before_failure{|env, opts| "foo"}
|
229
|
-
RAM.before_failure{|env, opts| "bar"}
|
230
|
-
expect(RAM._before_failure.length).to eq(2)
|
231
|
-
end
|
232
|
-
|
233
|
-
it "should run each before_failure hooks before failing" do
|
234
|
-
RAM.before_failure{|e,o| e['warden.spec.before_failure.foo'] = "foo"}
|
235
|
-
RAM.before_failure{|e,o| e['warden.spec.before_failure.bar'] = "bar"}
|
236
|
-
app = lambda{|e| e['warden'].authenticate!(:failz); valid_response}
|
237
|
-
env = env_with_params
|
238
|
-
setup_rack(app).call(env)
|
239
|
-
expect(env['warden.spec.before_failure.foo']).to eq("foo")
|
240
|
-
expect(env['warden.spec.before_failure.bar']).to eq("bar")
|
241
|
-
end
|
242
|
-
|
243
|
-
it "should run filters in the given order" do
|
244
|
-
RAM.before_failure{|e,o| e['warden.spec.order'] << 2}
|
245
|
-
RAM.before_failure{|e,o| e['warden.spec.order'] << 3}
|
246
|
-
RAM.prepend_before_failure{|e,o| e['warden.spec.order'] << 1}
|
247
|
-
app = lambda do |e|
|
248
|
-
e['warden.spec.order'] = []
|
249
|
-
e['warden'].authenticate!(:failz)
|
250
|
-
valid_response
|
251
|
-
end
|
252
|
-
env = env_with_params
|
253
|
-
setup_rack(app).call(env)
|
254
|
-
expect(env['warden.spec.order']).to eq([1,2,3])
|
255
|
-
end
|
256
|
-
end
|
257
|
-
|
258
|
-
describe "before_logout" do
|
259
|
-
before(:each) do
|
260
|
-
RAM = Warden::Manager unless defined?(RAM)
|
261
|
-
RAM._before_logout.clear
|
262
|
-
end
|
263
|
-
|
264
|
-
after(:each) do
|
265
|
-
RAM._before_logout.clear
|
266
|
-
end
|
267
|
-
|
268
|
-
it "should allow me to add an before_logout hook" do
|
269
|
-
RAM.before_logout{|user, auth, scopes| "foo"}
|
270
|
-
expect(RAM._before_logout.length).to eq(1)
|
271
|
-
end
|
272
|
-
|
273
|
-
it "should allow me to add multiple after_authentication hooks" do
|
274
|
-
RAM.before_logout{|u,a,o| "bar"}
|
275
|
-
RAM.before_logout{|u,a,o| "baz"}
|
276
|
-
expect(RAM._before_logout.length).to eq(2)
|
277
|
-
end
|
278
|
-
|
279
|
-
it "should run each before_logout hook before logout is run" do
|
280
|
-
RAM.before_logout{|u,a,o| a.env['warden.spec.hook.lorem'] = "run lorem"}
|
281
|
-
RAM.before_logout{|u,a,o| a.env['warden.spec.hook.ipsum'] = "run ipsum"}
|
282
|
-
app = lambda{|e| e['warden'].authenticate(:pass); valid_response}
|
283
|
-
env = env_with_params
|
284
|
-
setup_rack(app).call(env)
|
285
|
-
env['warden'].logout
|
286
|
-
expect(env['warden.spec.hook.lorem']).to eq('run lorem')
|
287
|
-
expect(env['warden.spec.hook.ipsum']).to eq('run ipsum')
|
288
|
-
end
|
289
|
-
|
290
|
-
it "should run before_logout hook for a specified scope" do
|
291
|
-
RAM.before_logout(:scope => :scope1){|u,a,o| a.env["warden.spec.hook.a"] << :scope1 }
|
292
|
-
RAM.before_logout(:scope => [:scope2]){|u,a,o| a.env["warden.spec.hook.b"] << :scope2 }
|
293
|
-
|
294
|
-
app = lambda do |e|
|
295
|
-
e['warden'].authenticate(:pass, :scope => :scope1)
|
296
|
-
e['warden'].authenticate(:pass, :scope => :scope2)
|
297
|
-
valid_response
|
298
|
-
end
|
299
|
-
env = env_with_params
|
300
|
-
env["warden.spec.hook.a"] ||= []
|
301
|
-
env["warden.spec.hook.b"] ||= []
|
302
|
-
setup_rack(app).call(env)
|
303
|
-
|
304
|
-
env['warden'].logout(:scope1)
|
305
|
-
expect(env['warden.spec.hook.a']).to eq([:scope1])
|
306
|
-
expect(env['warden.spec.hook.b']).to eq([])
|
307
|
-
|
308
|
-
env['warden'].logout(:scope2)
|
309
|
-
expect(env['warden.spec.hook.a']).to eq([:scope1])
|
310
|
-
expect(env['warden.spec.hook.b']).to eq([:scope2])
|
311
|
-
end
|
312
|
-
|
313
|
-
it "should run filters in the given order" do
|
314
|
-
RAM.before_logout{|u,a,o| a.env['warden.spec.order'] << 2}
|
315
|
-
RAM.before_logout{|u,a,o| a.env['warden.spec.order'] << 3}
|
316
|
-
RAM.prepend_before_logout{|u,a,o| a.env['warden.spec.order'] << 1}
|
317
|
-
app = lambda do |e|
|
318
|
-
e['warden.spec.order'] = []
|
319
|
-
e['warden'].authenticate(:pass)
|
320
|
-
e['warden'].logout
|
321
|
-
valid_response
|
322
|
-
end
|
323
|
-
env = env_with_params
|
324
|
-
setup_rack(app).call(env)
|
325
|
-
expect(env['warden.spec.order']).to eq([1,2,3])
|
326
|
-
end
|
327
|
-
end
|
328
|
-
|
329
|
-
describe "on_request" do
|
330
|
-
before(:each) do
|
331
|
-
RAM = Warden::Manager unless defined?(RAM)
|
332
|
-
@old_on_request = RAM._on_request.dup
|
333
|
-
RAM._on_request.clear
|
334
|
-
end
|
335
|
-
|
336
|
-
after(:each) do
|
337
|
-
RAM._on_request.clear
|
338
|
-
RAM._on_request.replace(@old_on_request)
|
339
|
-
end
|
340
|
-
|
341
|
-
it "should allow me to add an on_request hook" do
|
342
|
-
RAM.on_request{|proxy| "foo"}
|
343
|
-
expect(RAM._on_request.length).to eq(1)
|
344
|
-
end
|
345
|
-
|
346
|
-
it "should allow me to add multiple on_request hooks" do
|
347
|
-
RAM.on_request{|proxy| "foo"}
|
348
|
-
RAM.on_request{|proxy| "bar"}
|
349
|
-
expect(RAM._on_request.length).to eq(2)
|
350
|
-
end
|
351
|
-
|
352
|
-
it "should run each on_request hooks when initializing" do
|
353
|
-
RAM.on_request{|proxy| proxy.env['warden.spec.on_request.foo'] = "foo"}
|
354
|
-
RAM.on_request{|proxy| proxy.env['warden.spec.on_request.bar'] = "bar"}
|
355
|
-
app = lambda{|e| valid_response}
|
356
|
-
env = env_with_params
|
357
|
-
setup_rack(app).call(env)
|
358
|
-
expect(env['warden.spec.on_request.foo']).to eq("foo")
|
359
|
-
expect(env['warden.spec.on_request.bar']).to eq("bar")
|
360
|
-
end
|
361
|
-
|
362
|
-
it "should run filters in the given order" do
|
363
|
-
RAM.on_request{|proxy| proxy.env['warden.spec.order'] << 2}
|
364
|
-
RAM.on_request{|proxy| proxy.env['warden.spec.order'] << 3}
|
365
|
-
RAM.prepend_on_request{|proxy| proxy.env['warden.spec.order'] << 1}
|
366
|
-
app = lambda do |e|
|
367
|
-
valid_response
|
368
|
-
end
|
369
|
-
env = Rack::MockRequest.env_for("/", "warden.spec.order" => [])
|
370
|
-
setup_rack(app).call(env)
|
371
|
-
expect(env['warden.spec.order']).to eq([1,2,3])
|
372
|
-
end
|
373
|
-
end
|
374
|
-
end
|