From 288d1655c628f46584fac68bfc786c68cddf6053 Mon Sep 17 00:00:00 2001 From: baarkerlounger <5101747+baarkerlounger@users.noreply.github.com> Date: Fri, 25 Feb 2022 15:51:41 +0000 Subject: [PATCH] Handle invalid VCAP config (#336) * Handle invalid VCAP config * Rubocop --- app/services/paas_configuration_service.rb | 1 + spec/services/paas_configuration_service_spec.rb | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/app/services/paas_configuration_service.rb b/app/services/paas_configuration_service.rb index 9d8f1fe73..dc27a1b3b 100644 --- a/app/services/paas_configuration_service.rb +++ b/app/services/paas_configuration_service.rb @@ -27,6 +27,7 @@ private JSON.parse(ENV["VCAP_SERVICES"], { symbolize_names: true }) rescue StandardError @logger.warn("Could not parse VCAP_SERVICES!") + {} end end diff --git a/spec/services/paas_configuration_service_spec.rb b/spec/services/paas_configuration_service_spec.rb index 1e4c266e0..fa1e99d58 100644 --- a/spec/services/paas_configuration_service_spec.rb +++ b/spec/services/paas_configuration_service_spec.rb @@ -22,6 +22,22 @@ RSpec.describe PaasConfigurationService do end end + context "when configuration is present but invalid" do + let(:vcap_services) do + { "aws-s3-bucket": [{ instance_name: "bucket_1" }, { instance_name: "bucket_2" }] } + end + + before do + allow(ENV).to receive(:[]).with("VCAP_SERVICES").and_return(vcap_services) + allow(logger).to receive(:warn) + end + + it "logs an error" do + expect(logger).to receive(:warn).with("Could not parse VCAP_SERVICES!") + config_service.s3_config_present? + end + end + context "when the paas configuration is present with S3 buckets" do let(:vcap_services) do <<-JSON