From 38dababf953c346628304fb1a01ed3c0cf9ab9c8 Mon Sep 17 00:00:00 2001 From: Eric O Date: Wed, 10 Jan 2024 17:08:06 -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..27f85a7 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(path) : YAML.load(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..4c15431 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(conf_path) : YAML.load(conf_path) + _opts = conf[Rails.env] || {} _opts = _opts.symbolize_keys _opts end