Skip to content

Commit

Permalink
Merge pull request #3898 from 3scale/fix-psych-4-alias-incompatibility
Browse files Browse the repository at this point in the history
Remove psych hardcoded version and use alias explicitly
  • Loading branch information
mayorova authored Sep 30, 2024
2 parents 29c7ca9 + 10253aa commit b9c0cc1
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 12 deletions.
3 changes: 0 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ gem "activejob-uniqueness"
# Needed for XML serialization of ActiveRecord::Base
gem 'activemodel-serializers-xml'

# Fixing https://github.com/ruby/psych/pull/438, remove after upgrading Ruby
gem 'psych', '~> 3.2.0'

gem 'protected_attributes_continued', '~> 1.8.2'

gem 'rails-observers'
Expand Down
2 changes: 0 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,6 @@ GEM
pry-stack_explorer (0.6.1)
binding_of_caller (~> 1.0)
pry (~> 0.13)
psych (3.2.1)
public_suffix (4.0.7)
raabro (1.4.0)
racc (1.8.1)
Expand Down Expand Up @@ -1056,7 +1055,6 @@ DEPENDENCIES
pry-rails
pry-shell
pry-stack_explorer
psych (~> 3.2.0)
rack (~> 2.2.8)
rack-cors
rack-no_animations (~> 1.0.3)
Expand Down
2 changes: 1 addition & 1 deletion app/lib/backend/storage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Storage < ::System::RedisPool
def self.parse_config
config = File.read("#{Rails.root}/config/backend_redis.yml")
config = ERB.new(config).result(binding)
config = YAML.load(config)
config = YAML.load(config, aliases: true)
config.fetch(Rails.env).deep_symbolize_keys
end

Expand Down
9 changes: 8 additions & 1 deletion app/lib/three_scale/jobs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ module ThreeScale
module Jobs

class Task
attr_reader :object

def initialize(object, method, *args)
@object = object
@method = method
Expand Down Expand Up @@ -43,7 +45,8 @@ def map(tasks)

def deserialize(args)
hash = normalize_task_args(args)
klass, method, arguments = YAML.load(hash[:init_args]) # rubocop:disable Security/YAMLLoad
permitted_classes = ActiveRecord::Base.yaml_column_permitted_classes + ThreeScale::Jobs::JOB_CLASSES
klass, method, arguments = YAML.load(hash[:init_args], permitted_classes: permitted_classes)
hash[:klass].constantize.new(klass, method, *arguments)
end

Expand Down Expand Up @@ -130,5 +133,9 @@ def run
HOUR = Task.map([
[Rails, :env]
]).freeze # just a fake job to ensure cron works

PERIODS = [HOUR, DAILY, WEEK, MONTH, BILLING]

JOB_CLASSES = ThreeScale::Jobs::PERIODS.flatten.map(&:object)
end
end
8 changes: 4 additions & 4 deletions test/unit/lib/three_scale/jobs_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ def test_rake_task_serialize
end

def test_task_serialize
task = ThreeScale::Jobs::Task.new(Account, :new, org_name: 'Company')
serialized = YAML.dump([Account, :new, {org_name: 'Company'}])
task = ThreeScale::Jobs::Task.new(DestroyAllDeletedObjectsWorker, :perform_later, 'Service')
serialized = YAML.dump([DestroyAllDeletedObjectsWorker, :perform_later, 'Service'])
assert_equal({klass: "ThreeScale::Jobs::Task", init_args: serialized}, task.serialize)
end

def test_task_deserialize
task = ThreeScale::Jobs::Task.new(Account, :new, org_name: 'Company')
serialized = YAML.dump([Account, :new, [{org_name: 'Company'}]])
task = ThreeScale::Jobs::Task.new(DestroyAllDeletedObjectsWorker, :perform_later, 'Service')
serialized = YAML.dump([DestroyAllDeletedObjectsWorker, :perform_later, ['Service']])
assert_equal(task, ThreeScale::Jobs::Task.deserialize(klass: 'ThreeScale::Jobs::Task', init_args: serialized))
end

Expand Down
2 changes: 1 addition & 1 deletion test/unit/three_scale/middleware/cors_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class ThreeScale::Middleware::CorsTest < ActiveSupport::TestCase
end

test 'provider signup path excluded in default configs' do
cors_config = YAML.load_file(Rails.root.join("config/cors.yml")).deep_symbolize_keys
cors_config = YAML.load_file(Rails.root.join("config/cors.yml"), aliases: true, permitted_classes: [Symbol, Regexp]).deep_symbolize_keys
rails_envs = %i[development test production]
rails_envs.each do |rails_env|
stub_config = cors_config[rails_env]
Expand Down

0 comments on commit b9c0cc1

Please sign in to comment.