sorcery 0.5.1 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of sorcery might be problematic. Click here for more details.

Files changed (49) hide show
  1. data/README.rdoc +1 -1
  2. data/VERSION +1 -1
  3. data/lib/sorcery.rb +3 -5
  4. data/lib/sorcery/controller/adapters/sinatra.rb +35 -28
  5. data/lib/sorcery/controller/submodules/http_basic_auth.rb +1 -1
  6. data/lib/sorcery/engine.rb +0 -7
  7. data/lib/sorcery/initializers/initializer.rb +4 -2
  8. data/lib/sorcery/model.rb +2 -3
  9. data/lib/sorcery/test_helpers/internal/rails.rb +1 -0
  10. data/lib/sorcery/test_helpers/internal/sinatra.rb +3 -3
  11. data/lib/sorcery/test_helpers/internal/sinatra_modular.rb +74 -0
  12. data/sorcery.gemspec +54 -2
  13. data/spec/Gemfile.lock +1 -1
  14. data/spec/rails3/Gemfile.lock +1 -1
  15. data/spec/rails3/spec/user_spec.rb +0 -10
  16. data/spec/rails3_mongoid/Gemfile.lock +1 -1
  17. data/spec/rails3_mongoid/spec/user_spec.rb +0 -10
  18. data/spec/sinatra/Gemfile.lock +1 -1
  19. data/spec/sinatra/Rakefile +1 -1
  20. data/spec/sinatra/filters.rb +20 -14
  21. data/spec/sinatra/modular.rb +157 -0
  22. data/spec/sinatra_modular/Gemfile +15 -0
  23. data/spec/sinatra_modular/Gemfile.lock +117 -0
  24. data/spec/sinatra_modular/Rakefile +11 -0
  25. data/spec/sinatra_modular/authentication.rb +3 -0
  26. data/spec/sinatra_modular/db/migrate/activation/20101224223622_add_activation_to_users.rb +17 -0
  27. data/spec/sinatra_modular/db/migrate/activity_logging/20101224223624_add_activity_logging_to_users.rb +17 -0
  28. data/spec/sinatra_modular/db/migrate/brute_force_protection/20101224223626_add_brute_force_protection_to_users.rb +11 -0
  29. data/spec/sinatra_modular/db/migrate/core/20101224223620_create_users.rb +16 -0
  30. data/spec/sinatra_modular/db/migrate/external/20101224223628_create_authentications.rb +14 -0
  31. data/spec/sinatra_modular/db/migrate/remember_me/20101224223623_add_remember_me_token_to_users.rb +15 -0
  32. data/spec/sinatra_modular/db/migrate/reset_password/20101224223622_add_reset_password_to_users.rb +13 -0
  33. data/spec/sinatra_modular/filters.rb +27 -0
  34. data/spec/sinatra_modular/modular.rb +157 -0
  35. data/spec/sinatra_modular/myapp.rb +133 -0
  36. data/spec/sinatra_modular/sorcery_mailer.rb +25 -0
  37. data/spec/sinatra_modular/spec_modular/controller_activity_logging_spec.rb +85 -0
  38. data/spec/sinatra_modular/spec_modular/controller_brute_force_protection_spec.rb +70 -0
  39. data/spec/sinatra_modular/spec_modular/controller_http_basic_auth_spec.rb +53 -0
  40. data/spec/sinatra_modular/spec_modular/controller_oauth2_spec.rb +120 -0
  41. data/spec/sinatra_modular/spec_modular/controller_oauth_spec.rb +121 -0
  42. data/spec/sinatra_modular/spec_modular/controller_remember_me_spec.rb +64 -0
  43. data/spec/sinatra_modular/spec_modular/controller_session_timeout_spec.rb +57 -0
  44. data/spec/sinatra_modular/spec_modular/controller_spec.rb +116 -0
  45. data/spec/sinatra_modular/spec_modular/spec.opts +2 -0
  46. data/spec/sinatra_modular/spec_modular/spec_helper.rb +51 -0
  47. data/spec/sinatra_modular/user.rb +6 -0
  48. data/spec/sinatra_modular/views/test_login.erb +4 -0
  49. metadata +54 -2
