sorcery 0.7.0 → 0.7.1

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 (164) hide show
  1. data/Gemfile +2 -1
  2. data/Gemfile.lock +58 -51
  3. data/README.rdoc +19 -57
  4. data/Rakefile +27 -1
  5. data/VERSION +1 -1
  6. data/lib/generators/sorcery/USAGE +22 -0
  7. data/lib/generators/sorcery/install_generator.rb +71 -0
  8. data/lib/{sorcery/initializers → generators/sorcery/templates}/initializer.rb +4 -4
  9. data/lib/generators/sorcery/templates/migration/activity_logging.rb +17 -0
  10. data/lib/generators/sorcery/templates/migration/brute_force_protection.rb +11 -0
  11. data/lib/generators/{sorcery_migration/templates → sorcery/templates/migration}/core.rb +2 -2
  12. data/lib/generators/{sorcery_migration/templates → sorcery/templates/migration}/external.rb +1 -1
  13. data/lib/generators/sorcery/templates/migration/remember_me.rb +15 -0
  14. data/lib/generators/sorcery/templates/migration/reset_password.rb +17 -0
  15. data/lib/generators/sorcery/templates/migration/user_activation.rb +17 -0
  16. data/lib/sorcery.rb +5 -7
  17. data/lib/sorcery/controller.rb +40 -39
  18. data/lib/sorcery/controller/submodules/activity_logging.rb +7 -10
  19. data/lib/sorcery/controller/submodules/external/protocols/oauth2.rb +23 -8
  20. data/lib/sorcery/controller/submodules/remember_me.rb +3 -2
  21. data/lib/sorcery/model.rb +21 -4
  22. data/lib/sorcery/model/adapters/mongo_mapper.rb +49 -0
  23. data/lib/sorcery/model/adapters/mongoid.rb +1 -1
  24. data/lib/sorcery/model/submodules/brute_force_protection.rb +8 -0
  25. data/lib/sorcery/model/submodules/remember_me.rb +8 -1
  26. data/lib/sorcery/model/submodules/reset_password.rb +10 -0
  27. data/lib/sorcery/model/submodules/user_activation.rb +12 -0
  28. data/sorcery.gemspec +86 -210
  29. data/spec/Gemfile +1 -1
  30. data/spec/Gemfile.lock +28 -15
  31. data/spec/README.md +6 -1
  32. data/spec/rails3/Gemfile +2 -2
  33. data/spec/rails3/Gemfile.lock +45 -50
  34. data/spec/rails3/spec/controller_oauth2_spec.rb +5 -3
  35. data/spec/rails3/spec/spec_helper.rb +1 -3
  36. data/spec/rails3_mongo_mapper/.gitignore +4 -0
  37. data/spec/rails3_mongo_mapper/.rspec +1 -0
  38. data/spec/{sinatra_modular → rails3_mongo_mapper}/Gemfile +5 -5
  39. data/spec/rails3_mongo_mapper/Gemfile.lock +159 -0
  40. data/spec/{sinatra → rails3_mongo_mapper}/Rakefile +3 -3
  41. data/spec/rails3_mongo_mapper/app/controllers/application_controller.rb +108 -0
  42. data/spec/rails3_mongo_mapper/app/helpers/application_helper.rb +2 -0
  43. data/spec/{sinatra → rails3_mongo_mapper/app/mailers}/sorcery_mailer.rb +0 -0
  44. data/spec/rails3_mongo_mapper/app/models/authentication.rb +6 -0
  45. data/spec/rails3_mongo_mapper/app/models/user.rb +5 -0
  46. data/spec/rails3_mongo_mapper/app/views/layouts/application.html.erb +14 -0
  47. data/spec/rails3_mongo_mapper/app/views/sorcery_mailer/activation_email.html.erb +17 -0
  48. data/spec/rails3_mongo_mapper/app/views/sorcery_mailer/activation_email.text.erb +9 -0
  49. data/spec/rails3_mongo_mapper/app/views/sorcery_mailer/activation_success_email.html.erb +17 -0
  50. data/spec/rails3_mongo_mapper/app/views/sorcery_mailer/activation_success_email.text.erb +9 -0
  51. data/spec/rails3_mongo_mapper/app/views/sorcery_mailer/reset_password_email.html.erb +16 -0
  52. data/spec/rails3_mongo_mapper/app/views/sorcery_mailer/reset_password_email.text.erb +8 -0
  53. data/spec/rails3_mongo_mapper/config.ru +4 -0
  54. data/spec/rails3_mongo_mapper/config/application.rb +51 -0
  55. data/spec/rails3_mongo_mapper/config/boot.rb +13 -0
  56. data/spec/rails3_mongo_mapper/config/environment.rb +5 -0
  57. data/spec/rails3_mongo_mapper/config/environments/development.rb +30 -0
  58. data/spec/rails3_mongo_mapper/config/environments/in_memory.rb +0 -0
  59. data/spec/rails3_mongo_mapper/config/environments/production.rb +49 -0
  60. data/spec/rails3_mongo_mapper/config/environments/test.rb +35 -0
  61. data/spec/rails3_mongo_mapper/config/initializers/backtrace_silencers.rb +7 -0
  62. data/spec/rails3_mongo_mapper/config/initializers/inflections.rb +10 -0
  63. data/spec/rails3_mongo_mapper/config/initializers/mime_types.rb +5 -0
  64. data/spec/rails3_mongo_mapper/config/initializers/mongo.rb +2 -0
  65. data/spec/rails3_mongo_mapper/config/initializers/secret_token.rb +7 -0
  66. data/spec/rails3_mongo_mapper/config/initializers/session_store.rb +8 -0
  67. data/spec/rails3_mongo_mapper/config/locales/en.yml +5 -0
  68. data/spec/rails3_mongo_mapper/config/routes.rb +59 -0
  69. data/spec/rails3_mongo_mapper/db/schema.rb +23 -0
  70. data/spec/rails3_mongo_mapper/db/seeds.rb +7 -0
  71. data/spec/rails3_mongo_mapper/lib/tasks/.gitkeep +0 -0
  72. data/spec/rails3_mongo_mapper/public/404.html +26 -0
  73. data/spec/rails3_mongo_mapper/public/422.html +26 -0
  74. data/spec/rails3_mongo_mapper/public/500.html +26 -0
  75. data/spec/rails3_mongo_mapper/public/favicon.ico +0 -0
  76. data/spec/rails3_mongo_mapper/public/images/rails.png +0 -0
  77. data/spec/rails3_mongo_mapper/public/javascripts/application.js +2 -0
  78. data/spec/rails3_mongo_mapper/public/javascripts/controls.js +965 -0
  79. data/spec/rails3_mongo_mapper/public/javascripts/dragdrop.js +974 -0
  80. data/spec/rails3_mongo_mapper/public/javascripts/effects.js +1123 -0
  81. data/spec/rails3_mongo_mapper/public/javascripts/prototype.js +6001 -0
  82. data/spec/rails3_mongo_mapper/public/javascripts/rails.js +175 -0
  83. data/spec/rails3_mongo_mapper/public/robots.txt +5 -0
  84. data/spec/rails3_mongo_mapper/public/stylesheets/.gitkeep +0 -0
  85. data/spec/rails3_mongo_mapper/script/rails +6 -0
  86. data/spec/{sinatra → rails3_mongo_mapper}/spec/controller_spec.rb +45 -42
  87. data/spec/{sinatra → rails3_mongo_mapper}/spec/spec.opts +0 -0
  88. data/spec/rails3_mongo_mapper/spec/spec_helper.orig.rb +27 -0
  89. data/spec/rails3_mongo_mapper/spec/spec_helper.rb +55 -0
  90. data/spec/rails3_mongo_mapper/spec/user_activation_spec.rb +9 -0
  91. data/spec/rails3_mongo_mapper/spec/user_activity_logging_spec.rb +8 -0
  92. data/spec/rails3_mongo_mapper/spec/user_brute_force_protection_spec.rb +8 -0
  93. data/spec/rails3_mongo_mapper/spec/user_oauth_spec.rb +8 -0
  94. data/spec/rails3_mongo_mapper/spec/user_remember_me_spec.rb +8 -0
  95. data/spec/rails3_mongo_mapper/spec/user_reset_password_spec.rb +8 -0
  96. data/spec/rails3_mongo_mapper/spec/user_spec.rb +37 -0
  97. data/spec/rails3_mongo_mapper/vendor/plugins/.gitkeep +0 -0
  98. data/spec/rails3_mongoid/Gemfile +1 -1
  99. data/spec/rails3_mongoid/Gemfile.lock +44 -35
  100. data/spec/rails3_mongoid/spec/controller_activity_logging_spec.rb +98 -0
  101. data/spec/rails3_mongoid/spec/user_spec.rb +1 -0
  102. data/spec/shared_examples/user_shared_examples.rb +29 -1
  103. metadata +124 -237
  104. data/lib/generators/sorcery_migration/sorcery_migration_generator.rb +0 -24
  105. data/lib/generators/sorcery_migration/templates/activity_logging.rb +0 -17
  106. data/lib/generators/sorcery_migration/templates/brute_force_protection.rb +0 -11
  107. data/lib/generators/sorcery_migration/templates/remember_me.rb +0 -15
  108. data/lib/generators/sorcery_migration/templates/reset_password.rb +0 -17
  109. data/lib/generators/sorcery_migration/templates/user_activation.rb +0 -17
  110. data/lib/sorcery/controller/adapters/sinatra.rb +0 -115
  111. data/lib/sorcery/sinatra.rb +0 -4
  112. data/lib/sorcery/test_helpers/internal/sinatra.rb +0 -74
  113. data/lib/sorcery/test_helpers/internal/sinatra_modular.rb +0 -74
  114. data/lib/sorcery/test_helpers/sinatra.rb +0 -88
  115. data/spec/rails3/Rakefile.unused +0 -7
  116. data/spec/sinatra/Gemfile +0 -15
  117. data/spec/sinatra/Gemfile.lock +0 -115
  118. data/spec/sinatra/authentication.rb +0 -3
  119. data/spec/sinatra/db/migrate/activation/20101224223622_add_activation_to_users.rb +0 -17
  120. data/spec/sinatra/db/migrate/activity_logging/20101224223624_add_activity_logging_to_users.rb +0 -17
  121. data/spec/sinatra/db/migrate/brute_force_protection/20101224223626_add_brute_force_protection_to_users.rb +0 -11
  122. data/spec/sinatra/db/migrate/core/20101224223620_create_users.rb +0 -16
  123. data/spec/sinatra/db/migrate/external/20101224223628_create_authentications.rb +0 -14
  124. data/spec/sinatra/db/migrate/remember_me/20101224223623_add_remember_me_token_to_users.rb +0 -15
  125. data/spec/sinatra/db/migrate/reset_password/20101224223622_add_reset_password_to_users.rb +0 -13
  126. data/spec/sinatra/filters.rb +0 -27
  127. data/spec/sinatra/modular.rb +0 -157
  128. data/spec/sinatra/myapp.rb +0 -133
  129. data/spec/sinatra/spec/controller_activity_logging_spec.rb +0 -85
  130. data/spec/sinatra/spec/controller_brute_force_protection_spec.rb +0 -70
  131. data/spec/sinatra/spec/controller_http_basic_auth_spec.rb +0 -53
  132. data/spec/sinatra/spec/controller_oauth2_spec.rb +0 -96
  133. data/spec/sinatra/spec/controller_oauth_spec.rb +0 -100
  134. data/spec/sinatra/spec/controller_remember_me_spec.rb +0 -64
  135. data/spec/sinatra/spec/controller_session_timeout_spec.rb +0 -57
  136. data/spec/sinatra/spec/spec_helper.rb +0 -45
  137. data/spec/sinatra/user.rb +0 -6
  138. data/spec/sinatra/views/test_login.erb +0 -4
  139. data/spec/sinatra_modular/Gemfile.lock +0 -115
  140. data/spec/sinatra_modular/Rakefile +0 -11
  141. data/spec/sinatra_modular/authentication.rb +0 -3
  142. data/spec/sinatra_modular/db/migrate/activation/20101224223622_add_activation_to_users.rb +0 -17
  143. data/spec/sinatra_modular/db/migrate/activity_logging/20101224223624_add_activity_logging_to_users.rb +0 -17
  144. data/spec/sinatra_modular/db/migrate/brute_force_protection/20101224223626_add_brute_force_protection_to_users.rb +0 -11
  145. data/spec/sinatra_modular/db/migrate/core/20101224223620_create_users.rb +0 -16
  146. data/spec/sinatra_modular/db/migrate/external/20101224223628_create_authentications.rb +0 -14
  147. data/spec/sinatra_modular/db/migrate/remember_me/20101224223623_add_remember_me_token_to_users.rb +0 -15
  148. data/spec/sinatra_modular/db/migrate/reset_password/20101224223622_add_reset_password_to_users.rb +0 -13
  149. data/spec/sinatra_modular/filters.rb +0 -27
  150. data/spec/sinatra_modular/modular.rb +0 -157
  151. data/spec/sinatra_modular/myapp.rb +0 -133
  152. data/spec/sinatra_modular/sorcery_mailer.rb +0 -25
  153. data/spec/sinatra_modular/spec_modular/controller_activity_logging_spec.rb +0 -85
  154. data/spec/sinatra_modular/spec_modular/controller_brute_force_protection_spec.rb +0 -70
  155. data/spec/sinatra_modular/spec_modular/controller_http_basic_auth_spec.rb +0 -53
  156. data/spec/sinatra_modular/spec_modular/controller_oauth2_spec.rb +0 -96
  157. data/spec/sinatra_modular/spec_modular/controller_oauth_spec.rb +0 -100
  158. data/spec/sinatra_modular/spec_modular/controller_remember_me_spec.rb +0 -64
  159. data/spec/sinatra_modular/spec_modular/controller_session_timeout_spec.rb +0 -57
  160. data/spec/sinatra_modular/spec_modular/controller_spec.rb +0 -116
  161. data/spec/sinatra_modular/spec_modular/spec.opts +0 -2
  162. data/spec/sinatra_modular/spec_modular/spec_helper.rb +0 -51
  163. data/spec/sinatra_modular/user.rb +0 -6
  164. data/spec/sinatra_modular/views/test_login.erb +0 -4
