From 44c003acbefc5dd4ab0455223b6cf0ec9cdd7a74 Mon Sep 17 00:00:00 2001 From: Eric O Date: Wed, 10 Jan 2024 17:13:02 -0500 Subject: [PATCH] Compatibility with older and newer versions of psych gem --- app/models/concerns/cul/omniauth/abilities.rb | 4 +++- lib/cul/omniauth/file_configurable.rb | 6 +++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/models/concerns/cul/omniauth/abilities.rb b/app/models/concerns/cul/omniauth/abilities.rb index 9e5ee76..5cec7f4 100644 --- a/app/models/concerns/cul/omniauth/abilities.rb +++ b/app/models/concerns/cul/omniauth/abilities.rb @@ -80,7 +80,9 @@ def config @role_proxy_config ||= begin root = (Rails.root.blank?) ? '.' : Rails.root path = File.join(root,'config','roles.yml') - _opts = YAML.load_file(path) + # We'll use YAML loading logic similar to Rails 7, for older and newer psych gem compatibility + # https://github.com/rails/rails/blob/7-1-stable/activesupport/lib/active_support/encrypted_configuration.rb#L99 + _opts = YAML.respond_to?(:unsafe_load) ? YAML.unsafe_load_file(path) : YAML.load_file(path) all_config = _opts.fetch("_all_environments", {}) env_config = _opts.fetch(Rails.env, {}) symbolize_hash_keys(all_config.merge(env_config)) diff --git a/lib/cul/omniauth/file_configurable.rb b/lib/cul/omniauth/file_configurable.rb index 0c807ab..818f993 100644 --- a/lib/cul/omniauth/file_configurable.rb +++ b/lib/cul/omniauth/file_configurable.rb @@ -8,7 +8,11 @@ module Cul::Omniauth::FileConfigurable module ClassMethods def cas_configuration_opts @cas_opts ||= begin - _opts = YAML.load_file(File.join(Rails.root,'config','cas.yml'))[Rails.env] || {} + conf_path = File.join(Rails.root,'config','cas.yml') + # We'll use YAML loading logic similar to Rails 7, for older and newer psych gem compatibility + # https://github.com/rails/rails/blob/7-1-stable/activesupport/lib/active_support/encrypted_configuration.rb#L99 + conf = YAML.respond_to?(:unsafe_load) ? YAML.unsafe_load_file(conf_path) : YAML.load_file(conf_path) + _opts = conf[Rails.env] || {} _opts = _opts.symbolize_keys _opts end