@@ -0,0 +1,116 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe Modular do
4
+
5
+ # ----------------- PLUGIN CONFIGURATION -----------------------
6
+ describe "plugin configuration" do
7
+ before(:all) do
8
+ sorcery_reload!
9
+ end
10
+
11
+ after(:each) do
12
+ Sorcery::Controller::Config.reset!
13
+ sorcery_reload!
14
+ end
15
+
16
+ it "should enable configuration option 'user_class'" do
17
+ sorcery_controller_property_set(:user_class, TestUser)
18
+ Sorcery::Controller::Config.user_class.should equal(TestUser)
19
+ end
20
+
21
+ it "should enable configuration option 'not_authenticated_action'" do
22
+ sorcery_controller_property_set(:not_authenticated_action, :my_action)
23
+ Sorcery::Controller::Config.not_authenticated_action.should equal(:my_action)
24
+ end
25
+
26
+ end
27
+
28
+ # ----------------- PLUGIN ACTIVATED -----------------------
29
+ describe Modular, "when activated with sorcery" do
30
+
31
+ before(:all) do
32
+ sorcery_reload!
33
+ User.delete_all
34
+ create_new_user
35
+ end
36
+
37
+ it "should respond to the instance method login" do
38
+ get_sinatra_app(subject).should respond_to(:login)
39
+ end
40
+
41
+ it "should respond to the instance method logout" do
42
+ get_sinatra_app(subject).should respond_to(:logout)
43
+ end
44
+
45
+ it "should respond to the instance method logged_in?" do
46
+ get_sinatra_app(subject).should respond_to(:logged_in?)
47
+ end
48
+
49
+ it "should respond to the instance method current_user" do
50
+ get_sinatra_app(subject).should respond_to(:current_user)
51
+ end
52
+
53
+ it "login(username,password) should return the user when success and set the session with user.id" do
54
+ get "/test_login", :username => 'gizmo', :password => 'secret'
55
+ assigns[:user].should == @user
56
+ session[:user_id].should == @user.id
57
+ end
58
+
59
+ it "login(username,password) should return nil and not set the session when failure" do
60
+ get "/test_login", :username => 'gizmo', :password => 'opensesame!'
61
+ assigns[:user].should be_nil
62
+ session[:user_id].should be_nil
63
+ end
64
+
65
+ it "logout should clear the session" do
66
+ get "/test_logout"
67
+ session[:user_id].should be_nil
68
+ end
69
+
70
+ it "logged_in? should return true if logged in" do
71
+ get "/test_login", :username => 'gizmo', :password => 'secret'
72
+ assigns[:logged_in].should be_true
73
+ end
74
+
75
+ it "logged_in? should return false if not logged in" do
76
+ get "/test_login", :username => 'gizmo', :password => 'opensesame!'
77
+ assigns[:logged_in].should be_false
78
+ end
79
+
80
+ it "current_user should return the user instance if logged in" do
81
+ create_new_user
82
+ get "/test_current_user", :id => @user.id
83
+ assigns[:current_user].should == @user
84
+ end
85
+
86
+ it "current_user should return false if not logged in" do
87
+ get "/test_logout"
88
+ assigns[:current_user].should == false
89
+ end
90
+
91
+ it "should respond to 'require_login'" do
92
+ get_sinatra_app(subject).should respond_to(:require_login)
93
+ end
94
+
95
+ it "should call the configured 'not_authenticated_action' when authenticate before_filter fails" do
96
+ sorcery_controller_property_set(:not_authenticated_action, :test_not_authenticated_action)
97
+ get "/test_logout"
98
+ last_response.body.should == "test_not_authenticated_action"
99
+ end
100
+
101
+ it "require_login before_filter should save the url that the user originally wanted" do
102
+ sorcery_controller_property_set(:not_authenticated_action, :not_authenticated2)
103
+ get "/some_action"
104
+ assigns[:session][:return_to_url].should == "http://example.org/some_action"
105
+ last_response.status.should == 302
106
+ last_response.should redirect_to("http://example.org/")
107
+ end
108
+
109
+ it "on successful login the user should be redirected to the url he originally wanted" do
110
+ post "/test_return_to", :username => 'gizmo', :password => 'secret', :return_to_url => "http://example.org/blabla"
111
+ last_response.should redirect_to("http://example.org/blabla")
112
+ end
113
+
114
+ end
115
+
116
+ end
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
@@ -0,0 +1,51 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'modular.rb')
2
+ $: << APP_ROOT # for model reloading
3
+
4
+ require 'rack/test'
5
+ require 'rspec'
6
+ require 'timecop'
7
+
8
+ # set test environment
9
+ Modular.class_eval do
10
+ set :environment, :test
11
+ set :run, false
12
+ set :raise_errors, true
13
+ set :logging, false
14
+ set :lock, true
15
+ set :show_exceptions, true
16
+ end
17
+
18
+
19
+ module RSpecMixinExample
20
+ include Rack::Test::Methods
21
+
22
+ def app
23
+ @app ||= Modular
24
+ end
25
+ end
26
+
27
+ Rspec.configure do |config|
28
+ config.send(:include, RSpecMixinExample)
29
+ config.send(:include, ::Sorcery::TestHelpers::Internal)
30
+ config.send(:include, ::Sorcery::TestHelpers::Internal::SinatraModular)
31
+ config.before(:suite) do
32
+ ActiveRecord::Migrator.migrate("#{APP_ROOT}/db/migrate/core")
33
+ end
34
+
35
+ config.after(:suite) do
36
+ ActiveRecord::Migrator.rollback("#{APP_ROOT}/db/migrate/core")
37
+ end
38
+
39
+ end
40
+
41
+ # needed when running individual specs
42
+ require File.join(File.dirname(__FILE__), '..', 'user')
43
+ require File.join(File.dirname(__FILE__), '..', 'authentication')
44
+
45
+ class TestUser < ActiveRecord::Base
46
+ authenticates_with_sorcery!
47
+ end
48
+
49
+ class TestMailer < ActionMailer::Base
50
+
51
+ end
@@ -0,0 +1,6 @@
1
+ class User < ActiveRecord::Base
2
+ attr_accessible :email, :password, :password_confirmation, :authentications_attributes
3
+
4
+ has_many :authentications, :dependent => :destroy
5
+ accepts_nested_attributes_for :authentications
6
+ end
@@ -0,0 +1,4 @@
1
+ <%= @user %> bla bla
2
+
3
+ hourdyasd
4
+ <bla>
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: sorcery
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.5.1
5
+ version: 0.5.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Noam Ben Ari
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-05-11 00:00:00 +03:00
13
+ date: 2011-05-19 00:00:00 +03:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -275,6 +275,7 @@ files:
275
275
  - lib/sorcery/test_helpers/internal.rb
