From 7404884dbb18cbfef9f0bbec91ce51374206628c Mon Sep 17 00:00:00 2001 From: Jeremy Croteau Date: Mon, 18 Mar 2024 02:52:03 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=80=20AlecK/APPEALS-38443=20-=20Update?= =?UTF-8?q?=20to=20Rails=206.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Gemfile | 2 +- Gemfile.lock | 118 ++++++++++-------- app/services/image_converter_service.rb | 4 +- bin/setup | 14 +-- config/application.rb | 35 +++++- config/environments/development.rb | 10 +- config/environments/production.rb | 33 +++-- config/environments/test.rb | 16 +-- .../initializers/content_security_policy.rb | 7 +- config/locales/en.yml | 4 +- config/puma.rb | 9 +- spec/models/manifest_source_spec.rb | 10 +- 12 files changed, 168 insertions(+), 94 deletions(-) diff --git a/Gemfile b/Gemfile index 568209be5..1438fe410 100644 --- a/Gemfile +++ b/Gemfile @@ -28,7 +28,7 @@ gem "omniauth-saml-va", git: "https://github.com/department-of-veterans-affairs/ gem "pg", "~> 0.18", platforms: :ruby gem "puma", "5.6.4" gem "rack-cors", ">= 1.0.4" -gem "rails", "5.2.8.1" +gem "rails", "6.0.6.1" gem "redis-namespace" gem "redis-rails", "~> 5.0.2" gem "redis-semaphore" diff --git a/Gemfile.lock b/Gemfile.lock index 352cca70c..4b77c2607 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -85,61 +85,74 @@ GIT GEM remote: https://rubygems.org/ specs: - 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) + rails-html-sanitizer (~> 1.1, >= 1.2.0) active_model_serializers (0.10.12) actionpack (>= 4.1, < 6.2) activemodel (>= 4.1, < 6.2) case_transform (>= 0.2) jsonapi-renderer (>= 0.1.1.beta1, < 0.3) - activejob (5.2.8.1) - activesupport (= 5.2.8.1) + activejob (6.0.6.1) + activesupport (= 6.0.6.1) globalid (>= 0.3.6) activejob_dj_overrides (0.2.0) delayed_job rails (>= 4.2) - activemodel (5.2.8.1) - activesupport (= 5.2.8.1) - activerecord (5.2.8.1) - activemodel (= 5.2.8.1) - activesupport (= 5.2.8.1) - arel (>= 9.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) + activemodel (6.0.6.1) + activesupport (= 6.0.6.1) + activerecord (6.0.6.1) + activemodel (= 6.0.6.1) + activesupport (= 6.0.6.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) addressable (2.8.6) public_suffix (>= 2.0.2, < 6.0) akami (1.3.1) gyoku (>= 0.4.0) nokogiri - arel (9.0.0) ast (2.4.1) aws-eventstream (1.1.0) aws-sdk (2.11.632) @@ -184,7 +197,7 @@ GEM coffee-script-source execjs coffee-script-source (1.12.2) - concurrent-ruby (1.2.2) + concurrent-ruby (1.2.3) crack (0.4.5) rexml crass (1.0.6) @@ -244,7 +257,7 @@ GEM logstasher (2.1.5) activesupport (>= 5.2) request_store - loofah (2.21.3) + loofah (2.22.0) crass (~> 1.0.2) nokogiri (>= 1.12.0) macaddr (1.7.2) @@ -265,7 +278,7 @@ GEM mini_magick (4.11.0) mini_mime (1.1.5) mini_portile2 (2.8.5) - minitest (5.20.0) + minitest (5.22.2) moment_timezone-rails (0.5.14) momentjs-rails (~> 2.15.1) momentjs-rails (2.15.1) @@ -277,17 +290,17 @@ GEM ruby2_keywords (~> 0.0.1) neat (4.0.0) thor (~> 0.19) - net-imap (0.4.5) + net-imap (0.4.10) date net-protocol net-pop (0.1.2) net-protocol net-protocol (0.2.2) timeout - net-smtp (0.4.0) + net-smtp (0.4.0.1) net-protocol newrelic_rpm (6.14.0) - nio4r (2.5.9) + nio4r (2.7.0) nokogiri (1.15.5) mini_portile2 (~> 2.8.2) racc (~> 1.4) @@ -314,25 +327,27 @@ GEM puma (5.6.4) nio4r (~> 2.0) racc (1.7.3) - rack (2.2.8) + rack (2.2.8.1) rack-cors (1.1.1) rack (>= 2.0.0) rack-protection (2.2.0) rack rack-test (2.1.0) rack (>= 1.3) - 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-dom-testing (2.2.0) activesupport (>= 5.0.0) @@ -342,14 +357,14 @@ GEM loofah (~> 2.21) nokogiri (~> 1.14) rails_stdout_logging (0.0.5) - 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.0.0) - rake (13.0.6) + rake (13.1.0) rb-fsevent (0.10.4) rb-inotify (0.10.1) ffi (~> 1.0) @@ -520,6 +535,7 @@ GEM xpath (3.2.0) nokogiri (~> 1.8) zaru (0.3.0) + zeitwerk (2.6.13) zero_downtime_migrations (0.0.7) activerecord @@ -562,7 +578,7 @@ DEPENDENCIES pry-byebug puma (= 5.6.4) rack-cors (>= 1.0.4) - rails (= 5.2.8.1) + rails (= 6.0.6.1) rails_stdout_logging rb-readline redis-namespace diff --git a/app/services/image_converter_service.rb b/app/services/image_converter_service.rb index ec42d5f6d..6e5794684 100644 --- a/app/services/image_converter_service.rb +++ b/app/services/image_converter_service.rb @@ -10,10 +10,10 @@ def process return image if self.class.converted_mime_type(record.mime_type) == record.mime_type converted_image = convert - record.update_attributes!(conversion_status: :conversion_success) + record.update!(conversion_status: :conversion_success) converted_image rescue ImageConverterError - record.update_attributes!(conversion_status: :conversion_failed) + record.update!(conversion_status: :conversion_failed) image end diff --git a/bin/setup b/bin/setup index b2db6e6a2..13abfe14f 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,28 +8,29 @@ 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 ==' system! 'gem install bundler --conservative' system('bundle check') || system!('bundle install') - # Install JavaScript dependencies if using Yarn + # Install JavaScript dependencies system('bin/yarn') # puts "\n== Copying sample files ==" # unless File.exist?('config/database.yml') - # cp 'config/database.yml.sample', 'config/database.yml' + # FileUtils.cp 'config/database.yml.sample', 'config/database.yml' # end 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' puts "\n== Restarting application server ==" system! 'bin/rails restart' -end +end \ No newline at end of file diff --git a/config/application.rb b/config/application.rb index f54bc62f3..b96fb4fbb 100644 --- a/config/application.rb +++ b/config/application.rb @@ -9,7 +9,8 @@ module CaseflowEfolder class Application < Rails::Application # Initialize configuration defaults for originally generated Rails version. - config.load_defaults 5.2 + config.load_defaults 6.0 + config.autoloader = :classic # Settings in config/environments/* take precedence over those specified here. # Application configuration can go into files in config/initializers @@ -76,6 +77,36 @@ class Application < Rails::Application # Default as of 5.2: true Rails.application.config.active_record.sqlite3.represent_boolean_as_integer = false + # Make Active Record use stable #cache_key alongside new #cache_version method. + # This is needed for recyclable cache keys. + # Default as of 5.2: true + config.active_record.cache_versioning = false + + + #======================================================================================= + # Rails 6.0 default overrides + #--------------------------------------------------------------------------------------- + + # Don't force requests from old versions of IE to be UTF-8 encoded. + # Default changed as of 6.0 to false + # This can be changed to the defualt and removed if we no longer support IE5-8 (old browsers) + Rails.application.config.action_view.default_enforce_utf8 = true + + # Embed purpose and expiry metadata inside signed and 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 6.0. + # Default change to true as of 6.0 + # Remove after stable 6.0 + Rails.application.config.action_dispatch.use_cookies_with_metadata = false + + # Enable the same cache key to be reused when the object being cached of type + # `ActiveRecord::Relation` changes by moving the volatile information (max updated at and count) + # of the relation's cache key into the cache version to support recycling cache key. + # Default as of 6.0: true + Rails.application.config.active_record.collection_cache_versioning = false + #======================================================================================= # eFolder Specific configs @@ -129,4 +160,4 @@ class Application < Rails::Application config.bgs_environment = ENV["BGS_ENVIRONMENT"] || "beplinktest" end -end +end \ No newline at end of file diff --git a/config/environments/development.rb b/config/environments/development.rb index 805361a92..6da236837 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -16,16 +16,16 @@ # Run rails dev:cache to toggle caching. if Rails.root.join('tmp', 'caching-dev.txt').exist? config.action_controller.perform_caching = true + config.action_controller.enable_fragment_cache_logging = true config.public_file_server.headers = { 'Cache-Control' => "public, max-age=#{2.days.to_i}" } - else config.action_controller.perform_caching = false end - # Store uploaded files on the local file system (see config/storage.yml for options) + # Store uploaded files on the local file system (see config/storage.yml for options). config.active_storage.service = :local # Don't care if the mailer can't send. @@ -50,14 +50,14 @@ # Suppress logger output for asset requests. config.assets.quiet = true - # Raises error for missing translations + # Raises error for missing translations. # config.action_view.raise_on_missing_translations = true # Use an evented file watcher to asynchronously detect changes in source code, # routes, locales, etc. This feature depends on the listen gem. # config.file_watcher = ActiveSupport::EventedFileUpdateChecker - + #========================================================================================= # eFolder - Custom Config Settings # Keep all efolder specific config settings below for clean diff's when upgrading rails @@ -74,4 +74,4 @@ config.sqs_create_queues = true config.sqs_endpoint = 'http://localhost:4566' -end +end \ No newline at end of file diff --git a/config/environments/production.rb b/config/environments/production.rb index 1f8fd447c..1c3f7a9d3 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -29,8 +29,6 @@ # Do not fallback to assets pipeline if a precompiled asset is missed. config.assets.compile = false - # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb - # Enable serving of images, stylesheets, and JavaScripts from an asset server. # config.action_controller.asset_host = 'http://assets.example.com' @@ -38,10 +36,10 @@ # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX - # Store uploaded files on the local file system (see config/storage.yml for options) + # Store uploaded files on the local file system (see config/storage.yml for options). config.active_storage.service = :local - # Mount Action Cable outside main process or domain + # Mount Action Cable outside main process or domain. # config.action_cable.mount_path = nil # config.action_cable.url = 'wss://example.com/cable' # config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ] @@ -60,9 +58,9 @@ # Use a different cache store in production. # config.cache_store = :mem_cache_store - # Use a real queuing backend for Active Job (and separate queues per environment) + # Use a real queuing backend for Active Job (and separate queues per environment). # config.active_job.queue_adapter = :resque - # config.active_job.queue_name_prefix = "caseflow_efolder_#{Rails.env}" + # config.active_job.queue_name_prefix = "caseflow_efolder_production" config.action_mailer.perform_caching = false @@ -93,6 +91,27 @@ # Do not dump schema after migrations. config.active_record.dump_schema_after_migration = false + # Inserts middleware to perform automatic connection switching. + # The `database_selector` hash is used to pass options to the DatabaseSelector + # middleware. The `delay` is used to determine how long to wait after a write + # to send a subsequent read to the primary. + # + # The `database_resolver` class is used by the middleware to determine which + # database is appropriate to use based on the time delay. + # + # The `database_resolver_context` class is used by the middleware to set + # timestamps for the last write to the primary. The resolver uses the context + # class timestamps to determine how long to wait before reading from the + # replica. + # + # By default Rails will store a last write timestamp in the session. The + # DatabaseSelector middleware is designed as such you can define your own + # strategy for connection switching and pass that into the middleware through + # these configuration options. + # config.active_record.database_selector = { delay: 2.seconds } + # config.active_record.database_resolver = ActiveRecord::Middleware::DatabaseSelector::Resolver + # config.active_record.database_resolver_context = ActiveRecord::Middleware::DatabaseSelector::Resolver::Session + #========================================================================================= # eFolder - Custom Config Settings @@ -104,4 +123,4 @@ config.s3_bucket_name = ENV["AWS_BUCKET_NAME"] config.api_key = ENV["EFOLDER_API_KEY"] -end +end \ No newline at end of file diff --git a/config/environments/test.rb b/config/environments/test.rb index e4170a107..8657df185 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -1,10 +1,11 @@ +# The test environment is used exclusively to run your application's +# test suite. You never need to work with it otherwise. Remember that +# your test database is "scratch space" for the test suite and is wiped +# and recreated between test runs. Don't rely on the data there! + Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. - # The test environment is used exclusively to run your application's - # test suite. You never need to work with it otherwise. Remember that - # your test database is "scratch space" for the test suite and is wiped - # and recreated between test runs. Don't rely on the data there! config.cache_classes = true # Do not eager load code on boot. This avoids loading your whole application @@ -21,6 +22,7 @@ # Show full error reports and disable caching. config.consider_all_requests_local = true config.action_controller.perform_caching = false + #config.cache_store = :null_store # Raise exceptions instead of rendering exception templates. config.action_dispatch.show_exceptions = false @@ -28,7 +30,7 @@ # Disable request forgery protection in test environment. config.action_controller.allow_forgery_protection = false - # Store uploaded files on the local file system in a temporary directory + # Store uploaded files on the local file system in a temporary directory. config.active_storage.service = :test config.action_mailer.perform_caching = false @@ -41,7 +43,7 @@ # Print deprecation notices to the stderr. config.active_support.deprecation = :stderr - # Raises error for missing translations + # Raises error for missing translations. # config.action_view.raise_on_missing_translations = true @@ -52,4 +54,4 @@ config.s3_enabled = false config.api_key = "token" -end +end \ No newline at end of file diff --git a/config/initializers/content_security_policy.rb b/config/initializers/content_security_policy.rb index d3bcaa5ec..f819e1559 100644 --- a/config/initializers/content_security_policy.rb +++ b/config/initializers/content_security_policy.rb @@ -11,6 +11,8 @@ # policy.object_src :none # policy.script_src :self, :https # policy.style_src :self, :https +# # If you are using webpack-dev-server then specify webpack-dev-server host +# policy.connect_src :self, :https, "http://localhost:3035", "ws://localhost:3035" if Rails.env.development? # # Specify URI for violation reports # # policy.report_uri "/csp-violation-report-endpoint" @@ -19,7 +21,10 @@ # 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 -# Rails.application.config.content_security_policy_report_only = true +# Rails.application.config.content_security_policy_report_only = true \ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml index decc5a857..7670601d9 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -27,7 +27,7 @@ # 'true': 'foo' # # To learn more, please read the Rails Internationalization guide -# available at http://guides.rubyonrails.org/i18n.html. +# available at https://guides.rubyonrails.org/i18n.html. en: - hello: "Hello world" + hello: "Hello world" \ No newline at end of file diff --git a/config/puma.rb b/config/puma.rb index 989b288d2..dcb90d220 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -4,8 +4,9 @@ # the maximum value specified for Puma. Default is set to 5 threads for minimum # and maximum; this matches the default thread size of Active Record. # -threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 } -threads threads_count, threads_count +max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 } +min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count } +threads min_threads_count, max_threads_count # Specifies the `port` that Puma will listen on to receive requests; default is 3000. # @@ -19,7 +20,7 @@ pidfile ENV.fetch("PIDFILE") { "tmp/pids/puma.pid" } # Specifies the number of `workers` to boot in clustered mode. -# Workers are forked webserver processes. If using threads and workers together +# Workers are forked web server processes. If using threads and workers together # the concurrency of the application would be max `threads` * `workers`. # Workers do not work on JRuby or Windows (both of which do not support # processes). @@ -34,4 +35,4 @@ # preload_app! # Allow puma to be restarted by `rails restart` command. -plugin :tmp_restart +plugin :tmp_restart \ No newline at end of file diff --git a/spec/models/manifest_source_spec.rb b/spec/models/manifest_source_spec.rb index 2aac89446..d709f2dd2 100644 --- a/spec/models/manifest_source_spec.rb +++ b/spec/models/manifest_source_spec.rb @@ -62,7 +62,7 @@ context "when fetched more than 3 hours ago" do before do - source.update_attributes!(fetched_at: Time.zone.now - 4.hours, status: :success) + source.update!(fetched_at: Time.zone.now - 4.hours, status: :success) end it "starts the manifest job" do @@ -73,7 +73,7 @@ context "when failed" do before do - source.update_attributes!(fetched_at: Time.zone.now - 2.hours, status: :failed) + source.update!(fetched_at: Time.zone.now - 2.hours, status: :failed) end it "starts the manifest job" do @@ -84,7 +84,7 @@ context "when manifest is pending less than 24 hours" do before do - source.update_attributes!(fetched_at: Time.zone.now - 3.hours, status: :pending) + source.update!(fetched_at: Time.zone.now - 3.hours, status: :pending) end it "does not start the manifest job" do @@ -95,7 +95,7 @@ context "when manifest is pending more than 24 hours" do before do - source.update_attributes!(fetched_at: Time.zone.now - 25.hours, status: :pending) + source.update!(fetched_at: Time.zone.now - 25.hours, status: :pending) end it "starts the manifest job" do @@ -106,7 +106,7 @@ context "when fetched less than 3 hours ago" do before do - source.update_attributes!(fetched_at: Time.zone.now - 2.hours, status: :success) + source.update!(fetched_at: Time.zone.now - 2.hours, status: :success) end it "does not start the manifest job" do