Skip to content

Commit 7cdc46c

Browse files
authored
Merge pull request #554 from jrafanie/permit_yaml_safe_load_of_aliases
Permit yaml safe_load of aliases in automate ruby methods
2 parents 0afae73 + 7f4d58e commit 7cdc46c

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

lib/miq_automation_engine/engine/miq_ae_engine/drb_remote_invoker.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,14 @@ class AutomateMethodException < StandardError
110110
require 'drb'
111111
require 'yaml'
112112
113+
YAML.singleton_class.prepend(
114+
Module.new do
115+
def safe_load(yaml, aliases: false, **kwargs)
116+
super(yaml, aliases: true, **kwargs)
117+
end
118+
end
119+
)
120+
113121
Time.zone = 'UTC'
114122
115123
MIQ_OK = 0

spec/engine/miq_ae_method_spec.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,38 @@ def root
4747
end
4848
end
4949

50+
context "with a script that tries to YAML.load with aliases" do
51+
let(:script) do
52+
<<-RUBY
53+
YAML.load("---\na: &a\n b: true \n\ndevelopment:\n <<: *a\n c: false\n\n")
54+
RUBY
55+
end
56+
57+
it "logs and returns the correct exit status" do
58+
allow($miq_ae_logger).to receive(:info).and_call_original
59+
expect($miq_ae_logger).to receive(:info).with("Method exited with rc=MIQ_OK", :resource_id => 123).at_least(:once)
60+
expect($miq_ae_logger).to_not receive(:error)
61+
62+
expect(subject).to eq(0)
63+
end
64+
end
65+
66+
context "with a script that tries to YAML.safe_load with aliases" do
67+
let(:script) do
68+
<<-RUBY
69+
YAML.safe_load("---\na: &a\n b: true \n\ndevelopment:\n <<: *a\n c: false\n\n")
70+
RUBY
71+
end
72+
73+
it "logs and returns the correct exit status" do
74+
allow($miq_ae_logger).to receive(:info).and_call_original
75+
expect($miq_ae_logger).to receive(:info).with("Method exited with rc=MIQ_OK", :resource_id => 123).at_least(:once)
76+
expect($miq_ae_logger).to_not receive(:error)
77+
78+
expect(subject).to eq(0)
79+
end
80+
end
81+
5082
context "with a script that raises" do
5183
let(:script) do
5284
<<-RUBY

0 commit comments

Comments
 (0)