warden 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,2 @@
1
+ pkg
2
+ pkg/*
data/Rakefile CHANGED
@@ -1,34 +1,29 @@
1
1
  require 'rubygems'
2
- require 'rake/gempackagetask'
3
- require 'rubygems/specification'
4
- require 'date'
2
+ require 'rack'
5
3
  require 'spec/rake/spectask'
6
4
 
7
5
  GEM = "warden"
8
6
  GEM_VERSION = "0.2.1"
9
- AUTHOR = "Daniel Neighman"
7
+ AUTHORS = ["Daniel Neighman"]
10
8
  EMAIL = "has.sox@gmail.com"
11
9
  HOMEPAGE = "http://github.com/hassox/warden"
12
10
  SUMMARY = "Rack middleware that provides authentication for rack applications"
13
11
 
14
- spec = Gem::Specification.new do |s|
15
- s.name = GEM
16
- s.version = GEM_VERSION
17
- s.platform = Gem::Platform::RUBY
18
- s.has_rdoc = true
19
- s.extra_rdoc_files = ["README.textile", "LICENSE", 'TODO.textile']
20
- s.summary = SUMMARY
21
- s.description = s.summary
22
- s.author = AUTHOR
23
- s.email = EMAIL
24
- s.homepage = HOMEPAGE
25
-
26
- # Uncomment this to add a dependency
27
- # s.add_dependency "foo"
28
-
29
- s.require_path = 'lib'
30
- s.autorequire = GEM
31
- s.files = %w(LICENSE README.textile Rakefile TODO.textile) + Dir.glob("{lib,spec}/**/*")
12
+ begin
13
+ require 'jeweler'
14
+ Jeweler::Tasks.new do |gem|
15
+ gem.name = GEM
16
+ gem.summary = SUMMARY
17
+ gem.email = EMAIL
18
+ gem.homepage = HOMEPAGE
19
+ gem.authors = AUTHORS
20
+ gem.rubyforge_project = "warden"
21
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
22
+
23
+ gem.add_dependency "rack", ">= 1.0.0"
24
+ end
25
+ rescue LoadError
26
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
32
27
  end
33
28
 
34
29
  task :default => :spec
@@ -38,20 +33,3 @@ Spec::Rake::SpecTask.new do |t|
38
33
  t.spec_files = FileList['spec/**/*_spec.rb']
39
34
  t.spec_opts = %w(-fs --color)
40
35
  end
