Permalink
Browse files

Fixed issue where spaces were being double escaped which resulted

in some apparently valid requests to amazon, even though they should
not have been.
  • Loading branch information...
1 parent 35343e8 commit 33c20720d939164d0258d16e1e16698f85dc7cde @jiblits jiblits committed Jun 3, 2012
Showing with 14 additions and 12 deletions.
  1. +11 −7 lib/active_fulfillment/fulfillment/services/amazon_mws.rb
  2. +3 −5 test/unit/services/amazon_mws_test.rb
@@ -174,10 +174,14 @@ def test_mode?
false
end
+ def build_full_query(verb, uri, params)
+ signature = sign(verb, uri, params)
+ build_query(params) + "&Signature=#{signature}"
+ end
+
def commit(verb, service, op, params)
uri = URI.parse("https://#{endpoint}/#{ACTIONS[service]}/#{VERSION}")
- signature = sign(verb, uri, params)
- query = build_query(params) + "&Signature=#{signature}"
+ query = build_full_query(verb, uri, params)
headers = build_headers(query)
data = ssl_post(uri.to_s, query, headers)
@@ -395,7 +399,7 @@ def build_tracking_request(order_id, options)
def build_address(address)
requires!(address, :name, :address1, :city, :state, :country, :zip)
- ary = address.map{ |key, value| [escape(LOOKUPS[:destination_address][key]), escape(value)] if value.length > 0 }
+ ary = address.map{ |key, value| [LOOKUPS[:destination_address][key], value] if value.length > 0 }
Hash[ary.compact]
end
@@ -408,13 +412,13 @@ def build_items(line_items)
entry = value % counter
case key
when :sku
- items[entry] = escape(line_item[:sku] || "SKU-#{counter}")
+ items[entry] = line_item[:sku] || "SKU-#{counter}"
when :order_id
- items[entry] = escape(line_item[:sku] || "FULFILLMENT-ITEM-ID-#{counter}")
+ items[entry] = line_item[:sku] || "FULFILLMENT-ITEM-ID-#{counter}"
when :quantity
- items[entry] = escape(line_item[:quantity] || 1)
+ items[entry] = line_item[:quantity] || 1
else
- items[entry] = escape(line_item[key]) if line_item.include? key
+ items[entry] = line_item[key] if line_item.include? key
end
end
items
@@ -213,12 +213,10 @@ def test_fetch_tracking_numbers
end
def test_that_generated_requests_do_not_double_escape_spaces
- result = @service.fulfill("12345", @address, @line_items, @options)
- assert !result.include?('%2520')
- end
+ fulfillment_request = @service.send(:build_fulfillment_request, "12345", @address, @line_items, @options)
+ result = @service.build_full_query(:post, URI.parse("http://example.com/someservice/2011"), fulfillment_request)
- def test_a_fabulous_thing
- fail("shit is failing yo")
+ assert !result.include?('%2520')
end
def test_fetch_tracking_numbers_ignores_not_found

0 comments on commit 33c2072

Please sign in to comment.