sorcery 0.8.5 → 0.8.6

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 (119) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +60 -4
  4. data/CHANGELOG.md +15 -1
  5. data/Gemfile +9 -18
  6. data/Gemfile.rails4 +8 -10
  7. data/README.md +31 -11
  8. data/VERSION +1 -1
  9. data/gemfiles/active_record-rails41.gemfile +6 -0
  10. data/gemfiles/mongo_mapper-rails41.gemfile +8 -0
  11. data/gemfiles/mongoid-rails41.gemfile +11 -0
  12. data/lib/sorcery.rb +20 -28
  13. data/lib/sorcery/controller.rb +6 -11
  14. data/lib/sorcery/controller/submodules/external.rb +30 -15
  15. data/lib/sorcery/controller/submodules/session_timeout.rb +1 -1
  16. data/lib/sorcery/model.rb +102 -70
  17. data/lib/sorcery/model/adapters/active_record.rb +7 -2
  18. data/lib/sorcery/model/adapters/datamapper.rb +123 -0
  19. data/lib/sorcery/model/adapters/mongo_mapper.rb +8 -4
  20. data/lib/sorcery/model/adapters/mongoid.rb +6 -6
  21. data/lib/sorcery/model/submodules/activity_logging.rb +24 -0
  22. data/lib/sorcery/model/submodules/brute_force_protection.rb +16 -0
  23. data/lib/sorcery/model/submodules/remember_me.rb +19 -4
  24. data/lib/sorcery/model/submodules/reset_password.rb +30 -13
  25. data/lib/sorcery/model/submodules/user_activation.rb +53 -22
  26. data/lib/sorcery/{controller/submodules/external/protocols → protocols}/certs/ca-bundle.crt +0 -0
  27. data/lib/sorcery/protocols/oauth.rb +42 -0
  28. data/lib/sorcery/protocols/oauth2.rb +47 -0
  29. data/lib/sorcery/providers/base.rb +27 -0
  30. data/lib/sorcery/providers/facebook.rb +63 -0
  31. data/lib/sorcery/providers/github.rb +51 -0
  32. data/lib/sorcery/providers/google.rb +51 -0
  33. data/lib/sorcery/providers/linkedin.rb +66 -0
  34. data/lib/sorcery/providers/liveid.rb +53 -0
  35. data/lib/sorcery/providers/twitter.rb +59 -0
  36. data/lib/sorcery/providers/vk.rb +61 -0
  37. data/lib/sorcery/providers/xing.rb +64 -0
  38. data/lib/sorcery/test_helpers/internal.rb +3 -3
  39. data/lib/sorcery/test_helpers/internal/rails.rb +14 -3
  40. data/lib/sorcery/test_helpers/rails.rb +1 -10
  41. data/lib/sorcery/test_helpers/rails/controller.rb +17 -0
  42. data/lib/sorcery/test_helpers/rails/integration.rb +26 -0
  43. data/sorcery.gemspec +14 -18
  44. data/spec/active_record/controller_activity_logging_spec.rb +5 -116
  45. data/spec/active_record/controller_brute_force_protection_spec.rb +69 -47
  46. data/spec/active_record/controller_http_basic_auth_spec.rb +24 -18
  47. data/spec/active_record/controller_oauth2_spec.rb +112 -187
  48. data/spec/active_record/controller_oauth_spec.rb +41 -37
  49. data/spec/active_record/controller_remember_me_spec.rb +39 -38
  50. data/spec/active_record/controller_session_timeout_spec.rb +31 -16
  51. data/spec/active_record/controller_spec.rb +4 -178
  52. data/spec/active_record/integration_spec.rb +1 -1
  53. data/spec/active_record/user_activation_spec.rb +1 -1
  54. data/spec/active_record/user_activity_logging_spec.rb +1 -1
  55. data/spec/active_record/user_brute_force_protection_spec.rb +1 -1
  56. data/spec/active_record/user_oauth_spec.rb +1 -1
  57. data/spec/active_record/user_remember_me_spec.rb +1 -1
  58. data/spec/active_record/user_reset_password_spec.rb +1 -1
  59. data/spec/active_record/user_spec.rb +7 -8
  60. data/spec/datamapper/controller_activity_logging_spec.rb +17 -0
  61. data/spec/datamapper/controller_spec.rb +8 -0
  62. data/spec/datamapper/user_activation_spec.rb +10 -0
  63. data/spec/datamapper/user_activity_logging_spec.rb +9 -0
  64. data/spec/datamapper/user_brute_force_protection_spec.rb +9 -0
  65. data/spec/datamapper/user_oauth_spec.rb +9 -0
  66. data/spec/datamapper/user_remember_me_spec.rb +8 -0
  67. data/spec/datamapper/user_reset_password_spec.rb +8 -0
  68. data/spec/datamapper/user_spec.rb +27 -0
  69. data/spec/mongo_mapper/controller_spec.rb +4 -171
  70. data/spec/mongo_mapper/user_activation_spec.rb +1 -2
  71. data/spec/mongo_mapper/user_activity_logging_spec.rb +1 -1
  72. data/spec/mongo_mapper/user_brute_force_protection_spec.rb +1 -1
  73. data/spec/mongo_mapper/user_oauth_spec.rb +1 -1
  74. data/spec/mongo_mapper/user_remember_me_spec.rb +1 -1
  75. data/spec/mongo_mapper/user_reset_password_spec.rb +1 -1
  76. data/spec/mongo_mapper/user_spec.rb +7 -8
  77. data/spec/mongoid/controller_activity_logging_spec.rb +4 -99
  78. data/spec/mongoid/controller_spec.rb +4 -182
  79. data/spec/mongoid/user_activation_spec.rb +1 -2
  80. data/spec/mongoid/user_activity_logging_spec.rb +1 -2
  81. data/spec/mongoid/user_brute_force_protection_spec.rb +1 -2
  82. data/spec/mongoid/user_oauth_spec.rb +1 -2
  83. data/spec/mongoid/user_remember_me_spec.rb +1 -2
  84. data/spec/mongoid/user_reset_password_spec.rb +1 -2
  85. data/spec/mongoid/user_spec.rb +8 -9
  86. data/spec/orm/active_record.rb +2 -0
  87. data/spec/orm/datamapper.rb +34 -0
  88. data/spec/orm/mongo_mapper.rb +1 -0
  89. data/spec/orm/mongoid.rb +1 -0
  90. data/spec/rails_app/app/controllers/sorcery_controller.rb +64 -59
  91. data/spec/rails_app/app/datamapper/authentication.rb +8 -0
  92. data/spec/rails_app/app/datamapper/user.rb +7 -0
  93. data/spec/rails_app/config/routes.rb +18 -13
  94. data/spec/shared_examples/controller_activity_logging_shared_examples.rb +125 -0
  95. data/spec/shared_examples/controller_oauth2_shared_examples.rb +32 -36
  96. data/spec/shared_examples/controller_oauth_shared_examples.rb +19 -26
  97. data/spec/shared_examples/controller_shared_examples.rb +203 -0
  98. data/spec/shared_examples/user_activation_shared_examples.rb +107 -90
  99. data/spec/shared_examples/user_activity_logging_shared_examples.rb +10 -10
  100. data/spec/shared_examples/user_brute_force_protection_shared_examples.rb +14 -13
  101. data/spec/shared_examples/user_oauth_shared_examples.rb +23 -15
  102. data/spec/shared_examples/user_remember_me_shared_examples.rb +32 -23
  103. data/spec/shared_examples/user_reset_password_shared_examples.rb +136 -115
  104. data/spec/shared_examples/user_shared_examples.rb +206 -146
  105. data/spec/sorcery_crypto_providers_spec.rb +28 -28
  106. data/spec/spec_helper.rb +15 -6
  107. metadata +83 -127
  108. data/lib/sorcery/controller/submodules/external/protocols/oauth1.rb +0 -46
  109. data/lib/sorcery/controller/submodules/external/protocols/oauth2.rb +0 -50
  110. data/lib/sorcery/controller/submodules/external/providers/base.rb +0 -21
  111. data/lib/sorcery/controller/submodules/external/providers/facebook.rb +0 -99
  112. data/lib/sorcery/controller/submodules/external/providers/github.rb +0 -93
  113. data/lib/sorcery/controller/submodules/external/providers/google.rb +0 -92
  114. data/lib/sorcery/controller/submodules/external/providers/linkedin.rb +0 -103
  115. data/lib/sorcery/controller/submodules/external/providers/liveid.rb +0 -93
  116. data/lib/sorcery/controller/submodules/external/providers/twitter.rb +0 -94
  117. data/lib/sorcery/controller/submodules/external/providers/vk.rb +0 -101
  118. data/lib/sorcery/controller/submodules/external/providers/xing.rb +0 -98
  119. data/lib/sorcery/test_helpers.rb +0 -5