41
-
42
-
43
- Rake::GemPackageTask.new(spec) do |pkg|
44
- pkg.gem_spec = spec
45
- end
46
-
47
- desc "install the gem locally"
48
- task :install => [:package] do
49
- sh %{sudo gem install pkg/#{GEM}-#{GEM_VERSION}}
50
- end
51
-
52
- desc "create a gemspec file"
53
- task :make_spec do
54
- File.open("#{GEM}.gemspec", "w") do |file|
55
- file.puts spec.to_ruby
56
- end
57
- end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.2.2
@@ -26,18 +26,17 @@ module Warden
26
26
 
27
27
  # Check to see if there is an authenticated user for the given scope.
28
28
  # When scope is not specified, :default is assumed.
29
+ # This will not try to reconstitute the user from the session and will simply check for the
30
+ # existance of a session key
29
31
  #
30
32
  # Parameters:
31
- # args - a list of symbols (labels) that name the strategies to attempt
32
- # opts - an options hash that contains the :scope of the user to check
33
+ # scope - the scope to check for authentication. Defaults to :default
33
34
  #
34
35
  # Example:
35
- # env['warden'].authenticated?(:password, :scope => :admin)
36
+ # env['warden'].authenticated?(:admin)
36
37
  # :api: public
37
- def authenticated?(*args)
38
- scope = scope_from_args(args)
39
- _perform_authentication(*args)
40
- !user(scope).nil?
38
+ def authenticated?(scope = :default)
39
+ !_session["warden.user.#{scope}.key"].nil?
41
40
  end # authenticated?
42
41
 
43
42
  # Run the authentiation strategies for the given strategies.
@@ -101,7 +100,7 @@ module Warden
101
100
  #
102
101
  # :api: public
103
102
  def user(scope = :default)
104
- @users[scope]
103
+ @users[scope] ||= lookup_user_from_session(scope)
105
104
  end
106
105
 
107
106
  # Provides a scoped session data for authenticated users.
@@ -116,7 +115,7 @@ module Warden
116
115
  #
117
116
  # :api: public
118
117
  def session(scope = :default)
119
- raise NotAuthenticated, "#{scope.inspect} user is not logged in" unless authenticated?(:scope => scope)
118
+ raise NotAuthenticated, "#{scope.inspect} user is not logged in" unless authenticated?(scope)
120
119
  _session["warden.user.#{scope}.session"] ||= {}
121
120
  end
122
121
 
@@ -159,9 +158,10 @@ module Warden
159
158
  def _perform_authentication(*args)
160
159
  scope = scope_from_args(args)
161
160
  opts = opts_from_args(args)
161
+
162
162
  # Look for an existing user in the session for this scope
163
- if @users[scope] || set_user(Warden::Manager._fetch_user(_session, scope), :scope => scope)
164
- return @users[scope]
163
+ if the_user = user(scope)
164
+ return the_user
165
165
  end
166
166
 
167
167
  # If there was no user in the session. See if we can get one from the request
@@ -196,5 +196,9 @@ module Warden
196
196
  Hash === args.last ? args.pop : {}
197
197
  end
198
198
 
199
+ # :api: private
200
+ def lookup_user_from_session(scope)
201
+ set_user(Warden::Manager._fetch_user(_session, scope), :scope => scope)
202
+ end
199
203
  end # Proxy
200
204
  end # Warden
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '.'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/destroy'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:newgem_simple, :test_unit]
14
+ RubiGen::Scripts::Destroy.new.run(ARGV)
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '.'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/generate'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:newgem_simple, :test_unit]
14
+ RubiGen::Scripts::Generate.new.run(ARGV)
@@ -13,8 +13,10 @@ describe "authenticated data store" do
13
13
 
14
14
  it "should store data for the default scope" do
15
15
  app = lambda do |e|
16
- e['warden'].should be_authenticated(:pass)
17
- e['warden'].should be_authenticated(:pass, :scope => :foo)
16
+ e['warden'].authenticate(:pass)
17
+ e['warden'].authenticate(:pass, :scope => :foo)
18
+ e['warden'].should be_authenticated
19
+ e['warden'].should be_authenticated(:foo)
18
20
 
19
21
  # Store the data for :deafult
20
22
  e['warden'].session[:key] = "value"
@@ -60,7 +60,7 @@ describe "standard authentication hooks" do
60
60
  it "should run each after_authentication hook after authentication is run" do
61
61
  RAM.after_authentication{|u,a,o| a.env['warden.spec.hook.baz'] = "run baz"}
62
62
  RAM.after_authentication{|u,a,o| a.env['warden.spec.hook.paz'] = "run paz"}
63
- app = lambda{|e| e['warden'].authenticated?(:pass); valid_response}
63
+ app = lambda{|e| e['warden'].authenticate(:pass); valid_response}
64
64
  env = env_with_params
65
65
  setup_rack(app).call(env)
66
66
  env['warden.spec.hook.baz'].should == 'run baz'
@@ -9,6 +9,7 @@ describe Warden::Proxy do
9
9
  before(:each) do
10
10
  @basic_app = lambda{|env| [200,{'Content-Type' => 'text/plain'},'OK']}
11
11
  @authd_app = lambda do |e|
12
+ e['warden'].authenticate
12
13
  if e['warden'].authenticated?
13
14
  [200,{'Content-Type' => 'text/plain'},"OK"]
14
15
  else
@@ -50,6 +51,7 @@ describe Warden::Proxy do
50
51
  it "should allow authentication in my application" do
51
52
  env = env_with_params('/', :username => "fred", :password => "sekrit")
52
53
  app = lambda do |env|
54
+ env['warden'].authenticate
53
55
  env['warden'].should be_authenticated
54
56
  env['warden.spec.strategies'].should == [:password]
55
57
  end
@@ -58,6 +60,7 @@ describe Warden::Proxy do
58
60
  it "should be false in my application" do
59
61
  env = env_with_params("/", :foo => "bar")
60
62
  app = lambda do |env|
63
+ env['warden'].authenticate
61
64
  env['warden'].should_not be_authenticated
62
65
  env['warden.spec.strategies'].should == [:password]
63
66
  valid_response
@@ -68,7 +71,8 @@ describe Warden::Proxy do
68
71
  it "should allow me to select which strategies I use in my appliction" do
69
72
  env = env_with_params("/", :foo => "bar")
70
73
  app = lambda do |env|
71
- env['warden'].should_not be_authenticated(:failz)
74
+ env['warden'].authenticate(:failz)
75
+ env['warden'].should_not be_authenticated
72
76
  env['warden.spec.strategies'].should == [:failz]
73
77
  valid_response
74
78
  end
@@ -78,7 +82,8 @@ describe Warden::Proxy do
78
82
  it "should allow me to get access to the user at warden.user." do
79
83
  env = env_with_params("/")
80
84
  app = lambda do |env|
81
- env['warden'].should be_authenticated(:pass)
85
+ env['warden'].authenticate(:pass)
86
+ env['warden'].should be_authenticated
82
87
  env['warden.spec.strategies'].should == [:pass]
83
88
  valid_response
84
89
  end
@@ -88,7 +93,8 @@ describe Warden::Proxy do
88
93
  it "should try multiple authentication strategies" do
89
94
  env = env_with_params("/")
90
95
  app = lambda do |env|
91
- env['warden'].should be_authenticated(:password, :pass)
96
+ env['warden'].authenticate(:password,:pass)
97
+ env['warden'].should be_authenticated
92
98
  env['warden.spec.strategies'].should == [:password, :pass]
93
99
  valid_response
94
100
  end
@@ -109,7 +115,8 @@ describe Warden::Proxy do
109
115
  it "should look for an active user in the session with authenticate?" do
110
116
  app = lambda do |env|
111
117
  env['rack.session']['warden.user.foo_scope.key'] = "a foo user"
112
- env['warden'].authenticated?(:pass, :scope => :foo_scope)
118
+ env['warden'].authenticate(:pass, :scope => :foo_scope)
119
+ env['warden'].authenticated?(:foo_scope)
113
120
  valid_response
114
121
  end
115
122
  env = env_with_params
@@ -121,9 +128,12 @@ describe Warden::Proxy do
121
128
  app = lambda do |env|
122
129
  env['rack.session']['warden.user.foo.key'] = 'foo user'
123
130
  env['rack.session']['warden.user.bar.key'] = 'bar user'
124
- env['warden'].authenticated?(:pass, :scope => :foo).should be_true
125
- env['warden'].authenticated?(:pass, :scope => :bar).should be_true
126
- env['warden'].authenticated?(:password).should be_false
131
+ env['warden'].authenticate(:pass, :scope => :foo)
132
+ env['warden'].authenticate(:pass, :scope => :bar)
133
+ env['warden'].authenticate(:password)
134
+ env['warden'].authenticated?(:foo).should be_true
135
+ env['warden'].authenticated?(:bar).should be_true
136
+ env['warden'].authenticated?.should be_false
127
137
  valid_response
128
138
  end
129
139
  env = env_with_params
@@ -139,7 +149,8 @@ describe Warden::Proxy do
139
149
  it "should store the user into the session" do
140
150
  env = env_with_params("/")
141
151
  app = lambda do |env|
142
- env['warden'].should be_authenticated(:pass)
152
+ env['warden'].authenticate(:pass)
153
+ env['warden'].should be_authenticated
143
154
  env['warden'].user.should == "Valid User"
144
155
  env['rack.session']["warden.user.default.key"].should == "Valid User"
145
156
  valid_response
@@ -147,6 +158,47 @@ describe Warden::Proxy do
147
158
  setup_rack(app).call(env)
148
159
  end
149
160
  end
161
+
162
+ describe "get user" do
163
+ before(:each) do
164
+ @env['rack.session'] ||= {}
165
+ @env['rack.session'].delete("warden.user.default.key")
166
+ end
167
+
168
+ it "should return nil when not logged in" do
169
+ app = lambda do |env|
170
+ env['warden'].user.should be_nil
171
+ valid_response
172
+ end
173
+ setup_rack(app).call(@env)
174
+ end
175
+
176
+ it "should not run strategies when not logged in" do
177
+ app = lambda do |env|
178
+ env['warden'].user.should be_nil
179
+ env['warden.spec.strategies'].should be_nil
180
+ valid_response
181
+ end
182
+ setup_rack(app).call(@env)
183
+ end
184
+
185
+ describe "previously logged in" do
186
+
187
+ before(:each) do
188
+ @env['rack.session']['warden.user.default.key'] = "A Previous User"
189
+ end
190
+
191
+ it "should take the user from the session when logged in" do
192
+ app = lambda do |env|
193
+ env['warden'].user.should == "A Previous User"
194
+ valid_response
195
+ end
196
+ setup_rack(app).call(@env)
197
+ end
198
+
199
+ it "should not run strategies when the user exists in the session"
200
+ end
201
+ end
150
202
 
151
203
  describe "logout" do
152
204
 
@@ -0,0 +1,85 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{warden}
5
+ s.version = "0.2.2"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Daniel Neighman"]
9
+ s.date = %q{2009-07-07}
10
+ s.email = %q{has.sox@gmail.com}
11
+ s.extra_rdoc_files = [
12
+ "LICENSE",
13
+ "README.textile"
14
+ ]
15
+ s.files = [
16
+ ".gitignore",
17
+ "LICENSE",
18
+ "README.textile",
19
+ "Rakefile",
20
+ "TODO.textile",
21
+ "VERSION",
22
+ "lib/warden.rb",
23
+ "lib/warden/authentication/hooks.rb",
24
+ "lib/warden/authentication/strategies.rb",
25
+ "lib/warden/authentication/strategy_base.rb",
26
+ "lib/warden/errors.rb",
27
+ "lib/warden/manager.rb",
28
+ "lib/warden/mixins/common.rb",
29
+ "lib/warden/proxy.rb",
30
+ "script/destroy",
31
+ "script/generate",
32
+ "spec/helpers/request_helper.rb",
33
+ "spec/spec_helper.rb",
34
+ "spec/warden/authenticated_data_store_spec.rb",
35
+ "spec/warden/errors_spec.rb",
36
+ "spec/warden/hooks_spec.rb",
37
+ "spec/warden/manager_spec.rb",
38
+ "spec/warden/proxy_spec.rb",
39
+ "spec/warden/strategies/failz.rb",
40
+ "spec/warden/strategies/invalid.rb",
41
+ "spec/warden/strategies/pass.rb",
42
+ "spec/warden/strategies/pass_without_user.rb",
43
+ "spec/warden/strategies/password.rb",
44
+ "spec/warden/strategies_spec.rb",
45
+ "spec/warden/strategy_base_spec.rb",
46
+ "spec/warden_spec.rb",
47
+ "warden.gemspec"
48
+ ]
49
+ s.homepage = %q{http://github.com/hassox/warden}
50
+ s.rdoc_options = ["--charset=UTF-8"]
51
+ s.require_paths = ["lib"]
52
+ s.rubyforge_project = %q{warden}
53
+ s.rubygems_version = %q{1.3.3}
54
+ s.summary = %q{Rack middleware that provides authentication for rack applications}
55
+ s.test_files = [
56
+ "spec/helpers/request_helper.rb",
57
+ "spec/spec_helper.rb",
58
+ "spec/warden/authenticated_data_store_spec.rb",
59
+ "spec/warden/errors_spec.rb",
60
+ "spec/warden/hooks_spec.rb",
61
+ "spec/warden/manager_spec.rb",
62
+ "spec/warden/proxy_spec.rb",
63
+ "spec/warden/strategies/failz.rb",
64
+ "spec/warden/strategies/invalid.rb",
65
+ "spec/warden/strategies/pass.rb",
66
+ "spec/warden/strategies/pass_without_user.rb",
67
+ "spec/warden/strategies/password.rb",
68
+ "spec/warden/strategies_spec.rb",
69
+ "spec/warden/strategy_base_spec.rb",
70
+ "spec/warden_spec.rb"
71
+ ]
72
+
73
+ if s.respond_to? :specification_version then
74
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
75
+ s.specification_version = 3
76
+
77
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
78
+ s.add_runtime_dependency(%q<rack>, [">= 1.0.0"])
79
+ else
80
+ s.add_dependency(%q<rack>, [">= 1.0.0"])
81
+ end
82
+ else
83
+ s.add_dependency(%q<rack>, [">= 1.0.0"])
84
+ end
85
+ end
metadata CHANGED
@@ -1,33 +1,44 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: warden
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Neighman
8
- autorequire: warden
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-05-27 00:00:00 +10:00
12
+ date: 2009-07-07 00:00:00 +10:00
13
13
  default_executable:
14
- dependencies: []
15
-
16
- description: Rack middleware that provides authentication for rack applications
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rack
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.0.0
24
+ version:
25
+ description:
17
26
  email: has.sox@gmail.com
18
27
  executables: []
19
28
 
20
29
  extensions: []
21
30
 
22
31
  extra_rdoc_files:
23
- - README.textile
24
32
  - LICENSE
25
- - TODO.textile
33
+ - README.textile
26
34
  files:
35
+ - .gitignore
27
36
  - LICENSE
28
37
  - README.textile
29
38
  - Rakefile
30
39
  - TODO.textile
40
+ - VERSION
41
+ - lib/warden.rb
31
42
  - lib/warden/authentication/hooks.rb
32
43
  - lib/warden/authentication/strategies.rb
33
44
  - lib/warden/authentication/strategy_base.rb
@@ -35,7 +46,8 @@ files:
35
46
  - lib/warden/manager.rb
36
47
  - lib/warden/mixins/common.rb
37
48
  - lib/warden/proxy.rb
38
- - lib/warden.rb
49
+ - script/destroy
50
+ - script/generate
39
51
  - spec/helpers/request_helper.rb
40
52
  - spec/spec_helper.rb
41
53
  - spec/warden/authenticated_data_store_spec.rb
@@ -51,13 +63,14 @@ files:
51
63
  - spec/warden/strategies_spec.rb
52
64
  - spec/warden/strategy_base_spec.rb
53
65
  - spec/warden_spec.rb
66
+ - warden.gemspec
54
67
  has_rdoc: true
55
68
  homepage: http://github.com/hassox/warden
56
69
  licenses: []
57
70
 
58
71
  post_install_message:
59
- rdoc_options: []
60
-
72
+ rdoc_options:
73
+ - --charset=UTF-8
61
74
  require_paths:
62
75
  - lib
63
76
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -74,10 +87,24 @@ required_rubygems_version: !ruby/object:Gem::Requirement
74
87
  version:
75
88
  requirements: []
76
89
 
77
- rubyforge_project:
90
+ rubyforge_project: warden
78
91
  rubygems_version: 1.3.3
79
92
  signing_key:
80
93
  specification_version: 3
81
94
  summary: Rack middleware that provides authentication for rack applications
82
- test_files: []
83
-
95
+ test_files:
96
+ - spec/helpers/request_helper.rb
97
+ - spec/spec_helper.rb
98
+ - spec/warden/authenticated_data_store_spec.rb
99
+ - spec/warden/errors_spec.rb
100
+ - spec/warden/hooks_spec.rb
101
+ - spec/warden/manager_spec.rb
102
+ - spec/warden/proxy_spec.rb
103
+ - spec/warden/strategies/failz.rb
104
+ - spec/warden/strategies/invalid.rb
105
+ - spec/warden/strategies/pass.rb
106
+ - spec/warden/strategies/pass_without_user.rb
107
+ - spec/warden/strategies/password.rb
108
+ - spec/warden/strategies_spec.rb
109
+ - spec/warden/strategy_base_spec.rb
110
+ - spec/warden_spec.rb