loyal_warden 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. data/Gemfile +11 -0
  2. data/History.rdoc +150 -0
  3. data/LICENSE +20 -0
  4. data/README.textile +9 -0
  5. data/Rakefile +12 -0
  6. data/lib/loyal_warden.rb +2 -0
  7. data/lib/warden.rb +45 -0
  8. data/lib/warden/config.rb +112 -0
  9. data/lib/warden/errors.rb +66 -0
  10. data/lib/warden/hooks.rb +211 -0
  11. data/lib/warden/manager.rb +136 -0
  12. data/lib/warden/mixins/common.rb +44 -0
  13. data/lib/warden/proxy.rb +371 -0
  14. data/lib/warden/session_serializer.rb +52 -0
  15. data/lib/warden/strategies.rb +47 -0
  16. data/lib/warden/strategies/base.rb +175 -0
  17. data/lib/warden/test/helpers.rb +36 -0
  18. data/lib/warden/test/warden_helpers.rb +43 -0
  19. data/lib/warden/version.rb +4 -0
  20. data/loyal_warden.gemspec +26 -0
  21. data/spec/helpers/request_helper.rb +51 -0
  22. data/spec/helpers/strategies/failz.rb +8 -0
  23. data/spec/helpers/strategies/invalid.rb +8 -0
  24. data/spec/helpers/strategies/pass.rb +8 -0
  25. data/spec/helpers/strategies/pass_with_message.rb +8 -0
  26. data/spec/helpers/strategies/password.rb +13 -0
  27. data/spec/helpers/strategies/single.rb +12 -0
  28. data/spec/spec_helper.rb +24 -0
  29. data/spec/warden/authenticated_data_store_spec.rb +114 -0
  30. data/spec/warden/config_spec.rb +48 -0
  31. data/spec/warden/errors_spec.rb +47 -0
  32. data/spec/warden/hooks_spec.rb +373 -0
  33. data/spec/warden/manager_spec.rb +316 -0
  34. data/spec/warden/proxy_spec.rb +1041 -0
  35. data/spec/warden/scoped_session_serializer.rb +123 -0
  36. data/spec/warden/session_serializer_spec.rb +53 -0
  37. data/spec/warden/strategies/base_spec.rb +313 -0
  38. data/spec/warden/strategies_spec.rb +93 -0
  39. data/spec/warden/test/helpers_spec.rb +93 -0
  40. data/spec/warden/test/test_mode_spec.rb +76 -0
  41. data/warden.gemspec +24 -0
  42. metadata +105 -0
