deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lut...@redhat.com
Subject [PATCH 2/2] EC2 tests: change the VCR matcher to ignore time- and user-dependent params
Date Fri, 24 Aug 2012 04:24:30 GMT
From: David Lutterkort <lutter@redhat.com>

Requests to EC2 contain the parameters AWSAccessKeyId, Signature, and
Timestamp which are dependent on the user recording the tests and the time
of the recording. By ignoring these requests params the recordings become
independent of the access key/secret of the user making the recording, and
of how long ago the recordings were made.

That also obviates the need for Timecop-style time manipulation
---
 server/tests/README.md                             |    6 +---
 server/tests/drivers/ec2/common.rb                 |   14 ++------
 server/tests/drivers/ec2/storage_snapshots_test.rb |    1 -
 server/tests/test_helper.rb                        |   33 --------------------
 4 files changed, 5 insertions(+), 49 deletions(-)

diff --git a/server/tests/README.md b/server/tests/README.md
index c5fb2fb..ca84754 100644
--- a/server/tests/README.md
+++ b/server/tests/README.md
@@ -94,11 +94,7 @@ Updating VCR data
 
 In some cases you will need to re-record the VCR fixtures for particular test.
 This happen when a new request is made to the backend cloud in method that
-already has tests. To do so, you will need your own credentials. Then in the
-'before' section of test you will need to use Time.be method to freeze time
-to the current time and use your credentials instead of 'default' ones.
-
-NOTE: This may change at some point to be more user-friendly.
+already has tests. To do so, you will need your own credentials.
 
 
 Test scenarios
diff --git a/server/tests/drivers/ec2/common.rb b/server/tests/drivers/ec2/common.rb
index 26982dc..0d6b608 100644
--- a/server/tests/drivers/ec2/common.rb
+++ b/server/tests/drivers/ec2/common.rb
@@ -5,12 +5,6 @@ require 'vcr'
 
 require_relative '../../test_helper.rb'
 
-# Freeze time, so EC2 signatures have all the same time
-# This will avoid IncorrectSignature exceptions
-
-# NOTE: This timestamp need to be changed when re-recording
-#       the fixtures.
-
 def credentials
   {
     :user => 'AKIAJYOQYLLOIWN5LQ3A',
@@ -18,12 +12,12 @@ def credentials
   }
 end
 
-Time.be(DateTime.parse("2012-07-30 11:05:00 +0000").to_s)
-
 VCR.configure do |c|
   # NOTE: Empty this directory before re-recording
   c.cassette_library_dir = File.join(File.dirname(__FILE__), 'fixtures')
   c.hook_into :webmock
-  # Set this to :new_episodes when you want to 're-record'
-  c.default_cassette_options = { :record => :new_episodes }
+  matcher = VCR.request_matchers.uri_without_param("AWSAccessKeyId",
+                                                   "Signature", "Timestamp")
+  c.register_request_matcher(:ec2_matcher, &matcher)
+  c.default_cassette_options = { :record => :new_episodes, :match_requests_on => [:method,
:ec2_matcher] }
 end
diff --git a/server/tests/drivers/ec2/storage_snapshots_test.rb b/server/tests/drivers/ec2/storage_snapshots_test.rb
index 912d09b..06f0ce0 100644
--- a/server/tests/drivers/ec2/storage_snapshots_test.rb
+++ b/server/tests/drivers/ec2/storage_snapshots_test.rb
@@ -5,7 +5,6 @@ require_relative 'common.rb'
 
 describe 'Ec2Driver StorageSnapshots' do
   before do
-    Time.be(DateTime.parse("2012-08-13 13:03:00 +0000").to_s)
     @driver = Deltacloud::new(:ec2, credentials)
     VCR.insert_cassette __name__
   end
diff --git a/server/tests/test_helper.rb b/server/tests/test_helper.rb
index a5128cf..bf9f2ca 100644
--- a/server/tests/test_helper.rb
+++ b/server/tests/test_helper.rb
@@ -18,39 +18,6 @@ if ENV['COVERAGE']
   end
 end
 
-require 'time'
-
-# This code was originally copied from:
-# https://github.com/jtrupiano/timecop/issues/8#issuecomment-1396047
-#
-# Since 'timecop' gem has broken 'timezone' support, this small monkey-patching
-# on Time object seems to fix this issue.
-
-unless Time.respond_to? :be
-  class Time
-    module TimeMock
-      attr_accessor :mock_time
-
-      def mock_now
-        @mock_time || Time.original_now
-      end
-
-      def be(a_time)
-        @mock_time = Time.parse(a_time)
-      end
-
-    end
-
-    class << self
-      include TimeMock
-      alias_method :original_now, :now
-      alias_method :now, :mock_now
-    end
-  end
-end
-
-# Test helpers
-
 def record_retries(name='')
   {
     :before => Proc.new { |r, &block|
-- 
1.7.7.6


Mime
View raw message