diff --git a/.codeclimate.yml b/.codeclimate.yml index fb8b35669b..84be589cd9 100644 --- a/.codeclimate.yml +++ b/.codeclimate.yml @@ -35,7 +35,6 @@ exclude_patterns: - "app/javascript" - "assets/bundles/*.js" - "bin/webpack*" - - "lib/action_dispatch/rails5_ssl.rb" - "lib/developer_portal/app/assets/stylesheets/**/*" - "lib/developer_portal/app/views/developer_portal/css/*" - "lib/developer_portal/app/views/developer_portal/javascripts/*" diff --git a/Gemfile b/Gemfile index e2280d58fd..e635a7f586 100644 --- a/Gemfile +++ b/Gemfile @@ -12,8 +12,7 @@ gem 'aws-sdk-rails', '~> 3' gem 'aws-sdk-s3', '~> 1' gem 'dotenv-rails', '~> 2.7' -gem 'rails', '~> 5.2.8' -gem 'globalid', '~> 1.0.1' # remove line after we stop supporting Ruby 2.4 +gem 'rails', '~> 6.0' # Locking mail to 2.7.x, as 2.8 has a regression related to `enable_starttls_auto` setting: # https://github.com/mikel/mail/blob/2-8-stable/CHANGELOG.rdoc#version-281-unreleased- @@ -33,10 +32,10 @@ gem 'strong_migrations', '~> 0.6.8' group :assets do gem 'coffee-rails', '~> 5.0' gem 'non-stupid-digest-assets', '~> 1.0' - gem 'sprockets-rails', '3.2.2' # remove version after we stop supporting Ruby 2.4 + gem 'sprockets-rails' end -gem 'sass-rails', '~> 5.0' +gem 'sass-rails', '~> 5.0.8' gem 'bcrypt', '~> 3.1.7' gem 'oauth2', '~> 1.4' @@ -77,7 +76,6 @@ gem 'formtastic', '~> 4.0' gem 'htmlentities', '~>4.3', '>= 4.3.4' # TODO: Not actively maintained https://github.com/activeadmin/inherited_resources#notice replace with respond_with and fix things the rails way gem 'inherited_resources', '~> 1.12.0' -gem 'has_scope', '~> 0.7.2' # remove line after we stop supporting Ruby 2.4 gem 'json', '~> 2.3.0' gem 'mysql2', '~> 0.5.3' @@ -85,7 +83,7 @@ gem 'mysql2', '~> 0.5.3' gem '3scale_client', '~> 2.11', require: false gem 'analytics-ruby', require: false -gem 'dalli', '~> 2.7' # remove version once we stop supporting ruby 2.4 +gem 'dalli' gem 'faraday', '~> 0.15.3' gem 'faraday_middleware', '~> 0.13.1' gem 'mimemagic', '~> 0.3.10' @@ -95,8 +93,7 @@ gem 'redlock' gem 'acts-as-taggable-on', '~> 8.0' gem 'baby_squeel', '~> 1.4.3' -gem 'ransack', '2.4.1' # we can remove line when stop using ruby 2.4 -gem 'browser', '~> 5.0.0' # we can update to lts when we stop using ruby 2.4 +gem 'browser' gem 'diff-lcs', '~> 1.2' gem 'hiredis', '~> 0.6.3' gem 'httpclient', github: '3scale/httpclient', branch: 'ssl-env-cert' @@ -149,7 +146,7 @@ gem 'compass-rails', '~> 3.0.2' gem 'after_commit_queue', '~> 1.1.0' gem 'state_machines', '~> 0.5.0' -gem 'state_machines-activerecord', '~> 0.5.0' +gem 'state_machines-activerecord', '~> 0.8' # for liquid docs on-fly generation gem 'commonmarker', '~> 0.23.9' @@ -161,7 +158,7 @@ gem 'html-pipeline' gem 'ruby-openid' gem 'slim-rails', '~> 3.2' -gem 'draper', '~> 3.0' +gem 'draper', '~> 3.1' group :development do gem 'listen' @@ -188,7 +185,7 @@ group :test do # To remove once migrated all functional tests gem 'codecov', :require => false gem 'rack-no_animations', '~> 1.0.3' - gem 'rails-controller-testing' + gem 'rails-controller-testing', '~> 1.0.4' gem 'simplecov', '~> 0.21.2', require: false gem 'capybara', '~>3.35.3', source: 'https://rubygems.org' @@ -198,7 +195,7 @@ group :test do gem 'cucumber', '~> 7.0' gem 'cucumber-rails', '~> 2.4.0', require: false gem 'email_spec', require: false - gem 'fakefs', '~>0.18.0', require: 'fakefs/safe' + gem 'fakefs', require: 'fakefs/safe' gem 'launchy' gem 'mechanize' gem 'selenium-webdriver', '~> 3.142', require: false @@ -239,7 +236,7 @@ group :test do end group :development, :test do - gem 'bootsnap', '~> 1.4' + gem 'bootsnap', '~> 1.16' gem 'bullet', '~> 6.1.5' gem 'colorize' gem 'factory_bot_rails', '~> 6.2' @@ -265,11 +262,10 @@ gem 'unicorn', require: false, group: %i[production] # NOTE: Use ENV['DB'] only to install oracle dependencies group :oracle do oracle = -> { (ENV['ORACLE'] == '1') || ENV.fetch('DATABASE_URL', ENV['DB'])&.start_with?('oracle') } - gem 'activerecord-oracle_enhanced-adapter', '~> 5.2.0', install_if: oracle + gem 'activerecord-oracle_enhanced-adapter', '~> 6.0', install_if: oracle gem 'ruby-oci8', require: false, install_if: oracle end gem 'kubeclient' -gem 'jsonpath', '1.0.5' # remove line after we stop supporting ruby 2.4 gem 'pg', '~> 0.21.0' diff --git a/Gemfile.lock b/Gemfile.lock index 6ab5cae3db..c689cf9292 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -81,59 +81,73 @@ GEM activesupport (>= 3.2.19) Ascii85 (1.1.0) RedCloth (4.3.2) - actioncable (5.2.8.1) - actionpack (= 5.2.8.1) + actioncable (6.0.6.1) + actionpack (= 6.0.6.1) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailer (5.2.8.1) - actionpack (= 5.2.8.1) - actionview (= 5.2.8.1) - activejob (= 5.2.8.1) + actionmailbox (6.0.6.1) + actionpack (= 6.0.6.1) + activejob (= 6.0.6.1) + activerecord (= 6.0.6.1) + activestorage (= 6.0.6.1) + activesupport (= 6.0.6.1) + mail (>= 2.7.1) + actionmailer (6.0.6.1) + actionpack (= 6.0.6.1) + actionview (= 6.0.6.1) + activejob (= 6.0.6.1) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 2.0) - actionpack (5.2.8.1) - actionview (= 5.2.8.1) - activesupport (= 5.2.8.1) + actionpack (6.0.6.1) + actionview (= 6.0.6.1) + activesupport (= 6.0.6.1) rack (~> 2.0, >= 2.0.8) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (5.2.8.1) - activesupport (= 5.2.8.1) + rails-html-sanitizer (~> 1.0, >= 1.2.0) + actiontext (6.0.6.1) + actionpack (= 6.0.6.1) + activerecord (= 6.0.6.1) + activestorage (= 6.0.6.1) + activesupport (= 6.0.6.1) + nokogiri (>= 1.8.5) + actionview (6.0.6.1) + activesupport (= 6.0.6.1) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.0.3) - activejob (5.2.8.1) - activesupport (= 5.2.8.1) + rails-html-sanitizer (~> 1.1, >= 1.2.0) + activejob (6.0.6.1) + activesupport (= 6.0.6.1) globalid (>= 0.3.6) activemerchant (1.107.4) activesupport (>= 4.2) builder (>= 2.1.2, < 4.0.0) i18n (>= 0.6.9) nokogiri (~> 1.4) - activemodel (5.2.8.1) - activesupport (= 5.2.8.1) + activemodel (6.0.6.1) + activesupport (= 6.0.6.1) activemodel-serializers-xml (1.0.2) activemodel (> 5.x) activesupport (> 5.x) builder (~> 3.1) - activerecord (5.2.8.1) - activemodel (= 5.2.8.1) - activesupport (= 5.2.8.1) - arel (>= 9.0) - activerecord-oracle_enhanced-adapter (5.2.8) - activerecord (~> 5.2.0) + activerecord (6.0.6.1) + activemodel (= 6.0.6.1) + activesupport (= 6.0.6.1) + activerecord-oracle_enhanced-adapter (6.0.6) + activerecord (~> 6.0.0) ruby-plsql (>= 0.6.0) - activestorage (5.2.8.1) - actionpack (= 5.2.8.1) - activerecord (= 5.2.8.1) - marcel (~> 1.0.0) - activesupport (5.2.8.1) + activestorage (6.0.6.1) + actionpack (= 6.0.6.1) + activejob (= 6.0.6.1) + activerecord (= 6.0.6.1) + marcel (~> 1.0) + activesupport (6.0.6.1) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 0.7, < 2) minitest (~> 5.1) tzinfo (~> 1.1) + zeitwerk (~> 2.2, >= 2.2.2) acts-as-taggable-on (8.1.0) activerecord (>= 5.0, < 6.2) acts_as_list (0.9.17) @@ -149,7 +163,6 @@ GEM activesupport (>= 3.0) analytics-ruby (2.2.8) ansi (1.5.0) - arel (9.0.0) ast (2.4.2) audited (5.0.2) activerecord (>= 5.0, < 7.1) @@ -196,11 +209,11 @@ GEM bcrypt (3.1.13) binding_of_caller (1.0.0) debug_inspector (>= 0.0.1) - bootsnap (1.4.5) - msgpack (~> 1.0) + bootsnap (1.16.0) + msgpack (~> 1.2) braintree (2.104.1) builder (>= 2.0.0) - browser (5.0.0) + browser (5.3.1) bugsnag (6.11.1) concurrent-ruby (~> 1.0) builder (3.2.4) @@ -298,7 +311,7 @@ GEM cucumber-cucumber-expressions (~> 12.1, >= 12.1.2) cucumber-messages (~> 17.0, >= 17.0.1) daemons (1.3.1) - dalli (2.7.10) + dalli (3.2.4) database_cleaner (1.7.0) debug_inspector (1.1.0) diff-lcs (1.4.4) @@ -313,12 +326,12 @@ GEM dotenv-rails (2.7.5) dotenv (= 2.7.5) railties (>= 3.2, < 6.1) - draper (3.0.1) - actionpack (~> 5.0) - activemodel (~> 5.0) - activemodel-serializers-xml (~> 1.0) - activesupport (~> 5.0) - request_store (~> 1.0) + draper (3.1.0) + actionpack (>= 5.0) + activemodel (>= 5.0) + activemodel-serializers-xml (>= 1.0) + activesupport (>= 5.0) + request_store (>= 1.0) dry-initializer (3.0.4) dynamic_form (1.1.4) email_spec (2.2.0) @@ -338,7 +351,7 @@ GEM factory_bot_rails (6.2.0) factory_bot (~> 6.2.0) railties (>= 5.0.0) - fakefs (0.18.0) + fakefs (1.8.0) faraday (0.15.3) multipart-post (>= 1.2, < 3) faraday_middleware (0.13.1) @@ -355,11 +368,11 @@ GEM et-orbi (~> 1.1, >= 1.1.8) raabro (~> 1.4) github-markdown (0.6.9) - globalid (1.0.1) + globalid (1.1.0) activesupport (>= 5.0) - has_scope (0.7.2) - actionpack (>= 4.1) - activesupport (>= 4.1) + has_scope (0.8.1) + actionpack (>= 5.2) + activesupport (>= 5.2) hashdiff (1.0.1) hashery (2.1.2) hashie (3.6.0) @@ -395,9 +408,8 @@ GEM railties (>= 4.2.0) thor (>= 0.14, < 2.0) json (2.3.1) - jsonpath (1.0.5) + jsonpath (1.1.2) multi_json - to_regexp (~> 0.2.1) jwt (1.5.6) kgio (2.11.3) kramdown (2.4.0) @@ -466,7 +478,7 @@ GEM minitest-stub-const (0.6) mocha (1.1.0) metaclass (~> 0.0.1) - msgpack (1.3.1) + msgpack (1.7.1) multi_json (1.15.0) multi_test (0.1.2) multi_xml (0.6.0) @@ -478,7 +490,7 @@ GEM net-http-persistent (4.0.1) connection_pool (~> 2.2) netrc (0.11.0) - nio4r (2.5.8) + nio4r (2.5.9) nokogiri (1.13.10) mini_portile2 (~> 2.8.0) racc (~> 1.4) @@ -550,7 +562,7 @@ GEM public_suffix (4.0.7) raabro (1.4.0) racc (1.6.2) - rack (2.2.6.4) + rack (2.2.7) rack-cors (1.1.1) rack (>= 2.0.0) rack-no_animations (1.0.3) @@ -566,23 +578,25 @@ GEM rack-utf8_sanitizer (1.6.0) rack (>= 1.0, < 3.0) rack-x_served_by (0.1.1) - rails (5.2.8.1) - actioncable (= 5.2.8.1) - actionmailer (= 5.2.8.1) - actionpack (= 5.2.8.1) - actionview (= 5.2.8.1) - activejob (= 5.2.8.1) - activemodel (= 5.2.8.1) - activerecord (= 5.2.8.1) - activestorage (= 5.2.8.1) - activesupport (= 5.2.8.1) + rails (6.0.6.1) + actioncable (= 6.0.6.1) + actionmailbox (= 6.0.6.1) + actionmailer (= 6.0.6.1) + actionpack (= 6.0.6.1) + actiontext (= 6.0.6.1) + actionview (= 6.0.6.1) + activejob (= 6.0.6.1) + activemodel (= 6.0.6.1) + activerecord (= 6.0.6.1) + activestorage (= 6.0.6.1) + activesupport (= 6.0.6.1) bundler (>= 1.3.0) - railties (= 5.2.8.1) + railties (= 6.0.6.1) sprockets-rails (>= 2.0.0) - rails-controller-testing (1.0.2) - actionpack (~> 5.x, >= 5.0.1) - actionview (~> 5.x, >= 5.0.1) - activesupport (~> 5.x) + rails-controller-testing (1.0.5) + actionpack (>= 5.0.1.rc1) + actionview (>= 5.0.1.rc1) + activesupport (>= 5.0.1.rc1) rails-dom-testing (2.0.3) activesupport (>= 4.2.0) nokogiri (>= 1.6) @@ -600,18 +614,18 @@ GEM activemodel (>= 3.0) activesupport (>= 3.0) ruby_event_store (~> 0.9.0) - railties (5.2.8.1) - actionpack (= 5.2.8.1) - activesupport (= 5.2.8.1) + railties (6.0.6.1) + actionpack (= 6.0.6.1) + activesupport (= 6.0.6.1) method_source rake (>= 0.8.7) - thor (>= 0.19.0, < 2.0) + thor (>= 0.20.3, < 2.0) rainbow (3.1.1) raindrops (0.19.0) rake (13.0.6) - ransack (2.4.1) - activerecord (>= 5.2.4) - activesupport (>= 5.2.4) + ransack (2.6.0) + activerecord (>= 6.0.4) + activesupport (>= 6.0.4) i18n ratelimit (1.0.3) redis (>= 2.0.0) @@ -629,8 +643,8 @@ GEM redis-namespace (1.7.0) redis (>= 3.0.4) redis-prescription (1.0.0) - redlock (1.2.1) - redis (>= 3.0.0, < 5.0) + redlock (1.3.2) + redis (>= 3.0.0, < 6.0) reek (6.1.0) kwalify (~> 0.7.0) parser (~> 3.1.0) @@ -641,7 +655,7 @@ GEM regexp_parser (2.6.1) representable (2.3.0) uber (~> 0.0.7) - request_store (1.4.1) + request_store (1.5.1) rack (>= 1.4) responders (3.0.1) actionpack (>= 5.0) @@ -717,8 +731,8 @@ GEM ruby_event_store (0.9.0) rubyzip (1.3.0) sass (3.4.25) - sass-rails (5.0.7) - railties (>= 4.0.0, < 6) + sass-rails (5.0.8) + railties (>= 5.2.0) sass (~> 3.1) sprockets (>= 2.8, < 4.0) sprockets-rails (>= 2.0, < 4.0) @@ -769,17 +783,17 @@ GEM sprockets (3.7.2) concurrent-ruby (~> 1.0) rack (> 1, < 3) - sprockets-rails (3.2.2) - actionpack (>= 4.0) - activesupport (>= 4.0) + sprockets-rails (3.4.2) + actionpack (>= 5.2) + activesupport (>= 5.2) sprockets (>= 3.0.0) state_machines (0.5.0) - state_machines-activemodel (0.5.1) - activemodel (>= 4.1, < 6.0) + state_machines-activemodel (0.8.0) + activemodel (>= 5.1) state_machines (>= 0.5.0) - state_machines-activerecord (0.5.2) - activerecord (>= 4.1, < 6.0) - state_machines-activemodel (>= 0.5.0) + state_machines-activerecord (0.8.0) + activerecord (>= 5.1) + state_machines-activemodel (>= 0.8.0) statsd-ruby (1.4.0) strings (0.2.1) strings-ansi (~> 0.2) @@ -811,8 +825,7 @@ GEM riddle (~> 2.3) thor (1.2.2) thread_safe (0.3.6) - tilt (2.0.9) - to_regexp (0.2.1) + tilt (2.0.11) tomlrb (2.0.3) ts-datetime-delta (2.0.2) thinking-sphinx (>= 1.3.8) @@ -886,6 +899,7 @@ GEM yabeda (~> 0.6) yard (0.9.27) webrick (~> 1.7.0) + zeitwerk (2.6.8) zip-zip (0.3) rubyzip (>= 1.0.0) @@ -900,7 +914,7 @@ DEPENDENCIES activejob-uniqueness! activemerchant (~> 1.107.4) activemodel-serializers-xml - activerecord-oracle_enhanced-adapter (~> 5.2.0) + activerecord-oracle_enhanced-adapter (~> 6.0) acts-as-taggable-on (~> 8.0) acts_as_list (~> 0.9.17) acts_as_tree @@ -912,9 +926,9 @@ DEPENDENCIES aws-sdk-s3 (~> 1) baby_squeel (~> 1.4.3) bcrypt (~> 3.1.7) - bootsnap (~> 1.4) + bootsnap (~> 1.16) braintree (~> 2.93) - browser (~> 5.0.0) + browser bugsnag (~> 6.11) bullet (~> 6.1.5) cancancan (~> 3.0.0) @@ -929,25 +943,23 @@ DEPENDENCIES compass-rails (~> 3.0.2) cucumber (~> 7.0) cucumber-rails (~> 2.4.0) - dalli (~> 2.7) + dalli database_cleaner (~> 1.7) developer_portal! diff-lcs (~> 1.2) dotenv-rails (~> 2.7) - draper (~> 3.0) + draper (~> 3.1) dynamic_form email_spec equivalent-xml escape_utils factory_bot_rails (~> 6.2) - fakefs (~> 0.18.0) + fakefs faraday (~> 0.15.3) faraday_middleware (~> 0.13.1) font-awesome-rails (~> 4.7.0.5) formtastic (~> 4.0) github-markdown - globalid (~> 1.0.1) - has_scope (~> 0.7.2) hashie hiredis (~> 0.6.3) html-pipeline @@ -958,7 +970,6 @@ DEPENDENCIES jquery-rails (~> 4.4) json (~> 2.3.0) json-schema! - jsonpath (= 1.0.5) jwt (~> 1.5.2) kubeclient launchy @@ -999,11 +1010,10 @@ DEPENDENCIES rack-no_animations (~> 1.0.3) rack-utf8_sanitizer rack-x_served_by (~> 0.1.1) - rails (~> 5.2.8) - rails-controller-testing + rails (~> 6.0) + rails-controller-testing (~> 1.0.4) rails-observers rails_event_store (~> 0.9.0) - ransack (= 2.4.1) ratelimit recaptcha (= 4.13.1) record_tag_helper (~> 1.0) @@ -1026,7 +1036,7 @@ DEPENDENCIES ruby-openid ruby-prof rubyzip (~> 1.3.0) - sass-rails (~> 5.0) + sass-rails (~> 5.0.8) secure_headers (~> 6.3.0) selenium-webdriver (~> 3.142) shoulda (~> 4.0) @@ -1038,9 +1048,9 @@ DEPENDENCIES sidekiq-throttled simplecov (~> 0.21.2) slim-rails (~> 3.2) - sprockets-rails (= 3.2.2) + sprockets-rails state_machines (~> 0.5.0) - state_machines-activerecord (~> 0.5.0) + state_machines-activerecord (~> 0.8) statsd-ruby stripe (~> 5.28.0) strong_migrations (~> 0.6.8) diff --git a/app/controllers/admin/api/sso_tokens_controller.rb b/app/controllers/admin/api/sso_tokens_controller.rb index 87cff3ddd5..f71ba7277e 100644 --- a/app/controllers/admin/api/sso_tokens_controller.rb +++ b/app/controllers/admin/api/sso_tokens_controller.rb @@ -19,7 +19,7 @@ def provider_create provider = site_account.buyers.find(params[:provider_id]) sso_token = SSOToken.new sso_token.account = provider - sso_token.username = ThreeScale.config.impersonation_admin['username'] + sso_token.username = ThreeScale.config.impersonation_admin[:username] sso_token.expires_in = params.fetch(:expires_in) { sso_token.expires_in } sso_token.save diff --git a/app/controllers/provider/admin/dashboard/service/hits_controller.rb b/app/controllers/provider/admin/dashboard/service/hits_controller.rb index 818cfc1d84..01e07c07be 100644 --- a/app/controllers/provider/admin/dashboard/service/hits_controller.rb +++ b/app/controllers/provider/admin/dashboard/service/hits_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Provider::Admin::Dashboard::Service::HitsController < Provider::Admin::Dashboard::Service::BaseController include ActiveSupport::NumberHelper @@ -31,4 +33,3 @@ def traffic_service TrafficService.new(stats_client) end end -require_dependency 'stats/service' diff --git a/app/controllers/provider/admin/dashboard/service/top_traffic_controller.rb b/app/controllers/provider/admin/dashboard/service/top_traffic_controller.rb index 2aefbec0c5..39fe69063e 100644 --- a/app/controllers/provider/admin/dashboard/service/top_traffic_controller.rb +++ b/app/controllers/provider/admin/dashboard/service/top_traffic_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Provider::Admin::Dashboard::Service::TopTrafficController < Provider::Admin::Dashboard::Service::BaseController respond_to :json @@ -13,4 +15,3 @@ def stats_client ::Stats::Service.new(service) end end -require_dependency 'stats/service' diff --git a/app/lib/authentication/strategy.rb b/app/lib/authentication/strategy.rb index b75866f43d..171103bec7 100644 --- a/app/lib/authentication/strategy.rb +++ b/app/lib/authentication/strategy.rb @@ -15,7 +15,8 @@ def build_provider(provider_account) protected def build_strategy(type) - strategy_class_name = "authentication/strategy/#{type}".camelize + inflected_type = Rails.autoloaders.main.inflector.camelize(type.to_s, {}) + strategy_class_name = "Authentication::Strategy::#{inflected_type}" strategy_class_name.constantize end end diff --git a/app/lib/authentication/strategy/base.rb b/app/lib/authentication/strategy/base.rb index 406162af2e..ff4254e366 100644 --- a/app/lib/authentication/strategy/base.rb +++ b/app/lib/authentication/strategy/base.rb @@ -80,7 +80,7 @@ def authentication_provider; end def authentication_provider_id authentication_provider.try(:id) - rescue Authentication::Strategy::Oauth2Base::MissingAuthenticationProvider + rescue Authentication::Strategy::OAuth2Base::MissingAuthenticationProvider nil end end diff --git a/app/lib/authentication/strategy/oauth2.rb b/app/lib/authentication/strategy/oauth2.rb index 97a2663db5..17e0aade93 100644 --- a/app/lib/authentication/strategy/oauth2.rb +++ b/app/lib/authentication/strategy/oauth2.rb @@ -2,7 +2,7 @@ module Authentication module Strategy - class Oauth2 < Authentication::Strategy::Oauth2Base + class OAuth2 < Authentication::Strategy::OAuth2Base class FindOrCreateAccount < Procedure def call @@ -12,7 +12,7 @@ def call private def find_user - Users::FindOauth2UserService.run(user_data, authentication_provider, users).user.tap do |user| + Users::FindOAuth2UserService.run(user_data, authentication_provider, users).user.tap do |user| strategy.user_used_sso_authorization(user, user_data) if user end end diff --git a/app/lib/authentication/strategy/oauth2_base.rb b/app/lib/authentication/strategy/oauth2_base.rb index 83f8a69045..34ed51b456 100644 --- a/app/lib/authentication/strategy/oauth2_base.rb +++ b/app/lib/authentication/strategy/oauth2_base.rb @@ -2,7 +2,7 @@ module Authentication module Strategy - class Oauth2Base < Authentication::Strategy::Internal + class OAuth2Base < Authentication::Strategy::Internal def initialize(*) super diff --git a/app/lib/authentication/strategy/provider_oauth2.rb b/app/lib/authentication/strategy/provider_oauth2.rb index 869822feeb..299e140012 100644 --- a/app/lib/authentication/strategy/provider_oauth2.rb +++ b/app/lib/authentication/strategy/provider_oauth2.rb @@ -1,6 +1,6 @@ module Authentication module Strategy - class ProviderOauth2 < Authentication::Strategy::Oauth2Base + class ProviderOAuth2 < Authentication::Strategy::OAuth2Base class FindOrCreateUser < Procedure @@ -13,7 +13,7 @@ def call private def find_user - result = Users::FindOauth2UserService.run(user_data, authentication_provider, users) + result = Users::FindOAuth2UserService.run(user_data, authentication_provider, users) strategy.error_message = result.error_message result.user end diff --git a/app/lib/authentication/strategy/sso.rb b/app/lib/authentication/strategy/sso.rb index 16f3650c36..5a9ad5ecd7 100644 --- a/app/lib/authentication/strategy/sso.rb +++ b/app/lib/authentication/strategy/sso.rb @@ -73,7 +73,7 @@ def authenticate_with_sso(token, expires_at = nil) @error_message = 'User not found' nil # this happens when we fail to decrypt the message - rescue ActiveSupport::MessageVerifier::InvalidSignature => error + rescue ActiveSupport::MessageEncryptor::InvalidMessage, ActiveSupport::MessageVerifier::InvalidSignature => error @error_message = "Invalid SSO Token" nil # this happens when we fail to validate the decrypted message, right now only if the token expired diff --git a/app/lib/cms/database_file_system.rb b/app/lib/cms/database_file_system.rb index 61b9c1cdd7..8ecf2d701f 100644 --- a/app/lib/cms/database_file_system.rb +++ b/app/lib/cms/database_file_system.rb @@ -47,8 +47,8 @@ def initialize(*) @details = { formats: [:html], handlers: [:liquid] } end - def find_template(path) - super(path, []) + def find_template(path, locals = []) + super(path, locals) end end diff --git a/app/lib/events/importer.rb b/app/lib/events/importer.rb index 3f07dbf5ce..283a528f9e 100644 --- a/app/lib/events/importer.rb +++ b/app/lib/events/importer.rb @@ -1,9 +1,4 @@ -require_dependency 'events/event' - -require_dependency 'events/importers/base_importer' -require_dependency 'events/importers/first_traffic_importer' -require_dependency 'events/importers/first_daily_traffic_importer' -require_dependency 'events/importers/alert_importer' +# frozen_string_literal: true module Events module Importer diff --git a/app/lib/events/importers/alert_importer.rb b/app/lib/events/importers/alert_importer.rb index 5339a53ffb..2f647e7bdc 100644 --- a/app/lib/events/importers/alert_importer.rb +++ b/app/lib/events/importers/alert_importer.rb @@ -1,4 +1,4 @@ -require_dependency 'events/importers/base_importer' +# frozen_string_literal: true module Events module Importers @@ -103,4 +103,3 @@ def settings end end end - diff --git a/app/lib/events/importers/first_daily_traffic_importer.rb b/app/lib/events/importers/first_daily_traffic_importer.rb index 40ac54d305..a8b8f8c5bf 100644 --- a/app/lib/events/importers/first_daily_traffic_importer.rb +++ b/app/lib/events/importers/first_daily_traffic_importer.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require_dependency 'events/importers/base_importer' - module Events module Importers class FirstDailyTrafficImporter < BaseImporter diff --git a/app/lib/events/importers/first_traffic_importer.rb b/app/lib/events/importers/first_traffic_importer.rb index 0a0c05d315..f9daf00482 100644 --- a/app/lib/events/importers/first_traffic_importer.rb +++ b/app/lib/events/importers/first_traffic_importer.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require_dependency 'events/importers/base_importer' - module Events module Importers class FirstTrafficImporter < BaseImporter diff --git a/app/lib/finance/variable_cost.rb b/app/lib/finance/variable_cost.rb index 937b2e17b9..a4e85f86c8 100644 --- a/app/lib/finance/variable_cost.rb +++ b/app/lib/finance/variable_cost.rb @@ -1,4 +1,4 @@ -require_dependency 'stats/client' +# frozen_string_literal: true module Finance # Mixin for Cinstance to get the variable costs calculations. diff --git a/app/lib/last_traffic.rb b/app/lib/last_traffic.rb index 7114597231..09e69b5f48 100644 --- a/app/lib/last_traffic.rb +++ b/app/lib/last_traffic.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require_dependency 'stats' - class LastTraffic DEFAULT_METRIC = 'hits' diff --git a/app/lib/liquid/template_support.rb b/app/lib/liquid/template_support.rb index ab36b6c3ed..fc176ddf18 100644 --- a/app/lib/liquid/template_support.rb +++ b/app/lib/liquid/template_support.rb @@ -48,7 +48,21 @@ def add_liquid_view_paths(options = {}) end end - view_renderer.extend(LayoutSupport) + ActionView::Renderer.class_eval do + # RAILS: this overrides a Rails method. Beware when upgrading. + # We overwrite ActionView methods to make Liquid work. Due to changes in ActionView, we cannot depend on + # overwriting instances of ActionView::Renderer anymore, as those can be reinitialized during a page render. + # Because of that, we need to overwrite this method in class level, which may cause odd behaviours without + # the respond_to?(:liquify) check. + # Maybe move this to an initializer in case we can't find a better solution? + def render_template_to_object(context, options) + if context.controller.class.respond_to?(:liquify) + LiquidTemplateRenderer.new(@lookup_context).render(context, options) + else + ActionView::TemplateRenderer.new(@lookup_context).render(context, options) + end + end + end end class LiquidTemplateRenderer < ::ActionView::TemplateRenderer @@ -68,13 +82,6 @@ def determine_template(options) end end - module LayoutSupport - # RAILS: this overrides rails method, beware when upgrading - def render_template(context, options) - LiquidTemplateRenderer.new(@lookup_context).render(context, options) - end - end - def assigns_for_liquify @_assigned_drops ||= {} @_template_assigns ||= {} diff --git a/app/lib/plan_rule_loader.rb b/app/lib/plan_rule_loader.rb index 7b7cc984f1..c18067ec6c 100644 --- a/app/lib/plan_rule_loader.rb +++ b/app/lib/plan_rule_loader.rb @@ -3,9 +3,9 @@ module PlanRuleLoader DEFAULT_RULES = { enterprise: { - 'rank' => 27, - 'limits' => {'max_users' => nil, 'max_services' => nil}, - 'switches' => %w[ + rank: 27, + limits: { max_users: nil, max_services: nil }, + switches: %w[ finance multiple_applications branding @@ -19,7 +19,7 @@ module PlanRuleLoader web_hooks iam_tools ], - 'metadata' => { 'cannot_automatically_be_upgraded_to' => true } + metadata: { cannot_automatically_be_upgraded_to: true } } }.freeze @@ -32,7 +32,7 @@ def load_config end def sort_by_rank(yaml) - yaml.sort_by { |_, attributes| Integer(attributes['rank']) } + yaml.sort_by { |_, attributes| Integer(attributes[:rank]) } end def convert_to_hash_with_plan_rule_objects(config) diff --git a/app/lib/signup/impersonation_admin_builder.rb b/app/lib/signup/impersonation_admin_builder.rb index d4c78f3eb0..69d36fa028 100644 --- a/app/lib/signup/impersonation_admin_builder.rb +++ b/app/lib/signup/impersonation_admin_builder.rb @@ -4,11 +4,11 @@ module Signup class ImpersonationAdminBuilder def self.build(account:) config = ThreeScale.config.impersonation_admin - username = config['username'] + username = config[:username] impersonation_admin = account.users.new( { username: username, - email: "#{username}+#{account.internal_domain}@#{config['domain']}", + email: "#{username}+#{account.internal_domain}@#{config[:domain]}", first_name: '3scale', last_name: 'Admin', state: 'active' diff --git a/app/lib/stats/base.rb b/app/lib/stats/base.rb index b6e708a622..c8d907c150 100644 --- a/app/lib/stats/base.rb +++ b/app/lib/stats/base.rb @@ -1,5 +1,4 @@ - -require_dependency 'stats' +# frozen_string_literal: true module Stats class Base diff --git a/app/lib/system_name.rb b/app/lib/system_name.rb index 5fdeee72d1..15e5085996 100644 --- a/app/lib/system_name.rb +++ b/app/lib/system_name.rb @@ -59,7 +59,7 @@ def generate_system_name! # we can guess a reasonable one. # def internal_system_name - model_name = ActiveModel::Name.new(self.class, self.class.parent) + model_name = ActiveModel::Name.new(self.class, self.class.module_parent) "#{model_name.param_key}_#{SecureRandom.hex(6)}" end end diff --git a/app/lib/three_scale/filter_arguments.rb b/app/lib/three_scale/filter_arguments.rb index e56424a3c5..928cfe9822 100644 --- a/app/lib/three_scale/filter_arguments.rb +++ b/app/lib/three_scale/filter_arguments.rb @@ -1,13 +1,8 @@ # frozen_string_literal: true module ThreeScale - # This class is used to filter sensitive parameters from hashes inside an array of - # arguments. It depends on ActionDispatch::Http::ParameterFilter. - # - # ActionDispatch::Http::ParameterFilter will be removed in Rails 6.1. After we need to change to - # ActiveSupport::ParameterFilter class FilterArguments - FILTER = ActionDispatch::Http::ParameterFilter.new(Rails.configuration.filter_parameters) + FILTER = ActiveSupport::ParameterFilter.new(Rails.configuration.filter_parameters) def initialize(arguments = []) @arguments = arguments.dup diff --git a/app/lib/three_scale/has_money.rb b/app/lib/three_scale/has_money.rb index c39c9e399d..141aafa8ec 100644 --- a/app/lib/three_scale/has_money.rb +++ b/app/lib/three_scale/has_money.rb @@ -1,4 +1,4 @@ -require_dependency File.dirname(__FILE__) + '/money' +# frozen_string_literal: true module ThreeScale module HasMoney diff --git a/app/mailers/account_mailer.rb b/app/mailers/account_mailer.rb index 193cbe6f9c..f5904b6bcc 100644 --- a/app/mailers/account_mailer.rb +++ b/app/mailers/account_mailer.rb @@ -5,8 +5,8 @@ class AccountMailer < ActionMailer::Base include Liquid::Assigns include CMS::EmailTemplate::MailerExtension - add_template_helper(SupportEntitlementsHelper) - add_template_helper(Finance::InvoicesHelper) + helper(SupportEntitlementsHelper) + helper(Finance::InvoicesHelper) def confirmed(account) self.provider_account = account.provider_account diff --git a/app/models/account.rb b/app/models/account.rb index 4984b625f2..20f1d42d3b 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -199,7 +199,7 @@ def has_impersonation_admin? end def find_impersonation_admin - users.admins.find_by(username: ThreeScale.config.impersonation_admin['username']) + users.admins.find_by(username: ThreeScale.config.impersonation_admin[:username]) end # Users of this account + users of all buyer accounts of this account (if it is provider). diff --git a/app/models/authentication_provider.rb b/app/models/authentication_provider.rb index 6cc63729a1..484cd8e916 100644 --- a/app/models/authentication_provider.rb +++ b/app/models/authentication_provider.rb @@ -150,10 +150,3 @@ def set_defaults self.name ||= human_kind.to_s end end - -# to prevent warning: toplevel constant GitHub referenced by AuthenticationProvider::GitHub -require_dependency 'authentication_provider/github' -require_dependency 'authentication_provider/keycloak' -require_dependency 'authentication_provider/auth0' -require_dependency 'authentication_provider/custom' -require_dependency 'authentication_provider/redhat_customer_portal' diff --git a/app/models/cinstance.rb b/app/models/cinstance.rb index fcfbeeb3c9..ecf5640309 100644 --- a/app/models/cinstance.rb +++ b/app/models/cinstance.rb @@ -36,7 +36,7 @@ class Cinstance < Contract # this has to be before the include Backend::ModelExtensions::Cinstance # or callbacks order makes keys not to be saved in backend - after_save :create_first_key, on: :create + after_create :create_first_key # before_destroy :refund_fixed_cost after_commit :reject_if_pending, :on => :destroy diff --git a/app/models/concerns/symbolize.rb b/app/models/concerns/symbolize.rb index b70064e5f5..f3f182a8a4 100644 --- a/app/models/concerns/symbolize.rb +++ b/app/models/concerns/symbolize.rb @@ -10,6 +10,12 @@ module Symbolize end module AttributesAccessor + def changes + ActiveSupport::HashWithIndifferentAccess[ + mutations_from_database.changed_attribute_names.map { |attr| [attr, attribute_change(attr)] } + ] + end + def attribute_previous_change(attr) __symbolize_changes(attr, super) end diff --git a/app/models/email_configuration.rb b/app/models/email_configuration.rb index 4185d0fed8..571fbb5e54 100644 --- a/app/models/email_configuration.rb +++ b/app/models/email_configuration.rb @@ -18,7 +18,7 @@ class EmailConfiguration < ApplicationRecord belongs_to :account, optional: false validate :account_is_provider - before_save :set_tenant_id, on: :create + before_save :set_tenant_id scope :for, ->(search_email) { where arel_table[:email].matches(search_email.gsub(/([_%\\])/, '\\\\\\1'), "\\", false) diff --git a/app/models/finance/billing_strategy.rb b/app/models/finance/billing_strategy.rb index 7b2af254ea..8f44bc2646 100644 --- a/app/models/finance/billing_strategy.rb +++ b/app/models/finance/billing_strategy.rb @@ -420,6 +420,3 @@ def ignoring_find_each_scope(&block) extend FindEachFix include FindEachFix end - -require_dependency 'finance/prepaid_billing_strategy' -require_dependency 'finance/postpaid_billing_strategy' diff --git a/app/models/invoice.rb b/app/models/invoice.rb index a375c6ae75..7d85a7e7d4 100644 --- a/app/models/invoice.rb +++ b/app/models/invoice.rb @@ -1,7 +1,4 @@ -require_dependency 'pdf/finance/invoice_report_data' -require_dependency 'pdf/finance/invoice_generator' - -require_dependency 'month' +# frozen_string_literal: true # TODO: add uniqueness check on provider/buyer/period scope # diff --git a/app/models/service.rb b/app/models/service.rb index 23b0aac9ce..99615a63f1 100644 --- a/app/models/service.rb +++ b/app/models/service.rb @@ -113,7 +113,9 @@ def cinstance account = user.account account_services = (account.provider? ? account : account.provider_account).services - account_services.merge(user.forbidden_some_services? ? where(id: user.member_permission_service_ids) : {}) + self.merge( + account_services.merge(user.forbidden_some_services? ? where(id: user.member_permission_service_ids) : {}) + ) } validates :name, presence: true diff --git a/app/models/service_contract.rb b/app/models/service_contract.rb index 524bf7aef7..3deb560c85 100644 --- a/app/models/service_contract.rb +++ b/app/models/service_contract.rb @@ -1,7 +1,7 @@ class ServiceContract < Contract include Logic::Contracting::ServiceContract - before_create :accept_on_create, :on => :create, :unless => :live? + before_create :accept_on_create, :unless => :live? before_create :set_service_id before_validation :set_service_id diff --git a/app/models/user.rb b/app/models/user.rb index 1de559f9db..240fdb5390 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -140,8 +140,8 @@ def self.search_states scope :latest, -> {limit(5).order(created_at: :desc)} - scope :but_impersonation_admin, -> { where.has { username != ThreeScale.config.impersonation_admin['username'] } } - scope :impersonation_admins, -> { where(username: ThreeScale.config.impersonation_admin['username']) } + scope :but_impersonation_admin, -> { where.has { username != ThreeScale.config.impersonation_admin[:username] } } + scope :impersonation_admins, -> { where(username: ThreeScale.config.impersonation_admin[:username]) } scope :admins, -> { where(role: 'admin') } @@ -167,7 +167,7 @@ def self.impersonation_admin end def impersonation_admin? - username == ThreeScale.config.impersonation_admin['username'] + username == ThreeScale.config.impersonation_admin[:username] end def any_sso_authorizations? diff --git a/app/models/web_hook/event.rb b/app/models/web_hook/event.rb index ef9173a8c8..4ab36ecb63 100644 --- a/app/models/web_hook/event.rb +++ b/app/models/web_hook/event.rb @@ -39,7 +39,7 @@ def model delegate :logger, to: :Rails - def has_transactional_callbacks? + def trigger_transactional_callbacks? true end diff --git a/app/observers/message_observer.rb b/app/observers/message_observer.rb index 587d856c51..9380e7e8b8 100644 --- a/app/observers/message_observer.rb +++ b/app/observers/message_observer.rb @@ -1,4 +1,4 @@ -require_dependency 'notification_center' +require 'notification_center' class MessageObserver < ActiveRecord::Observer observe :cinstance, :service_contract diff --git a/app/services/users/find_oauth2_user_service.rb b/app/services/users/find_oauth2_user_service.rb index 55a0960c90..f4c57c9f32 100644 --- a/app/services/users/find_oauth2_user_service.rb +++ b/app/services/users/find_oauth2_user_service.rb @@ -1,4 +1,4 @@ -class Users::FindOauth2UserService +class Users::FindOAuth2UserService Result = Struct.new(:user, :error_message) diff --git a/app/subscribers/after_commit_subscriber.rb b/app/subscribers/after_commit_subscriber.rb index 5bdf4e7e90..5aa26deede 100644 --- a/app/subscribers/after_commit_subscriber.rb +++ b/app/subscribers/after_commit_subscriber.rb @@ -21,7 +21,7 @@ def rolledback!(*) subscriber.after_rollback(event) end - def has_transactional_callbacks? + def trigger_transactional_callbacks? true end diff --git a/app/workers/event_import_worker.rb b/app/workers/event_import_worker.rb index 0b22edaa5b..e6dac1225c 100644 --- a/app/workers/event_import_worker.rb +++ b/app/workers/event_import_worker.rb @@ -1,4 +1,4 @@ -require_dependency 'events/importer' +# frozen_string_literal: true class EventImportWorker include Sidekiq::Worker diff --git a/app/workers/last_traffic_worker.rb b/app/workers/last_traffic_worker.rb index a7894d294f..2b570d2191 100644 --- a/app/workers/last_traffic_worker.rb +++ b/app/workers/last_traffic_worker.rb @@ -1,4 +1,4 @@ -require_dependency 'last_traffic' +# frozen_string_literal: true class LastTrafficWorker include Sidekiq::Worker diff --git a/app/workers/pdf_report_worker.rb b/app/workers/pdf_report_worker.rb index b365292ee7..7a61a67b48 100644 --- a/app/workers/pdf_report_worker.rb +++ b/app/workers/pdf_report_worker.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class PdfReportWorker include Sidekiq::Worker @@ -38,7 +40,3 @@ def perform(service_id, account_id, period, reference) delegate :logger, to: :Rails end - -if Rails.application.config.three_scale.daily_weekly_reports_pref - require_dependency 'pdf/report' -end diff --git a/app/workers/signup_worker.rb b/app/workers/signup_worker.rb index 377c3c0ec5..0574d8b03c 100644 --- a/app/workers/signup_worker.rb +++ b/app/workers/signup_worker.rb @@ -1,4 +1,4 @@ -require_dependency 'notification_center' +# frozen_string_literal: true class SignupWorker include Sidekiq::Worker diff --git a/bin/setup b/bin/setup index a5eca9a71c..df8cf5004c 100755 --- a/bin/setup +++ b/bin/setup @@ -1,6 +1,5 @@ #!/usr/bin/env ruby require 'fileutils' -include FileUtils # path to your application root. APP_ROOT = File.expand_path('..', __dir__) @@ -9,8 +8,9 @@ def system!(*args) system(*args) || abort("\n== Command #{args} failed ==") end -chdir APP_ROOT do - # This script is a starting point to setup your application. +FileUtils.chdir APP_ROOT do + # This script is a way to setup or update your development environment automatically. + # This script is idempotent, so that you can run it at anytime and get an expectable outcome. # Add necessary setup steps to this file. puts '== Installing dependencies ==' @@ -24,7 +24,7 @@ chdir APP_ROOT do cp_r 'config/examples/.', 'config/', preserve: true, dereference_root: true puts "\n== Preparing database ==" - system! 'bin/rails db:setup' + system! 'bin/rails db:prepare' puts "\n== Removing old logs and tempfiles ==" system! 'bin/rails log:clear tmp:clear' diff --git a/config/application.rb b/config/application.rb index 770791d255..fd2abdf15f 100644 --- a/config/application.rb +++ b/config/application.rb @@ -58,29 +58,25 @@ class Application < Rails::Application # we do here instead of using initializers because of a Rails 5.1 vs # MySQL bug where `rake db:reset` causes ActiveRecord to be loaded # before initializers and causes configuration not to be respected. - # This is fixed in Rails 5.2 - config.load_defaults 5.1 + config.load_defaults 6.0 config.active_record.belongs_to_required_by_default = false config.active_record.include_root_in_json = true # Make `form_with` generate non-remote forms. Defaults true in Rails 5.1 to 6.0 + config.action_view.form_with_generates_remote_forms = false + # Make Ruby preserve the timezone of the receiver when calling `to_time`. + config.active_support.to_time_preserves_timezone = false + + # Use a modern approved hashing function. + # This is the default in Rails 7.0, so can be removed when we upgrade. + config.active_support.hash_digest_class = OpenSSL::Digest::SHA256 # Applying the patch for CVE-2022-32224 broke YAML deserialization because some classes are disallowed in the serialized YAML - # NOTE: Symbol was later added to enabled classes by default, see https://github.com/rails/rails/pull/45584, - # it was added to Rails 6.0.6, 6.1.7, 7.0.4 config.active_record.yaml_column_permitted_classes = [Symbol, Time, Date, BigDecimal, OpenStruct, ActionController::Parameters, ActiveSupport::TimeWithZone, ActiveSupport::TimeZone, ActiveSupport::HashWithIndifferentAccess] - config.action_view.form_with_generates_remote_forms = false - - # Make Ruby preserve the timezone of the receiver when calling `to_time`. - config.active_support.to_time_preserves_timezone = false - # Use a modern approved hashing function - # config.active_support.hash_digest_class = OpenSSL::Digest::SHA256 - ActiveSupport::Digest.hash_digest_class = OpenSSL::Digest::SHA256 # option above should work with Rails 6.x - # The old config_for gem returns HashWithIndifferentAccess # https://github.com/3scale/config_for/blob/master/lib/config_for/config.rb#L16 @@ -182,13 +178,16 @@ def try_config_for(*args) # We don't want Rack::Cache to be used config.action_dispatch.rack_cache = false - args = config_for(:cache_store) - store_type = args.shift - options = args.extract_options! - servers = args.flat_map { |arg| arg.split(',') } - config.cache_store = [store_type, servers, options] + def cache_store_config + args = config_for(:cache_store) + store_type = args.shift + options = args.extract_options! + options[:digest_class] ||= Digest::SHA256 if store_type == :mem_cache_store + [store_type, *args, options] + end + config.cache_store = cache_store_config - # Configure the default encoding used in templates for Ruby 1.9. + # Configure the default encoding used in templates for Ruby 1.9. config.encoding = "utf-8" config.web_hooks = ActiveSupport::OrderedOptions.new diff --git a/config/boot.rb b/config/boot.rb index 30f5120df6..fd869f358c 100644 --- a/config/boot.rb +++ b/config/boot.rb @@ -1,3 +1,5 @@ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) require 'bundler/setup' # Set up gems listed in the Gemfile. + +require 'bootsnap/setup' unless ENV['RAILS_ENV'] == 'production' # Speed up boot time by caching expensive operations. diff --git a/config/environments/development.rb b/config/environments/development.rb index e4fca8dcd7..dce2276783 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -19,6 +19,9 @@ config.asset_host = config.three_scale.asset_host.presence + # Match custom domains on development + config.hosts << /.+\.localhost/ + config.middleware.insert_before ActionDispatch::Static, Rack::Deflater config.public_file_server.enabled = true diff --git a/config/environments/test.rb b/config/environments/test.rb index 15c4ec1581..7026cb64d3 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -21,6 +21,7 @@ # config.consider_all_requests_local = true config.consider_all_requests_local = false config.action_controller.perform_caching = false + config.cache_store = :null_store # Raise exceptions instead of rendering exception templates. config.action_dispatch.show_exceptions = false diff --git a/config/initializers/application_controller_renderer.rb b/config/initializers/application_controller_renderer.rb index f4556db399..89d2efab2b 100644 --- a/config/initializers/application_controller_renderer.rb +++ b/config/initializers/application_controller_renderer.rb @@ -1,4 +1,3 @@ -# frozen_string_literal: true # Be sure to restart your server when you modify this file. # ActiveSupport::Reloader.to_prepare do diff --git a/config/initializers/content_security_policy.rb b/config/initializers/content_security_policy.rb index d3bcaa5ec8..41c43016f1 100644 --- a/config/initializers/content_security_policy.rb +++ b/config/initializers/content_security_policy.rb @@ -19,6 +19,9 @@ # If you are using UJS then enable automatic nonce generation # Rails.application.config.content_security_policy_nonce_generator = -> request { SecureRandom.base64(16) } +# Set the nonce only to specific directives +# Rails.application.config.content_security_policy_nonce_directives = %w(script-src) + # Report CSP violations to a specified URI # For further information see the following documentation: # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy-Report-Only diff --git a/config/initializers/dalli.rb b/config/initializers/dalli.rb deleted file mode 100644 index 28607126a6..0000000000 --- a/config/initializers/dalli.rb +++ /dev/null @@ -1,23 +0,0 @@ -# Patches dalli to use SHA256 checksum instead of MD5. -# Once we stop supporting Ruby 2.4, we should upgrade dalli -# and see if any configuration is needed for same effect. -# -# key digests were actually fixed with -# https://github.com/petergoldstein/dalli/commit/74b2625f11ff56dd6f55c7316bc115bc5a29be5f - -Dalli::Client.prepend(Module.new do - def validate_key(key) - raise ArgumentError, "key cannot be blank" if !key || key.length == 0 - key = key_with_namespace(key) - if key.length > 250 - digest = Digest::SHA256.hexdigest(key) - truncated_key_separator = ':md5:' - truncated_key_target_size = 249 - # replicating 3.x logic - truncated_key_target_size = truncated_key_target_size + 1 if namespace - max_length_before_namespace = truncated_key_target_size - truncated_key_separator.size - digest.size - key = "#{key[0, max_length_before_namespace]}#{truncated_key_separator}#{digest}" - end - return key - end -end) diff --git a/config/initializers/mime_types.rb b/config/initializers/mime_types.rb index dc1899682b..3e47d1a9d2 100644 --- a/config/initializers/mime_types.rb +++ b/config/initializers/mime_types.rb @@ -2,3 +2,17 @@ # Add new mime types for use in respond_to blocks: # Mime::Type.register "text/richtext", :rtf + +# Extracted from https://github.com/rails/rails/blob/6-1-stable/actionpack/lib/action_dispatch/http/mime_type.rb#L344-L346 +# Mime::NullType has an odd behaviour in Rails 6 due to the check performed in +# https://github.com/rails/rails/blob/6-0-stable/actionpack/lib/action_controller/metal/mime_responds.rb#L208-L210 +# where media_type and format are different even though both are Mime::NullType. +# The to_s method fixes the issue but, unfortunately, it was added only for Rails 6.1+. +# We may removed this patch once we upgrade Rails to 6.1. +module Mime + class NullType + def to_s + '' + end + end +end diff --git a/config/initializers/money.rb b/config/initializers/money.rb index 277219f7e1..5565bb24af 100644 --- a/config/initializers/money.rb +++ b/config/initializers/money.rb @@ -1,9 +1,9 @@ -require 'three_scale/conversions' +require 'three_scale/money_conversions' ActiveSupport.on_load(:active_record) do ActiveRecord::Base.send(:include, ThreeScale::HasMoney) end Rails.application.config.to_prepare do - ActionController::Base.helper(ThreeScale::MoneyHelper) if defined?(ActionController) + ActionController::Base.helper(ThreeScale::MoneyHelper) end diff --git a/config/initializers/new_framework_defaults_5_2.rb b/config/initializers/new_framework_defaults_5_2.rb deleted file mode 100644 index c383d072bc..0000000000 --- a/config/initializers/new_framework_defaults_5_2.rb +++ /dev/null @@ -1,38 +0,0 @@ -# Be sure to restart your server when you modify this file. -# -# This file contains migration options to ease your Rails 5.2 upgrade. -# -# Once upgraded flip defaults one by one to migrate to the new default. -# -# Read the Guide for Upgrading Ruby on Rails for more info on each option. - -# Make Active Record use stable #cache_key alongside new #cache_version method. -# This is needed for recyclable cache keys. -# Rails.application.config.active_record.cache_versioning = true - -# Use AES-256-GCM authenticated encryption for encrypted cookies. -# Also, embed cookie expiry in signed or encrypted cookies for increased security. -# -# This option is not backwards compatible with earlier Rails versions. -# It's best enabled when your entire app is migrated and stable on 5.2. -# -# Existing cookies will be converted on read then written with the new scheme. -# Rails.application.config.action_dispatch.use_authenticated_cookie_encryption = true - -# Use AES-256-GCM authenticated encryption as default cipher for encrypting messages -# instead of AES-256-CBC, when use_authenticated_message_encryption is set to true. -# Rails.application.config.active_support.use_authenticated_message_encryption = true - -# Add default protection from forgery to ActionController::Base instead of in -# ApplicationController. -# Rails.application.config.action_controller.default_protect_from_forgery = true - -# Store boolean values are in sqlite3 databases as 1 and 0 instead of 't' and -# 'f' after migrating old data. -# Rails.application.config.active_record.sqlite3.represent_boolean_as_integer = true - -# Use SHA-1 instead of MD5 to generate non-sensitive digests, such as the ETag header. -# Rails.application.config.active_support.use_sha1_digests = true - -# Make `form_with` generate id attributes for any generated HTML tags. -# Rails.application.config.action_view.form_with_generates_ids = true diff --git a/config/initializers/notifications.rb b/config/initializers/notifications.rb index 7cd1fb24a9..fd5a6e5769 100644 --- a/config/initializers/notifications.rb +++ b/config/initializers/notifications.rb @@ -1 +1 @@ -require_dependency 'tracking_notifications' +require 'tracking_notifications' diff --git a/config/initializers/oracle.rb b/config/initializers/oracle.rb index ab8b28d697..2029f3c75f 100644 --- a/config/initializers/oracle.rb +++ b/config/initializers/oracle.rb @@ -13,7 +13,7 @@ end ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.class_eval do - # see https://github.com/rails/rails/issues/44114 + # Remove when https://github.com/rsim/oracle-enhanced/issues/2237 is fixed self.use_old_oracle_visitor = true end diff --git a/config/initializers/zeitwerk.rb b/config/initializers/zeitwerk.rb new file mode 100644 index 0000000000..79c0377124 --- /dev/null +++ b/config/initializers/zeitwerk.rb @@ -0,0 +1,17 @@ +Rails.autoloaders.main.inflector.inflect( + 'dsl' => 'DSL', + 'csrf' => 'CSRF', + 'sso' => 'SSO', + 'oauth2' => 'OAuth2', + 'provider_oauth2' => 'ProviderOAuth2', + 'find_oauth2_user_service' => 'FindOAuth2UserService', + 'oauth2_base' => 'OAuth2Base', + 'xml' => 'XML', + 'json_representer' => 'JSONRepresenter', + 'json_validator' => 'JSONValidator', + 'by_sso_token' => 'BySSOToken' +) + +Rails.autoloaders.main.ignore( + 'app/lib/forum_support/deprecated/' +) diff --git a/db/oracle_schema.rb b/db/oracle_schema.rb index 991a437c5d..846e82fa68 100644 --- a/db/oracle_schema.rb +++ b/db/oracle_schema.rb @@ -2,11 +2,11 @@ # of editing this file, please use the migrations feature of Active Record to # incrementally modify your database, and then regenerate this schema definition. # -# Note that this schema.rb definition is the authoritative source for your -# database schema. If you need to create the application database on another -# system, you should be using db:schema:load, not running all the migrations -# from scratch. The latter is a flawed and unsustainable approach (the more migrations -# you'll amass, the slower it'll run and the greater likelihood for issues). +# This file is the source Rails uses to define your schema when running `rails +# db:schema:load`. When creating a new database, `rails db:schema:load` tends to +# be faster and is potentially less error prone than running all of your +# migrations from scratch. Old migrations may fail to apply correctly if those +# migrations use external dependencies or application code. # # It's strongly recommended that you check this file into your version control system. diff --git a/db/postgres_schema.rb b/db/postgres_schema.rb index 41c062b9f1..8b94fb84b7 100644 --- a/db/postgres_schema.rb +++ b/db/postgres_schema.rb @@ -2,11 +2,11 @@ # of editing this file, please use the migrations feature of Active Record to # incrementally modify your database, and then regenerate this schema definition. # -# Note that this schema.rb definition is the authoritative source for your -# database schema. If you need to create the application database on another -# system, you should be using db:schema:load, not running all the migrations -# from scratch. The latter is a flawed and unsustainable approach (the more migrations -# you'll amass, the slower it'll run and the greater likelihood for issues). +# This file is the source Rails uses to define your schema when running `rails +# db:schema:load`. When creating a new database, `rails db:schema:load` tends to +# be faster and is potentially less error prone than running all of your +# migrations from scratch. Old migrations may fail to apply correctly if those +# migrations use external dependencies or application code. # # It's strongly recommended that you check this file into your version control system. diff --git a/db/schema.rb b/db/schema.rb index 3424168336..e709afc166 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -2,11 +2,11 @@ # of editing this file, please use the migrations feature of Active Record to # incrementally modify your database, and then regenerate this schema definition. # -# Note that this schema.rb definition is the authoritative source for your -# database schema. If you need to create the application database on another -# system, you should be using db:schema:load, not running all the migrations -# from scratch. The latter is a flawed and unsustainable approach (the more migrations -# you'll amass, the slower it'll run and the greater likelihood for issues). +# This file is the source Rails uses to define your schema when running `rails +# db:schema:load`. When creating a new database, `rails db:schema:load` tends to +# be faster and is potentially less error prone than running all of your +# migrations from scratch. Old migrations may fail to apply correctly if those +# migrations use external dependencies or application code. # # It's strongly recommended that you check this file into your version control system. @@ -126,7 +126,7 @@ t.bigint "account_id" t.bigint "tenant_id" t.string "name" - t.text "body", limit: 4294967295 + t.text "body", size: :long t.text "description" t.boolean "published", default: false t.datetime "created_at" @@ -162,7 +162,7 @@ t.bigint "tenant_id" t.bigint "provider_id" t.string "kind" - t.text "audited_changes", limit: 16777215 + t.text "audited_changes", size: :medium t.text "comment" t.integer "associated_id" t.string "associated_type" @@ -222,7 +222,7 @@ create_table "backend_apis", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin", force: :cascade do |t| t.string "name", limit: 511, null: false t.string "system_name", null: false - t.text "description", limit: 16777215 + t.text "description", size: :medium t.string "private_endpoint" t.bigint "account_id" t.datetime "created_at", null: false @@ -390,8 +390,8 @@ t.string "path" t.string "title" t.string "system_name" - t.text "published", limit: 16777215 - t.text "draft", limit: 16777215 + t.text "published", size: :medium + t.text "draft", size: :medium t.boolean "liquid_enabled" t.string "content_type" t.datetime "created_at" @@ -418,8 +418,8 @@ t.string "path" t.string "title" t.string "system_name" - t.text "published", limit: 16777215 - t.text "draft", limit: 16777215 + t.text "published", size: :medium + t.text "draft", size: :medium t.boolean "liquid_enabled" t.string "content_type" t.datetime "created_at" @@ -492,7 +492,7 @@ t.string "stream", null: false t.string "event_type", null: false t.string "event_id", null: false - t.text "metadata", limit: 16777215 + t.text "metadata", size: :medium t.text "data" t.datetime "created_at", null: false t.bigint "provider_id" @@ -676,7 +676,7 @@ t.integer "version" t.string "name" t.string "slug" - t.text "body", limit: 4294967295 + t.text "body", size: :long t.datetime "created_at" t.datetime "updated_at" t.boolean "published", default: false @@ -693,7 +693,7 @@ t.integer "lock_version", default: 0 t.string "name" t.string "slug" - t.text "body", limit: 4294967295 + t.text "body", size: :long t.datetime "created_at" t.datetime "updated_at" t.boolean "published", default: false @@ -940,7 +940,7 @@ t.bigint "issuer_id", null: false t.string "name" t.string "rights" - t.text "full_legal", limit: 4294967295 + t.text "full_legal", size: :long t.decimal "cost_per_month", precision: 20, scale: 4, default: "0.0", null: false t.integer "trial_period_days" t.datetime "created_at" @@ -968,7 +968,7 @@ create_table "policies", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin", force: :cascade do |t| t.string "name", null: false t.string "version", null: false - t.binary "schema", limit: 4294967295, null: false + t.binary "schema", size: :long, null: false t.bigint "account_id", null: false t.bigint "tenant_id" t.datetime "created_at" @@ -1082,7 +1082,7 @@ t.string "oidc_issuer_endpoint" t.bigint "lock_version", default: 0, null: false t.string "authentication_method" - t.text "policies_config", limit: 16777215 + t.text "policies_config", size: :medium t.string "oidc_issuer_type", default: "keycloak" t.string "error_headers_limits_exceeded", default: "text/plain; charset=us-ascii" t.integer "error_status_limits_exceeded", default: 429 @@ -1106,7 +1106,7 @@ t.integer "version", default: 0, null: false t.bigint "tenant_id" t.string "environment", null: false - t.text "content", limit: 16777215, null: false + t.text "content", size: :medium, null: false t.datetime "created_at", null: false t.datetime "updated_at", null: false t.string "hosts", limit: 8192 @@ -1118,7 +1118,7 @@ create_table "proxy_logs", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin", force: :cascade do |t| t.bigint "provider_id" t.bigint "tenant_id" - t.text "lua_file", limit: 16777215 + t.text "lua_file", size: :medium t.string "status" t.datetime "created_at" t.datetime "updated_at" diff --git a/db/seeds.rb b/db/seeds.rb index 1ff0832b83..ff1fdb08d0 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -172,10 +172,10 @@ impersonation_admin.signup_type = :minimal impersonation_admin_config = ThreeScale.config.impersonation_admin - impersonation_admin_username = impersonation_admin_config['username'] + impersonation_admin_username = impersonation_admin_config[:username] impersonation_admin.attributes = { username: impersonation_admin_username, - email: "#{impersonation_admin_username}+#{provider.external_admin_domain}@#{impersonation_admin_config['domain']}", + email: "#{impersonation_admin_username}+#{provider.external_admin_domain}@#{impersonation_admin_config[:domain]}", first_name: '3scale', last_name: 'Admin' } diff --git a/features/step_definitions/provider_steps.rb b/features/step_definitions/provider_steps.rb index eccd397ee4..b60b192e2c 100644 --- a/features/step_definitions/provider_steps.rb +++ b/features/step_definitions/provider_steps.rb @@ -46,7 +46,7 @@ def import_simple_layout(provider) step %(a provider "#{provider_name}") provider = Account.find_by_org_name(provider_name) if provider.admins.impersonation_admins.empty? - FactoryBot.create :active_admin, username: ThreeScale.config.impersonation_admin['username'], account: provider + FactoryBot.create :active_admin, username: ThreeScale.config.impersonation_admin[:username], account: provider end end diff --git a/features/support/capybara.rb b/features/support/capybara.rb index 3c1b9cdaa0..94a7360374 100644 --- a/features/support/capybara.rb +++ b/features/support/capybara.rb @@ -28,7 +28,7 @@ config.raise_server_errors = true config.match = :prefer_exact config.always_include_port = true - config.default_max_wait_time = 2 + config.default_max_wait_time = 10 end # Needed because cucumber-rails requires capybara/cucumber diff --git a/lib/active_job/serializers/date_time_serializer.rb b/lib/active_job/serializers/date_time_serializer.rb index 958a3ea8ac..a9076dd45d 100644 --- a/lib/active_job/serializers/date_time_serializer.rb +++ b/lib/active_job/serializers/date_time_serializer.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require 'active_job/serializers/time_object_serializer' + module ActiveJob module Serializers class DateTimeSerializer < TimeObjectSerializer # :nodoc: diff --git a/lib/developer_portal/app/controllers/developer_portal/accounts/invitee_signups_controller.rb b/lib/developer_portal/app/controllers/developer_portal/accounts/invitee_signups_controller.rb index 8bd79151c5..d20aad3af8 100644 --- a/lib/developer_portal/app/controllers/developer_portal/accounts/invitee_signups_controller.rb +++ b/lib/developer_portal/app/controllers/developer_portal/accounts/invitee_signups_controller.rb @@ -21,7 +21,7 @@ def sso_create request: request, invitation: @invitation }), - procedure: Authentication::Strategy::Oauth2::CreateInvitedUser + procedure: Authentication::Strategy::OAuth2::CreateInvitedUser ) if signup_user diff --git a/lib/developer_portal/app/controllers/developer_portal/teapot_controller.rb b/lib/developer_portal/app/controllers/developer_portal/teapot_controller.rb index bc9f2a28db..1c5f85b508 100644 --- a/lib/developer_portal/app/controllers/developer_portal/teapot_controller.rb +++ b/lib/developer_portal/app/controllers/developer_portal/teapot_controller.rb @@ -1,4 +1,4 @@ -require_dependency "developer_portal/application_controller" +# frozen_string_literal: true module DeveloperPortal class TeapotController < ApplicationController diff --git a/lib/developer_portal/lib/cms/toolbar.rb b/lib/developer_portal/lib/cms/toolbar.rb index a2fa2d8039..77769dfc8e 100644 --- a/lib/developer_portal/lib/cms/toolbar.rb +++ b/lib/developer_portal/lib/cms/toolbar.rb @@ -39,7 +39,7 @@ def cms_toolbar_enabled? return false if @_exception_handled is_cms_domain = site_account.provider? && !site_account.master? # => buyer domain - is_html_content = response.content_type.nil? || response.content_type == 'text/html' #=> only for html content type + is_html_content = response.media_type.nil? || response.media_type == 'text/html' #=> only for html content type return false unless is_cms_domain return false unless is_html_content @@ -68,7 +68,13 @@ def cms_toolbar_with_iframe_html controller = self - view = CMS::Toolbar::View.new(lookup_context, cms_toolbar.assigns, controller, [:html]) + # When on development we want to clear the view cache on every request, this should be automatic, but after + # https://github.com/rails/rails/pull/35623 and https://github.com/rails/rails/pull/35629 this no longer works + # for hacked views like the +CMS::Toolbar::View+. So we have to manually clear the cache. Otherwise, we'll have + # to restart the server after every change in this file. + ActionView::LookupContext::DetailsKey.clear unless Rails.env.production? + + view = CMS::Toolbar::View.new(lookup_context, cms_toolbar.assigns, controller) view._routes = _routes view.render 'shared/cms/toolbar', :site_account => site_account, diff --git a/lib/developer_portal/lib/liquid/template/fallback_resolver.rb b/lib/developer_portal/lib/liquid/template/fallback_resolver.rb index 22a87b5690..27908d0ec2 100644 --- a/lib/developer_portal/lib/liquid/template/fallback_resolver.rb +++ b/lib/developer_portal/lib/liquid/template/fallback_resolver.rb @@ -1,28 +1,29 @@ +# frozen_string_literal: true + module Liquid class Template class FallbackResolver < ActionView::FileSystemResolver - def initialize(path = DeveloperPortal::VIEW_PATH) super end - def find_templates(name, prefix, partial, details, outside_app_allowed = false) + def _find_all(name, prefix, partial, details, key = nil, locals = []) path = build_path(name, prefix, partial) # force just liquid format details = details.merge(handlers: [:liquid]) - query(path, details, details[:formats], outside_app_allowed) + query(path, details, details[:formats], locals, cache: !!key) end def build_path(name, prefix, partial) prefix = prefix ? [prefix] : [] prefix = ::File.join(*prefix) ::Rails.logger.debug { "FallbackResolver: path: #{[name, prefix, partial].inspect}" } - super + Path.build(name, prefix, partial) end - public :find_templates + public :_find_all end end end diff --git a/lib/developer_portal/lib/liquid/template/fallback_resolver_no_prefix.rb b/lib/developer_portal/lib/liquid/template/fallback_resolver_no_prefix.rb index 06b615fd21..b5d95f64b5 100644 --- a/lib/developer_portal/lib/liquid/template/fallback_resolver_no_prefix.rb +++ b/lib/developer_portal/lib/liquid/template/fallback_resolver_no_prefix.rb @@ -8,15 +8,14 @@ def initialize(path = DeveloperPortal::VIEW_PATH) super end - def find_templates(name, prefix, partial, details, outside_app_allowed = false) + def _find_all(name, prefix, partial, details, key = nil, locals = []) path = build_path(name, prefix = nil, partial) # force just liquid format details = details.merge(handlers: [:liquid]) - query(path, details, details[:formats], outside_app_allowed) + query(path, details, details[:formats], locals, cache: !!key) end - end end end diff --git a/lib/developer_portal/lib/liquid/template/resolver.rb b/lib/developer_portal/lib/liquid/template/resolver.rb index 1bbc98229c..1f28869b6a 100644 --- a/lib/developer_portal/lib/liquid/template/resolver.rb +++ b/lib/developer_portal/lib/liquid/template/resolver.rb @@ -22,14 +22,13 @@ def initialize(scope) super() end - def find_templates(name, prefix, partial, _details, _outside_app_allowed = false) + def _find_all(name, prefix, partial, details, key = nil, locals = []) path = Path.build(name, prefix, partial) @scope.templates.for_rails_view(path).map do |record| Liquid::Template::View.from(record, path, cms) end end - end end end diff --git a/lib/developer_portal/lib/liquid/template/view.rb b/lib/developer_portal/lib/liquid/template/view.rb index d49b1b0b57..abe8aa138a 100644 --- a/lib/developer_portal/lib/liquid/template/view.rb +++ b/lib/developer_portal/lib/liquid/template/view.rb @@ -3,9 +3,17 @@ class Template class View < ActionView::Template attr_reader :record - def initialize(source, ident, handler, details) - source ||= '' # in case template is nil - super + def initialize(source = '', identifier, handler, details) + super( + source, + identifier, + handler, + locals: [], + format: nil, + variant: details[:variant], + virtual_path: details[:virtual_path] + ) + @record = details.fetch(:record) end diff --git a/lib/system/database.rb b/lib/system/database.rb index 72d38bcbb1..ef4b8fe0d7 100644 --- a/lib/system/database.rb +++ b/lib/system/database.rb @@ -14,9 +14,9 @@ def configuration_specification def read_configuration_specification configurations = Rails.application.config.database_configuration resolver = ActiveRecord::ConnectionAdapters::ConnectionSpecification::Resolver.new(configurations) - spec = ActiveRecord::ConnectionHandling::DEFAULT_ENV.call.to_sym + spec = ActiveRecord::ConnectionHandling::DEFAULT_ENV.call - resolver.spec(spec) + resolver.spec(resolver.configurations[spec]) end def adapter diff --git a/lib/tasks/fixes.rake b/lib/tasks/fixes.rake index 92811920f6..892e784489 100644 --- a/lib/tasks/fixes.rake +++ b/lib/tasks/fixes.rake @@ -23,8 +23,8 @@ namespace :fixes do desc "updates impersonation_admin email address" task :update_impersonation_admin_email => :environment do impersonation_admin_config = ThreeScale.config.impersonation_admin - impersonation_admin_username = impersonation_admin_config['username'] - impersonation_admin_domain = impersonation_admin_config['domain'] + impersonation_admin_username = impersonation_admin_config[:username] + impersonation_admin_domain = impersonation_admin_config[:domain] users= User.where(email: "#{impersonation_admin_username}@#{impersonation_admin_domain}") users.each do | user | diff --git a/lib/three_scale/conversions.rb b/lib/three_scale/money_conversions.rb similarity index 84% rename from lib/three_scale/conversions.rb rename to lib/three_scale/money_conversions.rb index 9d38b853c5..1c5f101493 100644 --- a/lib/three_scale/conversions.rb +++ b/lib/three_scale/money_conversions.rb @@ -1,14 +1,14 @@ # frozen_string_literal: true module ThreeScale - module Conversions + module MoneyConversions def to_has_money(currency, date = nil) ThreeScale::Money.new(self, currency, date) end end # Enhance numeric types with +to_has_money+ method. - Numeric.send(:include, Conversions) + Numeric.send(:include, MoneyConversions) # Enhance String with +to_has_money+ method. class ::String diff --git a/test/functional/buyers/impersonations_controller_test.rb b/test/functional/buyers/impersonations_controller_test.rb index 353b8e6da2..a7eaaa73ec 100644 --- a/test/functional/buyers/impersonations_controller_test.rb +++ b/test/functional/buyers/impersonations_controller_test.rb @@ -26,7 +26,7 @@ def setup end test "should impersonate a provider" do - user = FactoryBot.create :active_admin, username: ThreeScale.config.impersonation_admin['username'], :account => @provider + user = FactoryBot.create :active_admin, username: ThreeScale.config.impersonation_admin[:username], :account => @provider @provider.reload login_provider master_account @@ -37,7 +37,7 @@ def setup end test "api mode should return an url to impersonate a provider" do - user = FactoryBot.create :active_admin, username: ThreeScale.config.impersonation_admin['username'], :account => @provider + user = FactoryBot.create :active_admin, username: ThreeScale.config.impersonation_admin[:username], :account => @provider @provider.reload login_provider master_account diff --git a/test/functional/developer_portal/admin/account/account_plans_controller_test.rb b/test/functional/developer_portal/admin/account/account_plans_controller_test.rb index 4c7ccb2504..36de5ed7b5 100644 --- a/test/functional/developer_portal/admin/account/account_plans_controller_test.rb +++ b/test/functional/developer_portal/admin/account/account_plans_controller_test.rb @@ -67,7 +67,7 @@ def setup provider_key: 'fake', username: 'bob' } assert_response :forbidden - assert_equal 'application/xml', @response.content_type + assert_equal 'application/xml', @response.media_type assert_select 'error', 'provider_key is invalid' end @@ -85,7 +85,7 @@ def setup username: 'fake' } assert_response :forbidden - assert_equal 'application/xml', @response.content_type + assert_equal 'application/xml', @response.media_type assert_select 'error', 'username is invalid' end diff --git a/test/functional/developer_portal/signup_controller_test.rb b/test/functional/developer_portal/signup_controller_test.rb index 888458b479..022f705c0c 100644 --- a/test/functional/developer_portal/signup_controller_test.rb +++ b/test/functional/developer_portal/signup_controller_test.rb @@ -35,7 +35,7 @@ class WithDefaultAccountPlan < DeveloperPortal::SignupControllerTest session[:authentication_id] = 'A1234' session[:authentication_provider] = auth_provider.system_name # First check that the confirmation link is send - perform_enqueued_jobs(only: ActionMailer::DeliveryJob) do + perform_enqueued_jobs(only: ActionMailer::MailDeliveryJob) do post :create, params: valid_buyer_params end assert_response :redirect @@ -51,7 +51,7 @@ class WithDefaultAccountPlan < DeveloperPortal::SignupControllerTest session[:authentication_id] = 'A1234' session[:authentication_provider] = auth_provider.system_name session[:authentication_email] = valid_buyer_params.dig(:account, :user, :email) - perform_enqueued_jobs(only: ActionMailer::DeliveryJob) do + perform_enqueued_jobs(only: ActionMailer::MailDeliveryJob) do post :create, params: valid_buyer_params end assert_response :redirect diff --git a/test/integration/api/sso_tokens_controller_test.rb b/test/integration/api/sso_tokens_controller_test.rb index eee2e2d1be..e42a64bd5a 100644 --- a/test/integration/api/sso_tokens_controller_test.rb +++ b/test/integration/api/sso_tokens_controller_test.rb @@ -38,7 +38,7 @@ def setup end test 'provider_create' do - FactoryBot.create(:simple_admin, account: @provider, username: ThreeScale.config.impersonation_admin['username']) + FactoryBot.create(:simple_admin, account: @provider, username: ThreeScale.config.impersonation_admin[:username]) post provider_create_admin_api_sso_tokens_path(format: :json), params: { provider_id: @provider.id, access_token: @access_token.value } assert_response :success @@ -48,7 +48,7 @@ def setup end test 'provider_create with expires_in' do - FactoryBot.create(:simple_admin, account: @provider, username: ThreeScale.config.impersonation_admin['username']) + FactoryBot.create(:simple_admin, account: @provider, username: ThreeScale.config.impersonation_admin[:username]) freeze_time do post provider_create_admin_api_sso_tokens_path(format: :json), params: { provider_id: @provider.id, access_token: @access_token.value, expires_in: 60 } @@ -59,4 +59,3 @@ def setup end end end - diff --git a/test/integration/by_sso_token_test.rb b/test/integration/by_sso_token_test.rb index 1ec5268cfa..d25289b04c 100644 --- a/test/integration/by_sso_token_test.rb +++ b/test/integration/by_sso_token_test.rb @@ -10,7 +10,7 @@ def setup def test_sso_token # apicast mapping service use case - FactoryBot.create(:active_admin, account: @account, username: ThreeScale.config.impersonation_admin['username']) + FactoryBot.create(:active_admin, account: @account, username: ThreeScale.config.impersonation_admin[:username]) host! Account.master.internal_admin_domain post provider_create_admin_api_sso_tokens_path(format: :json), params: { provider_key: @master.api_key, provider_id: @account.id } sso_token = JSON.parse(response.body)['sso_token'] diff --git a/test/integration/developer_portal/invitation_signup_test.rb b/test/integration/developer_portal/invitation_signup_test.rb index e2296d5527..e2dc521a4e 100644 --- a/test/integration/developer_portal/invitation_signup_test.rb +++ b/test/integration/developer_portal/invitation_signup_test.rb @@ -3,7 +3,7 @@ class DeveloperPortal::InvitationSignupTest < ActionDispatch::IntegrationTest include System::UrlHelpers.cms_url_helpers - Oauth2 = Authentication::Strategy::Oauth2 + OAuth2 = Authentication::Strategy::OAuth2 def setup @provider = FactoryBot.create(:simple_provider) @@ -23,8 +23,8 @@ def test_show # sso attributes do exist, sso authorization object should be built # and therefore, user password should not be required - Oauth2.any_instance.stubs(:authentication_provider).returns(@auth_provider) - Oauth2.any_instance.expects(:user_data).returns({ uid: '12345' }) + OAuth2.any_instance.stubs(:authentication_provider).returns(@auth_provider) + OAuth2.any_instance.expects(:user_data).returns({ uid: '12345' }) get "/auth/invitations/#{@invitation.token}/github/callback" assert_response :success get invitee_signup_path(invitation_token: @invitation.token) @@ -63,38 +63,38 @@ def test_builtin_page def test_auth0_sso_create user = FactoryBot.create(:simple_user, account: @buyer) - Oauth2.any_instance.expects(:authenticate).returns(user).at_least_once + OAuth2.any_instance.expects(:authenticate).returns(user).at_least_once get "/auth/invitations/auth0/auth0_ab1234/callback?state=#{@invitation.token}" assert_response :redirect assert_equal 'Signed up successfully', flash[:notice] end def test_sso_create - Oauth2.any_instance.stubs(:authentication_provider).returns(@auth_provider) - Oauth2.any_instance.expects(:authenticate).returns(false).at_least_once + OAuth2.any_instance.stubs(:authentication_provider).returns(@auth_provider) + OAuth2.any_instance.expects(:authenticate).returns(false).at_least_once get "/auth/invitations/#{@invitation.token}/github/callback" assert_response :success assert session[:invitation_sso_uid].blank? refute assigns(:user).valid? - Oauth2.any_instance.expects(:user_data).returns({ uid: '12345' }) + OAuth2.any_instance.expects(:user_data).returns({ uid: '12345' }) get "/auth/invitations/#{@invitation.token}/github/callback" assert_response :success assert_equal '12345', session[:invitation_sso_uid] refute assigns(:user).valid? user = FactoryBot.create(:simple_user, account: @buyer) - Oauth2.any_instance.expects(:authenticate).returns(user).at_least_once + OAuth2.any_instance.expects(:authenticate).returns(user).at_least_once get "/auth/invitations/#{@invitation.token}/github/callback" assert_response :redirect assert_equal 'Signed up successfully', flash[:notice] end def test_error_sso_create - Oauth2.any_instance.stubs(:authentication_provider).returns(@auth_provider) - Oauth2.any_instance.expects(:authenticate).returns(false).at_least_once + OAuth2.any_instance.stubs(:authentication_provider).returns(@auth_provider) + OAuth2.any_instance.expects(:authenticate).returns(false).at_least_once error_data = ThreeScale::OAuth2::ErrorData.new(error: 'The code is incorrect or expired.') - Oauth2.any_instance.expects(:user_data).returns(error_data) + OAuth2.any_instance.expects(:user_data).returns(error_data) get "/auth/invitations/#{@invitation.token}/github/callback" assert_response :success @@ -103,7 +103,7 @@ def test_error_sso_create end def test_create - Oauth2.any_instance.stubs(:authentication_provider).returns(@auth_provider) + OAuth2.any_instance.stubs(:authentication_provider).returns(@auth_provider) assert_difference '@buyer.users.count' do post invitee_signup_path(invitation_token: @invitation.token, user: user_valid_params) diff --git a/test/integration/developer_portal/login_test.rb b/test/integration/developer_portal/login_test.rb index 284007a29a..ae7d9a3ffe 100644 --- a/test/integration/developer_portal/login_test.rb +++ b/test/integration/developer_portal/login_test.rb @@ -82,7 +82,7 @@ def test_create_approval_required @provider.authentication_providers.update_all(automatically_approve_accounts: false) stub_user_data(uid: 'uid1', email: 'foo@example.com', username: 'foo', org_name: 'company', email_verified: true) stub_oauth2_request - perform_enqueued_jobs(only: ActionMailer::DeliveryJob) do + perform_enqueued_jobs(only: ActionMailer::MailDeliveryJob) do post session_path(system_name: @auth.system_name, code: 'example') end assert_match "Your account isn't active or hasn't been approved yet.", flash[:error] diff --git a/test/integration/notifications_test.rb b/test/integration/notifications_test.rb index 3563d928fd..6c2881bb28 100644 --- a/test/integration/notifications_test.rb +++ b/test/integration/notifications_test.rb @@ -59,7 +59,7 @@ def setup MailDispatchRule.delete_all @message.save! - perform_enqueued_jobs(only: ActionMailer::DeliveryJob) { @message.deliver! } + perform_enqueued_jobs(only: ActionMailer::MailDeliveryJob) { @message.deliver! } @message_recipient = @provider_recipient.received_messages.last assert_equal true, @message_recipient.notifiable? @@ -71,7 +71,7 @@ def setup @message.system_operation = @operation @message.save! - perform_enqueued_jobs(only: ActionMailer::DeliveryJob) { @message.deliver! } + perform_enqueued_jobs(only: ActionMailer::MailDeliveryJob) { @message.deliver! } @message_recipient = @provider_recipient.received_messages.last assert_equal false, @message_recipient.notifiable? @@ -82,7 +82,7 @@ def setup assert_difference ActionMailer::Base.deliveries.method(:count) do @message.save! - perform_enqueued_jobs(only: ActionMailer::DeliveryJob) { @message.deliver! } + perform_enqueued_jobs(only: ActionMailer::MailDeliveryJob) { @message.deliver! } end @message_recipient = @provider_recipient.received_messages.last @@ -96,7 +96,7 @@ def setup assert_no_difference ActionMailer::Base.deliveries.method(:count) do @message.save! - perform_enqueued_jobs(only: ActionMailer::DeliveryJob) { @message.deliver! } + perform_enqueued_jobs(only: ActionMailer::MailDeliveryJob) { @message.deliver! } end end @@ -104,7 +104,7 @@ def setup @rule = FactoryBot.create(:mail_dispatch_rule, account: @provider_recipient, dispatch: false, system_operation: @operation) @message.save! - perform_enqueued_jobs(only: ActionMailer::DeliveryJob) { @message.deliver! } + perform_enqueued_jobs(only: ActionMailer::MailDeliveryJob) { @message.deliver! } @message_recipient = @provider_recipient.received_messages.last assert_equal @message_recipient.notifiable?, false @@ -113,7 +113,7 @@ def setup test 'notify recipient when operation has no corresponding system operation' do @message.update(system_operation: nil) @message.save! - perform_enqueued_jobs(only: ActionMailer::DeliveryJob) { @message.deliver! } + perform_enqueued_jobs(only: ActionMailer::MailDeliveryJob) { @message.deliver! } @message_recipient = @provider_recipient.received_messages.last assert_equal true, @message_recipient.notifiable? @@ -190,7 +190,7 @@ def setup end test 'be notified' do - perform_enqueued_jobs(only: ActionMailer::DeliveryJob) { @buyer.buy! @plan } + perform_enqueued_jobs(only: ActionMailer::MailDeliveryJob) { @buyer.buy! @plan } assert_includes ActionMailer::Base.deliveries.last.bcc, @admin.email end @@ -199,7 +199,7 @@ def setup rule = @provider.mail_dispatch_rules.create!(system_operation: op, emails: @admin.email) rule.update(dispatch: false) - perform_enqueued_jobs(only: ActionMailer::DeliveryJob) { @buyer.buy! @plan } + perform_enqueued_jobs(only: ActionMailer::MailDeliveryJob) { @buyer.buy! @plan } assert ActionMailer::Base.deliveries.empty? end @@ -222,7 +222,7 @@ def setup test 'notify admins' do @mail_rule.update(dispatch: true) - perform_enqueued_jobs(only: ActionMailer::DeliveryJob) { @buyer.make_pending! } + perform_enqueued_jobs(only: ActionMailer::MailDeliveryJob) { @buyer.make_pending! } assert_includes ActionMailer::Base.deliveries.map(&:bcc).flatten, @admin.email end @@ -230,7 +230,7 @@ def setup test 'not notify admins if mail_dispatch_rule denies it' do @mail_rule.update(dispatch: false) - perform_enqueued_jobs(only: ActionMailer::DeliveryJob) { @buyer.make_pending! } + perform_enqueued_jobs(only: ActionMailer::MailDeliveryJob) { @buyer.make_pending! } assert_not_includes ActionMailer::Base.deliveries.map(&:bcc).flatten, @admin.email end diff --git a/test/integration/provider/admin/account/authentication_provider_flow_testing_test.rb b/test/integration/provider/admin/account/authentication_provider_flow_testing_test.rb index 2f20955b80..4e39607124 100644 --- a/test/integration/provider/admin/account/authentication_provider_flow_testing_test.rb +++ b/test/integration/provider/admin/account/authentication_provider_flow_testing_test.rb @@ -18,20 +18,20 @@ def test_flow_testing end def test_flow_testing_callback - Authentication::Strategy::ProviderOauth2.any_instance.stubs(:authentication_provider).returns(@auth_provider) - Authentication::Strategy::ProviderOauth2.any_instance.expects(:authenticate).returns(nil) + Authentication::Strategy::ProviderOAuth2.any_instance.stubs(:authentication_provider).returns(@auth_provider) + Authentication::Strategy::ProviderOAuth2.any_instance.expects(:authenticate).returns(nil) get provider_admin_account_flow_testing_callback_url(system_name: @auth_provider.system_name) assert_nil flash[:success] - Authentication::Strategy::ProviderOauth2.any_instance.expects(:authenticate).returns(@user) + Authentication::Strategy::ProviderOAuth2.any_instance.expects(:authenticate).returns(@user) get provider_admin_account_flow_testing_callback_url(system_name: @auth_provider.system_name) assert_match 'Authentication flow successfully tested.', flash[:success] end def test_unsuccessful_callback - Authentication::Strategy::ProviderOauth2.any_instance.stubs(:authentication_provider).returns(@auth_provider) - Authentication::Strategy::ProviderOauth2.any_instance.stubs(:error_message).returns('some oauth error') - Authentication::Strategy::ProviderOauth2.any_instance.expects(:authenticate).returns(false) + Authentication::Strategy::ProviderOAuth2.any_instance.stubs(:authentication_provider).returns(@auth_provider) + Authentication::Strategy::ProviderOAuth2.any_instance.stubs(:error_message).returns('some oauth error') + Authentication::Strategy::ProviderOAuth2.any_instance.expects(:authenticate).returns(false) get provider_admin_account_flow_testing_callback_url(system_name: @auth_provider.system_name) assert_match 'some oauth error', flash[:error] end diff --git a/test/integration/provider/admin/applications/applications_controller_test.rb b/test/integration/provider/admin/applications/applications_controller_test.rb index 8cd089f9a1..ae270630df 100644 --- a/test/integration/provider/admin/applications/applications_controller_test.rb +++ b/test/integration/provider/admin/applications/applications_controller_test.rb @@ -270,7 +270,7 @@ def setup Logic::RollingUpdates.expects(skipped?: true).at_least_once ActionMailer::Base.deliveries = [] - perform_enqueued_jobs(only: ActionMailer::DeliveryJob) do + perform_enqueued_jobs(only: ActionMailer::MailDeliveryJob) do put change_plan_provider_admin_application_path(cinstance), params: { cinstance: { plan_id: new_plan.id } } end diff --git a/test/integration/sessions_test.rb b/test/integration/sessions_test.rb index 01034d93e6..4729431ae5 100644 --- a/test/integration/sessions_test.rb +++ b/test/integration/sessions_test.rb @@ -13,7 +13,7 @@ def setup provider_user = FactoryBot.create(:user, account: @provider) provider_user.activate! - Authentication::Strategy::ProviderOauth2.any_instance.expects(:authenticate).returns(provider_user) + Authentication::Strategy::ProviderOAuth2.any_instance.expects(:authenticate).returns(provider_user) open_session do |session| session.host! @provider.external_admin_domain diff --git a/test/integration/stats/api/applications_test.rb b/test/integration/stats/api/applications_test.rb index 4813185d51..f9437b4768 100644 --- a/test/integration/stats/api/applications_test.rb +++ b/test/integration/stats/api/applications_test.rb @@ -16,7 +16,7 @@ def setup } assert_response :success - assert_content_type 'application/json' + assert_media_type 'application/json' response = ActiveSupport::JSON.decode(@response.body) assert_equal response["values"], [0] * 25 diff --git a/test/integration/stats/authentication_test.rb b/test/integration/stats/authentication_test.rb index 5e352b79e3..9bbd3a3c27 100644 --- a/test/integration/stats/authentication_test.rb +++ b/test/integration/stats/authentication_test.rb @@ -14,19 +14,19 @@ def setup params = { period: 'day', metric_name: 'hits' } get usage_stats_data_services_path(@service, format: :json), params: params.merge(provider_key: @provider_account.api_key) assert_response :success - assert_content_type 'application/json' + assert_media_type 'application/json' token = FactoryBot.create(:access_token, owner: @provider_account.first_admin, scopes: ['stats']) get usage_stats_data_services_path(@service, format: :json), params: params.merge(access_token: token.value) assert_response :success - assert_content_type 'application/json' + assert_media_type 'application/json' end test 'access forbidden without authentication' do get usage_stats_data_services_path(@service, format: :json), params: { period: 'day', metric_name: "hits" } assert_response :forbidden - assert_content_type 'application/json' + assert_media_type 'application/json' assert_json 'status' => 'Forbidden' end diff --git a/test/integration/stats/clients_test.rb b/test/integration/stats/clients_test.rb index 70c1050106..56b4572833 100644 --- a/test/integration/stats/clients_test.rb +++ b/test/integration/stats/clients_test.rb @@ -37,7 +37,7 @@ def setup get usage_stats_api_applications_path(@cinstance, format: :json), params: { period: 'month', metric_name: @metric.system_name, skip_change: false } assert_response :success - assert_content_type 'application/json' + assert_media_type 'application/json' assert_json "period"=> {"name"=>"month", "granularity"=>"day", @@ -78,7 +78,7 @@ def setup get usage_response_code_stats_api_applications_path(@cinstance, format: :json), params: { period: 'month', response_code: 200 } assert_response :success - assert_content_type 'application/json' + assert_media_type 'application/json' assert_json "response_code" => {'code' => '200'}, "period"=> {"name"=>"month", @@ -101,7 +101,7 @@ def setup get usage_response_code_stats_api_applications_path(@cinstance, format: :json), params: { period: 'month', response_code: 404 } assert_response :success - assert_content_type 'application/json' + assert_media_type 'application/json' assert_json "response_code" => {'code' => '404'}, "period"=> {"name"=>"month", diff --git a/test/integration/stats/data/backend_apis_controller_test.rb b/test/integration/stats/data/backend_apis_controller_test.rb index 62346b94f4..ccedfd269f 100644 --- a/test/integration/stats/data/backend_apis_controller_test.rb +++ b/test/integration/stats/data/backend_apis_controller_test.rb @@ -18,7 +18,7 @@ def setup get usage_stats_data_backend_apis_path(backend_api, format: :json, access_token: access_token.value), params: stats_params assert_response :success - assert_content_type 'application/json' + assert_media_type 'application/json' expected_response = { metric: metric.attributes.slice('id', 'system_name', 'unit').merge(name: metric.friendly_name), diff --git a/test/integration/stats/data/requests_to_api_test.rb b/test/integration/stats/data/requests_to_api_test.rb index a3409c8fbc..076b6c7559 100644 --- a/test/integration/stats/data/requests_to_api_test.rb +++ b/test/integration/stats/data/requests_to_api_test.rb @@ -69,21 +69,21 @@ def setup params = { period: 'day', metric_name: "hits", provider_key: @provider_account.api_key } get usage_stats_data_applications_path(@application, format: :json), params: params assert_response :success - assert_content_type 'application/json' + assert_media_type 'application/json' end test 'respond on xml for applications' do params = { period: 'day', metric_name: "hits", provider_key: @provider_account.api_key } get usage_stats_data_applications_path(@application, format: :xml), params: params assert_response :success - assert_content_type 'application/xml' + assert_media_type 'application/xml' end test 'not returning change if asked' do params = { period: 'day', metric_name: "hits", provider_key: @provider_account.api_key, skip_change: 'false' } get usage_stats_data_applications_path(@application, format: :xml), params: params assert_response :success - assert_content_type 'application/xml' + assert_media_type 'application/xml' assert_no_match 'change', @response.body end @@ -92,7 +92,7 @@ def setup get usage_stats_data_applications_path(@application, format: :json), params: params assert_response :success assert_not data['change'] - assert_content_type 'application/json' + assert_media_type 'application/json' end test 'returning change if asked' do @@ -100,21 +100,21 @@ def setup get usage_stats_data_applications_path(@application, format: :json), params: params assert_response :success assert data['change'], "#{data} should have change key" - assert_content_type 'application/json' + assert_media_type 'application/json' end test 'respond when missing params for applications' do params = { period: 'day', provider_key: @provider_account.api_key } get usage_stats_data_applications_path(@application, format: :xml), params: params assert_response :bad_request - assert_content_type 'text/plain' + assert_media_type 'text/plain' end test 'response when application not found' do params = { period: 'day', metric_name: "hits", provider_key: @provider_account.api_key } get usage_stats_data_applications_path(application_id: 'XXX', format: :json), params: params assert_response :not_found - assert_content_type 'application/json' + assert_media_type 'application/json' assert_equal '{"error":"Application not found"}', @response.body end @@ -122,7 +122,7 @@ def setup params = { period: 'day', metric_name: "xxxx", provider_key: @provider_account.api_key } get usage_stats_data_applications_path(@application, format: :json), params: params assert_response :bad_request - assert_content_type 'application/json' + assert_media_type 'application/json' assert_equal '{"error":"metric xxxx not found"}', @response.body end @@ -133,50 +133,50 @@ def setup params = { period: 'day', metric_name: "hits", provider_key: @provider_account.api_key } get usage_stats_data_services_path(@service, format: :json), params: params assert_response :success - assert_content_type 'application/json' + assert_media_type 'application/json' end test 'respond on json for services in negative timezone and very old times' do params = { period: 'month', since: '0150-12-01', timezone: 'Pacific Time (US & Canada)', metric_name: "hits", provider_key: @provider_account.api_key } get usage_stats_data_services_path(@service, format: :json), params: params assert_response :success - assert_content_type 'application/json' + assert_media_type 'application/json' # to trigger the shift > 0 conditions get usage_stats_data_services_path(@service, format: :json), params: params.merge(timezone: 'New Delhi') assert_response :success - assert_content_type 'application/json' + assert_media_type 'application/json' # to trigger the granularity == :month condition get usage_stats_data_services_path(@service, format: :json), params: params.merge(period: 'year') assert_response :success - assert_content_type 'application/json' + assert_media_type 'application/json' # to trigger both the shift > 0 conditions and granularity == :month get usage_stats_data_services_path(@service, format: :json), params: params.merge(period: 'year', timezone: 'New Delhi') assert_response :success - assert_content_type 'application/json' + assert_media_type 'application/json' end test 'respond on xml for services' do params = { period: 'day', metric_name: "hits", provider_key: @provider_account.api_key } get usage_stats_data_services_path(@service, format: :xml), params: params assert_response :success - assert_content_type 'application/xml' + assert_media_type 'application/xml' end test 'respond when missing params for services' do params = { period: 'day', provider_key: @provider_account.api_key } get usage_stats_data_services_path(@service, format: :xml), params: params assert_response :bad_request - assert_content_type 'text/plain' + assert_media_type 'text/plain' end test 'respond when provided with non-existent metric for services' do params = { period: 'day', metric_name: "xxxx", provider_key: @provider_account.api_key } get usage_stats_data_services_path(@service, format: :json), params: params assert_response :bad_request - assert_content_type 'application/json' + assert_media_type 'application/json' assert_equal '{"error":"metric xxxx not found"}', @response.body end @@ -184,7 +184,7 @@ def setup params = { period: 'day', metric_name: "hits", provider_key: @provider_account.api_key } get usage_stats_data_services_path(service_id: 'XXX', format: :json), params: params assert_response :not_found - assert_content_type 'application/json' + assert_media_type 'application/json' assert_equal '{"error":"Service not found"}', @response.body end diff --git a/test/integration/stats/services_test.rb b/test/integration/stats/services_test.rb index 947c1d16e9..ea4e16d001 100644 --- a/test/integration/stats/services_test.rb +++ b/test/integration/stats/services_test.rb @@ -22,7 +22,7 @@ def setup get usage_response_code_stats_api_services_path(@cinstance.service_id, format: :json), params: { period: 'day', response_code: 200, timezone: 'Madrid', skip_change: false } assert_response :success - assert_content_type 'application/json' + assert_media_type 'application/json' assert_json "period" => { "name" => "day", "granularity" => "hour", @@ -44,7 +44,7 @@ def setup get usage_stats_api_services_path(@cinstance.service_id, format: :json), params: { period: 'day', metric_name: @metric.system_name, timezone: 'Madrid', skip_change: false } assert_response :success - assert_content_type 'application/json' + assert_media_type 'application/json' assert_json "period" => { "name" => "day", "granularity" => "hour", @@ -73,7 +73,7 @@ def setup get usage_stats_api_services_path(@cinstance.service_id, format: :json), params: opts assert_response :success - assert_content_type 'application/json' + assert_media_type 'application/json' assert_json_contains "period" => { "name" => "day", "granularity" => "hour", @@ -91,7 +91,7 @@ def setup get usage_stats_api_services_path(@cinstance.service_id, format: :json), params: opts assert_response :success - assert_content_type 'application/json' + assert_media_type 'application/json' assert_json_contains "period" => { "name" => "day", "granularity" => "hour", "since" => Time.zone.parse("2009-12-11T07:00:00+12:00"), @@ -115,7 +115,7 @@ def setup get usage_stats_api_services_path(@provider_account.default_service, format: :json), params: { period: 'day', metric_name: @metric.system_name, timezone: 'UTC', skip_change: false } assert_response :success - assert_content_type 'application/json' + assert_media_type 'application/json' assert_json "period" => { "name" => "day", "granularity" => "hour", @@ -151,7 +151,7 @@ def setup get usage_stats_api_services_path(@provider_account.default_service, format: :json), params: { period: 'year', metric_name: @metric.system_name, timezone: 'Madrid', since: "2010-01-01", skip_change: false } assert_response :success - assert_content_type 'application/json' + assert_media_type 'application/json' assert_json "period" => { "name" => "year", "granularity" => "month", @@ -186,7 +186,7 @@ def setup get usage_stats_api_services_path(@provider_account.default_service, format: :json), params: { period: 'year', metric_name: @metric.system_name, timezone: 'Azores', since: "2010-01-01", skip_change: false } assert_response :success - assert_content_type 'application/json' + assert_media_type 'application/json' assert_json "period" => { "name" => "year", "granularity" => "month", @@ -216,7 +216,7 @@ def setup get top_applications_stats_api_services_path(@provider_account.default_service, format: :json), params: { period: :month, metric_name: @metric.system_name } assert_response :success - assert_content_type 'application/json' + assert_media_type 'application/json' assert_json "period" => { "name" => "month", "since" => "2009-12-01T00:00:00Z", "until" => "2009-12-31T23:59:59Z" }, "applications" => [{ "name" =>nil, "plan" => { "name" => plan.name, "id" => plan.id }, diff --git a/test/integration/user-management-api/nginx_test.rb b/test/integration/user-management-api/nginx_test.rb index 6e0f930215..329bdbac49 100644 --- a/test/integration/user-management-api/nginx_test.rb +++ b/test/integration/user-management-api/nginx_test.rb @@ -19,7 +19,7 @@ def spec_path test 'spec' do get spec_path, params: { provider_key: @provider.provider_key } assert_response :success - assert_equal("application/json", @response.content_type) + assert_equal("application/json", @response.media_type) assert_not_nil @response.body end diff --git a/test/test_helpers/assert_content_type.rb b/test/test_helpers/assert_content_type.rb deleted file mode 100644 index da41d96c81..0000000000 --- a/test/test_helpers/assert_content_type.rb +++ /dev/null @@ -1,12 +0,0 @@ -module TestHelpers - module AssertContentType - private - - def assert_content_type(expected) - assert_equal expected, @response.content_type - end - end -end - -ActionController::TestCase.send(:include, TestHelpers::AssertContentType) -ActionDispatch::IntegrationTest.send(:include, TestHelpers::AssertContentType) diff --git a/test/test_helpers/assert_media_type.rb b/test/test_helpers/assert_media_type.rb new file mode 100644 index 0000000000..ffba8dd83e --- /dev/null +++ b/test/test_helpers/assert_media_type.rb @@ -0,0 +1,12 @@ +module TestHelpers + module AssertMediaType + private + + def assert_media_type(expected) + assert_equal expected, @response.media_type + end + end +end + +ActionController::TestCase.send(:include, TestHelpers::AssertMediaType) +ActionDispatch::IntegrationTest.send(:include, TestHelpers::AssertMediaType) diff --git a/test/unit/abilities/impersonate_test.rb b/test/unit/abilities/impersonate_test.rb index 5667a98746..0edeff82d5 100644 --- a/test/unit/abilities/impersonate_test.rb +++ b/test/unit/abilities/impersonate_test.rb @@ -13,7 +13,7 @@ def setup end test "master admin can impersonate provider accounts" do - @provider.admins.first.update_attribute :username, ThreeScale.config.impersonation_admin['username'] + @provider.admins.first.update_attribute :username, ThreeScale.config.impersonation_admin[:username] @provider.reload user = Account.master.admins.first @@ -21,7 +21,7 @@ def setup end test "provider admin users cannot impersonate" do - @provider.admins.first.update_attribute :username, ThreeScale.config.impersonation_admin['username'] + @provider.admins.first.update_attribute :username, ThreeScale.config.impersonation_admin[:username] @provider.reload assert_cannot Ability.new(@provider.admins.first), :impersonate, @provider diff --git a/test/unit/account/states_test.rb b/test/unit/account/states_test.rb index 23983bada0..646b71453f 100644 --- a/test/unit/account/states_test.rb +++ b/test/unit/account/states_test.rb @@ -1,7 +1,7 @@ require 'test_helper' class Account::StatesTest < ActiveSupport::TestCase - include ActiveJob::TestHelper + include ActionMailer::TestHelper test '.without_suspended' do accounts = FactoryBot.create_list(:simple_provider, 2) @@ -94,14 +94,14 @@ def test_events_when_state_not_changed test 'enqueues notification email when account is made pending' do account = FactoryBot.create(:buyer_account_with_provider) - assert_enqueued_with(job: ActionMailer::DeliveryJob, args: ["AccountMailer", "confirmed", "deliver_now", account]) do + assert_enqueued_email_with(AccountMailer, :confirmed, args: [account]) do account.make_pending! end end test 'enqueues notification email when account is rejected' do account = FactoryBot.create(:buyer_account_with_provider) - assert_enqueued_with(job: ActionMailer::DeliveryJob, args: ["AccountMailer", "rejected", "deliver_now", account]) do + assert_enqueued_email_with(AccountMailer, :rejected, args: [account]) do account.reject! end end @@ -113,7 +113,7 @@ def test_events_when_state_not_changed account.buy! FactoryBot.create(:account_plan, :approval_required => true) account.reload - assert_enqueued_with(job: ActionMailer::DeliveryJob, args: ["AccountMailer", "approved", "deliver_now", account]) do + assert_enqueued_email_with(AccountMailer, :approved, args: [account]) do account.approve! end @@ -123,7 +123,7 @@ def test_events_when_state_not_changed AccountMailer.any_instance.expects(:approved).never account = FactoryBot.create(:pending_account) - assert_no_enqueued_jobs(only: ActionMailer::DeliveryJob) do + assert_no_enqueued_jobs(only: ActionMailer::MailDeliveryJob) do account.approve! end end diff --git a/test/unit/apicast/provider_source_test.rb b/test/unit/apicast/provider_source_test.rb index 2f1c663de3..d36f12dea2 100644 --- a/test/unit/apicast/provider_source_test.rb +++ b/test/unit/apicast/provider_source_test.rb @@ -32,7 +32,7 @@ def test_services service.stubs(updated_at: Time.now) service_attributes = @source.attributes_for_proxy['services'][0] - assert_equal service.updated_at, service_attributes['updated_at'] + assert_equal service.updated_at.iso8601, service_attributes['updated_at'] assert proxy_attributes = services.first.proxy @@ -60,4 +60,3 @@ def test_policies_with_default_apicast_policy assert_nil @source.attributes_for_proxy['services'][0]['proxy']['policies_config'] end end - diff --git a/test/unit/authentication/strategy/oauth2_test.rb b/test/unit/authentication/strategy/oauth2_test.rb index d1c36349b4..2135170945 100644 --- a/test/unit/authentication/strategy/oauth2_test.rb +++ b/test/unit/authentication/strategy/oauth2_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class Authentication::Strategy::Oauth2Test < ActiveSupport::TestCase +class Authentication::Strategy::OAuth2Test < ActiveSupport::TestCase setup do @provider = FactoryBot.create(:simple_provider) @@ -219,7 +219,7 @@ class SsoSignupTest < ActiveSupport::TestCase user_data = valid_user_data client.stubs(authenticate!: user_data) ThreeScale::OAuth2::Client.expects(:build).with(authentication_provider).returns(client).once - perform_enqueued_jobs(only: ActionMailer::DeliveryJob) do + perform_enqueued_jobs(only: ActionMailer::MailDeliveryJob) do assert_difference(User.method(:count), +1) do result = authentication_strategy.authenticate({ system_name: authentication_provider.system_name, @@ -251,7 +251,7 @@ class SsoSignupTest < ActiveSupport::TestCase client.stubs(authenticate!: user_data) ThreeScale::OAuth2::Client.expects(:build).with(authentication_provider).returns(client).once - perform_enqueued_jobs(only: ActionMailer::DeliveryJob) do + perform_enqueued_jobs(only: ActionMailer::MailDeliveryJob) do assert_difference(User.method(:count), +1) do result = authentication_strategy.authenticate({ system_name: authentication_provider.system_name, @@ -324,7 +324,7 @@ class SsoSignupTest < ActiveSupport::TestCase code: '1234', request: mock_request, invitation: invitation - }, procedure: Authentication::Strategy::Oauth2::CreateInvitedUser) + }, procedure: Authentication::Strategy::OAuth2::CreateInvitedUser) assert_instance_of User, result assert_equal result.email, user_data[:email] diff --git a/test/unit/authentication/strategy/provider_oauth2_test.rb b/test/unit/authentication/strategy/provider_oauth2_test.rb index e5c01f2902..1f72a2c2ff 100644 --- a/test/unit/authentication/strategy/provider_oauth2_test.rb +++ b/test/unit/authentication/strategy/provider_oauth2_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class Authentication::Strategy::ProviderOauth2Test < ActiveSupport::TestCase +class Authentication::Strategy::ProviderOAuth2Test < ActiveSupport::TestCase setup do @provider = FactoryBot.create(:simple_provider) @@ -209,7 +209,7 @@ class SsoSignupTest < ActiveSupport::TestCase ThreeScale::OAuth2::Client.expects(:build).with(authentication_provider).returns(client).once deliveries = ActionMailer::Base.deliveries - perform_enqueued_jobs(only: ActionMailer::DeliveryJob) do + perform_enqueued_jobs(only: ActionMailer::MailDeliveryJob) do assert_difference(User.method(:count), +1) do @@ -249,7 +249,7 @@ class SsoSignupTest < ActiveSupport::TestCase code: '1234', request: mock_request, invitation: invitation - }, procedure: Authentication::Strategy::Oauth2::CreateInvitedUser) + }, procedure: Authentication::Strategy::OAuth2::CreateInvitedUser) assert_instance_of User, result assert_equal result.email, user_data[:email] diff --git a/test/unit/cache_store_test.rb b/test/unit/cache_store_test.rb new file mode 100644 index 0000000000..1463c9bfa3 --- /dev/null +++ b/test/unit/cache_store_test.rb @@ -0,0 +1,136 @@ +require 'test_helper' + +class CacheStoreTest < ActionView::TestCase + + test ':null_store can be set as cache store' do + # cache_store.yml + # --- + # test: + # - :null_store + System::Application.any_instance.expects(:config_for).with(:cache_store).returns([:null_store]) + + cache = ActiveSupport::Cache.lookup_store(*System::Application.cache_store_config) + + assert_equal ActiveSupport::Cache::NullStore, cache.class + end + + test ':memory_store can be set as cache store' do + # cache_store.yml: + # --- + # test: + # - :memory_store + # - :size: 5000 + options = { size: 5000 } + System::Application.any_instance.expects(:config_for).with(:cache_store).returns([:memory_store, options]) + + cache = ActiveSupport::Cache.lookup_store(*System::Application.cache_store_config) + + assert_equal ActiveSupport::Cache::MemoryStore, cache.class + assert_equal options, cache.options + end + + test ':file_store can be set as cache store' do + # cache_store.yml + # --- + # test: + # - :file_store + # - /tmp/test-file-store + path = '/tmp/test-file-store' + System::Application.any_instance.expects(:config_for).with(:cache_store).returns([:file_store, path]) + + cache = ActiveSupport::Cache.lookup_store(*System::Application.cache_store_config) + + assert_equal ActiveSupport::Cache::FileStore, cache.class + assert_equal path, cache.cache_path + end + + test ':mem_cache_store can be set as cache store' do + # cache_store.yml + # --- + # test: + # - :mem_cache_store + # - localhost:11211 + server = 'localhost:11211' + System::Application.any_instance.expects(:config_for).with(:cache_store).returns([:mem_cache_store, server]) + + cache = ActiveSupport::Cache.lookup_store(*System::Application.cache_store_config) + + assert_equal ActiveSupport::Cache::MemCacheStore, cache.class + assert_equal server, cache.stats.keys.first + end + + test ':mem_cache_store accepts multiple servers in a string' do + # cache_store.yml + # --- + # test: + # - :mem_cache_store + # - localhost:11211,127.0.0.1:11211,3scale.localhost:11211 + servers = 'localhost:11211,127.0.0.1:11211,3scale.localhost:11211' + System::Application.any_instance.expects(:config_for).with(:cache_store).returns([:mem_cache_store, servers]) + + cache = ActiveSupport::Cache.lookup_store(*System::Application.cache_store_config) + + assert_equal ActiveSupport::Cache::MemCacheStore, cache.class + assert_same_elements servers.split(','), cache.stats.keys + end + + test ':mem_cache_store accepts multiple servers in a list' do + # cache_store.yml + # --- + # test: + # - :mem_cache_store + # - localhost:11211 + # - 127.0.0.1:11211 + # - 3scale.localhost:11211 + servers = %w[localhost:11211 127.0.0.1:11211 3scale.localhost:11211] + System::Application.any_instance.expects(:config_for).with(:cache_store).returns([:mem_cache_store, servers]) + + cache = ActiveSupport::Cache.lookup_store(*System::Application.cache_store_config) + + assert_equal ActiveSupport::Cache::MemCacheStore, cache.class + assert_same_elements servers, cache.stats.keys + end + + test ':mem_cache_store sets SHA256 as default digest algorithm' do + # cache_store.yml + # --- + # test: + # - :mem_cache_store + System::Application.any_instance.expects(:config_for).with(:cache_store).returns([:mem_cache_store]) + + cache = ActiveSupport::Cache.lookup_store(*System::Application.cache_store_config) + + assert_equal ActiveSupport::Cache::MemCacheStore, cache.class + assert_equal({ digest_class: Digest::SHA256 }, cache.options) + end + + test ':mem_cache_store allows overwriting the default digest algorithm' do + # cache_store.yml + # --- + # test: + # - :mem_cache_store + # - :digest_class: !ruby/class Digest::SHA1 + options = { digest_class: Digest::SHA1 } + System::Application.any_instance.expects(:config_for).with(:cache_store).returns([:mem_cache_store, options]) + + cache = ActiveSupport::Cache.lookup_store(*System::Application.cache_store_config) + + assert_equal ActiveSupport::Cache::MemCacheStore, cache.class + assert_equal options, cache.options + end + + test ':redis_cache_store can be set as cache store' do + # cache_store.yml + # --- + # test: + # - :redis_cache_store + # - :url: redis://localhost:6379 + options = { url: 'redis://localhost:6379' } + System::Application.any_instance.expects(:config_for).with(:cache_store).returns([:redis_cache_store, options]) + + cache = ActiveSupport::Cache.lookup_store(*System::Application.cache_store_config) + + assert_equal ActiveSupport::Cache::RedisCacheStore, cache.class + assert_equal options, cache.redis_options + end +end diff --git a/test/unit/cinstance_test.rb b/test/unit/cinstance_test.rb index b00edc1ee8..ddd8b34131 100644 --- a/test/unit/cinstance_test.rb +++ b/test/unit/cinstance_test.rb @@ -781,7 +781,7 @@ class SuspendTest < ActiveSupport::TestCase test 'email the buyer if configured so' do FactoryBot.create(:mail_dispatch_rule, system_operation: SystemOperation.for('app_suspended'), account: @cinstance.provider_account) - perform_enqueued_jobs(only: ActionMailer::DeliveryJob) { @cinstance.suspend! } + perform_enqueued_jobs(only: ActionMailer::MailDeliveryJob) { @cinstance.suspend! } #TODO: write some email assertion helper? assert mail = ActionMailer::Base.deliveries.last, 'missing email' diff --git a/test/unit/db/seeds_test.rb b/test/unit/db/seeds_test.rb index 97fb0afcac..5288c36d77 100644 --- a/test/unit/db/seeds_test.rb +++ b/test/unit/db/seeds_test.rb @@ -133,8 +133,8 @@ def teardown assert impersonation_user.admin? assert impersonation_user.active? assert impersonation_user.activated_at.present? - assert_equal impersonation_admin_config['username'], impersonation_user.username - assert_equal "#{impersonation_admin_config['username']}+#{tenant_account.internal_admin_domain}@#{impersonation_admin_config['domain']}", impersonation_user.email + assert_equal impersonation_admin_config[:username], impersonation_user.username + assert_equal "#{impersonation_admin_config[:username]}+#{tenant_account.internal_admin_domain}@#{impersonation_admin_config[:domain]}", impersonation_user.email assert_equal '3scale', impersonation_user.first_name assert_equal 'Admin', impersonation_user.last_name diff --git a/test/unit/events/importers/alert_importer_test.rb b/test/unit/events/importers/alert_importer_test.rb index b0a7d9622f..afb540fd75 100644 --- a/test/unit/events/importers/alert_importer_test.rb +++ b/test/unit/events/importers/alert_importer_test.rb @@ -88,7 +88,7 @@ def import_events(events = @events) }) ActionMailer::Base.deliveries = [] - perform_enqueued_jobs(only: ActionMailer::DeliveryJob) do + perform_enqueued_jobs(only: ActionMailer::MailDeliveryJob) do import_events end diff --git a/test/unit/liquid/tags/sort_link_test.rb b/test/unit/liquid/tags/sort_link_test.rb index 92cef20286..55e262c2be 100644 --- a/test/unit/liquid/tags/sort_link_test.rb +++ b/test/unit/liquid/tags/sort_link_test.rb @@ -21,7 +21,7 @@ class Liquid::Tags::SortLinkTest < ActiveSupport::TestCase request.parameters[:controller] = controller.controller_path request.parameters[:application_id] = '1' controller.stubs(request: request) - _view = ActionView::Base.new('app/views', {}, controller) + _view = ActionView::Base.new(ActionView::LookupContext.new('app/views'), {}, controller) context = Liquid::Context.new context.registers[:controller] = controller @@ -38,7 +38,7 @@ class Liquid::Tags::SortLinkTest < ActiveSupport::TestCase request = ActionDispatch::TestRequest.create request.parameters[:controller] = controller.controller_path controller.stubs(request: request) - _view = ActionView::Base.new('app/views', {}, controller) + _view = ActionView::Base.new(ActionView::LookupContext.new('app/views'), {}, controller) context = Liquid::Context.new context.registers[:controller] = controller @@ -48,4 +48,3 @@ class Liquid::Tags::SortLinkTest < ActiveSupport::TestCase assert_nil rendered end end - diff --git a/test/unit/logic/plan_changes_test.rb b/test/unit/logic/plan_changes_test.rb index 57474e066a..51ea949916 100644 --- a/test/unit/logic/plan_changes_test.rb +++ b/test/unit/logic/plan_changes_test.rb @@ -51,7 +51,7 @@ def setup test '#buyer_changes_plan! - :request' do @plan.issuer.stubs(plan_change_permission: :request) - perform_enqueued_jobs(only: ActionMailer::DeliveryJob) do + perform_enqueued_jobs(only: ActionMailer::MailDeliveryJob) do @app.buyer_changes_plan!(@new_plan) end @@ -63,7 +63,7 @@ def setup @plan.issuer.stubs(plan_change_permission: :credit_card) @app.user_account.stubs(:credit_card_stored? => false) - perform_enqueued_jobs(only: ActionMailer::DeliveryJob) do + perform_enqueued_jobs(only: ActionMailer::MailDeliveryJob) do @app.buyer_changes_plan!(@new_plan) end @@ -75,7 +75,7 @@ def setup @plan.issuer.stubs(plan_change_permission: :credit_card) @app.user_account.stubs(:credit_card_stored? => true) - perform_enqueued_jobs(only: ActionMailer::DeliveryJob) do + perform_enqueued_jobs(only: ActionMailer::MailDeliveryJob) do @app.buyer_changes_plan!(@new_plan) end @@ -88,7 +88,7 @@ def setup @plan.issuer.stubs(plan_change_permission: :request_credit_card) @app.user_account.stubs(:credit_card_stored? => true) - perform_enqueued_jobs(only: ActionMailer::DeliveryJob) do + perform_enqueued_jobs(only: ActionMailer::MailDeliveryJob) do @app.buyer_changes_plan!(@new_plan) end @@ -101,7 +101,7 @@ def setup @plan.issuer.stubs(plan_change_permission: :request_credit_card) @app.user_account.stubs(:credit_card_stored? => false) - perform_enqueued_jobs(only: ActionMailer::DeliveryJob) do + perform_enqueued_jobs(only: ActionMailer::MailDeliveryJob) do msg = @app.buyer_changes_plan!(@new_paid_plan) assert_equal "Please enter your credit card before changing the plan.", msg @@ -114,7 +114,7 @@ def setup @plan.issuer.stubs(plan_change_permission: :request_credit_card) @app.user_account.stubs(:credit_card_stored? => false) - perform_enqueued_jobs(only: ActionMailer::DeliveryJob) do + perform_enqueued_jobs(only: ActionMailer::MailDeliveryJob) do msg = @app.buyer_changes_plan!(@new_plan) assert_equal "Plan change was successful.", msg diff --git a/test/unit/message_test.rb b/test/unit/message_test.rb index 76ec851ffb..f2c2157f0e 100644 --- a/test/unit/message_test.rb +++ b/test/unit/message_test.rb @@ -47,7 +47,7 @@ class MessageTest < ActiveSupport::TestCase message = Message.create!(sender: sender, to: recipients, subject: 'hello', body: "what's up?") - perform_enqueued_jobs(only: ActionMailer::DeliveryJob) { message.deliver! } + perform_enqueued_jobs(only: ActionMailer::MailDeliveryJob) { message.deliver! } assert delivery = ActionMailer::Base.deliveries.first assert_equal delivery['from'].value, Rails.configuration.three_scale.noreply_email @@ -86,7 +86,7 @@ class MessageTest < ActiveSupport::TestCase ActionMailer::Base.deliveries = [] message = Message.create!(sender: sender, to: recipients, subject: 'hello', body: "what's up?") - perform_enqueued_jobs(only: ActionMailer::DeliveryJob) { message.deliver! } + perform_enqueued_jobs(only: ActionMailer::MailDeliveryJob) { message.deliver! } assert delivery = ActionMailer::Base.deliveries.first assert_equal delivery['from'].value, sender.from_email diff --git a/test/unit/messengers/plans_messenger_test.rb b/test/unit/messengers/plans_messenger_test.rb index 7d330879b2..587c9b24b2 100644 --- a/test/unit/messengers/plans_messenger_test.rb +++ b/test/unit/messengers/plans_messenger_test.rb @@ -10,7 +10,7 @@ class PlansMessengerTest < ActiveSupport::TestCase test '#plan_change_request' do cinstance = FactoryBot.create(:cinstance) plan = FactoryBot.create(:account_plan) - perform_enqueued_jobs(only: ActionMailer::DeliveryJob) do + perform_enqueued_jobs(only: ActionMailer::MailDeliveryJob) do PlansMessenger.plan_change_request(cinstance, plan).deliver end diff --git a/test/unit/plan_rule_loader_test.rb b/test/unit/plan_rule_loader_test.rb index 87bc78f7b9..363ce6a38a 100644 --- a/test/unit/plan_rule_loader_test.rb +++ b/test/unit/plan_rule_loader_test.rb @@ -4,7 +4,7 @@ class PlanRuleLoaderTest < ActiveSupport::TestCase def given_plan_rules_config(config) - ThreeScale.config.stubs(:plan_rules).returns(config) + ThreeScale.config.stubs(:plan_rules).returns(HashWithIndifferentAccess.new(config)) end class LoadErrorTest < PlanRuleLoaderTest diff --git a/test/unit/services/users/find_oauth2_user_service_test.rb b/test/unit/services/users/find_oauth2_user_service_test.rb index 2aa987e592..9e4e03615d 100644 --- a/test/unit/services/users/find_oauth2_user_service_test.rb +++ b/test/unit/services/users/find_oauth2_user_service_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class Users::FindOauth2UserServiceTest < ActiveSupport::TestCase +class Users::FindOAuth2UserServiceTest < ActiveSupport::TestCase UsersDouble = Class.new(ActiveRecord::Relation) @@ -91,6 +91,6 @@ def relation end def service - Users::FindOauth2UserService + Users::FindOAuth2UserService end end diff --git a/test/unit/signup/account_manager_test.rb b/test/unit/signup/account_manager_test.rb index 827b1c8bbc..b9139162ce 100644 --- a/test/unit/signup/account_manager_test.rb +++ b/test/unit/signup/account_manager_test.rb @@ -44,7 +44,7 @@ class ProviderAccountManagerTest < Signup::AccountManagerTest assert_equal :admin, user.role # impersonation_admin user is also created with the right attributes - assert_equal "#{ThreeScale.config.impersonation_admin['username']}+#{account.internal_domain}@#{imp_config['domain']}", impersonation_user.email + assert_equal "#{ThreeScale.config.impersonation_admin[:username]}+#{account.internal_domain}@#{imp_config[:domain]}", impersonation_user.email assert_equal '3scale', impersonation_user.first_name assert_equal 'Admin', impersonation_user.last_name diff --git a/test/unit/signup/impersonation_admin_builder_test.rb b/test/unit/signup/impersonation_admin_builder_test.rb index e4b3241367..d6faedd713 100644 --- a/test/unit/signup/impersonation_admin_builder_test.rb +++ b/test/unit/signup/impersonation_admin_builder_test.rb @@ -8,10 +8,10 @@ class ImpersonationAdminBuilderTest < ActiveSupport::TestCase user_returned = Signup::ImpersonationAdminBuilder.build(account: account) user_returned.save! config = ThreeScale.config.impersonation_admin - username = config['username'] + username = config[:username] user_db = User.find_by!(username: username) assert_equal user_returned, user_db - assert_equal "#{username}+#{account.internal_domain}@#{config['domain']}", user_db.email + assert_equal "#{username}+#{account.internal_domain}@#{config[:domain]}", user_db.email assert_equal '3scale', user_db.first_name assert_equal 'Admin', user_db.last_name assert_equal 'active', user_db.state diff --git a/test/unit/three_scale/analytics/account_classifier_test.rb b/test/unit/three_scale/analytics/account_classifier_test.rb index 3b95a73cc2..fa1c86e116 100644 --- a/test/unit/three_scale/analytics/account_classifier_test.rb +++ b/test/unit/three_scale/analytics/account_classifier_test.rb @@ -7,7 +7,7 @@ def classifier(user_attributes = {}) provider = FactoryBot.build_stubbed(:provider_account) provider.stubs(:users).returns([ FactoryBot.build_stubbed(:admin, - username: ThreeScale.config.impersonation_admin['username']), + username: ThreeScale.config.impersonation_admin[:username]), FactoryBot.build_stubbed(:admin, user_attributes) ]) @@ -25,10 +25,10 @@ def test_account_type assert_equal 'Customer', classifier(email: 'user@example.net', username: 'user').account_type impersonation_admin_config = ThreeScale.config.impersonation_admin - impersonation_admin_username = impersonation_admin_config['username'] + impersonation_admin_username = impersonation_admin_config[:username] assert_equal 'Internal', classifier(email: 'user@example.net', username: impersonation_admin_username).account_type - assert_equal 'Customer', classifier(email: "user@#{impersonation_admin_config['domain']}", username: 'user').account_type - assert_equal 'Internal', classifier(email: "user@#{impersonation_admin_config['domain']}", username: impersonation_admin_username).account_type + assert_equal 'Customer', classifier(email: "user@#{impersonation_admin_config[:domain]}", username: 'user').account_type + assert_equal 'Internal', classifier(email: "user@#{impersonation_admin_config[:domain]}", username: impersonation_admin_username).account_type assert_equal 'Customer', classifier(email: nil, username: nil).account_type assert_equal 'Customer', classifier(email: 'user@example.com', username: nil).account_type diff --git a/test/unit/three_scale/analytics/user_classifier_test.rb b/test/unit/three_scale/analytics/user_classifier_test.rb index 82e5c3bb6c..1b2c281a99 100644 --- a/test/unit/three_scale/analytics/user_classifier_test.rb +++ b/test/unit/three_scale/analytics/user_classifier_test.rb @@ -24,11 +24,11 @@ def test_has_3scale_email? def test_is_impersonation_admin? refute classifier(username: 'foo').is_impersonation_admin? - assert classifier(username: ThreeScale.config.impersonation_admin['username']).is_impersonation_admin? + assert classifier(username: ThreeScale.config.impersonation_admin[:username]).is_impersonation_admin? end def test_is_3scale? - impersonation_admin_username = ThreeScale.config.impersonation_admin['username'] + impersonation_admin_username = ThreeScale.config.impersonation_admin[:username] refute classifier(email: 'foo@example.com', username: 'foo').is_3scale? assert classifier(email: 'foo@example.com', username: impersonation_admin_username).is_3scale? assert classifier(email: 'foo@3scale.net', username: impersonation_admin_username).is_3scale? @@ -44,7 +44,7 @@ def test_is_guest? end def test_user_type - impersonation_admin_username = ThreeScale.config.impersonation_admin['username'] + impersonation_admin_username = ThreeScale.config.impersonation_admin[:username] assert_equal 'customer', classifier(email: 'user@example.com', username: 'user').user_type assert_equal '3scale', classifier(email: 'user@3scale.net', username: 'user').user_type diff --git a/test/unit/three_scale/analytics/user_tracking_test.rb b/test/unit/three_scale/analytics/user_tracking_test.rb index b5c2e289d7..7e8680fbe3 100644 --- a/test/unit/three_scale/analytics/user_tracking_test.rb +++ b/test/unit/three_scale/analytics/user_tracking_test.rb @@ -136,7 +136,7 @@ def setup end test 'do not track impersonation admins' do - @user.username = ThreeScale.config.impersonation_admin['username'] + @user.username = ThreeScale.config.impersonation_admin[:username] refute UserTracking.new(@user).can_send? end end diff --git a/test/unit/three_scale/sso_test.rb b/test/unit/three_scale/sso_test.rb index e9ed9cd142..8761536119 100644 --- a/test/unit/three_scale/sso_test.rb +++ b/test/unit/three_scale/sso_test.rb @@ -20,7 +20,7 @@ class ThreeScale::SsoTest < ActiveSupport::TestCase decoder = ThreeScale::SSO::Encryptor.new ThreeScale::SSO.generate_sso_key - assert_raise ActiveSupport::MessageVerifier::InvalidSignature do + assert_raise ActiveSupport::MessageEncryptor::InvalidMessage do decoder.decrypt_token token end end diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb index 2023ec570c..85c8ab4750 100644 --- a/test/unit/user_test.rb +++ b/test/unit/user_test.rb @@ -382,7 +382,7 @@ class ExistingProviderUserTest < ActiveSupport::TestCase test 'send lost password email on :generate_lost_password_token!' do @user.account.update_column(:provider, true) # rubocop:disable Rails/SkipsModelValidations - perform_enqueued_jobs(only: ActionMailer::DeliveryJob) do + perform_enqueued_jobs(only: ActionMailer::MailDeliveryJob) do @user.generate_lost_password_token! end message = ActionMailer::Base.deliveries.last @@ -395,7 +395,7 @@ class ExistingProviderUserTest < ActiveSupport::TestCase test 'send buyer lost password email on :generate_lost_password_token!' do @user.account.update_column(:provider, false) # rubocop:disable Rails/SkipsModelValidations - perform_enqueued_jobs(only: ActionMailer::DeliveryJob) do + perform_enqueued_jobs(only: ActionMailer::MailDeliveryJob) do @user.generate_lost_password_token! end diff --git a/test/workers/active_job_uniqueness_test.rb b/test/workers/active_job_uniqueness_test.rb index 7ebdd936af..068718e781 100644 --- a/test/workers/active_job_uniqueness_test.rb +++ b/test/workers/active_job_uniqueness_test.rb @@ -37,8 +37,8 @@ class ActiveJobUniquenessTest < ActiveSupport::TestCase JobUniquenessTestWorker.perform_later end assert_enqueued_jobs 1, only: JobUniquenessTestWorker - # In Rails 6.0 we can just call #perform_enqueued_jobs - enqueued_jobs.each { |job_data| instantiate_job(job_data).perform_now } + + perform_enqueued_jobs assert_equal 1, JobUniquenessTestWorker.run_counter assert_equal 1, locks