From f4dae45b7841899def478834cc05dc565842614c Mon Sep 17 00:00:00 2001 From: Brandon Dunne Date: Wed, 13 Jul 2016 18:10:30 -0400 Subject: [PATCH] Ensure user_data is Base64 encoded https://bugzilla.redhat.com/show_bug.cgi?id=1355895 --- .../amazon/cloud_manager/provision/configuration.rb | 5 +++++ .../cloud_manager/provision/configuration_spec.rb | 11 +++++++++++ 2 files changed, 16 insertions(+) create mode 100644 spec/models/manageiq/providers/amazon/cloud_manager/provision/configuration_spec.rb diff --git a/app/models/manageiq/providers/amazon/cloud_manager/provision/configuration.rb b/app/models/manageiq/providers/amazon/cloud_manager/provision/configuration.rb index d14360e93..742eacb88 100644 --- a/app/models/manageiq/providers/amazon/cloud_manager/provision/configuration.rb +++ b/app/models/manageiq/providers/amazon/cloud_manager/provision/configuration.rb @@ -4,4 +4,9 @@ def associate_floating_ip(ip_address) instance.client.associate_address(:instance_id => instance.instance_id, :public_ip => ip_address) end end + + def userdata_payload + return unless raw_script = super + Base64.encode64(raw_script) + end end diff --git a/spec/models/manageiq/providers/amazon/cloud_manager/provision/configuration_spec.rb b/spec/models/manageiq/providers/amazon/cloud_manager/provision/configuration_spec.rb new file mode 100644 index 000000000..cd791bb80 --- /dev/null +++ b/spec/models/manageiq/providers/amazon/cloud_manager/provision/configuration_spec.rb @@ -0,0 +1,11 @@ +require_relative "../../aws_helper" + +describe ManageIQ::Providers::Amazon::CloudManager::Provision::Configuration do + it "#userdata_payload is Base64 encoded" do + template = FactoryGirl.build(:customization_template, :script => "#cloud-init") + provision = ManageIQ::Providers::Amazon::CloudManager::Provision.new + allow(provision).to receive(:customization_template).and_return(template) + allow(provision).to receive(:post_install_callback_url).and_return("") + expect(Base64.decode64(provision.userdata_payload)).to eq(template.script) + end +end