loyal_warden 2.0.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. data/Gemfile +1 -1
  2. data/History.rdoc +7 -0
  3. data/README.textile +2 -1
  4. data/lib/loyal_warden.rb +2 -0
  5. data/lib/warden.rb +1 -1
  6. data/lib/warden/config.rb +1 -1
  7. data/lib/warden/errors.rb +1 -1
  8. data/lib/warden/hooks.rb +1 -1
  9. data/lib/warden/manager.rb +3 -2
  10. data/lib/warden/mixins/common.rb +4 -3
  11. data/lib/warden/proxy.rb +2 -2
  12. data/lib/warden/session_serializer.rb +6 -2
  13. data/lib/warden/strategies.rb +3 -2
  14. data/lib/warden/strategies/base.rb +1 -1
  15. data/lib/warden/test/helpers.rb +1 -1
  16. data/lib/warden/test/warden_helpers.rb +1 -1
  17. data/lib/warden/version.rb +2 -2
  18. data/loyal_warden.gemspec +6 -3
  19. data/spec/helpers/request_helper.rb +2 -2
  20. data/spec/helpers/strategies/failz.rb +1 -1
  21. data/spec/helpers/strategies/invalid.rb +2 -2
  22. data/spec/helpers/strategies/pass.rb +1 -1
  23. data/spec/helpers/strategies/pass_with_message.rb +1 -1
  24. data/spec/helpers/strategies/password.rb +1 -1
  25. data/spec/helpers/strategies/single.rb +1 -1
  26. data/spec/spec_helper.rb +1 -1
  27. data/spec/warden/authenticated_data_store_spec.rb +1 -1
  28. data/spec/warden/config_spec.rb +1 -1
  29. data/spec/warden/errors_spec.rb +1 -1
  30. data/spec/warden/hooks_spec.rb +1 -1
  31. data/spec/warden/manager_spec.rb +1 -1
  32. data/spec/warden/proxy_spec.rb +24 -7
  33. data/spec/warden/scoped_session_serializer.rb +1 -1
  34. data/spec/warden/session_serializer_spec.rb +6 -1
  35. data/spec/warden/strategies/base_spec.rb +1 -1
  36. data/spec/warden/strategies_spec.rb +12 -2
  37. data/spec/warden/test/helpers_spec.rb +1 -1
  38. data/spec/warden/test/test_mode_spec.rb +1 -1
  39. data/warden.gemspec +1 -0
  40. metadata +7 -5
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source :rubygems
1
+ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
@@ -1,3 +1,10 @@
1
+ == Version 1.2.3 / 2013-07-14
2
+ * Fix an issue with lazy loaded sessions
3
+
4
+ == Version 1.2.2 / 2013-07-12
5
+ * Support nil session stores on logout
6
+ * Fix strategies blowing up with undefined method base
7
+
1
8
  == Version 1.2.1 / 2012-06-16
2
9
  * Minor caching and speed improvements
3
10
  * Add support to #lock in the proxy
@@ -4,5 +4,6 @@ h2. Maintainers
4
4
 
5
5
  * Daniel Neighman (hassox)
6
6
  * José Valim (josevalim)
7
+ * Justin Smestad (jsmestad)
7
8
 
8
- "A list of all contributors is available on Github.":https://github.com/hassox/warden/contributors
9
+ "A list of all contributors is available on Github.":https://github.com/hassox/warden/contributors
@@ -0,0 +1,2 @@
1
+ require 'warden'
2
+
@@ -1,4 +1,4 @@
1
- # -*- encoding : utf-8 -*-
1
+ # encoding: utf-8
2
2
  require 'forwardable'
3
3
 
4
4
  require 'warden/mixins/common'
@@ -1,4 +1,4 @@
1
- # -*- encoding : utf-8 -*-
1
+ # encoding: utf-8
2
2
 
3
3
  module Warden
4
4
  # This is a class which is yielded on use Warden::Manager. If you have a plugin
@@ -1,4 +1,4 @@
1
- # -*- encoding : utf-8 -*-
1
+ # encoding: utf-8
2
2
  module Warden
3
3
  class Proxy
4
4
  # Lifted from DataMapper's dm-validations plugin :)
@@ -1,4 +1,4 @@
1
- # -*- encoding : utf-8 -*-
1
+ # encoding: utf-8
2
2
  module Warden
3
3
  module Hooks
4
4
 
