From 52e0eb2933f4737da20bfb1ae0396a82e2de4490 Mon Sep 17 00:00:00 2001 From: Sam Levenick Date: Mon, 3 Dec 2018 22:49:16 +0000 Subject: [PATCH] Move vcr config, require relative to load from inspec profile --- .../controls/google_compute_ssl_policies.rb | 2 +- .../controls/google_compute_ssl_policy.rb | 2 +- test/integration/verify-mm/vcr_config.rb | 34 +++++++++++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 test/integration/verify-mm/vcr_config.rb diff --git a/test/integration/verify-mm/controls/google_compute_ssl_policies.rb b/test/integration/verify-mm/controls/google_compute_ssl_policies.rb index 8616112e0..9e326ae09 100644 --- a/test/integration/verify-mm/controls/google_compute_ssl_policies.rb +++ b/test/integration/verify-mm/controls/google_compute_ssl_policies.rb @@ -12,7 +12,7 @@ # # ---------------------------------------------------------------------------- -require 'vcr_config' +require_relative '../vcr_config' title 'Test GCP google_compute_ssl_policies resource.' diff --git a/test/integration/verify-mm/controls/google_compute_ssl_policy.rb b/test/integration/verify-mm/controls/google_compute_ssl_policy.rb index 989ce4904..4a5bb3d54 100644 --- a/test/integration/verify-mm/controls/google_compute_ssl_policy.rb +++ b/test/integration/verify-mm/controls/google_compute_ssl_policy.rb @@ -12,7 +12,7 @@ # # ---------------------------------------------------------------------------- -require 'vcr_config' +require_relative '../vcr_config' title 'Test GCP google_compute_ssl_policy resource.' diff --git a/test/integration/verify-mm/vcr_config.rb b/test/integration/verify-mm/vcr_config.rb new file mode 100644 index 000000000..4c8921ce6 --- /dev/null +++ b/test/integration/verify-mm/vcr_config.rb @@ -0,0 +1,34 @@ +# Copyright 2017 Google Inc. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +require 'vcr' + +VCR.configure do |c| + c.hook_into :webmock + c.cassette_library_dir = 'inspec-cassettes' + c.allow_http_connections_when_no_cassette = true + + c.before_record do |i| + i.response.headers.delete_if { |key| key != 'Content-Type' } + i.request.headers.delete_if { |key| true } + if auth_call?(i) + i.request.body = 'AUTH REQUEST' + i.response.body = "{\n \"access_token\": \"ya29.c.samsamsamsamsamsamsamsamsa-thisisnintysixcharactersoftexttolooklikeanauthtokenthisisnintysixcharactersoftexttolooklikeanaut\",\n \"expires_in\": 3600,\n \"token_type\": \"Bearer\"\n}" + end + end +end + +def auth_call?(interaction) + # Auth calls require extra scrubbing, this method is very broad, this is intentional + interaction.request.uri.include? 'oauth2' +end \ No newline at end of file