sorcery 0.12.0 → 0.13.0
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 +5 -5
- data/.github/ISSUE_TEMPLATE.md +20 -0
- data/.rubocop.yml +52 -2
- data/.rubocop_todo.yml +1 -429
- data/.travis.yml +11 -21
- data/CHANGELOG.md +16 -0
- data/Gemfile +2 -2
- data/{LICENSE.txt → LICENSE.md} +1 -1
- data/README.md +7 -1
- data/gemfiles/{active_record-rails40.gemfile → active_record_rails_40.gemfile} +1 -2
- data/gemfiles/{active_record-rails41.gemfile → active_record_rails_41.gemfile} +1 -2
- data/gemfiles/{active_record-rails42.gemfile → active_record_rails_42.gemfile} +1 -2
- data/lib/generators/sorcery/USAGE +1 -1
- data/lib/generators/sorcery/install_generator.rb +21 -21
- data/lib/generators/sorcery/templates/initializer.rb +19 -1
- data/lib/sorcery/adapters/active_record_adapter.rb +1 -1
- data/lib/sorcery/adapters/mongoid_adapter.rb +23 -11
- data/lib/sorcery/controller.rb +22 -16
- data/lib/sorcery/controller/config.rb +2 -0
- data/lib/sorcery/controller/submodules/activity_logging.rb +4 -0
- data/lib/sorcery/controller/submodules/external.rb +37 -33
- data/lib/sorcery/controller/submodules/http_basic_auth.rb +1 -0
- data/lib/sorcery/controller/submodules/remember_me.rb +1 -7
- data/lib/sorcery/controller/submodules/session_timeout.rb +25 -4
- data/lib/sorcery/crypto_providers/aes256.rb +1 -0
- data/lib/sorcery/crypto_providers/bcrypt.rb +2 -1
- data/lib/sorcery/engine.rb +10 -3
- data/lib/sorcery/model.rb +9 -6
- data/lib/sorcery/model/config.rb +3 -3
- data/lib/sorcery/model/submodules/brute_force_protection.rb +6 -7
- data/lib/sorcery/model/submodules/external.rb +4 -3
- data/lib/sorcery/model/submodules/magic_login.rb +29 -36
- data/lib/sorcery/model/submodules/reset_password.rb +5 -4
- data/lib/sorcery/model/submodules/user_activation.rb +1 -1
- data/lib/sorcery/protocols/oauth.rb +1 -0
- data/lib/sorcery/providers/auth0.rb +46 -0
- data/lib/sorcery/providers/heroku.rb +1 -0
- data/lib/sorcery/providers/instagram.rb +73 -0
- data/lib/sorcery/providers/linkedin.rb +1 -1
- data/lib/sorcery/providers/vk.rb +1 -1
- data/lib/sorcery/providers/wechat.rb +8 -6
- data/lib/sorcery/test_helpers/internal.rb +5 -4
- data/lib/sorcery/test_helpers/internal/rails.rb +11 -11
- data/lib/sorcery/version.rb +1 -1
- data/sorcery.gemspec +25 -9
- data/spec/active_record/user_activation_spec.rb +2 -2
- data/spec/active_record/user_activity_logging_spec.rb +2 -2
- data/spec/active_record/user_brute_force_protection_spec.rb +2 -2
- data/spec/active_record/user_magic_login_spec.rb +4 -4
- data/spec/active_record/user_oauth_spec.rb +2 -2
- data/spec/active_record/user_remember_me_spec.rb +2 -2
- data/spec/active_record/user_reset_password_spec.rb +2 -2
- data/spec/active_record/user_spec.rb +0 -10
- data/spec/controllers/controller_http_basic_auth_spec.rb +1 -1
- data/spec/controllers/controller_oauth2_spec.rb +195 -123
- data/spec/controllers/controller_oauth_spec.rb +7 -7
- data/spec/controllers/controller_remember_me_spec.rb +11 -6
- data/spec/controllers/controller_session_timeout_spec.rb +90 -3
- data/spec/controllers/controller_spec.rb +2 -2
- data/spec/orm/active_record.rb +2 -2
- data/spec/providers/vk_spec.rb +13 -12
- data/spec/rails_app/app/controllers/sorcery_controller.rb +83 -32
- data/spec/rails_app/app/mailers/sorcery_mailer.rb +1 -1
- data/spec/rails_app/config/application.rb +8 -3
- data/spec/rails_app/config/boot.rb +1 -1
- data/spec/rails_app/config/environment.rb +1 -1
- data/spec/rails_app/config/routes.rb +7 -0
- data/spec/rails_app/config/secrets.yml +4 -0
- data/spec/rails_app/db/migrate/activity_logging/20101224223624_add_activity_logging_to_users.rb +2 -2
- data/spec/rails_app/db/migrate/invalidate_active_sessions/20180221093235_add_invalidate_active_sessions_before_to_users.rb +9 -0
- data/spec/rails_app/db/migrate/magic_login/20170924151831_add_magic_login_to_users.rb +3 -3
- data/spec/rails_app/db/schema.rb +7 -9
- data/spec/shared_examples/user_magic_login_shared_examples.rb +50 -50
- data/spec/shared_examples/user_oauth_shared_examples.rb +1 -1
- data/spec/shared_examples/user_remember_me_shared_examples.rb +1 -1
- data/spec/shared_examples/user_reset_password_shared_examples.rb +3 -3
- data/spec/shared_examples/user_shared_examples.rb +41 -43
- data/spec/sorcery_crypto_providers_spec.rb +1 -1
- data/spec/spec.opts +1 -1
- data/spec/spec_helper.rb +2 -2
- data/spec/support/migration_helper.rb +19 -0
- metadata +60 -38
- data/spec/rails_app/config/initializers/secret_token.rb +0 -7
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.expand_path('
|
1
|
+
require File.expand_path('boot', __dir__)
|
2
2
|
|
3
3
|
require 'action_controller/railtie'
|
4
4
|
require 'action_mailer/railtie'
|
@@ -6,16 +6,19 @@ require 'rails/test_unit/railtie'
|
|
6
6
|
|
7
7
|
Bundler.require :default, SORCERY_ORM
|
8
8
|
|
9
|
+
# rubocop:disable Lint/HandleExceptions
|
9
10
|
begin
|
10
11
|
require "#{SORCERY_ORM}/railtie"
|
11
12
|
rescue LoadError
|
13
|
+
# TODO: Log this issue or change require scheme.
|
12
14
|
end
|
15
|
+
# rubocop:enable Lint/HandleExceptions
|
13
16
|
|
14
17
|
require 'sorcery'
|
15
18
|
|
16
19
|
module AppRoot
|
17
20
|
class Application < Rails::Application
|
18
|
-
config.autoload_paths.reject! { |p| p =~ /\/app\/(\w+)$/ && !%w
|
21
|
+
config.autoload_paths.reject! { |p| p =~ %r{/\/app\/(\w+)$/} && !%w[controllers helpers mailers views].include?(Regexp.last_match(1)) }
|
19
22
|
config.autoload_paths += ["#{config.root}/app/#{SORCERY_ORM}"]
|
20
23
|
|
21
24
|
# Settings in config/environments/* take precedence over those specified here.
|
@@ -50,7 +53,9 @@ module AppRoot
|
|
50
53
|
config.filter_parameters += [:password]
|
51
54
|
|
52
55
|
config.action_mailer.delivery_method = :test
|
53
|
-
|
54
56
|
config.active_support.deprecation = :stderr
|
57
|
+
if Rails.version >= '5.1.0' && config.active_record.sqlite3.present?
|
58
|
+
config.active_record.sqlite3.represent_boolean_as_integer = true
|
59
|
+
end
|
55
60
|
end
|
56
61
|
end
|
@@ -12,6 +12,7 @@ AppRoot::Application.routes.draw do
|
|
12
12
|
get :test_login_from
|
13
13
|
get :test_logout_with_remember
|
14
14
|
get :test_logout_with_force_forget_me
|
15
|
+
get :test_invalidate_active_session
|
15
16
|
get :test_should_be_logged_in
|
16
17
|
get :test_create_from_provider
|
17
18
|
get :test_add_second_provider
|
@@ -29,6 +30,8 @@ AppRoot::Application.routes.draw do
|
|
29
30
|
get :test_login_from_jira
|
30
31
|
get :test_login_from_salesforce
|
31
32
|
get :test_login_from_slack
|
33
|
+
get :test_login_from_instagram
|
34
|
+
get :test_login_from_auth0
|
32
35
|
get :login_at_test
|
33
36
|
get :login_at_test_twitter
|
34
37
|
get :login_at_test_facebook
|
@@ -42,6 +45,8 @@ AppRoot::Application.routes.draw do
|
|
42
45
|
get :login_at_test_jira
|
43
46
|
get :login_at_test_salesforce
|
44
47
|
get :login_at_test_slack
|
48
|
+
get :login_at_test_instagram
|
49
|
+
get :login_at_test_auth0
|
45
50
|
get :test_return_to_with_external
|
46
51
|
get :test_return_to_with_external_twitter
|
47
52
|
get :test_return_to_with_external_facebook
|
@@ -55,6 +60,8 @@ AppRoot::Application.routes.draw do
|
|
55
60
|
get :test_return_to_with_external_jira
|
56
61
|
get :test_return_to_with_external_salesforce
|
57
62
|
get :test_return_to_with_external_slack
|
63
|
+
get :test_return_to_with_external_instagram
|
64
|
+
get :test_return_to_with_external_auth0
|
58
65
|
get :test_http_basic_auth
|
59
66
|
get :some_action_making_a_non_persisted_change_to_the_user
|
60
67
|
post :test_login_with_remember
|
data/spec/rails_app/db/migrate/activity_logging/20101224223624_add_activity_logging_to_users.rb
CHANGED
@@ -5,11 +5,11 @@ class AddActivityLoggingToUsers < ActiveRecord::CompatibleLegacyMigration.migrat
|
|
5
5
|
add_column :users, :last_activity_at, :datetime, default: nil
|
6
6
|
add_column :users, :last_login_from_ip_address, :string, default: nil
|
7
7
|
|
8
|
-
add_index :users, [
|
8
|
+
add_index :users, %i[last_logout_at last_activity_at]
|
9
9
|
end
|
10
10
|
|
11
11
|
def self.down
|
12
|
-
remove_index :users, [
|
12
|
+
remove_index :users, %i[last_logout_at last_activity_at]
|
13
13
|
|
14
14
|
remove_column :users, :last_activity_at
|
15
15
|
remove_column :users, :last_logout_at
|
@@ -0,0 +1,9 @@
|
|
1
|
+
class AddInvalidateSessionsBeforeToUsers < ActiveRecord::CompatibleLegacyMigration.migration_class
|
2
|
+
def self.up
|
3
|
+
add_column :users, :invalidate_sessions_before, :datetime, default: nil
|
4
|
+
end
|
5
|
+
|
6
|
+
def self.down
|
7
|
+
remove_column :users, :invalidate_sessions_before
|
8
|
+
end
|
9
|
+
end
|
@@ -3,13 +3,13 @@ class AddMagicLoginToUsers < ActiveRecord::CompatibleLegacyMigration.migration_c
|
|
3
3
|
add_column :users, :magic_login_token, :string, default: nil
|
4
4
|
add_column :users, :magic_login_token_expires_at, :datetime, default: nil
|
5
5
|
add_column :users, :magic_login_email_sent_at, :datetime, default: nil
|
6
|
-
|
6
|
+
|
7
7
|
add_index :users, :magic_login_token
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
10
|
def self.down
|
11
11
|
remove_index :users, :magic_login_token
|
12
|
-
|
12
|
+
|
13
13
|
remove_column :users, :magic_login_token
|
14
14
|
remove_column :users, :magic_login_token_expires_at
|
15
15
|
remove_column :users, :magic_login_email_sent_at
|
data/spec/rails_app/db/schema.rb
CHANGED
@@ -10,14 +10,12 @@
|
|
10
10
|
#
|
11
11
|
# It's strongly recommended to check this file into your version control system.
|
12
12
|
|
13
|
-
ActiveRecord::Schema.define(:
|
14
|
-
|
15
|
-
|
16
|
-
t.string
|
17
|
-
t.string
|
18
|
-
t.
|
19
|
-
t.datetime
|
20
|
-
t.datetime "updated_at"
|
13
|
+
ActiveRecord::Schema.define(version: 20_101_224_223_620) do
|
14
|
+
create_table 'users', force: true do |t|
|
15
|
+
t.string 'username'
|
16
|
+
t.string 'email'
|
17
|
+
t.string 'crypted_password'
|
18
|
+
t.datetime 'created_at'
|
19
|
+
t.datetime 'updated_at'
|
21
20
|
end
|
22
|
-
|
23
21
|
end
|
@@ -1,145 +1,145 @@
|
|
1
|
-
shared_examples_for
|
2
|
-
let(:user) {create_new_user}
|
1
|
+
shared_examples_for 'magic_login_model' do
|
2
|
+
let(:user) { create_new_user }
|
3
3
|
before(:each) do
|
4
4
|
User.sorcery_adapter.delete_all
|
5
5
|
end
|
6
|
-
|
6
|
+
|
7
7
|
context 'loaded plugin configuration' do
|
8
|
-
let(:config) {User.sorcery_config}
|
9
|
-
|
8
|
+
let(:config) { User.sorcery_config }
|
9
|
+
|
10
10
|
before(:all) do
|
11
11
|
sorcery_reload!([:magic_login])
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
after(:each) do
|
15
15
|
User.sorcery_config.reset!
|
16
16
|
end
|
17
|
-
|
18
|
-
describe
|
17
|
+
|
18
|
+
describe 'enables configuration options' do
|
19
19
|
it do
|
20
20
|
sorcery_model_property_set(:magic_login_token_attribute_name, :test_magic_login_token)
|
21
21
|
expect(config.magic_login_token_attribute_name).to eq :test_magic_login_token
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
it do
|
25
25
|
sorcery_model_property_set(:magic_login_token_expires_at_attribute_name, :test_magic_login_token_expires_at)
|
26
26
|
expect(config.magic_login_token_expires_at_attribute_name).to eq :test_magic_login_token_expires_at
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
it do
|
30
30
|
sorcery_model_property_set(:magic_login_email_sent_at_attribute_name, :test_magic_login_email_sent_at)
|
31
31
|
expect(config.magic_login_email_sent_at_attribute_name).to eq :test_magic_login_email_sent_at
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
it do
|
35
35
|
TestMailerClass = Class.new # need a mailer class to test
|
36
36
|
sorcery_model_property_set(:magic_login_mailer_class, TestMailerClass)
|
37
37
|
expect(config.magic_login_mailer_class).to eq TestMailerClass
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
it do
|
41
41
|
sorcery_model_property_set(:magic_login_mailer_disabled, false)
|
42
42
|
expect(config.magic_login_mailer_disabled).to eq false
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
it do
|
46
46
|
sorcery_model_property_set(:magic_login_email_method_name, :test_magic_login_email)
|
47
47
|
expect(config.magic_login_email_method_name).to eq :test_magic_login_email
|
48
48
|
end
|
49
|
-
|
49
|
+
|
50
50
|
it do
|
51
|
-
sorcery_model_property_set(:magic_login_expiration_period,
|
52
|
-
expect(config.magic_login_expiration_period).to eq
|
51
|
+
sorcery_model_property_set(:magic_login_expiration_period, 100_000_000)
|
52
|
+
expect(config.magic_login_expiration_period).to eq 100_000_000
|
53
53
|
end
|
54
|
-
|
54
|
+
|
55
55
|
it do
|
56
|
-
sorcery_model_property_set(:magic_login_time_between_emails,
|
57
|
-
expect(config.magic_login_time_between_emails).to eq
|
56
|
+
sorcery_model_property_set(:magic_login_time_between_emails, 100_000_000)
|
57
|
+
expect(config.magic_login_time_between_emails).to eq 100_000_000
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
|
-
describe
|
62
|
-
context
|
61
|
+
describe '#generate_magic_login_token!' do
|
62
|
+
context 'magic_login_token is nil' do
|
63
63
|
it "magic_login_token_expires_at and magic_login_email_sent_at aren't nil " do
|
64
64
|
user.generate_magic_login_token!
|
65
65
|
expect(user.magic_login_token_expires_at).not_to be_nil
|
66
66
|
expect(user.magic_login_email_sent_at).not_to be_nil
|
67
67
|
end
|
68
|
-
|
69
|
-
it
|
68
|
+
|
69
|
+
it 'magic_login_token is different from the one before' do
|
70
70
|
token_before = user.magic_login_token
|
71
71
|
user.generate_magic_login_token!
|
72
72
|
expect(user.magic_login_token).not_to eq token_before
|
73
73
|
end
|
74
74
|
end
|
75
|
-
|
76
|
-
context
|
77
|
-
it
|
75
|
+
|
76
|
+
context 'magic_login_token is not nil' do
|
77
|
+
it 'changes `user.magic_login_token`' do
|
78
78
|
token_before = user.magic_login_token
|
79
79
|
user.generate_magic_login_token!
|
80
80
|
expect(user.magic_login_token).not_to eq token_before
|
81
81
|
end
|
82
82
|
end
|
83
83
|
end
|
84
|
-
|
85
|
-
describe
|
86
|
-
context
|
84
|
+
|
85
|
+
describe '#deliver_magic_login_instructions!' do
|
86
|
+
context 'success' do
|
87
87
|
before do
|
88
|
-
sorcery_model_property_set(:magic_login_time_between_emails, 30*60)
|
88
|
+
sorcery_model_property_set(:magic_login_time_between_emails, 30 * 60)
|
89
89
|
sorcery_model_property_set(:magic_login_mailer_disabled, false)
|
90
90
|
Timecop.travel(10.days.ago) do
|
91
91
|
user.send(:"#{config.magic_login_email_sent_at_attribute_name}=", DateTime.now)
|
92
92
|
end
|
93
93
|
sorcery_model_property_set(:magic_login_mailer_class, ::SorceryMailer)
|
94
94
|
end
|
95
|
-
|
95
|
+
|
96
96
|
it do
|
97
97
|
user.deliver_magic_login_instructions!
|
98
98
|
expect(ActionMailer::Base.deliveries.size).to eq 1
|
99
99
|
end
|
100
|
-
|
100
|
+
|
101
101
|
it do
|
102
102
|
expect(user.deliver_magic_login_instructions!).to eq true
|
103
103
|
end
|
104
104
|
end
|
105
105
|
|
106
|
-
context
|
107
|
-
context
|
108
|
-
it
|
106
|
+
context 'failure' do
|
107
|
+
context 'magic_login_time_between_emails is nil' do
|
108
|
+
it 'returns false' do
|
109
109
|
sorcery_model_property_set(:magic_login_time_between_emails, nil)
|
110
110
|
expect(user.deliver_magic_login_instructions!).to eq false
|
111
111
|
end
|
112
112
|
end
|
113
|
-
|
114
|
-
context
|
115
|
-
it
|
113
|
+
|
114
|
+
context 'magic_login_email_sent_at is nil' do
|
115
|
+
it 'returns false' do
|
116
116
|
user.send(:"#{config.magic_login_email_sent_at_attribute_name}=", nil)
|
117
117
|
expect(user.deliver_magic_login_instructions!).to eq false
|
118
118
|
end
|
119
119
|
end
|
120
|
-
|
121
|
-
context
|
122
|
-
it
|
120
|
+
|
121
|
+
context 'now is before magic_login_email_sent_at plus the interval' do
|
122
|
+
it 'returns false' do
|
123
123
|
user.send(:"#{config.magic_login_email_sent_at_attribute_name}=", DateTime.now)
|
124
|
-
sorcery_model_property_set(:magic_login_time_between_emails, 30*60)
|
124
|
+
sorcery_model_property_set(:magic_login_time_between_emails, 30 * 60)
|
125
125
|
expect(user.deliver_magic_login_instructions!).to eq false
|
126
126
|
end
|
127
127
|
end
|
128
|
-
|
129
|
-
context
|
130
|
-
it
|
128
|
+
|
129
|
+
context 'magic_login_mailer_disabled is true' do
|
130
|
+
it 'returns false' do
|
131
131
|
sorcery_model_property_set(:magic_login_mailer_disabled, true)
|
132
132
|
expect(user.deliver_magic_login_instructions!).to eq false
|
133
133
|
end
|
134
134
|
end
|
135
135
|
end
|
136
136
|
end
|
137
|
-
|
138
|
-
describe
|
139
|
-
it
|
140
|
-
user.magic_login_token =
|
137
|
+
|
138
|
+
describe '#clear_magic_login_token!' do
|
139
|
+
it 'makes magic_login_token_attribute_name and magic_login_token_expires_at_attribute_name nil' do
|
140
|
+
user.magic_login_token = 'test_token'
|
141
141
|
user.magic_login_token_expires_at = Time.now
|
142
|
-
|
142
|
+
|
143
143
|
user.clear_magic_login_token!
|
144
144
|
|
145
145
|
expect(user.magic_login_token).to eq nil
|
@@ -27,7 +27,7 @@ shared_examples_for 'rails_3_oauth_model' do
|
|
27
27
|
|
28
28
|
it "'load_from_provider' returns nil if user doesn't exist" do
|
29
29
|
external_user
|
30
|
-
expect(User.load_from_provider(:twitter,
|
30
|
+
expect(User.load_from_provider(:twitter, 980_342)).to be_nil
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
@@ -42,7 +42,7 @@ shared_examples_for 'rails_3_remember_me_model' do
|
|
42
42
|
user.remember_me!
|
43
43
|
end
|
44
44
|
|
45
|
-
expect(user.remember_me_token_expires_at.utc.to_s).to eq
|
45
|
+
expect(user.remember_me_token_expires_at.utc.to_s).to eq((ts + 2 * 60 * 60 * 24).utc.to_s)
|
46
46
|
end
|
47
47
|
|
48
48
|
context 'when not persisting globally' do
|
@@ -245,7 +245,7 @@ shared_examples_for 'rails_3_reset_password_model' do
|
|
245
245
|
end
|
246
246
|
|
247
247
|
it 'does not send an email if time between emails has not passed since last email' do
|
248
|
-
sorcery_model_property_set(:reset_password_time_between_emails,
|
248
|
+
sorcery_model_property_set(:reset_password_time_between_emails, 10_000)
|
249
249
|
old_size = ActionMailer::Base.deliveries.size
|
250
250
|
user.deliver_reset_password_instructions!
|
251
251
|
|
@@ -289,7 +289,7 @@ shared_examples_for 'rails_3_reset_password_model' do
|
|
289
289
|
end
|
290
290
|
|
291
291
|
it 'does not send an email if time between emails has not passed since last email' do
|
292
|
-
sorcery_model_property_set(:reset_password_time_between_emails,
|
292
|
+
sorcery_model_property_set(:reset_password_time_between_emails, 10_000)
|
293
293
|
old_size = ActionMailer::Base.deliveries.size
|
294
294
|
user.deliver_reset_password_instructions!
|
295
295
|
|
@@ -326,7 +326,7 @@ shared_examples_for 'rails_3_reset_password_model' do
|
|
326
326
|
end
|
327
327
|
|
328
328
|
it 'returns false if time between emails has not passed since last email' do
|
329
|
-
sorcery_model_property_set(:reset_password_time_between_emails,
|
329
|
+
sorcery_model_property_set(:reset_password_time_between_emails, 10_000)
|
330
330
|
user.deliver_reset_password_instructions!
|
331
331
|
|
332
332
|
expect(user.deliver_reset_password_instructions!).to be false
|
@@ -228,10 +228,13 @@ shared_examples_for 'rails_3_core_model' do
|
|
228
228
|
|
229
229
|
expect(user).to receive(:save) { raise RuntimeError }
|
230
230
|
|
231
|
+
# rubocop:disable Lint/HandleExceptions
|
231
232
|
begin
|
232
233
|
user.save
|
233
|
-
rescue
|
234
|
+
rescue RuntimeError
|
235
|
+
# Intentionally force exception during save
|
234
236
|
end
|
237
|
+
# rubocop:enable Lint/HandleExceptions
|
235
238
|
|
236
239
|
expect(user.password).not_to be_nil
|
237
240
|
end
|
@@ -308,12 +311,12 @@ shared_examples_for 'rails_3_core_model' do
|
|
308
311
|
|
309
312
|
describe 'generic send email' do
|
310
313
|
before(:all) do
|
311
|
-
|
314
|
+
MigrationHelper.migrate("#{Rails.root}/db/migrate/activation")
|
312
315
|
User.reset_column_information
|
313
316
|
end
|
314
317
|
|
315
318
|
after(:all) do
|
316
|
-
|
319
|
+
MigrationHelper.rollback("#{Rails.root}/db/migrate/activation")
|
317
320
|
end
|
318
321
|
|
319
322
|
before do
|
@@ -323,9 +326,11 @@ shared_examples_for 'rails_3_core_model' do
|
|
323
326
|
|
324
327
|
it 'use deliver_later' do
|
325
328
|
sorcery_reload!(
|
326
|
-
[
|
327
|
-
|
328
|
-
|
329
|
+
%i[
|
330
|
+
user_activation
|
331
|
+
user_activation_mailer
|
332
|
+
activation_needed_email_method_name
|
333
|
+
email_delivery_method
|
329
334
|
],
|
330
335
|
user_activation_mailer: SorceryMailer,
|
331
336
|
activation_needed_email_method_name: nil,
|
@@ -340,9 +345,10 @@ shared_examples_for 'rails_3_core_model' do
|
|
340
345
|
it 'use deliver_now if rails version 4.2+' do
|
341
346
|
allow(Rails).to receive(:version).and_return('4.2.0')
|
342
347
|
sorcery_reload!(
|
343
|
-
[
|
344
|
-
|
345
|
-
|
348
|
+
%i[
|
349
|
+
user_activation
|
350
|
+
user_activation_mailer
|
351
|
+
activation_needed_email_method_name
|
346
352
|
],
|
347
353
|
user_activation_mailer: SorceryMailer,
|
348
354
|
activation_needed_email_method_name: nil
|
@@ -355,9 +361,10 @@ shared_examples_for 'rails_3_core_model' do
|
|
355
361
|
it 'use deliver if rails version < 4.2' do
|
356
362
|
allow(Rails).to receive(:version).and_return('4.1.0')
|
357
363
|
sorcery_reload!(
|
358
|
-
[
|
359
|
-
|
360
|
-
|
364
|
+
%i[
|
365
|
+
user_activation
|
366
|
+
user_activation_mailer
|
367
|
+
activation_needed_email_method_name
|
361
368
|
],
|
362
369
|
user_activation_mailer: SorceryMailer,
|
363
370
|
activation_needed_email_method_name: nil
|
@@ -503,7 +510,7 @@ shared_examples_for 'rails_3_core_model' do
|
|
503
510
|
end
|
504
511
|
|
505
512
|
it 'find_by_username works as expected with multiple username attributes' do
|
506
|
-
sorcery_model_property_set(:username_attribute_names, [
|
513
|
+
sorcery_model_property_set(:username_attribute_names, %i[username email])
|
507
514
|
|
508
515
|
expect(User.sorcery_adapter.find_by_username('gizmo')).to eq user
|
509
516
|
end
|
@@ -518,6 +525,21 @@ shared_examples_for 'external_user' do
|
|
518
525
|
let(:user) { create_new_user }
|
519
526
|
let(:external_user) { create_new_external_user :twitter }
|
520
527
|
|
528
|
+
before(:all) do
|
529
|
+
if SORCERY_ORM == :active_record
|
530
|
+
MigrationHelper.migrate("#{Rails.root}/db/migrate/external")
|
531
|
+
MigrationHelper.migrate("#{Rails.root}/db/migrate/activation")
|
532
|
+
end
|
533
|
+
sorcery_reload!
|
534
|
+
end
|
535
|
+
|
536
|
+
after(:all) do
|
537
|
+
if SORCERY_ORM == :active_record
|
538
|
+
MigrationHelper.rollback("#{Rails.root}/db/migrate/external")
|
539
|
+
MigrationHelper.rollback("#{Rails.root}/db/migrate/activation")
|
540
|
+
end
|
541
|
+
end
|
542
|
+
|
521
543
|
before(:each) do
|
522
544
|
User.sorcery_adapter.delete_all
|
523
545
|
end
|
@@ -535,24 +557,12 @@ shared_examples_for 'external_user' do
|
|
535
557
|
end
|
536
558
|
|
537
559
|
describe '.create_from_provider' do
|
538
|
-
before(:
|
539
|
-
if SORCERY_ORM == :active_record
|
540
|
-
ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate/external")
|
541
|
-
User.reset_column_information
|
542
|
-
end
|
543
|
-
|
560
|
+
before(:each) do
|
544
561
|
sorcery_reload!([:external])
|
545
|
-
|
546
|
-
|
547
|
-
after(:all) do
|
548
|
-
if SORCERY_ORM == :active_record
|
549
|
-
ActiveRecord::Migrator.rollback("#{Rails.root}/db/migrate/external")
|
550
|
-
end
|
562
|
+
sorcery_model_property_set(:authentications_class, Authentication)
|
551
563
|
end
|
552
564
|
|
553
565
|
it 'supports nested attributes' do
|
554
|
-
sorcery_model_property_set(:authentications_class, Authentication)
|
555
|
-
|
556
566
|
expect do
|
557
567
|
User.create_from_provider('facebook', '123', username: 'Noam Ben Ari')
|
558
568
|
end.to change { User.count }.by(1)
|
@@ -570,33 +580,21 @@ shared_examples_for 'external_user' do
|
|
570
580
|
it 'does not create user when block return false' do
|
571
581
|
expect do
|
572
582
|
User.create_from_provider('facebook', '123', username: 'Noam Ben Ari') { false }
|
573
|
-
end.not_to
|
583
|
+
end.not_to(change { User.count })
|
574
584
|
end
|
575
585
|
end
|
576
586
|
end
|
577
587
|
|
578
588
|
describe 'activation' do
|
579
|
-
before(:
|
580
|
-
|
581
|
-
ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate/external")
|
582
|
-
ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate/activation")
|
583
|
-
end
|
584
|
-
|
585
|
-
sorcery_reload!([:user_activation, :external], user_activation_mailer: ::SorceryMailer)
|
586
|
-
end
|
587
|
-
|
588
|
-
after(:all) do
|
589
|
-
if SORCERY_ORM == :active_record
|
590
|
-
ActiveRecord::Migrator.rollback("#{Rails.root}/db/migrate/external")
|
591
|
-
ActiveRecord::Migrator.rollback("#{Rails.root}/db/migrate/activation")
|
592
|
-
end
|
589
|
+
before(:each) do
|
590
|
+
sorcery_reload!(%i[user_activation external], user_activation_mailer: ::SorceryMailer)
|
593
591
|
end
|
594
592
|
|
595
593
|
after(:each) do
|
596
594
|
User.sorcery_adapter.delete_all
|
597
595
|
end
|
598
596
|
|
599
|
-
[
|
597
|
+
%i[facebook github google liveid slack].each do |provider|
|
600
598
|
it 'does not send activation email to external users' do
|
601
599
|
old_size = ActionMailer::Base.deliveries.size
|
602
600
|
create_new_external_user(provider)
|