warden 0.5.3 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. data/History.rdoc +8 -5
  2. data/README.textile +1 -1
  3. data/lib/warden.rb +7 -4
  4. data/lib/warden/declarable.rb +43 -0
  5. data/lib/warden/hooks.rb +121 -0
  6. data/lib/warden/manager.rb +52 -21
  7. data/lib/warden/mixins/common.rb +11 -2
  8. data/lib/warden/proxy.rb +88 -32
  9. data/lib/warden/serializers.rb +20 -0
  10. data/lib/warden/serializers/base.rb +38 -0
  11. data/lib/warden/serializers/cookie.rb +34 -0
  12. data/lib/warden/serializers/session.rb +30 -0
  13. data/lib/warden/strategies.rb +18 -0
  14. data/lib/warden/{authentication/strategy_base.rb → strategies/base.rb} +27 -2
  15. data/lib/warden/version.rb +1 -1
  16. data/spec/helpers/request_helper.rb +14 -12
  17. data/spec/{warden → helpers}/strategies/failz.rb +0 -0
  18. data/spec/{warden → helpers}/strategies/invalid.rb +0 -0
  19. data/spec/{warden → helpers}/strategies/pass.rb +0 -0
  20. data/spec/{warden → helpers}/strategies/pass_without_user.rb +0 -0
  21. data/spec/{warden → helpers}/strategies/password.rb +0 -0
  22. data/spec/spec_helper.rb +1 -1
  23. data/spec/warden/authenticated_data_store_spec.rb +4 -4
  24. data/spec/warden/manager_spec.rb +0 -8
  25. data/spec/warden/proxy_spec.rb +61 -10
  26. data/spec/warden/serializers/cookie_spec.rb +60 -0
  27. data/spec/warden/serializers/session_spec.rb +47 -0
  28. data/spec/warden/serializers_spec.rb +96 -0
  29. data/spec/warden/{strategy_base_spec.rb → strategies/base_spec.rb} +1 -1
  30. data/spec/warden/strategies_spec.rb +19 -15
  31. data/warden.gemspec +28 -18
  32. metadata +28 -18
  33. data/VERSION +0 -1
  34. data/lib/warden/authentication/hooks.rb +0 -124
  35. data/lib/warden/authentication/strategies.rb +0 -59