@@ -1,3 +1,5 @@
1
+ require 'sorcery'
2
+
1
3
  ActiveRecord::Migration.verbose = false
2
4
  # ActiveRecord::Base.logger = Logger.new(nil)
3
5
  # ActiveRecord::Base.include_root_in_json = true
@@ -0,0 +1,34 @@
1
+ require 'data_mapper'
2
+ require 'dm-migrations'
3
+ require 'sorcery'
4
+
5
+ #DataMapper.setup(:default, 'sqlite::memory:')
6
+ # NOTE
7
+ # 1. Problems with Time fields, hh mm ss values.
8
+ #DataMapper.setup(:default, "sqlite3://#{File.dirname(__FILE__)}/../rails_app/test.sqlite3")
9
+
10
+ # MySQL
11
+ # NOTE
12
+ # 1. Create test database.
13
+ # 2. DM creates tables case insensitive by default.
14
+ # -
15
+ #DataMapper.setup(:default, "mysql://root:<password>@localhost/sorcery_test")
16
+ DataMapper.setup(:default, "mysql://root@127.0.0.1/sorcery_test")
17
+
18
+ # Redis
19
+ # NOTE
20
+ # 1. Submodule activity_logging is not supported.
21
+ # 2. case sensitive.
22
+ #DataMapper.setup(:default, {
23
+ # :adapter => 'redis',
24
+ # :host => 'localhost',
25
+ # :port => 6379,
26
+ #})
27
+
28
+ class TestUser
29
+ include DataMapper::Resource
30
+ property :id, Serial
31
+ authenticates_with_sorcery!
32
+ end
33
+ TestUser.finalize
34
+ DataMapper.auto_migrate!
@@ -1,4 +1,5 @@
1
1
  require 'mongo_mapper'
