sorcery 0.2.1 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (163) hide show
  1. data/Gemfile +3 -2
  2. data/Gemfile.lock +13 -11
  3. data/README.rdoc +157 -61
  4. data/Rakefile +4 -4
  5. data/VERSION +1 -1
  6. data/lib/generators/sorcery_migration/sorcery_migration_generator.rb +24 -0
  7. data/lib/generators/sorcery_migration/templates/activity_logging.rb +17 -0
  8. data/lib/generators/sorcery_migration/templates/brute_force_protection.rb +11 -0
  9. data/lib/generators/sorcery_migration/templates/core.rb +16 -0
  10. data/lib/generators/sorcery_migration/templates/external.rb +14 -0
  11. data/lib/generators/sorcery_migration/templates/remember_me.rb +15 -0
  12. data/lib/generators/sorcery_migration/templates/reset_password.rb +13 -0
  13. data/lib/generators/sorcery_migration/templates/user_activation.rb +17 -0
  14. data/lib/sorcery/controller/adapters/sinatra.rb +97 -0
  15. data/lib/sorcery/controller/submodules/external/protocols/oauth1.rb +35 -0
  16. data/lib/sorcery/controller/submodules/external/protocols/oauth2.rb +26 -0
  17. data/lib/sorcery/controller/submodules/{oauth → external}/providers/facebook.rb +24 -6
  18. data/lib/sorcery/controller/submodules/{oauth → external}/providers/twitter.rb +31 -6
  19. data/lib/sorcery/controller/submodules/{oauth.rb → external.rb} +18 -27
  20. data/lib/sorcery/controller/submodules/http_basic_auth.rb +11 -7
  21. data/lib/sorcery/controller.rb +21 -21
  22. data/lib/sorcery/crypto_providers/bcrypt.rb +3 -5
  23. data/lib/sorcery/crypto_providers/common.rb +35 -0
  24. data/lib/sorcery/crypto_providers/md5.rb +3 -23
  25. data/lib/sorcery/crypto_providers/sha1.rb +4 -16
  26. data/lib/sorcery/crypto_providers/sha256.rb +3 -23
  27. data/lib/sorcery/crypto_providers/sha512.rb +3 -23
  28. data/lib/sorcery/engine.rb +4 -0
  29. data/lib/sorcery/initializers/initializer.rb +86 -0
  30. data/lib/sorcery/model/submodules/activity_logging.rb +2 -2
  31. data/lib/sorcery/model/submodules/brute_force_protection.rb +1 -5
  32. data/lib/sorcery/model/submodules/{oauth.rb → external.rb} +3 -3
  33. data/lib/sorcery/model/submodules/reset_password.rb +1 -1
  34. data/lib/sorcery/model.rb +34 -9
  35. data/lib/sorcery/railties/tasks.rake +10 -0
  36. data/lib/sorcery/sinatra.rb +5 -0
  37. data/lib/sorcery/test_helpers/internal/rails.rb +52 -0
  38. data/lib/sorcery/test_helpers/internal/sinatra.rb +122 -0
  39. data/lib/sorcery/test_helpers/internal.rb +55 -0
  40. data/lib/sorcery/test_helpers/rails.rb +16 -0
  41. data/lib/sorcery/test_helpers/sinatra.rb +85 -0
  42. data/lib/sorcery/test_helpers.rb +0 -79
  43. data/lib/sorcery.rb +25 -7
  44. data/sorcery.gemspec +207 -137
  45. data/spec/Gemfile +2 -2
  46. data/spec/Gemfile.lock +20 -12
  47. data/spec/Rakefile +1 -0
  48. data/spec/rails3/.rspec +1 -1
  49. data/spec/rails3/{app_root/Gemfile → Gemfile} +5 -7
  50. data/spec/rails3/{app_root/Gemfile.lock → Gemfile.lock} +20 -23
  51. data/spec/rails3/{app_root/Rakefile → Rakefile} +1 -0
  52. data/spec/rails3/{app_root/app → app}/controllers/application_controller.rb +11 -11
  53. data/spec/rails3/config/database.yml +27 -0
  54. data/spec/rails3/{app_root/spec → spec}/controller_activity_logging_spec.rb +2 -4
  55. data/spec/rails3/{app_root/spec → spec}/controller_brute_force_protection_spec.rb +3 -2
  56. data/spec/rails3/{app_root/spec → spec}/controller_oauth2_spec.rb +25 -22
  57. data/spec/rails3/{app_root/spec → spec}/controller_oauth_spec.rb +24 -19
  58. data/spec/rails3/spec/controller_session_timeout_spec.rb +55 -0
  59. data/spec/rails3/{app_root/spec → spec}/controller_spec.rb +6 -16
  60. data/spec/rails3/spec/spec.opts +2 -0
  61. data/spec/rails3/spec/spec_helper.rb +70 -0
  62. data/spec/rails3/{app_root/spec → spec}/user_activation_spec.rb +7 -13
  63. data/spec/rails3/{app_root/spec → spec}/user_brute_force_protection_spec.rb +2 -30
  64. data/spec/rails3/{app_root/spec → spec}/user_oauth_spec.rb +7 -7
  65. data/spec/rails3/{app_root/spec → spec}/user_remember_me_spec.rb +3 -11
  66. data/spec/rails3/{app_root/spec → spec}/user_reset_password_spec.rb +20 -17
  67. data/spec/rails3/{app_root/spec → spec}/user_spec.rb +21 -11
  68. data/spec/sinatra/Gemfile +12 -0
  69. data/spec/sinatra/Gemfile.lock +134 -0
  70. data/spec/sinatra/Rakefile +11 -0
  71. data/spec/sinatra/authentication.rb +3 -0
  72. data/spec/sinatra/db/migrate/activation/20101224223622_add_activation_to_users.rb +17 -0
  73. data/spec/sinatra/db/migrate/activity_logging/20101224223624_add_activity_logging_to_users.rb +17 -0
  74. data/spec/sinatra/db/migrate/brute_force_protection/20101224223626_add_brute_force_protection_to_users.rb +11 -0
  75. data/spec/sinatra/db/migrate/core/20101224223620_create_users.rb +16 -0
  76. data/spec/sinatra/db/migrate/external/20101224223628_create_authentications.rb +14 -0
  77. data/spec/sinatra/db/migrate/remember_me/20101224223623_add_remember_me_token_to_users.rb +15 -0
  78. data/spec/sinatra/db/migrate/reset_password/20101224223622_add_reset_password_to_users.rb +13 -0
  79. data/spec/sinatra/filters.rb +21 -0
  80. data/spec/sinatra/myapp.rb +133 -0
  81. data/spec/sinatra/sorcery_mailer.rb +25 -0
  82. data/spec/sinatra/spec/controller_activity_logging_spec.rb +85 -0
  83. data/spec/sinatra/spec/controller_brute_force_protection_spec.rb +70 -0
  84. data/spec/sinatra/spec/controller_http_basic_auth_spec.rb +53 -0
  85. data/spec/sinatra/spec/controller_oauth2_spec.rb +120 -0
  86. data/spec/sinatra/spec/controller_oauth_spec.rb +121 -0
  87. data/spec/sinatra/spec/controller_remember_me_spec.rb +64 -0
  88. data/spec/sinatra/spec/controller_session_timeout_spec.rb +57 -0
  89. data/spec/sinatra/spec/controller_spec.rb +120 -0
  90. data/spec/sinatra/spec/spec.opts +2 -0
  91. data/spec/sinatra/spec/spec_helper.rb +46 -0
  92. data/spec/sinatra/user.rb +6 -0
  93. data/spec/sinatra/views/test_login.erb +4 -0
  94. data/spec/sorcery_crypto_providers_spec.rb +5 -4
  95. data/spec/spec.opts +2 -0
  96. data/spec/spec_helper.rb +3 -4
  97. data/spec/untitled folder +18 -0
  98. metadata +217 -139
  99. data/lib/sorcery/controller/submodules/oauth/oauth1.rb +0 -26
  100. data/lib/sorcery/controller/submodules/oauth/oauth2.rb +0 -24
  101. data/spec/rails3/app_root/.rspec +0 -1
  102. data/spec/rails3/app_root/config/database.yml +0 -27
  103. data/spec/rails3/app_root/spec/controller_session_timeout_spec.rb +0 -50
  104. data/spec/rails3/app_root/spec/spec_helper.rb +0 -61
  105. /data/spec/rails3/{app_root/.gitignore → .gitignore} +0 -0
  106. /data/spec/rails3/{app_root/README → README} +0 -0
  107. /data/spec/rails3/{app_root/Rakefile.unused → Rakefile.unused} +0 -0
  108. /data/spec/rails3/{app_root/app → app}/helpers/application_helper.rb +0 -0
  109. /data/spec/rails3/{app_root/app → app}/mailers/sorcery_mailer.rb +0 -0
  110. /data/spec/rails3/{app_root/app → app}/models/authentication.rb +0 -0
  111. /data/spec/rails3/{app_root/app → app}/models/user.rb +0 -0
  112. /data/spec/rails3/{app_root/app → app}/views/layouts/application.html.erb +0 -0
  113. /data/spec/rails3/{app_root/app → app}/views/sorcery_mailer/activation_email.html.erb +0 -0
  114. /data/spec/rails3/{app_root/app → app}/views/sorcery_mailer/activation_email.text.erb +0 -0
  115. /data/spec/rails3/{app_root/app → app}/views/sorcery_mailer/activation_success_email.html.erb +0 -0
  116. /data/spec/rails3/{app_root/app → app}/views/sorcery_mailer/activation_success_email.text.erb +0 -0
  117. /data/spec/rails3/{app_root/app → app}/views/sorcery_mailer/reset_password_email.html.erb +0 -0
  118. /data/spec/rails3/{app_root/app → app}/views/sorcery_mailer/reset_password_email.text.erb +0 -0
  119. /data/spec/rails3/{app_root/config → config}/application.rb +0 -0
  120. /data/spec/rails3/{app_root/config → config}/boot.rb +0 -0
  121. /data/spec/rails3/{app_root/config → config}/environment.rb +0 -0
  122. /data/spec/rails3/{app_root/config → config}/environments/development.rb +0 -0
  123. /data/spec/rails3/{app_root/config → config}/environments/in_memory.rb +0 -0
  124. /data/spec/rails3/{app_root/config → config}/environments/production.rb +0 -0
  125. /data/spec/rails3/{app_root/config → config}/environments/test.rb +0 -0
  126. /data/spec/rails3/{app_root/config → config}/initializers/backtrace_silencers.rb +0 -0
  127. /data/spec/rails3/{app_root/config → config}/initializers/inflections.rb +0 -0
  128. /data/spec/rails3/{app_root/config → config}/initializers/mime_types.rb +0 -0
  129. /data/spec/rails3/{app_root/config → config}/initializers/secret_token.rb +0 -0
  130. /data/spec/rails3/{app_root/config → config}/initializers/session_store.rb +0 -0
  131. /data/spec/rails3/{app_root/config → config}/locales/en.yml +0 -0
  132. /data/spec/rails3/{app_root/config → config}/routes.rb +0 -0
  133. /data/spec/rails3/{app_root/config.ru → config.ru} +0 -0
  134. /data/spec/rails3/{app_root/db → db}/migrate/activation/20101224223622_add_activation_to_users.rb +0 -0
  135. /data/spec/rails3/{app_root/db → db}/migrate/activity_logging/20101224223624_add_activity_logging_to_users.rb +0 -0
  136. /data/spec/rails3/{app_root/db → db}/migrate/brute_force_protection/20101224223626_add_brute_force_protection_to_users.rb +0 -0
  137. /data/spec/rails3/{app_root/db → db}/migrate/core/20101224223620_create_users.rb +0 -0
  138. /data/spec/rails3/{app_root/db/migrate/oauth → db/migrate/external}/20101224223628_create_authentications.rb +0 -0
  139. /data/spec/rails3/{app_root/db → db}/migrate/remember_me/20101224223623_add_remember_me_token_to_users.rb +0 -0
  140. /data/spec/rails3/{app_root/db → db}/migrate/reset_password/20101224223622_add_reset_password_to_users.rb +0 -0
  141. /data/spec/rails3/{app_root/db → db}/schema.rb +0 -0
  142. /data/spec/rails3/{app_root/db → db}/seeds.rb +0 -0
  143. /data/spec/rails3/{app_root/lib → lib}/tasks/.gitkeep +0 -0
  144. /data/spec/rails3/{app_root/public → public}/404.html +0 -0
  145. /data/spec/rails3/{app_root/public → public}/422.html +0 -0
  146. /data/spec/rails3/{app_root/public → public}/500.html +0 -0
  147. /data/spec/rails3/{app_root/public → public}/favicon.ico +0 -0
  148. /data/spec/rails3/{app_root/public → public}/images/rails.png +0 -0
  149. /data/spec/rails3/{app_root/public → public}/index.html +0 -0
  150. /data/spec/rails3/{app_root/public → public}/javascripts/application.js +0 -0
  151. /data/spec/rails3/{app_root/public → public}/javascripts/controls.js +0 -0
  152. /data/spec/rails3/{app_root/public → public}/javascripts/dragdrop.js +0 -0
  153. /data/spec/rails3/{app_root/public → public}/javascripts/effects.js +0 -0
  154. /data/spec/rails3/{app_root/public → public}/javascripts/prototype.js +0 -0
  155. /data/spec/rails3/{app_root/public → public}/javascripts/rails.js +0 -0
  156. /data/spec/rails3/{app_root/public → public}/robots.txt +0 -0
  157. /data/spec/rails3/{app_root/public → public}/stylesheets/.gitkeep +0 -0
  158. /data/spec/rails3/{app_root/script → script}/rails +0 -0
  159. /data/spec/rails3/{app_root/spec → spec}/controller_http_basic_auth_spec.rb +0 -0
  160. /data/spec/rails3/{app_root/spec → spec}/controller_remember_me_spec.rb +0 -0
  161. /data/spec/rails3/{app_root/spec → spec}/spec_helper.orig.rb +0 -0
  162. /data/spec/rails3/{app_root/spec → spec}/user_activity_logging_spec.rb +0 -0
  163. /data/spec/rails3/{app_root/vendor → vendor}/plugins/.gitkeep +0 -0