276
276
  - lib/sorcery/test_helpers/internal/rails.rb
277
277
  - lib/sorcery/test_helpers/internal/sinatra.rb
278
+ - lib/sorcery/test_helpers/internal/sinatra_modular.rb
278
279
  - lib/sorcery/test_helpers/rails.rb
279
280
  - lib/sorcery/test_helpers/sinatra.rb
280
281
  - sorcery.gemspec
@@ -433,6 +434,7 @@ files:
433
434
  - spec/sinatra/db/migrate/remember_me/20101224223623_add_remember_me_token_to_users.rb
434
435
  - spec/sinatra/db/migrate/reset_password/20101224223622_add_reset_password_to_users.rb
435
436
  - spec/sinatra/filters.rb
437
+ - spec/sinatra/modular.rb
436
438
  - spec/sinatra/myapp.rb
437
439
  - spec/sinatra/sorcery_mailer.rb
438
440
  - spec/sinatra/spec/controller_activity_logging_spec.rb
@@ -447,6 +449,33 @@ files:
447
449
  - spec/sinatra/spec/spec_helper.rb
448
450
  - spec/sinatra/user.rb
449
451
  - spec/sinatra/views/test_login.erb
452
+ - spec/sinatra_modular/Gemfile
453
+ - spec/sinatra_modular/Gemfile.lock
454
+ - spec/sinatra_modular/Rakefile
455
+ - spec/sinatra_modular/authentication.rb
456
+ - spec/sinatra_modular/db/migrate/activation/20101224223622_add_activation_to_users.rb
457
+ - spec/sinatra_modular/db/migrate/activity_logging/20101224223624_add_activity_logging_to_users.rb
458
+ - spec/sinatra_modular/db/migrate/brute_force_protection/20101224223626_add_brute_force_protection_to_users.rb
459
+ - spec/sinatra_modular/db/migrate/core/20101224223620_create_users.rb
460
+ - spec/sinatra_modular/db/migrate/external/20101224223628_create_authentications.rb
461
+ - spec/sinatra_modular/db/migrate/remember_me/20101224223623_add_remember_me_token_to_users.rb
462
+ - spec/sinatra_modular/db/migrate/reset_password/20101224223622_add_reset_password_to_users.rb
463
+ - spec/sinatra_modular/filters.rb
464
+ - spec/sinatra_modular/modular.rb
465
+ - spec/sinatra_modular/myapp.rb
466
+ - spec/sinatra_modular/sorcery_mailer.rb
467
+ - spec/sinatra_modular/spec_modular/controller_activity_logging_spec.rb
468
+ - spec/sinatra_modular/spec_modular/controller_brute_force_protection_spec.rb
469
+ - spec/sinatra_modular/spec_modular/controller_http_basic_auth_spec.rb
470
+ - spec/sinatra_modular/spec_modular/controller_oauth2_spec.rb
471
+ - spec/sinatra_modular/spec_modular/controller_oauth_spec.rb
472
+ - spec/sinatra_modular/spec_modular/controller_remember_me_spec.rb
473
+ - spec/sinatra_modular/spec_modular/controller_session_timeout_spec.rb
474
+ - spec/sinatra_modular/spec_modular/controller_spec.rb
475
+ - spec/sinatra_modular/spec_modular/spec.opts
476
+ - spec/sinatra_modular/spec_modular/spec_helper.rb
477
+ - spec/sinatra_modular/user.rb
478
+ - spec/sinatra_modular/views/test_login.erb
450
479
  - spec/sorcery_crypto_providers_spec.rb