@@ -0,0 +1,60 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe Warden::Serializers::Cookie do
4
+ before(:each) do
5
+ @env = env_with_params
6
+ @cookie = Warden::Serializers::Cookie.new(@env)
7
+ end
8
+
9
+ def set_cookie!
10
+ @env['HTTP_COOKIE'] = @cookie.response.headers['Set-Cookie']
11
+ end
12
+
13
+ def read_cookie
14
+ cookie = @cookie.response.headers['Set-Cookie']
15
+ cookie = cookie.first if cookie.is_a?(Array)
16
+ cookie.split(";").first
17
+ end
18
+
19
+ it "should store data for the default scope" do
20
+ @cookie.store("user", :default)
21
+ read_cookie.should == "warden.user.default.key=user"
22
+ end
23
+
24
+ it "should check if a data is stored or not" do
25
+ @cookie.should_not be_stored(:default)
26
+ @cookie.store("user", :default)
27
+ set_cookie!
28
+ @cookie.should be_stored(:default)
29
+ end
30
+
31
+ it "should load an user from store" do
32
+ @cookie.fetch(:default).should be_nil
33
+ @cookie.store("user", :default)
34
+ set_cookie!
35
+ @cookie.fetch(:default).should == "user"
36
+ end
37
+
38
+ it "should store data based on the scope" do
39
+ @cookie.store("user", :default)
40
+ set_cookie!
41
+ @cookie.fetch(:default).should == "user"
42
+ @cookie.fetch(:another).should be_nil
43
+ end
44
+
45
+ it "should delete data from store" do
46
+ @cookie.store("user", :default)
47
+ set_cookie!
48
+ @cookie.fetch(:default).should == "user"
49
+ @cookie.delete(:default)
50
+ read_cookie.should == "warden.user.default.key="
51
+ end
52
+
53
+ it "should delete information from store if user cannot be retrieved" do
54
+ @cookie.store("user", :default)
55
+ set_cookie!
56
+ @cookie.instance_eval "def deserialize(key); nil; end"
57
+ @cookie.fetch(:default)
58
+ read_cookie.should == "warden.user.default.key="
59
+ end
60
+ end
@@ -0,0 +1,47 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe Warden::Serializers::Session do
4
+ before(:each) do
5
+ @env = env_with_params
6
+ @env['rack.session'] ||= {}
7
+ @session = Warden::Serializers::Session.new(@env)
8
+ end
9
+
10
+ it "should store data for the default scope" do
11
+ @session.store("user", :default)
12
+ @env['rack.session'].should == { "warden.user.default.key"=>"user" }
13
+ end
14
+
15
+ it "should check if a data is stored or not" do
16
+ @session.should_not be_stored(:default)
17
+ @session.store("user", :default)
18
+ @session.should be_stored(:default)
19
+ end
20
+
21
+ it "should load an user from store" do
22
+ @session.fetch(:default).should be_nil
23
+ @session.store("user", :default)
24
+ @session.fetch(:default).should == "user"
25
+ end
26
+
27
+ it "should store data based on the scope" do
28
+ @session.store("user", :default)
29
+ @session.fetch(:default).should == "user"
30
+ @session.fetch(:another).should be_nil
31
+ end
32
+
33
+ it "should delete data from store" do
34
+ @session.store("user", :default)
35
+ @session.fetch(:default).should == "user"
36
+ @session.delete(:default)
37
+ @session.fetch(:default).should be_nil
38
+ end
39
+
40
+ it "should delete information from store if user cannot be retrieved" do
41
+ @session.store("user", :default)
42
+ @env['rack.session'].should have_key("warden.user.default.key")
43
+ @session.instance_eval "def deserialize(key); nil; end"
44
+ @session.fetch(:default)
45
+ @env['rack.session'].should_not have_key("warden.user.default.key")
46
+ end
47
+ end
@@ -0,0 +1,96 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe Warden::Serializers do
4
+ it "should let me add a serializer via a block" do
5
+ Warden::Serializers.add(:serializer1) do
6
+ def fetch; end
7
+ def store; end
8
+ def stored?; end
9
+ def delete; end
10
+ end
11
+ Warden::Serializers[:serializer1].ancestors.should include(Warden::Serializers::Base)
12
+ end
13
+
14
+ it "should raise an error if I add a serializer via a block, that does not have an autheniticate! method" do
15
+ lambda do
16
+ Warden::Serializers.add(:serializer2) do
17
+ end
18
+ end.should raise_error
19
+ end
20
+
21
+ it "should allow me to get access to a particular serializer" do
22
+ Warden::Serializers.add(:serializer3) do
23
+ def fetch; end
24
+ def store; end
25
+ def stored?; end
26
+ def delete; end
27
+ end
28
+ serializer = Warden::Serializers[:serializer3]
29
+ serializer.should_not be_nil
30
+ serializer.ancestors.should include(Warden::Serializers::Base)
31
+ end
32
+
33
+ it "should allow me to add a serializer with the required methods" do
34
+ class MySerializer < Warden::Serializers::Base
35
+ def fetch; end
36
+ def store; end
37
+ def stored?; end
38
+ def delete; end
39
+ end
40
+ lambda do
41
+ Warden::Serializers.add(:serializer4, MySerializer)
42
+ end.should_not raise_error
43
+ end
44
+
45
+ it "should not allow a serializer that does not have any required method" do
46
+ class MyOtherSerializer
47
+ end
48
+ lambda do
49
+ Warden::Serializers.add(:serializer5, MyOtherSerializer)
50
+ end.should raise_error
51
+ end
52
+
53
+ it "should allow me to change a class when providing a block and class" do
54
+ class MySerializer < Warden::Serializers::Base
55
+ end
56
+
57
+ Warden::Serializers.add(:foo, MySerializer) do
58
+ def fetch; end
59
+ def store; end
60
+ def stored?; end
61
+ def delete; end
62
+ end
63
+
64
+ Warden::Serializers[:foo].ancestors.should include(MySerializer)
65
+ end
66
+
67
+ it "should allow me to update a previously given serializer" do
68
+ class MySerializer < Warden::Serializers::Base
69
+ def fetch; end
70
+ def store; end
71
+ def stored?; end
72
+ def delete; end
73
+ end
74
+
75
+ Warden::Serializers.add(:serializer6, MySerializer)
76
+
77
+ new_module = Module.new
78
+ Warden::Serializers.update(:serializer6) do
79
+ include new_module
80
+ end
81
+
82
+ Warden::Serializers[:serializer6].ancestors.should include(new_module)
83
+ end
84
+
85
+ it "should allow me to clear the Serializers" do
86
+ Warden::Serializers.add(:foobar) do
87
+ def fetch; end
88
+ def store; end
89
+ def stored?; end
90
+ def delete; end
91
+ end
92
+ Warden::Serializers[:foobar].should_not be_nil
93
+ Warden::Serializers.clear!
94
+ Warden::Serializers[:foobar].should be_nil
95
+ end
96
+ end
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
2
 