@@ -0,0 +1,93 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Warden::Strategies do
5
+ it "should let me add a strategy via a block" do
6
+ Warden::Strategies.add(:strategy1) do
7
+ def authenticate!
8
+ success("foo")
9
+ end
10
+ end
11
+ Warden::Strategies[:strategy1].ancestors.should include(Warden::Strategies::Base)
12
+ end
13
+
14
+ it "should raise an error if I add a strategy via a block, that does not have an authenticate! method" do
15
+ lambda do
16
+ Warden::Strategies.add(:strategy2) do
17
+ end
18
+ end.should raise_error
19
+ end
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
+
31
+ it "should allow me to get access to a particular strategy" do
32
+ Warden::Strategies.add(:strategy3) do
33
+ def authenticate!; end
34
+ end
35
+ strategy = Warden::Strategies[:strategy3]
36
+ strategy.should_not be_nil
37
+ strategy.ancestors.should include(Warden::Strategies::Base)
38
+ end
39
+
40
+ it "should allow me to add a strategy with the required methods" do
41
+ class MyStrategy < Warden::Strategies::Base
42
+ def authenticate!; end
43
+ end
44
+ lambda do
45
+ Warden::Strategies.add(:strategy4, MyStrategy)
46
+ end.should_not raise_error
47
+ end
48
+
49
+ it "should not allow a strategy that does not have an authenticate! method" do
50
+ class MyOtherStrategy
51
+ end
52
+ lambda do
53
+ Warden::Strategies.add(:strategy5, MyOtherStrategy)
54
+ end.should raise_error
55
+ end
56
+
57
+ it "should allow me to change a class when providing a block and class" do
58
+ class MyStrategy < Warden::Strategies::Base
59
+ end
60
+
61
+ Warden::Strategies.add(:foo, MyStrategy) do
62
+ def authenticate!; end
63
+ end
64
+
65
+ Warden::Strategies[:foo].ancestors.should include(MyStrategy)
66
+ end
67
+
68
+ it "should allow me to update a previously given strategy" do
69
+ class MyStrategy < Warden::Strategies::Base
70
+ def authenticate!; end
71
+ end
72
+
73
+ Warden::Strategies.add(:strategy6, MyStrategy)
74
+
75
+ new_module = Module.new
76
+ Warden::Strategies.update(:strategy6) do
77
+ include new_module
78
+ end
79
+
80
+ Warden::Strategies[:strategy6].ancestors.should include(new_module)
81
+ end
82
+
83
+ it "should allow me to clear the strategies" do
84
+ Warden::Strategies.add(:foobar) do
85
+ def authenticate!
86
+ :foo
87
+ end
88
+ end
89
+ Warden::Strategies[:foobar].should_not be_nil
90
+ Warden::Strategies.clear!
91
+ Warden::Strategies[:foobar].should be_nil
92
+ end
93
+ end
@@ -0,0 +1,93 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Warden::Test::Helpers do
5
+ before{ $captures = [] }
6
+ after{ Warden.test_reset! }
7
+
8
+ it "should log me in as a user" do
9
+ user = "A User"
10
+ login_as user
11
+ app = lambda{|e|
12
+ $captures << :run
13
+ e['warden'].should be_authenticated
14
+ e['warden'].user.should == "A User"
15
+ valid_response
16
+ }
17
+ setup_rack(app).call(env_with_params)
18
+ $captures.should == [:run]
19
+ end
20
+
21
+ it "should log me in as a user of a given scope" do
22
+ user = {:some => "user"}
23
+ login_as user, :scope => :foo_scope
24
+ app = lambda{|e|
25
+ $captures << :run
26
+ w = e['warden']
27
+ w.should be_authenticated(:foo_scope)
28
+ w.user(:foo_scope).should == {:some => "user"}
29
+ }
30
+ setup_rack(app).call(env_with_params)
31
+ $captures.should == [:run]
32
+ end
33
+
34
+ it "should login multiple users with different scopes" do
35
+ user = "A user"
36
+ foo_user = "A foo user"
37
+ login_as user
38
+ login_as foo_user, :scope => :foo
39
+ app = lambda{|e|
40
+ $captures << :run
41
+ w = e['warden']
42
+ w.user.should == "A user"
43
+ w.user(:foo).should == "A foo user"
44
+ w.should be_authenticated
45
+ w.should be_authenticated(:foo)
46
+ }
47
+ setup_rack(app).call(env_with_params)
48
+ $captures.should == [:run]
49
+ end
50
+
51
+ it "should log out all users" do
52
+ user = "A user"
53
+ foo = "Foo"
54
+ login_as user
55
+ login_as foo, :scope => :foo
56
+ app = lambda{|e|
57
+ $captures << :run
58
+ w = e['warden']
59
+ w.user.should == "A user"
60
+ w.user(:foo).should == "Foo"
61
+ w.logout
62
+ w.user.should be_nil
63
+ w.user(:foo).should be_nil
64
+ w.should_not be_authenticated
65
+ w.should_not be_authenticated(:foo)
66
+ }
67
+ setup_rack(app).call(env_with_params)
68
+ $captures.should == [:run]
69
+ end
70
+
71
+ it "should logout a specific user" do
72
+ user = "A User"
73
+ foo = "Foo"
74
+ login_as user
75
+ login_as foo, :scope => :foo
76
+ app = lambda{|e|
77
+ $captures << :run
78
+ w = e['warden']
79
+ w.logout :foo
80
+ w.user.should == "A User"
81
+ w.user(:foo).should be_nil
82
+ w.should_not be_authenticated(:foo)
83
+ }
84
+ setup_rack(app).call(env_with_params)
85
+ $captures.should == [:run]
86
+ end
87
+
88
+ describe "#asset_paths" do
89
+ it "should default asset_paths to anything asset path regex" do
90
+ Warden.asset_paths.should == [/^\/assets\//]
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,76 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Warden::Test::WardenHelpers do
5
+ before :all do
6
+ Warden.test_mode!
7
+ end
8
+
9
+ before do
10
+ $captures = []
11
+ @app = lambda{|e| valid_response }
12
+ end
13
+
14
+ after do
15
+ Warden.test_reset!
16
+ end
17
+
18
+ it{ Warden.should respond_to(:test_mode!) }
19
+ it{ Warden.should respond_to(:on_next_request) }
20
+ it{ Warden.should respond_to(:test_reset!) }
21
+
22
+ it "should execute the on_next_request block on the next request" do
23
+ Warden.on_next_request do |warden|
24
+ $captures << warden
25
+ end
26
+
27
+ setup_rack(@app).call(env_with_params)
28
+ $captures.should have(1).item
29
+ $captures.first.should be_an_instance_of(Warden::Proxy)
30
+ end
31
+
32
+ it "should execute many on_next_request blocks on the next request" do
33
+ Warden.on_next_request{|w| $captures << :first }
34
+ Warden.on_next_request{|w| $captures << :second }
35
+ setup_rack(@app).call(env_with_params)
36
+ $captures.should have(2).items
37
+ $captures.should == [:first, :second]
38
+ end
39
+
40
+ it "should not execute on_next_request blocks on subsequent requests" do
41
+ app = setup_rack(@app)
42
+ Warden.on_next_request{|w| $captures << :first }
43
+ app.call(env_with_params)
44
+ $captures.should == [:first]
45
+ $captures.clear
46
+ app.call(env_with_params)
47
+ $captures.should be_empty
48
+ end
49
+
50
+ it "should allow me to set new_on_next_request items to execute in the same test" do
51
+ app = setup_rack(@app)
52
+ Warden.on_next_request{|w| $captures << :first }
53
+ app.call(env_with_params)
54
+ $captures.should == [:first]
55
+ Warden.on_next_request{|w| $captures << :second }
56
+ app.call(env_with_params)
57
+ $captures.should == [:first, :second]
58
+ end
59
+
60
+ it "should remove the on_next_request items when test is reset" do
61
+ app = setup_rack(@app)
62
+ Warden.on_next_request{|w| $captures << :first }
63
+ Warden.test_reset!
64
+ app.call(env_with_params)
65
+ $captures.should == []
66
+ end
67
+
68
+ context "asset requests" do
69
+ it "should not execute on_next_request blocks if this is an asset request" do
70
+ app = setup_rack(@app)
71
+ Warden.on_next_request{|w| $captures << :first }
72
+ app.call(env_with_params("/assets/fun.gif"))
73
+ $captures.should == []
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require './lib/warden/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = %q{warden}
7
+ s.version = Warden::VERSION.dup
8
+ s.authors = ["Daniel Neighman"]
9
+ s.email = %q{has.sox@gmail.com}
10
+ s.license = "MIT"
11
+ s.extra_rdoc_files = [
12
+ "LICENSE",
13
+ "README.textile"
14
+ ]
15
+ s.files = Dir["**/*"] - Dir["*.gem"] - ["Gemfile.lock"]
16
+ s.homepage = %q{http://github.com/hassox/warden}
17
+ s.rdoc_options = ["--charset=UTF-8"]
18
+ s.require_paths = ["lib"]
19
+ s.rubyforge_project = %q{warden}
20
+ s.rubygems_version = %q{1.3.7}
21
+ s.summary = %q{Rack middleware that provides authentication for rack applications}
22
+ s.add_dependency "rack", ">= 1.0"
23
+ end
24
+
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: loyal_warden
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.5
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Daniel Neighman
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-08-01 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rack
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ">="
20
+ - !ruby/object:Gem::Version
21
+ version: '1.0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '1.0'
30
+ description:
31
+ email: has.sox@gmail.com
32
+ executables: []
33
+ extensions: []
34
+ extra_rdoc_files:
35
+ - LICENSE
36
+ - README.textile
37
+ files:
38
+ - loyal_warden.gemspec
39
+ - lib/warden/strategies/base.rb
40
+ - lib/warden/proxy.rb
41
+ - lib/warden/mixins/common.rb
42
+ - lib/warden/test/helpers.rb
43
+ - lib/warden/test/warden_helpers.rb
44
+ - lib/warden/config.rb
45
+ - lib/warden/hooks.rb
46
+ - lib/warden/version.rb
47
+ - lib/warden/strategies.rb
48
+ - lib/warden/manager.rb
49
+ - lib/warden/errors.rb
50
+ - lib/warden/session_serializer.rb
51
+ - lib/warden.rb
52
+ - lib/loyal_warden.rb
53
+ - warden.gemspec
54
+ - History.rdoc
55
+ - spec/warden/hooks_spec.rb
56
+ - spec/warden/manager_spec.rb
57
+ - spec/warden/strategies/base_spec.rb
58
+ - spec/warden/config_spec.rb
59
+ - spec/warden/test/test_mode_spec.rb
60
+ - spec/warden/test/helpers_spec.rb
61
+ - spec/warden/proxy_spec.rb
62
+ - spec/warden/session_serializer_spec.rb
63
+ - spec/warden/scoped_session_serializer.rb
64
+ - spec/warden/strategies_spec.rb
65
+ - spec/warden/errors_spec.rb
66
+ - spec/warden/authenticated_data_store_spec.rb
67
+ - spec/helpers/strategies/password.rb
68
+ - spec/helpers/strategies/failz.rb
69
+ - spec/helpers/strategies/single.rb
70
+ - spec/helpers/strategies/invalid.rb
71
+ - spec/helpers/strategies/pass.rb
72
+ - spec/helpers/strategies/pass_with_message.rb
73
+ - spec/helpers/request_helper.rb
74
+ - spec/spec_helper.rb
75
+ - LICENSE
76
+ - Gemfile
77
+ - Rakefile
78
+ - README.textile
79
+ homepage: http://github.com/hassox/warden
80
+ licenses:
81
+ - MIT
82
+ post_install_message:
83
+ rdoc_options:
84
+ - "--charset=UTF-8"
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ requirements: []
100
+ rubyforge_project: warden
101
+ rubygems_version: 1.8.25
102
+ signing_key:
103
+ specification_version: 3
104
+ summary: Rack middleware that provides authentication for rack applications
105
+ test_files: []