From 6c155be1319a8699eb05f51c2bcba5dc63dd94df Mon Sep 17 00:00:00 2001 From: Josh Buker Date: Thu, 8 Nov 2018 21:47:56 +0000 Subject: [PATCH] Prepare for 1.0.0 (#157) * Remove jruby references jruby was added previously, but never fully supported. Removing for now, pending proper support. * Match min ruby requirement with lowest tested ruby version * Add maintainer to gemspec author list * Update license to md format * Remove excess whitespace * Update rubocop ruby lock and regen TODO list * Disable rubocop for migration files (breaks) * Fix Bundler/OrderedGems * Fix rails 6 deprecation warning * Add missing newline * Fix Gemspec/OrderedDependencies * Fix Gemspec/RequiredRubyVersion and regen TODO * Fix Layout/AlignHash * Fix Layout/ClosingParenthesisIndentation * Fix Layout/EmptyLineAfterGuardClause * Fix Layout/EmptyLineBetweenDefs * Fix Layout/EmptyLines Fixed by last commit * Fix Layout/EmptyLinesAroundArguments * Fix Layout/EmptyLinesAroundBlockBody * Fix Layout/EmptyLinesAroundClassBody * Fixed Layout/EmptyLinesAroundModuleBody on previous commit * Fix Layout/EndAlignment * Fix Layout/ExtraSpacing * Fix Layout/FirstParameterIndentation * Fix Layout/IndentHash * Fix Layout/MultilineMethodCallBraceLayout * Fix Layout/MultilineMethodCallIndentation * Fix Layout/MultilineOperationIndentation * Fix Layout/SpaceAfterComma * Fix Layout/SpaceAroundEqualsInParameterDefault * Fix Layout/SpaceAroundOperators * Fix Layout/SpaceBeforeBlockBraces * Fix Layout/SpaceInsideBlockBraces * Fix Layout/SpaceInsideHashLiteralBraces * Fix Layout/TrailingBlankLines * Fix Layout/TrailingWhitespace * Fix Lint/AmbiguousBlockAssociation * Fix Lint/AssignmentInCondition * Fix Lint/DuplicateMethods * Add rubocop to development dependencies * Rails 4.1 has been released, remove rescue statement * Fix Lint/HandleExceptions * Fix Lint/NonLocalExitFromIterator * Fix Lint/ParenthesesAsGroupedExpression * Fix Lint/UnderscorePrefixedVariableName * Fix Lint/UselessAssignment * Fix Lint/Void - Found potentially broken specs for remember_me functionality * Fix Naming/FileName * Fix Style/AndOr * Fix Style/BracesAroundHashParameters * Add Github issue template * Fix Style/TrailingCommaInHashLiteral * Fix Style/TrailingCommaInArguments * Fix Style/SymbolArray * Fix Style/StringLiterals * Fix Style/RescueStandardError * Fix Style/RegexpLiteral * Fix Style/RedundantSelf * Fix Style/RedundantReturn * Fix Style/RedundantParentheses * Move harder to solve rubocop issues to prepare for 1.0.0 * Naming conventions will be fixed by rewrite in 1.0.0 * Fix Naming/MemoizedInstanceVariableName * Naming conventions will be fixed by rewrite in 1.0.0 * Fix Style/PercentLiteralDelimiters * Fix Style/ParenthesesAroundCondition Fixed by previous commit * Fix Style/NumericLiterals * Fix Style/MutableConstant * Fix Style/MultipleComparison * Fix Style/IfUnlessModifier Fixed on previous commit * Fix Style/HashSyntax * Fix Style/GuardClause * Fix Style/FormatString * Fix Style/ExpandPathArguments * Fix Style/EvalWithLocation * Fix Style/EmptyLiteral * Disable Style/DoubleNegation * Documentation will be fixed by rewrite in 1.0.0 * Fix Style/Dir * Fix Style/ConditionalAssignment Fixed by previous commit * Fix Style/ClassAndModuleChildren * Regenerate rubocop TODO * Add maintainer to gemspec email list --- .github/ISSUE_TEMPLATE.md | 20 + .rubocop.yml | 54 ++- .rubocop_todo.yml | 430 +----------------- .travis.yml | 32 +- Gemfile | 2 +- LICENSE.txt => LICENSE.md | 2 +- ...gemfile => active_record_rails_40.gemfile} | 3 +- ...gemfile => active_record_rails_41.gemfile} | 3 +- ...gemfile => active_record_rails_42.gemfile} | 3 +- lib/generators/sorcery/USAGE | 2 +- lib/generators/sorcery/install_generator.rb | 40 +- lib/sorcery/adapters/mongoid_adapter.rb | 24 +- lib/sorcery/controller.rb | 32 +- .../controller/submodules/activity_logging.rb | 4 + lib/sorcery/controller/submodules/external.rb | 68 +-- .../controller/submodules/http_basic_auth.rb | 1 + .../controller/submodules/session_timeout.rb | 2 + lib/sorcery/crypto_providers/aes256.rb | 1 + lib/sorcery/crypto_providers/bcrypt.rb | 3 +- lib/sorcery/model.rb | 15 +- lib/sorcery/model/config.rb | 6 +- .../submodules/brute_force_protection.rb | 13 +- lib/sorcery/model/submodules/external.rb | 3 +- lib/sorcery/model/submodules/magic_login.rb | 65 ++- .../model/submodules/reset_password.rb | 3 +- lib/sorcery/protocols/oauth.rb | 1 + lib/sorcery/providers/heroku.rb | 1 + lib/sorcery/providers/instagram.rb | 35 +- lib/sorcery/providers/linkedin.rb | 2 +- lib/sorcery/providers/vk.rb | 2 +- lib/sorcery/providers/wechat.rb | 14 +- lib/sorcery/test_helpers/internal.rb | 9 +- lib/sorcery/test_helpers/internal/rails.rb | 22 +- lib/sorcery/version.rb | 2 +- sorcery.gemspec | 34 +- spec/active_record/user_magic_login_spec.rb | 4 +- spec/controllers/controller_oauth2_spec.rb | 293 +++++++----- spec/controllers/controller_oauth_spec.rb | 10 +- .../controller_remember_me_spec.rb | 15 +- .../controller_session_timeout_spec.rb | 18 +- spec/controllers/controller_spec.rb | 2 +- spec/providers/vk_spec.rb | 25 +- .../app/controllers/sorcery_controller.rb | 74 +-- spec/rails_app/app/mailers/sorcery_mailer.rb | 2 +- spec/rails_app/config/application.rb | 7 +- spec/rails_app/config/boot.rb | 2 +- spec/rails_app/config/environment.rb | 2 +- ...224223624_add_activity_logging_to_users.rb | 4 +- ...20170924151831_add_magic_login_to_users.rb | 6 +- spec/rails_app/db/schema.rb | 16 +- .../user_magic_login_shared_examples.rb | 100 ++-- .../user_oauth_shared_examples.rb | 2 +- .../user_remember_me_shared_examples.rb | 2 +- .../user_reset_password_shared_examples.rb | 6 +- spec/shared_examples/user_shared_examples.rb | 35 +- spec/sorcery_crypto_providers_spec.rb | 2 +- spec/spec.opts | 2 +- spec/spec_helper.rb | 2 +- 58 files changed, 658 insertions(+), 926 deletions(-) create mode 100644 .github/ISSUE_TEMPLATE.md rename LICENSE.txt => LICENSE.md (94%) rename gemfiles/{active_record-rails40.gemfile => active_record_rails_40.gemfile} (64%) rename gemfiles/{active_record-rails41.gemfile => active_record_rails_41.gemfile} (64%) rename gemfiles/{active_record-rails42.gemfile => active_record_rails_42.gemfile} (64%) diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md new file mode 100644 index 00000000..582e1fac --- /dev/null +++ b/.github/ISSUE_TEMPLATE.md @@ -0,0 +1,20 @@ +Please complete all sections. + +### Configuration + +- Sorcery Version: `` +- Ruby Version: `` +- Framework: `` +- Platform: `` + +### Expected Behavior + +Tell us what should happen. + +### Actual Behavior + +Tell us what happens instead. + +### Steps to Reproduce + +Please list all steps to reproduce the issue. diff --git a/.rubocop.yml b/.rubocop.yml index 67036565..ce1dc552 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,5 +1,55 @@ -# Use auto generated file to ignore existing warnings. -inherit_from: '.rubocop_todo.yml' +inherit_from: .rubocop_todo.yml AllCops: + Exclude: + - 'lib/generators/sorcery/templates/**/*' TargetRubyVersion: 2.2 + +# See: https://github.com/rubocop-hq/rubocop/issues/3344 +Style/DoubleNegation: + Enabled: false + +#################### +## Pre-1.0.0 Code ## +#################### + +Metrics/AbcSize: + Exclude: + - 'lib/**/*' + - 'spec/**/*' +Metrics/BlockLength: + Exclude: + - 'lib/**/*' + - 'spec/**/*' +Metrics/LineLength: + Exclude: + - 'lib/**/*' + - 'spec/**/*' +Metrics/ClassLength: + Exclude: + - 'lib/**/*' + - 'spec/**/*' +Metrics/CyclomaticComplexity: + Exclude: + - 'lib/**/*' + - 'spec/**/*' +Metrics/MethodLength: + Exclude: + - 'lib/**/*' + - 'spec/**/*' +Metrics/PerceivedComplexity: + Exclude: + - 'lib/**/*' + - 'spec/**/*' +Naming/AccessorMethodName: + Exclude: + - 'lib/**/*' + - 'spec/**/*' +Naming/PredicateName: + Exclude: + - 'lib/**/*' + - 'spec/**/*' +Style/Documentation: + Exclude: + - 'lib/**/*' + - 'spec/**/*' diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index c539bacd..4d8c565f 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,435 +1,7 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2018-02-03 14:20:34 -0800 using RuboCop version 0.51.0. +# on 2018-11-01 18:13:47 -0700 using RuboCop version 0.59.2. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: Include, TreatCommentsAsGroupSeparators. -# Include: **/Gemfile, **/gems.rb -Bundler/OrderedGems: - Exclude: - - 'Gemfile' - -# Offense count: 5 -# Cop supports --auto-correct. -# Configuration parameters: Include, TreatCommentsAsGroupSeparators. -# Include: **/*.gemspec -Gemspec/OrderedDependencies: - Exclude: - - 'sorcery.gemspec' - -# Offense count: 7 -# Cop supports --auto-correct. -Layout/EmptyLines: - Exclude: - - 'lib/generators/sorcery/templates/initializer.rb' - -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -# SupportedStyles: empty_lines, no_empty_lines -Layout/EmptyLinesAroundBlockBody: - Exclude: - - 'spec/rails_app/db/schema.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -# SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines -Layout/EmptyLinesAroundClassBody: - Exclude: - - 'lib/sorcery/adapters/mongoid_adapter.rb' - -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: AllowForAlignment, ForceEqualSignAlignment. -Layout/ExtraSpacing: - Exclude: - - 'lib/sorcery/adapters/mongoid_adapter.rb' - -# Offense count: 3 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth. -# SupportedStyles: special_inside_parentheses, consistent, align_braces -Layout/IndentHash: - Exclude: - - 'lib/sorcery/model/submodules/magic_login.rb' - - 'lib/sorcery/providers/wechat.rb' - -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth. -# SupportedStyles: aligned, indented, indented_relative_to_receiver -Layout/MultilineMethodCallIndentation: - Exclude: - - 'lib/sorcery/adapters/mongoid_adapter.rb' - -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth. -# SupportedStyles: aligned, indented -Layout/MultilineOperationIndentation: - Exclude: - - 'lib/sorcery/model/submodules/magic_login.rb' - -# Offense count: 2 -# Cop supports --auto-correct. -Layout/SpaceAfterComma: - Exclude: - - 'lib/sorcery/adapters/mongoid_adapter.rb' - - 'spec/controllers/controller_oauth2_spec.rb' - -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -# SupportedStyles: space, no_space -Layout/SpaceAroundEqualsInParameterDefault: - Exclude: - - 'lib/sorcery/adapters/mongoid_adapter.rb' - -# Offense count: 3 -# Cop supports --auto-correct. -# Configuration parameters: AllowForAlignment. -Layout/SpaceAroundOperators: - Exclude: - - 'lib/sorcery/adapters/mongoid_adapter.rb' - - 'spec/shared_examples/user_magic_login_shared_examples.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles, SupportedStylesForEmptyBraces. -# SupportedStyles: space, no_space -# SupportedStylesForEmptyBraces: space, no_space -Layout/SpaceBeforeBlockBraces: - Exclude: - - 'lib/sorcery/providers/linkedin.rb' - -# Offense count: 8 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles, EnforcedStyleForEmptyBraces, SupportedStylesForEmptyBraces, SpaceBeforeBlockParameters. -# SupportedStyles: space, no_space -# SupportedStylesForEmptyBraces: space, no_space -Layout/SpaceInsideBlockBraces: - Exclude: - - 'lib/sorcery/adapters/mongoid_adapter.rb' - - 'lib/sorcery/providers/linkedin.rb' - - 'spec/shared_examples/user_magic_login_shared_examples.rb' - -# Offense count: 4 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles, EnforcedStyleForEmptyBraces, SupportedStylesForEmptyBraces. -# SupportedStyles: space, no_space, compact -# SupportedStylesForEmptyBraces: space, no_space -Layout/SpaceInsideHashLiteralBraces: - Exclude: - - 'lib/sorcery/adapters/mongoid_adapter.rb' - - 'lib/sorcery/model/submodules/magic_login.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -# SupportedStyles: final_newline, final_blank_line -Layout/TrailingBlankLines: - Exclude: - - 'lib/sorcery/providers/wechat.rb' - -# Offense count: 52 -# Cop supports --auto-correct. -Layout/TrailingWhitespace: - Exclude: - - 'lib/sorcery/model/submodules/magic_login.rb' - - 'spec/active_record/user_magic_login_spec.rb' - - 'spec/rails_app/app/mailers/sorcery_mailer.rb' - - 'spec/rails_app/db/migrate/magic_login/20170924151831_add_magic_login_to_users.rb' - - 'spec/shared_examples/user_magic_login_shared_examples.rb' - -# Offense count: 1 -Lint/AmbiguousBlockAssociation: - Exclude: - - 'spec/shared_examples/user_shared_examples.rb' - -# Offense count: 28 -# Configuration parameters: AllowSafeAssignment. -Lint/AssignmentInCondition: - Exclude: - - 'lib/sorcery/controller/submodules/external.rb' - - 'lib/sorcery/providers/vk.rb' - - 'spec/rails_app/app/controllers/sorcery_controller.rb' - -# Offense count: 1 -Lint/DuplicateMethods: - Exclude: - - 'lib/sorcery/model/config.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyleAlignWith, SupportedStylesAlignWith, AutoCorrect. -# SupportedStylesAlignWith: keyword, variable, start_of_line -Lint/EndAlignment: - Exclude: - - 'lib/sorcery/model/config.rb' - -# Offense count: 5 -Lint/HandleExceptions: - Exclude: - - 'lib/sorcery/controller.rb' - - 'lib/sorcery/model.rb' - - 'spec/rails_app/config/application.rb' - - 'spec/shared_examples/user_shared_examples.rb' - -# Offense count: 1 -Lint/NonLocalExitFromIterator: - Exclude: - - 'lib/sorcery/controller.rb' - -# Offense count: 1 -Lint/ParenthesesAsGroupedExpression: - Exclude: - - 'spec/shared_examples/user_remember_me_shared_examples.rb' - -# Offense count: 3 -Lint/RescueWithoutErrorClass: - Exclude: - - 'lib/sorcery/controller/submodules/external.rb' - - 'spec/shared_examples/user_shared_examples.rb' - - 'spec/spec_helper.rb' - -# Offense count: 7 -Lint/UselessAssignment: - Exclude: - - 'lib/sorcery/controller/submodules/external.rb' - - 'lib/sorcery/model/submodules/external.rb' - - 'spec/controllers/controller_oauth2_spec.rb' - - 'spec/controllers/controller_remember_me_spec.rb' - -# Offense count: 2 -Lint/Void: - Exclude: - - 'spec/controllers/controller_remember_me_spec.rb' - -# Offense count: 28 -Metrics/AbcSize: - Max: 36 - -# Offense count: 73 -# Configuration parameters: CountComments, ExcludedMethods. -Metrics/BlockLength: - Max: 391 - -# Offense count: 1 -# Configuration parameters: CountComments. -Metrics/ClassLength: - Max: 303 - -# Offense count: 3 -Metrics/CyclomaticComplexity: - Max: 9 - -# Offense count: 833 -# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. -# URISchemes: http, https -Metrics/LineLength: - Max: 323 - -# Offense count: 33 -# Configuration parameters: CountComments. -Metrics/MethodLength: - Max: 39 - -# Offense count: 1 -Metrics/PerceivedComplexity: - Max: 9 - -# Offense count: 11 -Naming/AccessorMethodName: - Exclude: - - 'lib/sorcery/adapters/mongoid_adapter.rb' - - 'lib/sorcery/controller/submodules/remember_me.rb' - - 'lib/sorcery/model/submodules/activity_logging.rb' - - 'lib/sorcery/protocols/oauth.rb' - - 'lib/sorcery/providers/jira.rb' - - 'lib/sorcery/providers/linkedin.rb' - - 'lib/sorcery/providers/twitter.rb' - - 'lib/sorcery/providers/xing.rb' - -# Offense count: 2 -# Configuration parameters: NamePrefix, NamePrefixBlacklist, NameWhitelist, MethodDefinitionMacros. -# NamePrefix: is_, has_, have_ -# NamePrefixBlacklist: is_, has_, have_ -# NameWhitelist: is_a? -# MethodDefinitionMacros: define_method, define_singleton_method -Naming/PredicateName: - Exclude: - - 'spec/**/*' - - 'lib/sorcery/model/submodules/remember_me.rb' - - 'lib/sorcery/providers/base.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -# SupportedStyles: always, conditionals -Style/AndOr: - Exclude: - - 'lib/sorcery/model/submodules/magic_login.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -# SupportedStyles: braces, no_braces, context_dependent -Style/BracesAroundHashParameters: - Exclude: - - 'lib/sorcery/model/submodules/magic_login.rb' - -# Offense count: 1 -# Configuration parameters: EnforcedStyle, SupportedStyles. -# SupportedStyles: nested, compact -Style/ClassAndModuleChildren: - Exclude: - - 'lib/sorcery/test_helpers/internal.rb' - -# Offense count: 2 -Style/DateTime: - Exclude: - - 'spec/shared_examples/user_magic_login_shared_examples.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -Style/Dir: - Exclude: - - 'lib/sorcery/controller/submodules/external.rb' - -# Offense count: 52 -Style/Documentation: - Enabled: false - -# Offense count: 2 -Style/DoubleNegation: - Exclude: - - 'lib/generators/sorcery/helpers.rb' - - 'lib/sorcery/controller.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -# SupportedStyles: format, sprintf, percent -Style/FormatString: - Exclude: - - 'lib/generators/sorcery/install_generator.rb' - -# Offense count: 16 -# Configuration parameters: MinBodyLength. -Style/GuardClause: - Exclude: - - 'lib/generators/sorcery/install_generator.rb' - - 'lib/sorcery/controller.rb' - - 'lib/sorcery/controller/submodules/external.rb' - - 'lib/sorcery/model.rb' - - 'lib/sorcery/model/submodules/brute_force_protection.rb' - - 'lib/sorcery/test_helpers/internal.rb' - - 'lib/sorcery/test_helpers/internal/rails.rb' - - 'spec/rails_app/app/controllers/sorcery_controller.rb' - -# Offense count: 4 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols. -# SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys -Style/HashSyntax: - Exclude: - - 'lib/sorcery/adapters/mongoid_adapter.rb' - - 'spec/controllers/controller_oauth2_spec.rb' - - 'spec/rails_app/db/schema.rb' - -# Offense count: 1 -Style/MultipleComparison: - Exclude: - - 'lib/generators/sorcery/install_generator.rb' - -# Offense count: 2 -# Cop supports --auto-correct. -Style/MutableConstant: - Exclude: - - 'lib/sorcery/test_helpers/internal/rails.rb' - - 'lib/sorcery/version.rb' - -# Offense count: 11 -# Cop supports --auto-correct. -# Configuration parameters: Strict. -Style/NumericLiterals: - MinDigits: 18 - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: AllowSafeAssignment. -Style/ParenthesesAroundCondition: - Exclude: - - 'lib/sorcery/adapters/mongoid_adapter.rb' - -# Offense count: 5 -# Cop supports --auto-correct. -# Configuration parameters: PreferredDelimiters. -Style/PercentLiteralDelimiters: - Exclude: - - 'lib/sorcery/test_helpers/internal/rails.rb' - - 'spec/controllers/controller_oauth2_spec.rb' - - 'spec/rails_app/config/application.rb' - - 'spec/sorcery_crypto_providers_spec.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -Style/RedundantParentheses: - Exclude: - - 'lib/sorcery/adapters/mongoid_adapter.rb' - -# Offense count: 4 -# Cop supports --auto-correct. -Style/RedundantSelf: - Exclude: - - 'lib/sorcery/model/submodules/magic_login.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles, AllowInnerSlashes. -# SupportedStyles: slashes, percent_r, mixed -Style/RegexpLiteral: - Exclude: - - 'spec/rails_app/config/application.rb' - -# Offense count: 89 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles, ConsistentQuotesInMultiline. -# SupportedStyles: single_quotes, double_quotes -Style/StringLiterals: - Exclude: - - 'lib/sorcery/adapters/mongoid_adapter.rb' - - 'lib/sorcery/model/submodules/magic_login.rb' - - 'spec/controllers/controller_oauth2_spec.rb' - - 'spec/rails_app/db/schema.rb' - - 'spec/shared_examples/user_magic_login_shared_examples.rb' - -# Offense count: 22 -# Cop supports --auto-correct. -# Configuration parameters: MinSize, SupportedStyles. -# SupportedStyles: percent, brackets -Style/SymbolArray: - EnforcedStyle: brackets - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyleForMultiline, SupportedStylesForMultiline. -# SupportedStylesForMultiline: comma, consistent_comma, no_comma -Style/TrailingCommaInArguments: - Exclude: - - 'lib/sorcery/providers/wechat.rb' - -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyleForMultiline, SupportedStylesForMultiline. -# SupportedStylesForMultiline: comma, consistent_comma, no_comma -Style/TrailingCommaInLiteral: - Exclude: - - 'lib/sorcery/providers/wechat.rb' - - 'spec/controllers/controller_oauth2_spec.rb' diff --git a/.travis.yml b/.travis.yml index 3283ceaf..cd3c6641 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,20 +1,15 @@ language: ruby rvm: - - jruby - 2.2.9 - 2.3.6 - 2.4.3 - 2.5.0 -env: - global: - - JRUBY_OPTS="--2.0" - gemfile: - Gemfile - - gemfiles/active_record-rails40.gemfile - - gemfiles/active_record-rails41.gemfile - - gemfiles/active_record-rails42.gemfile + - gemfiles/active_record_rails_40.gemfile + - gemfiles/active_record_rails_41.gemfile + - gemfiles/active_record_rails_42.gemfile before_script: - mysql -e 'create database sorcery_test;' @@ -24,25 +19,20 @@ before_install: - gem update bundler matrix: - allow_failures: - - rvm: jruby - exclude: - rvm: 2.2.9 - gemfile: gemfiles/active_record-rails40.gemfile + gemfile: gemfiles/active_record_rails_40.gemfile - rvm: 2.3.6 - gemfile: gemfiles/active_record-rails40.gemfile + gemfile: gemfiles/active_record_rails_40.gemfile - rvm: 2.4.3 - gemfile: gemfiles/active_record-rails40.gemfile + gemfile: gemfiles/active_record_rails_40.gemfile - rvm: 2.4.3 - gemfile: gemfiles/active_record-rails41.gemfile + gemfile: gemfiles/active_record_rails_41.gemfile - rvm: 2.4.3 - gemfile: gemfiles/active_record-rails42.gemfile + gemfile: gemfiles/active_record_rails_42.gemfile - rvm: 2.5.0 - gemfile: gemfiles/active_record-rails40.gemfile + gemfile: gemfiles/active_record_rails_40.gemfile - rvm: 2.5.0 - gemfile: gemfiles/active_record-rails41.gemfile + gemfile: gemfiles/active_record_rails_41.gemfile - rvm: 2.5.0 - gemfile: gemfiles/active_record-rails42.gemfile - - rvm: jruby - gemfile: Gemfile + gemfile: gemfiles/active_record_rails_42.gemfile diff --git a/Gemfile b/Gemfile index c7c8f10c..6afda476 100644 --- a/Gemfile +++ b/Gemfile @@ -1,8 +1,8 @@ source 'https://rubygems.org' +gem 'pry' gem 'rails', '~> 5.2.0' gem 'rails-controller-testing' gem 'sqlite3' -gem 'pry' gemspec diff --git a/LICENSE.txt b/LICENSE.md similarity index 94% rename from LICENSE.txt rename to LICENSE.md index cb0d98c0..e43f00c5 100644 --- a/LICENSE.txt +++ b/LICENSE.md @@ -1,4 +1,4 @@ -Copyright (c) 2010 Noam Ben-Ari +Copyright (c) 2010 [Noam Ben-Ari](mailto:nbenari@gmail.com) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/gemfiles/active_record-rails40.gemfile b/gemfiles/active_record_rails_40.gemfile similarity index 64% rename from gemfiles/active_record-rails40.gemfile rename to gemfiles/active_record_rails_40.gemfile index 9d5aa3e0..ffaf538a 100644 --- a/gemfiles/active_record-rails40.gemfile +++ b/gemfiles/active_record_rails_40.gemfile @@ -1,7 +1,6 @@ source 'https://rubygems.org' -gem 'sqlite3', platform: :mri -gem 'activerecord-jdbcsqlite3-adapter', platform: :jruby gem 'rails', '~> 4.0.1' +gem 'sqlite3', platform: :mri gemspec path: '..' diff --git a/gemfiles/active_record-rails41.gemfile b/gemfiles/active_record_rails_41.gemfile similarity index 64% rename from gemfiles/active_record-rails41.gemfile rename to gemfiles/active_record_rails_41.gemfile index 397ce6a7..67180498 100644 --- a/gemfiles/active_record-rails41.gemfile +++ b/gemfiles/active_record_rails_41.gemfile @@ -1,7 +1,6 @@ source 'https://rubygems.org' -gem 'sqlite3', platform: :mri -gem 'activerecord-jdbcsqlite3-adapter', platform: :jruby gem 'rails', '~> 4.1.0' +gem 'sqlite3', platform: :mri gemspec path: '..' diff --git a/gemfiles/active_record-rails42.gemfile b/gemfiles/active_record_rails_42.gemfile similarity index 64% rename from gemfiles/active_record-rails42.gemfile rename to gemfiles/active_record_rails_42.gemfile index 63c4d0f7..0fec5757 100644 --- a/gemfiles/active_record-rails42.gemfile +++ b/gemfiles/active_record_rails_42.gemfile @@ -1,7 +1,6 @@ source 'https://rubygems.org' -gem 'sqlite3', platform: :mri -gem 'activerecord-jdbcsqlite3-adapter', platform: :jruby gem 'rails', '~> 4.2.0' +gem 'sqlite3', platform: :mri gemspec path: '..' diff --git a/lib/generators/sorcery/USAGE b/lib/generators/sorcery/USAGE index 36b1a263..6e735aac 100644 --- a/lib/generators/sorcery/USAGE +++ b/lib/generators/sorcery/USAGE @@ -1,6 +1,6 @@ Description: Generates the necessary files to get you up and running with Sorcery gem - + Examples: rails generate sorcery:install diff --git a/lib/generators/sorcery/install_generator.rb b/lib/generators/sorcery/install_generator.rb index b03171bb..c3fefa32 100644 --- a/lib/generators/sorcery/install_generator.rb +++ b/lib/generators/sorcery/install_generator.rb @@ -7,7 +7,7 @@ class InstallGenerator < Rails::Generators::Base include Rails::Generators::Migration include Sorcery::Generators::Helpers - source_root File.expand_path('../templates', __FILE__) + source_root File.expand_path('templates', __dir__) argument :submodules, optional: true, type: :array, banner: 'submodules' @@ -21,9 +21,9 @@ class InstallGenerator < Rails::Generators::Base desc: "Specify if you want to add submodules to an existing model\n\t\t\t # (will generate migrations files, and add submodules to config file)" def check_deprecated_options - if options[:migrations] - warn('[DEPRECATED] `--migrations` option is deprecated, please use `--only-submodules` instead') - end + return unless options[:migrations] + + warn('[DEPRECATED] `--migrations` option is deprecated, please use `--only-submodules` instead') end # Copy the initializer file to config/initializers folder. @@ -33,23 +33,22 @@ def copy_initializer_file def configure_initializer_file # Add submodules to the initializer file. - if submodules - submodule_names = submodules.collect { |submodule| ':' + submodule } + return unless submodules - gsub_file sorcery_config_path, /submodules = \[.*\]/ do |str| - current_submodule_names = (str =~ /\[(.*)\]/ ? Regexp.last_match(1) : '').delete(' ').split(',') - "submodules = [#{(current_submodule_names | submodule_names).join(', ')}]" - end + submodule_names = submodules.collect { |submodule| ':' + submodule } + + gsub_file sorcery_config_path, /submodules = \[.*\]/ do |str| + current_submodule_names = (str =~ /\[(.*)\]/ ? Regexp.last_match(1) : '').delete(' ').split(',') + "submodules = [#{(current_submodule_names | submodule_names).join(', ')}]" end end def configure_model # Generate the model and add 'authenticates_with_sorcery!' unless you passed --only-submodules - unless only_submodules? - generate "model #{model_class_name} --skip-migration" + return if only_submodules? - inject_sorcery_to_model - end + generate "model #{model_class_name} --skip-migration" + inject_sorcery_to_model end def inject_sorcery_to_model @@ -62,13 +61,14 @@ def inject_sorcery_to_model def copy_migration_files # Copy core migration file in all cases except when you pass --only-submodules. return unless defined?(ActiveRecord) + migration_template 'migration/core.rb', 'db/migrate/sorcery_core.rb', migration_class_name: migration_class_name unless only_submodules? - if submodules - submodules.each do |submodule| - unless submodule == 'http_basic_auth' || submodule == 'session_timeout' || submodule == 'core' - migration_template "migration/#{submodule}.rb", "db/migrate/sorcery_#{submodule}.rb", migration_class_name: migration_class_name - end + return unless submodules + + submodules.each do |submodule| + unless %w[http_basic_auth session_timeout core].include?(submodule) + migration_template "migration/#{submodule}.rb", "db/migrate/sorcery_#{submodule}.rb", migration_class_name: migration_class_name end end end @@ -79,7 +79,7 @@ def self.next_migration_number(dirname) sleep 1 # make sure each time we get a different timestamp Time.new.utc.strftime('%Y%m%d%H%M%S') else - '%.3d' % (current_migration_number(dirname) + 1) + format('%.3d', (current_migration_number(dirname) + 1)) end end diff --git a/lib/sorcery/adapters/mongoid_adapter.rb b/lib/sorcery/adapters/mongoid_adapter.rb index baace2da..fbf5e23d 100644 --- a/lib/sorcery/adapters/mongoid_adapter.rb +++ b/lib/sorcery/adapters/mongoid_adapter.rb @@ -10,7 +10,7 @@ def update_attributes(attrs) attrs[name] = value.utc if value.is_a?(ActiveSupport::TimeWithZone) @model.send(:"#{name}=", value) end - @model.class.where(:_id => @model.id).update_all(attrs) + @model.class.where(_id: @model.id).update_all(attrs) end def update_attribute(name, value) @@ -23,16 +23,15 @@ def save(options = {}) end def mongoid_4? - Gem::Version.new(::Mongoid::VERSION) >= Gem::Version.new("4.0.0.alpha") + Gem::Version.new(::Mongoid::VERSION) >= Gem::Version.new('4.0.0.alpha') end class << self - - def define_field(name, type, options={}) + def define_field(name, type, options = {}) @klass.field name, options.slice(:default).merge(type: type) end - def define_callback(time, event, method_name, options={}) + def define_callback(time, event, method_name, options = {}) @klass.send callback_name(time, event, options), method_name, options.slice(:if) end @@ -45,7 +44,8 @@ def callback_name(time, event, options) end def credential_regex(credential) - return { :$regex => /^#{Regexp.escape(credential)}$/i } if (@klass.sorcery_config.downcase_username_before_authenticating) + return { :$regex => /^#{Regexp.escape(credential)}$/i } if @klass.sorcery_config.downcase_username_before_authenticating + credential end @@ -81,7 +81,7 @@ def find_by_id(id) end def find_by_username(username) - query = @klass.sorcery_config.username_attribute_names.map {|name| {name => username}} + query = @klass.sorcery_config.username_attribute_names.map { |name| { name => username } } @klass.any_of(*query).first end @@ -95,9 +95,13 @@ def find_by_email(email) def get_current_users config = @klass.sorcery_config - @klass.where(config.last_activity_at_attribute_name.ne => nil) \ - .where("this.#{config.last_logout_at_attribute_name} == null || this.#{config.last_activity_at_attribute_name} > this.#{config.last_logout_at_attribute_name}") \ - .where(config.last_activity_at_attribute_name.gt => config.activity_timeout.seconds.ago.utc).order_by([:_id,:asc]) + @klass.where( + config.last_activity_at_attribute_name.ne => nil + ).where( + "this.#{config.last_logout_at_attribute_name} == null || this.#{config.last_activity_at_attribute_name} > this.#{config.last_logout_at_attribute_name}" + ).where( + config.last_activity_at_attribute_name.gt => config.activity_timeout.seconds.ago.utc + ).order_by(%i[_id asc]) end end end diff --git a/lib/sorcery/controller.rb b/lib/sorcery/controller.rb index 3344ba19..7b40adce 100644 --- a/lib/sorcery/controller.rb +++ b/lib/sorcery/controller.rb @@ -4,11 +4,14 @@ def self.included(klass) klass.class_eval do include InstanceMethods Config.submodules.each do |mod| + # FIXME: Is there a cleaner way to handle missing submodules? + # rubocop:disable Lint/HandleExceptions begin include Submodules.const_get(mod.to_s.split('_').map(&:capitalize).join) rescue NameError # don't stop on a missing submodule. end + # rubocop:enable Lint/HandleExceptions end end Config.update! @@ -20,10 +23,10 @@ module InstanceMethods # Will trigger auto-login attempts via the call to logged_in? # If all attempts to auto-login fail, the failure callback will be called. def require_login - unless logged_in? - session[:return_to_url] = request.url if Config.save_return_to_url && request.get? && !request.xhr? - send(Config.not_authenticated_action) - end + return if logged_in? + + session[:return_to_url] = request.url if Config.save_return_to_url && request.get? && !request.xhr? + send(Config.not_authenticated_action) end # Takes credentials and returns a user on successful authentication. @@ -37,7 +40,10 @@ def login(*credentials) yield(user, failure_reason) if block_given? + # FIXME: Does using `break` or `return nil` change functionality? + # rubocop:disable Lint/NonLocalExitFromIterator return + # rubocop:enable Lint/NonLocalExitFromIterator end old_session = session.dup.to_hash @@ -54,23 +60,19 @@ def login(*credentials) end end - # put this into the catch block to rescue undefined method `destroy_session' - # hotfix for https://github.com/NoamB/sorcery/issues/464 - # can be removed when Rails 4.1 is out def reset_sorcery_session reset_session # protect from session fixation attacks - rescue NoMethodError end # Resets the session and runs hooks before and after. def logout - if logged_in? - user = current_user - before_logout! - @current_user = nil - reset_sorcery_session - after_logout!(user) - end + return unless logged_in? + + user = current_user + before_logout! + @current_user = nil + reset_sorcery_session + after_logout!(user) end def logged_in? diff --git a/lib/sorcery/controller/submodules/activity_logging.rb b/lib/sorcery/controller/submodules/activity_logging.rb index 5aaf578c..eb04cf0b 100644 --- a/lib/sorcery/controller/submodules/activity_logging.rb +++ b/lib/sorcery/controller/submodules/activity_logging.rb @@ -43,6 +43,7 @@ module InstanceMethods # This runs as a hook just after a successful login. def register_login_time_to_db(user, _credentials) return unless Config.register_login_time + user.set_last_login_at(Time.now.in_time_zone) end @@ -50,6 +51,7 @@ def register_login_time_to_db(user, _credentials) # This runs as a hook just before a logout. def register_logout_time_to_db return unless Config.register_logout_time + current_user.set_last_logout_at(Time.now.in_time_zone) end @@ -58,6 +60,7 @@ def register_logout_time_to_db def register_last_activity_time_to_db return unless Config.register_last_activity_time return unless logged_in? + current_user.set_last_activity_at(Time.now.in_time_zone) end @@ -65,6 +68,7 @@ def register_last_activity_time_to_db # This runs as a hook just after a successful login. def register_last_ip_address(_user, _credentials) return unless Config.register_last_ip_address + current_user.set_last_ip_address(request.remote_ip) end end diff --git a/lib/sorcery/controller/submodules/external.rb b/lib/sorcery/controller/submodules/external.rb index 3c78aca8..bb0b08d8 100644 --- a/lib/sorcery/controller/submodules/external.rb +++ b/lib/sorcery/controller/submodules/external.rb @@ -34,17 +34,17 @@ def external_providers=(providers) @external_providers = providers providers.each do |name| - class_eval <<-E + class_eval <<-RUBY, __FILE__, __LINE__ + 1 def self.#{name} @#{name} ||= Sorcery::Providers.const_get('#{name}'.to_s.capitalize).new end - E + RUBY end end def merge_external_defaults! @defaults.merge!(:@external_providers => [], - :@ca_file => File.join(File.expand_path(File.dirname(__FILE__)), '../../protocols/certs/ca-bundle.crt')) + :@ca_file => File.join(__dir__, '../../protocols/certs/ca-bundle.crt')) end end merge_external_defaults! @@ -57,6 +57,7 @@ module InstanceMethods # save the singleton ProviderClient instance into @provider def sorcery_get_provider(provider_name) return unless Config.external_providers.include?(provider_name.to_sym) + Config.send(provider_name.to_sym) end @@ -65,12 +66,11 @@ def sorcery_get_provider(provider_name) def sorcery_login_url(provider_name, args = {}) @provider = sorcery_get_provider provider_name sorcery_fixup_callback_url @provider - if @provider.respond_to?(:login_url) && @provider.has_callback? - @provider.state = args[:state] - return @provider.login_url(params, session) - else - return nil - end + + return nil unless @provider.respond_to?(:login_url) && @provider.has_callback? + + @provider.state = args[:state] + @provider.login_url(params, session) end # get the user hash from a provider using information from the params and session. @@ -89,6 +89,7 @@ def sorcery_fetch_user_hash(provider_name) # cache them in instance variables. @access_token ||= @provider.process_callback(params, session) # sends request to oauth agent to get the token @user_hash ||= @provider.get_user_hash(@access_token) # uses the token to send another request to the oauth agent requesting user info + nil end # for backwards compatibility @@ -99,14 +100,15 @@ def access_token(*_args) # this method should be somewhere else. It only does something once per application per provider. def sorcery_fixup_callback_url(provider) provider.original_callback_url ||= provider.callback_url - if provider.original_callback_url.present? && provider.original_callback_url[0] == '/' - uri = URI.parse(request.url.gsub(/\?.*$/, '')) - uri.path = '' - uri.query = nil - uri.scheme = 'https' if request.env['HTTP_X_FORWARDED_PROTO'] == 'https' - host = uri.to_s - provider.callback_url = "#{host}#{@provider.original_callback_url}" - end + + return unless provider.original_callback_url.present? && provider.original_callback_url[0] == '/' + + uri = URI.parse(request.url.gsub(/\?.*$/, '')) + uri.path = '' + uri.query = nil + uri.scheme = 'https' if request.env['HTTP_X_FORWARDED_PROTO'] == 'https' + host = uri.to_s + provider.callback_url = "#{host}#{@provider.original_callback_url}" end # sends user to authenticate at the provider's website. @@ -119,26 +121,26 @@ def login_at(provider_name, args = {}) def login_from(provider_name, should_remember = false) sorcery_fetch_user_hash provider_name - if user = user_class.load_from_provider(provider_name, @user_hash[:uid].to_s) - # we found the user. - # clear the session - return_to_url = session[:return_to_url] - reset_sorcery_session - session[:return_to_url] = return_to_url + return unless (user = user_class.load_from_provider(provider_name, @user_hash[:uid].to_s)) - # sign in the user - auto_login(user, should_remember) - after_login!(user) + # we found the user. + # clear the session + return_to_url = session[:return_to_url] + reset_sorcery_session + session[:return_to_url] = return_to_url - # return the user - user - end + # sign in the user + auto_login(user, should_remember) + after_login!(user) + + # return the user + user end # If user is logged, he can add all available providers into his account def add_provider_to_user(provider_name) sorcery_fetch_user_hash provider_name - config = user_class.sorcery_config + # config = user_class.sorcery_config # TODO: Unused, remove? current_user.add_provider_to_user(provider_name.to_s, @user_hash[:uid].to_s) end @@ -182,7 +184,7 @@ def create_and_validate_from(provider_name) # def create_from(provider_name, &block) sorcery_fetch_user_hash provider_name - config = user_class.sorcery_config + # config = user_class.sorcery_config # TODO: Unused, remove? attrs = user_attrs(@provider.user_info_mapping, @user_hash) @user = user_class.create_from_provider(provider_name, @user_hash[:uid], attrs, &block) @@ -191,7 +193,7 @@ def create_from(provider_name, &block) # follows the same patterns as create_from, but builds the user instead of creating def build_from(provider_name, &block) sorcery_fetch_user_hash provider_name - config = user_class.sorcery_config + # config = user_class.sorcery_config # TODO: Unused, remove? attrs = user_attrs(@provider.user_info_mapping, @user_hash) @user = user_class.build_from_provider(attrs, &block) @@ -203,7 +205,7 @@ def user_attrs(user_info_mapping, user_hash) if (varr = v.split('/')).size > 1 attribute_value = begin varr.inject(user_hash[:user_info]) { |hash, value| hash[value] } - rescue + rescue StandardError nil end attribute_value.nil? ? attrs : attrs.merge!(k => attribute_value) diff --git a/lib/sorcery/controller/submodules/http_basic_auth.rb b/lib/sorcery/controller/submodules/http_basic_auth.rb index 672615f3..56bf5346 100644 --- a/lib/sorcery/controller/submodules/http_basic_auth.rb +++ b/lib/sorcery/controller/submodules/http_basic_auth.rb @@ -57,6 +57,7 @@ def realm_name_by_controller while current_controller != ActionController::Base result = Config.controller_to_realm_map[current_controller.controller_name] return result if result + current_controller = current_controller.superclass end nil diff --git a/lib/sorcery/controller/submodules/session_timeout.rb b/lib/sorcery/controller/submodules/session_timeout.rb index 08dfd285..b0cc65b9 100644 --- a/lib/sorcery/controller/submodules/session_timeout.rb +++ b/lib/sorcery/controller/submodules/session_timeout.rb @@ -32,6 +32,7 @@ module InstanceMethods def invalidate_active_sessions! return unless Config.session_timeout_invalidate_active_sessions_enabled return unless current_user.present? + current_user.send(:invalidate_sessions_before=, Time.now.in_time_zone) current_user.save end @@ -64,6 +65,7 @@ def sorcery_session_expired?(time) def sorcery_session_invalidated? return false unless Config.session_timeout_invalidate_active_sessions_enabled return false unless current_user.present? && current_user.try(:invalidate_sessions_before).present? + time = session[:login_time] || session[:last_action_time] || Time.now.in_time_zone time < current_user.invalidate_sessions_before end diff --git a/lib/sorcery/crypto_providers/aes256.rb b/lib/sorcery/crypto_providers/aes256.rb index 616f0f92..81dd2b68 100644 --- a/lib/sorcery/crypto_providers/aes256.rb +++ b/lib/sorcery/crypto_providers/aes256.rb @@ -43,6 +43,7 @@ def decrypt(crypted) def aes raise ArgumentError, "#{name} expects a 32 bytes long key. Please use Sorcery::Model::Config.encryption_key to set it." if @key.nil? || @key == '' + @aes ||= OpenSSL::Cipher.new('AES-256-ECB') end end diff --git a/lib/sorcery/crypto_providers/bcrypt.rb b/lib/sorcery/crypto_providers/bcrypt.rb index 4c1a5655..85413990 100644 --- a/lib/sorcery/crypto_providers/bcrypt.rb +++ b/lib/sorcery/crypto_providers/bcrypt.rb @@ -60,6 +60,7 @@ def encrypt(*tokens) def matches?(hash, *tokens) hash = new_from_hash(hash) return false if hash.nil? || hash == {} + hash == join_tokens(tokens) end @@ -87,7 +88,7 @@ def join_tokens(tokens) def new_from_hash(hash) ::BCrypt::Password.new(hash) rescue ::BCrypt::Errors::InvalidHash - return nil + nil end end end diff --git a/lib/sorcery/model.rb b/lib/sorcery/model.rb index c36fb2fd..a195bdd7 100644 --- a/lib/sorcery/model.rb +++ b/lib/sorcery/model.rb @@ -47,12 +47,15 @@ def include_required_submodules! class_eval do @sorcery_config.submodules = ::Sorcery::Controller::Config.submodules @sorcery_config.submodules.each do |mod| + # TODO: Is there a cleaner way to handle missing submodules? + # rubocop:disable Lint/HandleExceptions begin include Submodules.const_get(mod.to_s.split('_').map(&:capitalize).join) rescue NameError # don't stop on a missing submodule. Needed because some submodules are only defined # in the controller side. end + # rubocop:enable Lint/HandleExceptions end end end @@ -192,9 +195,9 @@ def clear_virtual_password config = sorcery_config send(:"#{config.password_attribute_name}=", nil) - if respond_to?(:"#{config.password_attribute_name}_confirmation=") - send(:"#{config.password_attribute_name}_confirmation=", nil) - end + return unless respond_to?(:"#{config.password_attribute_name}_confirmation=") + + send(:"#{config.password_attribute_name}_confirmation=", nil) end # calls the requested email method on the configured mailer @@ -202,9 +205,9 @@ def clear_virtual_password def generic_send_email(method, mailer) config = sorcery_config mail = config.send(mailer).send(config.send(method), self) - if defined?(ActionMailer) && config.send(mailer).is_a?(Class) && config.send(mailer) < ActionMailer::Base - mail.send(config.email_delivery_method) - end + return unless defined?(ActionMailer) && config.send(mailer).is_a?(Class) && config.send(mailer) < ActionMailer::Base + + mail.send(config.email_delivery_method) end end end diff --git a/lib/sorcery/model/config.rb b/lib/sorcery/model/config.rb index 0bad9332..885c27ee 100644 --- a/lib/sorcery/model/config.rb +++ b/lib/sorcery/model/config.rb @@ -4,8 +4,6 @@ module Sorcery module Model class Config - # change default username attribute, for example, to use :email as the login. - attr_accessor :username_attribute_names # change *virtual* password attribute, the one which is used until an encrypted one is generated. attr_accessor :password_attribute_name # change default email attribute. @@ -38,6 +36,8 @@ class Config # Set token randomness attr_accessor :token_randomness + # change default username attribute, for example, to use :email as the login. See 'username_attribute_names=' below. + attr_reader :username_attribute_names # change default encryption_provider. attr_reader :encryption_provider # use an external encryption class. @@ -96,7 +96,7 @@ def encryption_algorithm=(algo) when :bcrypt then CryptoProviders::BCrypt when :custom then @custom_encryption_provider else raise ArgumentError, "Encryption algorithm supplied, #{algo}, is invalid" - end + end end private diff --git a/lib/sorcery/model/submodules/brute_force_protection.rb b/lib/sorcery/model/submodules/brute_force_protection.rb index 51950e38..18c55074 100644 --- a/lib/sorcery/model/submodules/brute_force_protection.rb +++ b/lib/sorcery/model/submodules/brute_force_protection.rb @@ -14,7 +14,6 @@ def self.included(base) :consecutive_login_retries_amount_limit, # how many failed logins allowed. :login_lock_time_period, # how long the user should be banned. # in seconds. 0 for permanent. - :unlock_token_attribute_name, # Unlock token attribute name :unlock_token_email_method_name, # Mailer method name :unlock_token_mailer_disabled, # When true, dont send unlock token via email @@ -70,9 +69,9 @@ def register_failed_login! sorcery_adapter.increment(config.failed_logins_count_attribute_name) - if send(config.failed_logins_count_attribute_name) >= config.consecutive_login_retries_amount_limit - login_lock! - end + return unless send(config.failed_logins_count_attribute_name) >= config.consecutive_login_retries_amount_limit + + login_lock! end # /!\ @@ -98,9 +97,9 @@ def login_lock! config.unlock_token_attribute_name => TemporaryToken.generate_random_token } sorcery_adapter.update_attributes(attributes) - unless config.unlock_token_mailer_disabled || config.unlock_token_mailer.nil? - send_unlock_token_email! - end + return if config.unlock_token_mailer_disabled || config.unlock_token_mailer.nil? + + send_unlock_token_email! end def login_unlocked? diff --git a/lib/sorcery/model/submodules/external.rb b/lib/sorcery/model/submodules/external.rb index 864bc3ef..7c33d8a0 100644 --- a/lib/sorcery/model/submodules/external.rb +++ b/lib/sorcery/model/submodules/external.rb @@ -40,7 +40,8 @@ module ClassMethods def load_from_provider(provider, uid) config = sorcery_config authentication = config.authentications_class.sorcery_adapter.find_by_oauth_credentials(provider, uid) - user = sorcery_adapter.find_by_id(authentication.send(config.authentications_user_id_attribute_name)) if authentication + # Return user if matching authentication found + sorcery_adapter.find_by_id(authentication.send(config.authentications_user_id_attribute_name)) if authentication end def create_and_validate_from_provider(provider, uid, attrs) diff --git a/lib/sorcery/model/submodules/magic_login.rb b/lib/sorcery/model/submodules/magic_login.rb index b1e534cc..409cbdce 100644 --- a/lib/sorcery/model/submodules/magic_login.rb +++ b/lib/sorcery/model/submodules/magic_login.rb @@ -16,24 +16,18 @@ def self.included(base) :magic_login_token_expires_at_attribute_name, # expires at attribute name. :magic_login_email_sent_at_attribute_name, # when was email sent, used for hammering # protection. - :magic_login_mailer_class, # mailer class. Needed. - :magic_login_mailer_disabled, # when true sorcery will not automatically # email magic login details and allow you to # manually handle how and when email is sent - :magic_login_email_method_name, # magic login email method on your # mailer class. - :magic_login_expiration_period, # how many seconds before the request # expires. nil for never expires. - :magic_login_time_between_emails # hammering protection, how long to wait # before allowing another email to be sent. - end - + base.sorcery_config.instance_eval do @defaults.merge!(:@magic_login_token_attribute_name => :magic_login_token, :@magic_login_token_expires_at_attribute_name => :magic_login_token_expires_at, @@ -43,19 +37,18 @@ def self.included(base) :@magic_login_email_method_name => :magic_login_email, :@magic_login_expiration_period => 15 * 60, :@magic_login_time_between_emails => 5 * 60) - + reset! end - + base.extend(ClassMethods) - + base.sorcery_config.after_config << :validate_mailer_defined base.sorcery_config.after_config << :define_magic_login_fields - + base.send(:include, InstanceMethods) - end - + module ClassMethods # Find user by token, also checks for expiration. # Returns the user if token found and is valid. @@ -64,44 +57,45 @@ def load_from_magic_login_token(token) token_expiration_date_attr = @sorcery_config.magic_login_token_expires_at_attribute_name load_from_token(token, token_attr_name, token_expiration_date_attr) end - + protected - + # This submodule requires the developer to define his own mailer class to be used by it # when magic_login_mailer_disabled is false def validate_mailer_defined - msg = "To use magic_login submodule, you must define a mailer (config.magic_login_mailer_class = YourMailerClass)." - raise ArgumentError, msg if @sorcery_config.magic_login_mailer_class.nil? and @sorcery_config.magic_login_mailer_disabled == false + msg = 'To use magic_login submodule, you must define a mailer (config.magic_login_mailer_class = YourMailerClass).' + raise ArgumentError, msg if @sorcery_config.magic_login_mailer_class.nil? && @sorcery_config.magic_login_mailer_disabled == false end - + def define_magic_login_fields sorcery_adapter.define_field sorcery_config.magic_login_token_attribute_name, String sorcery_adapter.define_field sorcery_config.magic_login_token_expires_at_attribute_name, Time sorcery_adapter.define_field sorcery_config.magic_login_email_sent_at_attribute_name, Time end - end - + module InstanceMethods # generates a reset code with expiration def generate_magic_login_token! config = sorcery_config - attributes = {config.magic_login_token_attribute_name => TemporaryToken.generate_random_token, - config.magic_login_email_sent_at_attribute_name => Time.now.in_time_zone} + attributes = { + config.magic_login_token_attribute_name => TemporaryToken.generate_random_token, + config.magic_login_email_sent_at_attribute_name => Time.now.in_time_zone + } attributes[config.magic_login_token_expires_at_attribute_name] = Time.now.in_time_zone + config.magic_login_expiration_period if config.magic_login_expiration_period - - self.sorcery_adapter.update_attributes(attributes) + + sorcery_adapter.update_attributes(attributes) end - + # generates a magic login code with expiration and sends an email to the user. def deliver_magic_login_instructions! mail = false config = sorcery_config # hammering protection return false if !config.magic_login_time_between_emails.nil? && - self.send(config.magic_login_email_sent_at_attribute_name) && - self.send(config.magic_login_email_sent_at_attribute_name) > config.magic_login_time_between_emails.seconds.ago - + send(config.magic_login_email_sent_at_attribute_name) && + send(config.magic_login_email_sent_at_attribute_name) > config.magic_login_time_between_emails.seconds.ago + self.class.sorcery_adapter.transaction do generate_magic_login_token! unless config.magic_login_mailer_disabled @@ -111,23 +105,22 @@ def deliver_magic_login_instructions! end mail end - + # Clears the token. def clear_magic_login_token! config = sorcery_config - self.sorcery_adapter.update_attributes({ - config.magic_login_token_attribute_name => nil, - config.magic_login_token_expires_at_attribute_name => nil - }) + sorcery_adapter.update_attributes( + config.magic_login_token_attribute_name => nil, + config.magic_login_token_expires_at_attribute_name => nil + ) end - + protected - + def send_magic_login_email! generic_send_email(:magic_login_email_method_name, :magic_login_mailer_class) end end - end end end diff --git a/lib/sorcery/model/submodules/reset_password.rb b/lib/sorcery/model/submodules/reset_password.rb index 1c0a5f7f..48e5f312 100644 --- a/lib/sorcery/model/submodules/reset_password.rb +++ b/lib/sorcery/model/submodules/reset_password.rb @@ -101,6 +101,7 @@ def deliver_reset_password_instructions! config = sorcery_config # hammering protection return false if config.reset_password_time_between_emails.present? && send(config.reset_password_email_sent_at_attribute_name) && send(config.reset_password_email_sent_at_attribute_name) > config.reset_password_time_between_emails.seconds.ago.utc + self.class.sorcery_adapter.transaction do generate_reset_password_token! mail = send_reset_password_email! unless config.reset_password_mailer_disabled @@ -112,7 +113,7 @@ def deliver_reset_password_instructions! # For example, access_count_to_reset_password_page attribute is over 1, which # means the user doesn't have a right to access. def increment_password_reset_page_access_counter - sorcery_adapter.increment(self.sorcery_config.reset_password_page_access_count_attribute_name) + sorcery_adapter.increment(sorcery_config.reset_password_page_access_count_attribute_name) end # Reset access_count_to_reset_password_page attribute into 0. diff --git a/lib/sorcery/protocols/oauth.rb b/lib/sorcery/protocols/oauth.rb index 448602cf..bb59d4d4 100644 --- a/lib/sorcery/protocols/oauth.rb +++ b/lib/sorcery/protocols/oauth.rb @@ -9,6 +9,7 @@ def oauth_version def get_request_token(token = nil, secret = nil) return ::OAuth::RequestToken.new(get_consumer, token, secret) if token && secret + get_consumer.get_request_token(oauth_callback: @callback_url) end diff --git a/lib/sorcery/providers/heroku.rb b/lib/sorcery/providers/heroku.rb index cd420d56..ac6427bd 100644 --- a/lib/sorcery/providers/heroku.rb +++ b/lib/sorcery/providers/heroku.rb @@ -45,6 +45,7 @@ def login_url(_params, _session) # tries to login the user from access token def process_callback(params, _session) raise 'Invalid state. Potential Cross Site Forgery' if params[:state] != state + args = {}.tap do |a| a[:code] = params[:code] if params[:code] end diff --git a/lib/sorcery/providers/instagram.rb b/lib/sorcery/providers/instagram.rb index cb6d42d1..a01e35e3 100644 --- a/lib/sorcery/providers/instagram.rb +++ b/lib/sorcery/providers/instagram.rb @@ -1,21 +1,17 @@ module Sorcery module Providers # This class adds support for OAuth with Instagram.com. - class Instagram < Base - include Protocols::Oauth2 - attr_accessor :access_permissions, :token_url, :authorization_path, :user_info_path, :scope, :user_info_fields - def initialize super - @site = 'https://api.instagram.com' + @site = 'https://api.instagram.com' @token_url = '/oauth/access_token' @authorization_path = '/oauth/authorize/' @user_info_path = '/v1/users/self' @@ -31,11 +27,10 @@ def login_url(_params, _session) authorize_url(token_url: @token_url) end - # overrides oauth2#authorize_url to allow customized scope. def authorize_url(opts = {}) @scope = access_permissions.present? ? access_permissions.join(' ') : scope - super(opts.merge(:token_url => @token_url)) + super(opts.merge(token_url: @token_url)) end # pass oauth2 param `code` provided by instgrm server @@ -43,11 +38,14 @@ def process_callback(params, _session) args = {}.tap do |a| a[:code] = params[:code] if params[:code] end - get_access_token(args, token_url: @token_url, - client_id: @key, client_secret: @secret) + get_access_token( + args, + token_url: @token_url, + client_id: @key, + client_secret: @secret + ) end - # see `user_info_mapping` in config/initializer, # given `user_info_mapping` to specify # {:db_attribute_name => 'instagram_attr_name'} @@ -58,21 +56,18 @@ def process_callback(params, _session) # testing strategy relies on querying user_info_path def get_user_hash(access_token) call_api_params = { - :access_token => access_token.token, - :client_id => access_token[:client_id] + access_token: access_token.token, + client_id: access_token[:client_id] } response = access_token.get( - "#{user_info_path}?#{call_api_params.to_param}" + "#{user_info_path}?#{call_api_params.to_param}" ) - _user_attrs = Hash.new - _user_attrs[:user_info] = JSON.parse(response.body)['data'] - _user_attrs[:uid] = _user_attrs[:user_info]['id'] - _user_attrs + user_attrs = {} + user_attrs[:user_info] = JSON.parse(response.body)['data'] + user_attrs[:uid] = user_attrs[:user_info]['id'] + user_attrs end - end - end - end diff --git a/lib/sorcery/providers/linkedin.rb b/lib/sorcery/providers/linkedin.rb index 239ad877..7404a9fe 100644 --- a/lib/sorcery/providers/linkedin.rb +++ b/lib/sorcery/providers/linkedin.rb @@ -31,7 +31,7 @@ def get_consumer def get_user_hash(access_token) # Always include id for provider uid and prevent accidental duplication via setting `user_info_field = ['id']` (needed in Sorcery 0.9.1) - info_fields = user_info_fields ? user_info_fields.reject{|n| n == 'id'} : [] + info_fields = user_info_fields ? user_info_fields.reject { |n| n == 'id' } : [] fields = info_fields.any? ? 'id,' + info_fields.join(',') : 'id' response = access_token.get("#{@user_info_path}:(#{fields})", 'x-li-format' => 'json') diff --git a/lib/sorcery/providers/vk.rb b/lib/sorcery/providers/vk.rb index 82edf6f4..ebbaf636 100644 --- a/lib/sorcery/providers/vk.rb +++ b/lib/sorcery/providers/vk.rb @@ -33,7 +33,7 @@ def get_user_hash(access_token) } response = access_token.get(user_info_url, params: params) - if user_hash[:user_info] = JSON.parse(response.body) + if (user_hash[:user_info] = JSON.parse(response.body)) user_hash[:user_info] = user_hash[:user_info]['response'][0] user_hash[:user_info]['full_name'] = [user_hash[:user_info]['first_name'], user_hash[:user_info]['last_name']].join(' ') diff --git a/lib/sorcery/providers/wechat.rb b/lib/sorcery/providers/wechat.rb index 329246d0..fb023429 100644 --- a/lib/sorcery/providers/wechat.rb +++ b/lib/sorcery/providers/wechat.rb @@ -37,10 +37,13 @@ def authorize_url(options = {}) end def get_user_hash(access_token) - response = access_token.get(user_info_path, params: { - access_token: access_token.token, - openid: access_token.params['openid'], - }) + response = access_token.get( + user_info_path, + params: { + access_token: access_token.token, + openid: access_token.params['openid'] + } + ) {}.tap do |h| h[:user_info] = JSON.parse(response.body) @@ -70,10 +73,9 @@ def process_callback(params, _session) args, token_url: token_url, mode: mode, - param_name: param_name, + param_name: param_name ) end end end end - diff --git a/lib/sorcery/test_helpers/internal.rb b/lib/sorcery/test_helpers/internal.rb index 6f603c27..1201ac2b 100644 --- a/lib/sorcery/test_helpers/internal.rb +++ b/lib/sorcery/test_helpers/internal.rb @@ -17,7 +17,7 @@ def cost # a patch to fix a bug in testing that happens when you 'destroy' a session twice. # After the first destroy, the session is an ordinary hash, and then when destroy # is called again there's an exception. - class ::Hash + class ::Hash # rubocop:disable Style/ClassAndModuleChildren def destroy clear end @@ -69,9 +69,10 @@ def update_model(&block) def reload_user_class User && Object.send(:remove_const, 'User') load 'user.rb' - if User.respond_to?(:reset_column_information) - User.reset_column_information - end + + return unless User.respond_to?(:reset_column_information) + + User.reset_column_information end end end diff --git a/lib/sorcery/test_helpers/internal/rails.rb b/lib/sorcery/test_helpers/internal/rails.rb index 28e4a45d..a9eb4365 100644 --- a/lib/sorcery/test_helpers/internal/rails.rb +++ b/lib/sorcery/test_helpers/internal/rails.rb @@ -4,11 +4,11 @@ module Internal module Rails include ::Sorcery::TestHelpers::Rails::Controller - SUBMODULES_AUTO_ADDED_CONTROLLER_FILTERS = [ - :register_last_activity_time_to_db, - :deny_banned_user, - :validate_session - ] + SUBMODULES_AUTO_ADDED_CONTROLLER_FILTERS = %i[ + register_last_activity_time_to_db + deny_banned_user + validate_session + ].freeze def sorcery_reload!(submodules = [], options = {}) reload_user_class @@ -40,11 +40,11 @@ def sorcery_reload!(submodules = [], options = {}) end end User.authenticates_with_sorcery! - if defined?(DataMapper) && User.ancestors.include?(DataMapper::Resource) - DataMapper.auto_migrate! - User.finalize - Authentication.finalize - end + return unless defined?(DataMapper) && User.ancestors.include?(DataMapper::Resource) + + DataMapper.auto_migrate! + User.finalize + Authentication.finalize end def sorcery_controller_property_set(property, value) @@ -64,7 +64,7 @@ def clear_user_without_logout end if ::Rails.version < '5.0.0' - %w(get post put).each do |method| + %w[get post put].each do |method| define_method(method) do |action, options = {}| super action, options[:params] || {}, options[:session] end diff --git a/lib/sorcery/version.rb b/lib/sorcery/version.rb index 1c8791d0..cf14d722 100644 --- a/lib/sorcery/version.rb +++ b/lib/sorcery/version.rb @@ -1,3 +1,3 @@ module Sorcery - VERSION = '0.12.0' + VERSION = '0.12.0'.freeze end diff --git a/sorcery.gemspec b/sorcery.gemspec index 4668a2a3..a62c40b0 100644 --- a/sorcery.gemspec +++ b/sorcery.gemspec @@ -1,34 +1,50 @@ -lib = File.expand_path('../lib', __FILE__) +lib = File.expand_path('lib', __dir__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'sorcery/version' +# rubocop:disable Metrics/BlockLength Gem::Specification.new do |s| s.name = 'sorcery' s.version = Sorcery::VERSION - s.authors = ['Noam Ben Ari', 'Kir Shatrov', 'Grzegorz Witek', 'Chase Gilliam'] - s.email = 'chase.gilliam@gmail.com' + s.authors = [ + 'Noam Ben Ari', + 'Kir Shatrov', + 'Grzegorz Witek', + 'Chase Gilliam', + 'Josh Buker' + ] + s.email = [ + 'chase.gilliam@gmail.com', + 'contact@joshbuker.com' + ] + + # TODO: Cleanup formatting. + # rubocop:disable Metrics/LineLength s.description = 'Provides common authentication needs such as signing in/out, activating by email and resetting password.' s.summary = 'Magical authentication for Rails applications' s.homepage = 'https://github.com/Sorcery/sorcery' 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" 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' + # rubocop:enable Metrics/LineLength s.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR) s.require_paths = ['lib'] s.licenses = ['MIT'] - s.required_ruby_version = '>= 2.2.2' + s.required_ruby_version = '>= 2.2.9' + s.add_dependency 'bcrypt', '~> 3.1' s.add_dependency 'oauth', '~> 0.4', '>= 0.4.4' s.add_dependency 'oauth2', '~> 1.0', '>= 0.8.0' - s.add_dependency 'bcrypt', '~> 3.1' - s.add_development_dependency 'yard', '~> 0.9.0', '>= 0.9.12' - s.add_development_dependency 'timecop' - s.add_development_dependency 'simplecov', '>= 0.3.8' + s.add_development_dependency 'byebug', '~> 10.0.0' s.add_development_dependency 'rspec-rails', '~> 3.7.0' + s.add_development_dependency 'rubocop' + s.add_development_dependency 'simplecov', '>= 0.3.8' s.add_development_dependency 'test-unit', '~> 3.2.0' - s.add_development_dependency 'byebug', '~> 10.0.0' + s.add_development_dependency 'timecop' s.add_development_dependency 'webmock', '~> 3.3.0' + s.add_development_dependency 'yard', '~> 0.9.0', '>= 0.9.12' end +# rubocop:enable Metrics/BlockLength diff --git a/spec/active_record/user_magic_login_spec.rb b/spec/active_record/user_magic_login_spec.rb index a561e739..d40f8bdb 100644 --- a/spec/active_record/user_magic_login_spec.rb +++ b/spec/active_record/user_magic_login_spec.rb @@ -6,10 +6,10 @@ MigrationHelper.migrate("#{Rails.root}/db/migrate/magic_login") User.reset_column_information end - + after(:all) do MigrationHelper.rollback("#{Rails.root}/db/migrate/magic_login") end - + it_behaves_like 'magic_login_model' end diff --git a/spec/controllers/controller_oauth2_spec.rb b/spec/controllers/controller_oauth2_spec.rb index 4702e6b8..b4b3d792 100644 --- a/spec/controllers/controller_oauth2_spec.rb +++ b/spec/controllers/controller_oauth2_spec.rb @@ -155,7 +155,7 @@ expect(flash[:notice]).to eq 'Success!' end - [:github, :google, :liveid, :vk, :salesforce, :paypal, :slack, :wechat, :microsoft, :instagram].each do |provider| + %i[github google liveid vk salesforce paypal slack wechat microsoft instagram].each do |provider| describe "with #{provider}" do it 'login_at redirects correctly' do get :"login_at_test_#{provider}" @@ -200,43 +200,58 @@ describe 'OAuth with User Activation features' do before(:all) do - sorcery_reload!([:user_activation,:external], :user_activation_mailer => ::SorceryMailer) - sorcery_controller_property_set(:external_providers, [:facebook, :github, :google, :liveid, :vk, :salesforce, :paypal, :slack, :wechat, :microsoft, :instagram]) + sorcery_reload!(%i[user_activation external], user_activation_mailer: ::SorceryMailer) + sorcery_controller_property_set( + :external_providers, + %i[ + facebook + github + google + liveid + vk + salesforce + paypal + slack + wechat + microsoft + instagram + ] + ) # TODO: refactor - sorcery_controller_external_property_set(:facebook, :key, "eYVNBjBDi33aa9GkA3w") - sorcery_controller_external_property_set(:facebook, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8") - sorcery_controller_external_property_set(:facebook, :callback_url, "http://blabla.com") - sorcery_controller_external_property_set(:github, :key, "eYVNBjBDi33aa9GkA3w") - sorcery_controller_external_property_set(:github, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8") - sorcery_controller_external_property_set(:github, :callback_url, "http://blabla.com") - sorcery_controller_external_property_set(:google, :key, "eYVNBjBDi33aa9GkA3w") - sorcery_controller_external_property_set(:google, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8") - sorcery_controller_external_property_set(:google, :callback_url, "http://blabla.com") - sorcery_controller_external_property_set(:liveid, :key, "eYVNBjBDi33aa9GkA3w") - sorcery_controller_external_property_set(:liveid, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8") - sorcery_controller_external_property_set(:liveid, :callback_url, "http://blabla.com") - sorcery_controller_external_property_set(:vk, :key, "eYVNBjBDi33aa9GkA3w") - sorcery_controller_external_property_set(:vk, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8") - sorcery_controller_external_property_set(:vk, :callback_url, "http://blabla.com") - sorcery_controller_external_property_set(:salesforce, :key, "eYVNBjBDi33aa9GkA3w") - sorcery_controller_external_property_set(:salesforce, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8") - sorcery_controller_external_property_set(:salesforce, :callback_url, "http://blabla.com") - sorcery_controller_external_property_set(:paypal, :key, "eYVNBjBDi33aa9GkA3w") - sorcery_controller_external_property_set(:paypal, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8") - sorcery_controller_external_property_set(:paypal, :callback_url, "http://blabla.com") - sorcery_controller_external_property_set(:slack, :key, "eYVNBjBDi33aa9GkA3w") - sorcery_controller_external_property_set(:slack, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8") - sorcery_controller_external_property_set(:slack, :callback_url, "http://blabla.com") - sorcery_controller_external_property_set(:wechat, :key, "eYVNBjBDi33aa9GkA3w") - sorcery_controller_external_property_set(:wechat, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8") - sorcery_controller_external_property_set(:wechat, :callback_url, "http://blabla.com") - sorcery_controller_external_property_set(:microsoft, :key, "eYVNBjBDi33aa9GkA3w") - sorcery_controller_external_property_set(:microsoft, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8") - sorcery_controller_external_property_set(:microsoft, :callback_url, "http://blabla.com") - sorcery_controller_external_property_set(:instagram, :key, "eYVNBjBDi33aa9GkA3w") - sorcery_controller_external_property_set(:instagram, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8") - sorcery_controller_external_property_set(:instagram, :callback_url, "http://blabla.com") + sorcery_controller_external_property_set(:facebook, :key, 'eYVNBjBDi33aa9GkA3w') + sorcery_controller_external_property_set(:facebook, :secret, 'XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8') + sorcery_controller_external_property_set(:facebook, :callback_url, 'http://blabla.com') + sorcery_controller_external_property_set(:github, :key, 'eYVNBjBDi33aa9GkA3w') + sorcery_controller_external_property_set(:github, :secret, 'XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8') + sorcery_controller_external_property_set(:github, :callback_url, 'http://blabla.com') + sorcery_controller_external_property_set(:google, :key, 'eYVNBjBDi33aa9GkA3w') + sorcery_controller_external_property_set(:google, :secret, 'XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8') + sorcery_controller_external_property_set(:google, :callback_url, 'http://blabla.com') + sorcery_controller_external_property_set(:liveid, :key, 'eYVNBjBDi33aa9GkA3w') + sorcery_controller_external_property_set(:liveid, :secret, 'XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8') + sorcery_controller_external_property_set(:liveid, :callback_url, 'http://blabla.com') + sorcery_controller_external_property_set(:vk, :key, 'eYVNBjBDi33aa9GkA3w') + sorcery_controller_external_property_set(:vk, :secret, 'XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8') + sorcery_controller_external_property_set(:vk, :callback_url, 'http://blabla.com') + sorcery_controller_external_property_set(:salesforce, :key, 'eYVNBjBDi33aa9GkA3w') + sorcery_controller_external_property_set(:salesforce, :secret, 'XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8') + sorcery_controller_external_property_set(:salesforce, :callback_url, 'http://blabla.com') + sorcery_controller_external_property_set(:paypal, :key, 'eYVNBjBDi33aa9GkA3w') + sorcery_controller_external_property_set(:paypal, :secret, 'XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8') + sorcery_controller_external_property_set(:paypal, :callback_url, 'http://blabla.com') + sorcery_controller_external_property_set(:slack, :key, 'eYVNBjBDi33aa9GkA3w') + sorcery_controller_external_property_set(:slack, :secret, 'XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8') + sorcery_controller_external_property_set(:slack, :callback_url, 'http://blabla.com') + sorcery_controller_external_property_set(:wechat, :key, 'eYVNBjBDi33aa9GkA3w') + sorcery_controller_external_property_set(:wechat, :secret, 'XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8') + sorcery_controller_external_property_set(:wechat, :callback_url, 'http://blabla.com') + sorcery_controller_external_property_set(:microsoft, :key, 'eYVNBjBDi33aa9GkA3w') + sorcery_controller_external_property_set(:microsoft, :secret, 'XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8') + sorcery_controller_external_property_set(:microsoft, :callback_url, 'http://blabla.com') + sorcery_controller_external_property_set(:instagram, :key, 'eYVNBjBDi33aa9GkA3w') + sorcery_controller_external_property_set(:instagram, :secret, 'XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8') + sorcery_controller_external_property_set(:instagram, :callback_url, 'http://blabla.com') end after(:each) do @@ -259,7 +274,7 @@ expect(ActionMailer::Base.deliveries.size).to eq old_size end - [:github, :google, :liveid, :vk, :salesforce, :paypal, :wechat, :microsoft, :instagram].each do |provider| + %i[github google liveid vk salesforce paypal wechat microsoft instagram].each do |provider| it "does not send activation email to external users (#{provider})" do old_size = ActionMailer::Base.deliveries.size create_new_external_user provider @@ -271,6 +286,7 @@ create_new_external_user provider old_size = ActionMailer::Base.deliveries.size @user.activate! + expect(ActionMailer::Base.deliveries.size).to eq old_size end end end @@ -279,10 +295,10 @@ let(:user) { double('user', id: 42) } before(:all) do - sorcery_reload!([:activity_logging, :external]) + sorcery_reload!(%i[activity_logging external]) end - %w(facebook github google liveid vk salesforce slack).each do |provider| + %w[facebook github google liveid vk salesforce slack].each do |provider| context "when #{provider}" do before(:each) do sorcery_controller_property_set(:register_login_time, true) @@ -316,12 +332,12 @@ describe 'OAuth with session timeout features' do before(:all) do - sorcery_reload!([:session_timeout, :external]) + sorcery_reload!(%i[session_timeout external]) end let(:user) { double('user', id: 42) } - %w(facebook github google liveid vk salesforce slack).each do |provider| + %w[facebook github google liveid vk salesforce slack].each do |provider| context "when #{provider}" do before(:each) do sorcery_model_property_set(:authentications_class, Authentication) @@ -359,52 +375,76 @@ def stub_all_oauth2_requests! access_token = double(OAuth2::AccessToken) allow(access_token).to receive(:token_param=) # Needed for Instagram - allow(access_token).to receive(:[]).with(:client_id){"eYVNBjBDi33aa9GkA3w"} + allow(access_token).to receive(:[]).with(:client_id) { 'eYVNBjBDi33aa9GkA3w' } response = double(OAuth2::Response) allow(response).to receive(:body) { - { - 'id' => '123', - 'user_id' => '123', # Needed for Salesforce - 'name' => 'Noam Ben Ari', - 'first_name' => 'Noam', - 'last_name' => 'Ben Ari', - 'link' => 'http://www.facebook.com/nbenari1', - 'hometown' => { 'id' => '110619208966868', 'name' => 'Haifa, Israel' }, - 'location' => { 'id' => '106906559341067', 'name' => 'Pardes Hanah, Hefa, Israel' }, - 'bio' => "I'm a new daddy, and enjoying it!", - 'gender' => 'male', - 'email' => 'nbenari@gmail.com', - 'timezone' => 2, - 'locale' => 'en_US', - 'languages' => [{ 'id' => '108405449189952', 'name' => 'Hebrew' }, { 'id' => '106059522759137', 'name' => 'English' }, { 'id' => '112624162082677', 'name' => 'Russian' }], - 'verified' => true, - 'updated_time' => '2011-02-16T20:59:38+0000', - # response for VK auth - 'response' => [ - { - 'uid' => '123', - 'first_name' => 'Noam', - 'last_name' => 'Ben Ari' - } - ], - 'user' => { - 'name' => 'Sonny Whether', - 'id' => '123', - 'email' => 'bobby@example.com' - }, - # response for wechat auth - 'unionid' => '123', - # response for instagram - 'data' => { - 'username' => 'pnmahoney', - 'bio' => 'turn WHAT down?', - 'website' => '', - 'profile_picture' => 'http://photos-d.ak.instagram.com/hphotos-ak-xpa1/10454121_417985815007395_867850883_a.jpg', - 'full_name' => 'Patrick Mahoney', - 'counts' => {'media' => 2, 'followed_by' => 100, 'follows' => 71}, - 'id'=>'123' - } - }.to_json } + { + 'id' => '123', + 'user_id' => '123', # Needed for Salesforce + 'name' => 'Noam Ben Ari', + 'first_name' => 'Noam', + 'last_name' => 'Ben Ari', + 'link' => 'http://www.facebook.com/nbenari1', + 'hometown' => { + 'id' => '110619208966868', + 'name' => 'Haifa, Israel' + }, + 'location' => { + 'id' => '106906559341067', + 'name' => 'Pardes Hanah, Hefa, Israel' + }, + 'bio' => "I'm a new daddy, and enjoying it!", + 'gender' => 'male', + 'email' => 'nbenari@gmail.com', + 'timezone' => 2, + 'locale' => 'en_US', + 'languages' => [ + { + 'id' => '108405449189952', + 'name' => 'Hebrew' + }, + { + 'id' => '106059522759137', + 'name' => 'English' + }, + { + 'id' => '112624162082677', + 'name' => 'Russian' + } + ], + 'verified' => true, + 'updated_time' => '2011-02-16T20:59:38+0000', + # response for VK auth + 'response' => [ + { + 'uid' => '123', + 'first_name' => 'Noam', + 'last_name' => 'Ben Ari' + } + ], + 'user' => { + 'name' => 'Sonny Whether', + 'id' => '123', + 'email' => 'bobby@example.com' + }, + # response for wechat auth + 'unionid' => '123', + # response for instagram + 'data' => { + 'username' => 'pnmahoney', + 'bio' => 'turn WHAT down?', + 'website' => '', + 'profile_picture' => 'http://photos-d.ak.instagram.com/hphotos-ak-xpa1/10454121_417985815007395_867850883_a.jpg', + 'full_name' => 'Patrick Mahoney', + 'counts' => { + 'media' => 2, + 'followed_by' => 100, + 'follows' => 71 + }, + 'id' => '123' + } + }.to_json + } allow(access_token).to receive(:get) { response } allow(access_token).to receive(:token) { '187041a618229fdaf16613e96e1caabc1e86e46bbfad228de41520e63fe45873684c365a14417289599f3' } # access_token params for VK auth @@ -413,40 +453,55 @@ def stub_all_oauth2_requests! end def set_external_property - sorcery_controller_property_set(:external_providers, [:facebook, :github, :google, :liveid, :vk, :salesforce, :paypal, :slack, :wechat, :microsoft, :instagram]) - sorcery_controller_external_property_set(:facebook, :key, "eYVNBjBDi33aa9GkA3w") - sorcery_controller_external_property_set(:facebook, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8") - sorcery_controller_external_property_set(:facebook, :callback_url, "http://blabla.com") - sorcery_controller_external_property_set(:github, :key, "eYVNBjBDi33aa9GkA3w") - sorcery_controller_external_property_set(:github, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8") - sorcery_controller_external_property_set(:github, :callback_url, "http://blabla.com") - sorcery_controller_external_property_set(:google, :key, "eYVNBjBDi33aa9GkA3w") - sorcery_controller_external_property_set(:google, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8") - sorcery_controller_external_property_set(:google, :callback_url, "http://blabla.com") - sorcery_controller_external_property_set(:liveid, :key, "eYVNBjBDi33aa9GkA3w") - sorcery_controller_external_property_set(:liveid, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8") - sorcery_controller_external_property_set(:liveid, :callback_url, "http://blabla.com") - sorcery_controller_external_property_set(:vk, :key, "eYVNBjBDi33aa9GkA3w") - sorcery_controller_external_property_set(:vk, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8") - sorcery_controller_external_property_set(:vk, :callback_url, "http://blabla.com") - sorcery_controller_external_property_set(:salesforce, :key, "eYVNBjBDi33aa9GkA3w") - sorcery_controller_external_property_set(:salesforce, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8") - sorcery_controller_external_property_set(:salesforce, :callback_url, "http://blabla.com") - sorcery_controller_external_property_set(:paypal, :key, "eYVNBjBDi33aa9GkA3w") - sorcery_controller_external_property_set(:paypal, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8") - sorcery_controller_external_property_set(:paypal, :callback_url, "http://blabla.com") - sorcery_controller_external_property_set(:slack, :key, "eYVNBjBDi33aa9GkA3w") - sorcery_controller_external_property_set(:slack, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8") - sorcery_controller_external_property_set(:slack, :callback_url, "http://blabla.com") - sorcery_controller_external_property_set(:wechat, :key, "eYVNBjBDi33aa9GkA3w") - sorcery_controller_external_property_set(:wechat, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8") - sorcery_controller_external_property_set(:wechat, :callback_url, "http://blabla.com") - sorcery_controller_external_property_set(:microsoft, :key, "eYVNBjBDi33aa9GkA3w") - sorcery_controller_external_property_set(:microsoft, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8") - sorcery_controller_external_property_set(:microsoft, :callback_url, "http://blabla.com") - sorcery_controller_external_property_set(:instagram, :key, "eYVNBjBDi33aa9GkA3w") - sorcery_controller_external_property_set(:instagram, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8") - sorcery_controller_external_property_set(:instagram, :callback_url, "http://blabla.com") + sorcery_controller_property_set( + :external_providers, + %i[ + facebook + github + google + liveid + vk + salesforce + paypal + slack + wechat + microsoft + instagram + ] + ) + sorcery_controller_external_property_set(:facebook, :key, 'eYVNBjBDi33aa9GkA3w') + sorcery_controller_external_property_set(:facebook, :secret, 'XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8') + sorcery_controller_external_property_set(:facebook, :callback_url, 'http://blabla.com') + sorcery_controller_external_property_set(:github, :key, 'eYVNBjBDi33aa9GkA3w') + sorcery_controller_external_property_set(:github, :secret, 'XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8') + sorcery_controller_external_property_set(:github, :callback_url, 'http://blabla.com') + sorcery_controller_external_property_set(:google, :key, 'eYVNBjBDi33aa9GkA3w') + sorcery_controller_external_property_set(:google, :secret, 'XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8') + sorcery_controller_external_property_set(:google, :callback_url, 'http://blabla.com') + sorcery_controller_external_property_set(:liveid, :key, 'eYVNBjBDi33aa9GkA3w') + sorcery_controller_external_property_set(:liveid, :secret, 'XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8') + sorcery_controller_external_property_set(:liveid, :callback_url, 'http://blabla.com') + sorcery_controller_external_property_set(:vk, :key, 'eYVNBjBDi33aa9GkA3w') + sorcery_controller_external_property_set(:vk, :secret, 'XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8') + sorcery_controller_external_property_set(:vk, :callback_url, 'http://blabla.com') + sorcery_controller_external_property_set(:salesforce, :key, 'eYVNBjBDi33aa9GkA3w') + sorcery_controller_external_property_set(:salesforce, :secret, 'XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8') + sorcery_controller_external_property_set(:salesforce, :callback_url, 'http://blabla.com') + sorcery_controller_external_property_set(:paypal, :key, 'eYVNBjBDi33aa9GkA3w') + sorcery_controller_external_property_set(:paypal, :secret, 'XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8') + sorcery_controller_external_property_set(:paypal, :callback_url, 'http://blabla.com') + sorcery_controller_external_property_set(:slack, :key, 'eYVNBjBDi33aa9GkA3w') + sorcery_controller_external_property_set(:slack, :secret, 'XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8') + sorcery_controller_external_property_set(:slack, :callback_url, 'http://blabla.com') + sorcery_controller_external_property_set(:wechat, :key, 'eYVNBjBDi33aa9GkA3w') + sorcery_controller_external_property_set(:wechat, :secret, 'XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8') + sorcery_controller_external_property_set(:wechat, :callback_url, 'http://blabla.com') + sorcery_controller_external_property_set(:microsoft, :key, 'eYVNBjBDi33aa9GkA3w') + sorcery_controller_external_property_set(:microsoft, :secret, 'XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8') + sorcery_controller_external_property_set(:microsoft, :callback_url, 'http://blabla.com') + sorcery_controller_external_property_set(:instagram, :key, 'eYVNBjBDi33aa9GkA3w') + sorcery_controller_external_property_set(:instagram, :secret, 'XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8') + sorcery_controller_external_property_set(:instagram, :callback_url, 'http://blabla.com') end def provider_url(provider) diff --git a/spec/controllers/controller_oauth_spec.rb b/spec/controllers/controller_oauth_spec.rb index 13d934d2..31086a0c 100644 --- a/spec/controllers/controller_oauth_spec.rb +++ b/spec/controllers/controller_oauth_spec.rb @@ -20,7 +20,7 @@ def stub_all_oauth_requests! 'in_reply_to_status_id_str' => nil, 'created_at' => 'Sun Mar 06 23:01:12 +0000 2011', 'contributors' => nil, 'place' => nil, 'retweeted' => false, 'in_reply_to_status_id' => nil, 'in_reply_to_user_id_str' => nil, 'coordinates' => nil, 'retweet_count' => 0, - 'id' => 44533012284706816, 'id_str' => '44533012284706816' + 'id' => 44_533_012_284_706_816, 'id_str' => '44533012284706816' }, 'show_all_inline_media' => false, 'geo_enabled' => true, 'profile_sidebar_border_color' => 'a8c7f7', 'url' => nil, 'followers_count' => 10, @@ -32,7 +32,7 @@ def stub_all_oauth_requests! 'is_translator' => false, 'contributors_enabled' => false, 'protected' => false, 'follow_request_sent' => false, 'time_zone' => 'Greenland', 'profile_text_color' => '333333', 'name' => 'Noam Ben Ari', 'friends_count' => 10, 'profile_sidebar_fill_color' => 'C0DFEC', - 'id' => 123, 'id_str' => '91434812', 'profile_background_tile' => false, 'utc_offset' => -10800 + 'id' => 123, 'id_str' => '91434812', 'profile_background_tile' => false, 'utc_offset' => -10_800 }.to_json session[:request_token] = req_token.token @@ -50,7 +50,7 @@ def stub_all_oauth_requests! before(:all) do sorcery_reload!([:external]) - sorcery_controller_property_set(:external_providers, [:twitter, :jira]) + sorcery_controller_property_set(:external_providers, %i[twitter jira]) sorcery_controller_external_property_set(:twitter, :key, 'eYVNBjBDi33aa9GkA3w') sorcery_controller_external_property_set(:twitter, :secret, 'XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8') sorcery_controller_external_property_set(:twitter, :callback_url, 'http://blabla.com') @@ -179,7 +179,7 @@ def stub_all_oauth_requests! describe SorceryController, 'OAuth with user activation features' do before(:all) do - sorcery_reload!([:activity_logging, :external]) + sorcery_reload!(%i[activity_logging external]) end context 'when twitter' do @@ -219,7 +219,7 @@ def stub_all_oauth_requests! User.reset_column_information end - sorcery_reload!([:session_timeout, :external]) + sorcery_reload!(%i[session_timeout external]) end after(:all) do diff --git a/spec/controllers/controller_remember_me_spec.rb b/spec/controllers/controller_remember_me_spec.rb index 11c331cb..5358bfcb 100644 --- a/spec/controllers/controller_remember_me_spec.rb +++ b/spec/controllers/controller_remember_me_spec.rb @@ -9,10 +9,11 @@ sorcery_reload!([:remember_me]) end - after(:each) do - session = nil - cookies = nil - end + # TODO: Unused, remove? + # after(:each) do + # session = nil + # cookies = nil + # end before(:each) do allow(user).to receive(:remember_me_token) @@ -31,16 +32,18 @@ end it 'clears cookie on forget_me!' do - cookies['remember_me_token'] == { value: 'asd54234dsfsd43534', expires: 3600 } + cookies['remember_me_token'] = { value: 'asd54234dsfsd43534', expires: 3600 } get :test_logout + pending 'Test previously broken, functionality might not be working here.' expect(cookies['remember_me_token']).to be_nil end it 'clears cookie on force_forget_me!' do - cookies['remember_me_token'] == { value: 'asd54234dsfsd43534', expires: 3600 } + cookies['remember_me_token'] = { value: 'asd54234dsfsd43534', expires: 3600 } get :test_logout_with_force_forget_me + pending 'Test previously broken, functionality might not be working here.' expect(cookies['remember_me_token']).to be_nil end diff --git a/spec/controllers/controller_session_timeout_spec.rb b/spec/controllers/controller_session_timeout_spec.rb index 2a3495ce..43e565e2 100644 --- a/spec/controllers/controller_session_timeout_spec.rb +++ b/spec/controllers/controller_session_timeout_spec.rb @@ -45,7 +45,7 @@ get :test_should_be_logged_in expect(session[:user_id]).not_to be_nil - expect(response).to be_a_success + expect(response).to be_successful end it 'does not reset the session if it was not created before invalidate_sessions_before' do @@ -56,7 +56,7 @@ get :test_should_be_logged_in expect(session[:user_id]).not_to be_nil - expect(response).to be_a_success + expect(response).to be_successful end it 'resets the session if the session was created before invalidate_sessions_before' do @@ -74,12 +74,12 @@ # precondition that the user is logged in login_user user get :test_should_be_logged_in - expect(response).to be_a_success + expect(response).to be_successful allow(user).to receive(:send) { |_method, value| allow(user).to receive(:invalidate_sessions_before) { value } } allow(user).to receive(:save) get :test_invalidate_active_session - expect(response).to be_a_success + expect(response).to be_successful get :test_should_be_logged_in expect(session[:user_id]).to be_nil @@ -91,13 +91,13 @@ # precondition that the user is logged in login_user user get :test_should_be_logged_in - expect(response).to be_a_success + expect(response).to be_successful allow(user).to receive(:send) { |_method, value| allow(user).to receive(:invalidate_sessions_before) { value } } allow(user).to receive(:save) # Call to invalidate get :test_invalidate_active_session - expect(response).to be_a_success + expect(response).to be_successful # Check that existing sessions were logged out get :test_should_be_logged_in @@ -107,12 +107,12 @@ # Check that new session is allowed to login login_user user get :test_should_be_logged_in - expect(response).to be_a_success + expect(response).to be_successful expect(session[:user_id]).not_to be_nil # Check an additional request to make sure not logged out on next request get :test_should_be_logged_in - expect(response).to be_a_success + expect(response).to be_successful expect(session[:user_id]).not_to be_nil end end @@ -157,7 +157,7 @@ end end - it "registers login time on remember_me callback" do + it 'registers login time on remember_me callback' do expect(subject).to receive(:register_login_time).with(user) subject.send(:after_remember_me!, user) diff --git a/spec/controllers/controller_spec.rb b/spec/controllers/controller_spec.rb index 9d564e9c..83e00a21 100644 --- a/spec/controllers/controller_spec.rb +++ b/spec/controllers/controller_spec.rb @@ -143,7 +143,7 @@ end it 'require_login before_action does not save the url that the user originally wanted upon all non-get http methods' do - [:post, :put, :delete].each do |m| + %i[post put delete].each do |m| send(m, :some_action) expect(session[:return_to_url]).to be_nil diff --git a/spec/providers/vk_spec.rb b/spec/providers/vk_spec.rb index 0a885a16..2a918d48 100644 --- a/spec/providers/vk_spec.rb +++ b/spec/providers/vk_spec.rb @@ -11,25 +11,27 @@ before(:all) do sorcery_reload!([:external]) sorcery_controller_property_set(:external_providers, [:vk]) - sorcery_controller_external_property_set(:vk, :key, "KEY") - sorcery_controller_external_property_set(:vk, :secret, "SECRET") + sorcery_controller_external_property_set(:vk, :key, 'KEY') + sorcery_controller_external_property_set(:vk, :secret, 'SECRET') end def stub_vk_authorize - stub_request(:post, /https\:\/\/oauth\.vk\.com\/access_token/) - .to_return( - status: 200, - body: '{"access_token":"TOKEN","expires_in":86329,"user_id":1}', - headers: {'content-type' => 'application/json'}) + stub_request(:post, %r{https\:\/\/oauth\.vk\.com\/access_token}).to_return( + status: 200, + body: '{"access_token":"TOKEN","expires_in":86329,"user_id":1}', + headers: { 'content-type' => 'application/json' } + ) end - context "getting user info hash" do - it "should provide VK API version" do + context 'getting user info hash' do + it 'should provide VK API version' do stub_vk_authorize sorcery_controller_external_property_set(:vk, :api_version, '5.71') - get_user = stub_request(:get, "https://api.vk.com/method/getProfiles?access_token=TOKEN&fields=&scope=email&uids=1&v=5.71") - .to_return(body: '{"response":[{"id":1}]}') + get_user = stub_request( + :get, + 'https://api.vk.com/method/getProfiles?access_token=TOKEN&fields=&scope=email&uids=1&v=5.71' + ).to_return(body: '{"response":[{"id":1}]}') token = provider.process_callback({ code: 'CODE' }, nil) provider.get_user_hash(token) @@ -37,5 +39,4 @@ def stub_vk_authorize expect(get_user).to have_been_requested end end - end diff --git a/spec/rails_app/app/controllers/sorcery_controller.rb b/spec/rails_app/app/controllers/sorcery_controller.rb index 938e85be..1fdf93a6 100644 --- a/spec/rails_app/app/controllers/sorcery_controller.rb +++ b/spec/rails_app/app/controllers/sorcery_controller.rb @@ -4,7 +4,12 @@ class SorceryController < ActionController::Base protect_from_forgery before_action :require_login_from_http_basic, only: [:test_http_basic_auth] - before_action :require_login, only: [:test_logout, :test_logout_with_force_forget_me, :test_should_be_logged_in, :some_action] + before_action :require_login, only: %i[ + test_logout + test_logout_with_force_forget_me + test_should_be_logged_in + some_action + ] def index; end @@ -146,7 +151,7 @@ def login_at_test_instagram end def test_login_from_twitter - if @user = login_from(:twitter) + if (@user = login_from(:twitter)) redirect_to 'bla', notice: 'Success!' else redirect_to 'blu', alert: 'Failed!' @@ -156,7 +161,7 @@ def test_login_from_twitter alias test_login_from test_login_from_twitter def test_login_from_facebook - if @user = login_from(:facebook) + if (@user = login_from(:facebook)) redirect_to 'bla', notice: 'Success!' else redirect_to 'blu', alert: 'Failed!' @@ -164,7 +169,7 @@ def test_login_from_facebook end def test_login_from_github - if @user = login_from(:github) + if (@user = login_from(:github)) redirect_to 'bla', notice: 'Success!' else redirect_to 'blu', alert: 'Failed!' @@ -172,7 +177,7 @@ def test_login_from_github end def test_login_from_paypal - if @user = login_from(:paypal) + if (@user = login_from(:paypal)) redirect_to 'bla', notice: 'Success!' else redirect_to 'blu', alert: 'Failed!' @@ -180,7 +185,7 @@ def test_login_from_paypal end def test_login_from_wechat - if @user = login_from(:wechat) + if (@user = login_from(:wechat)) redirect_to 'bla', notice: 'Success!' else redirect_to 'blu', alert: 'Failed!' @@ -188,7 +193,7 @@ def test_login_from_wechat end def test_login_from_microsoft - if @user = login_from(:microsoft) + if (@user = login_from(:microsoft)) redirect_to 'bla', notice: 'Success!' else redirect_to 'blu', alert: 'Failed!' @@ -196,7 +201,7 @@ def test_login_from_microsoft end def test_login_from_google - if @user = login_from(:google) + if (@user = login_from(:google)) redirect_to 'bla', notice: 'Success!' else redirect_to 'blu', alert: 'Failed!' @@ -204,7 +209,7 @@ def test_login_from_google end def test_login_from_liveid - if @user = login_from(:liveid) + if (@user = login_from(:liveid)) redirect_to 'bla', notice: 'Success!' else redirect_to 'blu', alert: 'Failed!' @@ -212,7 +217,7 @@ def test_login_from_liveid end def test_login_from_vk - if @user = login_from(:vk) + if (@user = login_from(:vk)) redirect_to 'bla', notice: 'Success!' else redirect_to 'blu', alert: 'Failed!' @@ -220,7 +225,7 @@ def test_login_from_vk end def test_login_from_jira - if @user = login_from(:jira) + if (@user = login_from(:jira)) redirect_to 'bla', notice: 'Success!' else redirect_to 'blu', alert: 'Failed!' @@ -228,7 +233,7 @@ def test_login_from_jira end def test_login_from_salesforce - if @user = login_from(:salesforce) + if (@user = login_from(:salesforce)) redirect_to 'bla', notice: 'Success!' else redirect_to 'blu', alert: 'Failed!' @@ -236,7 +241,7 @@ def test_login_from_salesforce end def test_login_from_slack - if @user = login_from(:slack) + if (@user = login_from(:slack)) redirect_to 'bla', notice: 'Success!' else redirect_to 'blu', alert: 'Failed!' @@ -244,7 +249,7 @@ def test_login_from_slack end def test_login_from_instagram - if @user = login_from(:instagram) + if (@user = login_from(:instagram)) redirect_to 'bla', notice: 'Success!' else redirect_to 'blu', alert: 'Failed!' @@ -252,7 +257,7 @@ def test_login_from_instagram end def test_return_to_with_external_twitter - if @user = login_from(:twitter) + if (@user = login_from(:twitter)) redirect_back_or_to 'bla', notice: 'Success!' else redirect_to 'blu', alert: 'Failed!' @@ -260,7 +265,7 @@ def test_return_to_with_external_twitter end def test_return_to_with_external_jira - if @user = login_from(:jira) + if (@user = login_from(:jira)) redirect_back_or_to 'bla', notice: 'Success!' else redirect_to 'blu', alert: 'Failed!' @@ -270,7 +275,7 @@ def test_return_to_with_external_jira alias test_return_to_with_external test_return_to_with_external_twitter def test_return_to_with_external_facebook - if @user = login_from(:facebook) + if (@user = login_from(:facebook)) redirect_back_or_to 'bla', notice: 'Success!' else redirect_to 'blu', alert: 'Failed!' @@ -278,7 +283,7 @@ def test_return_to_with_external_facebook end def test_return_to_with_external_github - if @user = login_from(:github) + if (@user = login_from(:github)) redirect_back_or_to 'bla', notice: 'Success!' else redirect_to 'blu', alert: 'Failed!' @@ -286,7 +291,7 @@ def test_return_to_with_external_github end def test_return_to_with_external_paypal - if @user = login_from(:paypal) + if (@user = login_from(:paypal)) redirect_back_or_to 'bla', notice: 'Success!' else redirect_to 'blu', alert: 'Failed!' @@ -294,7 +299,7 @@ def test_return_to_with_external_paypal end def test_return_to_with_external_wechat - if @user = login_from(:wechat) + if (@user = login_from(:wechat)) redirect_back_or_to 'bla', notice: 'Success!' else redirect_to 'blu', alert: 'Failed!' @@ -302,7 +307,7 @@ def test_return_to_with_external_wechat end def test_return_to_with_external_microsoft - if @user = login_from(:microsoft) + if (@user = login_from(:microsoft)) redirect_back_or_to 'bla', notice: 'Success!' else redirect_to 'blu', alert: 'Failed!' @@ -310,7 +315,7 @@ def test_return_to_with_external_microsoft end def test_return_to_with_external_google - if @user = login_from(:google) + if (@user = login_from(:google)) redirect_back_or_to 'bla', notice: 'Success!' else redirect_to 'blu', alert: 'Failed!' @@ -318,7 +323,7 @@ def test_return_to_with_external_google end def test_return_to_with_external_liveid - if @user = login_from(:liveid) + if (@user = login_from(:liveid)) redirect_back_or_to 'bla', notice: 'Success!' else redirect_to 'blu', alert: 'Failed!' @@ -326,7 +331,7 @@ def test_return_to_with_external_liveid end def test_return_to_with_external_vk - if @user = login_from(:vk) + if (@user = login_from(:vk)) redirect_back_or_to 'bla', notice: 'Success!' else redirect_to 'blu', alert: 'Failed!' @@ -334,7 +339,7 @@ def test_return_to_with_external_vk end def test_return_to_with_external_salesforce - if @user = login_from(:salesforce) + if (@user = login_from(:salesforce)) redirect_back_or_to 'bla', notice: 'Success!' else redirect_to 'blu', alert: 'Failed!' @@ -342,7 +347,7 @@ def test_return_to_with_external_salesforce end def test_return_to_with_external_slack - if @user = login_from(:slack) + if (@user = login_from(:slack)) redirect_back_or_to 'bla', notice: 'Success!' else redirect_to 'blu', alert: 'Failed!' @@ -350,7 +355,7 @@ def test_return_to_with_external_slack end def test_return_to_with_external_instagram - if @user = login_from(:instagram) + if (@user = login_from(:instagram)) redirect_back_or_to 'bla', notice: 'Success!' else redirect_to 'blu', alert: 'Failed!' @@ -360,7 +365,7 @@ def test_return_to_with_external_instagram def test_create_from_provider provider = params[:provider] login_from(provider) - if @user = create_from(provider) + if (@user = create_from(provider)) redirect_to 'bla', notice: 'Success!' else redirect_to 'blu', alert: 'Failed!' @@ -369,12 +374,13 @@ def test_create_from_provider def test_add_second_provider provider = params[:provider] - if logged_in? - if @user = add_provider_to_user(provider) - redirect_to 'bla', notice: 'Success!' - else - redirect_to 'blu', alert: 'Failed!' - end + + return unless logged_in? + + if (@user = add_provider_to_user(provider)) + redirect_to 'bla', notice: 'Success!' + else + redirect_to 'blu', alert: 'Failed!' end end diff --git a/spec/rails_app/app/mailers/sorcery_mailer.rb b/spec/rails_app/app/mailers/sorcery_mailer.rb index bf68d59e..88ca918f 100644 --- a/spec/rails_app/app/mailers/sorcery_mailer.rb +++ b/spec/rails_app/app/mailers/sorcery_mailer.rb @@ -28,7 +28,7 @@ def send_unlock_token_email(user) mail(to: user.email, subject: 'Your account has been locked due to many wrong logins') end - + def magic_login_email(user) @user = user @url = 'http://example.com/login' diff --git a/spec/rails_app/config/application.rb b/spec/rails_app/config/application.rb index 9d4f3dbd..0eeec0db 100644 --- a/spec/rails_app/config/application.rb +++ b/spec/rails_app/config/application.rb @@ -1,4 +1,4 @@ -require File.expand_path('../boot', __FILE__) +require File.expand_path('boot', __dir__) require 'action_controller/railtie' require 'action_mailer/railtie' @@ -6,16 +6,19 @@ Bundler.require :default, SORCERY_ORM +# rubocop:disable Lint/HandleExceptions begin require "#{SORCERY_ORM}/railtie" rescue LoadError + # TODO: Log this issue or change require scheme. end +# rubocop:enable Lint/HandleExceptions require 'sorcery' module AppRoot class Application < Rails::Application - config.autoload_paths.reject! { |p| p =~ /\/app\/(\w+)$/ && !%w(controllers helpers mailers views).include?(Regexp.last_match(1)) } + config.autoload_paths.reject! { |p| p =~ %r{/\/app\/(\w+)$/} && !%w[controllers helpers mailers views].include?(Regexp.last_match(1)) } config.autoload_paths += ["#{config.root}/app/#{SORCERY_ORM}"] # Settings in config/environments/* take precedence over those specified here. diff --git a/spec/rails_app/config/boot.rb b/spec/rails_app/config/boot.rb index eaa6ee87..e06e0ebe 100644 --- a/spec/rails_app/config/boot.rb +++ b/spec/rails_app/config/boot.rb @@ -1,4 +1,4 @@ # Set up gems listed in the Gemfile. -ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__) +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../Gemfile', __dir__) require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE']) diff --git a/spec/rails_app/config/environment.rb b/spec/rails_app/config/environment.rb index 98a94c6d..37ea24a9 100644 --- a/spec/rails_app/config/environment.rb +++ b/spec/rails_app/config/environment.rb @@ -1,5 +1,5 @@ # Load the rails application -require File.expand_path('../application', __FILE__) +require File.expand_path('application', __dir__) # Initialize the rails application AppRoot::Application.initialize! diff --git a/spec/rails_app/db/migrate/activity_logging/20101224223624_add_activity_logging_to_users.rb b/spec/rails_app/db/migrate/activity_logging/20101224223624_add_activity_logging_to_users.rb index 52c0d9e9..ad96e090 100644 --- a/spec/rails_app/db/migrate/activity_logging/20101224223624_add_activity_logging_to_users.rb +++ b/spec/rails_app/db/migrate/activity_logging/20101224223624_add_activity_logging_to_users.rb @@ -5,11 +5,11 @@ def self.up add_column :users, :last_activity_at, :datetime, default: nil add_column :users, :last_login_from_ip_address, :string, default: nil - add_index :users, [:last_logout_at, :last_activity_at] + add_index :users, %i[last_logout_at last_activity_at] end def self.down - remove_index :users, [:last_logout_at, :last_activity_at] + remove_index :users, %i[last_logout_at last_activity_at] remove_column :users, :last_activity_at remove_column :users, :last_logout_at diff --git a/spec/rails_app/db/migrate/magic_login/20170924151831_add_magic_login_to_users.rb b/spec/rails_app/db/migrate/magic_login/20170924151831_add_magic_login_to_users.rb index 33196a6c..446d21fe 100644 --- a/spec/rails_app/db/migrate/magic_login/20170924151831_add_magic_login_to_users.rb +++ b/spec/rails_app/db/migrate/magic_login/20170924151831_add_magic_login_to_users.rb @@ -3,13 +3,13 @@ def self.up add_column :users, :magic_login_token, :string, default: nil add_column :users, :magic_login_token_expires_at, :datetime, default: nil add_column :users, :magic_login_email_sent_at, :datetime, default: nil - + add_index :users, :magic_login_token end - + def self.down remove_index :users, :magic_login_token - + remove_column :users, :magic_login_token remove_column :users, :magic_login_token_expires_at remove_column :users, :magic_login_email_sent_at diff --git a/spec/rails_app/db/schema.rb b/spec/rails_app/db/schema.rb index 7c319ca8..ebc42033 100644 --- a/spec/rails_app/db/schema.rb +++ b/spec/rails_app/db/schema.rb @@ -10,14 +10,12 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20101224223620) do - - create_table "users", :force => true do |t| - t.string "username" - t.string "email" - t.string "crypted_password" - t.datetime "created_at" - t.datetime "updated_at" +ActiveRecord::Schema.define(version: 20_101_224_223_620) do + create_table 'users', force: true do |t| + t.string 'username' + t.string 'email' + t.string 'crypted_password' + t.datetime 'created_at' + t.datetime 'updated_at' end - end diff --git a/spec/shared_examples/user_magic_login_shared_examples.rb b/spec/shared_examples/user_magic_login_shared_examples.rb index 758a2526..7a75c0fd 100644 --- a/spec/shared_examples/user_magic_login_shared_examples.rb +++ b/spec/shared_examples/user_magic_login_shared_examples.rb @@ -1,145 +1,145 @@ -shared_examples_for "magic_login_model" do - let(:user) {create_new_user} +shared_examples_for 'magic_login_model' do + let(:user) { create_new_user } before(:each) do User.sorcery_adapter.delete_all end - + context 'loaded plugin configuration' do - let(:config) {User.sorcery_config} - + let(:config) { User.sorcery_config } + before(:all) do sorcery_reload!([:magic_login]) end - + after(:each) do User.sorcery_config.reset! end - - describe "enables configuration options" do + + describe 'enables configuration options' do it do sorcery_model_property_set(:magic_login_token_attribute_name, :test_magic_login_token) expect(config.magic_login_token_attribute_name).to eq :test_magic_login_token end - + it do sorcery_model_property_set(:magic_login_token_expires_at_attribute_name, :test_magic_login_token_expires_at) expect(config.magic_login_token_expires_at_attribute_name).to eq :test_magic_login_token_expires_at end - + it do sorcery_model_property_set(:magic_login_email_sent_at_attribute_name, :test_magic_login_email_sent_at) expect(config.magic_login_email_sent_at_attribute_name).to eq :test_magic_login_email_sent_at end - + it do TestMailerClass = Class.new # need a mailer class to test sorcery_model_property_set(:magic_login_mailer_class, TestMailerClass) expect(config.magic_login_mailer_class).to eq TestMailerClass end - + it do sorcery_model_property_set(:magic_login_mailer_disabled, false) expect(config.magic_login_mailer_disabled).to eq false end - + it do sorcery_model_property_set(:magic_login_email_method_name, :test_magic_login_email) expect(config.magic_login_email_method_name).to eq :test_magic_login_email end - + it do - sorcery_model_property_set(:magic_login_expiration_period, 100000000) - expect(config.magic_login_expiration_period).to eq 100000000 + sorcery_model_property_set(:magic_login_expiration_period, 100_000_000) + expect(config.magic_login_expiration_period).to eq 100_000_000 end - + it do - sorcery_model_property_set(:magic_login_time_between_emails, 100000000) - expect(config.magic_login_time_between_emails).to eq 100000000 + sorcery_model_property_set(:magic_login_time_between_emails, 100_000_000) + expect(config.magic_login_time_between_emails).to eq 100_000_000 end end - describe "#generate_magic_login_token!" do - context "magic_login_token is nil" do + describe '#generate_magic_login_token!' do + context 'magic_login_token is nil' do it "magic_login_token_expires_at and magic_login_email_sent_at aren't nil " do user.generate_magic_login_token! expect(user.magic_login_token_expires_at).not_to be_nil expect(user.magic_login_email_sent_at).not_to be_nil end - - it "magic_login_token is different from the one before" do + + it 'magic_login_token is different from the one before' do token_before = user.magic_login_token user.generate_magic_login_token! expect(user.magic_login_token).not_to eq token_before end end - - context "magic_login_token is not nil" do - it "changes `user.magic_login_token`" do + + context 'magic_login_token is not nil' do + it 'changes `user.magic_login_token`' do token_before = user.magic_login_token user.generate_magic_login_token! expect(user.magic_login_token).not_to eq token_before end end end - - describe "#deliver_magic_login_instructions!" do - context "success" do + + describe '#deliver_magic_login_instructions!' do + context 'success' do before do - sorcery_model_property_set(:magic_login_time_between_emails, 30*60) + sorcery_model_property_set(:magic_login_time_between_emails, 30 * 60) sorcery_model_property_set(:magic_login_mailer_disabled, false) Timecop.travel(10.days.ago) do user.send(:"#{config.magic_login_email_sent_at_attribute_name}=", DateTime.now) end sorcery_model_property_set(:magic_login_mailer_class, ::SorceryMailer) end - + it do user.deliver_magic_login_instructions! expect(ActionMailer::Base.deliveries.size).to eq 1 end - + it do expect(user.deliver_magic_login_instructions!).to eq true end end - context "failure" do - context "magic_login_time_between_emails is nil" do - it "returns false" do + context 'failure' do + context 'magic_login_time_between_emails is nil' do + it 'returns false' do sorcery_model_property_set(:magic_login_time_between_emails, nil) expect(user.deliver_magic_login_instructions!).to eq false end end - - context "magic_login_email_sent_at is nil" do - it "returns false" do + + context 'magic_login_email_sent_at is nil' do + it 'returns false' do user.send(:"#{config.magic_login_email_sent_at_attribute_name}=", nil) expect(user.deliver_magic_login_instructions!).to eq false end end - - context "now is before magic_login_email_sent_at plus the interval" do - it "returns false" do + + context 'now is before magic_login_email_sent_at plus the interval' do + it 'returns false' do user.send(:"#{config.magic_login_email_sent_at_attribute_name}=", DateTime.now) - sorcery_model_property_set(:magic_login_time_between_emails, 30*60) + sorcery_model_property_set(:magic_login_time_between_emails, 30 * 60) expect(user.deliver_magic_login_instructions!).to eq false end end - - context "magic_login_mailer_disabled is true" do - it "returns false" do + + context 'magic_login_mailer_disabled is true' do + it 'returns false' do sorcery_model_property_set(:magic_login_mailer_disabled, true) expect(user.deliver_magic_login_instructions!).to eq false end end end end - - describe "#clear_magic_login_token!" do - it "makes magic_login_token_attribute_name and magic_login_token_expires_at_attribute_name nil" do - user.magic_login_token = "test_token" + + describe '#clear_magic_login_token!' do + it 'makes magic_login_token_attribute_name and magic_login_token_expires_at_attribute_name nil' do + user.magic_login_token = 'test_token' user.magic_login_token_expires_at = Time.now - + user.clear_magic_login_token! expect(user.magic_login_token).to eq nil diff --git a/spec/shared_examples/user_oauth_shared_examples.rb b/spec/shared_examples/user_oauth_shared_examples.rb index f06bbab8..3e6ec302 100644 --- a/spec/shared_examples/user_oauth_shared_examples.rb +++ b/spec/shared_examples/user_oauth_shared_examples.rb @@ -27,7 +27,7 @@ it "'load_from_provider' returns nil if user doesn't exist" do external_user - expect(User.load_from_provider(:twitter, 980342)).to be_nil + expect(User.load_from_provider(:twitter, 980_342)).to be_nil end end end diff --git a/spec/shared_examples/user_remember_me_shared_examples.rb b/spec/shared_examples/user_remember_me_shared_examples.rb index e7448d31..b31c4372 100644 --- a/spec/shared_examples/user_remember_me_shared_examples.rb +++ b/spec/shared_examples/user_remember_me_shared_examples.rb @@ -42,7 +42,7 @@ user.remember_me! end - expect(user.remember_me_token_expires_at.utc.to_s).to eq (ts + 2 * 60 * 60 * 24).utc.to_s + expect(user.remember_me_token_expires_at.utc.to_s).to eq((ts + 2 * 60 * 60 * 24).utc.to_s) end context 'when not persisting globally' do diff --git a/spec/shared_examples/user_reset_password_shared_examples.rb b/spec/shared_examples/user_reset_password_shared_examples.rb index c5a7af8f..be117034 100644 --- a/spec/shared_examples/user_reset_password_shared_examples.rb +++ b/spec/shared_examples/user_reset_password_shared_examples.rb @@ -245,7 +245,7 @@ end it 'does not send an email if time between emails has not passed since last email' do - sorcery_model_property_set(:reset_password_time_between_emails, 10000) + sorcery_model_property_set(:reset_password_time_between_emails, 10_000) old_size = ActionMailer::Base.deliveries.size user.deliver_reset_password_instructions! @@ -289,7 +289,7 @@ end it 'does not send an email if time between emails has not passed since last email' do - sorcery_model_property_set(:reset_password_time_between_emails, 10000) + sorcery_model_property_set(:reset_password_time_between_emails, 10_000) old_size = ActionMailer::Base.deliveries.size user.deliver_reset_password_instructions! @@ -326,7 +326,7 @@ end it 'returns false if time between emails has not passed since last email' do - sorcery_model_property_set(:reset_password_time_between_emails, 10000) + sorcery_model_property_set(:reset_password_time_between_emails, 10_000) user.deliver_reset_password_instructions! expect(user.deliver_reset_password_instructions!).to be false diff --git a/spec/shared_examples/user_shared_examples.rb b/spec/shared_examples/user_shared_examples.rb index e5d8e735..89e69f6f 100644 --- a/spec/shared_examples/user_shared_examples.rb +++ b/spec/shared_examples/user_shared_examples.rb @@ -228,10 +228,13 @@ class Admin2 < User; end expect(user).to receive(:save) { raise RuntimeError } + # rubocop:disable Lint/HandleExceptions begin user.save - rescue + rescue RuntimeError + # Intentionally force exception during save end + # rubocop:enable Lint/HandleExceptions expect(user.password).not_to be_nil end @@ -323,9 +326,11 @@ class Admin2 < User; end it 'use deliver_later' do sorcery_reload!( - [ - :user_activation, :user_activation_mailer, - :activation_needed_email_method_name, :email_delivery_method + %i[ + user_activation + user_activation_mailer + activation_needed_email_method_name + email_delivery_method ], user_activation_mailer: SorceryMailer, activation_needed_email_method_name: nil, @@ -340,9 +345,10 @@ class Admin2 < User; end it 'use deliver_now if rails version 4.2+' do allow(Rails).to receive(:version).and_return('4.2.0') sorcery_reload!( - [ - :user_activation, :user_activation_mailer, - :activation_needed_email_method_name + %i[ + user_activation + user_activation_mailer + activation_needed_email_method_name ], user_activation_mailer: SorceryMailer, activation_needed_email_method_name: nil @@ -355,9 +361,10 @@ class Admin2 < User; end it 'use deliver if rails version < 4.2' do allow(Rails).to receive(:version).and_return('4.1.0') sorcery_reload!( - [ - :user_activation, :user_activation_mailer, - :activation_needed_email_method_name + %i[ + user_activation + user_activation_mailer + activation_needed_email_method_name ], user_activation_mailer: SorceryMailer, activation_needed_email_method_name: nil @@ -503,7 +510,7 @@ def self.matches?(crypted, *tokens) end it 'find_by_username works as expected with multiple username attributes' do - sorcery_model_property_set(:username_attribute_names, [:username, :email]) + sorcery_model_property_set(:username_attribute_names, %i[username email]) expect(User.sorcery_adapter.find_by_username('gizmo')).to eq user end @@ -573,21 +580,21 @@ def self.matches?(crypted, *tokens) it 'does not create user when block return false' do expect do User.create_from_provider('facebook', '123', username: 'Noam Ben Ari') { false } - end.not_to change { User.count } + end.not_to(change { User.count }) end end end describe 'activation' do before(:each) do - sorcery_reload!([:user_activation, :external], user_activation_mailer: ::SorceryMailer) + sorcery_reload!(%i[user_activation external], user_activation_mailer: ::SorceryMailer) end after(:each) do User.sorcery_adapter.delete_all end - [:facebook, :github, :google, :liveid, :slack].each do |provider| + %i[facebook github google liveid slack].each do |provider| it 'does not send activation email to external users' do old_size = ActionMailer::Base.deliveries.size create_new_external_user(provider) diff --git a/spec/sorcery_crypto_providers_spec.rb b/spec/sorcery_crypto_providers_spec.rb index 604018fb..44610515 100644 --- a/spec/sorcery_crypto_providers_spec.rb +++ b/spec/sorcery_crypto_providers_spec.rb @@ -53,7 +53,7 @@ it 'matches password encrypted using salt and join token from upstream' do Sorcery::CryptoProviders::SHA1.join_token = 'test' - expect(Sorcery::CryptoProviders::SHA1.encrypt(%w(password gq18WBnJYNh2arkC1kgH))).to eq '894b5bf1643b8d0e1b2eaddb22426be7036dab70' + expect(Sorcery::CryptoProviders::SHA1.encrypt(%w[password gq18WBnJYNh2arkC1kgH])).to eq '894b5bf1643b8d0e1b2eaddb22426be7036dab70' end end diff --git a/spec/spec.opts b/spec/spec.opts index b3eb8b49..16f9cdb0 100644 --- a/spec/spec.opts +++ b/spec/spec.opts @@ -1,2 +1,2 @@ --color ---format documentation \ No newline at end of file +--format documentation diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 6c033504..bc5c48aa 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -40,7 +40,7 @@ class TestMailer < ActionMailer::Base; end if begin Module.const_defined?('::Rails::Controller::Testing') - rescue + rescue StandardError false end config.include ::Rails::Controller::Testing::TestProcess, type: :controller