451
480
  - spec/spec.opts
452
481
  - spec/spec_helper.rb
@@ -561,6 +590,7 @@ test_files:
561
590
  - spec/sinatra/db/migrate/remember_me/20101224223623_add_remember_me_token_to_users.rb
562
591
  - spec/sinatra/db/migrate/reset_password/20101224223622_add_reset_password_to_users.rb
563
592
  - spec/sinatra/filters.rb
593
+ - spec/sinatra/modular.rb
564
594
  - spec/sinatra/myapp.rb
565
595
  - spec/sinatra/sorcery_mailer.rb
566
596
  - spec/sinatra/spec/controller_activity_logging_spec.rb
@@ -573,5 +603,27 @@ test_files:
573
603
  - spec/sinatra/spec/controller_spec.rb
574
604
  - spec/sinatra/spec/spec_helper.rb
575
605
  - spec/sinatra/user.rb
606
+ - spec/sinatra_modular/authentication.rb
607
+ - spec/sinatra_modular/db/migrate/activation/20101224223622_add_activation_to_users.rb
608
+ - spec/sinatra_modular/db/migrate/activity_logging/20101224223624_add_activity_logging_to_users.rb
609
+ - spec/sinatra_modular/db/migrate/brute_force_protection/20101224223626_add_brute_force_protection_to_users.rb
610
+ - spec/sinatra_modular/db/migrate/core/20101224223620_create_users.rb
611
+ - spec/sinatra_modular/db/migrate/external/20101224223628_create_authentications.rb
612
+ - spec/sinatra_modular/db/migrate/remember_me/20101224223623_add_remember_me_token_to_users.rb
613
+ - spec/sinatra_modular/db/migrate/reset_password/20101224223622_add_reset_password_to_users.rb
614
+ - spec/sinatra_modular/filters.rb
615
+ - spec/sinatra_modular/modular.rb
616
+ - spec/sinatra_modular/myapp.rb
617
+ - spec/sinatra_modular/sorcery_mailer.rb
618
+ - spec/sinatra_modular/spec_modular/controller_activity_logging_spec.rb
619
+ - spec/sinatra_modular/spec_modular/controller_brute_force_protection_spec.rb
620
+ - spec/sinatra_modular/spec_modular/controller_http_basic_auth_spec.rb
621
+ - spec/sinatra_modular/spec_modular/controller_oauth2_spec.rb
622
+ - spec/sinatra_modular/spec_modular/controller_oauth_spec.rb
623
+ - spec/sinatra_modular/spec_modular/controller_remember_me_spec.rb
624
+ - spec/sinatra_modular/spec_modular/controller_session_timeout_spec.rb
625
+ - spec/sinatra_modular/spec_modular/controller_spec.rb
626
+ - spec/sinatra_modular/spec_modular/spec_helper.rb
627
+ - spec/sinatra_modular/user.rb
576
628
  - spec/sorcery_crypto_providers_spec.rb
577
629
  - spec/spec_helper.rb