@@ -1,4 +1,4 @@
1
- # -*- encoding : utf-8 -*-
1
+ # encoding: utf-8
2
2
  require 'warden/hooks'
3
3
  require 'warden/config'
4
4
 
@@ -123,7 +123,8 @@ module Warden
123
123
  def call_failure_app(env, options = {})
124
124
  if config.failure_app
125
125
  options.merge!(:attempted_path => ::Rack::Request.new(env).fullpath)
126
- options.merge!(:attempted_url => ::Rack::Request.new(env).url)
126
+ options.merge!(:attempted_url => ::Rack::Request.new(env).url)
127
+
127
128
  env["PATH_INFO"] = "/#{options[:action]}"
128
129
  env["warden.options"] = options
129
130
 
@@ -1,4 +1,4 @@
1
- # -*- encoding : utf-8 -*-
1
+ # encoding: utf-8
2
2
  module Warden
3
3
  module Mixins
4
4
  module Common
@@ -24,7 +24,7 @@ module Warden
24
24
  def warden_cookies
25
25
  warn "warden_cookies was never functional and is going to be removed in next versions"
26
26
  env['warden.cookies'] ||= {}
27
- end # response
27
+ end # warden_cookies
28
28
 
29
29
  # Convenience method to access the rack request params
30
30
  # :api: public
@@ -37,7 +37,8 @@ module Warden
37
37
  # @api overwritable
38
38
  def reset_session!
39
39
  raw_session.clear
40
- end
40
+ end # reset_session!
41
+
41
42
  end # Common
42
43
  end # Mixins
43
44
  end # Warden
@@ -1,4 +1,4 @@
1
- # -*- encoding : utf-8 -*-
1
+ # encoding: utf-8
2
2
 
3
3
  module Warden
4
4
  class UserNotSet < RuntimeError; end
@@ -261,7 +261,7 @@ module Warden
261
261
  user = @users.delete(scope)
262
262
  manager._run_callbacks(:before_logout, user, self, :scope => scope)
263
263
 
264
- raw_session.delete("warden.user.#{scope}.session")
264
+ raw_session.delete("warden.user.#{scope}.session") unless raw_session.nil?
265
265
  session_serializer.delete(scope, user)
266
266
  end
267
267
 
@@ -1,8 +1,7 @@
1
- # -*- encoding : utf-8 -*-
1
+ # encoding: utf-8
2
2
  module Warden
3
3
  class SessionSerializer
4
4
  attr_reader :env
5
- include ::Warden::Mixins::Common
6
5
 
7
6
  def initialize(env)
8
7
  @env = env
@@ -44,5 +43,10 @@ module Warden
44
43
  def delete(scope, user=nil)
45
44
  session.delete(key_for(scope))
46
45
  end
46
+
47
+ # We can't cache this result because the session can be lazy loaded
48
+ def session
49
+ env["rack.session"] || {}
50
+ end
47
51
  end # SessionSerializer
48
52
  end # Warden
@@ -1,4 +1,4 @@
1
- # -*- encoding : utf-8 -*-
1
+ # encoding: utf-8
2
2
  module Warden
3
3
  module Strategies
4
4
  class << self
@@ -11,7 +11,8 @@ module Warden
11
11
  raise NoMethodError, "authenticate! is not declared in the #{label.inspect} strategy"
12
12
  end
13
13
 
14
- unless strategy.ancestors.include?(Warden::Strategies::Base)
14
+ base = Warden::Strategies::Base
15
+ unless strategy.ancestors.include?(base)
15
16
  raise "#{label.inspect} is not a #{base}"
16
17
  end
17
18
 
@@ -1,4 +1,4 @@
1
- # -*- encoding : utf-8 -*-
1
+ # encoding: utf-8
2
2
  module Warden
3
3
  module Strategies
4
4
  # A strategy is a place where you can put logic related to authentication. Any strategy inherits
@@ -1,4 +1,4 @@
1
- # -*- encoding : utf-8 -*-
1
+ # encoding: utf-8
2
2
 
3
3
  module Warden
4
4
  module Test
@@ -1,4 +1,4 @@
1
- # -*- encoding : utf-8 -*-
1
+ # encoding: utf-8
2
2
 
3
3
  module Warden
4
4
 
@@ -1,4 +1,4 @@
1
- # -*- encoding : utf-8 -*-
1
+ # encoding: utf-8
2
2
  module Warden
