sorcery 0.16.1 → 0.18.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +33 -1
- data/README.md +9 -8
- data/lib/generators/sorcery/helpers.rb +1 -1
- data/lib/generators/sorcery/install_generator.rb +9 -11
- data/lib/generators/sorcery/templates/initializer.rb +34 -10
- data/lib/generators/sorcery/templates/migration/core.rb +1 -3
- data/lib/sorcery/adapters/active_record_adapter.rb +12 -14
- data/lib/sorcery/adapters/mongoid_adapter.rb +7 -9
- data/lib/sorcery/controller/config.rb +27 -29
- data/lib/sorcery/controller/submodules/activity_logging.rb +4 -7
- data/lib/sorcery/controller/submodules/brute_force_protection.rb +4 -1
- data/lib/sorcery/controller/submodules/external.rb +12 -12
- data/lib/sorcery/controller/submodules/http_basic_auth.rb +7 -2
- data/lib/sorcery/controller/submodules/remember_me.rb +2 -1
- data/lib/sorcery/controller/submodules/session_timeout.rb +2 -2
- data/lib/sorcery/controller.rb +37 -19
- data/lib/sorcery/crypto_providers/aes256.rb +4 -2
- data/lib/sorcery/crypto_providers/bcrypt.rb +2 -1
- data/lib/sorcery/crypto_providers/md5.rb +1 -0
- data/lib/sorcery/crypto_providers/sha1.rb +1 -0
- data/lib/sorcery/crypto_providers/sha256.rb +1 -0
- data/lib/sorcery/crypto_providers/sha512.rb +1 -0
- data/lib/sorcery/engine.rb +6 -4
- data/lib/sorcery/errors.rb +10 -0
- data/lib/sorcery/model/config.rb +20 -31
- data/lib/sorcery/model/submodules/activity_logging.rb +8 -6
- data/lib/sorcery/model/submodules/brute_force_protection.rb +16 -14
- data/lib/sorcery/model/submodules/external.rb +8 -10
- data/lib/sorcery/model/submodules/magic_login.rb +8 -4
- data/lib/sorcery/model/submodules/remember_me.rb +3 -3
- data/lib/sorcery/model/submodules/reset_password.rb +23 -13
- data/lib/sorcery/model/submodules/user_activation.rb +19 -17
- data/lib/sorcery/model/temporary_token.rb +5 -5
- data/lib/sorcery/model.rb +29 -28
- data/lib/sorcery/protocols/oauth2.rb +1 -0
- data/lib/sorcery/providers/base.rb +1 -1
- data/lib/sorcery/providers/facebook.rb +2 -2
- data/lib/sorcery/providers/github.rb +3 -3
- data/lib/sorcery/providers/heroku.rb +1 -2
- data/lib/sorcery/providers/jira.rb +3 -2
- data/lib/sorcery/providers/line.rb +2 -4
- data/lib/sorcery/providers/microsoft.rb +1 -1
- data/lib/sorcery/providers/slack.rb +1 -1
- data/lib/sorcery/providers/twitter.rb +2 -2
- data/lib/sorcery/providers/vk.rb +4 -4
- data/lib/sorcery/providers/xing.rb +3 -2
- data/lib/sorcery/test_helpers/internal/rails.rb +5 -22
- data/lib/sorcery/test_helpers/internal.rb +4 -6
- data/lib/sorcery/test_helpers/rails/integration.rb +1 -1
- data/lib/sorcery/test_helpers/rails/request.rb +1 -1
- data/lib/sorcery/version.rb +1 -1
- data/lib/sorcery.rb +6 -1
- metadata +23 -157
- data/.document +0 -5
- data/.github/FUNDING.yml +0 -1
- data/.github/ISSUE_TEMPLATE.md +0 -20
- data/.github/PULL_REQUEST_TEMPLATE.md +0 -5
- data/.github/workflows/ruby.yml +0 -49
- data/.gitignore +0 -59
- data/.rspec +0 -1
- data/.rubocop.yml +0 -55
- data/.rubocop_todo.yml +0 -163
- data/CODE_OF_CONDUCT.md +0 -14
- data/Gemfile +0 -8
- data/Rakefile +0 -8
- data/SECURITY.md +0 -19
- data/gemfiles/rails_52.gemfile +0 -7
- data/gemfiles/rails_60.gemfile +0 -7
- data/sorcery.gemspec +0 -49
- data/spec/active_record/user_activation_spec.rb +0 -17
- data/spec/active_record/user_activity_logging_spec.rb +0 -15
- data/spec/active_record/user_brute_force_protection_spec.rb +0 -15
- data/spec/active_record/user_magic_login_spec.rb +0 -15
- data/spec/active_record/user_oauth_spec.rb +0 -15
- data/spec/active_record/user_remember_me_spec.rb +0 -15
- data/spec/active_record/user_reset_password_spec.rb +0 -15
- data/spec/active_record/user_spec.rb +0 -27
- data/spec/controllers/controller_activity_logging_spec.rb +0 -113
- data/spec/controllers/controller_brute_force_protection_spec.rb +0 -41
- data/spec/controllers/controller_http_basic_auth_spec.rb +0 -67
- data/spec/controllers/controller_oauth2_spec.rb +0 -568
- data/spec/controllers/controller_oauth_spec.rb +0 -266
- data/spec/controllers/controller_remember_me_spec.rb +0 -130
- data/spec/controllers/controller_session_timeout_spec.rb +0 -166
- data/spec/controllers/controller_spec.rb +0 -194
- data/spec/orm/active_record.rb +0 -21
- data/spec/providers/example_provider_spec.rb +0 -17
- data/spec/providers/example_spec.rb +0 -17
- data/spec/providers/vk_spec.rb +0 -42
- data/spec/rails_app/app/active_record/authentication.rb +0 -3
- data/spec/rails_app/app/active_record/user.rb +0 -5
- data/spec/rails_app/app/active_record/user_provider.rb +0 -3
- data/spec/rails_app/app/assets/config/manifest.js +0 -1
- data/spec/rails_app/app/controllers/application_controller.rb +0 -2
- data/spec/rails_app/app/controllers/sorcery_controller.rb +0 -489
- data/spec/rails_app/app/helpers/application_helper.rb +0 -2
- data/spec/rails_app/app/mailers/sorcery_mailer.rb +0 -38
- data/spec/rails_app/app/views/application/index.html.erb +0 -17
- data/spec/rails_app/app/views/layouts/application.html.erb +0 -14
- data/spec/rails_app/app/views/sorcery_mailer/activation_email.html.erb +0 -17
- data/spec/rails_app/app/views/sorcery_mailer/activation_email.text.erb +0 -9
- data/spec/rails_app/app/views/sorcery_mailer/activation_needed_email.html.erb +0 -17
- data/spec/rails_app/app/views/sorcery_mailer/activation_success_email.html.erb +0 -17
- data/spec/rails_app/app/views/sorcery_mailer/activation_success_email.text.erb +0 -9
- data/spec/rails_app/app/views/sorcery_mailer/magic_login_email.html.erb +0 -13
- data/spec/rails_app/app/views/sorcery_mailer/magic_login_email.text.erb +0 -6
- data/spec/rails_app/app/views/sorcery_mailer/reset_password_email.html.erb +0 -16
- data/spec/rails_app/app/views/sorcery_mailer/reset_password_email.text.erb +0 -8
- data/spec/rails_app/app/views/sorcery_mailer/send_unlock_token_email.text.erb +0 -1
- data/spec/rails_app/config/application.rb +0 -61
- data/spec/rails_app/config/boot.rb +0 -4
- data/spec/rails_app/config/database.yml +0 -22
- data/spec/rails_app/config/environment.rb +0 -5
- data/spec/rails_app/config/environments/test.rb +0 -37
- data/spec/rails_app/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/rails_app/config/initializers/compatible_legacy_migration.rb +0 -11
- data/spec/rails_app/config/initializers/inflections.rb +0 -10
- data/spec/rails_app/config/initializers/mime_types.rb +0 -5
- data/spec/rails_app/config/initializers/session_store.rb +0 -12
- data/spec/rails_app/config/locales/en.yml +0 -5
- data/spec/rails_app/config/routes.rb +0 -81
- data/spec/rails_app/config/secrets.yml +0 -4
- data/spec/rails_app/config.ru +0 -4
- data/spec/rails_app/db/migrate/activation/20101224223622_add_activation_to_users.rb +0 -17
- data/spec/rails_app/db/migrate/activity_logging/20101224223624_add_activity_logging_to_users.rb +0 -19
- data/spec/rails_app/db/migrate/brute_force_protection/20101224223626_add_brute_force_protection_to_users.rb +0 -13
- data/spec/rails_app/db/migrate/core/20101224223620_create_users.rb +0 -16
- data/spec/rails_app/db/migrate/external/20101224223628_create_authentications_and_user_providers.rb +0 -22
- data/spec/rails_app/db/migrate/invalidate_active_sessions/20180221093235_add_invalidate_active_sessions_before_to_users.rb +0 -9
- data/spec/rails_app/db/migrate/magic_login/20170924151831_add_magic_login_to_users.rb +0 -17
- data/spec/rails_app/db/migrate/remember_me/20101224223623_add_remember_me_token_to_users.rb +0 -15
- data/spec/rails_app/db/migrate/reset_password/20101224223622_add_reset_password_to_users.rb +0 -15
- data/spec/rails_app/db/schema.rb +0 -21
- data/spec/rails_app/db/seeds.rb +0 -7
- data/spec/shared_examples/user_activation_shared_examples.rb +0 -361
- data/spec/shared_examples/user_activity_logging_shared_examples.rb +0 -106
- data/spec/shared_examples/user_brute_force_protection_shared_examples.rb +0 -151
- data/spec/shared_examples/user_magic_login_shared_examples.rb +0 -150
- data/spec/shared_examples/user_oauth_shared_examples.rb +0 -33
- data/spec/shared_examples/user_remember_me_shared_examples.rb +0 -129
- data/spec/shared_examples/user_reset_password_shared_examples.rb +0 -358
- data/spec/shared_examples/user_shared_examples.rb +0 -678
- data/spec/sorcery_crypto_providers_spec.rb +0 -245
- data/spec/sorcery_temporary_token_spec.rb +0 -27
- data/spec/spec.opts +0 -2
- data/spec/spec_helper.rb +0 -50
- data/spec/support/migration_helper.rb +0 -29
- data/spec/support/providers/example.rb +0 -11
- data/spec/support/providers/example_provider.rb +0 -11
data/SECURITY.md
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
# Security Policy
|
|
2
|
-
|
|
3
|
-
## Supported Versions
|
|
4
|
-
|
|
5
|
-
| Version | Supported |
|
|
6
|
-
| --------- | ------------------ |
|
|
7
|
-
| ~> 0.16.0 | :white_check_mark: |
|
|
8
|
-
| ~> 0.15.0 | :white_check_mark: |
|
|
9
|
-
| < 0.15.0 | :x: |
|
|
10
|
-
|
|
11
|
-
## Reporting a Vulnerability
|
|
12
|
-
|
|
13
|
-
Email the current maintainer(s) with a description of the vulnerability. You
|
|
14
|
-
should expect a response within 48 hours. If the vulnerability is accepted, a
|
|
15
|
-
Github advisory will be created and eventually released with a CVE corresponding
|
|
16
|
-
to the issue found.
|
|
17
|
-
|
|
18
|
-
A list of the current maintainers can be found on the README under the contact
|
|
19
|
-
section. See: [README.md](https://github.com/Sorcery/sorcery#contact)
|
data/gemfiles/rails_52.gemfile
DELETED
data/gemfiles/rails_60.gemfile
DELETED
data/sorcery.gemspec
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
lib = File.expand_path('lib', __dir__)
|
|
2
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
3
|
-
require 'sorcery/version'
|
|
4
|
-
|
|
5
|
-
# rubocop:disable Metrics/BlockLength
|
|
6
|
-
Gem::Specification.new do |s|
|
|
7
|
-
s.name = 'sorcery'
|
|
8
|
-
s.version = Sorcery::VERSION
|
|
9
|
-
s.authors = [
|
|
10
|
-
'Noam Ben Ari',
|
|
11
|
-
'Kir Shatrov',
|
|
12
|
-
'Grzegorz Witek',
|
|
13
|
-
'Chase Gilliam',
|
|
14
|
-
'Josh Buker'
|
|
15
|
-
]
|
|
16
|
-
s.email = [
|
|
17
|
-
'crypto@joshbuker.com'
|
|
18
|
-
]
|
|
19
|
-
|
|
20
|
-
# TODO: Cleanup formatting.
|
|
21
|
-
# rubocop:disable Layout/LineLength
|
|
22
|
-
s.description = 'Provides common authentication needs such as signing in/out, activating by email and resetting password.'
|
|
23
|
-
s.summary = 'Magical authentication for Rails applications'
|
|
24
|
-
s.homepage = 'https://github.com/Sorcery/sorcery'
|
|
25
|
-
s.post_install_message = "As of version 1.0 oauth/oauth2 won't be automatically bundled so you may need to add those dependencies to your Gemfile.\n"
|
|
26
|
-
s.post_install_message += 'You may need oauth2 if you use external providers such as any of these: https://github.com/Sorcery/sorcery/tree/master/lib/sorcery/providers'
|
|
27
|
-
# rubocop:enable Layout/LineLength
|
|
28
|
-
|
|
29
|
-
s.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
|
30
|
-
s.require_paths = ['lib']
|
|
31
|
-
|
|
32
|
-
s.licenses = ['MIT']
|
|
33
|
-
|
|
34
|
-
s.required_ruby_version = '>= 2.4.9'
|
|
35
|
-
|
|
36
|
-
s.add_dependency 'bcrypt', '~> 3.1'
|
|
37
|
-
s.add_dependency 'oauth', '~> 0.5', '>= 0.5.5'
|
|
38
|
-
s.add_dependency 'oauth2', '~> 1.0', '>= 0.8.0'
|
|
39
|
-
|
|
40
|
-
s.add_development_dependency 'byebug', '~> 10.0.0'
|
|
41
|
-
s.add_development_dependency 'rspec-rails', '~> 3.7.0'
|
|
42
|
-
s.add_development_dependency 'rubocop'
|
|
43
|
-
s.add_development_dependency 'simplecov', '>= 0.3.8'
|
|
44
|
-
s.add_development_dependency 'test-unit', '~> 3.2.0'
|
|
45
|
-
s.add_development_dependency 'timecop'
|
|
46
|
-
s.add_development_dependency 'webmock', '~> 3.3.0'
|
|
47
|
-
s.add_development_dependency 'yard', '~> 0.9.0', '>= 0.9.12'
|
|
48
|
-
end
|
|
49
|
-
# rubocop:enable Metrics/BlockLength
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
require 'rails_app/app/mailers/sorcery_mailer'
|
|
4
|
-
require 'shared_examples/user_activation_shared_examples'
|
|
5
|
-
|
|
6
|
-
describe User, 'with activation submodule', active_record: true do
|
|
7
|
-
before(:all) do
|
|
8
|
-
MigrationHelper.migrate("#{Rails.root}/db/migrate/activation")
|
|
9
|
-
User.reset_column_information
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
after(:all) do
|
|
13
|
-
MigrationHelper.rollback("#{Rails.root}/db/migrate/activation")
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
it_behaves_like 'rails_3_activation_model'
|
|
17
|
-
end
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
require 'shared_examples/user_activity_logging_shared_examples'
|
|
3
|
-
|
|
4
|
-
describe User, 'with activity logging submodule', active_record: true do
|
|
5
|
-
before(:all) do
|
|
6
|
-
MigrationHelper.migrate("#{Rails.root}/db/migrate/activity_logging")
|
|
7
|
-
User.reset_column_information
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
after(:all) do
|
|
11
|
-
MigrationHelper.rollback("#{Rails.root}/db/migrate/activity_logging")
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
it_behaves_like 'rails_3_activity_logging_model'
|
|
15
|
-
end
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
require 'shared_examples/user_brute_force_protection_shared_examples'
|
|
3
|
-
|
|
4
|
-
describe User, 'with brute_force_protection submodule', active_record: true do
|
|
5
|
-
before(:all) do
|
|
6
|
-
MigrationHelper.migrate("#{Rails.root}/db/migrate/brute_force_protection")
|
|
7
|
-
User.reset_column_information
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
after(:all) do
|
|
11
|
-
MigrationHelper.rollback("#{Rails.root}/db/migrate/brute_force_protection")
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
it_behaves_like 'rails_3_brute_force_protection_model'
|
|
15
|
-
end
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
require 'shared_examples/user_magic_login_shared_examples'
|
|
3
|
-
|
|
4
|
-
describe User, 'with magic_login submodule', active_record: true do
|
|
5
|
-
before(:all) do
|
|
6
|
-
MigrationHelper.migrate("#{Rails.root}/db/migrate/magic_login")
|
|
7
|
-
User.reset_column_information
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
after(:all) do
|
|
11
|
-
MigrationHelper.rollback("#{Rails.root}/db/migrate/magic_login")
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
it_behaves_like 'magic_login_model'
|
|
15
|
-
end
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
require 'shared_examples/user_oauth_shared_examples'
|
|
3
|
-
|
|
4
|
-
describe User, 'with oauth submodule', active_record: true do
|
|
5
|
-
before(:all) do
|
|
6
|
-
MigrationHelper.migrate("#{Rails.root}/db/migrate/external")
|
|
7
|
-
User.reset_column_information
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
after(:all) do
|
|
11
|
-
MigrationHelper.rollback("#{Rails.root}/db/migrate/external")
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
it_behaves_like 'rails_3_oauth_model'
|
|
15
|
-
end
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
require 'shared_examples/user_remember_me_shared_examples'
|
|
3
|
-
|
|
4
|
-
describe User, 'with remember_me submodule', active_record: true do
|
|
5
|
-
before(:all) do
|
|
6
|
-
MigrationHelper.migrate("#{Rails.root}/db/migrate/remember_me")
|
|
7
|
-
User.reset_column_information
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
after(:all) do
|
|
11
|
-
MigrationHelper.rollback("#{Rails.root}/db/migrate/remember_me")
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
it_behaves_like 'rails_3_remember_me_model'
|
|
15
|
-
end
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
require 'shared_examples/user_reset_password_shared_examples'
|
|
3
|
-
|
|
4
|
-
describe User, 'with reset_password submodule', active_record: true do
|
|
5
|
-
before(:all) do
|
|
6
|
-
MigrationHelper.migrate("#{Rails.root}/db/migrate/reset_password")
|
|
7
|
-
User.reset_column_information
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
after(:all) do
|
|
11
|
-
MigrationHelper.rollback("#{Rails.root}/db/migrate/reset_password")
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
it_behaves_like 'rails_3_reset_password_model'
|
|
15
|
-
end
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
require 'rails_app/app/mailers/sorcery_mailer'
|
|
3
|
-
require 'shared_examples/user_shared_examples'
|
|
4
|
-
|
|
5
|
-
describe User, 'with no submodules (core)', active_record: true do
|
|
6
|
-
before(:all) do
|
|
7
|
-
sorcery_reload!
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
context 'when app has plugin loaded' do
|
|
11
|
-
it 'responds to the plugin activation class method' do
|
|
12
|
-
expect(ActiveRecord::Base).to respond_to :authenticates_with_sorcery!
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
it 'User responds to .authenticates_with_sorcery!' do
|
|
16
|
-
expect(User).to respond_to :authenticates_with_sorcery!
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
# ----------------- PLUGIN CONFIGURATION -----------------------
|
|
21
|
-
|
|
22
|
-
it_should_behave_like 'rails_3_core_model'
|
|
23
|
-
|
|
24
|
-
describe 'external users' do
|
|
25
|
-
it_should_behave_like 'external_user'
|
|
26
|
-
end
|
|
27
|
-
end
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
# require 'shared_examples/controller_activity_logging_shared_examples'
|
|
4
|
-
|
|
5
|
-
describe SorceryController, type: :controller do
|
|
6
|
-
after(:all) do
|
|
7
|
-
sorcery_controller_property_set(:register_login_time, true)
|
|
8
|
-
sorcery_controller_property_set(:register_logout_time, true)
|
|
9
|
-
sorcery_controller_property_set(:register_last_activity_time, true)
|
|
10
|
-
# sorcery_controller_property_set(:last_login_from_ip_address_name, true)
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
# ----------------- ACTIVITY LOGGING -----------------------
|
|
14
|
-
context 'with activity logging features' do
|
|
15
|
-
let(:adapter) { double('sorcery_adapter') }
|
|
16
|
-
let(:user) { double('user', id: 42, sorcery_adapter: adapter) }
|
|
17
|
-
|
|
18
|
-
before(:all) do
|
|
19
|
-
sorcery_reload!([:activity_logging])
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
before(:each) do
|
|
23
|
-
allow(user).to receive(:username)
|
|
24
|
-
allow(user).to receive_message_chain(:sorcery_config, :username_attribute_names, :first) { :username }
|
|
25
|
-
allow(User.sorcery_config).to receive(:last_login_at_attribute_name) { :last_login_at }
|
|
26
|
-
allow(User.sorcery_config).to receive(:last_login_from_ip_address_name) { :last_login_from_ip_address }
|
|
27
|
-
|
|
28
|
-
sorcery_controller_property_set(:register_login_time, false)
|
|
29
|
-
sorcery_controller_property_set(:register_last_ip_address, false)
|
|
30
|
-
sorcery_controller_property_set(:register_last_activity_time, false)
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
it 'logs login time on login' do
|
|
34
|
-
now = Time.now.in_time_zone
|
|
35
|
-
Timecop.freeze(now)
|
|
36
|
-
|
|
37
|
-
sorcery_controller_property_set(:register_login_time, true)
|
|
38
|
-
expect(user).to receive(:set_last_login_at).with(be_within(0.1).of(now))
|
|
39
|
-
login_user(user)
|
|
40
|
-
|
|
41
|
-
Timecop.return
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
it 'logs logout time on logout' do
|
|
45
|
-
login_user(user)
|
|
46
|
-
now = Time.now.in_time_zone
|
|
47
|
-
Timecop.freeze(now)
|
|
48
|
-
expect(user).to receive(:set_last_logout_at).with(be_within(0.1).of(now))
|
|
49
|
-
|
|
50
|
-
logout_user
|
|
51
|
-
|
|
52
|
-
Timecop.return
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
it 'logs last activity time when logged in' do
|
|
56
|
-
sorcery_controller_property_set(:register_last_activity_time, true)
|
|
57
|
-
|
|
58
|
-
login_user(user)
|
|
59
|
-
now = Time.now.in_time_zone
|
|
60
|
-
Timecop.freeze(now)
|
|
61
|
-
expect(user).to receive(:set_last_activity_at).with(be_within(0.1).of(now))
|
|
62
|
-
|
|
63
|
-
get :some_action
|
|
64
|
-
|
|
65
|
-
Timecop.return
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
it 'logs last IP address when logged in' do
|
|
69
|
-
sorcery_controller_property_set(:register_last_ip_address, true)
|
|
70
|
-
expect(user).to receive(:set_last_ip_address).with('0.0.0.0')
|
|
71
|
-
|
|
72
|
-
login_user(user)
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
it 'updates nothing but activity fields' do
|
|
76
|
-
pending 'Move to model'
|
|
77
|
-
original_user_name = User.last.username
|
|
78
|
-
login_user(user)
|
|
79
|
-
get :some_action_making_a_non_persisted_change_to_the_user
|
|
80
|
-
|
|
81
|
-
expect(User.last.username).to eq original_user_name
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
it 'does not register login time if configured so' do
|
|
85
|
-
sorcery_controller_property_set(:register_login_time, false)
|
|
86
|
-
|
|
87
|
-
expect(user).to receive(:set_last_login_at).never
|
|
88
|
-
login_user(user)
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
it 'does not register logout time if configured so' do
|
|
92
|
-
sorcery_controller_property_set(:register_logout_time, false)
|
|
93
|
-
login_user(user)
|
|
94
|
-
|
|
95
|
-
expect(user).to receive(:set_last_logout_at).never
|
|
96
|
-
logout_user
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
it 'does not register last activity time if configured so' do
|
|
100
|
-
sorcery_controller_property_set(:register_last_activity_time, false)
|
|
101
|
-
|
|
102
|
-
expect(user).to receive(:set_last_activity_at).never
|
|
103
|
-
login_user(user)
|
|
104
|
-
end
|
|
105
|
-
|
|
106
|
-
it 'does not register last IP address if configured so' do
|
|
107
|
-
sorcery_controller_property_set(:register_last_ip_address, false)
|
|
108
|
-
expect(user).to receive(:set_last_ip_address).never
|
|
109
|
-
|
|
110
|
-
login_user(user)
|
|
111
|
-
end
|
|
112
|
-
end
|
|
113
|
-
end
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
describe SorceryController, type: :controller do
|
|
4
|
-
let(:user) { double('user', id: 42, email: 'bla@bla.com') }
|
|
5
|
-
|
|
6
|
-
def request_test_login
|
|
7
|
-
get :test_login, params: { email: 'bla@bla.com', password: 'blabla' }
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
# ----------------- SESSION TIMEOUT -----------------------
|
|
11
|
-
describe 'brute force protection features' do
|
|
12
|
-
before(:all) do
|
|
13
|
-
sorcery_reload!([:brute_force_protection])
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
after(:each) do
|
|
17
|
-
Sorcery::Controller::Config.reset!
|
|
18
|
-
sorcery_controller_property_set(:user_class, User)
|
|
19
|
-
Timecop.return
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
it 'counts login retries' do
|
|
23
|
-
allow(User).to receive(:authenticate) { |&block| block.call(nil, :other) }
|
|
24
|
-
allow(User.sorcery_adapter).to receive(:find_by_credentials).with(['bla@bla.com', 'blabla']).and_return(user)
|
|
25
|
-
|
|
26
|
-
expect(user).to receive(:register_failed_login!).exactly(3).times
|
|
27
|
-
|
|
28
|
-
3.times { request_test_login }
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
it 'resets the counter on a good login' do
|
|
32
|
-
# dirty hack for rails 4
|
|
33
|
-
allow(@controller).to receive(:register_last_activity_time_to_db)
|
|
34
|
-
|
|
35
|
-
allow(User).to receive(:authenticate) { |&block| block.call(user, nil) }
|
|
36
|
-
expect(user).to receive_message_chain(:sorcery_adapter, :update_attribute).with(:failed_logins_count, 0)
|
|
37
|
-
|
|
38
|
-
get :test_login, params: { email: 'bla@bla.com', password: 'secret' }
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
end
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
describe SorceryController, type: :controller do
|
|
4
|
-
let(:user) { double('user', id: 42, email: 'bla@bla.com') }
|
|
5
|
-
|
|
6
|
-
describe 'with http basic auth features' do
|
|
7
|
-
before(:all) do
|
|
8
|
-
sorcery_reload!([:http_basic_auth])
|
|
9
|
-
|
|
10
|
-
sorcery_controller_property_set(:controller_to_realm_map, 'sorcery' => 'sorcery')
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
after(:each) do
|
|
14
|
-
logout_user
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
it 'requests basic authentication when before_action is used' do
|
|
18
|
-
get :test_http_basic_auth
|
|
19
|
-
|
|
20
|
-
expect(response.status).to eq 401
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
it 'authenticates from http basic if credentials are sent' do
|
|
24
|
-
# dirty hack for rails 4
|
|
25
|
-
allow(subject).to receive(:register_last_activity_time_to_db)
|
|
26
|
-
|
|
27
|
-
@request.env['HTTP_AUTHORIZATION'] = "Basic #{Base64.encode64("#{user.email}:secret")}"
|
|
28
|
-
expect(User).to receive('authenticate').with('bla@bla.com', 'secret').and_return(user)
|
|
29
|
-
get :test_http_basic_auth, params: {}, session: { http_authentication_used: true }
|
|
30
|
-
|
|
31
|
-
expect(response).to be_successful
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
it 'fails authentication if credentials are wrong' do
|
|
35
|
-
@request.env['HTTP_AUTHORIZATION'] = "Basic #{Base64.encode64("#{user.email}:wrong!")}"
|
|
36
|
-
expect(User).to receive('authenticate').with('bla@bla.com', 'wrong!').and_return(nil)
|
|
37
|
-
get :test_http_basic_auth, params: {}, session: { http_authentication_used: true }
|
|
38
|
-
|
|
39
|
-
expect(response).to redirect_to root_url
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
it "allows configuration option 'controller_to_realm_map'" do
|
|
43
|
-
sorcery_controller_property_set(:controller_to_realm_map, '1' => '2')
|
|
44
|
-
|
|
45
|
-
expect(Sorcery::Controller::Config.controller_to_realm_map).to eq('1' => '2')
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
it 'displays the correct realm name configured for the controller' do
|
|
49
|
-
sorcery_controller_property_set(:controller_to_realm_map, 'sorcery' => 'Salad')
|
|
50
|
-
get :test_http_basic_auth
|
|
51
|
-
|
|
52
|
-
expect(response.headers['WWW-Authenticate']).to eq 'Basic realm="Salad"'
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
it "signs in the user's session on successful login" do
|
|
56
|
-
# dirty hack for rails 4
|
|
57
|
-
allow(controller).to receive(:register_last_activity_time_to_db)
|
|
58
|
-
|
|
59
|
-
@request.env['HTTP_AUTHORIZATION'] = "Basic #{Base64.encode64("#{user.email}:secret")}"
|
|
60
|
-
expect(User).to receive('authenticate').with('bla@bla.com', 'secret').and_return(user)
|
|
61
|
-
|
|
62
|
-
get :test_http_basic_auth, params: {}, session: { http_authentication_used: true }
|
|
63
|
-
|
|
64
|
-
expect(session[:user_id]).to eq '42'
|
|
65
|
-
end
|
|
66
|
-
end
|
|
67
|
-
end
|