@@ -1,7 +1,8 @@
1
1
  PATH
2
2
  remote: ../../../
3
3
  specs:
4
- sorcery (0.2.1)
4
+ oauth (0.4.4)
5
+ sorcery (0.4.2)
5
6
  bcrypt-ruby (~> 2.1.4)
6
7
  json (>= 1.5.1)
7
8
  oauth (>= 0.4.4)
@@ -40,7 +41,7 @@ GEM
40
41
  activemodel (= 3.0.3)
41
42
  activesupport (= 3.0.3)
42
43
  activesupport (3.0.3)
43
- addressable (2.2.4)
44
+ addressable (2.2.5)
44
45
  archive-tar-minitar (0.5.2)
45
46
  arel (2.0.6)
46
47
  bcrypt-ruby (2.1.4)
@@ -49,7 +50,7 @@ GEM
49
50
  diff-lcs (1.1.2)
50
51
  erubis (2.6.6)
51
52
  abstract (>= 1.0.0)
52
- faraday (0.5.5)
53
+ faraday (0.6.1)
53
54
  addressable (~> 2.2.4)
54
55
  multipart-post (~> 1.1.0)
55
56
  rack (< 2, >= 1.1.0)
@@ -65,9 +66,8 @@ GEM
65
66
  mime-types (1.16)