2
+ require 'sorcery'
2
3
 
3
4
  MongoMapper.connection = Mongo::Connection.new('localhost', 27017)
4
5
  MongoMapper.database = "sorcery_mongomapper_test"
@@ -1,4 +1,5 @@
1
1
  require 'mongoid'
2
+ require 'sorcery'
2
3
 
3
4
  Mongoid.configure do |config|
4
5
  database = "sorcery_mongoid_test"
@@ -3,181 +3,186 @@ require 'oauth'
3
3
  class SorceryController < ActionController::Base
4
4
  protect_from_forgery
5
5
 
6
- #before_filter :validate_session, :only => [:test_should_be_logged_in] if defined?(:validate_session)
7
- before_filter :require_login_from_http_basic, :only => [:test_http_basic_auth]
8
- before_filter :require_login, :only => [:test_logout, :test_should_be_logged_in, :some_action]
6
+ before_filter :require_login_from_http_basic, only: [:test_http_basic_auth]
7
+ before_filter :require_login, only: [:test_logout, :test_should_be_logged_in, :some_action]
9
8
 
10
9
  def index
11
10
  end
12
11
 
13
12
  def some_action
14
- render :nothing => true
13
+ render nothing: true
15
14
  end
16
15
 
17
16
  def some_action_making_a_non_persisted_change_to_the_user