@@ -1,53 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
- require 'base64'
3
-
4
- describe Modular do
5
-
6
- # ----------------- HTTP BASIC AUTH -----------------------
7
- describe Modular, "with http basic auth features" do
8
- before(:all) do
9
- sorcery_reload!([:http_basic_auth])
10
- create_new_user
11
- end
12
-
13
- after(:each) do
14
- get "/test_logout"
15
- end
16
-
17
- it "requests basic authentication when before_filter is used" do
18
- session[:http_authentication_used] = nil
19
- get "/test_http_basic_auth"
20
- last_response.status.should == 401
21
- session[:http_authentication_used].should == true
22
- end
23
-
24
- it "authenticates from http basic if credentials are sent" do
25
- session[:http_authentication_used] = true
26
- get "/test_http_basic_auth", {}, {"HTTP_AUTHORIZATION" => "Basic " + Base64::encode64("#{@user.username}:secret")}
27
- last_response.should be_ok
28
- end
29
-
30
- it "fails authentication if credentials are wrong" do
31
- session[:http_authentication_used] = true
32
- get "/test_http_basic_auth", {}, {"HTTP_AUTHORIZATION" => "Basic " + Base64::encode64("#{@user.username}:wrong!")}
33
- last_response.should redirect_to 'http://example.org/'
34
- end
35
-
36
- it "should allow configuration option 'controller_to_realm_map'" do
37
- sorcery_controller_property_set(:controller_to_realm_map, {"1" => "2"})
38
- Sorcery::Controller::Config.controller_to_realm_map.should == {"1" => "2"}
39
- end
40
-
41
- it "should display the correct realm name configured for the controller" do
42
- sorcery_controller_property_set(:controller_to_realm_map, {"application" => "Salad"})
43
- get "/test_http_basic_auth"
44
- last_response.headers["WWW-Authenticate"].should == "Basic realm=\"Salad\""
45
- end
46
-
47
- it "should sign in the user's session on successful login" do
48
- session[:http_authentication_used] = true
49
- get "/test_http_basic_auth", {}, {"HTTP_AUTHORIZATION" => "Basic " + Base64::encode64("#{@user.username}:secret")}
50
- session[:user_id].should == User.find_by_username(@user.username).id
51
- end
52
- end
53
- end
@@ -1,96 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
- require File.expand_path(File.dirname(__FILE__) + '/../../shared_examples/controller_oauth2_shared_examples')
3
-
4
- def stub_all_oauth2_requests!
5
- @client = OAuth2::Client.new("key","secret", :site => "http://myapi.com")
6
- OAuth2::Client.stub!(:new).and_return(@client)
7
- @acc_token = OAuth2::AccessToken.new(@client, "asd", {})
8
- @client.stub!(:get_token).and_return(@acc_token)
9
- @acc_token.stub!(:get).and_return({"id"=>"123", "name"=>"Noam Ben Ari", "first_name"=>"Noam", "last_name"=>"Ben Ari", "link"=>"http://www.facebook.com/nbenari1", "hometown"=>{"id"=>"110619208966868", "name"=>"Haifa, Israel"}, "location"=>{"id"=>"106906559341067", "name"=>"Pardes Hanah, Hefa, Israel"}, "bio"=>"I'm a new daddy, and enjoying it!", "gender"=>"male", "email"=>"nbenari@gmail.com", "timezone"=>2, "locale"=>"en_US", "languages"=>[{"id"=>"108405449189952", "name"=>"Hebrew"}, {"id"=>"106059522759137", "name"=>"English"}, {"id"=>"112624162082677", "name"=>"Russian"}], "verified"=>true, "updated_time"=>"2011-02-16T20:59:38+0000"}.to_json)
10
- end
11
-
12
- describe 'MyApp' do
13
- before(:all) do
14
- ActiveRecord::Migrator.migrate("#{APP_ROOT}/db/migrate/external")
15
- sorcery_reload!([:external])
16
- sorcery_controller_property_set(:external_providers, [:facebook])
17
- sorcery_controller_external_property_set(:facebook, :key, "eYVNBjBDi33aa9GkA3w")
18
- sorcery_controller_external_property_set(:facebook, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8")
19
- sorcery_controller_external_property_set(:facebook, :callback_url, "http://blabla.com")
20
- end
21
-
22
- after(:all) do
23
- ActiveRecord::Migrator.rollback("#{APP_ROOT}/db/migrate/external")
24
- end
25
- # ----------------- OAuth -----------------------
26
- describe Modular, "with OAuth features" do
27
-
28
- before(:each) do
29
- stub_all_oauth2_requests!
30
- end
31
-
32
- after(:each) do
33
- User.delete_all
34
- Authentication.delete_all
35
- end
36
-
37
- it "login_at redirects correctly" do
38
- create_new_user
39
- get "/login_at_test2"
40
- last_response.should be_a_redirect
41
- last_response.should redirect_to("http://myapi.com/oauth/authorize?redirect_uri=http%3A%2F%2Fblabla.com&scope=email%2Coffline_access")
42
- end
43
-
44
- it "'login_from' logins if user exists" do
45
- sorcery_model_property_set(:authentications_class, Authentication)
46
- create_new_external_user(:facebook)
47
- get "/test_login_from2"
48
- last_response.body.should == "Success!"
49
- end
50
-
51
- it "'login_from' fails if user doesn't exist" do
52
- sorcery_model_property_set(:authentications_class, Authentication)
53
- create_new_user
54
- get "/test_login_from2"
55
- last_response.body.should == "Failed!"
56
- end
57
- end
58
-
59
- describe Modular do
60
- it_behaves_like "oauth2_controller"
61
- end
62
-
63
- describe Modular, "OAuth with User Activation features" do
64
- before(:all) do
65
- ActiveRecord::Migrator.migrate("#{APP_ROOT}/db/migrate/activation")
66
- sorcery_reload!([:user_activation,:external], :user_activation_mailer => ::SorceryMailer)
67
- sorcery_controller_property_set(:external_providers, [:facebook])
68
- sorcery_controller_external_property_set(:facebook, :key, "eYVNBjBDi33aa9GkA3w")
69
- sorcery_controller_external_property_set(:facebook, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8")
70
- sorcery_controller_external_property_set(:facebook, :callback_url, "http://blabla.com")
71
- end
72
-
73
- after(:all) do
74
- ActiveRecord::Migrator.rollback("#{APP_ROOT}/db/migrate/activation")
75
- end
76
-
77
- after(:each) do
78
- User.delete_all
79
- end
80
-
81
- it "should not send activation email to external users" do
82
- old_size = ActionMailer::Base.deliveries.size
83
- create_new_external_user(:facebook)
84
- ActionMailer::Base.deliveries.size.should == old_size
85
- end
86
-
87
- it "should not send external users an activation success email" do
88
- sorcery_model_property_set(:activation_success_email_method_name, nil)
89
- create_new_external_user(:facebook)
90
- old_size = ActionMailer::Base.deliveries.size
91
- @user.activate!
92
- ActionMailer::Base.deliveries.size.should == old_size
93
- end
94
- end
95
-
96
- end
@@ -1,100 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
- require File.expand_path(File.dirname(__FILE__) + '/../../shared_examples/controller_oauth_shared_examples')
3
- require 'ostruct'
4
-
5
- def stub_all_oauth_requests!
6
- @consumer = OAuth::Consumer.new("key","secret", :site => "http://myapi.com")
7
- OAuth::Consumer.stub!(:new).and_return(@consumer)
8
- @req_token = OAuth::RequestToken.new(@consumer) # OpenStruct.new()
9
- @consumer.stub!(:get_request_token).and_return(@req_token)
10
- @acc_token = OAuth::AccessToken.new(@consumer)
11
- @req_token.stub!(:get_access_token).and_return(@acc_token)
12
- session[:request_token] = @req_token.token
13
- session[:request_token_secret] = @req_token.secret
14
- OAuth::RequestToken.stub!(:new).and_return(@req_token)
15
- response = OpenStruct.new()
16
- response.body = {"following"=>false, "listed_count"=>0, "profile_link_color"=>"0084B4", "profile_image_url"=>"http://a1.twimg.com/profile_images/536178575/noamb_normal.jpg", "description"=>"Programmer/Heavy Metal Fan/New Father", "status"=>{"text"=>"coming soon to sorcery gem: twitter and facebook authentication support.", "truncated"=>false, "favorited"=>false, "source"=>"web", "geo"=>nil, "in_reply_to_screen_name"=>nil, "in_reply_to_user_id"=>nil, "in_reply_to_status_id_str"=>nil, "created_at"=>"Sun Mar 06 23:01:12 +0000 2011", "contributors"=>nil, "place"=>nil, "retweeted"=>false, "in_reply_to_status_id"=>nil, "in_reply_to_user_id_str"=>nil, "coordinates"=>nil, "retweet_count"=>0, "id"=>44533012284706816, "id_str"=>"44533012284706816"}, "show_all_inline_media"=>false, "geo_enabled"=>true, "profile_sidebar_border_color"=>"a8c7f7", "url"=>nil, "followers_count"=>10, "screen_name"=>"nbenari", "profile_use_background_image"=>true, "location"=>"Israel", "statuses_count"=>25, "profile_background_color"=>"022330", "lang"=>"en", "verified"=>false, "notifications"=>false, "profile_background_image_url"=>"http://a3.twimg.com/profile_background_images/104087198/04042010339.jpg", "favourites_count"=>5, "created_at"=>"Fri Nov 20 21:58:19 +0000 2009", "is_translator"=>false, "contributors_enabled"=>false, "protected"=>false, "follow_request_sent"=>false, "time_zone"=>"Greenland", "profile_text_color"=>"333333", "name"=>"Noam Ben Ari", "friends_count"=>10, "profile_sidebar_fill_color"=>"C0DFEC", "id"=>123, "id_str"=>"91434812", "profile_background_tile"=>false, "utc_offset"=>-10800}.to_json
17
- @acc_token.stub!(:get).and_return(response)
18
- end
19
-
20
- describe Modular do
21
- before(:all) do
22
- ActiveRecord::Migrator.migrate("#{APP_ROOT}/db/migrate/external")
23
- sorcery_reload!([:external])
24
- sorcery_controller_property_set(:external_providers, [:twitter])
25
- sorcery_controller_external_property_set(:twitter, :key, "eYVNBjBDi33aa9GkA3w")
26
- sorcery_controller_external_property_set(:twitter, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8")
27
- sorcery_controller_external_property_set(:twitter, :callback_url, "http://blabla.com")
28
- end
29
-
30
- after(:all) do
31
- ActiveRecord::Migrator.rollback("#{APP_ROOT}/db/migrate/external")
32
- end
33
- # ----------------- OAuth -----------------------
34
- describe Modular, "'login_from'" do
35
-
36
- before(:each) do
37
- stub_all_oauth_requests!
38
- end
39
-
40
- after(:each) do
41
- User.delete_all
42
- Authentication.delete_all
43
- end
44
-
45
- it "login_at_test redirects correctly" do
46
- create_new_user
47
- get "/login_at_test"
48
- last_response.should be_a_redirect
49
- last_response.should redirect_to("http://myapi.com/oauth/authorize?oauth_callback=http%3A%2F%2Fblabla.com&oauth_token=")
50
- end
51
-
52
- it "logins if user exists" do
53
- sorcery_model_property_set(:authentications_class, Authentication)
54
- create_new_external_user(:twitter)
55
- get '/test_login_from', :oauth_verifier => "blablaRERASDFcxvSDFA"
56
- last_response.body.should == "Success!"
57
- end
58
-
59
- it "'login_from' fails if user doesn't exist" do
60
- sorcery_model_property_set(:authentications_class, Authentication)
61
- create_new_user
62
- get '/test_login_from', :oauth_verifier => "blablaRERASDFcxvSDFA"
63
- last_response.body.should == "Failed!"
64
- end
65
- end
66
-
67
- describe Modular do
68
- it_behaves_like "oauth_controller"
69
- end
70
-
71
- describe Modular, "OAuth with User Activation features" do
72
- before(:all) do
73
- ActiveRecord::Migrator.migrate("#{APP_ROOT}/db/migrate/activation")
74
- sorcery_reload!([:user_activation,:external], :user_activation_mailer => ::SorceryMailer)
75
- end
76
-
77
- after(:all) do
78
- ActiveRecord::Migrator.rollback("#{APP_ROOT}/db/migrate/activation")
79
- end
80
-
81
- after(:each) do
82
- User.delete_all
83
- Authentication.delete_all
84
- end
85
-
86
- it "should not send activation email to external users" do
87
- old_size = ActionMailer::Base.deliveries.size
88
- create_new_external_user(:twitter)
89
- ActionMailer::Base.deliveries.size.should == old_size
90
- end
91
-
92
- it "should not send external users an activation success email" do
93
- sorcery_model_property_set(:activation_success_email_method_name, nil)
94
- create_new_external_user(:twitter)
95
- old_size = ActionMailer::Base.deliveries.size
96
- @user.activate!
97
- ActionMailer::Base.deliveries.size.should == old_size
98
- end
99
- end
100
- end
@@ -1,64 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
-
3
- describe Modular do
4
-
5
- # ----------------- REMEMBER ME -----------------------
6
- describe Modular, "with remember me features" do
7
- before(:all) do
8
- ActiveRecord::Migrator.migrate("#{APP_ROOT}/db/migrate/remember_me")
9
- sorcery_reload!([:remember_me])
10
- end
11
-
12
- before(:each) do
13
- create_new_user
14
- end
15
-
16
- after(:all) do
17
- ActiveRecord::Migrator.rollback("#{APP_ROOT}/db/migrate/remember_me")
18
- end
19
-
20
- after(:each) do
21
- session = nil
22
- clear_cookies
23
- User.delete_all
24
- end
25
-
26
- it "should set cookie on remember_me!" do
27
- post "/test_login_with_remember", :username => 'gizmo', :password => 'secret'
28
- cookies["remember_me_token"].should == assigns[:user].remember_me_token
29
- end
30
-
31
- it "should clear cookie on forget_me!" do
32
- cookies["remember_me_token"] == {:value => 'asd54234dsfsd43534', :expires => 3600}
33
- get '/test_logout'
34
- cookies["remember_me_token"].should == nil
35
- end
36
-
37
- it "login(username,password,remember_me) should login and remember" do
38
- post '/test_login_with_remember_in_login', :username => 'gizmo', :password => 'secret', :remember => "1"
39
- cookies["remember_me_token"].should_not be_nil
40
- cookies["remember_me_token"].should == assigns[:user].remember_me_token
41
- end
42
-
43
- it "logout should also forget_me!" do
44
- session[:user_id] = @user.id
45
- get '/test_logout_with_remember'
46
- cookies["remember_me_token"].should == nil
47
- end
48
-
49
- it "should login_from_cookie" do
50
- post "/test_login_with_remember", :username => 'gizmo', :password => 'secret'
51
- get_sinatra_app(subject).instance_eval do
52
- @current_user = nil
53
- end
54
- session[:user_id] = nil
55
- get '/test_login_from_cookie'
56
- assigns[:current_user].should == @user
57
- end
58
-
59
- it "should not remember_me! when not asked to" do
60
- post '/test_login', :username => 'gizmo', :password => 'secret'
61
- cookies["remember_me_token"].should == nil
62
- end
63
- end
64
- end
@@ -1,57 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
-
3
- describe Modular do
4
-
5
- # ----------------- SESSION TIMEOUT -----------------------
6
- describe Modular, "with session timeout features" do
7
- before(:all) do
8
- sorcery_reload!([:session_timeout])
9
- sorcery_controller_property_set(:session_timeout,0.5)
10
- create_new_user
11
- end
12
-
13
- after(:each) do
14
- Timecop.return
15
- end
16
-
17
- it "should not reset session before session timeout" do
18
- session[:user_id] = User.first.id
19
- get "/test_should_be_logged_in"
20
- last_response.should be_ok
21
- end
22
-
23
- it "should reset session after session timeout" do
24
- get "/test_login", :username => 'gizmo', :password => 'secret'
25
- session[:user_id].should_not be_nil
26
- Timecop.travel(Time.now+0.6)
27
- get "/test_should_be_logged_in"
28
- last_response.should be_a_redirect
29
- end
30
-
31
- context "with 'session_timeout_from_last_action'" do
32
- it "should not logout if there was activity" do
33
- session[:user_id] = nil
34
- sorcery_controller_property_set(:session_timeout,2)
35
- sorcery_controller_property_set(:session_timeout_from_last_action, true)
36
- get "/test_login", :username => 'gizmo', :password => 'secret'
37
- Timecop.travel(Time.now+1)
38
- get "/test_should_be_logged_in"
39
- session[:user_id].should_not be_nil
40
- Timecop.travel(Time.now+1)
41
- get "/test_should_be_logged_in"
42
- session[:user_id].should_not be_nil
43
- last_response.should be_ok
44
- end
45
-
46
- it "should logout if there was no activity" do
47
- sorcery_controller_property_set(:session_timeout,0.5)
48
- sorcery_controller_property_set(:session_timeout_from_last_action, true)
49
- get "/test_login", :username => 'gizmo', :password => 'secret'
50
- Timecop.travel(Time.now+0.6)
51
- get "/test_should_be_logged_in"
52
- session[:user_id].should be_nil
53
- last_response.should be_a_redirect
54
- end
55
- end
56
- end
57
- end
@@ -1,116 +0,0 @@
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 == "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