66
67
  multi_json (0.0.5)
67
68
  multipart-post (1.1.0)
68
- oauth (0.4.4)
69
- oauth2 (0.1.1)
70
- faraday (~> 0.5.0)
69
+ oauth2 (0.4.0)
70
+ faraday (~> 0.6.0)
71
71
  multi_json (~> 0.0.4)
72
72
  polyglot (0.3.1)
73
73
  rack (1.2.1)
@@ -89,19 +89,19 @@ GEM
89
89
  rake (>= 0.8.7)
90
90
  thor (~> 0.14.4)
91
91
  rake (0.8.7)
92
- rspec (2.3.0)
93
- rspec-core (~> 2.3.0)
94
- rspec-expectations (~> 2.3.0)
95
- rspec-mocks (~> 2.3.0)
96
- rspec-core (2.3.1)
97
- rspec-expectations (2.3.0)
92
+ rspec (2.5.0)
93
+ rspec-core (~> 2.5.0)
94
+ rspec-expectations (~> 2.5.0)
95
+ rspec-mocks (~> 2.5.0)
96
+ rspec-core (2.5.1)
97
+ rspec-expectations (2.5.0)
98
98
  diff-lcs (~> 1.1.2)
99
- rspec-mocks (2.3.0)
100
- rspec-rails (2.3.1)
99
+ rspec-mocks (2.5.0)
100
+ rspec-rails (2.5.0)
101
101
  actionpack (~> 3.0)
