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
@@ -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
|
@@ -1,76 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
# frozen_string_literal: true
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe Warden::Test::WardenHelpers do
|
6
|
-
before :all do
|
7
|
-
Warden.test_mode!
|
8
|
-
end
|
9
|
-
|
10
|
-
before do
|
11
|
-
$captures = []
|
12
|
-
@app = lambda{|e| valid_response }
|
13
|
-
end
|
14
|
-
|
15
|
-
after do
|
16
|
-
Warden.test_reset!
|
17
|
-
end
|
18
|
-
|
19
|
-
it{ expect(Warden).to respond_to(:test_mode!) }
|
20
|
-
it{ expect(Warden).to respond_to(:on_next_request) }
|
21
|
-
it{ expect(Warden).to respond_to(:test_reset!) }
|
22
|
-
|
23
|
-
it "should execute the on_next_request block on the next request" do
|
24
|
-
Warden.on_next_request do |warden|
|
25
|
-
$captures << warden
|
26
|
-
end
|
27
|
-
|
28
|
-
setup_rack(@app).call(env_with_params)
|
29
|
-
expect($captures.length).to eq(1)
|
30
|
-
expect($captures.first).to be_an_instance_of(Warden::Proxy)
|
31
|
-
end
|
32
|
-
|
33
|
-
it "should execute many on_next_request blocks on the next request" do
|
34
|
-
Warden.on_next_request{|w| $captures << :first }
|
35
|
-
Warden.on_next_request{|w| $captures << :second }
|
36
|
-
setup_rack(@app).call(env_with_params)
|
37
|
-
expect($captures).to eq([:first, :second])
|
38
|
-
end
|
39
|
-
|
40
|
-
it "should not execute on_next_request blocks on subsequent requests" do
|
41
|
-
app = setup_rack(@app)
|
42
|
-
Warden.on_next_request{|w| $captures << :first }
|
43
|
-
app.call(env_with_params)
|
44
|
-
expect($captures).to eq([:first])
|
45
|
-
$captures.clear
|
46
|
-
app.call(env_with_params)
|
47
|
-
expect($captures).to be_empty
|
48
|
-
end
|
49
|
-
|
50
|
-
it "should allow me to set new_on_next_request items to execute in the same test" do
|
51
|
-
app = setup_rack(@app)
|
52
|
-
Warden.on_next_request{|w| $captures << :first }
|
53
|
-
app.call(env_with_params)
|
54
|
-
expect($captures).to eq([:first])
|
55
|
-
Warden.on_next_request{|w| $captures << :second }
|
56
|
-
app.call(env_with_params)
|
57
|
-
expect($captures).to eq([:first, :second])
|
58
|
-
end
|
59
|
-
|
60
|
-
it "should remove the on_next_request items when test is reset" do
|
61
|
-
app = setup_rack(@app)
|
62
|
-
Warden.on_next_request{|w| $captures << :first }
|
63
|
-
Warden.test_reset!
|
64
|
-
app.call(env_with_params)
|
65
|
-
expect($captures).to eq([])
|
66
|
-
end
|
67
|
-
|
68
|
-
context "asset requests" do
|
69
|
-
it "should not execute on_next_request blocks if this is an asset request" do
|
70
|
-
app = setup_rack(@app)
|
71
|
-
Warden.on_next_request{|w| $captures << :first }
|
72
|
-
app.call(env_with_params("/assets/fun.gif"))
|
73
|
-
expect($captures).to eq([])
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|