18
- current_user.email = "to_be_ignored"
19
- render :nothing => true
17
+ current_user.email = 'to_be_ignored'
18
+ render nothing: true
20
19
  end
21
20
 
22
21
  def test_login
23
22
  @user = login(params[:email], params[:password])
24
- render :text => ""
23
+ render nothing: true
25
24
  end
26
25
 
27
26
  def test_auto_login
28
- @user = User.find(:first)
27
+ @user = User.first
29
28
  auto_login(@user)
30
29
  @result = current_user
31
- render :text => ""
30
+ render nothing: true
32
31
  end
33
32
 
34
33
  def test_return_to
35
34
  @user = login(params[:email], params[:password])
36
- redirect_back_or_to(:index, :notice => 'haha!')
35
+ redirect_back_or_to(:index, notice: 'haha!')
37
36
  end
38
37
 
39
38
  def test_logout
40
39
  logout
41
- render :text => ""
40
+ render nothing: true
42
41
  end
43
42
 
44
43
  def test_logout_with_remember
45
44
  remember_me!
46
45
  logout
47
- render :text => ""
46
+ render nothing: true
48
47
  end
49
48
 
50
49
  def test_login_with_remember
51
50
  @user = login(params[:email], params[:password])
52
51
  remember_me!
53
52
 
54
- render :text => ""
53
+ render nothing: true
55
54
  end
56
55
 
57
56
  def test_login_with_remember_in_login
58
57
  @user = login(params[:email], params[:password], params[:remember])
59
58
 
60
- render :text => ""
59
+ render nothing: true
61
60
  end
62
61
 
63
62
  def test_login_from_cookie
64
63
  @user = current_user
65
- render :text => ""
64
+ render nothing: true
66
65
  end
67
66
 
68
67
  def test_not_authenticated_action
69
- render :text => "test_not_authenticated_action"
68
+ render text: 'test_not_authenticated_action'
70
69
  end
71
70
 
72
71
  def test_should_be_logged_in
73
- render :text => ""
72
+ render nothing: true
74
73
  end
75
74
 
76
75
  def test_http_basic_auth
77
- render :text => "HTTP Basic Auth"
76
+ render text: 'HTTP Basic Auth'
78
77
  end
79
78
 
80
- def login_at_test
79
+ def login_at_test_twitter
81
80
  login_at(:twitter)
82
81
  end
83
82
 
84
- def login_at_test2
83
+ alias :login_at_test :login_at_test_twitter
84
+
85
+ def login_at_test_facebook
85
86
  login_at(:facebook)
86
87
  end
87
88
 
88
- def login_at_test3
89
+ def login_at_test_github
89
90
  login_at(:github)
90
91
  end
91
92
 
92
- def login_at_test4
93
+ def login_at_test_google
93
94
  login_at(:google)
94
95
  end
95
96
 
96
- def login_at_test5
97
+ def login_at_test_liveid
97
98
  login_at(:liveid)
98
99
  end
99
100
 
100
101
  def login_at_test_with_state
101
- login_at(:facebook, {:state => "bla"})
102
+ login_at(:facebook, {state: 'bla'})
102
103
  end
103
104
 
104
- def test_login_from
105
+ def test_login_from_twitter
105
106
  if @user = login_from(:twitter)
106
- redirect_to "bla", :notice => "Success!"
107
+ redirect_to 'bla', notice: 'Success!'
107
108
  else
108
- redirect_to "blu", :alert => "Failed!"
109
+ redirect_to 'blu', alert: 'Failed!'
109
110
  end
110
111
  end
111
112
 
112
- def test_login_from2
113
+ alias :test_login_from :test_login_from_twitter
114
+
115
+ def test_login_from_facebook
113
116
  if @user = login_from(:facebook)