102
102
  activesupport (~> 3.0)
103
103
  railties (~> 3.0)
104
- rspec (~> 2.3.0)
104
+ rspec (~> 2.5.0)
105
105
  ruby-debug-base19 (0.11.24)
106
106
  columnize (>= 0.3.1)
107
107
  linecache19 (>= 0.5.11)
@@ -115,9 +115,9 @@ GEM
115
115
  simplecov (0.3.9)
116
116
  simplecov-html (>= 0.3.7)
117
117
  simplecov-html (0.3.9)
118
- spork (0.9.0.rc3)
119
118
  sqlite3-ruby (1.3.2)
120
119
  thor (0.14.6)
120
+ timecop (0.3.5)
121
121
  treetop (1.4.9)
122
122
  polyglot (>= 0.3.1)
123
123
  tzinfo (0.3.23)
@@ -126,14 +126,11 @@ PLATFORMS
126
126
  ruby
127
127
 
128
128
  DEPENDENCIES
129
- bcrypt-ruby (~> 2.1.4)
130
- oauth (>= 0.4.4)
131
- oauth2 (>= 0.1.1)
132
129
  rails (= 3.0.3)
133
- rspec
134
- rspec-rails
130
+ rspec (~> 2.5.0)
131
+ rspec-rails (~> 2.5.0)
135
132
  ruby-debug19
136
133
  simplecov (>= 0.3.8)
137
- sorcery (= 0.2.1)!
138
- spork (~> 0.9.0.rc)
134
+ sorcery (>= 0.1.0)!
139
135
  sqlite3-ruby
136
+ timecop
@@ -7,4 +7,5 @@ task :default => :spec
7
7
  desc "Run all specs for a specific rails version"
8
8
  RSpec::Core::RakeTask.new(:spec) do |t|
9
9
  t.pattern = '**/*_spec.rb'
10
+ t.rspec_opts = ["--options #{File.dirname(__FILE__)}/spec/spec.opts"]
10
11
  end
@@ -22,7 +22,7 @@ class ApplicationController < ActionController::Base
22
22
 
23
23
  def test_return_to
24
24
  @user = login(params[:username], params[:password])
25
- return_or_redirect_to(:index, :notice => 'haha!')
25
+ redirect_back_or_to(:index, :notice => 'haha!')
26
26
  end
27
27
 
28
28
  def test_logout
@@ -66,24 +66,24 @@ class ApplicationController < ActionController::Base
66
66
  render :text => "HTTP Basic Auth"
67
67
  end
68
68
 
69
- def auth_at_provider_test
70
- auth_at_provider(:twitter)
69
+ def login_at_test
70
+ login_at(:twitter)
71
71
  end
72
72
 
73
- def auth_at_provider_test2
74
- auth_at_provider(:facebook)
73
+ def login_at_test2
74
+ login_at(:facebook)
75
75
  end
76
76
 
77
- def test_login_from_access_token
78
- if @user = login_from_access_token(:twitter)
77
+ def test_login_from
78
+ if @user = login_from(:twitter)
79
79
  redirect_to "bla", :notice => "Success!"
80
80
  else
81
81
  redirect_to "blu", :alert => "Failed!"
82
82
  end
83
83
  end
84
84
 
85
- def test_login_from_access_token2
86
- if @user = login_from_access_token(:facebook)
85
+ def test_login_from2
86
+ if @user = login_from(:facebook)
87
87
  redirect_to "bla", :notice => "Success!"
