warden 0.8.1 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,10 +1,10 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
2
 
3
- describe Warden::Serializers::Session do
3
+ describe Warden::SessionSerializer do
4
4
  before(:each) do
5
5
  @env = env_with_params
6
6
  @env['rack.session'] ||= {}
7
- @session = Warden::Serializers::Session.new(@env)
7
+ @session = Warden::SessionSerializer.new(@env)
8
8
  end
9
9
 
10
10
  it "should store data for the default scope" do
@@ -43,7 +43,19 @@ describe Warden::Strategies::Base do
43
43
  strategy._run!
44
44
  strategy.user.should == "foo"
45
45
  end
46
-
46
+
47
+ it "should be performed after run" do
48
+ RAS.add(:foobar) do
49
+ def authenticate!; end
50
+ end
51
+ strategy = RAS[:foobar].new(env_with_params)
52
+ strategy.should_not be_performed
53
+ strategy._run!
54
+ strategy.should be_performed
55
+ strategy.clear!
56
+ strategy.should_not be_performed
57
+ end
58
+
47
59
  it "should set the scope" do
48
60
  RAS.add(:foobar) do
49
61
  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.8.1"
8
+ s.version = "0.9.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{2010-01-08}
12
+ s.date = %q{2010-01-21}
13
13
  s.email = %q{has.sox@gmail.com}