3
3
  describe Warden::Strategies::Base do
4
4
 
@@ -17,7 +17,7 @@ describe Warden::Strategies do
17
17
  end.should raise_error
18
18
  end
19
19
 
20
- it "should allow me to get access to a particular middleware" do
20
+ it "should allow me to get access to a particular strategy" do
21
21
  Warden::Strategies.add(:strategy3) do
22
22
  def authenticate!; end
23
23
  end
@@ -35,7 +35,7 @@ describe Warden::Strategies do
35
35
  end.should_not raise_error
36
36
  end
37
37
 
38
- it "should not allow a strategy that does not have a call(env) and initialize(app, config={}) method" do
38
+ it "should not allow a strategy that does not have an authenticate! method" do
39
39
  class MyOtherStrategy
40
40
  end
41
41
  lambda do
@@ -43,28 +43,32 @@ describe Warden::Strategies do
43
43
  end.should raise_error
44
44
  end
45
45
 
46
- it "should allow me to inherit from a class when providing a block and class" do
46
+ it "should allow me to change a class when providing a block and class" do
47
47
  class MyStrategy < Warden::Strategies::Base
48
- def authenticate!
49
- self.call
50
- end
51
-
52
- def call
53
- request.env['warden.spec.strategies'] ||= []
54
- request.env['warden.spec.strategies'] << :inherited
55
- end
56
48
  end
57
49
 
58
50
  Warden::Strategies.add(:foo, MyStrategy) do
59
- def authenticate!
60
- self.call
61
- end
51
+ def authenticate!; end
62
52
  end
63
53
 
64
54
  Warden::Strategies[:foo].ancestors.should include(MyStrategy)
55
+ end
56
+
57
+ it "should allow me to update a previously given strategy" do
58
+ class MyStrategy < Warden::Strategies::Base
59
+ def authenticate!; end
60
+ end
61
+
62
+ Warden::Strategies.add(:strategy6, MyStrategy)
65
63
 
64
+ new_module = Module.new
65
+ Warden::Strategies.update(:strategy6) do
66
+ include new_module
67
+ end
68
+
69
+ Warden::Strategies[:strategy6].ancestors.should include(new_module)
66
70
  end
67
-
71
+
68
72
  it "should allow me to clear the strategies" do
69
73
  Warden::Strategies.add(:foobar) do
70
74
  def authenticate!
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{warden}
8
- s.version = "0.5.3"
8
+ s.version = "0.6.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Daniel Neighman"]
12
- s.date = %q{2009-11-20}
12
+ s.date = %q{2009-11-15}
13
13
  s.email = %q{has.sox@gmail.com}
