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.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +60 -4
- data/CHANGELOG.md +15 -1
- data/Gemfile +9 -18
- data/Gemfile.rails4 +8 -10
- data/README.md +31 -11
- data/VERSION +1 -1
- data/gemfiles/active_record-rails41.gemfile +6 -0
- data/gemfiles/mongo_mapper-rails41.gemfile +8 -0
- data/gemfiles/mongoid-rails41.gemfile +11 -0
- data/lib/sorcery.rb +20 -28
- data/lib/sorcery/controller.rb +6 -11
- data/lib/sorcery/controller/submodules/external.rb +30 -15
- data/lib/sorcery/controller/submodules/session_timeout.rb +1 -1
- data/lib/sorcery/model.rb +102 -70
- data/lib/sorcery/model/adapters/active_record.rb +7 -2
- data/lib/sorcery/model/adapters/datamapper.rb +123 -0
- data/lib/sorcery/model/adapters/mongo_mapper.rb +8 -4
- data/lib/sorcery/model/adapters/mongoid.rb +6 -6
- data/lib/sorcery/model/submodules/activity_logging.rb +24 -0
- data/lib/sorcery/model/submodules/brute_force_protection.rb +16 -0
- data/lib/sorcery/model/submodules/remember_me.rb +19 -4
- data/lib/sorcery/model/submodules/reset_password.rb +30 -13
- data/lib/sorcery/model/submodules/user_activation.rb +53 -22
- data/lib/sorcery/{controller/submodules/external/protocols → protocols}/certs/ca-bundle.crt +0 -0
- data/lib/sorcery/protocols/oauth.rb +42 -0
- data/lib/sorcery/protocols/oauth2.rb +47 -0
- data/lib/sorcery/providers/base.rb +27 -0
- data/lib/sorcery/providers/facebook.rb +63 -0
- data/lib/sorcery/providers/github.rb +51 -0
- data/lib/sorcery/providers/google.rb +51 -0
- data/lib/sorcery/providers/linkedin.rb +66 -0
- data/lib/sorcery/providers/liveid.rb +53 -0
- data/lib/sorcery/providers/twitter.rb +59 -0
- data/lib/sorcery/providers/vk.rb +61 -0
- data/lib/sorcery/providers/xing.rb +64 -0
- data/lib/sorcery/test_helpers/internal.rb +3 -3
- data/lib/sorcery/test_helpers/internal/rails.rb +14 -3
- data/lib/sorcery/test_helpers/rails.rb +1 -10
- data/lib/sorcery/test_helpers/rails/controller.rb +17 -0
- data/lib/sorcery/test_helpers/rails/integration.rb +26 -0
- data/sorcery.gemspec +14 -18
- data/spec/active_record/controller_activity_logging_spec.rb +5 -116
- data/spec/active_record/controller_brute_force_protection_spec.rb +69 -47
- data/spec/active_record/controller_http_basic_auth_spec.rb +24 -18
- data/spec/active_record/controller_oauth2_spec.rb +112 -187
- data/spec/active_record/controller_oauth_spec.rb +41 -37
- data/spec/active_record/controller_remember_me_spec.rb +39 -38
- data/spec/active_record/controller_session_timeout_spec.rb +31 -16
- data/spec/active_record/controller_spec.rb +4 -178
- data/spec/active_record/integration_spec.rb +1 -1
- data/spec/active_record/user_activation_spec.rb +1 -1
- data/spec/active_record/user_activity_logging_spec.rb +1 -1
- data/spec/active_record/user_brute_force_protection_spec.rb +1 -1
- data/spec/active_record/user_oauth_spec.rb +1 -1
- data/spec/active_record/user_remember_me_spec.rb +1 -1
- data/spec/active_record/user_reset_password_spec.rb +1 -1
- data/spec/active_record/user_spec.rb +7 -8
- data/spec/datamapper/controller_activity_logging_spec.rb +17 -0
- data/spec/datamapper/controller_spec.rb +8 -0
- data/spec/datamapper/user_activation_spec.rb +10 -0
- data/spec/datamapper/user_activity_logging_spec.rb +9 -0
- data/spec/datamapper/user_brute_force_protection_spec.rb +9 -0
- data/spec/datamapper/user_oauth_spec.rb +9 -0
- data/spec/datamapper/user_remember_me_spec.rb +8 -0
- data/spec/datamapper/user_reset_password_spec.rb +8 -0
- data/spec/datamapper/user_spec.rb +27 -0
- data/spec/mongo_mapper/controller_spec.rb +4 -171
- data/spec/mongo_mapper/user_activation_spec.rb +1 -2
- data/spec/mongo_mapper/user_activity_logging_spec.rb +1 -1
- data/spec/mongo_mapper/user_brute_force_protection_spec.rb +1 -1
- data/spec/mongo_mapper/user_oauth_spec.rb +1 -1
- data/spec/mongo_mapper/user_remember_me_spec.rb +1 -1
- data/spec/mongo_mapper/user_reset_password_spec.rb +1 -1
- data/spec/mongo_mapper/user_spec.rb +7 -8
- data/spec/mongoid/controller_activity_logging_spec.rb +4 -99
- data/spec/mongoid/controller_spec.rb +4 -182
- data/spec/mongoid/user_activation_spec.rb +1 -2
- data/spec/mongoid/user_activity_logging_spec.rb +1 -2
- data/spec/mongoid/user_brute_force_protection_spec.rb +1 -2
- data/spec/mongoid/user_oauth_spec.rb +1 -2
- data/spec/mongoid/user_remember_me_spec.rb +1 -2
- data/spec/mongoid/user_reset_password_spec.rb +1 -2
- data/spec/mongoid/user_spec.rb +8 -9
- data/spec/orm/active_record.rb +2 -0
- data/spec/orm/datamapper.rb +34 -0
- data/spec/orm/mongo_mapper.rb +1 -0
- data/spec/orm/mongoid.rb +1 -0
- data/spec/rails_app/app/controllers/sorcery_controller.rb +64 -59
- data/spec/rails_app/app/datamapper/authentication.rb +8 -0
- data/spec/rails_app/app/datamapper/user.rb +7 -0
- data/spec/rails_app/config/routes.rb +18 -13
- data/spec/shared_examples/controller_activity_logging_shared_examples.rb +125 -0
- data/spec/shared_examples/controller_oauth2_shared_examples.rb +32 -36
- data/spec/shared_examples/controller_oauth_shared_examples.rb +19 -26
- data/spec/shared_examples/controller_shared_examples.rb +203 -0
- data/spec/shared_examples/user_activation_shared_examples.rb +107 -90
- data/spec/shared_examples/user_activity_logging_shared_examples.rb +10 -10
- data/spec/shared_examples/user_brute_force_protection_shared_examples.rb +14 -13
- data/spec/shared_examples/user_oauth_shared_examples.rb +23 -15
- data/spec/shared_examples/user_remember_me_shared_examples.rb +32 -23
- data/spec/shared_examples/user_reset_password_shared_examples.rb +136 -115
- data/spec/shared_examples/user_shared_examples.rb +206 -146
- data/spec/sorcery_crypto_providers_spec.rb +28 -28
- data/spec/spec_helper.rb +15 -6
- metadata +83 -127
- data/lib/sorcery/controller/submodules/external/protocols/oauth1.rb +0 -46
- data/lib/sorcery/controller/submodules/external/protocols/oauth2.rb +0 -50
- data/lib/sorcery/controller/submodules/external/providers/base.rb +0 -21
- data/lib/sorcery/controller/submodules/external/providers/facebook.rb +0 -99
- data/lib/sorcery/controller/submodules/external/providers/github.rb +0 -93
- data/lib/sorcery/controller/submodules/external/providers/google.rb +0 -92
- data/lib/sorcery/controller/submodules/external/providers/linkedin.rb +0 -103
- data/lib/sorcery/controller/submodules/external/providers/liveid.rb +0 -93
- data/lib/sorcery/controller/submodules/external/providers/twitter.rb +0 -94
- data/lib/sorcery/controller/submodules/external/providers/vk.rb +0 -101
- data/lib/sorcery/controller/submodules/external/providers/xing.rb +0 -98
- data/lib/sorcery/test_helpers.rb +0 -5
data/spec/orm/active_record.rb
CHANGED
@@ -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!
|
data/spec/orm/mongo_mapper.rb
CHANGED
data/spec/orm/mongoid.rb
CHANGED
@@ -3,181 +3,186 @@ require 'oauth'
|
|
3
3
|
class SorceryController < ActionController::Base
|
4
4
|
protect_from_forgery
|
5
5
|
|
6
|
-
|
7
|
-
before_filter :
|
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 :
|
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 =
|
19
|
-
render :
|
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 :
|
23
|
+
render nothing: true
|
25
24
|
end
|
26
25
|
|
27
26
|
def test_auto_login
|
28
|
-
@user = User.
|
27
|
+
@user = User.first
|
29
28
|
auto_login(@user)
|
30
29
|
@result = current_user
|
31
|
-
render :
|
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, :
|
35
|
+
redirect_back_or_to(:index, notice: 'haha!')
|
37
36
|
end
|
38
37
|
|
39
38
|
def test_logout
|
40
39
|
logout
|
41
|
-
render :
|
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 :
|
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 :
|
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 :
|
59
|
+
render nothing: true
|
61
60
|
end
|
62
61
|
|
63
62
|
def test_login_from_cookie
|
64
63
|
@user = current_user
|
65
|
-
render :
|
64
|
+
render nothing: true
|
66
65
|
end
|
67
66
|
|
68
67
|
def test_not_authenticated_action
|
69
|
-
render :
|
68
|
+
render text: 'test_not_authenticated_action'
|
70
69
|
end
|
71
70
|
|
72
71
|
def test_should_be_logged_in
|
73
|
-
render :
|
72
|
+
render nothing: true
|
74
73
|
end
|
75
74
|
|
76
75
|
def test_http_basic_auth
|
77
|
-
render :
|
76
|
+
render text: 'HTTP Basic Auth'
|
78
77
|
end
|
79
78
|
|
80
|
-
def
|
79
|
+
def login_at_test_twitter
|
81
80
|
login_at(:twitter)
|
82
81
|
end
|
83
82
|
|
84
|
-
|
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
|
89
|
+
def login_at_test_github
|
89
90
|
login_at(:github)
|
90
91
|
end
|
91
92
|
|
92
|
-
def
|
93
|
+
def login_at_test_google
|
93
94
|
login_at(:google)
|
94
95
|
end
|
95
96
|
|
96
|
-
def
|
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, {:
|
102
|
+
login_at(:facebook, {state: 'bla'})
|
102
103
|
end
|
103
104
|
|
104
|
-
def
|
105
|
+
def test_login_from_twitter
|
105
106
|
if @user = login_from(:twitter)
|
106
|
-
redirect_to
|
107
|
+
redirect_to 'bla', notice: 'Success!'
|
107
108
|
else
|
108
|
-
redirect_to
|
109
|
+
redirect_to 'blu', alert: 'Failed!'
|
109
110
|
end
|
110
111
|
end
|
111
112
|
|
112
|
-
|
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
|
117
|
+
redirect_to 'bla', notice: 'Success!'
|
115
118
|
else
|
116
|
-
redirect_to
|
119
|
+
redirect_to 'blu', alert: 'Failed!'
|
117
120
|
end
|
118
121
|
end
|
119
122
|
|
120
|
-
def
|
123
|
+
def test_login_from_github
|
121
124
|
if @user = login_from(:github)
|
122
|
-
redirect_to
|
125
|
+
redirect_to 'bla', notice: 'Success!'
|
123
126
|
else
|
124
|
-
redirect_to
|
127
|
+
redirect_to 'blu', alert: 'Failed!'
|
125
128
|
end
|
126
129
|
end
|
127
130
|
|
128
|
-
def
|
131
|
+
def test_login_from_google
|
129
132
|
if @user = login_from(:google)
|
130
|
-
redirect_to
|
133
|
+
redirect_to 'bla', notice: 'Success!'
|
131
134
|
else
|
132
|
-
redirect_to
|
135
|
+
redirect_to 'blu', alert: 'Failed!'
|
133
136
|
end
|
134
137
|
end
|
135
138
|
|
136
|
-
def
|
139
|
+
def test_login_from_liveid
|
137
140
|
if @user = login_from(:liveid)
|
138
|
-
redirect_to
|
141
|
+
redirect_to 'bla', notice: 'Success!'
|
139
142
|
else
|
140
|
-
redirect_to
|
143
|
+
redirect_to 'blu', alert: 'Failed!'
|
141
144
|
end
|
142
145
|
end
|
143
146
|
|
144
|
-
def
|
147
|
+
def test_return_to_with_external_twitter
|
145
148
|
if @user = login_from(:twitter)
|
146
|
-
redirect_back_or_to
|
149
|
+
redirect_back_or_to 'bla', notice: 'Success!'
|
147
150
|
else
|
148
|
-
redirect_to
|
151
|
+
redirect_to 'blu', alert: 'Failed!'
|
149
152
|
end
|
150
153
|
end
|
151
154
|
|
152
|
-
|
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
|
159
|
+
redirect_back_or_to 'bla', notice: 'Success!'
|
155
160
|
else
|
156
|
-
redirect_to
|
161
|
+
redirect_to 'blu', alert: 'Failed!'
|
157
162
|
end
|
158
163
|
end
|
159
164
|
|
160
|
-
def
|
165
|
+
def test_return_to_with_external_github
|
161
166
|
if @user = login_from(:github)
|
162
|
-
redirect_back_or_to
|
167
|
+
redirect_back_or_to 'bla', notice: 'Success!'
|
163
168
|
else
|
164
|
-
redirect_to
|
169
|
+
redirect_to 'blu', alert: 'Failed!'
|
165
170
|
end
|
166
171
|
end
|
167
172
|
|
168
|
-
def
|
173
|
+
def test_return_to_with_external_google
|
169
174
|
if @user = login_from(:google)
|
170
|
-
redirect_back_or_to
|
175
|
+
redirect_back_or_to 'bla', notice: 'Success!'
|
171
176
|
else
|
172
|
-
redirect_to
|
177
|
+
redirect_to 'blu', alert: 'Failed!'
|
173
178
|
end
|
174
179
|
end
|
175
180
|
|
176
|
-
def
|
181
|
+
def test_return_to_with_external_liveid
|
177
182
|
if @user = login_from(:liveid)
|
178
|
-
redirect_back_or_to
|
183
|
+
redirect_back_or_to 'bla', notice: 'Success!'
|
179
184
|
else
|
180
|
-
redirect_to
|
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
|
193
|
+
redirect_to 'bla', notice: 'Success!'
|
189
194
|
else
|
190
|
-
redirect_to
|
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(:
|
215
|
+
User.where(email: user.email).empty?
|
211
216
|
end
|
212
217
|
if @user
|
213
|
-
redirect_to
|
218
|
+
redirect_to 'bla', notice: 'Success!'
|
214
219
|
else
|
215
|
-
redirect_to
|
220
|
+
redirect_to 'blu', alert: 'Failed!'
|
216
221
|
end
|
217
222
|
end
|
218
223
|
|
@@ -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 :
|
19
|
-
get :
|
20
|
-
get :
|
21
|
-
get :
|
22
|
-
get :
|
23
|
-
get :
|
24
|
-
get :
|
25
|
-
get :
|
26
|
-
get :
|
27
|
-
get :
|
28
|
-
get :
|
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
|