114
- redirect_to "bla", :notice => "Success!"
117
+ redirect_to 'bla', notice: 'Success!'
115
118
  else
116
- redirect_to "blu", :alert => "Failed!"
119
+ redirect_to 'blu', alert: 'Failed!'
117
120
  end
118
121
  end
119
122
 
120
- def test_login_from3
123
+ def test_login_from_github
121
124
  if @user = login_from(:github)
122
- redirect_to "bla", :notice => "Success!"
125
+ redirect_to 'bla', notice: 'Success!'
123
126
  else
124
- redirect_to "blu", :alert => "Failed!"
127
+ redirect_to 'blu', alert: 'Failed!'
125
128
  end
126
129
  end
127
130
 
128
- def test_login_from4
131
+ def test_login_from_google
129
132
  if @user = login_from(:google)
130
- redirect_to "bla", :notice => "Success!"
133
+ redirect_to 'bla', notice: 'Success!'
131
134
  else
132
- redirect_to "blu", :alert => "Failed!"
135
+ redirect_to 'blu', alert: 'Failed!'
133
136
  end
134
137
  end
135
138
 
136
- def test_login_from5
139
+ def test_login_from_liveid
137
140
  if @user = login_from(:liveid)
138
- redirect_to "bla", :notice => "Success!"
141
+ redirect_to 'bla', notice: 'Success!'
139
142
  else
140
- redirect_to "blu", :alert => "Failed!"
143
+ redirect_to 'blu', alert: 'Failed!'
141
144
  end
142
145
  end
143
146
 
144
- def test_return_to_with_external
147
+ def test_return_to_with_external_twitter
145
148
  if @user = login_from(:twitter)
146
- redirect_back_or_to "bla", :notice => "Success!"
149
+ redirect_back_or_to 'bla', notice: 'Success!'
147
150
  else
148
- redirect_to "blu", :alert => "Failed!"
151
+ redirect_to 'blu', alert: 'Failed!'
149
152
  end
150
153
  end
151
154
 
152
- def test_return_to_with_external2
155
+ alias :test_return_to_with_external :test_return_to_with_external_twitter
156
+
157
+ def test_return_to_with_external_facebook
153
158
  if @user = login_from(:facebook)
154
- redirect_back_or_to "bla", :notice => "Success!"
159
+ redirect_back_or_to 'bla', notice: 'Success!'
155
160
  else
156
- redirect_to "blu", :alert => "Failed!"
161
+ redirect_to 'blu', alert: 'Failed!'
157
162
  end
158
163
  end
159
164
 
160
- def test_return_to_with_external3
165
+ def test_return_to_with_external_github
161
166
  if @user = login_from(:github)
162
- redirect_back_or_to "bla", :notice => "Success!"
167
+ redirect_back_or_to 'bla', notice: 'Success!'
163
168
  else
164
- redirect_to "blu", :alert => "Failed!"
169
+ redirect_to 'blu', alert: 'Failed!'
165
170
  end
166
171
  end
167
172
 
168
- def test_return_to_with_external4
173
+ def test_return_to_with_external_google
169
174
  if @user = login_from(:google)
170
- redirect_back_or_to "bla", :notice => "Success!"
175
+ redirect_back_or_to 'bla', notice: 'Success!'
171
176
  else
172
- redirect_to "blu", :alert => "Failed!"
177
+ redirect_to 'blu', alert: 'Failed!'
173
178
  end
174
179
  end
175
180
 
176
- def test_return_to_with_external5
181
+ def test_return_to_with_external_liveid
177
182
  if @user = login_from(:liveid)
178
- redirect_back_or_to "bla", :notice => "Success!"
183
+ redirect_back_or_to 'bla', notice: 'Success!'
179
184
  else
180
- redirect_to "blu", :alert => "Failed!"
185
+ redirect_to 'blu', alert: 'Failed!'
181
186
  end
182
187
  end
183
188
 
@@ -185,9 +190,9 @@ class SorceryController < ActionController::Base
185
190
  provider = params[:provider]
