From 5ee4e4e4ce932cb087cb507c2d19b1394a6236f1 Mon Sep 17 00:00:00 2001 From: Bill Klenotiz Date: Tue, 15 Nov 2022 16:24:56 -0500 Subject: [PATCH 01/35] rename controller concerns and add deprecated method to logger class --- .../concerns/shopify_app/authenticated.rb | 13 ++--- .../shopify_app/ensure_has_session.rb | 19 +++++++ .../concerns/shopify_app/ensure_installed.rb | 56 +++++++++++++++++++ .../shopify_app/require_known_shop.rb | 48 +--------------- lib/shopify_app/logger.rb | 22 ++++++-- 5 files changed, 99 insertions(+), 59 deletions(-) create mode 100644 app/controllers/concerns/shopify_app/ensure_has_session.rb create mode 100644 app/controllers/concerns/shopify_app/ensure_installed.rb diff --git a/app/controllers/concerns/shopify_app/authenticated.rb b/app/controllers/concerns/shopify_app/authenticated.rb index fba8fbb95..84d1e4358 100644 --- a/app/controllers/concerns/shopify_app/authenticated.rb +++ b/app/controllers/concerns/shopify_app/authenticated.rb @@ -5,15 +5,10 @@ module Authenticated extend ActiveSupport::Concern included do - include ShopifyApp::Localization - include ShopifyApp::LoginProtection - include ShopifyApp::CsrfProtection - include ShopifyApp::EmbeddedApp - include ShopifyApp::EnsureBilling - - before_action :login_again_if_different_user_or_shop - around_action :activate_shopify_session - after_action :add_top_level_redirection_headers + ShopifyApp::Logger.deprecated("RequireKnownShop has been renamed to EnsureInstalled."\ + " Please use EnsureInstalled controller concern for the same behavior") end + + include ShopifyApp::EnsureHasSession end end diff --git a/app/controllers/concerns/shopify_app/ensure_has_session.rb b/app/controllers/concerns/shopify_app/ensure_has_session.rb new file mode 100644 index 000000000..7e3159fd3 --- /dev/null +++ b/app/controllers/concerns/shopify_app/ensure_has_session.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +module ShopifyApp + module EnsureHasSession + extend ActiveSupport::Concern + + included do + include ShopifyApp::Localization + include ShopifyApp::LoginProtection + include ShopifyApp::CsrfProtection + include ShopifyApp::EmbeddedApp + include ShopifyApp::EnsureBilling + + before_action :login_again_if_different_user_or_shop + around_action :activate_shopify_session + after_action :add_top_level_redirection_headers + end + end +end diff --git a/app/controllers/concerns/shopify_app/ensure_installed.rb b/app/controllers/concerns/shopify_app/ensure_installed.rb new file mode 100644 index 000000000..44ad06c16 --- /dev/null +++ b/app/controllers/concerns/shopify_app/ensure_installed.rb @@ -0,0 +1,56 @@ +# frozen_string_literal: true + +module ShopifyApp + module EnsureInstalled + extend ActiveSupport::Concern + include ShopifyApp::RedirectForEmbedded + + included do + if ancestors.include?(ShopifyApp::LoginProtection) + ActiveSupport::Deprecation.warn(<<~EOS) + We detected the use of incompatible concerns (EnsureInstalled and LoginProtection) in #{name}, + which may lead to unpredictable behavior. In a future release of this library this will raise an error. + EOS + + end + + before_action :check_shop_domain + before_action :check_shop_known + end + + def current_shopify_domain + return if params[:shop].blank? + + @shopify_domain ||= ShopifyApp::Utils.sanitize_shop_domain(params[:shop]) + end + + private + + def check_shop_domain + redirect_to(ShopifyApp.configuration.login_url) unless current_shopify_domain + end + + def check_shop_known + @shop = SessionRepository.retrieve_shop_session_by_shopify_domain(current_shopify_domain) + unless @shop + if embedded_param? + redirect_for_embedded + else + redirect_to(shop_login) + end + end + end + + def shop_login + url = URI(ShopifyApp.configuration.login_url) + + url.query = URI.encode_www_form( + shop: params[:shop], + host: params[:host], + return_to: request.fullpath, + ) + + url.to_s + end + end +end diff --git a/app/controllers/concerns/shopify_app/require_known_shop.rb b/app/controllers/concerns/shopify_app/require_known_shop.rb index f0721fade..d0deaffc0 100644 --- a/app/controllers/concerns/shopify_app/require_known_shop.rb +++ b/app/controllers/concerns/shopify_app/require_known_shop.rb @@ -3,54 +3,12 @@ module ShopifyApp module RequireKnownShop extend ActiveSupport::Concern - include ShopifyApp::RedirectForEmbedded included do - if ancestors.include?(ShopifyApp::LoginProtection) - ActiveSupport::Deprecation.warn(<<~EOS) - We detected the use of incompatible concerns (RequireKnownShop and LoginProtection) in #{name}, - which may lead to unpredictable behavior. In a future release of this library this will raise an error. - EOS - - end - - before_action :check_shop_domain - before_action :check_shop_known + ShopifyApp::Logger.deprecated("RequireKnownShop has been renamed to EnsureInstalled."\ + " Please use EnsureInstalled controller concern for the same behavior") end - def current_shopify_domain - return if params[:shop].blank? - - @shopify_domain ||= ShopifyApp::Utils.sanitize_shop_domain(params[:shop]) - end - - private - - def check_shop_domain - redirect_to(ShopifyApp.configuration.login_url) unless current_shopify_domain - end - - def check_shop_known - @shop = SessionRepository.retrieve_shop_session_by_shopify_domain(current_shopify_domain) - unless @shop - if embedded_param? - redirect_for_embedded - else - redirect_to(shop_login) - end - end - end - - def shop_login - url = URI(ShopifyApp.configuration.login_url) - - url.query = URI.encode_www_form( - shop: params[:shop], - host: params[:host], - return_to: request.fullpath, - ) - - url.to_s - end + include ShopifyApp::EnsureInstalled end end diff --git a/lib/shopify_app/logger.rb b/lib/shopify_app/logger.rb index c93497859..7b99369d4 100644 --- a/lib/shopify_app/logger.rb +++ b/lib/shopify_app/logger.rb @@ -1,17 +1,16 @@ # frozen_string_literal: true module ShopifyApp - module Logger + class Logger LOG_LEVELS = { debug: 0, info: 1, warn: 2, error: 3, off: 6 } DEFAULT_LOG_LEVEL = :info def self.send_to_logger(log_level, message) return unless enabled_for_log_level?(log_level) - current_shop = ShopifyAPI::Context.active_session&.shop || "Unknown Shop" - message_context = "[ ShopifyApp | #{log_level.to_s.upcase} | #{current_shop} ] #{message}" + full_message = "#{context(log_level)} #{message}" - ShopifyAPI::Context.logger.public_send(log_level, message_context) + ShopifyAPI::Context.logger.send(log_level, full_message) end def self.debug(message) @@ -30,7 +29,20 @@ def self.error(message) send_to_logger(:error, message) end - def self.enabled_for_log_level?(log_level) + def self.deprecated(message) + return unless enabled_for_log_level?(:warn) + + ActiveSupport::Deprecation.warn("#{context(:warn)} #{message}") + end + + private + + def context(log_level) + current_shop = ShopifyAPI::Context.active_session&.shop || "Shop Not Found" + "[ ShopifyApp | #{log_level.to_s.upcase} | #{current_shop} ]" + end + + def enabled_for_log_level?(log_level) raise(ShopifyApp::ConfigurationError, "Invalid Log Level - #{log_level}") unless LOG_LEVELS.keys.include?(log_level) From 18a0c0245c19960ff14f37e7924b1049b3cc9404 Mon Sep 17 00:00:00 2001 From: Bill Klenotiz Date: Tue, 15 Nov 2022 16:27:43 -0500 Subject: [PATCH 02/35] use logger deprecation method --- app/controllers/concerns/shopify_app/ensure_installed.rb | 2 +- app/controllers/shopify_app/callback_controller.rb | 2 +- lib/shopify_app/controller_concerns/login_protection.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/concerns/shopify_app/ensure_installed.rb b/app/controllers/concerns/shopify_app/ensure_installed.rb index 44ad06c16..136a8aa62 100644 --- a/app/controllers/concerns/shopify_app/ensure_installed.rb +++ b/app/controllers/concerns/shopify_app/ensure_installed.rb @@ -7,7 +7,7 @@ module EnsureInstalled included do if ancestors.include?(ShopifyApp::LoginProtection) - ActiveSupport::Deprecation.warn(<<~EOS) + ShopifyApp::Logger.deprecated(<<~EOS) We detected the use of incompatible concerns (EnsureInstalled and LoginProtection) in #{name}, which may lead to unpredictable behavior. In a future release of this library this will raise an error. EOS diff --git a/app/controllers/shopify_app/callback_controller.rb b/app/controllers/shopify_app/callback_controller.rb index b6e37dd57..099017b42 100644 --- a/app/controllers/shopify_app/callback_controller.rb +++ b/app/controllers/shopify_app/callback_controller.rb @@ -19,7 +19,7 @@ def callback ) rescue => e unless e.class.module_parent == ShopifyAPI::Errors - ActiveSupport::Deprecation.warn(<<~EOS) + ShopifyApp::Logger.deprecated(<<~EOS) An error of type #{e.class} was rescued. This is not part of `ShopifyAPI::Errors`, which could indicate a bug in your app, or a bug in the shopify_app gem. Future versions of the gem may re-raise this error rather than rescuing it. diff --git a/lib/shopify_app/controller_concerns/login_protection.rb b/lib/shopify_app/controller_concerns/login_protection.rb index 98f8c1df5..9b61f74a9 100644 --- a/lib/shopify_app/controller_concerns/login_protection.rb +++ b/lib/shopify_app/controller_concerns/login_protection.rb @@ -10,7 +10,7 @@ module LoginProtection included do if ancestors.include?(ShopifyApp::RequireKnownShop) - ActiveSupport::Deprecation.warn(<<~EOS) + ShopifyApp::Logger.deprecated(<<~EOS) We detected the use of incompatible concerns (RequireKnownShop and LoginProtection) in #{name}, which may lead to unpredictable behavior. In a future release of this library this will raise an error. EOS From 9f543fe37bd77208482cdec8e323ad0df449d56d Mon Sep 17 00:00:00 2001 From: Bill Klenotiz Date: Tue, 15 Nov 2022 16:29:36 -0500 Subject: [PATCH 03/35] fix private methods --- lib/shopify_app/logger.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/shopify_app/logger.rb b/lib/shopify_app/logger.rb index 7b99369d4..49dd11f10 100644 --- a/lib/shopify_app/logger.rb +++ b/lib/shopify_app/logger.rb @@ -37,12 +37,12 @@ def self.deprecated(message) private - def context(log_level) + def self.context(log_level) current_shop = ShopifyAPI::Context.active_session&.shop || "Shop Not Found" "[ ShopifyApp | #{log_level.to_s.upcase} | #{current_shop} ]" end - def enabled_for_log_level?(log_level) + def self.enabled_for_log_level?(log_level) raise(ShopifyApp::ConfigurationError, "Invalid Log Level - #{log_level}") unless LOG_LEVELS.keys.include?(log_level) From 194c9992a4e55cf711065f3560735fdd7798e143 Mon Sep 17 00:00:00 2001 From: Bill Klenotiz Date: Tue, 15 Nov 2022 16:38:43 -0500 Subject: [PATCH 04/35] just keep it a module --- lib/shopify_app/logger.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/shopify_app/logger.rb b/lib/shopify_app/logger.rb index 49dd11f10..39c484d3b 100644 --- a/lib/shopify_app/logger.rb +++ b/lib/shopify_app/logger.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module ShopifyApp - class Logger + module Logger LOG_LEVELS = { debug: 0, info: 1, warn: 2, error: 3, off: 6 } DEFAULT_LOG_LEVEL = :info @@ -35,8 +35,6 @@ def self.deprecated(message) ActiveSupport::Deprecation.warn("#{context(:warn)} #{message}") end - private - def self.context(log_level) current_shop = ShopifyAPI::Context.active_session&.shop || "Shop Not Found" "[ ShopifyApp | #{log_level.to_s.upcase} | #{current_shop} ]" From ed55ef3edc25ee13171d6a00c931b9239e4c4d1a Mon Sep 17 00:00:00 2001 From: Bill Klenotiz Date: Tue, 15 Nov 2022 16:51:20 -0500 Subject: [PATCH 05/35] replaced by instead of renamed --- app/controllers/concerns/shopify_app/authenticated.rb | 2 +- app/controllers/concerns/shopify_app/require_known_shop.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/concerns/shopify_app/authenticated.rb b/app/controllers/concerns/shopify_app/authenticated.rb index 84d1e4358..35e93a43d 100644 --- a/app/controllers/concerns/shopify_app/authenticated.rb +++ b/app/controllers/concerns/shopify_app/authenticated.rb @@ -5,7 +5,7 @@ module Authenticated extend ActiveSupport::Concern included do - ShopifyApp::Logger.deprecated("RequireKnownShop has been renamed to EnsureInstalled."\ + ShopifyApp::Logger.deprecated("RequireKnownShop has been replaced by to EnsureInstalled."\ " Please use EnsureInstalled controller concern for the same behavior") end diff --git a/app/controllers/concerns/shopify_app/require_known_shop.rb b/app/controllers/concerns/shopify_app/require_known_shop.rb index d0deaffc0..96f9efd1c 100644 --- a/app/controllers/concerns/shopify_app/require_known_shop.rb +++ b/app/controllers/concerns/shopify_app/require_known_shop.rb @@ -5,7 +5,7 @@ module RequireKnownShop extend ActiveSupport::Concern included do - ShopifyApp::Logger.deprecated("RequireKnownShop has been renamed to EnsureInstalled."\ + ShopifyApp::Logger.deprecated("RequireKnownShop has been replaced by to EnsureInstalled."\ " Please use EnsureInstalled controller concern for the same behavior") end From 490a93c981941914023630c63012971c74cc60d1 Mon Sep 17 00:00:00 2001 From: Bill Klenotiz Date: Wed, 16 Nov 2022 09:39:37 -0500 Subject: [PATCH 06/35] add version number to deprecated message --- lib/shopify_app/logger.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/shopify_app/logger.rb b/lib/shopify_app/logger.rb index 39c484d3b..e8d66c8a8 100644 --- a/lib/shopify_app/logger.rb +++ b/lib/shopify_app/logger.rb @@ -29,10 +29,10 @@ def self.error(message) send_to_logger(:error, message) end - def self.deprecated(message) + def self.deprecated(message, version) return unless enabled_for_log_level?(:warn) - ActiveSupport::Deprecation.warn("#{context(:warn)} #{message}") + ActiveSupport::Deprecation.warn("[#{version}] #{context(:warn)} #{message}") end def self.context(log_level) From a785fc294e20206d1c0cbfe0173655e8b132a434 Mon Sep 17 00:00:00 2001 From: Bill Klenotiz Date: Wed, 16 Nov 2022 12:07:51 -0500 Subject: [PATCH 07/35] add versions to deprecated messages --- app/controllers/concerns/shopify_app/authenticated.rb | 2 +- app/controllers/concerns/shopify_app/ensure_installed.rb | 8 +++++--- .../concerns/shopify_app/require_known_shop.rb | 2 +- app/controllers/shopify_app/callback_controller.rb | 3 ++- lib/shopify_app/controller_concerns/login_protection.rb | 3 ++- 5 files changed, 11 insertions(+), 7 deletions(-) diff --git a/app/controllers/concerns/shopify_app/authenticated.rb b/app/controllers/concerns/shopify_app/authenticated.rb index 35e93a43d..dbd01328c 100644 --- a/app/controllers/concerns/shopify_app/authenticated.rb +++ b/app/controllers/concerns/shopify_app/authenticated.rb @@ -6,7 +6,7 @@ module Authenticated included do ShopifyApp::Logger.deprecated("RequireKnownShop has been replaced by to EnsureInstalled."\ - " Please use EnsureInstalled controller concern for the same behavior") + " Please use EnsureInstalled controller concern for the same behavior", "22.0.0") end include ShopifyApp::EnsureHasSession diff --git a/app/controllers/concerns/shopify_app/ensure_installed.rb b/app/controllers/concerns/shopify_app/ensure_installed.rb index 136a8aa62..230ff56a0 100644 --- a/app/controllers/concerns/shopify_app/ensure_installed.rb +++ b/app/controllers/concerns/shopify_app/ensure_installed.rb @@ -7,10 +7,12 @@ module EnsureInstalled included do if ancestors.include?(ShopifyApp::LoginProtection) - ShopifyApp::Logger.deprecated(<<~EOS) - We detected the use of incompatible concerns (EnsureInstalled and LoginProtection) in #{name}, - which may lead to unpredictable behavior. In a future release of this library this will raise an error. + message = <<~EOS) + We detected the use of incompatible concerns (EnsureInstalled and LoginProtection) in #{name}, + which may lead to unpredictable behavior. In a future release of this library this will raise an error. EOS + + ShopifyApp::Logger.deprecated(message ,"22.0.0") end diff --git a/app/controllers/concerns/shopify_app/require_known_shop.rb b/app/controllers/concerns/shopify_app/require_known_shop.rb index 96f9efd1c..46d65bf4e 100644 --- a/app/controllers/concerns/shopify_app/require_known_shop.rb +++ b/app/controllers/concerns/shopify_app/require_known_shop.rb @@ -6,7 +6,7 @@ module RequireKnownShop included do ShopifyApp::Logger.deprecated("RequireKnownShop has been replaced by to EnsureInstalled."\ - " Please use EnsureInstalled controller concern for the same behavior") + " Please use EnsureInstalled controller concern for the same behavior", "22.0.0") end include ShopifyApp::EnsureInstalled diff --git a/app/controllers/shopify_app/callback_controller.rb b/app/controllers/shopify_app/callback_controller.rb index 099017b42..5c167dbe5 100644 --- a/app/controllers/shopify_app/callback_controller.rb +++ b/app/controllers/shopify_app/callback_controller.rb @@ -19,11 +19,12 @@ def callback ) rescue => e unless e.class.module_parent == ShopifyAPI::Errors - ShopifyApp::Logger.deprecated(<<~EOS) + message = <<~EOS) An error of type #{e.class} was rescued. This is not part of `ShopifyAPI::Errors`, which could indicate a bug in your app, or a bug in the shopify_app gem. Future versions of the gem may re-raise this error rather than rescuing it. EOS + ShopifyApp::Logger.deprecated(message, "22.0.0") end return respond_with_error end diff --git a/lib/shopify_app/controller_concerns/login_protection.rb b/lib/shopify_app/controller_concerns/login_protection.rb index 9b61f74a9..110f7634a 100644 --- a/lib/shopify_app/controller_concerns/login_protection.rb +++ b/lib/shopify_app/controller_concerns/login_protection.rb @@ -10,10 +10,11 @@ module LoginProtection included do if ancestors.include?(ShopifyApp::RequireKnownShop) - ShopifyApp::Logger.deprecated(<<~EOS) + message = <<~EOS) We detected the use of incompatible concerns (RequireKnownShop and LoginProtection) in #{name}, which may lead to unpredictable behavior. In a future release of this library this will raise an error. EOS + ShopifyApp::Logger.deprecated(message, "22.0.0") end after_action :set_test_cookie From cc706d4c841228f31bf903c6e7f3f20fe60ca8cf Mon Sep 17 00:00:00 2001 From: Bill Klenotiz Date: Wed, 16 Nov 2022 12:23:05 -0500 Subject: [PATCH 08/35] fix strings and add version check --- app/controllers/concerns/shopify_app/ensure_installed.rb | 4 ++-- app/controllers/shopify_app/callback_controller.rb | 2 +- lib/shopify_app/controller_concerns/login_protection.rb | 2 +- lib/shopify_app/logger.rb | 2 ++ 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/controllers/concerns/shopify_app/ensure_installed.rb b/app/controllers/concerns/shopify_app/ensure_installed.rb index 230ff56a0..a5e689648 100644 --- a/app/controllers/concerns/shopify_app/ensure_installed.rb +++ b/app/controllers/concerns/shopify_app/ensure_installed.rb @@ -7,11 +7,11 @@ module EnsureInstalled included do if ancestors.include?(ShopifyApp::LoginProtection) - message = <<~EOS) + message = <<~EOS We detected the use of incompatible concerns (EnsureInstalled and LoginProtection) in #{name}, which may lead to unpredictable behavior. In a future release of this library this will raise an error. EOS - + ShopifyApp::Logger.deprecated(message ,"22.0.0") end diff --git a/app/controllers/shopify_app/callback_controller.rb b/app/controllers/shopify_app/callback_controller.rb index 5c167dbe5..323f18ae4 100644 --- a/app/controllers/shopify_app/callback_controller.rb +++ b/app/controllers/shopify_app/callback_controller.rb @@ -19,7 +19,7 @@ def callback ) rescue => e unless e.class.module_parent == ShopifyAPI::Errors - message = <<~EOS) + message = <<~EOS An error of type #{e.class} was rescued. This is not part of `ShopifyAPI::Errors`, which could indicate a bug in your app, or a bug in the shopify_app gem. Future versions of the gem may re-raise this error rather than rescuing it. diff --git a/lib/shopify_app/controller_concerns/login_protection.rb b/lib/shopify_app/controller_concerns/login_protection.rb index 110f7634a..749adec9e 100644 --- a/lib/shopify_app/controller_concerns/login_protection.rb +++ b/lib/shopify_app/controller_concerns/login_protection.rb @@ -10,7 +10,7 @@ module LoginProtection included do if ancestors.include?(ShopifyApp::RequireKnownShop) - message = <<~EOS) + message = <<~EOS We detected the use of incompatible concerns (RequireKnownShop and LoginProtection) in #{name}, which may lead to unpredictable behavior. In a future release of this library this will raise an error. EOS diff --git a/lib/shopify_app/logger.rb b/lib/shopify_app/logger.rb index e8d66c8a8..75c587413 100644 --- a/lib/shopify_app/logger.rb +++ b/lib/shopify_app/logger.rb @@ -32,6 +32,8 @@ def self.error(message) def self.deprecated(message, version) return unless enabled_for_log_level?(:warn) + raise unless ShopifyApp::VERSION < version + ActiveSupport::Deprecation.warn("[#{version}] #{context(:warn)} #{message}") end From 3cde1ee3e5b2f57540a51cf277d55e5f58957d4f Mon Sep 17 00:00:00 2001 From: Bill Klenotiz Date: Wed, 16 Nov 2022 13:09:16 -0500 Subject: [PATCH 09/35] add depreaction tests for ci --- app/controllers/concerns/shopify_app/authenticated.rb | 4 ++-- test/controllers/concerns/authenticated_test.rb | 11 +++++++++++ test/controllers/concerns/require_known_shop_test.rb | 11 +++++++++++ test/test_helper.rb | 1 + 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/app/controllers/concerns/shopify_app/authenticated.rb b/app/controllers/concerns/shopify_app/authenticated.rb index dbd01328c..b12ab72a6 100644 --- a/app/controllers/concerns/shopify_app/authenticated.rb +++ b/app/controllers/concerns/shopify_app/authenticated.rb @@ -5,8 +5,8 @@ module Authenticated extend ActiveSupport::Concern included do - ShopifyApp::Logger.deprecated("RequireKnownShop has been replaced by to EnsureInstalled."\ - " Please use EnsureInstalled controller concern for the same behavior", "22.0.0") + ShopifyApp::Logger.deprecated("Authenticated has been replaced by to EnsureHasSession."\ + " Please use EnsureHasSession controller concern for the same behavior", "22.0.0") end include ShopifyApp::EnsureHasSession diff --git a/test/controllers/concerns/authenticated_test.rb b/test/controllers/concerns/authenticated_test.rb index c12c6cbd0..53ea3a9e6 100644 --- a/test/controllers/concerns/authenticated_test.rb +++ b/test/controllers/concerns/authenticated_test.rb @@ -19,4 +19,15 @@ def index AuthenticatedTestController.include?(ShopifyApp::EmbeddedApp) AuthenticatedTestController.include?(ShopifyApp::EnsureBilling) end + + test "detects deprecation message" do + ActiveSupport::Deprecation.expects(:warn).with( + "[22.0.0] [ ShopifyApp | WARN | Shop Not Found ] "\ + "Authenticated has been replaced by to EnsureHasSession. "\ + "Please use EnsureHasSession controller concern for the same behavior") + + Class.new(ApplicationController) do + include ShopifyApp::Authenticated + end + end end diff --git a/test/controllers/concerns/require_known_shop_test.rb b/test/controllers/concerns/require_known_shop_test.rb index 944d305e3..2bd17ce92 100644 --- a/test/controllers/concerns/require_known_shop_test.rb +++ b/test/controllers/concerns/require_known_shop_test.rb @@ -86,4 +86,15 @@ def index end end end + + test "detects deprecation message" do + ActiveSupport::Deprecation.expects(:warn).with( + "[22.0.0] [ ShopifyApp | WARN | Shop Not Found ] "\ + "RequireKnownShop has been replaced by to EnsureInstalled. "\ + "Please use EnsureInstalled controller concern for the same behavior") + + Class.new(ApplicationController) do + include ShopifyApp::RequireKnownShop + end + end end diff --git a/test/test_helper.rb b/test/test_helper.rb index 26871f8f5..2d6df3e5d 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -48,6 +48,7 @@ def before_setup ShopifyAppConfigurer.call Rails.application.reload_routes! ShopifyApp.configuration.log_level = :warn + # ActiveSupport::Deprecation.silenced = true end def mock_session(shop: "my-shop.myshopify.com", scope: ShopifyApp.configuration.scope) From 1bc695290068c30d0b505baa1792ddc961f27184 Mon Sep 17 00:00:00 2001 From: Bill Klenotiz Date: Thu, 17 Nov 2022 09:58:26 -0500 Subject: [PATCH 10/35] fix test spam --- test/controllers/callback_controller_test.rb | 3 +++ .../concerns/authenticated_test.rb | 15 +++++++------- .../concerns/require_known_shop_test.rb | 20 +++++++++++-------- .../login_protection_test.rb | 3 +++ test/test_helper.rb | 2 +- 5 files changed, 27 insertions(+), 16 deletions(-) diff --git a/test/controllers/callback_controller_test.rb b/test/controllers/callback_controller_test.rb index 21e70ef9c..1683084f2 100644 --- a/test/controllers/callback_controller_test.rb +++ b/test/controllers/callback_controller_test.rb @@ -57,12 +57,15 @@ class CallbackControllerTest < ActionController::TestCase end test "#callback rescued errors other than ShopifyAPI::Error will emit a deprecation notice" do + parent_deprecation_setting = ActiveSupport::Deprecation.silenced + ActiveSupport::Deprecation.silenced = false ShopifyAPI::Auth::Oauth.expects(:validate_auth_callback).raises(StandardError) assert_deprecated(/An error of type StandardError was rescued/) do get :callback, params: { shop: "shop", code: "code", state: "state", timestamp: "timestamp", host: "host", hmac: "hmac" } end assert_equal flash[:error], "Could not log in to Shopify store" + ActiveSupport::Deprecation.silenced = parent_deprecation_setting end test "#callback calls ShopifyAPI::Auth::Oauth.validate_auth_callback" do diff --git a/test/controllers/concerns/authenticated_test.rb b/test/controllers/concerns/authenticated_test.rb index 53ea3a9e6..bd9358a44 100644 --- a/test/controllers/concerns/authenticated_test.rb +++ b/test/controllers/concerns/authenticated_test.rb @@ -21,13 +21,14 @@ def index end test "detects deprecation message" do - ActiveSupport::Deprecation.expects(:warn).with( - "[22.0.0] [ ShopifyApp | WARN | Shop Not Found ] "\ - "Authenticated has been replaced by to EnsureHasSession. "\ - "Please use EnsureHasSession controller concern for the same behavior") - - Class.new(ApplicationController) do - include ShopifyApp::Authenticated + parent_deprecation_setting = ActiveSupport::Deprecation.silenced + + ActiveSupport::Deprecation.silenced = false + assert_deprecated(/Authenticated has been replaced by to EnsureHasSession./) do + Class.new(ApplicationController) do + include ShopifyApp::Authenticated + end end + ActiveSupport::Deprecation.silenced = parent_deprecation_setting end end diff --git a/test/controllers/concerns/require_known_shop_test.rb b/test/controllers/concerns/require_known_shop_test.rb index 2bd17ce92..0c3052c6b 100644 --- a/test/controllers/concerns/require_known_shop_test.rb +++ b/test/controllers/concerns/require_known_shop_test.rb @@ -62,6 +62,8 @@ def index end test "detects incompatible controller concerns" do + parent_deprecation_setting = ActiveSupport::Deprecation.silenced + ActiveSupport::Deprecation.silenced = false assert_deprecated(/incompatible concerns/) do Class.new(ApplicationController) do include ShopifyApp::RequireKnownShop @@ -85,16 +87,18 @@ def index include ShopifyApp::RequireKnownShop end end + ActiveSupport::Deprecation.silenced = parent_deprecation_setting end - test "detects deprecation message" do - ActiveSupport::Deprecation.expects(:warn).with( - "[22.0.0] [ ShopifyApp | WARN | Shop Not Found ] "\ - "RequireKnownShop has been replaced by to EnsureInstalled. "\ - "Please use EnsureInstalled controller concern for the same behavior") - - Class.new(ApplicationController) do - include ShopifyApp::RequireKnownShop + test "detects name change deprecation message" do + parent_deprecation_setting = ActiveSupport::Deprecation.silenced + + ActiveSupport::Deprecation.silenced = false + assert_deprecated(/RequireKnownShop has been replaced by to EnsureInstalled./) do + Class.new(ApplicationController) do + include ShopifyApp::RequireKnownShop + end end + ActiveSupport::Deprecation.silenced = parent_deprecation_setting end end diff --git a/test/shopify_app/controller_concerns/login_protection_test.rb b/test/shopify_app/controller_concerns/login_protection_test.rb index 681ff5c17..556edb434 100644 --- a/test/shopify_app/controller_concerns/login_protection_test.rb +++ b/test/shopify_app/controller_concerns/login_protection_test.rb @@ -467,12 +467,15 @@ class LoginProtectionControllerTest < ActionController::TestCase end test "detects incompatible controller concerns" do + parent_deprecation_setting = ActiveSupport::Deprecation.silenced + ActiveSupport::Deprecation.silenced = false assert_deprecated(/incompatible concerns/) do Class.new(ApplicationController) do include ShopifyApp::LoginProtection include ShopifyApp::RequireKnownShop end end + ActiveSupport::Deprecation.silenced = parent_deprecation_setting end private diff --git a/test/test_helper.rb b/test/test_helper.rb index 2d6df3e5d..38b70a4c7 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -48,7 +48,7 @@ def before_setup ShopifyAppConfigurer.call Rails.application.reload_routes! ShopifyApp.configuration.log_level = :warn - # ActiveSupport::Deprecation.silenced = true + ActiveSupport::Deprecation.silenced = true end def mock_session(shop: "my-shop.myshopify.com", scope: ShopifyApp.configuration.scope) From a9b4b8f0fa0f82930eafc87f5f3c3b82fe6a489c Mon Sep 17 00:00:00 2001 From: Bill Klenotiz Date: Thu, 17 Nov 2022 15:05:27 -0500 Subject: [PATCH 11/35] add tests to new interface one of them is broke ahhhh --- .../concerns/ensure_has_session_test.rb | 22 +++++ .../concerns/ensure_installed_test.rb | 92 +++++++++++++++++++ 2 files changed, 114 insertions(+) create mode 100644 test/controllers/concerns/ensure_has_session_test.rb create mode 100644 test/controllers/concerns/ensure_installed_test.rb diff --git a/test/controllers/concerns/ensure_has_session_test.rb b/test/controllers/concerns/ensure_has_session_test.rb new file mode 100644 index 000000000..e65c2c503 --- /dev/null +++ b/test/controllers/concerns/ensure_has_session_test.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +require "test_helper" + +class EnsureHasSessionTest < ActionController::TestCase + class EnsureHasSessionTestController < ActionController::Base + include ShopifyApp::EnsureHasSession + + def index + end + end + + tests EnsureHasSessionTestController + + test "includes all the needed concerns" do + EnsureHasSessionTestController.include?(ShopifyApp::Localization) + EnsureHasSessionTestController.include?(ShopifyApp::LoginProtection) + EnsureHasSessionTestController.include?(ShopifyApp::CsrfProtection) + EnsureHasSessionTestController.include?(ShopifyApp::EmbeddedApp) + EnsureHasSessionTestController.include?(ShopifyApp::EnsureBilling) + end +end diff --git a/test/controllers/concerns/ensure_installed_test.rb b/test/controllers/concerns/ensure_installed_test.rb new file mode 100644 index 000000000..1d16f085f --- /dev/null +++ b/test/controllers/concerns/ensure_installed_test.rb @@ -0,0 +1,92 @@ +# frozen_string_literal: true + +require "test_helper" + +class EnsureInstalledTest < ActionController::TestCase + class UnauthenticatedTestController < ActionController::Base + include ShopifyApp::EnsureInstalled + + def index + render(html: "