14
14
  s.extra_rdoc_files = [
15
15
  "LICENSE",
@@ -24,17 +24,13 @@ Gem::Specification.new do |s|
24
24
  "TODO.textile",
25
25
  "lib/warden.rb",
26
26
  "lib/warden/config.rb",
27
- "lib/warden/declarable.rb",
28
27
  "lib/warden/errors.rb",
29
28
  "lib/warden/hooks.rb",
30
29
  "lib/warden/manager.rb",
31
30
  "lib/warden/manager_deprecation.rb",
32
31
  "lib/warden/mixins/common.rb",
33
32
  "lib/warden/proxy.rb",
34
- "lib/warden/serializers.rb",
35
- "lib/warden/serializers/base.rb",
36
- "lib/warden/serializers/cookie.rb",
37
- "lib/warden/serializers/session.rb",
33
+ "lib/warden/session_serializer.rb",
38
34
  "lib/warden/strategies.rb",
39
35
  "lib/warden/strategies/base.rb",
40
36
  "lib/warden/version.rb",
@@ -52,9 +48,7 @@ Gem::Specification.new do |s|
52
48
  "spec/warden/hooks_spec.rb",
53
49
  "spec/warden/manager_spec.rb",
54
50
  "spec/warden/proxy_spec.rb",
55
- "spec/warden/serializers/cookie_spec.rb",
56
- "spec/warden/serializers/session_spec.rb",
57
- "spec/warden/serializers_spec.rb",
51
+ "spec/warden/session_serializer_spec.rb",
58
52
  "spec/warden/strategies/base_spec.rb",
59
53
  "spec/warden/strategies_spec.rb",
60
54
  "spec/warden_spec.rb",
@@ -79,9 +73,7 @@ Gem::Specification.new do |s|
79
73
  "spec/warden/hooks_spec.rb",
80
74
  "spec/warden/manager_spec.rb",
81
75
  "spec/warden/proxy_spec.rb",
82
- "spec/warden/serializers/cookie_spec.rb",
83
- "spec/warden/serializers/session_spec.rb",
84
- "spec/warden/serializers_spec.rb",
76
+ "spec/warden/session_serializer_spec.rb",
85
77
  "spec/warden/strategies/base_spec.rb",
86
78
  "spec/warden/strategies_spec.rb",
87
79
  "spec/warden_spec.rb"
@@ -93,11 +85,14 @@ Gem::Specification.new do |s|
93
85
 
94
86
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
95
87
  s.add_runtime_dependency(%q<rack>, [">= 1.0.0"])
88
+ s.add_development_dependency(%q<rspec>, [">= 1.0.0"])
96
89
  else
97
90
  s.add_dependency(%q<rack>, [">= 1.0.0"])
91
+ s.add_dependency(%q<rspec>, [">= 1.0.0"])
98
92
  end
99
93
  else
100
94
  s.add_dependency(%q<rack>, [">= 1.0.0"])
95
+ s.add_dependency(%q<rspec>, [">= 1.0.0"])
101
96
  end
102
97
  end
103
98
 
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.8.1
4
+ version: 0.9.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: 2010-01-08 00:00:00 +01:00
12
+ date: 2010-01-21 00:00:00 +11:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -22,6 +22,16 @@ dependencies:
22
22
  - !ruby/object:Gem::Version
23
23
  version: 1.0.0
24
24
  version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.0.0
34
+ version:
25
35
  description:
26
36
  email: has.sox@gmail.com
27
37
  executables: []
@@ -40,17 +50,13 @@ files:
40
50
  - TODO.textile
41
51
  - lib/warden.rb
42
52
  - lib/warden/config.rb
43
- - lib/warden/declarable.rb
44
53
  - lib/warden/errors.rb
45
54
  - lib/warden/hooks.rb
46
55
  - lib/warden/manager.rb
47
56
  - lib/warden/manager_deprecation.rb
48
57
  - lib/warden/mixins/common.rb
49
58
  - lib/warden/proxy.rb
50
- - lib/warden/serializers.rb
51
- - lib/warden/serializers/base.rb
52
- - lib/warden/serializers/cookie.rb
53
- - lib/warden/serializers/session.rb
59
+ - lib/warden/session_serializer.rb
54
60
  - lib/warden/strategies.rb
55
61
  - lib/warden/strategies/base.rb
56
62
  - lib/warden/version.rb
@@ -68,9 +74,7 @@ files:
68
74
  - spec/warden/hooks_spec.rb
69
75
  - spec/warden/manager_spec.rb
70
76
  - spec/warden/proxy_spec.rb
71
- - spec/warden/serializers/cookie_spec.rb
72
- - spec/warden/serializers/session_spec.rb
73
- - spec/warden/serializers_spec.rb
77
+ - spec/warden/session_serializer_spec.rb
74
78
  - spec/warden/strategies/base_spec.rb
75
79
  - spec/warden/strategies_spec.rb
76
80
  - spec/warden_spec.rb
@@ -116,9 +120,7 @@ test_files:
116
120
  - spec/warden/hooks_spec.rb
117
121
  - spec/warden/manager_spec.rb
118
122
  - spec/warden/proxy_spec.rb
119
- - spec/warden/serializers/cookie_spec.rb
120
- - spec/warden/serializers/session_spec.rb
121
- - spec/warden/serializers_spec.rb
123
+ - spec/warden/session_serializer_spec.rb
122
124
  - spec/warden/strategies/base_spec.rb
123
125
  - spec/warden/strategies_spec.rb
124
126
  - spec/warden_spec.rb
@@ -1,43 +0,0 @@
1
- # encoding: utf-8
2
- module Warden
3
- module Declarable
4
-
5
- # Add a declaration and store it in a hash.
6
- def add(label, declaration = nil, &block)
7
- base = self.const_get(:Base)
8
-
9
- declaration ||= Class.new(base)
10
- declaration.class_eval(&block) if block_given?
11
-
12
- check_validity!(label, declaration)
13
- raise "#{label.inspect} is not a #{base}" unless declaration.ancestors.include?(base)
14
-
15
- _declarations[label] = declaration
16
- end
17
-
18
- # Update a previously given declaration.
19
- def update(label, &block)
20
- declaration = _declarations[label]
21
- raise "Unknown declaration #{label.inspect}" unless declaration
22
- add(label, declaration, &block)
23
- end
24
-
25
- # Provides access to declarations by label
26
- # :api: public
27
- def [](label)
28
- _declarations[label]
29
- end
30
-
31
- # Clears all declared.
32
- # :api: public
33
- def clear!
34
- _declarations.clear
35
- end
36
-
37
- # :api: private
38
- def _declarations
39
- @declarations ||= {}
40
- end
41
-
42
- end # Declarable
43
- end # Warden
@@ -1,20 +0,0 @@
1
- # encoding: utf-8
2
- require 'warden/declarable'
3
-
4
- module Warden
5
- module Serializers
6
- extend Warden::Declarable
7
-
8
- class << self
9
- def check_validity!(label, serializer)
10
- [:fetch, :store, :stored?, :delete].each do |method|
11
- next if serializer.method_defined?(method)
12
- raise NoMethodError, "#{method} is not declared in the #{label.inspect} serializer"
13
- end
14
- end
15
-
16
- alias :_serializers :_declarations
17
- end # << self
18
-
19
- end # Serializers
20
- end # Warden
@@ -1,38 +0,0 @@
1
- # encoding: utf-8
2
- module Warden
3
- module Serializers
4
- # A serializer is a place where you put the logic to serializing and deserializing an user. All serializers
5
- # inherits from Warden::Serializers::Base.
6
- #
7
- # The Warden::Serializers.add method is a simple way to provide custom serializers. In order to do so,
8
- # you _must_ declare @store@, @fetch@, @delete@ and @stored?@ methods.
9
- #
10
- # The parameters for Warden::Serializers.add method is:
11
- # <label: Symbol> The label is the name given to a serializer. Use the label to refer to the serializer when authenticating
12
- # <serializer: Class|nil> The optional serializer argument if set _must_ be a class that inherits from Warden::Serializers::Base
13
- # <block> The block acts as a convinient way to declare your serializer. Inside is the class definition of a serializer.
14
- #
15
- # Check Session and Cookie serializers for more information.
16
- #
17
- class Base
18
- attr_accessor :env
19
- include ::Warden::Mixins::Common
20
-
21
- def initialize(env)
22
- @env = env
23
- end
24
-
25
- def key_for(scope)
26
- "warden.user.#{scope}.key"
27
- end
28
-
29
- def serialize(user)
30
- user
31
- end
32
-
33
- def deserialize(key)
34
- key
35
- end
36
- end # Base
37
- end # Serializers
38
- end # Warden
@@ -1,34 +0,0 @@
1
- # encoding: utf-8
2
- module Warden
3
- module Serializers
4
- # A cookie serializer provided by Warden. You need to implement the serialize and deserialize
5
- # methods in order to use it.
6
- class Cookie < Base
7
- def store(user, scope)
8
- response.set_cookie key_for(scope), default_options(user)
9
- end
10
-
11
- def fetch(scope)
12
- key = request.cookies[key_for(scope)]
13
- return nil unless key
14
- user = deserialize(key)
15
- delete(scope) unless user
16
- user
17
- end
18
-
19
- def stored?(scope)
20
- !!request.cookies[key_for(scope)]
21
- end
22
-
23
- def delete(scope, user=nil)
24
- response.delete_cookie(key_for(scope))
25
- end
26
-
27
- def default_options(user)
28
- { :value => serialize(user), :expires => (Time.now + 7 * 24 * 3600), :path => "/" }
29
- end
30
- end # Cookie
31
-
32
- Serializers.add(:cookie, Cookie)
33
- end # Serializers
34
- end # Warden
@@ -1,30 +0,0 @@
1
- # encoding: utf-8
2
- module Warden
3
- module Serializers
4
- # A session serializer provided by Warden. You need to implement the serialize and deserialize
5
- # methods in order to use it.
6
- class Session < Base
7
- def store(user, scope)
8
- session[key_for(scope)] = serialize(user)
9
- end
10
-
11
- def fetch(scope)
12
- key = session[key_for(scope)]
13
- return nil unless key
14
- user = deserialize(key)
15
- delete(scope) unless user
16
- user
17
- end
18
-
19
- def stored?(scope)
20
- !!session[key_for(scope)]
21
- end
22
-
23
- def delete(scope, user=nil)
24
- session.delete(key_for(scope))
25
- end
26
- end # Session
27
-
28
- Serializers.add(:session, Session)
29
- end # Serializers
30
- end # Warden
@@ -1,60 +0,0 @@
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
@@ -1,102 +0,0 @@
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
- old_serializers = Warden::Serializers._serializers.dup
87
-
88
- begin
89
- Warden::Serializers.add(:foobar) do
90
- def fetch; end
91
- def store; end
92
- def stored?; end
93
- def delete; end
94
- end
95
- Warden::Serializers[:foobar].should_not be_nil
96
- Warden::Serializers.clear!
97
- Warden::Serializers[:foobar].should be_nil
98
- else
99
- Warden::Serializers._serializers.replace(old_serializers)
100
- end
101
- end
102
- end