warden 1.2.5 → 1.2.8

Sign up to get free protection for your applications and to get access to all the features.
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} +13 -3
  6. data/Gemfile +2 -1
  7. data/Gemfile.lock +40 -0
  8. data/LICENSE +1 -1
  9. data/README.md +18 -0
  10. data/Rakefile +4 -8
  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 +15 -3
  17. data/lib/warden/session_serializer.rb +1 -0
  18. data/lib/warden/strategies/base.rb +2 -1
  19. data/lib/warden/strategies.rb +1 -0
  20. data/lib/warden/test/helpers.rb +2 -56
  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/lib/warden.rb +2 -0
  25. data/warden.gemspec +21 -18
  26. metadata +19 -33
  27. data/README.textile +0 -9
  28. data/spec/helpers/request_helper.rb +0 -51
  29. data/spec/helpers/strategies/fail_with_user.rb +0 -10
  30. data/spec/helpers/strategies/failz.rb +0 -8
  31. data/spec/helpers/strategies/invalid.rb +0 -8
  32. data/spec/helpers/strategies/pass.rb +0 -8
  33. data/spec/helpers/strategies/pass_with_message.rb +0 -8
  34. data/spec/helpers/strategies/password.rb +0 -13
  35. data/spec/helpers/strategies/single.rb +0 -12
  36. data/spec/spec_helper.rb +0 -24
  37. data/spec/warden/authenticated_data_store_spec.rb +0 -114
  38. data/spec/warden/config_spec.rb +0 -48
  39. data/spec/warden/errors_spec.rb +0 -47
  40. data/spec/warden/hooks_spec.rb +0 -373
  41. data/spec/warden/manager_spec.rb +0 -340
  42. data/spec/warden/proxy_spec.rb +0 -1050
  43. data/spec/warden/scoped_session_serializer.rb +0 -123
  44. data/spec/warden/session_serializer_spec.rb +0 -53
  45. data/spec/warden/strategies/base_spec.rb +0 -313
  46. data/spec/warden/strategies_spec.rb +0 -94
  47. data/spec/warden/test/helpers_spec.rb +0 -101
  48. data/spec/warden/test/test_mode_spec.rb +0 -75
