From 9ace678803592c027170a42945226529439abfd2 Mon Sep 17 00:00:00 2001 From: Ash Wilson Date: Thu, 20 Mar 2014 15:31:26 -0400 Subject: [PATCH] Test the relevant bits of the temp_urls explicitly. --- .../requests/storage/object_tests.rb | 36 +++++++++++++++---- 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/tests/openstack/requests/storage/object_tests.rb b/tests/openstack/requests/storage/object_tests.rb index 69d8f35c3..ef1a8785b 100644 --- a/tests/openstack/requests/storage/object_tests.rb +++ b/tests/openstack/requests/storage/object_tests.rb @@ -41,18 +41,42 @@ Shindo.tests('Fog::Storage[:openstack] | object requests', ["openstack"]) do Fog::Storage[:openstack].delete_object('fogobjecttests', 'fog_object') end - tests("#get_object_http_url('directory.identity', 'fog_object', expiration timestamp)").returns(true) do + tests("#get_object_http_url('directory.identity', 'fog_object', expiration timestamp)").succeeds do pending if Fog.mocking? - object_url = Fog::Storage[:openstack].get_object_http_url(@directory.identity, 'fog_object', (Time.now + 60)) + ts = Time.at(1395343213) + object_url_s = Fog::Storage[:openstack].get_object_http_url(@directory.identity, 'fog_object', ts) + object_url = URI.parse(object_url_s) + query_params = URI.decode_www_form(object_url.query) - (object_url =~ /http:\/\/\S+\/v1\/AUTH_\S+\/#{@directory.identity}\/fog_object\?temp_url_sig=\S+&temp_url_expires=\d+/) != nil + tests('the link is http').returns('http') { object_url.scheme } + tests('the container and object are present in the path').returns(true) do + (object_url.path =~ /\/#{@directory.identity}\/fog_object/) != nil + end + tests('a temp_url_sig is present').returns(true) do + query_params.any? { |p| p[0] == 'temp_url_sig' } + end + tests('temp_url_expires matches the expiration').returns(true) do + query_params.any? { |p| p == ['temp_url_expires', ts.to_i.to_s] } + end end - tests("#get_object_https_url('directory.identity', 'fog_object', expiration timestamp)").returns(true) do + tests("#get_object_https_url('directory.identity', 'fog_object', expiration timestamp)").succeeds do pending if Fog.mocking? - object_url = Fog::Storage[:openstack].get_object_https_url(@directory.identity, 'fog_object', (Time.now + 60)) + ts = Time.at(1395343213) + object_url_s = Fog::Storage[:openstack].get_object_https_url(@directory.identity, 'fog_object', ts) + object_url = URI.parse(object_url_s) + query_params = URI.decode_www_form(object_url.query) - (object_url =~ /https:\/\/\S+\/v1\/AUTH_\S+\/#{@directory.identity}\/fog_object\?temp_url_sig=\S+&temp_url_expires=\d+/) != nil + tests('the link is https').returns('https') { object_url.scheme } + tests('the container and object are present in the path').returns(true) do + (object_url.path =~ /\/#{@directory.identity}\/fog_object/) != nil + end + tests('a temp_url_sig is present').returns(true) do + query_params.any? { |p| p[0] == 'temp_url_sig' } + end + tests('temp_url_expires matches the expiration').returns(true) do + query_params.any? { |p| p == ['temp_url_expires', ts.to_i.to_s] } + end end tests("put_object with block") do