3
- VERSION = "2.0.0".freeze
3
+ VERSION = "1.2.3".freeze
4
4
  end
@@ -4,20 +4,23 @@ require './lib/warden/version'
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = %q{loyal_warden}
7
- s.version = Warden::VERSION.dup
7
+ # s.version = Warden::VERSION.dup
8
+ s.version = '2.0.1'
8
9
  s.authors = ["Daniel Neighman"]
9
- s.email = %q{andywang7259@gmail.com}
10
+ s.email = %q{has.sox@gmail.com}
11
+ s.license = "MIT"
10
12
  s.extra_rdoc_files = [
11
13
  "LICENSE",
12
14
  "README.textile"
13
15
  ]
14
16
  s.files = Dir["**/*"] - Dir["*.gem"] - ["Gemfile.lock"]
15
- s.homepage = %q{http://github.com/blogsoso/warden}
17
+ s.homepage = %q{http://github.com/hassox/warden}
16
18
  s.rdoc_options = ["--charset=UTF-8"]
17
19
  s.require_paths = ["lib"]
18
20
  s.rubyforge_project = %q{warden}
19
21
  s.rubygems_version = %q{1.3.7}
20
22
  s.summary = %q{Rack middleware that provides authentication for rack applications}
23
+
21
24
  s.add_dependency "rack", ">= 1.0"
22
25
  end
23
26
 
@@ -1,4 +1,4 @@
1
- # -*- encoding : utf-8 -*-
1
+ # encoding: utf-8
2
2
  module Warden::Spec
3
3
  module Helpers
4
4
  FAILURE_APP = lambda{|e|[401, {"Content-Type" => "text/plain"}, ["You Fail!"]] }
@@ -18,7 +18,7 @@ module Warden::Spec
18
18
  blk = opts[:configurator] || proc{}
19
19
 
20
20
  Rack::Builder.new do
21
- use opts[:session] || Warden::Spec::Helpers::Session
21
+ use opts[:session] || Warden::Spec::Helpers::Session unless opts[:nil_session]
22
22
  use Warden::Manager, opts, &blk
23
23
  run app
24
24
  end
@@ -1,4 +1,4 @@
1
- # -*- encoding : utf-8 -*-
1
+ # encoding: utf-8
2
2
  Warden::Strategies.add(:failz) do
3
3
  def authenticate!
4
4
  request.env['warden.spec.strategies'] ||= []
@@ -1,8 +1,8 @@
1
- # -*- encoding : utf-8 -*-
1
+ # encoding: utf-8
2
2
  Warden::Strategies.add(:invalid) do
3
3
  def valid?
4
4
  false
5
5
  end
6
6
 
7
7
  def authenticate!; end
8
- end
8
+ end
@@ -1,4 +1,4 @@
1
- # -*- encoding : utf-8 -*-
1
+ # encoding: utf-8
2
2
  Warden::Strategies.add(:pass) do
3
3
  def authenticate!
4
4
  request.env['warden.spec.strategies'] ||= []
@@ -1,4 +1,4 @@
1
- # -*- encoding : utf-8 -*-
1
+ # encoding: utf-8
2
2
  Warden::Strategies.add(:pass_with_message) do
3
3
  def authenticate!
4
4
  request.env['warden.spec.strategies'] ||= []
@@ -1,4 +1,4 @@
1
- # -*- encoding : utf-8 -*-
1
+ # encoding: utf-8
2
2
  Warden::Strategies.add(:password) do
3
3
  def authenticate!
4
4
  request.env['warden.spec.strategies'] ||= []
@@ -1,4 +1,4 @@
1
- # -*- encoding : utf-8 -*-
1
+ # encoding: utf-8
2
2
  Warden::Strategies.add(:single) do
3
3
  def authenticate!
4
4
  request.env['warden.spec.strategies'] ||= []
@@ -1,4 +1,4 @@
1
- # -*- encoding : utf-8 -*-
1
+ # encoding: utf-8
2
2
  $TESTING=true
3
3
 
4
4
  $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
@@ -1,4 +1,4 @@
1
- # -*- encoding : utf-8 -*-
1
+ # encoding: utf-8
2
2
  require 'spec_helper'
3
3
 
4
4
  describe "authenticated data store" do
@@ -1,4 +1,4 @@
1
- # -*- encoding : utf-8 -*-
1
+ # encoding: utf-8
2
2
  require 'spec_helper'
3
3
 
4
4
  describe Warden::Config do
@@ -1,4 +1,4 @@
1
- # -*- encoding : utf-8 -*-
1
+ # encoding: utf-8
2
2
  require 'spec_helper'
3
3
 
4
4
  describe Warden::Proxy::Errors do
@@ -1,4 +1,4 @@
1
- # -*- encoding : utf-8 -*-
1
+ # encoding: utf-8
2
2
  require 'spec_helper'
3
3
 
4
4
  describe "standard authentication hooks" do
@@ -1,4 +1,4 @@
1
- # -*- encoding : utf-8 -*-
1
+ # encoding: utf-8
2
2
  require 'spec_helper'
3
3
 
4
4
  describe Warden::Manager do
@@ -1,8 +1,7 @@
1
- # -*- encoding : utf-8 -*-
1
+ # encoding: utf-8
2
2
  require 'spec_helper'
3
3
 
4
4
  describe Warden::Proxy do
5
-
6
5
  before(:all) do
7
6
  load_strategies
8
7
  end
@@ -340,7 +339,6 @@ describe Warden::Proxy do
340
339
  end
341
340
  setup_rack(app).call(@env)
342
341
  end
343
-
344
342
  end
345
343
 
346
344
  describe "set user" do
@@ -366,6 +364,17 @@ describe Warden::Proxy do
366
364
  setup_rack(app).call(@env)
367
365
  end
368
366
 
367
+ it "should not throw error when no session is configured and store is false" do
368
+ app = lambda do |env|
369
+ env['rack.session'] = nil
370
+ env['warden'].authenticate(:pass, :store => false)
371
+ env['warden'].should be_authenticated
372
+ env['warden'].user.should == "Valid User"
373
+ valid_response
374
+ end
375
+ setup_rack(app).call(@env)
376
+ end
377
+
369
378
  it "should not run the callbacks when :run_callbacks is false" do
370
379
  app = lambda do |env|
371
380
  env['warden'].manager.should_not_receive(:_run_callbacks)
@@ -512,7 +521,6 @@ describe Warden::Proxy do
512
521
  end
513
522
 
514
523
  describe "logout" do
515
-
516
524
  before(:each) do
517
525
  @env['rack.session'] = {"warden.user.default.key" => "default key", "warden.user.foo.key" => "foo key", :foo => "bar"}
518
526
  @app = lambda do |e|
@@ -549,6 +557,13 @@ describe Warden::Proxy do
549
557
  @env['rack.session'].should be_empty
550
558
  end
551
559
 
560
+ it "should not raise exception if raw_session is nil" do
561
+ @app = setup_rack(@app, { nil_session: true })
562
+ @env['rack.session'] = nil
563
+ @env['warden.spec.which_logout'] = :foo
564
+ expect { @app.call(@env) }.to_not raise_error(NoMethodError)
565
+ end
566
+
552
567
  it "should clear the user when logging out" do
553
568
  @env['rack.session'].should_not be_nil
554
569
  app = lambda do |e|
@@ -665,7 +680,7 @@ describe Warden::Proxy do
665
680
  app = lambda do |e|
666
681
  e['warden'].should be_authenticated
667
682
  end
668
- result = setup_rack(app).call(@env)
683
+ setup_rack(app).call(@env)
669
684
  end
670
685
 
671
686
  it "should yield to a block when the block is passed and authenticated" do
@@ -700,7 +715,7 @@ describe Warden::Proxy do
700
715
  app = lambda do |e|
701
716
  e['warden'].should_not be_authenticated
702
717
  end
703
- result = setup_rack(app).call(@env)
718
+ setup_rack(app).call(@env)
704
719
  end
705
720
 
706
721
  it "should return false if scope cannot be retrieved from session" do
@@ -786,7 +801,7 @@ describe Warden::Proxy do
786
801
  app = lambda do |e|
787
802
  e['warden'].should be_unauthenticated
788
803
  end
789
- result = setup_rack(app).call(@env)
804
+ setup_rack(app).call(@env)
790
805
  end
791
806
 
792
807
  it "should yield to a block when the block is passed and authenticated" do
@@ -828,6 +843,8 @@ end
828
843
 
829
844
  describe "dynamic default_strategies" do
830
845
  before(:all) do
846
+ load_strategies
847
+
831
848
  class ::DynamicDefaultStrategies
832
849
  def initialize(app, &blk)
833
850
  @app, @blk = app, blk
@@ -1,4 +1,4 @@
1
- # -*- encoding : utf-8 -*-
1
+ # encoding: utf-8
2
2
  require 'spec_helper'
3
3
 
4
4
  describe Warden::Manager do
@@ -1,4 +1,4 @@
1
- # -*- encoding : utf-8 -*-
1
+ # encoding: utf-8
2
2
  require 'spec_helper'
3
3
 
4
4
  describe Warden::SessionSerializer do
@@ -45,4 +45,9 @@ describe Warden::SessionSerializer do
45
45
  @session.fetch(:default)
46
46
  @env['rack.session'].should_not have_key("warden.user.default.key")
47
47
  end
48
+
49
+ it "should support a nil session store" do
50
+ @env['rack.session'] = nil
51
+ @session.fetch(:default).should be_nil
52
+ end
48
53
  end
@@ -1,4 +1,4 @@
1
- # -*- encoding : utf-8 -*-
1
+ # encoding: utf-8
2
2
  require 'spec_helper'
3
3
 
4
4
  describe Warden::Strategies::Base do
@@ -1,4 +1,4 @@
1
- # -*- encoding : utf-8 -*-
1
+ # encoding: utf-8
2
2
  require 'spec_helper'
3
3
 
4
4
  describe Warden::Strategies do
@@ -11,13 +11,23 @@ describe Warden::Strategies do
11
11
  Warden::Strategies[:strategy1].ancestors.should include(Warden::Strategies::Base)
12
12
  end
13
13
 
14
- it "should raise an error if I add a strategy via a block, that does not have an autheniticate! method" do
14
+ it "should raise an error if I add a strategy via a block, that does not have an authenticate! method" do
15
15
  lambda do
16
16
  Warden::Strategies.add(:strategy2) do
17
17
  end
18
18
  end.should raise_error
19
19
  end
20
20
 
21
+ it "should raise an error if I add a strategy that does not extend Warden::Strategies::Base" do
22
+ non_base = Class.new do
23
+ def authenticate!
24
+ end
25
+ end
26
+ expect do
27
+ Warden::Strategies.add(:strategy_non_base, non_base)
28
+ end.to raise_error(/is not a Warden::Strategies::Base/)
29
+ end
30
+
21
31
  it "should allow me to get access to a particular strategy" do
22
32
  Warden::Strategies.add(:strategy3) do
23
33
  def authenticate!; end
@@ -1,4 +1,4 @@
1
- # -*- encoding : utf-8 -*-
1
+ # encoding: utf-8
2
2
  require 'spec_helper'
3
3
 
4
4
  describe Warden::Test::Helpers do
@@ -1,4 +1,4 @@
1
- # -*- encoding : utf-8 -*-
1
+ # encoding: utf-8
2
2
  require 'spec_helper'
3
3
 
4
4
  describe Warden::Test::WardenHelpers do
@@ -7,6 +7,7 @@ Gem::Specification.new do |s|
7
7
  s.version = Warden::VERSION.dup
8
8
  s.authors = ["Daniel Neighman"]
9
9
  s.email = %q{has.sox@gmail.com}
10
+ s.license = "MIT"
10
11
  s.extra_rdoc_files = [
11
12
  "LICENSE",
12
13
  "README.textile"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: loyal_warden
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-16 00:00:00.000000000 Z
12
+ date: 2013-08-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack
@@ -28,7 +28,7 @@ dependencies:
28
28
  - !ruby/object:Gem::Version
29
29
  version: '1.0'
30
30
  description:
31
- email: andywang7259@gmail.com
31
+ email: has.sox@gmail.com
32
32
  executables: []
33
33
  extensions: []
34
34
  extra_rdoc_files:
@@ -49,6 +49,7 @@ files:
49
49
  - lib/warden/errors.rb
50
50
  - lib/warden/session_serializer.rb
51
51
  - lib/warden.rb
52
+ - lib/loyal_warden.rb
52
53
  - warden.gemspec
53
54
  - History.rdoc
54
55
  - spec/warden/hooks_spec.rb
@@ -75,8 +76,9 @@ files:
75
76
  - Gemfile
76
77
  - Rakefile
77
78
  - README.textile
78
- homepage: http://github.com/blogsoso/warden
79
- licenses: []
79
+ homepage: http://github.com/hassox/warden
80
+ licenses:
81
+ - MIT
80
82
  post_install_message:
81
83
  rdoc_options:
82
84
  - "--charset=UTF-8"