88
88
  else
89
89
  redirect_to "blu", :alert => "Failed!"
@@ -92,8 +92,8 @@ class ApplicationController < ActionController::Base
92
92
 
93
93
  def test_create_from_provider
94
94
  provider = params[:provider]
95
- login_from_access_token(provider)
96
- if @user = create_from_provider!(provider)
95
+ login_from(provider)
96
+ if @user = create_from(provider)
97
97
  redirect_to "bla", :notice => "Success!"
98
98
  else
99
99
  redirect_to "blu", :alert => "Failed!"
@@ -0,0 +1,27 @@
1
+ # SQLite version 3.x
2
+ # gem install sqlite3-ruby (not necessary on OS X Leopard)
3
+ # development:
4
+ # adapter: sqlite3
5
+ # database: db/development.sqlite3
6
+ # pool: 5
7
+ # timeout: 5000
8
+ #
9
+ # # Warning: The database defined as "test" will be erased and
10
+ # # re-generated from your development database when you run "rake".
11
+ # # Do not set this db to the same as development or production.
12
+ # test:
13
+ # adapter: sqlite3
14
+ # database: db/test.sqlite3
15
+ # pool: 5
16
+ # timeout: 5000
17
+ #
18
+ # production:
19
+ # adapter: sqlite3
20
+ # database: db/production.sqlite3
21
+ # pool: 5
22
+ # timeout: 5000
23
+
24
+ in_memory:
25
+ adapter: sqlite3
26
+ database: ":memory:"
27
+ verbosity: quiet
@@ -22,10 +22,8 @@ describe ApplicationController do
22
22
  after(:each) do
23
23
  User.delete_all
24
24
  end
25
-
26
- it "should respond to 'current_users'" do
27
- subject.should respond_to(:current_users)
28
- end
25
+
26
+ specify { subject.should respond_to(:current_users) }
29
27
 
30
28
  it "'current_users' should be empty when no users are logged in" do
31
29
  subject.current_users.size.should == 0
@@ -19,6 +19,7 @@ describe ApplicationController do
19
19
  after(:each) do
20
20
  Sorcery::Controller::Config.reset!
21
21
  sorcery_controller_property_set(:user_class, User)
22
+ Timecop.return
22
23
  end
23
24
 
24
25
  it "should count login retries" do
@@ -46,7 +47,7 @@ describe ApplicationController do
46
47
  get :test_login, :username => 'gizmo', :password => 'blabla'
47
48
  get :test_login, :username => 'gizmo', :password => 'blabla'
48
49
  User.find_by_username('gizmo').lock_expires_at.should_not be_nil
49
- sleep 0.3
50
+ Timecop.travel(Time.now + 0.3)
50
51
  get :test_login, :username => 'gizmo', :password => 'blabla'
51
52
  User.find_by_username('gizmo').lock_expires_at.should be_nil
52
53
  end
@@ -57,7 +58,7 @@ describe ApplicationController do
57
58
  get :test_login, :username => 'gizmo', :password => 'blabla'
58
59
  get :test_login, :username => 'gizmo', :password => 'blabla'
59
60
  unlock_date = User.find_by_username('gizmo').lock_expires_at
60
- sleep 1
61
+ Timecop.travel(Time.now + 1)
61
62
  get :test_login, :username => 'gizmo', :password => 'blabla'
62
63
  User.find_by_username('gizmo').lock_expires_at.to_s.should == unlock_date.to_s
63
64
  end
@@ -12,16 +12,16 @@ end
12
12
 
13
13
  describe ApplicationController do
14
14
  before(:all) do