@@ -1,51 +0,0 @@
1
- # encoding: utf-8
2
- module Warden::Spec
3
- module Helpers
4
- FAILURE_APP = lambda{|e|[401, {"Content-Type" => "text/plain"}, ["You Fail!"]] }
5
-
6
- def env_with_params(path = "/", params = {}, env = {})
7
- method = params.delete(:method) || "GET"
8
- env = { 'HTTP_VERSION' => '1.1', 'REQUEST_METHOD' => "#{method}" }.merge(env)
9
- Rack::MockRequest.env_for("#{path}?#{Rack::Utils.build_query(params)}", env)
10
- end
11
-
12
- def setup_rack(app = nil, opts = {}, &block)
13
- app ||= block if block_given?
14
-
15
- opts[:failure_app] ||= failure_app
16
- opts[:default_strategies] ||= [:password]
17
- opts[:default_serializers] ||= [:session]
18
- blk = opts[:configurator] || proc{}
19
-
20
- Rack::Builder.new do
21
- use opts[:session] || Warden::Spec::Helpers::Session unless opts[:nil_session]
22
- use Warden::Manager, opts, &blk
23
- run app
24
- end
25
- end
26
-
27
- def valid_response
28
- Rack::Response.new("OK").finish
29
- end
30
-
31
- def failure_app
32
- Warden::Spec::Helpers::FAILURE_APP
33
- end
34
-
35
- def success_app
36
- lambda{|e| [200, {"Content-Type" => "text/plain"}, ["You Win"]]}
37
- end
38
-
39
- class Session
40
- attr_accessor :app
41
- def initialize(app,configs = {})
42
- @app = app
43
- end
44
-
45
- def call(e)
46
- e['rack.session'] ||= {}
47
- @app.call(e)
48
- end
49
- end # session
50
- end
51
- end
@@ -1,10 +0,0 @@
1
- # encoding: utf-8
2
- Warden::Strategies.add(:fail_with_user) do
3
- def authenticate!
4
- request.env['warden.spec.strategies'] ||= []
5
- request.env['warden.spec.strategies'] << :fail_with_user
6
- self.user = 'Valid User'
7
- fail!
8
- end
9
- end
10
-
@@ -1,8 +0,0 @@
1
- # encoding: utf-8
2
- Warden::Strategies.add(:failz) do
3
- def authenticate!
4
- request.env['warden.spec.strategies'] ||= []
5
- request.env['warden.spec.strategies'] << :failz
6
- fail!("The Fails Strategy Has Failed You")
7
- end
8
- end
@@ -1,8 +0,0 @@
1
- # encoding: utf-8
2
- Warden::Strategies.add(:invalid) do
3
- def valid?
4
- false
5
- end
6
-
7
- def authenticate!; end
8
- end
@@ -1,8 +0,0 @@
1
- # encoding: utf-8
2
- Warden::Strategies.add(:pass) do
3
- def authenticate!
4
- request.env['warden.spec.strategies'] ||= []
5
- request.env['warden.spec.strategies'] << :pass
6
- success!("Valid User") unless scope == :failz
7
- end
8
- end
@@ -1,8 +0,0 @@
1
- # encoding: utf-8
2
- Warden::Strategies.add(:pass_with_message) do
3
- def authenticate!
4
- request.env['warden.spec.strategies'] ||= []
5
- request.env['warden.spec.strategies'] << :pass_with_message
6
- success!("Valid User", "The Success Strategy Has Accepted You") unless scope == :failz
7
- end
8
- end
@@ -1,13 +0,0 @@
1
- # encoding: utf-8
2
- Warden::Strategies.add(:password) do
3
- def authenticate!
4
- request.env['warden.spec.strategies'] ||= []
5
- request.env['warden.spec.strategies'] << :password
6
- if params["password"] || params["username"]
7
- params["password"] == "sekrit" && params["username"] == "fred" ?
8
- success!("Authenticated User") : fail!("Username or password is incorrect")
9
- else
10
- pass
11
- end
12
- end
13
- end
@@ -1,12 +0,0 @@
1
- # encoding: utf-8
2
- Warden::Strategies.add(:single) do
3
- def authenticate!
4
- request.env['warden.spec.strategies'] ||= []
5
- request.env['warden.spec.strategies'] << :single
6
- success!("Valid User")
7
- end
8
-
9
- def store?
10
- false
11
- end
12
- end
data/spec/spec_helper.rb DELETED
@@ -1,24 +0,0 @@
1
- # encoding: utf-8
2
- $TESTING=true
3
-
4
- $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
5
- $:.unshift File.expand_path(File.join(File.dirname(__FILE__)))
6
- require 'warden'
7
-
8
- require 'rubygems'
9
- require 'rack'
10
-
11
- Dir[File.join(File.dirname(__FILE__), "helpers", "**/*.rb")].each do |f|
12
- require f
13
- end
14
-
15
- RSpec.configure do |config|
16
- config.include(Warden::Spec::Helpers)
17
- config.include(Warden::Test::Helpers)
18
-
19
- def load_strategies
20
- Dir[File.join(File.dirname(__FILE__), "helpers", "strategies", "**/*.rb")].each do |f|
21
- load f
22
- end
23
- end
24
- end
@@ -1,114 +0,0 @@
1
- # encoding: utf-8
2
- require 'spec_helper'
3
-
4
- describe "authenticated data store" do
5
-
6
- before(:each) do
7
- @env = env_with_params
8
- @env['rack.session'] = {
9
- "warden.user.foo.key" => "foo user",
10
- "warden.user.default.key" => "default user",
11
- :foo => "bar"
12
- }
13
- end
14
-
15
- it "should store data for the default scope" do
16
- app = lambda do |e|
17
- e['warden'].authenticate(:pass)
18
- e['warden'].authenticate(:pass, :scope => :foo)
19
- expect(e['warden']).to be_authenticated
20
- expect(e['warden']).to be_authenticated(:foo)
21
-
22
- # Store the data for :default
23
- e['warden'].session[:key] = "value"
24
- valid_response
25
- end
26
- setup_rack(app).call(@env)
27
- expect(@env['rack.session']['warden.user.default.session']).to eq(key: "value")
28
- expect(@env['rack.session']['warden.user.foo.session']).to be_nil
29
- end
30
-
31
- it "should store data for the foo user" do
32
- app = lambda do |e|
33
- e['warden'].session(:foo)[:key] = "value"
34
- valid_response
35
- end
36
- setup_rack(app).call(@env)
37
- expect(@env['rack.session']['warden.user.foo.session']).to eq(key: "value")
38
- end
39
-
40
- it "should store the data separately" do
41
- app = lambda do |e|
42
- e['warden'].session[:key] = "value"
43
- e['warden'].session(:foo)[:key] = "another value"
44
- valid_response
45
- end
46
- setup_rack(app).call(@env)
47
- expect(@env['rack.session']['warden.user.default.session']).to eq(key: "value")
48
- expect(@env['rack.session']['warden.user.foo.session' ]).to eq(key: "another value")
49
- end
50
-
51
- it "should clear the foo scoped data when foo logs out" do
52
- app = lambda do |e|
53
- e['warden'].session[:key] = "value"
54
- e['warden'].session(:foo)[:key] = "another value"
55
- e['warden'].logout(:foo)
56
- valid_response
57
- end
58
- setup_rack(app).call(@env)
59
- expect(@env['rack.session']['warden.user.default.session']).to eq(key: "value")
60
- expect(@env['rack.session']['warden.user.foo.session' ]).to be_nil
61
- end
62
-
63
- it "should clear out the default data when :default logs out" do
64
- app = lambda do |e|
65
- e['warden'].session[:key] = "value"
66
- e['warden'].session(:foo)[:key] = "another value"
67
- e['warden'].logout(:default)
68
- valid_response
69
- end
70
- setup_rack(app).call(@env)
71
- expect(@env['rack.session']['warden.user.default.session']).to be_nil
72
- expect(@env['rack.session']['warden.user.foo.session' ]).to eq(key: "another value")
73
- end
74
-
75
- it "should clear out all data when a general logout is performed" do
76
- app = lambda do |e|
77
- e['warden'].session[:key] = "value"
78
- e['warden'].session(:foo)[:key] = "another value"
79
- e['warden'].logout
80
- valid_response
81
- end
82
- setup_rack(app).call(@env)
83
- expect(@env['rack.session']['warden.user.default.session']).to be_nil
84
- expect(@env['rack.session']['warden.user.foo.session' ]).to be_nil
85
- end
86
-
87
- it "should logout multiple persons at once" do
88
- @env['rack.session']['warden.user.bar.key'] = "bar user"
89
-
90
- app = lambda do |e|
91
- e['warden'].session[:key] = "value"
92
- e['warden'].session(:foo)[:key] = "another value"
93
- e['warden'].session(:bar)[:key] = "yet another"
94
- e['warden'].logout(:bar, :default)
95
- valid_response
96
- end
97
- setup_rack(app).call(@env)
98
- expect(@env['rack.session']['warden.user.default.session']).to be_nil
99
- expect(@env['rack.session']['warden.user.foo.session' ]).to eq(key: "another value")
100
- expect(@env['rack.session']['warden.user.bar.session' ]).to be_nil
101
- end
102
-
103
- it "should not store data for a user who is not logged in" do
104
- @env['rack.session']
105
- app = lambda do |e|
106
- e['warden'].session(:not_here)[:key] = "value"
107
- valid_response
108
- end
109
-
110
- expect {
111
- setup_rack(app).call(@env)
112
- }.to raise_error(Warden::NotAuthenticated)
113
- end
114
- end
@@ -1,48 +0,0 @@
1
- # encoding: utf-8
2
- require 'spec_helper'
3
-
4
- describe Warden::Config do
5
-
6
- before(:each) do
7
- @config = Warden::Config.new
8
- end
9
-
10
- it "should behave like a hash" do
11
- @config[:foo] = :bar
12
- expect(@config[:foo]).to eq(:bar)
13
- end
14
-
15
- it "should provide hash accessors" do
16
- @config.failure_app = :foo
17
- expect(@config[:failure_app]).to eq(:foo)
18
- @config[:failure_app] = :bar
19
- expect(@config.failure_app).to eq(:bar)
20
- end
21
-
22
- it "should allow to read and set default strategies" do
23
- @config.default_strategies :foo, :bar
24
- expect(@config.default_strategies).to eq([:foo, :bar])
25
- end
26
-
27
- it "should allow to silence missing strategies" do
28
- @config.silence_missing_strategies!
29
- expect(@config.silence_missing_strategies?).to eq(true)
30
- end
31
-
32
- it "should set the default_scope" do
33
- expect(@config.default_scope).to eq(:default)
34
- @config.default_scope = :foo
35
- expect(@config.default_scope).to eq(:foo)
36
- end
37
-
38
- it "should merge given options on initialization" do
39
- expect(Warden::Config.new(:foo => :bar)[:foo]).to eq(:bar)
40
- end
41
-
42
- it "should setup defaults with the scope_defaults method" do
43
- c = Warden::Config.new
44
- c.scope_defaults :foo, :strategies => [:foo, :bar], :store => false
45
- expect(c.default_strategies(:scope => :foo)).to eq([:foo, :bar])
46
- expect(c.scope_defaults(:foo)).to eq(store: false)
47
- end
48
- end
@@ -1,47 +0,0 @@
1
- # encoding: utf-8
2
- require 'spec_helper'
3
-
4
- describe Warden::Proxy::Errors do
5
-
6
- before(:each) do
7
- @errors = Warden::Proxy::Errors.new
8
- end
9
-
10
- it "should report that it is empty on first creation" do
11
- expect(@errors).to be_empty
12
- end
13
-
14
- it "should continue to report that it is empty even after being checked" do
15
- @errors.on(:foo)
16
- expect(@errors).to be_empty
17
- end
18
-
19
- it "should add an error" do
20
- @errors.add(:login, "Login or password incorrect")
21
- expect(@errors[:login]).to eq(["Login or password incorrect"])
22
- end
23
-
24
- it "should allow many errors to be added to the same field" do
25
- @errors.add(:login, "bad 1")
26
- @errors.add(:login, "bad 2")
27
- expect(@errors.on(:login)).to eq(["bad 1", "bad 2"])
28
- end
29
-
30
- it "should give the full messages for an error" do
31
- @errors.add(:login, "login wrong")
32
- @errors.add(:password, "password wrong")
33
- ["password wrong", "login wrong"].each do |msg|
34
- expect(@errors.full_messages).to include(msg)
35
- end
36
- end
37
-
38
- it "should return the error for a specific field / label" do
39
- @errors.add(:login, "wrong")
40
- expect(@errors.on(:login)).to eq(["wrong"])
41
- end
42
-
43
- it "should return nil for a specific field if it's not been set" do
44
- expect(@errors.on(:not_there)).to be_nil
45
- end
46
-
47
- end