Success") + end + end + + tests UnauthenticatedTestController + + setup do + Rails.application.routes.draw do + get "/unauthenticated_test", to: "ensure_installed_test/unauthenticated_test#index" + end + end + + test "redirects to login if no shop param is present" do + get :index + + assert_redirected_to ShopifyApp.configuration.login_url + end + + test "redirects to login if no shop is not a valid shopify domain" do + invalid_shop = "https://shop1.example.com" + + get :index, params: { shop: invalid_shop } + + assert_redirected_to ShopifyApp.configuration.login_url + end + + test "redirects to login if the shop is not installed" do + ShopifyApp::SessionRepository.expects(:retrieve_shop_session_by_shopify_domain).returns(false) + + shopify_domain = "shop1.myshopify.com" + host = "mock-host" + + get :index, params: { shop: shopify_domain, host: host } + + redirect_url = URI("/login") + redirect_url.query = URI.encode_www_form( + shop: shopify_domain, + host: host, + return_to: request.fullpath, + ) + + assert_redirected_to redirect_url.to_s + end + + test "returns :ok if the shop is installed" do + ShopifyApp::SessionRepository.expects(:retrieve_shop_session_by_shopify_domain).returns(true) + + shopify_domain = "shop1.myshopify.com" + + get :index, params: { shop: shopify_domain } + + assert_response :ok + end + + test "detects incompatible controller concerns" do + parent_deprecation_setting = ActiveSupport::Deprecation.silenced + ActiveSupport::Deprecation.silenced = false + assert_deprecated(/incompatible concerns/) do + Class.new(ApplicationController) do + include ShopifyApp::EnsureInstalled + include ShopifyApp::LoginProtection + end + end + + assert_deprecated(/incompatible concerns/) do + Class.new(ApplicationController) do + include ShopifyApp::EnsureInstalled + include ShopifyApp::Authenticated # since this indirectly includes LoginProtection + end + end + + assert_deprecated(/incompatible concerns/) do + authenticated_controller = Class.new(ApplicationController) do + include ShopifyApp::Authenticated + end + + Class.new(authenticated_controller) do + include ShopifyApp::EnsureInstalled + end + end + ActiveSupport::Deprecation.silenced = parent_deprecation_setting + end +end From 6edb7cbc106b27738e3975e229f6dcf85a9194dc Mon Sep 17 00:00:00 2001 From: Bill Klenotiz Date: Thu, 17 Nov 2022 21:48:01 -0500 Subject: [PATCH 12/35] add deprecation log for scripttagsmanger --- lib/shopify_app/managers/scripttags_manager.rb | 1 + test/shopify_app/managers/scripttags_manager_test.rb | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/lib/shopify_app/managers/scripttags_manager.rb b/lib/shopify_app/managers/scripttags_manager.rb index fd6240efe..b6e60b604 100644 --- a/lib/shopify_app/managers/scripttags_manager.rb +++ b/lib/shopify_app/managers/scripttags_manager.rb @@ -24,6 +24,7 @@ def self.build_src(scripttags, domain) attr_reader :required_scripttags, :shop_domain def initialize(scripttags, shop_domain) + ShopifyApp::Logger.deprecated("The ScripttagsManager will become deprecated in an upcoming version", "22.0.0") @required_scripttags = scripttags @shop_domain = shop_domain end diff --git a/test/shopify_app/managers/scripttags_manager_test.rb b/test/shopify_app/managers/scripttags_manager_test.rb index 4a7b2915c..54489f872 100644 --- a/test/shopify_app/managers/scripttags_manager_test.rb +++ b/test/shopify_app/managers/scripttags_manager_test.rb @@ -115,6 +115,15 @@ class ShopifyApp::ScripttagsManagerTest < ActiveSupport::TestCase end end + test "deprecation message is found on initialization" do + parent_deprecation_setting = ActiveSupport::Deprecation.silenced + ActiveSupport::Deprecation.silenced = false + assert_deprecated(/ScripttagsManager will become deprecated/) do + ShopifyApp::ScripttagsManager.new("scripttags", "shop_domain") + end + ActiveSupport::Deprecation.silenced = parent_deprecation_setting + end + private def expect_scripttag_creation(event, src) From 2a894d3332d2fbe75996528d8bc85fc8db5afa81 Mon Sep 17 00:00:00 2001 From: Bill Klenotiz Date: Thu, 17 Nov 2022 22:06:29 -0500 Subject: [PATCH 13/35] itp depreaction --- lib/shopify_app/controller_concerns/itp.rb | 5 +++++ .../shopify_app/controller_concerns/itp_test.rb | 17 +++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 test/shopify_app/controller_concerns/itp_test.rb diff --git a/lib/shopify_app/controller_concerns/itp.rb b/lib/shopify_app/controller_concerns/itp.rb index edafde95e..fe5310379 100644 --- a/lib/shopify_app/controller_concerns/itp.rb +++ b/lib/shopify_app/controller_concerns/itp.rb @@ -3,6 +3,11 @@ module ShopifyApp # Cookie management helpers required for ITP implementation module Itp + extend ActiveSupport::Concern + included do + ShopifyApp::Logger.deprecated("Itp will be removed in an upcoming version","22.0.0") + end + private def set_test_cookie diff --git a/test/shopify_app/controller_concerns/itp_test.rb b/test/shopify_app/controller_concerns/itp_test.rb new file mode 100644 index 000000000..8426f1c48 --- /dev/null +++ b/test/shopify_app/controller_concerns/itp_test.rb @@ -0,0 +1,17 @@ +require "test_helper" +require "action_controller" +require "action_controller/base" +require "action_view/testing/resolvers" + +class ItpTest < ActionController::TestCase + test "detects deprecation notice" do + parent_deprecation_setting = ActiveSupport::Deprecation.silenced + ActiveSupport::Deprecation.silenced = false + assert_deprecated(/Itp will be removed/) do + Class.new(ApplicationController) do + include ShopifyApp::Itp + end + end + ActiveSupport::Deprecation.silenced = parent_deprecation_setting + end +end \ No newline at end of file From 057efde34520a23ff51fc636194c7373ab23b4b8 Mon Sep 17 00:00:00 2001 From: Bill Klenotiz Date: Thu, 17 Nov 2022 22:14:09 -0500 Subject: [PATCH 14/35] add depreaction notice for marketing activities controller generator --- .../add_marketing_activity_extension_generator.rb | 1 + .../templates/marketing_activities_controller.rb | 5 +++++ .../add_marketing_activity_extension_generator_test.rb | 10 ++++++++++ 3 files changed, 16 insertions(+) diff --git a/lib/generators/shopify_app/add_marketing_activity_extension/add_marketing_activity_extension_generator.rb b/lib/generators/shopify_app/add_marketing_activity_extension/add_marketing_activity_extension_generator.rb index 6b1b4f95f..ae22fe996 100644 --- a/lib/generators/shopify_app/add_marketing_activity_extension/add_marketing_activity_extension_generator.rb +++ b/lib/generators/shopify_app/add_marketing_activity_extension/add_marketing_activity_extension_generator.rb @@ -8,6 +8,7 @@ class AddMarketingActivityExtensionGenerator < Rails::Generators::Base source_root File.expand_path("../templates", __FILE__) def generate_app_extension + ShopifyApp::Logger.deprecated("MarketingActivitiesController will be removed in an upcoming version", "22.0.0") template("marketing_activities_controller.rb", "app/controllers/marketing_activities_controller.rb") generate_routes end diff --git a/lib/generators/shopify_app/add_marketing_activity_extension/templates/marketing_activities_controller.rb b/lib/generators/shopify_app/add_marketing_activity_extension/templates/marketing_activities_controller.rb index 955b5512c..7effe4e2b 100644 --- a/lib/generators/shopify_app/add_marketing_activity_extension/templates/marketing_activities_controller.rb +++ b/lib/generators/shopify_app/add_marketing_activity_extension/templates/marketing_activities_controller.rb @@ -1,6 +1,11 @@ # frozen_string_literal: true class MarketingActivitiesController < ShopifyApp::ExtensionVerificationController + + def initialize + ShopifyApp::Logger.deprecated("The MarketingActivitiesController will be removed in an upcoming update","22.0.0") + end + def preload_form_data preload_data = { "form_data": {}, diff --git a/test/generators/add_marketing_activity_extension_generator_test.rb b/test/generators/add_marketing_activity_extension_generator_test.rb index 079f5cd80..4553f3759 100644 --- a/test/generators/add_marketing_activity_extension_generator_test.rb +++ b/test/generators/add_marketing_activity_extension_generator_test.rb @@ -37,4 +37,14 @@ class AddMarketingActivityExtensionGeneratorTest < Rails::Generators::TestCase assert routes_declarations, routes end end + + test "detect deprecation notice when generating controller" do + parent_deprecation_setting = ActiveSupport::Deprecation.silenced + ActiveSupport::Deprecation.silenced = false + assert_deprecated(/MarketingActivitiesController will be removed/) do + provide_existing_routes_file + run_generator + end + ActiveSupport::Deprecation.silenced = parent_deprecation_setting + end end From bdc3a5f8831050d58632652c534a9879eb4b9fe8 Mon Sep 17 00:00:00 2001 From: Bill Klenotiz Date: Fri, 18 Nov 2022 09:36:36 -0500 Subject: [PATCH 15/35] fix test --- app/controllers/concerns/shopify_app/ensure_installed.rb | 3 ++- test/controllers/concerns/ensure_installed_test.rb | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/controllers/concerns/shopify_app/ensure_installed.rb b/app/controllers/concerns/shopify_app/ensure_installed.rb index a5e689648..a68322f80 100644 --- a/app/controllers/concerns/shopify_app/ensure_installed.rb +++ b/app/controllers/concerns/shopify_app/ensure_installed.rb @@ -6,6 +6,8 @@ module EnsureInstalled include ShopifyApp::RedirectForEmbedded included do + # binding.pry + if ancestors.include?(ShopifyApp::LoginProtection) message = <<~EOS We detected the use of incompatible concerns (EnsureInstalled and LoginProtection) in #{name}, @@ -13,7 +15,6 @@ module EnsureInstalled EOS ShopifyApp::Logger.deprecated(message ,"22.0.0") - end before_action :check_shop_domain diff --git a/test/controllers/concerns/ensure_installed_test.rb b/test/controllers/concerns/ensure_installed_test.rb index 1d16f085f..7ad9c2366 100644 --- a/test/controllers/concerns/ensure_installed_test.rb +++ b/test/controllers/concerns/ensure_installed_test.rb @@ -66,15 +66,15 @@ def index ActiveSupport::Deprecation.silenced = false assert_deprecated(/incompatible concerns/) do Class.new(ApplicationController) do - include ShopifyApp::EnsureInstalled include ShopifyApp::LoginProtection + include ShopifyApp::EnsureInstalled end end assert_deprecated(/incompatible concerns/) do Class.new(ApplicationController) do + include ShopifyApp::EnsureHasSession # since this indirectly includes LoginProtection include ShopifyApp::EnsureInstalled - include ShopifyApp::Authenticated # since this indirectly includes LoginProtection end end From dfa7950192a6b21f2841f9b141bcf2babb0e8b2f Mon Sep 17 00:00:00 2001 From: Bill Klenotiz Date: Fri, 18 Nov 2022 14:20:03 -0500 Subject: [PATCH 16/35] add ensureinstalled to ancestor look up for login protection --- app/controllers/concerns/shopify_app/ensure_installed.rb | 2 -- lib/shopify_app/controller_concerns/login_protection.rb | 3 ++- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/app/controllers/concerns/shopify_app/ensure_installed.rb b/app/controllers/concerns/shopify_app/ensure_installed.rb index a68322f80..4ef1ca6f3 100644 --- a/app/controllers/concerns/shopify_app/ensure_installed.rb +++ b/app/controllers/concerns/shopify_app/ensure_installed.rb @@ -6,8 +6,6 @@ module EnsureInstalled include ShopifyApp::RedirectForEmbedded included do - # binding.pry - if ancestors.include?(ShopifyApp::LoginProtection) message = <<~EOS We detected the use of incompatible concerns (EnsureInstalled and LoginProtection) in #{name}, diff --git a/lib/shopify_app/controller_concerns/login_protection.rb b/lib/shopify_app/controller_concerns/login_protection.rb index 749adec9e..284b5548b 100644 --- a/lib/shopify_app/controller_concerns/login_protection.rb +++ b/lib/shopify_app/controller_concerns/login_protection.rb @@ -9,7 +9,7 @@ module LoginProtection include ShopifyApp::SanitizedParams included do - if ancestors.include?(ShopifyApp::RequireKnownShop) + if ancestors.include?(ShopifyApp::RequireKnownShop || ShopifyApp::EnsureInstalled) message = <<~EOS We detected the use of incompatible concerns (RequireKnownShop and LoginProtection) in #{name}, which may lead to unpredictable behavior. In a future release of this library this will raise an error. @@ -91,6 +91,7 @@ def add_top_level_redirection_headers(url: nil, ignore_response_code: false) ShopifyApp::Logger.debug("Setting current shop session") params[:shop] = if current_shopify_session current_shopify_session.shop + elsif (matches = request.headers["HTTP_AUTHORIZATION"]&.match(/^Bearer (.+)$/)) jwt_payload = ShopifyAPI::Auth::JwtPayload.new(T.must(matches[1])) jwt_payload.shop From bdb90432a53d4c582dc3e9509aa90592c9bd6a81 Mon Sep 17 00:00:00 2001 From: Bill Klenotiz Date: Tue, 22 Nov 2022 15:58:38 -0500 Subject: [PATCH 17/35] update logger to inherit from shopify api --- .../shopify_app/require_known_shop.rb | 10 +++-- .../install/templates/shopify_app.rb.tt | 1 + lib/shopify_app/logger.rb | 43 +------------------ test/controllers/callback_controller_test.rb | 5 +++ .../concerns/authenticated_test.rb | 8 +++- .../concerns/ensure_installed_test.rb | 5 +++ .../concerns/require_known_shop_test.rb | 11 ++++- test/dummy/config/initializers/shopify_app.rb | 1 + test/generators/install_generator_test.rb | 1 + .../login_protection_test.rb | 5 +++ 10 files changed, 42 insertions(+), 48 deletions(-) diff --git a/app/controllers/concerns/shopify_app/require_known_shop.rb b/app/controllers/concerns/shopify_app/require_known_shop.rb index 46d65bf4e..788f2cda7 100644 --- a/app/controllers/concerns/shopify_app/require_known_shop.rb +++ b/app/controllers/concerns/shopify_app/require_known_shop.rb @@ -3,12 +3,16 @@ module ShopifyApp module RequireKnownShop extend ActiveSupport::Concern - - included do + include ShopifyApp::EnsureInstalled + + def self.extended(mod) ShopifyApp::Logger.deprecated("RequireKnownShop has been replaced by to EnsureInstalled."\ " Please use EnsureInstalled controller concern for the same behavior", "22.0.0") end - include ShopifyApp::EnsureInstalled + def self.included(mod) + ShopifyApp::Logger.deprecated("RequireKnownShop has been replaced by to EnsureInstalled."\ + " Please use EnsureInstalled controller concern for the same behavior", "22.0.0") + end end end diff --git a/lib/generators/shopify_app/install/templates/shopify_app.rb.tt b/lib/generators/shopify_app/install/templates/shopify_app.rb.tt index e47fbe729..1b0e5dccf 100644 --- a/lib/generators/shopify_app/install/templates/shopify_app.rb.tt +++ b/lib/generators/shopify_app/install/templates/shopify_app.rb.tt @@ -43,6 +43,7 @@ Rails.application.config.after_initialize do is_private: !ENV.fetch('SHOPIFY_APP_PRIVATE_SHOP', '').empty?, is_embedded: ShopifyApp.configuration.embedded_app, session_storage: ShopifyApp::SessionRepository, + log_level: :info, logger: Rails.logger, private_shop: ENV.fetch('SHOPIFY_APP_PRIVATE_SHOP', nil), user_agent_prefix: "ShopifyApp/#{ShopifyApp::VERSION}" diff --git a/lib/shopify_app/logger.rb b/lib/shopify_app/logger.rb index 75c587413..1015133fd 100644 --- a/lib/shopify_app/logger.rb +++ b/lib/shopify_app/logger.rb @@ -1,52 +1,13 @@ # frozen_string_literal: true module ShopifyApp - module Logger - LOG_LEVELS = { debug: 0, info: 1, warn: 2, error: 3, off: 6 } - DEFAULT_LOG_LEVEL = :info - - def self.send_to_logger(log_level, message) - return unless enabled_for_log_level?(log_level) - - full_message = "#{context(log_level)} #{message}" - - ShopifyAPI::Context.logger.send(log_level, full_message) - end - - def self.debug(message) - send_to_logger(:debug, message) - end - - def self.info(message) - send_to_logger(:info, message) - end - - def self.warn(message) - send_to_logger(:warn, message) - end - - def self.error(message) - send_to_logger(:error, message) - end - + class Logger < ShopifyAPI::Logger def self.deprecated(message, version) return unless enabled_for_log_level?(:warn) - raise unless ShopifyApp::VERSION < version + raise StandardError unless ShopifyApp::VERSION < version ActiveSupport::Deprecation.warn("[#{version}] #{context(:warn)} #{message}") end - - def self.context(log_level) - current_shop = ShopifyAPI::Context.active_session&.shop || "Shop Not Found" - "[ ShopifyApp | #{log_level.to_s.upcase} | #{current_shop} ]" - end - - def self.enabled_for_log_level?(log_level) - raise(ShopifyApp::ConfigurationError, - "Invalid Log Level - #{log_level}") unless LOG_LEVELS.keys.include?(log_level) - - LOG_LEVELS[log_level] >= LOG_LEVELS[ShopifyApp.configuration.log_level || DEFAULT_LOG_LEVEL] - end end end diff --git a/test/controllers/callback_controller_test.rb b/test/controllers/callback_controller_test.rb index 1683084f2..bdc2e87e7 100644 --- a/test/controllers/callback_controller_test.rb +++ b/test/controllers/callback_controller_test.rb @@ -58,13 +58,18 @@ class CallbackControllerTest < ActionController::TestCase test "#callback rescued errors other than ShopifyAPI::Error will emit a deprecation notice" do parent_deprecation_setting = ActiveSupport::Deprecation.silenced + parent_context_log_level = ShopifyAPI::Context.log_level ActiveSupport::Deprecation.silenced = false + ShopifyAPI::Context.log_level = :warn + ShopifyAPI::Auth::Oauth.expects(:validate_auth_callback).raises(StandardError) assert_deprecated(/An error of type StandardError was rescued/) do get :callback, params: { shop: "shop", code: "code", state: "state", timestamp: "timestamp", host: "host", hmac: "hmac" } end assert_equal flash[:error], "Could not log in to Shopify store" + + ShopifyAPI::Context.log_level = parent_context_log_level ActiveSupport::Deprecation.silenced = parent_deprecation_setting end diff --git a/test/controllers/concerns/authenticated_test.rb b/test/controllers/concerns/authenticated_test.rb index bd9358a44..e8f1c7dae 100644 --- a/test/controllers/concerns/authenticated_test.rb +++ b/test/controllers/concerns/authenticated_test.rb @@ -22,13 +22,17 @@ def index test "detects deprecation message" do parent_deprecation_setting = ActiveSupport::Deprecation.silenced - + parent_context_log_level = ShopifyAPI::Context.log_level ActiveSupport::Deprecation.silenced = false + ShopifyAPI::Context.log_level = :warn + assert_deprecated(/Authenticated has been replaced by to EnsureHasSession./) do Class.new(ApplicationController) do include ShopifyApp::Authenticated end end - ActiveSupport::Deprecation.silenced = parent_deprecation_setting + + ActiveSupport::Deprecation.silenced = parent_deprecation_setting + ShopifyAPI::Context.log_level = parent_context_log_level end end diff --git a/test/controllers/concerns/ensure_installed_test.rb b/test/controllers/concerns/ensure_installed_test.rb index 7ad9c2366..fc3c3b351 100644 --- a/test/controllers/concerns/ensure_installed_test.rb +++ b/test/controllers/concerns/ensure_installed_test.rb @@ -63,7 +63,10 @@ def index test "detects incompatible controller concerns" do parent_deprecation_setting = ActiveSupport::Deprecation.silenced + parent_context_log_level = ShopifyAPI::Context.log_level ActiveSupport::Deprecation.silenced = false + ShopifyAPI::Context.log_level = :warn + assert_deprecated(/incompatible concerns/) do Class.new(ApplicationController) do include ShopifyApp::LoginProtection @@ -87,6 +90,8 @@ def index include ShopifyApp::EnsureInstalled end end + ActiveSupport::Deprecation.silenced = parent_deprecation_setting + ShopifyAPI::Context.log_level = parent_context_log_level end end diff --git a/test/controllers/concerns/require_known_shop_test.rb b/test/controllers/concerns/require_known_shop_test.rb index 0c3052c6b..8a6b9cbe8 100644 --- a/test/controllers/concerns/require_known_shop_test.rb +++ b/test/controllers/concerns/require_known_shop_test.rb @@ -63,7 +63,9 @@ def index test "detects incompatible controller concerns" do parent_deprecation_setting = ActiveSupport::Deprecation.silenced + parent_context_log_level = ShopifyAPI::Context.log_level ActiveSupport::Deprecation.silenced = false + ShopifyAPI::Context.log_level = :warn assert_deprecated(/incompatible concerns/) do Class.new(ApplicationController) do include ShopifyApp::RequireKnownShop @@ -88,17 +90,22 @@ def index end end ActiveSupport::Deprecation.silenced = parent_deprecation_setting + ShopifyAPI::Context.log_level = parent_context_log_level end test "detects name change deprecation message" do parent_deprecation_setting = ActiveSupport::Deprecation.silenced - + parent_context_log_level = ShopifyAPI::Context.log_level ActiveSupport::Deprecation.silenced = false + ShopifyAPI::Context.log_level = :warn + assert_deprecated(/RequireKnownShop has been replaced by to EnsureInstalled./) do Class.new(ApplicationController) do include ShopifyApp::RequireKnownShop end end - ActiveSupport::Deprecation.silenced = parent_deprecation_setting + + ActiveSupport::Deprecation.silenced = parent_deprecation_setting + ShopifyAPI::Context.log_level = parent_context_log_level end end diff --git a/test/dummy/config/initializers/shopify_app.rb b/test/dummy/config/initializers/shopify_app.rb index 52460f747..bafbeabcc 100644 --- a/test/dummy/config/initializers/shopify_app.rb +++ b/test/dummy/config/initializers/shopify_app.rb @@ -34,6 +34,7 @@ def self.setup_context is_private: false, is_embedded: ShopifyApp.configuration.embedded_app, session_storage: ShopifyApp::SessionRepository, + log_level: :off, ) end end diff --git a/test/generators/install_generator_test.rb b/test/generators/install_generator_test.rb index 06ffa08d4..06f8c0a11 100644 --- a/test/generators/install_generator_test.rb +++ b/test/generators/install_generator_test.rb @@ -37,6 +37,7 @@ class InstallGeneratorTest < Rails::Generators::TestCase is_private: !ENV.fetch('SHOPIFY_APP_PRIVATE_SHOP', '').empty?, is_embedded: ShopifyApp.configuration.embedded_app, session_storage: ShopifyApp::SessionRepository, + log_level: :info, logger: Rails.logger, private_shop: ENV.fetch('SHOPIFY_APP_PRIVATE_SHOP', nil), user_agent_prefix: "ShopifyApp/\#{ShopifyApp::VERSION}" diff --git a/test/shopify_app/controller_concerns/login_protection_test.rb b/test/shopify_app/controller_concerns/login_protection_test.rb index 556edb434..a1508e283 100644 --- a/test/shopify_app/controller_concerns/login_protection_test.rb +++ b/test/shopify_app/controller_concerns/login_protection_test.rb @@ -468,14 +468,19 @@ class LoginProtectionControllerTest < ActionController::TestCase test "detects incompatible controller concerns" do parent_deprecation_setting = ActiveSupport::Deprecation.silenced + parent_context_log_level = ShopifyAPI::Context.log_level ActiveSupport::Deprecation.silenced = false + ShopifyAPI::Context.log_level = :warn + assert_deprecated(/incompatible concerns/) do Class.new(ApplicationController) do include ShopifyApp::LoginProtection include ShopifyApp::RequireKnownShop end end + ActiveSupport::Deprecation.silenced = parent_deprecation_setting + ShopifyAPI::Context.log_level = parent_context_log_level end private From b952fe35689b16fbf6c16f8c32cde1abda4a65ea Mon Sep 17 00:00:00 2001 From: Bill Klenotiz Date: Tue, 22 Nov 2022 16:18:02 -0500 Subject: [PATCH 18/35] update context to ShopifyApp --- lib/shopify_app/logger.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/shopify_app/logger.rb b/lib/shopify_app/logger.rb index 1015133fd..57d0165a7 100644 --- a/lib/shopify_app/logger.rb +++ b/lib/shopify_app/logger.rb @@ -5,9 +5,14 @@ class Logger < ShopifyAPI::Logger def self.deprecated(message, version) return unless enabled_for_log_level?(:warn) - raise StandardError unless ShopifyApp::VERSION < version + raise ShopifyAPI::Errors::FeatureDeprecatedError unless ShopifyApp::VERSION < version ActiveSupport::Deprecation.warn("[#{version}] #{context(:warn)} #{message}") end + + def self.context(log_level) + current_shop = ShopifyAPI::Context.active_session&.shop || "Shop Not Found" + "[ ShopifyApp | #{log_level.to_s.upcase} | #{current_shop} ]" + end end end From 42b44cd7b044170f3e000cc36f224fbdd11e41fa Mon Sep 17 00:00:00 2001 From: Bill Klenotiz Date: Mon, 28 Nov 2022 11:30:26 -0500 Subject: [PATCH 19/35] update tests --- test/controllers/callback_controller_test.rb | 4 ++-- test/controllers/concerns/authenticated_test.rb | 4 ++-- test/controllers/concerns/ensure_installed_test.rb | 3 +-- test/controllers/concerns/require_known_shop_test.rb | 8 ++++---- .../controller_concerns/login_protection_test.rb | 4 ++-- 5 files changed, 11 insertions(+), 12 deletions(-) diff --git a/test/controllers/callback_controller_test.rb b/test/controllers/callback_controller_test.rb index bdc2e87e7..1ab68d5c6 100644 --- a/test/controllers/callback_controller_test.rb +++ b/test/controllers/callback_controller_test.rb @@ -60,7 +60,7 @@ class CallbackControllerTest < ActionController::TestCase parent_deprecation_setting = ActiveSupport::Deprecation.silenced parent_context_log_level = ShopifyAPI::Context.log_level ActiveSupport::Deprecation.silenced = false - ShopifyAPI::Context.log_level = :warn + ShopifyAPI::Context.stubs(:log_level).returns(:warn) ShopifyAPI::Auth::Oauth.expects(:validate_auth_callback).raises(StandardError) assert_deprecated(/An error of type StandardError was rescued/) do @@ -69,7 +69,7 @@ class CallbackControllerTest < ActionController::TestCase end assert_equal flash[:error], "Could not log in to Shopify store" - ShopifyAPI::Context.log_level = parent_context_log_level + ActiveSupport::Deprecation.silenced = parent_deprecation_setting end diff --git a/test/controllers/concerns/authenticated_test.rb b/test/controllers/concerns/authenticated_test.rb index e8f1c7dae..45e35c899 100644 --- a/test/controllers/concerns/authenticated_test.rb +++ b/test/controllers/concerns/authenticated_test.rb @@ -24,7 +24,7 @@ def index parent_deprecation_setting = ActiveSupport::Deprecation.silenced parent_context_log_level = ShopifyAPI::Context.log_level ActiveSupport::Deprecation.silenced = false - ShopifyAPI::Context.log_level = :warn + ShopifyAPI::Context.stubs(:log_level).returns(:warn) assert_deprecated(/Authenticated has been replaced by to EnsureHasSession./) do Class.new(ApplicationController) do @@ -33,6 +33,6 @@ def index end ActiveSupport::Deprecation.silenced = parent_deprecation_setting - ShopifyAPI::Context.log_level = parent_context_log_level + end end diff --git a/test/controllers/concerns/ensure_installed_test.rb b/test/controllers/concerns/ensure_installed_test.rb index fc3c3b351..d393806be 100644 --- a/test/controllers/concerns/ensure_installed_test.rb +++ b/test/controllers/concerns/ensure_installed_test.rb @@ -65,7 +65,7 @@ def index parent_deprecation_setting = ActiveSupport::Deprecation.silenced parent_context_log_level = ShopifyAPI::Context.log_level ActiveSupport::Deprecation.silenced = false - ShopifyAPI::Context.log_level = :warn + ShopifyAPI::Context.stubs(:log_level).returns(:warn) assert_deprecated(/incompatible concerns/) do Class.new(ApplicationController) do @@ -92,6 +92,5 @@ def index end ActiveSupport::Deprecation.silenced = parent_deprecation_setting - ShopifyAPI::Context.log_level = parent_context_log_level end end diff --git a/test/controllers/concerns/require_known_shop_test.rb b/test/controllers/concerns/require_known_shop_test.rb index 8a6b9cbe8..720e3bfe5 100644 --- a/test/controllers/concerns/require_known_shop_test.rb +++ b/test/controllers/concerns/require_known_shop_test.rb @@ -65,7 +65,7 @@ def index parent_deprecation_setting = ActiveSupport::Deprecation.silenced parent_context_log_level = ShopifyAPI::Context.log_level ActiveSupport::Deprecation.silenced = false - ShopifyAPI::Context.log_level = :warn + ShopifyAPI::Context.stubs(:log_level).returns(:warn) assert_deprecated(/incompatible concerns/) do Class.new(ApplicationController) do include ShopifyApp::RequireKnownShop @@ -90,14 +90,14 @@ def index end end ActiveSupport::Deprecation.silenced = parent_deprecation_setting - ShopifyAPI::Context.log_level = parent_context_log_level + end test "detects name change deprecation message" do parent_deprecation_setting = ActiveSupport::Deprecation.silenced parent_context_log_level = ShopifyAPI::Context.log_level ActiveSupport::Deprecation.silenced = false - ShopifyAPI::Context.log_level = :warn + ShopifyAPI::Context.stubs(:log_level).returns(:warn) assert_deprecated(/RequireKnownShop has been replaced by to EnsureInstalled./) do Class.new(ApplicationController) do @@ -106,6 +106,6 @@ def index end ActiveSupport::Deprecation.silenced = parent_deprecation_setting - ShopifyAPI::Context.log_level = parent_context_log_level + end end diff --git a/test/shopify_app/controller_concerns/login_protection_test.rb b/test/shopify_app/controller_concerns/login_protection_test.rb index a1508e283..52ef545c7 100644 --- a/test/shopify_app/controller_concerns/login_protection_test.rb +++ b/test/shopify_app/controller_concerns/login_protection_test.rb @@ -470,7 +470,7 @@ class LoginProtectionControllerTest < ActionController::TestCase parent_deprecation_setting = ActiveSupport::Deprecation.silenced parent_context_log_level = ShopifyAPI::Context.log_level ActiveSupport::Deprecation.silenced = false - ShopifyAPI::Context.log_level = :warn + ShopifyAPI::Context.stubs(:log_level).returns(:warn) assert_deprecated(/incompatible concerns/) do Class.new(ApplicationController) do @@ -480,7 +480,7 @@ class LoginProtectionControllerTest < ActionController::TestCase end ActiveSupport::Deprecation.silenced = parent_deprecation_setting - ShopifyAPI::Context.log_level = parent_context_log_level + end private From df40c1e0bef2ef5755959e71b6b0986ace19bbc7 Mon Sep 17 00:00:00 2001 From: Bill Klenotiz Date: Thu, 1 Dec 2022 12:12:37 -0500 Subject: [PATCH 20/35] stub out log level so tests pass --- lib/shopify_app/controller_concerns/login_protection.rb | 4 ++-- .../add_marketing_activity_extension_generator_test.rb | 2 ++ test/shopify_app/controller_concerns/itp_test.rb | 1 + test/shopify_app/managers/scripttags_manager_test.rb | 1 + 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/shopify_app/controller_concerns/login_protection.rb b/lib/shopify_app/controller_concerns/login_protection.rb index 284b5548b..d2a86da51 100644 --- a/lib/shopify_app/controller_concerns/login_protection.rb +++ b/lib/shopify_app/controller_concerns/login_protection.rb @@ -56,10 +56,10 @@ def current_shopify_session is_online: online_token_configured?, ) rescue ShopifyAPI::Errors::CookieNotFoundError - ShopifyApp::Logger.info("No cookies have been found - cookie name: #{cookie_name}") + ShopifyApp::Logger.warn("No cookies have been found - cookie name: #{cookie_name}") nil rescue ShopifyAPI::Errors::InvalidJwtTokenError - ShopifyApp::Logger.info("Invalid JWT token for current Shopify session") + ShopifyApp::Logger.warn("Invalid JWT token for current Shopify session") nil end end diff --git a/test/generators/add_marketing_activity_extension_generator_test.rb b/test/generators/add_marketing_activity_extension_generator_test.rb index 4553f3759..0bc5cad0e 100644 --- a/test/generators/add_marketing_activity_extension_generator_test.rb +++ b/test/generators/add_marketing_activity_extension_generator_test.rb @@ -41,6 +41,8 @@ class AddMarketingActivityExtensionGeneratorTest < Rails::Generators::TestCase test "detect deprecation notice when generating controller" do parent_deprecation_setting = ActiveSupport::Deprecation.silenced ActiveSupport::Deprecation.silenced = false + ShopifyAPI::Context.stubs(:log_level).returns(:warn) + assert_deprecated(/MarketingActivitiesController will be removed/) do provide_existing_routes_file run_generator diff --git a/test/shopify_app/controller_concerns/itp_test.rb b/test/shopify_app/controller_concerns/itp_test.rb index 8426f1c48..e38640062 100644 --- a/test/shopify_app/controller_concerns/itp_test.rb +++ b/test/shopify_app/controller_concerns/itp_test.rb @@ -7,6 +7,7 @@ class ItpTest < ActionController::TestCase test "detects deprecation notice" do parent_deprecation_setting = ActiveSupport::Deprecation.silenced ActiveSupport::Deprecation.silenced = false + ShopifyAPI::Context.stubs(:log_level).returns(:warn) assert_deprecated(/Itp will be removed/) do Class.new(ApplicationController) do include ShopifyApp::Itp diff --git a/test/shopify_app/managers/scripttags_manager_test.rb b/test/shopify_app/managers/scripttags_manager_test.rb index 54489f872..8bc314877 100644 --- a/test/shopify_app/managers/scripttags_manager_test.rb +++ b/test/shopify_app/managers/scripttags_manager_test.rb @@ -118,6 +118,7 @@ class ShopifyApp::ScripttagsManagerTest < ActiveSupport::TestCase test "deprecation message is found on initialization" do parent_deprecation_setting = ActiveSupport::Deprecation.silenced ActiveSupport::Deprecation.silenced = false + ShopifyAPI::Context.stubs(:log_level).returns(:warn) assert_deprecated(/ScripttagsManager will become deprecated/) do ShopifyApp::ScripttagsManager.new("scripttags", "shop_domain") end From 1418d9e8a16aadb4ebe4def789a4ebd04f0b4be1 Mon Sep 17 00:00:00 2001 From: Bill Klenotiz Date: Thu, 1 Dec 2022 12:36:36 -0500 Subject: [PATCH 21/35] random stuff I found --- app/controllers/concerns/shopify_app/authenticated.rb | 2 +- .../templates/marketing_activities_controller.rb | 4 ---- .../controller_concerns/login_protection.rb | 2 +- lib/shopify_app/logger.rb | 10 +++++++++- test/controllers/concerns/authenticated_test.rb | 3 +-- 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/app/controllers/concerns/shopify_app/authenticated.rb b/app/controllers/concerns/shopify_app/authenticated.rb index b12ab72a6..a77620386 100644 --- a/app/controllers/concerns/shopify_app/authenticated.rb +++ b/app/controllers/concerns/shopify_app/authenticated.rb @@ -5,7 +5,7 @@ module Authenticated extend ActiveSupport::Concern included do - ShopifyApp::Logger.deprecated("Authenticated has been replaced by to EnsureHasSession."\ + ShopifyApp::Logger.deprecated("Authenticated has been replaced by EnsureHasSession."\ " Please use EnsureHasSession controller concern for the same behavior", "22.0.0") end diff --git a/lib/generators/shopify_app/add_marketing_activity_extension/templates/marketing_activities_controller.rb b/lib/generators/shopify_app/add_marketing_activity_extension/templates/marketing_activities_controller.rb index 7effe4e2b..1cf8b09fb 100644 --- a/lib/generators/shopify_app/add_marketing_activity_extension/templates/marketing_activities_controller.rb +++ b/lib/generators/shopify_app/add_marketing_activity_extension/templates/marketing_activities_controller.rb @@ -2,10 +2,6 @@ class MarketingActivitiesController < ShopifyApp::ExtensionVerificationController - def initialize - ShopifyApp::Logger.deprecated("The MarketingActivitiesController will be removed in an upcoming update","22.0.0") - end - def preload_form_data preload_data = { "form_data": {}, diff --git a/lib/shopify_app/controller_concerns/login_protection.rb b/lib/shopify_app/controller_concerns/login_protection.rb index d2a86da51..1b1b8aa68 100644 --- a/lib/shopify_app/controller_concerns/login_protection.rb +++ b/lib/shopify_app/controller_concerns/login_protection.rb @@ -11,7 +11,7 @@ module LoginProtection included do if ancestors.include?(ShopifyApp::RequireKnownShop || ShopifyApp::EnsureInstalled) message = <<~EOS - We detected the use of incompatible concerns (RequireKnownShop and LoginProtection) in #{name}, + We detected the use of incompatible concerns (RequireKnownShop/EnsureInstalled and LoginProtection) in #{name}, which may lead to unpredictable behavior. In a future release of this library this will raise an error. EOS ShopifyApp::Logger.deprecated(message, "22.0.0") diff --git a/lib/shopify_app/logger.rb b/lib/shopify_app/logger.rb index 57d0165a7..b6920a983 100644 --- a/lib/shopify_app/logger.rb +++ b/lib/shopify_app/logger.rb @@ -5,7 +5,7 @@ class Logger < ShopifyAPI::Logger def self.deprecated(message, version) return unless enabled_for_log_level?(:warn) - raise ShopifyAPI::Errors::FeatureDeprecatedError unless ShopifyApp::VERSION < version + raise ShopifyAPI::Errors::FeatureDeprecatedError unless valid_version(version) ActiveSupport::Deprecation.warn("[#{version}] #{context(:warn)} #{message}") end @@ -14,5 +14,13 @@ def self.context(log_level) current_shop = ShopifyAPI::Context.active_session&.shop || "Shop Not Found" "[ ShopifyApp | #{log_level.to_s.upcase} | #{current_shop} ]" end + + private + + def valid_version(version) + current_version = Gem::Version.create(ShopifyApp::VERSION) + deprecate_version = Gem::Version.create(version) + current_version < deprecate_version + end end end diff --git a/test/controllers/concerns/authenticated_test.rb b/test/controllers/concerns/authenticated_test.rb index 45e35c899..aa51b89fa 100644 --- a/test/controllers/concerns/authenticated_test.rb +++ b/test/controllers/concerns/authenticated_test.rb @@ -26,13 +26,12 @@ def index ActiveSupport::Deprecation.silenced = false ShopifyAPI::Context.stubs(:log_level).returns(:warn) - assert_deprecated(/Authenticated has been replaced by to EnsureHasSession./) do + assert_deprecated(/Authenticated has been replaced by EnsureHasSession./) do Class.new(ApplicationController) do include ShopifyApp::Authenticated end end ActiveSupport::Deprecation.silenced = parent_deprecation_setting - end end From 5099534f37db564000268704b5a8ad66ad89bee7 Mon Sep 17 00:00:00 2001 From: Bill Klenotiz Date: Thu, 1 Dec 2022 12:40:50 -0500 Subject: [PATCH 22/35] rubocop --- app/controllers/concerns/shopify_app/ensure_installed.rb | 6 +++--- app/controllers/concerns/shopify_app/require_known_shop.rb | 2 +- .../templates/marketing_activities_controller.rb | 1 - lib/shopify_app/controller_concerns/itp.rb | 2 +- lib/shopify_app/controller_concerns/login_protection.rb | 2 +- test/controllers/callback_controller_test.rb | 2 -- test/controllers/concerns/authenticated_test.rb | 1 - test/controllers/concerns/ensure_installed_test.rb | 1 - test/controllers/concerns/require_known_shop_test.rb | 4 ---- .../add_marketing_activity_extension_generator_test.rb | 2 +- test/shopify_app/controller_concerns/itp_test.rb | 4 +++- .../controller_concerns/login_protection_test.rb | 2 -- 12 files changed, 10 insertions(+), 19 deletions(-) diff --git a/app/controllers/concerns/shopify_app/ensure_installed.rb b/app/controllers/concerns/shopify_app/ensure_installed.rb index 4ef1ca6f3..b215912ce 100644 --- a/app/controllers/concerns/shopify_app/ensure_installed.rb +++ b/app/controllers/concerns/shopify_app/ensure_installed.rb @@ -8,11 +8,11 @@ module EnsureInstalled included do if ancestors.include?(ShopifyApp::LoginProtection) message = <<~EOS - We detected the use of incompatible concerns (EnsureInstalled and LoginProtection) in #{name}, - which may lead to unpredictable behavior. In a future release of this library this will raise an error. + We detected the use of incompatible concerns (EnsureInstalled and LoginProtection) in #{name}, + which may lead to unpredictable behavior. In a future release of this library this will raise an error. EOS - ShopifyApp::Logger.deprecated(message ,"22.0.0") + ShopifyApp::Logger.deprecated(message, "22.0.0") end before_action :check_shop_domain diff --git a/app/controllers/concerns/shopify_app/require_known_shop.rb b/app/controllers/concerns/shopify_app/require_known_shop.rb index 788f2cda7..597f6bfef 100644 --- a/app/controllers/concerns/shopify_app/require_known_shop.rb +++ b/app/controllers/concerns/shopify_app/require_known_shop.rb @@ -4,7 +4,7 @@ module ShopifyApp module RequireKnownShop extend ActiveSupport::Concern include ShopifyApp::EnsureInstalled - + def self.extended(mod) ShopifyApp::Logger.deprecated("RequireKnownShop has been replaced by to EnsureInstalled."\ " Please use EnsureInstalled controller concern for the same behavior", "22.0.0") diff --git a/lib/generators/shopify_app/add_marketing_activity_extension/templates/marketing_activities_controller.rb b/lib/generators/shopify_app/add_marketing_activity_extension/templates/marketing_activities_controller.rb index 1cf8b09fb..955b5512c 100644 --- a/lib/generators/shopify_app/add_marketing_activity_extension/templates/marketing_activities_controller.rb +++ b/lib/generators/shopify_app/add_marketing_activity_extension/templates/marketing_activities_controller.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true class MarketingActivitiesController < ShopifyApp::ExtensionVerificationController - def preload_form_data preload_data = { "form_data": {}, diff --git a/lib/shopify_app/controller_concerns/itp.rb b/lib/shopify_app/controller_concerns/itp.rb index fe5310379..61af64bd5 100644 --- a/lib/shopify_app/controller_concerns/itp.rb +++ b/lib/shopify_app/controller_concerns/itp.rb @@ -5,7 +5,7 @@ module ShopifyApp module Itp extend ActiveSupport::Concern included do - ShopifyApp::Logger.deprecated("Itp will be removed in an upcoming version","22.0.0") + ShopifyApp::Logger.deprecated("Itp will be removed in an upcoming version", "22.0.0") end private diff --git a/lib/shopify_app/controller_concerns/login_protection.rb b/lib/shopify_app/controller_concerns/login_protection.rb index 1b1b8aa68..7911ff943 100644 --- a/lib/shopify_app/controller_concerns/login_protection.rb +++ b/lib/shopify_app/controller_concerns/login_protection.rb @@ -91,7 +91,7 @@ def add_top_level_redirection_headers(url: nil, ignore_response_code: false) ShopifyApp::Logger.debug("Setting current shop session") params[:shop] = if current_shopify_session current_shopify_session.shop - + elsif (matches = request.headers["HTTP_AUTHORIZATION"]&.match(/^Bearer (.+)$/)) jwt_payload = ShopifyAPI::Auth::JwtPayload.new(T.must(matches[1])) jwt_payload.shop diff --git a/test/controllers/callback_controller_test.rb b/test/controllers/callback_controller_test.rb index 1ab68d5c6..9fc477ff4 100644 --- a/test/controllers/callback_controller_test.rb +++ b/test/controllers/callback_controller_test.rb @@ -58,7 +58,6 @@ class CallbackControllerTest < ActionController::TestCase test "#callback rescued errors other than ShopifyAPI::Error will emit a deprecation notice" do parent_deprecation_setting = ActiveSupport::Deprecation.silenced - parent_context_log_level = ShopifyAPI::Context.log_level ActiveSupport::Deprecation.silenced = false ShopifyAPI::Context.stubs(:log_level).returns(:warn) @@ -69,7 +68,6 @@ class CallbackControllerTest < ActionController::TestCase end assert_equal flash[:error], "Could not log in to Shopify store" - ActiveSupport::Deprecation.silenced = parent_deprecation_setting end diff --git a/test/controllers/concerns/authenticated_test.rb b/test/controllers/concerns/authenticated_test.rb index aa51b89fa..3ddee87ed 100644 --- a/test/controllers/concerns/authenticated_test.rb +++ b/test/controllers/concerns/authenticated_test.rb @@ -22,7 +22,6 @@ def index test "detects deprecation message" do parent_deprecation_setting = ActiveSupport::Deprecation.silenced - parent_context_log_level = ShopifyAPI::Context.log_level ActiveSupport::Deprecation.silenced = false ShopifyAPI::Context.stubs(:log_level).returns(:warn) diff --git a/test/controllers/concerns/ensure_installed_test.rb b/test/controllers/concerns/ensure_installed_test.rb index d393806be..d4032194f 100644 --- a/test/controllers/concerns/ensure_installed_test.rb +++ b/test/controllers/concerns/ensure_installed_test.rb @@ -63,7 +63,6 @@ def index test "detects incompatible controller concerns" do parent_deprecation_setting = ActiveSupport::Deprecation.silenced - parent_context_log_level = ShopifyAPI::Context.log_level ActiveSupport::Deprecation.silenced = false ShopifyAPI::Context.stubs(:log_level).returns(:warn) diff --git a/test/controllers/concerns/require_known_shop_test.rb b/test/controllers/concerns/require_known_shop_test.rb index 720e3bfe5..4d4db9227 100644 --- a/test/controllers/concerns/require_known_shop_test.rb +++ b/test/controllers/concerns/require_known_shop_test.rb @@ -63,7 +63,6 @@ def index test "detects incompatible controller concerns" do parent_deprecation_setting = ActiveSupport::Deprecation.silenced - parent_context_log_level = ShopifyAPI::Context.log_level ActiveSupport::Deprecation.silenced = false ShopifyAPI::Context.stubs(:log_level).returns(:warn) assert_deprecated(/incompatible concerns/) do @@ -90,12 +89,10 @@ def index end end ActiveSupport::Deprecation.silenced = parent_deprecation_setting - end test "detects name change deprecation message" do parent_deprecation_setting = ActiveSupport::Deprecation.silenced - parent_context_log_level = ShopifyAPI::Context.log_level ActiveSupport::Deprecation.silenced = false ShopifyAPI::Context.stubs(:log_level).returns(:warn) @@ -106,6 +103,5 @@ def index end ActiveSupport::Deprecation.silenced = parent_deprecation_setting - end end diff --git a/test/generators/add_marketing_activity_extension_generator_test.rb b/test/generators/add_marketing_activity_extension_generator_test.rb index 0bc5cad0e..c02f9c415 100644 --- a/test/generators/add_marketing_activity_extension_generator_test.rb +++ b/test/generators/add_marketing_activity_extension_generator_test.rb @@ -42,7 +42,7 @@ class AddMarketingActivityExtensionGeneratorTest < Rails::Generators::TestCase parent_deprecation_setting = ActiveSupport::Deprecation.silenced ActiveSupport::Deprecation.silenced = false ShopifyAPI::Context.stubs(:log_level).returns(:warn) - + assert_deprecated(/MarketingActivitiesController will be removed/) do provide_existing_routes_file run_generator diff --git a/test/shopify_app/controller_concerns/itp_test.rb b/test/shopify_app/controller_concerns/itp_test.rb index e38640062..3b61bd3d9 100644 --- a/test/shopify_app/controller_concerns/itp_test.rb +++ b/test/shopify_app/controller_concerns/itp_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" require "action_controller" require "action_controller/base" @@ -15,4 +17,4 @@ class ItpTest < ActionController::TestCase end ActiveSupport::Deprecation.silenced = parent_deprecation_setting end -end \ No newline at end of file +end diff --git a/test/shopify_app/controller_concerns/login_protection_test.rb b/test/shopify_app/controller_concerns/login_protection_test.rb index 52ef545c7..d9fe00279 100644 --- a/test/shopify_app/controller_concerns/login_protection_test.rb +++ b/test/shopify_app/controller_concerns/login_protection_test.rb @@ -468,7 +468,6 @@ class LoginProtectionControllerTest < ActionController::TestCase test "detects incompatible controller concerns" do parent_deprecation_setting = ActiveSupport::Deprecation.silenced - parent_context_log_level = ShopifyAPI::Context.log_level ActiveSupport::Deprecation.silenced = false ShopifyAPI::Context.stubs(:log_level).returns(:warn) @@ -480,7 +479,6 @@ class LoginProtectionControllerTest < ActionController::TestCase end ActiveSupport::Deprecation.silenced = parent_deprecation_setting - end private From 23df405bd8abcf634d7917e6f933e1c8ccd2cf1a Mon Sep 17 00:00:00 2001 From: Bill Klenotiz Date: Fri, 2 Dec 2022 09:43:55 -0500 Subject: [PATCH 23/35] small changes --- app/controllers/concerns/shopify_app/authenticated.rb | 2 +- .../concerns/shopify_app/require_known_shop.rb | 11 +++-------- test/controllers/concerns/require_known_shop_test.rb | 2 +- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/app/controllers/concerns/shopify_app/authenticated.rb b/app/controllers/concerns/shopify_app/authenticated.rb index a77620386..e309d33f4 100644 --- a/app/controllers/concerns/shopify_app/authenticated.rb +++ b/app/controllers/concerns/shopify_app/authenticated.rb @@ -6,7 +6,7 @@ module Authenticated included do ShopifyApp::Logger.deprecated("Authenticated has been replaced by EnsureHasSession."\ - " Please use EnsureHasSession controller concern for the same behavior", "22.0.0") + " Please use the EnsureHasSession controller concern for the same behavior", "22.0.0") end include ShopifyApp::EnsureHasSession diff --git a/app/controllers/concerns/shopify_app/require_known_shop.rb b/app/controllers/concerns/shopify_app/require_known_shop.rb index 597f6bfef..33f5e956f 100644 --- a/app/controllers/concerns/shopify_app/require_known_shop.rb +++ b/app/controllers/concerns/shopify_app/require_known_shop.rb @@ -5,14 +5,9 @@ module RequireKnownShop extend ActiveSupport::Concern include ShopifyApp::EnsureInstalled - def self.extended(mod) - ShopifyApp::Logger.deprecated("RequireKnownShop has been replaced by to EnsureInstalled."\ - " Please use EnsureInstalled controller concern for the same behavior", "22.0.0") - end - - def self.included(mod) - ShopifyApp::Logger.deprecated("RequireKnownShop has been replaced by to EnsureInstalled."\ - " Please use EnsureInstalled controller concern for the same behavior", "22.0.0") + included do + ShopifyApp::Logger.deprecated("RequireKnownShop has been replaced by EnsureInstalled."\ + " Please use the EnsureInstalled controller concern for the same behavior", "22.0.0") end end end diff --git a/test/controllers/concerns/require_known_shop_test.rb b/test/controllers/concerns/require_known_shop_test.rb index 4d4db9227..488993d2d 100644 --- a/test/controllers/concerns/require_known_shop_test.rb +++ b/test/controllers/concerns/require_known_shop_test.rb @@ -96,7 +96,7 @@ def index ActiveSupport::Deprecation.silenced = false ShopifyAPI::Context.stubs(:log_level).returns(:warn) - assert_deprecated(/RequireKnownShop has been replaced by to EnsureInstalled./) do + assert_deprecated(/RequireKnownShop has been replaced by EnsureInstalled./) do Class.new(ApplicationController) do include ShopifyApp::RequireKnownShop end From b6eb7499737401606fb66f239a293b9667b035ce Mon Sep 17 00:00:00 2001 From: Bill Klenotiz Date: Fri, 2 Dec 2022 14:18:12 -0500 Subject: [PATCH 24/35] add shopify domain log --- app/controllers/concerns/shopify_app/ensure_installed.rb | 2 ++ lib/shopify_app/controller_concerns/login_protection.rb | 1 + 2 files changed, 3 insertions(+) diff --git a/app/controllers/concerns/shopify_app/ensure_installed.rb b/app/controllers/concerns/shopify_app/ensure_installed.rb index b215912ce..3b47f4213 100644 --- a/app/controllers/concerns/shopify_app/ensure_installed.rb +++ b/app/controllers/concerns/shopify_app/ensure_installed.rb @@ -23,6 +23,8 @@ def current_shopify_domain return if params[:shop].blank? @shopify_domain ||= ShopifyApp::Utils.sanitize_shop_domain(params[:shop]) + ShopifyApp::Logger.info("Current Shopify Domain - #{@shopify_domain}") + @shopify_domain end private diff --git a/lib/shopify_app/controller_concerns/login_protection.rb b/lib/shopify_app/controller_concerns/login_protection.rb index 7911ff943..e10216118 100644 --- a/lib/shopify_app/controller_concerns/login_protection.rb +++ b/lib/shopify_app/controller_concerns/login_protection.rb @@ -214,6 +214,7 @@ def fullpage_redirect_to(url) def current_shopify_domain shopify_domain = sanitized_shop_name || current_shopify_session&.shop + ShopifyApp::Logger.info("Current Shopify Domain - #{shopify_domain}") return shopify_domain if shopify_domain.present? raise ::ShopifyApp::ShopifyDomainNotFound From 857f4a690d3c7c6e7aa605e14805c7689a01594b Mon Sep 17 00:00:00 2001 From: Bill Klenotiz <54754550+klenotiw@users.noreply.github.com> Date: Fri, 2 Dec 2022 14:39:06 -0500 Subject: [PATCH 25/35] Update lib/shopify_app/controller_concerns/login_protection.rb Co-authored-by: Nelson --- lib/shopify_app/controller_concerns/login_protection.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/shopify_app/controller_concerns/login_protection.rb b/lib/shopify_app/controller_concerns/login_protection.rb index 56ebfd4dd..8b14f408b 100644 --- a/lib/shopify_app/controller_concerns/login_protection.rb +++ b/lib/shopify_app/controller_concerns/login_protection.rb @@ -213,7 +213,7 @@ def fullpage_redirect_to(url) def current_shopify_domain shopify_domain = sanitized_shop_name || current_shopify_session&.shop - ShopifyApp::Logger.info("Current Shopify Domain - #{shopify_domain}") + ShopifyApp::Logger.info("Installed store - #{shopify_domain} deduced from user session") shopify_domain end From 74d858294f89d376bb2cb606bc5ab0cddfeb81eb Mon Sep 17 00:00:00 2001 From: Bill Klenotiz <54754550+klenotiw@users.noreply.github.com> Date: Fri, 2 Dec 2022 14:39:14 -0500 Subject: [PATCH 26/35] Update app/controllers/concerns/shopify_app/ensure_installed.rb Co-authored-by: Nelson --- app/controllers/concerns/shopify_app/ensure_installed.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/concerns/shopify_app/ensure_installed.rb b/app/controllers/concerns/shopify_app/ensure_installed.rb index 3b47f4213..39e10166a 100644 --- a/app/controllers/concerns/shopify_app/ensure_installed.rb +++ b/app/controllers/concerns/shopify_app/ensure_installed.rb @@ -23,7 +23,7 @@ def current_shopify_domain return if params[:shop].blank? @shopify_domain ||= ShopifyApp::Utils.sanitize_shop_domain(params[:shop]) - ShopifyApp::Logger.info("Current Shopify Domain - #{@shopify_domain}") + ShopifyApp::Logger.info("Installed store: #{@shopify_domain} - deduced from Shopify Admin params") @shopify_domain end From 877b628d7f643610da4feb786acd4cde1e5609b1 Mon Sep 17 00:00:00 2001 From: Bill Klenotiz <54754550+klenotiw@users.noreply.github.com> Date: Fri, 2 Dec 2022 14:39:37 -0500 Subject: [PATCH 27/35] Update app/controllers/concerns/shopify_app/ensure_installed.rb Co-authored-by: Nelson --- app/controllers/concerns/shopify_app/ensure_installed.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/controllers/concerns/shopify_app/ensure_installed.rb b/app/controllers/concerns/shopify_app/ensure_installed.rb index 39e10166a..39b0db4e6 100644 --- a/app/controllers/concerns/shopify_app/ensure_installed.rb +++ b/app/controllers/concerns/shopify_app/ensure_installed.rb @@ -20,7 +20,10 @@ module EnsureInstalled end def current_shopify_domain - return if params[:shop].blank? + if params[:shop].blank? + ShopifyApp::Logger.info("Could not identify installed store from current_shopify_domain") + return + end @shopify_domain ||= ShopifyApp::Utils.sanitize_shop_domain(params[:shop]) ShopifyApp::Logger.info("Installed store: #{@shopify_domain} - deduced from Shopify Admin params") From d101194e7a4327c31844e19ac2aab87da70bf5f4 Mon Sep 17 00:00:00 2001 From: Bill Klenotiz Date: Sun, 4 Dec 2022 17:22:41 -0500 Subject: [PATCH 28/35] tests fixed --- shopify_app.gemspec | 2 +- .../controller_concerns/login_protection_test.rb | 6 ++++-- test/shopify_app/managers/scripttags_manager_test.rb | 3 ++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/shopify_app.gemspec b/shopify_app.gemspec index 77acc1f1a..5f8f4535d 100644 --- a/shopify_app.gemspec +++ b/shopify_app.gemspec @@ -19,7 +19,7 @@ Gem::Specification.new do |s| s.add_runtime_dependency("jwt", ">= 2.2.3") s.add_runtime_dependency("rails", "> 5.2.1") s.add_runtime_dependency("redirect_safely", "~> 1.0") - s.add_runtime_dependency("shopify_api", "~> 12.2") + s.add_runtime_dependency("shopify_api") s.add_runtime_dependency("sprockets-rails", ">= 2.0.0") s.add_development_dependency("byebug") diff --git a/test/shopify_app/controller_concerns/login_protection_test.rb b/test/shopify_app/controller_concerns/login_protection_test.rb index 681ff5c17..689db6285 100644 --- a/test/shopify_app/controller_concerns/login_protection_test.rb +++ b/test/shopify_app/controller_concerns/login_protection_test.rb @@ -32,11 +32,13 @@ def redirect end def raise_unauthorized - raise ShopifyAPI::Errors::HttpResponseError.new(code: 401), "unauthorized" + unauthorized_response = ShopifyAPI::Clients::HttpResponse.new(code: 401, headers: {}, body: "") + raise ShopifyAPI::Errors::HttpResponseError.new(response: unauthorized_response), "unauthorized" end def raise_not_found - raise ShopifyAPI::Errors::HttpResponseError.new(code: 404), "not found" + not_found_response = ShopifyAPI::Clients::HttpResponse.new(code: 404, headers: {}, body: "") + raise ShopifyAPI::Errors::HttpResponseError.new(response: not_found_response), "not found" end end diff --git a/test/shopify_app/managers/scripttags_manager_test.rb b/test/shopify_app/managers/scripttags_manager_test.rb index 4a7b2915c..754e8ef83 100644 --- a/test/shopify_app/managers/scripttags_manager_test.rb +++ b/test/shopify_app/managers/scripttags_manager_test.rb @@ -42,7 +42,8 @@ class ShopifyApp::ScripttagsManagerTest < ActiveSupport::TestCase ShopifyAPI::ScriptTag.stubs(all: []) scripttag = ShopifyAPI::ScriptTag.new ShopifyAPI::ScriptTag.stubs(:new).returns(scripttag) - scripttag.stubs(:save!).raises(ShopifyAPI::Errors::HttpResponseError.new(code: 401), "Error message") + a_response = ShopifyAPI::Clients::HttpResponse.new(code: 401, headers: {}, body: "") + scripttag.stubs(:save!).raises(ShopifyAPI::Errors::HttpResponseError.new(response: a_response), "Error message") e = assert_raise ::ShopifyApp::CreationFailed do @manager.create_scripttags From 92fa8e424cebf4828087d39d198690808feda88e Mon Sep 17 00:00:00 2001 From: Bill Klenotiz Date: Mon, 5 Dec 2022 09:04:39 -0500 Subject: [PATCH 29/35] fix gemspec --- shopify_app.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shopify_app.gemspec b/shopify_app.gemspec index 5f8f4535d..77acc1f1a 100644 --- a/shopify_app.gemspec +++ b/shopify_app.gemspec @@ -19,7 +19,7 @@ Gem::Specification.new do |s| s.add_runtime_dependency("jwt", ">= 2.2.3") s.add_runtime_dependency("rails", "> 5.2.1") s.add_runtime_dependency("redirect_safely", "~> 1.0") - s.add_runtime_dependency("shopify_api") + s.add_runtime_dependency("shopify_api", "~> 12.2") s.add_runtime_dependency("sprockets-rails", ">= 2.0.0") s.add_development_dependency("byebug") From eeb1947cb002a14144e13f4a002a392ba19e7468 Mon Sep 17 00:00:00 2001 From: Bill Klenotiz Date: Mon, 5 Dec 2022 09:48:56 -0500 Subject: [PATCH 30/35] change controller concerns to new names --- app/controllers/shopify_app/authenticated_controller.rb | 2 +- .../templates/authenticated_controller.rb | 2 +- .../templates/unauthenticated_home_controller.rb | 2 +- test/controllers/concerns/require_known_shop_test.rb | 4 ++-- test/dummy/app/controllers/home_controller.rb | 2 +- test/generators/home_controller_generator_test.rb | 2 +- test/shopify_app/controller_concerns/login_protection_test.rb | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/controllers/shopify_app/authenticated_controller.rb b/app/controllers/shopify_app/authenticated_controller.rb index 6a8f5e920..a722d7eaf 100644 --- a/app/controllers/shopify_app/authenticated_controller.rb +++ b/app/controllers/shopify_app/authenticated_controller.rb @@ -2,7 +2,7 @@ module ShopifyApp class AuthenticatedController < ActionController::Base - include ShopifyApp::Authenticated + include ShopifyApp::EnsureHasSession protect_from_forgery with: :exception end diff --git a/lib/generators/shopify_app/authenticated_controller/templates/authenticated_controller.rb b/lib/generators/shopify_app/authenticated_controller/templates/authenticated_controller.rb index 3c00839e4..9d8c5bb29 100644 --- a/lib/generators/shopify_app/authenticated_controller/templates/authenticated_controller.rb +++ b/lib/generators/shopify_app/authenticated_controller/templates/authenticated_controller.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true class AuthenticatedController < ApplicationController - include ShopifyApp::Authenticated + include ShopifyApp::EnsureHasSession end diff --git a/lib/generators/shopify_app/home_controller/templates/unauthenticated_home_controller.rb b/lib/generators/shopify_app/home_controller/templates/unauthenticated_home_controller.rb index 52e884f1b..69d6778d2 100644 --- a/lib/generators/shopify_app/home_controller/templates/unauthenticated_home_controller.rb +++ b/lib/generators/shopify_app/home_controller/templates/unauthenticated_home_controller.rb @@ -2,7 +2,7 @@ class HomeController < ApplicationController include ShopifyApp::EmbeddedApp - include ShopifyApp::RequireKnownShop + include ShopifyApp::EnsureInstalled include ShopifyApp::ShopAccessScopesVerification def index diff --git a/test/controllers/concerns/require_known_shop_test.rb b/test/controllers/concerns/require_known_shop_test.rb index 488993d2d..e783efe05 100644 --- a/test/controllers/concerns/require_known_shop_test.rb +++ b/test/controllers/concerns/require_known_shop_test.rb @@ -75,13 +75,13 @@ def index assert_deprecated(/incompatible concerns/) do Class.new(ApplicationController) do include ShopifyApp::RequireKnownShop - include ShopifyApp::Authenticated # since this indirectly includes LoginProtection + include ShopifyApp::EnsureHasSession # since this indirectly includes LoginProtection end end assert_deprecated(/incompatible concerns/) do authenticated_controller = Class.new(ApplicationController) do - include ShopifyApp::Authenticated + include ShopifyApp::EnsureHasSession end Class.new(authenticated_controller) do diff --git a/test/dummy/app/controllers/home_controller.rb b/test/dummy/app/controllers/home_controller.rb index 6021d3724..1061aaa92 100644 --- a/test/dummy/app/controllers/home_controller.rb +++ b/test/dummy/app/controllers/home_controller.rb @@ -2,7 +2,7 @@ class HomeController < ApplicationController include ShopifyApp::EmbeddedApp - include ShopifyApp::RequireKnownShop + include ShopifyApp::EnsureInstalled def index "index" diff --git a/test/generators/home_controller_generator_test.rb b/test/generators/home_controller_generator_test.rb index 6e22e01be..d356ec4da 100644 --- a/test/generators/home_controller_generator_test.rb +++ b/test/generators/home_controller_generator_test.rb @@ -25,7 +25,7 @@ class HomeControllerGeneratorTest < Rails::Generators::TestCase assert_match "HomeController < ApplicationController", file assert_match "include ShopifyApp::ShopAccessScopesVerification", file assert_match "include ShopifyApp::EmbeddedApp", file - assert_match "include ShopifyApp::RequireKnownShop", file + assert_match "include ShopifyApp::EnsureInstalled", file end assert_file "app/views/home/index.html.erb" end diff --git a/test/shopify_app/controller_concerns/login_protection_test.rb b/test/shopify_app/controller_concerns/login_protection_test.rb index fcc131994..7a29533be 100644 --- a/test/shopify_app/controller_concerns/login_protection_test.rb +++ b/test/shopify_app/controller_concerns/login_protection_test.rb @@ -476,7 +476,7 @@ class LoginProtectionControllerTest < ActionController::TestCase assert_deprecated(/incompatible concerns/) do Class.new(ApplicationController) do include ShopifyApp::LoginProtection - include ShopifyApp::RequireKnownShop + include ShopifyApp::EnsureInstalled end end From 018d59039f174ad5dd5a6d730e4e19a931f9c3ba Mon Sep 17 00:00:00 2001 From: Bill Klenotiz Date: Mon, 5 Dec 2022 14:42:21 -0500 Subject: [PATCH 31/35] assertion helper --- .../shopify_app/callback_controller.rb | 4 +-- test/controllers/callback_controller_test.rb | 33 ++++++++++++------- test/test_helper.rb | 4 +++ 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/app/controllers/shopify_app/callback_controller.rb b/app/controllers/shopify_app/callback_controller.rb index 323f18ae4..baef72e77 100644 --- a/app/controllers/shopify_app/callback_controller.rb +++ b/app/controllers/shopify_app/callback_controller.rb @@ -18,13 +18,13 @@ def callback auth_query: ShopifyAPI::Auth::Oauth::AuthQuery.new(**filtered_params), ) rescue => e - unless e.class.module_parent == ShopifyAPI::Errors + if e.class.module_parent != ShopifyAPI::Errors message = <<~EOS An error of type #{e.class} was rescued. This is not part of `ShopifyAPI::Errors`, which could indicate a bug in your app, or a bug in the shopify_app gem. Future versions of the gem may re-raise this error rather than rescuing it. EOS - ShopifyApp::Logger.deprecated(message, "22.0.0") + ShopifyApp::Logger.deprecated(message, "22.0.0") end return respond_with_error end diff --git a/test/controllers/callback_controller_test.rb b/test/controllers/callback_controller_test.rb index 9fc477ff4..cbad5224b 100644 --- a/test/controllers/callback_controller_test.rb +++ b/test/controllers/callback_controller_test.rb @@ -56,19 +56,30 @@ class CallbackControllerTest < ActionController::TestCase assert_equal flash[:error], "Could not log in to Shopify store" end - test "#callback rescued errors other than ShopifyAPI::Error will emit a deprecation notice" do - parent_deprecation_setting = ActiveSupport::Deprecation.silenced - ActiveSupport::Deprecation.silenced = false - ShopifyAPI::Context.stubs(:log_level).returns(:warn) + test "#callback rescued shopify errors will not be deprecated" do + + response = ShopifyAPI::Clients::HttpResponse.new(code: 500, headers: {}, body: "") + error = ShopifyAPI::Errors::HttpResponseError.new(response: response) + ShopifyAPI::Auth::Oauth.expects(:validate_auth_callback).raises(error) + + ShopifyApp::Logger.expects(:deprecated).never + get :callback, params: { shop: "shop", code: "code", state: "state", timestamp: "timestamp", host: "host", hmac: "hmac" } + end - ShopifyAPI::Auth::Oauth.expects(:validate_auth_callback).raises(StandardError) - assert_deprecated(/An error of type StandardError was rescued/) do - get :callback, - params: { shop: "shop", code: "code", state: "state", timestamp: "timestamp", host: "host", hmac: "hmac" } - end - assert_equal flash[:error], "Could not log in to Shopify store" + test "#callback rescued non-shopify errors will be deprecated" do + error = StandardError.new + ShopifyAPI::Auth::Oauth.expects(:validate_auth_callback).raises(error) + + message = <<~EOS + An error of type #{error.class} was rescued. This is not part of `ShopifyAPI::Errors`, which could indicate a + bug in your app, or a bug in the shopify_app gem. Future versions of the gem may re-raise this error rather + than rescuing it. + EOS + version = "22.0.0" - ActiveSupport::Deprecation.silenced = parent_deprecation_setting + assert_within_deprecation_schedule(version) + ShopifyApp::Logger.expects(:deprecated).with(message, version) + get :callback, params: { shop: "shop", code: "code", state: "state", timestamp: "timestamp", host: "host", hmac: "hmac" } end test "#callback calls ShopifyAPI::Auth::Oauth.validate_auth_callback" do diff --git a/test/test_helper.rb b/test/test_helper.rb index 38b70a4c7..9d66f7860 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -59,4 +59,8 @@ def mock_session(shop: "my-shop.myshopify.com", scope: ShopifyApp.configuration. mock_session end + + def assert_within_deprecation_schedule(version_number) + assert Gem::Version.create(ShopifyApp::VERSION) < Gem::Version.create(version_number) + end end From c440eb48ea12a5feaef0157989b7cc1c59601829 Mon Sep 17 00:00:00 2001 From: Bill Klenotiz Date: Mon, 5 Dec 2022 20:56:42 -0500 Subject: [PATCH 32/35] update tests --- lib/shopify_app/logger.rb | 6 +- .../concerns/authenticated_test.rb | 15 ++--- .../concerns/ensure_installed_test.rb | 41 +++++------- .../concerns/require_known_shop_test.rb | 66 ++++++++++--------- ...eting_activity_extension_generator_test.rb | 14 ++-- .../controller_concerns/itp_test.rb | 17 ++--- .../login_protection_test.rb | 19 +++--- .../managers/scripttags_manager_test.rb | 11 ++-- 8 files changed, 90 insertions(+), 99 deletions(-) diff --git a/lib/shopify_app/logger.rb b/lib/shopify_app/logger.rb index b6920a983..c343294ba 100644 --- a/lib/shopify_app/logger.rb +++ b/lib/shopify_app/logger.rb @@ -10,14 +10,14 @@ def self.deprecated(message, version) ActiveSupport::Deprecation.warn("[#{version}] #{context(:warn)} #{message}") end + private + def self.context(log_level) current_shop = ShopifyAPI::Context.active_session&.shop || "Shop Not Found" "[ ShopifyApp | #{log_level.to_s.upcase} | #{current_shop} ]" end - private - - def valid_version(version) + def self.valid_version(version) current_version = Gem::Version.create(ShopifyApp::VERSION) deprecate_version = Gem::Version.create(version) current_version < deprecate_version diff --git a/test/controllers/concerns/authenticated_test.rb b/test/controllers/concerns/authenticated_test.rb index 3ddee87ed..dee5058c6 100644 --- a/test/controllers/concerns/authenticated_test.rb +++ b/test/controllers/concerns/authenticated_test.rb @@ -21,16 +21,13 @@ def index end test "detects deprecation message" do - parent_deprecation_setting = ActiveSupport::Deprecation.silenced - ActiveSupport::Deprecation.silenced = false - ShopifyAPI::Context.stubs(:log_level).returns(:warn) - - assert_deprecated(/Authenticated has been replaced by EnsureHasSession./) do - Class.new(ApplicationController) do - include ShopifyApp::Authenticated - end + version = "22.0.0" + ShopifyApp::Logger.expects(:deprecated).with(regexp_matches(/Authenticated has been replaced by EnsureHasSession./), version) + ShopifyApp::Logger.stubs(:deprecated).with("Itp will be removed in an upcoming version", version) + Class.new(ApplicationController) do + include ShopifyApp::Authenticated end - ActiveSupport::Deprecation.silenced = parent_deprecation_setting + assert_within_deprecation_schedule(version) end end diff --git a/test/controllers/concerns/ensure_installed_test.rb b/test/controllers/concerns/ensure_installed_test.rb index d4032194f..f5d17395f 100644 --- a/test/controllers/concerns/ensure_installed_test.rb +++ b/test/controllers/concerns/ensure_installed_test.rb @@ -62,34 +62,29 @@ def index end test "detects incompatible controller concerns" do - parent_deprecation_setting = ActiveSupport::Deprecation.silenced - ActiveSupport::Deprecation.silenced = false - ShopifyAPI::Context.stubs(:log_level).returns(:warn) - - assert_deprecated(/incompatible concerns/) do - Class.new(ApplicationController) do - include ShopifyApp::LoginProtection - include ShopifyApp::EnsureInstalled - end + version = "22.0.0" + ShopifyApp::Logger.expects(:deprecated).with(regexp_matches(/incompatible concerns/), version) + ShopifyApp::Logger.stubs(:deprecated).with("Itp will be removed in an upcoming version", "22.0.0") + + Class.new(ApplicationController) do + include ShopifyApp::LoginProtection + include ShopifyApp::EnsureInstalled end - assert_deprecated(/incompatible concerns/) do - Class.new(ApplicationController) do - include ShopifyApp::EnsureHasSession # since this indirectly includes LoginProtection - include ShopifyApp::EnsureInstalled - end + ShopifyApp::Logger.expects(:deprecated).with(regexp_matches(/incompatible concerns/), version) + Class.new(ApplicationController) do + include ShopifyApp::EnsureHasSession # since this indirectly includes LoginProtection + include ShopifyApp::EnsureInstalled end - assert_deprecated(/incompatible concerns/) do - authenticated_controller = Class.new(ApplicationController) do - include ShopifyApp::Authenticated - end - - Class.new(authenticated_controller) do - include ShopifyApp::EnsureInstalled - end + ShopifyApp::Logger.expects(:deprecated).with(regexp_matches(/incompatible concerns/), version) + authenticated_controller = Class.new(ApplicationController) do + include ShopifyApp::EnsureHasSession + end + Class.new(authenticated_controller) do + include ShopifyApp::EnsureInstalled end - ActiveSupport::Deprecation.silenced = parent_deprecation_setting + assert_within_deprecation_schedule(version) end end diff --git a/test/controllers/concerns/require_known_shop_test.rb b/test/controllers/concerns/require_known_shop_test.rb index e783efe05..84febd3de 100644 --- a/test/controllers/concerns/require_known_shop_test.rb +++ b/test/controllers/concerns/require_known_shop_test.rb @@ -62,46 +62,52 @@ def index end test "detects incompatible controller concerns" do - parent_deprecation_setting = ActiveSupport::Deprecation.silenced - ActiveSupport::Deprecation.silenced = false - ShopifyAPI::Context.stubs(:log_level).returns(:warn) - assert_deprecated(/incompatible concerns/) do - Class.new(ApplicationController) do - include ShopifyApp::RequireKnownShop - include ShopifyApp::LoginProtection - end + replaced_message = "RequireKnownShop has been replaced by EnsureInstalled."\ + " Please use the EnsureInstalled controller concern for the same behavior" + + version = "22.0.0" + + + ShopifyApp::Logger.stubs(:deprecated).with("Itp will be removed in an upcoming version", version) + ShopifyApp::Logger.stubs(:deprecated).with(replaced_message, version) + + ShopifyApp::Logger.expects(:deprecated).with(regexp_matches(/incompatible concerns/), version) + + Class.new(ApplicationController) do + include ShopifyApp::RequireKnownShop + include ShopifyApp::LoginProtection end - assert_deprecated(/incompatible concerns/) do - Class.new(ApplicationController) do - include ShopifyApp::RequireKnownShop - include ShopifyApp::EnsureHasSession # since this indirectly includes LoginProtection - end + ShopifyApp::Logger.expects(:deprecated).with(regexp_matches(/incompatible concerns/), version) + + Class.new(ApplicationController) do + include ShopifyApp::RequireKnownShop + include ShopifyApp::EnsureHasSession # since this indirectly includes LoginProtection end - assert_deprecated(/incompatible concerns/) do - authenticated_controller = Class.new(ApplicationController) do - include ShopifyApp::EnsureHasSession - end + ShopifyApp::Logger.expects(:deprecated).with(regexp_matches(/incompatible concerns/), version) - Class.new(authenticated_controller) do - include ShopifyApp::RequireKnownShop - end + authenticated_controller = Class.new(ApplicationController) do + include ShopifyApp::EnsureHasSession end - ActiveSupport::Deprecation.silenced = parent_deprecation_setting + + Class.new(authenticated_controller) do + include ShopifyApp::RequireKnownShop + end + + assert_within_deprecation_schedule(version) end test "detects name change deprecation message" do - parent_deprecation_setting = ActiveSupport::Deprecation.silenced - ActiveSupport::Deprecation.silenced = false - ShopifyAPI::Context.stubs(:log_level).returns(:warn) - - assert_deprecated(/RequireKnownShop has been replaced by EnsureInstalled./) do - Class.new(ApplicationController) do - include ShopifyApp::RequireKnownShop - end + message = "RequireKnownShop has been replaced by EnsureInstalled."\ + " Please use the EnsureInstalled controller concern for the same behavior" + version = "22.0.0" + ShopifyApp::Logger.expects(:deprecated).with(message, version) + + Class.new(ApplicationController) do + include ShopifyApp::RequireKnownShop end - ActiveSupport::Deprecation.silenced = parent_deprecation_setting + assert_within_deprecation_schedule(version) end end diff --git a/test/generators/add_marketing_activity_extension_generator_test.rb b/test/generators/add_marketing_activity_extension_generator_test.rb index c02f9c415..5b9783d2f 100644 --- a/test/generators/add_marketing_activity_extension_generator_test.rb +++ b/test/generators/add_marketing_activity_extension_generator_test.rb @@ -39,14 +39,10 @@ class AddMarketingActivityExtensionGeneratorTest < Rails::Generators::TestCase end test "detect deprecation notice when generating controller" do - parent_deprecation_setting = ActiveSupport::Deprecation.silenced - ActiveSupport::Deprecation.silenced = false - ShopifyAPI::Context.stubs(:log_level).returns(:warn) - - assert_deprecated(/MarketingActivitiesController will be removed/) do - provide_existing_routes_file - run_generator - end - ActiveSupport::Deprecation.silenced = parent_deprecation_setting + message = "MarketingActivitiesController will be removed in an upcoming version" + version = "22.0.0" + ShopifyApp::Logger.expects(:deprecated).with(message, version) + run_generator + assert_within_deprecation_schedule(version) end end diff --git a/test/shopify_app/controller_concerns/itp_test.rb b/test/shopify_app/controller_concerns/itp_test.rb index 3b61bd3d9..4c43c39f1 100644 --- a/test/shopify_app/controller_concerns/itp_test.rb +++ b/test/shopify_app/controller_concerns/itp_test.rb @@ -7,14 +7,15 @@ class ItpTest < ActionController::TestCase test "detects deprecation notice" do - parent_deprecation_setting = ActiveSupport::Deprecation.silenced - ActiveSupport::Deprecation.silenced = false - ShopifyAPI::Context.stubs(:log_level).returns(:warn) - assert_deprecated(/Itp will be removed/) do - Class.new(ApplicationController) do - include ShopifyApp::Itp - end + message = "Itp will be removed in an upcoming version" + version = "22.0.0" + + ShopifyApp::Logger.expects(:deprecated).with(message, version) + + Class.new(ApplicationController) do + include ShopifyApp::Itp end - ActiveSupport::Deprecation.silenced = parent_deprecation_setting + + assert_within_deprecation_schedule(version) end end diff --git a/test/shopify_app/controller_concerns/login_protection_test.rb b/test/shopify_app/controller_concerns/login_protection_test.rb index 7a29533be..0d29463b8 100644 --- a/test/shopify_app/controller_concerns/login_protection_test.rb +++ b/test/shopify_app/controller_concerns/login_protection_test.rb @@ -469,18 +469,17 @@ class LoginProtectionControllerTest < ActionController::TestCase end test "detects incompatible controller concerns" do - parent_deprecation_setting = ActiveSupport::Deprecation.silenced - ActiveSupport::Deprecation.silenced = false - ShopifyAPI::Context.stubs(:log_level).returns(:warn) - - assert_deprecated(/incompatible concerns/) do - Class.new(ApplicationController) do - include ShopifyApp::LoginProtection - include ShopifyApp::EnsureInstalled - end + version = "22.0.0" + + ShopifyApp::Logger.expects(:deprecated).with(regexp_matches(/incompatible concerns/), version) + ShopifyApp::Logger.stubs(:deprecated).with("Itp will be removed in an upcoming version", version) + + Class.new(ApplicationController) do + include ShopifyApp::LoginProtection + include ShopifyApp::EnsureInstalled end - ActiveSupport::Deprecation.silenced = parent_deprecation_setting + assert_within_deprecation_schedule(version) end private diff --git a/test/shopify_app/managers/scripttags_manager_test.rb b/test/shopify_app/managers/scripttags_manager_test.rb index 10370859b..f4317796e 100644 --- a/test/shopify_app/managers/scripttags_manager_test.rb +++ b/test/shopify_app/managers/scripttags_manager_test.rb @@ -117,13 +117,10 @@ class ShopifyApp::ScripttagsManagerTest < ActiveSupport::TestCase end test "deprecation message is found on initialization" do - parent_deprecation_setting = ActiveSupport::Deprecation.silenced - ActiveSupport::Deprecation.silenced = false - ShopifyAPI::Context.stubs(:log_level).returns(:warn) - assert_deprecated(/ScripttagsManager will become deprecated/) do - ShopifyApp::ScripttagsManager.new("scripttags", "shop_domain") - end - ActiveSupport::Deprecation.silenced = parent_deprecation_setting + version = "22.0.0" + ShopifyApp::Logger.expects(:deprecated).with(regexp_matches(/ScripttagsManager will become deprecated/), version) + ShopifyApp::ScripttagsManager.new("scripttags", "shop_domain") + assert_within_deprecation_schedule(version) end private From 9cd4856ebef5bb6aef68d1e586fb936cbbf979f3 Mon Sep 17 00:00:00 2001 From: Bill Klenotiz <54754550+klenotiw@users.noreply.github.com> Date: Tue, 6 Dec 2022 09:08:27 -0500 Subject: [PATCH 33/35] Update test/test_helper.rb Co-authored-by: Nelson --- test/test_helper.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/test_helper.rb b/test/test_helper.rb index 9d66f7860..1246dbcad 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -59,7 +59,9 @@ def mock_session(shop: "my-shop.myshopify.com", scope: ShopifyApp.configuration. mock_session end - +## +# If a test fails with this assertion it means the behavior should now be removed from the codebase. +# The deprecation schedule gives users time to upgrade before the functionality can safely removed. def assert_within_deprecation_schedule(version_number) assert Gem::Version.create(ShopifyApp::VERSION) < Gem::Version.create(version_number) end From 5ca1d360242025cd7f9fdeee169c7dfc83ab3a18 Mon Sep 17 00:00:00 2001 From: Bill Klenotiz Date: Tue, 6 Dec 2022 09:17:42 -0500 Subject: [PATCH 34/35] rubocop --- .../concerns/shopify_app/ensure_installed.rb | 8 ++--- .../shopify_app/callback_controller.rb | 2 +- lib/shopify_app/logger.rb | 30 ++++++++++--------- test/controllers/callback_controller_test.rb | 9 +++--- .../concerns/authenticated_test.rb | 4 ++- .../concerns/ensure_installed_test.rb | 2 +- .../concerns/require_known_shop_test.rb | 1 - 7 files changed, 30 insertions(+), 26 deletions(-) diff --git a/app/controllers/concerns/shopify_app/ensure_installed.rb b/app/controllers/concerns/shopify_app/ensure_installed.rb index 39b0db4e6..c0ce88da4 100644 --- a/app/controllers/concerns/shopify_app/ensure_installed.rb +++ b/app/controllers/concerns/shopify_app/ensure_installed.rb @@ -20,10 +20,10 @@ module EnsureInstalled end def current_shopify_domain - if params[:shop].blank? - ShopifyApp::Logger.info("Could not identify installed store from current_shopify_domain") - return - end + if params[:shop].blank? + ShopifyApp::Logger.info("Could not identify installed store from current_shopify_domain") + return + end @shopify_domain ||= ShopifyApp::Utils.sanitize_shop_domain(params[:shop]) ShopifyApp::Logger.info("Installed store: #{@shopify_domain} - deduced from Shopify Admin params") diff --git a/app/controllers/shopify_app/callback_controller.rb b/app/controllers/shopify_app/callback_controller.rb index baef72e77..e43339500 100644 --- a/app/controllers/shopify_app/callback_controller.rb +++ b/app/controllers/shopify_app/callback_controller.rb @@ -24,7 +24,7 @@ def callback bug in your app, or a bug in the shopify_app gem. Future versions of the gem may re-raise this error rather than rescuing it. EOS - ShopifyApp::Logger.deprecated(message, "22.0.0") + ShopifyApp::Logger.deprecated(message, "22.0.0") end return respond_with_error end diff --git a/lib/shopify_app/logger.rb b/lib/shopify_app/logger.rb index c343294ba..d225d5b6a 100644 --- a/lib/shopify_app/logger.rb +++ b/lib/shopify_app/logger.rb @@ -2,25 +2,27 @@ module ShopifyApp class Logger < ShopifyAPI::Logger - def self.deprecated(message, version) - return unless enabled_for_log_level?(:warn) + class << self + def deprecated(message, version) + return unless enabled_for_log_level?(:warn) - raise ShopifyAPI::Errors::FeatureDeprecatedError unless valid_version(version) + raise ShopifyAPI::Errors::FeatureDeprecatedError unless valid_version(version) - ActiveSupport::Deprecation.warn("[#{version}] #{context(:warn)} #{message}") - end + ActiveSupport::Deprecation.warn("[#{version}] #{context(:warn)} #{message}") + end - private + private - def self.context(log_level) - current_shop = ShopifyAPI::Context.active_session&.shop || "Shop Not Found" - "[ ShopifyApp | #{log_level.to_s.upcase} | #{current_shop} ]" - end + def context(log_level) + current_shop = ShopifyAPI::Context.active_session&.shop || "Shop Not Found" + "[ ShopifyApp | #{log_level.to_s.upcase} | #{current_shop} ]" + end - def self.valid_version(version) - current_version = Gem::Version.create(ShopifyApp::VERSION) - deprecate_version = Gem::Version.create(version) - current_version < deprecate_version + def valid_version(version) + current_version = Gem::Version.create(ShopifyApp::VERSION) + deprecate_version = Gem::Version.create(version) + current_version < deprecate_version + end end end end diff --git a/test/controllers/callback_controller_test.rb b/test/controllers/callback_controller_test.rb index cbad5224b..da00ba3d0 100644 --- a/test/controllers/callback_controller_test.rb +++ b/test/controllers/callback_controller_test.rb @@ -57,13 +57,13 @@ class CallbackControllerTest < ActionController::TestCase end test "#callback rescued shopify errors will not be deprecated" do - response = ShopifyAPI::Clients::HttpResponse.new(code: 500, headers: {}, body: "") error = ShopifyAPI::Errors::HttpResponseError.new(response: response) ShopifyAPI::Auth::Oauth.expects(:validate_auth_callback).raises(error) - + ShopifyApp::Logger.expects(:deprecated).never - get :callback, params: { shop: "shop", code: "code", state: "state", timestamp: "timestamp", host: "host", hmac: "hmac" } + get :callback, + params: { shop: "shop", code: "code", state: "state", timestamp: "timestamp", host: "host", hmac: "hmac" } end test "#callback rescued non-shopify errors will be deprecated" do @@ -79,7 +79,8 @@ class CallbackControllerTest < ActionController::TestCase assert_within_deprecation_schedule(version) ShopifyApp::Logger.expects(:deprecated).with(message, version) - get :callback, params: { shop: "shop", code: "code", state: "state", timestamp: "timestamp", host: "host", hmac: "hmac" } + get :callback, + params: { shop: "shop", code: "code", state: "state", timestamp: "timestamp", host: "host", hmac: "hmac" } end test "#callback calls ShopifyAPI::Auth::Oauth.validate_auth_callback" do diff --git a/test/controllers/concerns/authenticated_test.rb b/test/controllers/concerns/authenticated_test.rb index dee5058c6..38a4deac7 100644 --- a/test/controllers/concerns/authenticated_test.rb +++ b/test/controllers/concerns/authenticated_test.rb @@ -22,7 +22,9 @@ def index test "detects deprecation message" do version = "22.0.0" - ShopifyApp::Logger.expects(:deprecated).with(regexp_matches(/Authenticated has been replaced by EnsureHasSession./), version) + ShopifyApp::Logger.expects(:deprecated).with( + regexp_matches(/Authenticated has been replaced by EnsureHasSession./), version + ) ShopifyApp::Logger.stubs(:deprecated).with("Itp will be removed in an upcoming version", version) Class.new(ApplicationController) do include ShopifyApp::Authenticated diff --git a/test/controllers/concerns/ensure_installed_test.rb b/test/controllers/concerns/ensure_installed_test.rb index f5d17395f..212e553c7 100644 --- a/test/controllers/concerns/ensure_installed_test.rb +++ b/test/controllers/concerns/ensure_installed_test.rb @@ -65,7 +65,7 @@ def index version = "22.0.0" ShopifyApp::Logger.expects(:deprecated).with(regexp_matches(/incompatible concerns/), version) ShopifyApp::Logger.stubs(:deprecated).with("Itp will be removed in an upcoming version", "22.0.0") - + Class.new(ApplicationController) do include ShopifyApp::LoginProtection include ShopifyApp::EnsureInstalled diff --git a/test/controllers/concerns/require_known_shop_test.rb b/test/controllers/concerns/require_known_shop_test.rb index 84febd3de..c85cbdf88 100644 --- a/test/controllers/concerns/require_known_shop_test.rb +++ b/test/controllers/concerns/require_known_shop_test.rb @@ -67,7 +67,6 @@ def index version = "22.0.0" - ShopifyApp::Logger.stubs(:deprecated).with("Itp will be removed in an upcoming version", version) ShopifyApp::Logger.stubs(:deprecated).with(replaced_message, version) From 058657b6d7658132f7ac2d6a315f3cbd81f4c21f Mon Sep 17 00:00:00 2001 From: Bill Klenotiz Date: Wed, 7 Dec 2022 09:43:15 -0500 Subject: [PATCH 35/35] update api ci should pass --- Gemfile.lock | 61 ++++++++++++++++++++++++++++----------------- shopify_app.gemspec | 2 +- test/test_helper.rb | 7 +++--- 3 files changed, 43 insertions(+), 27 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 787367ae6..8cd59c2b7 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -7,7 +7,7 @@ PATH jwt (>= 2.2.3) rails (> 5.2.1) redirect_safely (~> 1.0) - shopify_api (~> 12.2) + shopify_api (~> 12.3) sprockets-rails (>= 2.0.0) GEM @@ -85,7 +85,7 @@ GEM ast (2.4.2) binding_of_caller (1.0.0) debug_inspector (>= 0.0.1) - browser_sniffer (2.1.0) + browser_sniffer (2.2.0) builder (3.2.4) byebug (11.1.3) coderay (1.1.3) @@ -104,14 +104,17 @@ GEM multi_xml (>= 0.5.2) i18n (1.12.0) concurrent-ruby (~> 1.0) - json (2.6.2) + json (2.6.3) jwt (2.5.0) - language_server-protocol (3.17.0.1) + language_server-protocol (3.17.0.2) loofah (2.19.0) crass (~> 1.0.2) nokogiri (>= 1.5.9) - mail (2.7.1) + mail (2.8.0) mini_mime (>= 0.1.1) + net-imap + net-pop + net-smtp marcel (1.0.2) method_source (1.0.0) mime-types (3.4.1) @@ -120,18 +123,27 @@ GEM mini_mime (1.1.2) mini_portile2 (2.8.0) minitest (5.16.3) - mocha (1.16.0) + mocha (2.0.2) + ruby2_keywords (>= 0.0.5) multi_xml (0.6.0) + net-imap (0.3.1) + net-protocol + net-pop (0.1.2) + net-protocol + net-protocol (0.2.0) + timeout + net-smtp (0.3.3) + net-protocol nio4r (2.5.8) nokogiri (1.13.9) mini_portile2 (~> 2.8.0) racc (~> 1.4) - oj (3.13.21) + oj (3.13.23) openssl (3.0.1) parallel (1.22.1) - parser (3.1.2.1) + parser (3.1.3.0) ast (~> 2.4.1) - prettier_print (1.0.2) + prettier_print (1.1.0) pry (0.14.1) coderay (~> 1.1) method_source (~> 1.0) @@ -140,8 +152,8 @@ GEM pry-stack_explorer (0.6.1) binding_of_caller (~> 1.0) pry (~> 0.13) - public_suffix (5.0.0) - racc (1.6.0) + public_suffix (5.0.1) + racc (1.6.1) rack (2.2.4) rack-test (2.0.2) rack (>= 1.3) @@ -180,29 +192,31 @@ GEM rb-readline (0.5.5) redirect_safely (1.0.0) activemodel - regexp_parser (2.6.0) + regexp_parser (2.6.1) rexml (3.2.5) - rubocop (1.37.0) + rubocop (1.39.0) json (~> 2.3) parallel (~> 1.10) parser (>= 3.1.2.1) rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) rexml (>= 3.2.5, < 4.0) - rubocop-ast (>= 1.22.0, < 2.0) + rubocop-ast (>= 1.23.0, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 1.4.0, < 3.0) - rubocop-ast (1.22.0) + rubocop-ast (1.24.0) parser (>= 3.1.1.0) rubocop-shopify (2.10.1) rubocop (~> 1.35) - ruby-lsp (0.3.5) + ruby-lsp (0.3.6) language_server-protocol (~> 3.17.0) sorbet-runtime - syntax_tree (>= 4.0.2) + syntax_tree (>= 4.0.2, < 5.0.0) ruby-progressbar (1.11.0) - securerandom (0.2.0) - shopify_api (12.2.1) + ruby2_keywords (0.0.5) + securerandom (0.2.1) + shopify_api (12.3.0) + activesupport concurrent-ruby hash_diff httparty @@ -211,8 +225,8 @@ GEM openssl securerandom sorbet-runtime - zeitwerk (~> 2.5) - sorbet-runtime (0.5.10514) + zeitwerk (~> 2.5, < 2.6.5) + sorbet-runtime (0.5.10576) sprockets (4.1.1) concurrent-ruby (~> 1.0) rack (> 1, < 3) @@ -220,11 +234,12 @@ GEM actionpack (>= 5.2) activesupport (>= 5.2) sprockets (>= 3.0.0) - sqlite3 (1.5.3) + sqlite3 (1.5.4) mini_portile2 (~> 2.8.0) syntax_tree (4.3.0) prettier_print (>= 1.0.2) thor (1.2.1) + timeout (0.3.1) tzinfo (2.0.5) concurrent-ruby (~> 1.0) unicode-display_width (2.3.0) @@ -235,7 +250,7 @@ GEM websocket-driver (0.7.5) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) - zeitwerk (2.6.1) + zeitwerk (2.6.4) PLATFORMS ruby diff --git a/shopify_app.gemspec b/shopify_app.gemspec index 77acc1f1a..8ed338baf 100644 --- a/shopify_app.gemspec +++ b/shopify_app.gemspec @@ -19,7 +19,7 @@ Gem::Specification.new do |s| s.add_runtime_dependency("jwt", ">= 2.2.3") s.add_runtime_dependency("rails", "> 5.2.1") s.add_runtime_dependency("redirect_safely", "~> 1.0") - s.add_runtime_dependency("shopify_api", "~> 12.2") + s.add_runtime_dependency("shopify_api", "~> 12.3") s.add_runtime_dependency("sprockets-rails", ">= 2.0.0") s.add_development_dependency("byebug") diff --git a/test/test_helper.rb b/test/test_helper.rb index 1246dbcad..cf78da916 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -59,9 +59,10 @@ def mock_session(shop: "my-shop.myshopify.com", scope: ShopifyApp.configuration. mock_session end -## -# If a test fails with this assertion it means the behavior should now be removed from the codebase. -# The deprecation schedule gives users time to upgrade before the functionality can safely removed. + + ## + # If a test fails with this assertion it means the behavior should now be removed from the codebase. + # The deprecation schedule gives users time to upgrade before the functionality can safely removed. def assert_within_deprecation_schedule(version_number) assert Gem::Version.create(ShopifyApp::VERSION) < Gem::Version.create(version_number) end