Skip to content

Commit

Permalink
Fixed issue where spaces were being double escaped which resulted
Browse files Browse the repository at this point in the history
in some apparently valid requests to amazon, even though they should
not have been.
  • Loading branch information
jiblits committed Jun 3, 2012
1 parent 35343e8 commit 33c2072
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
18 changes: 11 additions & 7 deletions lib/active_fulfillment/fulfillment/services/amazon_mws.rb
Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down
8 changes: 3 additions & 5 deletions test/unit/services/amazon_mws_test.rb
Expand Up @@ -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
Expand Down

0 comments on commit 33c2072

Please sign in to comment.