14
14
  s.extra_rdoc_files = [
15
15
  "LICENSE",
@@ -22,32 +22,39 @@ Gem::Specification.new do |s|
22
22
  "README.textile",
23
23
  "Rakefile",
24
24
  "TODO.textile",
25
- "VERSION",
26
25
  "lib/warden.rb",
27
- "lib/warden/authentication/hooks.rb",
28
- "lib/warden/authentication/strategies.rb",
29
- "lib/warden/authentication/strategy_base.rb",
26
+ "lib/warden/declarable.rb",
30
27
  "lib/warden/errors.rb",
28
+ "lib/warden/hooks.rb",
31
29
  "lib/warden/manager.rb",
32
30
  "lib/warden/mixins/common.rb",
33
31
  "lib/warden/proxy.rb",
32
+ "lib/warden/serializers.rb",
33
+ "lib/warden/serializers/base.rb",
34
+ "lib/warden/serializers/cookie.rb",
35
+ "lib/warden/serializers/session.rb",
36
+ "lib/warden/strategies.rb",
37
+ "lib/warden/strategies/base.rb",
34
38
  "lib/warden/version.rb",
35
39
  "script/destroy",
36
40
  "script/generate",
37
41
  "spec/helpers/request_helper.rb",
42
+ "spec/helpers/strategies/failz.rb",
43
+ "spec/helpers/strategies/invalid.rb",
44
+ "spec/helpers/strategies/pass.rb",
45
+ "spec/helpers/strategies/pass_without_user.rb",
46
+ "spec/helpers/strategies/password.rb",
38
47
  "spec/spec_helper.rb",
39
48
  "spec/warden/authenticated_data_store_spec.rb",
40
49
  "spec/warden/errors_spec.rb",
41
50
  "spec/warden/hooks_spec.rb",
42
51
  "spec/warden/manager_spec.rb",
43
52
  "spec/warden/proxy_spec.rb",
44
- "spec/warden/strategies/failz.rb",
45
- "spec/warden/strategies/invalid.rb",
46
- "spec/warden/strategies/pass.rb",
47
- "spec/warden/strategies/pass_without_user.rb",
48
- "spec/warden/strategies/password.rb",
53
+ "spec/warden/serializers/cookie_spec.rb",
54
+ "spec/warden/serializers/session_spec.rb",
55
+ "spec/warden/serializers_spec.rb",
56
+ "spec/warden/strategies/base_spec.rb",
49
57
  "spec/warden/strategies_spec.rb",
50
- "spec/warden/strategy_base_spec.rb",
51
58
  "spec/warden_spec.rb",
52
59
  "warden.gemspec"
53
60
  ]
@@ -59,19 +66,22 @@ Gem::Specification.new do |s|
59
66
  s.summary = %q{Rack middleware that provides authentication for rack applications}
60
67
  s.test_files = [
61
68
  "spec/helpers/request_helper.rb",
69
+ "spec/helpers/strategies/failz.rb",
70
+ "spec/helpers/strategies/invalid.rb",
71
+ "spec/helpers/strategies/pass.rb",
72
+ "spec/helpers/strategies/pass_without_user.rb",
73
+ "spec/helpers/strategies/password.rb",
62
74
  "spec/spec_helper.rb",
63
75
  "spec/warden/authenticated_data_store_spec.rb",
64
76
  "spec/warden/errors_spec.rb",
65
77
  "spec/warden/hooks_spec.rb",
66
78
  "spec/warden/manager_spec.rb",
67
79
  "spec/warden/proxy_spec.rb",
68
- "spec/warden/strategies/failz.rb",
69
- "spec/warden/strategies/invalid.rb",
70
- "spec/warden/strategies/pass.rb",
71
- "spec/warden/strategies/pass_without_user.rb",
72
- "spec/warden/strategies/password.rb",
80
+ "spec/warden/serializers/cookie_spec.rb",
81
+ "spec/warden/serializers/session_spec.rb",
82
+ "spec/warden/serializers_spec.rb",
83
+ "spec/warden/strategies/base_spec.rb",
73
84
  "spec/warden/strategies_spec.rb",
74
- "spec/warden/strategy_base_spec.rb",
75
85
  "spec/warden_spec.rb"
76
86
  ]