186
191
  login_from(provider)
187
192
  if @user = create_from(provider)
188
- redirect_to "bla", :notice => "Success!"
193
+ redirect_to 'bla', notice: 'Success!'
189
194
  else
190
- redirect_to "blu", :alert => "Failed!"
195
+ redirect_to 'blu', alert: 'Failed!'
191
196
  end
192
197
  end
193
198
 
@@ -207,12 +212,12 @@ class SorceryController < ActionController::Base
207
212
  login_from(provider)
208
213
  @user = create_from(provider) do |user|
209
214
  # check uniqueness of email
210
- User.where(:email => user.email).empty?
215
+ User.where(email: user.email).empty?
211
216
  end
212
217
  if @user
213
- redirect_to "bla", :notice => "Success!"
218
+ redirect_to 'bla', notice: 'Success!'
214
219
  else
215
- redirect_to "blu", :alert => "Failed!"
220
+ redirect_to 'blu', alert: 'Failed!'
216
221
  end
217
222
  end
218
223
 
@@ -0,0 +1,8 @@
1
+ class Authentication
2
+ include DataMapper::Resource
3
+
4
+ property :id, Serial
5
+ property :uid, Integer
6
+ property :provider, String
7
+ belongs_to :user
8
+ end
@@ -0,0 +1,7 @@
1
+ class User
2
+ include DataMapper::Resource
3
+ property :id, Serial
4
+ property :username, String
5
+
6
+ has n, :authentications, :constraint => :destroy
7
+ end
@@ -15,23 +15,28 @@ AppRoot::Application.routes.draw do
15
15
  get :test_create_from_provider
16
16
  get :test_add_second_provider
17
17
  get :test_return_to_with_external
18
- get :test_login_from5
19
- get :test_login_from4
20
- get :test_login_from2
21
- get :test_login_from3
22
- get :test_return_to_with_external5
23
- get :login_at_test2
24
- get :login_at_test3
25
- get :login_at_test4
26
- get :test_return_to_with_external2
27
- get :test_return_to_with_external3
28
- get :test_return_to_with_external4
18
+ get :test_login_from
19
+ get :test_login_from_twitter
20
+ get :test_login_from_facebook
21
+ get :test_login_from_github
22
+ get :test_login_from_google
23
+ get :test_login_from_liveid
24
+ get :login_at_test
25
+ get :login_at_test_twitter
26
+ get :login_at_test_facebook
27
+ get :login_at_test_github
28
+ get :login_at_test_google
29
+ get :login_at_test_liveid
30
+ get :test_return_to_with_external
31
+ get :test_return_to_with_external_twitter
32
+ get :test_return_to_with_external_facebook
33
+ get :test_return_to_with_external_github
34
+ get :test_return_to_with_external_google
35
+ get :test_return_to_with_external_liveid
29
36
  get :test_http_basic_auth
30
37
  get :some_action_making_a_non_persisted_change_to_the_user
31
38
  post :test_login_with_remember
32
39
  get :test_create_from_provider_with_block
33
- get :login_at_test
34
- get :login_at_test5
35
40
  get :login_at_test_with_state
36
41
  end
37
42
  end
