From fdc283878bdf5d6738979c24842469ab7b97179f Mon Sep 17 00:00:00 2001 From: Jason Frey Date: Tue, 6 Jun 2023 16:11:55 -0400 Subject: [PATCH] Merge pull request #851 from agrare/move_fix_expires_at_to_shared_helper Move fix_token_expries_at to spec/support (cherry picked from commit a31f0c89c674cbaeded91f756bdc480971099723) --- spec/spec_helper.rb | 10 +--------- spec/support/vcr_helper.rb | 13 +++++++++++++ 2 files changed, 14 insertions(+), 9 deletions(-) create mode 100644 spec/support/vcr_helper.rb diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index b1082bc46..f4dfca41f 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -12,19 +12,11 @@ config.filter_run_excluding(:qpid_proton) unless ENV['CI'] || Gem.loaded_specs.key?(:qpid_proton) end -def fix_token_expires_at(interaction) - data = JSON.parse(interaction.response.body) - data["token"]["expires_at"] = "9999-12-31T23:59:59.999999Z" - interaction.response.body = data.to_json.force_encoding('ASCII-8BIT') -end - VCR.configure do |config| config.ignore_hosts 'codeclimate.com' if ENV['CI'] config.cassette_library_dir = File.join(ManageIQ::Providers::Openstack::Engine.root, 'spec/vcr_cassettes') - config.before_record do |interaction| - fix_token_expires_at(interaction) if interaction.request.uri.end_with?("v3/auth/tokens") - end + fix_token_expires_at(config) secrets = Rails.application.secrets secrets.openstack.each_key do |secret| diff --git a/spec/support/vcr_helper.rb b/spec/support/vcr_helper.rb new file mode 100644 index 000000000..b36b0a880 --- /dev/null +++ b/spec/support/vcr_helper.rb @@ -0,0 +1,13 @@ +def fix_token_expires_at_interaction(interaction) + return unless interaction.request.uri.end_with?("v3/auth/tokens") + + data = JSON.parse(interaction.response.body) + return if data.dig("token", "expires_at").nil? + + data["token"]["expires_at"] = "9999-12-31T23:59:59.999999Z" + interaction.response.body = data.to_json.force_encoding('ASCII-8BIT') +end + +def fix_token_expires_at(config) + config.before_record { |interaction| fix_token_expires_at_interaction(interaction) } +end