77
87
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: warden
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.3
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Neighman
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-20 00:00:00 +11:00
12
+ date: 2009-11-15 00:00:00 +11:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -38,32 +38,39 @@ files:
38
38
  - README.textile
39
39
  - Rakefile
40
40
  - TODO.textile
41
- - VERSION
42
41
  - lib/warden.rb
43
- - lib/warden/authentication/hooks.rb
44
- - lib/warden/authentication/strategies.rb
45
- - lib/warden/authentication/strategy_base.rb
42
+ - lib/warden/declarable.rb
46
43
  - lib/warden/errors.rb
44
+ - lib/warden/hooks.rb
47
45
  - lib/warden/manager.rb
48
46
  - lib/warden/mixins/common.rb
49
47
  - lib/warden/proxy.rb
48
+ - lib/warden/serializers.rb
49
+ - lib/warden/serializers/base.rb
50
+ - lib/warden/serializers/cookie.rb
51
+ - lib/warden/serializers/session.rb
52
+ - lib/warden/strategies.rb
53
+ - lib/warden/strategies/base.rb
50
54
  - lib/warden/version.rb
51
55
  - script/destroy
52
56
  - script/generate
53
57
  - spec/helpers/request_helper.rb
58
+ - spec/helpers/strategies/failz.rb
59
+ - spec/helpers/strategies/invalid.rb
60
+ - spec/helpers/strategies/pass.rb
61
+ - spec/helpers/strategies/pass_without_user.rb
62
+ - spec/helpers/strategies/password.rb
54
63
  - spec/spec_helper.rb
55
64
  - spec/warden/authenticated_data_store_spec.rb
56
65
  - spec/warden/errors_spec.rb
57
66
  - spec/warden/hooks_spec.rb
58
67
  - spec/warden/manager_spec.rb
59
68
  - spec/warden/proxy_spec.rb
60
- - spec/warden/strategies/failz.rb
61
- - spec/warden/strategies/invalid.rb
62
- - spec/warden/strategies/pass.rb
63
- - spec/warden/strategies/pass_without_user.rb
64
- - spec/warden/strategies/password.rb
69
+ - spec/warden/serializers/cookie_spec.rb
70
+ - spec/warden/serializers/session_spec.rb
71
+ - spec/warden/serializers_spec.rb
72
+ - spec/warden/strategies/base_spec.rb
65
73
  - spec/warden/strategies_spec.rb
66
- - spec/warden/strategy_base_spec.rb
67
74
  - spec/warden_spec.rb
68
75
  - warden.gemspec
69
76
  has_rdoc: true
@@ -96,17 +103,20 @@ specification_version: 3
96
103
  summary: Rack middleware that provides authentication for rack applications
97
104
  test_files:
98
105
  - spec/helpers/request_helper.rb
106
+ - spec/helpers/strategies/failz.rb
107
+ - spec/helpers/strategies/invalid.rb
108
+ - spec/helpers/strategies/pass.rb
109
+ - spec/helpers/strategies/pass_without_user.rb
110
+ - spec/helpers/strategies/password.rb
99
111
  - spec/spec_helper.rb
100
112
  - spec/warden/authenticated_data_store_spec.rb
101
113
  - spec/warden/errors_spec.rb
102
114
  - spec/warden/hooks_spec.rb
103
115
  - spec/warden/manager_spec.rb
104
116
  - spec/warden/proxy_spec.rb
105
- - spec/warden/strategies/failz.rb
106
- - spec/warden/strategies/invalid.rb
107
- - spec/warden/strategies/pass.rb
108
- - spec/warden/strategies/pass_without_user.rb
109
- - spec/warden/strategies/password.rb
117
+ - spec/warden/serializers/cookie_spec.rb
118
+ - spec/warden/serializers/session_spec.rb
119
+ - spec/warden/serializers_spec.rb
120
+ - spec/warden/strategies/base_spec.rb
110
121
  - spec/warden/strategies_spec.rb
111
- - spec/warden/strategy_base_spec.rb
112
122
  - spec/warden_spec.rb