15
- ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate/oauth")
16
- sorcery_reload!([:oauth])
17
- sorcery_controller_property_set(:oauth_providers, [:facebook])
18
- sorcery_controller_oauth_property_set(:facebook, :key, "eYVNBjBDi33aa9GkA3w")
19
- sorcery_controller_oauth_property_set(:facebook, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8")
20
- sorcery_controller_oauth_property_set(:facebook, :callback_url, "http://blabla.com")
15
+ ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate/external")
16
+ sorcery_reload!([:external])
17
+ sorcery_controller_property_set(:external_providers, [:facebook])
18
+ sorcery_controller_external_property_set(:facebook, :key, "eYVNBjBDi33aa9GkA3w")
19
+ sorcery_controller_external_property_set(:facebook, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8")
20
+ sorcery_controller_external_property_set(:facebook, :callback_url, "http://blabla.com")
21
21
  end
22
22
 
23
23
  after(:all) do
24
- ActiveRecord::Migrator.rollback("#{Rails.root}/db/migrate/oauth")
24
+ ActiveRecord::Migrator.rollback("#{Rails.root}/db/migrate/external")
25
25
  end
26
26
  # ----------------- OAuth -----------------------
27
27
  describe ApplicationController, "with OAuth features" do
@@ -32,39 +32,42 @@ describe ApplicationController do
32
32
 
33
33
  after(:each) do
34
34
  User.delete_all
35
+ Authentication.delete_all
35
36
  end
36
37
 
37
- it "auth_at_provider redirects correctly" do
38
+ it "login_at redirects correctly" do
38
39
  create_new_user
39
- get :auth_at_provider_test2
40
+ get :login_at_test2
40
41
  response.should be_a_redirect
41
- response.should redirect_to("http://myapi.com/oauth/authorize?client_id=key&redirect_uri=http%3A%2F%2Fblabla.com&scope=email%2Coffline_access&type=web_server")
42
+ #response.should redirect_to("http://myapi.com/oauth/authorize?client_id=key&redirect_uri=http%3A%2F%2Fblabla.com&scope=email%2Coffline_access&type=web_server")
43
+ response.should redirect_to("http://myapi.com/oauth/authorize?client_id=key&redirect_uri=http%3A%2F%2Fblabla.com&scope=email%2Coffline_access&response_type=code")
42
44
  end
43
45
 
44
- it "'login_from_access_token' logins if user exists" do
46
+ it "'login_from' logins if user exists" do
45
47
  sorcery_model_property_set(:authentications_class, Authentication)
46
48
  create_new_external_user(:facebook)
47
- get :test_login_from_access_token2
49
+ get :test_login_from2
48
50
  flash[:notice].should == "Success!"
49
51
  end
50
52
 
51
- it "'login_from_access_token' fails if user doesn't exist" do
53
+ it "'login_from' fails if user doesn't exist" do
52
54
  sorcery_model_property_set(:authentications_class, Authentication)
53
55
  create_new_user
54
- get :test_login_from_access_token2
56
+ get :test_login_from2
55
57
  flash[:alert].should == "Failed!"
56
58
  end
57
59
  end
58
60
 
59
- describe ApplicationController, "'create_from_provider!'" do
61
+ describe ApplicationController, "'create_from'" do
60
62
  before(:each) do
61
63
  stub_all_oauth2_requests!
62
64
  User.delete_all
65
+ Authentication.delete_all
63
66
  end
64
67
 
65
68
  it "should create a new user" do
66
69
  sorcery_model_property_set(:authentications_class, Authentication)
67
- sorcery_controller_oauth_property_set(:facebook, :user_info_mapping, {:username => "name"})
70
+ sorcery_controller_external_property_set(:facebook, :user_info_mapping, {:username => "name"})
68
71
  lambda do
69
72
  get :test_create_from_provider, :provider => "facebook"
70
73
  end.should change(User, :count).by(1)
@@ -73,7 +76,7 @@ describe ApplicationController do
73
76
 
74
77
  it "should support nested attributes" do
75
78
  sorcery_model_property_set(:authentications_class, Authentication)
76
- sorcery_controller_oauth_property_set(:facebook, :user_info_mapping, {:username => "hometown/name"})
79
+ sorcery_controller_external_property_set(:facebook, :user_info_mapping, {:username => "hometown/name"})
77
80
  lambda do
78
81
  get :test_create_from_provider, :provider => "facebook"
79
82
  end.should change(User, :count).by(1)
@@ -84,11 +87,11 @@ describe ApplicationController do
84
87
  describe ApplicationController, "OAuth with User Activation features" do
85
88
  before(:all) do
86
89
  ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate/activation")
87
- sorcery_reload!([:user_activation,:oauth], :user_activation_mailer => ::SorceryMailer)
88
- sorcery_controller_property_set(:oauth_providers, [:facebook])
89
- sorcery_controller_oauth_property_set(:facebook, :key, "eYVNBjBDi33aa9GkA3w")
90
- sorcery_controller_oauth_property_set(:facebook, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8")
91
- sorcery_controller_oauth_property_set(:facebook, :callback_url, "http://blabla.com")
90
+ sorcery_reload!([:user_activation,:external], :user_activation_mailer => ::SorceryMailer)
91
+ sorcery_controller_property_set(:external_providers, [:facebook])
92
+ sorcery_controller_external_property_set(:facebook, :key, "eYVNBjBDi33aa9GkA3w")
93
+ sorcery_controller_external_property_set(:facebook, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8")
94
+ sorcery_controller_external_property_set(:facebook, :callback_url, "http://blabla.com")
92
95
  end
93
96
 
94
97
  after(:all) do
@@ -9,7 +9,9 @@ def stub_all_oauth_requests!
9
9
  @consumer.stub!(:get_request_token).and_return(@req_token)
10
10
  @acc_token = OAuth::AccessToken.new(@consumer)
11
11
  @req_token.stub!(:get_access_token).and_return(@acc_token)
12
- session[:request_token] = @req_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)
13
15
  response = OpenStruct.new()
14
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
15
17
  @acc_token.stub!(:get).and_return(response)
@@ -17,19 +19,19 @@ end
17
19
 
18
20
  describe ApplicationController do
19
21
  before(:all) do
20
- ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate/oauth")
21
- sorcery_reload!([:oauth])
22
- sorcery_controller_property_set(:oauth_providers, [:twitter])
23
- sorcery_controller_oauth_property_set(:twitter, :key, "eYVNBjBDi33aa9GkA3w")
24
- sorcery_controller_oauth_property_set(:twitter, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8")
25
- sorcery_controller_oauth_property_set(:twitter, :callback_url, "http://blabla.com")
22
+ ActiveRecord::Migrator.migrate("#{Rails.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")
26
28
  end
27
29
 
28
30
  after(:all) do
29
- ActiveRecord::Migrator.rollback("#{Rails.root}/db/migrate/oauth")
31
+ ActiveRecord::Migrator.rollback("#{Rails.root}/db/migrate/external")
30
32
  end
31
33
  # ----------------- OAuth -----------------------
32
- describe ApplicationController, "'login_from_access_token'" do
34
+ describe ApplicationController, "'using external API to login'" do
33
35
 
34
36
  before(:each) do
35
37
  stub_all_oauth_requests!
@@ -37,11 +39,12 @@ describe ApplicationController do
37
39
 
38
40
  after(:each) do
39
41
  User.delete_all
42
+ Authentication.delete_all
40
43
  end
41
44
 
42
- it "auth_at_provider redirects correctly" do
45
+ it "login_at redirects correctly" do
43
46
  create_new_user
44
- get :auth_at_provider_test
47
+ get :login_at_test
45
48
  response.should be_a_redirect
46
49
  response.should redirect_to("http://myapi.com/oauth/authorize?oauth_callback=http%3A%2F%2Fblabla.com&oauth_token=")
47
50
  end
@@ -49,27 +52,28 @@ describe ApplicationController do
49
52
  it "logins if user exists" do
50
53
  sorcery_model_property_set(:authentications_class, Authentication)
51
54
  create_new_external_user(:twitter)
52
- get :test_login_from_access_token, :oauth_verifier => "blablaRERASDFcxvSDFA"
55
+ get :test_login_from, :oauth_verifier => "blablaRERASDFcxvSDFA"
53
56
  flash[:notice].should == "Success!"
54
57
  end
55
58
 
56
- it "'login_from_access_token' fails if user doesn't exist" do
59
+ it "'login_from' fails if user doesn't exist" do
57
60
  sorcery_model_property_set(:authentications_class, Authentication)
58
61
  create_new_user
59
- get :test_login_from_access_token, :oauth_verifier => "blablaRERASDFcxvSDFA"
62
+ get :test_login_from, :oauth_verifier => "blablaRERASDFcxvSDFA"
60
63
  flash[:alert].should == "Failed!"
61
64
  end
62
65
  end
63
66
 
64
- describe ApplicationController, "'create_from_provider!'" do
67
+ describe ApplicationController, "using 'create_from'" do
65
68
  before(:each) do
66
69
  stub_all_oauth_requests!
67
70
  User.delete_all
71
+ Authentication.delete_all
68
72
  end
69
73
 
70
74
  it "should create a new user" do
71
75
  sorcery_model_property_set(:authentications_class, Authentication)
72
- sorcery_controller_oauth_property_set(:twitter, :user_info_mapping, {:username => "screen_name"})
76
+ sorcery_controller_external_property_set(:twitter, :user_info_mapping, {:username => "screen_name"})
73
77
  lambda do
74
78
  get :test_create_from_provider, :provider => "twitter"
75
79
  end.should change(User, :count).by(1)
@@ -78,7 +82,7 @@ describe ApplicationController do
78
82
 
79
83
  it "should support nested attributes" do
80
84
  sorcery_model_property_set(:authentications_class, Authentication)
81
- sorcery_controller_oauth_property_set(:twitter, :user_info_mapping, {:username => "status/text"})
85
+ sorcery_controller_external_property_set(:twitter, :user_info_mapping, {:username => "status/text"})
82
86
  lambda do
83
87
  get :test_create_from_provider, :provider => "twitter"
84
88
  end.should change(User, :count).by(1)
@@ -86,10 +90,10 @@ describe ApplicationController do
86
90
  end
87
91
  end
88
92
 
89
- describe ApplicationController, "OAuth with User Activation features" do
93
+ describe ApplicationController, "using OAuth with User Activation features" do
90
94
  before(:all) do
91
95
  ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate/activation")
92
- sorcery_reload!([:user_activation,:oauth], :user_activation_mailer => ::SorceryMailer)
96
+ sorcery_reload!([:user_activation,:external], :user_activation_mailer => ::SorceryMailer)
93
97
  end
94
98
 
95
99
  after(:all) do
@@ -98,6 +102,7 @@ describe ApplicationController do
98
102
 
99
103
  after(:each) do
100
104
  User.delete_all
105
+ Authentication.delete_all
101
106
  end
102
107
 
103
108
  it "should not send activation email to external users" do
@@ -0,0 +1,55 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe ApplicationController do
4
+
5
+ # ----------------- SESSION TIMEOUT -----------------------
6
+ describe ApplicationController, "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
+ login_user
19
+ get :test_should_be_logged_in
20
+ session[:user_id].should_not be_nil
21
+ response.should be_a_success
22
+ end
23
+
24
+ it "should reset session after session timeout" do
25
+ login_user
26
+ Timecop.travel(Time.now+0.6)
27
+ get :test_should_be_logged_in
28
+ session[:user_id].should be_nil
29
+ response.should be_a_redirect
30
+ end
31
+
32
+ context "with 'session_timeout_from_last_action'" do
33
+ it "should not logout if there was activity" do
34
+ sorcery_controller_property_set(:session_timeout_from_last_action, true)
35
+ get :test_login, :username => 'gizmo', :password => 'secret'
36
+ Timecop.travel(Time.now+0.3)
37
+ get :test_should_be_logged_in
38
+ session[:user_id].should_not be_nil
39
+ Timecop.travel(Time.now+0.3)
40
+ get :test_should_be_logged_in
41
+ session[:user_id].should_not be_nil
42
+ response.should be_a_success
43
+ end
44
+
45
+ it "with 'session_timeout_from_last_action' should logout if there was no activity" do
46
+ sorcery_controller_property_set(:session_timeout_from_last_action, true)
47
+ get :test_login, :username => 'gizmo', :password => 'secret'
48
+ Timecop.travel(Time.now+0.6)
49
+ get :test_should_be_logged_in
50
+ session[:user_id].should be_nil
51
+ response.should be_a_redirect
52
+ end
53
+ end
54
+ end
55
+ end
@@ -37,21 +37,13 @@ describe ApplicationController do
37
37
  sorcery_controller_property_set(:user_class, User)
38
38
  end
39
39
 
40
- it "should respond to the instance method login" do
41
- should respond_to(:login)
42
- end
43
-
44
- it "should respond to the instance method logout" do
45
- should respond_to(:logout)
46
- end
40
+ specify { should respond_to(:login) }
41
+
42
+ specify { should respond_to(:logout) }
47
43
 
48
- it "should respond to the instance method logged_in?" do
49
- should respond_to(:logged_in?)
50
- end
44
+ specify { should respond_to(:logged_in?) }
51
45
 
52
- it "should respond to the instance method current_user" do
53
- should respond_to(:current_user)
54
- end
46
+ specify { should respond_to(:current_user) }
55
47
 
56
48
  it "login(username,password) should return the user when success and set the session with user.id" do
57
49
  get :test_login, :username => 'gizmo', :password => 'secret'
@@ -93,9 +85,7 @@ describe ApplicationController do
93
85
  subject.current_user.should == false
94
86
  end
95
87
 
96
- it "should respond to 'require_login'" do
97
- should respond_to(:require_login)
98
- end
88
+ specify { should respond_to(:require_login) }
99
89
 
100
90
  it "should call the configured 'not_authenticated_action' when authenticate before_filter fails" do
101
91
  session[:user_id] = nil
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
@@ -0,0 +1,70 @@
1
+ $: << File.join(File.dirname(__FILE__), '..', '..', 'lib' )
2
+ # This file is copied to spec/ when you run 'rails generate rspec:install'
3
+ # Set the default environment to sqlite3's in_memory database
4
+ ENV['RAILS_ENV'] ||= 'in_memory'
5
+ require File.expand_path("../../config/environment", __FILE__)
6
+ require 'rspec/rails'
7
+ require 'timecop'
8
+ # require 'simplecov'
9
+ # SimpleCov.root File.join(File.dirname(__FILE__), "..", "..", "rails3" )
10
+ # SimpleCov.start do
11
+ # add_filter "/config/"
12
+ #
13
+ # add_group 'Controllers', 'app/controllers'
14
+ # add_group 'Models', 'app/models'
15
+ # add_group 'Helpers', 'app/helpers'
16
+ # add_group 'Libraries', 'lib'
17
+ # add_group 'Plugins', 'vendor/plugins'
18
+ # add_group 'Migrations', 'db/migrate'
19
+ # end
20
+
21
+ # Requires supporting ruby files with custom matchers and macros, etc,
22
+ # in spec/support/ and its subdirectories.
23
+ Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
24
+
25
+
26
+
27
+ RSpec.configure do |config|
28
+ config.include RSpec::Rails::ControllerExampleGroup, :example_group => { :file_path => /controller(.)*_spec.rb$/ }
29
+ # == Mock Framework
30
+ #
31
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
32
+ #
33
+ # config.mock_with :mocha
34
+ # config.mock_with :flexmock
35
+ # config.mock_with :rr
36
+ config.mock_with :rspec
37
+
38
+ # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
39
+ config.fixture_path = "#{::Rails.root}/spec/fixtures"
40
+
41
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
42
+ # examples within a transaction, remove the following line or assign false
43
+ # instead of true.
44
+ config.use_transactional_fixtures = true
45
+
46
+ config.before(:suite) do
47
+ ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate/core")
48
+ end
49
+
50
+ config.after(:suite) do
51
+ ActiveRecord::Migrator.rollback("#{Rails.root}/db/migrate/core")
52
+ end
53
+ end
54
+
55
+ #----------------------------------------------------------------
56
+ # needed when running individual specs
57
+ require File.join(File.dirname(__FILE__), '..','app','models','user')
58
+ require File.join(File.dirname(__FILE__), '..','app','models','authentication')
59
+
60
+ class TestUser < ActiveRecord::Base
61
+ authenticates_with_sorcery!
62
+ end
63
+
64
+ class TestMailer < ActionMailer::Base
65
+
66
+ end
67
+
68
+ include ::Sorcery::TestHelpers::Internal
69
+ include ::Sorcery::TestHelpers::Internal::Rails
70
+