@@ -0,0 +1,125 @@
1
+ shared_examples_for "controller_activity_logging" do
2
+
3
+ before(:all) do
4
+ sorcery_reload!([:activity_logging])
5
+ end
6
+
7
+ specify { expect(subject).to respond_to(:current_users) }
8
+ let(:user) { create_new_user }
9
+
10
+ before(:each) { user }
11
+
12
+ it "'current_users' is empty when no users are logged in" do
13
+ expect(subject.current_users.size).to eq 0
14
+ end
15
+
16
+ it "logs login time on login" do
17
+ now = Time.now.in_time_zone
18
+ login_user
19
+
20
+ expect(user.last_login_at).not_to be_nil
21
+ expect(user.last_login_at.utc.to_s).to be >= now.utc.to_s
22
+ expect(user.last_login_at.utc.to_s).to be <= (now.utc+2).to_s
23
+ end
24
+
25
+ it "logs logout time on logout" do
26
+ login_user
27
+ now = Time.now.in_time_zone
28
+ logout_user
29
+
30
+ expect(User.last.last_logout_at).not_to be_nil
31
+
32
+ expect(User.last.last_logout_at.utc.to_s).to be >= now.utc.to_s
33
+ expect(User.last.last_logout_at.utc.to_s).to be <= (now+2).utc.to_s
34
+ end
35
+
36
+ it "logs last activity time when logged in" do
37
+ sorcery_controller_property_set(:register_last_activity_time, true)
38
+
39
+ login_user
40
+ now = Time.now.in_time_zone
41
+ get :some_action
42
+
43
+ last_activity_at = User.last.last_activity_at
44
+
45
+ expect(last_activity_at).to be_present
46
+ expect(last_activity_at.utc.to_s).to be >= now.utc.to_s
47
+ expect(last_activity_at.utc.to_s).to be <= (now+2).utc.to_s
48
+ end
49
+
50
+ it "logs last IP address when logged in" do
51
+ login_user
52
+ get :some_action
53
+
54
+ expect(User.last.last_login_from_ip_address).to eq "0.0.0.0"
55
+ end
56
+
57
+ it "updates nothing but activity fields" do
58
+ original_user_name = User.last.username
59
+ login_user
60
+ get :some_action_making_a_non_persisted_change_to_the_user
61
+
62
+ expect(User.last.username).to eq original_user_name
63
+ end
64
+
65
+ it "'current_users' holds the user object when 1 user is logged in" do
66
+ login_user
67
+ get :some_action
68
+
69
+ expect(subject.current_users).to match([User.find(user.id)])
70
+ end
71
+
72
+ it "'current_users' shows all current_users, whether they have logged out before or not." do
73
+ user1 = create_new_user({:username => 'gizmo1', :email => "bla1@bla.com", :password => 'secret1'})
74
+ login_user(user1)
75
+ get :some_action
76
+ clear_user_without_logout
77
+ user2 = create_new_user({:username => 'gizmo2', :email => "bla2@bla.com", :password => 'secret2'})
78
+ login_user(user2)
79
+ get :some_action
80
+ clear_user_without_logout
81
+ user3 = create_new_user({:username => 'gizmo3', :email => "bla3@bla.com", :password => 'secret3'})
82
+ login_user(user3)
83
+ get :some_action
84
+
85
+ expect(subject.current_users.size).to eq 3
86
+ expect(subject.current_users[0]).to eq User.find(user1.id)
87
+ expect(subject.current_users[1]).to eq User.find(user2.id)
88
+ expect(subject.current_users[2]).to eq User.find(user3.id)
89
+ end
90
+
91
+ it "does not register login time if configured so" do
92
+ sorcery_controller_property_set(:register_login_time, false)
93
+ now = Time.now.in_time_zone
94
+ login_user
95
+
96
+ expect(user.last_login_at).to be_nil
97
+ end
98
+
99
+ it "does not register logout time if configured so" do
100
+ sorcery_controller_property_set(:register_logout_time, false)
101
+ now = Time.now.in_time_zone
102
+ login_user
103
+ logout_user
104
+
105
+ expect(user.last_logout_at).to be_nil
106
+ end
107
+
108
+ it "does not register last activity time if configured so" do
109
+ sorcery_controller_property_set(:register_last_activity_time, false)
110
+ now = Time.now.in_time_zone
111
+ login_user
112
+ get :some_action
113
+
114
+ expect(user.last_activity_at).to be_nil
115
+ end
116
+
117
+ it "does not register last IP address if configured so" do
118
+ sorcery_controller_property_set(:register_last_ip_address, false)
119
+ ip_address = "127.0.0.1"
120
+ login_user
121
+ get :some_action
122
+
123
+ expect(user.last_activity_at).to be_nil
124
+ end
125
+ end