From 389477ec30caac95c6b40e5f5521decbd49251b1 Mon Sep 17 00:00:00 2001 From: Nathaniel Talbott Date: Wed, 25 Feb 2015 12:08:36 -0500 Subject: [PATCH] Clean up `rake gateways:hosts` output Closes #1478. Closes #1581. --- CHANGELOG | 2 + Rakefile | 14 ++- lib/active_merchant/billing/gateways/epay.rb | 17 ++-- .../billing/gateways/iridium.rb | 2 +- .../billing/gateways/paymill.rb | 5 +- lib/support/outbound_hosts.rb | 23 ++--- test/remote/gateways/remote_epay_test.rb | 89 ++++++------------- 7 files changed, 68 insertions(+), 84 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 70702cc42eb..db2fd56a719 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,7 @@ = ActiveMerchant CHANGELOG +* Clean up `rake gateways:hosts` output [ntalbott] + == Version 1.47.0 (February 25, 2015) * Authorize.Net: Properly send name in shipping address line, when shipping address is provided [girasquid] diff --git a/Rakefile b/Rakefile index 596b675f003..4852f416101 100644 --- a/Rakefile +++ b/Rakefile @@ -76,7 +76,19 @@ namespace :gateways do desc 'Print the list of destination hosts with port' task :hosts do - OutboundHosts.list + hosts, invalid_lines = OutboundHosts.list + + hosts.each do |host| + puts host + end + + unless invalid_lines.empty? + puts + puts "Unable to parse:" + invalid_lines.each do |line| + puts line + end + end end desc 'Test that gateways allow SSL verify_peer' diff --git a/lib/active_merchant/billing/gateways/epay.rb b/lib/active_merchant/billing/gateways/epay.rb index 198f661e334..eb49b71f2fa 100644 --- a/lib/active_merchant/billing/gateways/epay.rb +++ b/lib/active_merchant/billing/gateways/epay.rb @@ -1,8 +1,7 @@ module ActiveMerchant #:nodoc: module Billing #:nodoc: class EpayGateway < Gateway - API_HOST = 'ssl.ditonlinebetalingssystem.dk' - self.live_url = 'https://' + API_HOST + '/remote/payment' + self.live_url = 'https://ssl.ditonlinebetalingssystem.dk/' self.default_currency = 'DKK' self.money_format = :cents @@ -175,14 +174,14 @@ def messages(epay, pbs = nil) def soap_post(method, params) data = xml_builder(params, method) headers = make_headers(data, method) - REXML::Document.new(ssl_post('https://' + API_HOST + '/remote/payment.asmx', data, headers)) + REXML::Document.new(ssl_post(live_url + 'remote/payment.asmx', data, headers)) end def do_authorize(params) headers = {} headers['Referer'] = (options[:password] || "activemerchant.org") - response = raw_ssl_request(:post, 'https://' + API_HOST + '/auth/default.aspx', authorize_post_data(params), headers) + response = raw_ssl_request(:post, live_url + 'auth/default.aspx', authorize_post_data(params), headers) # Authorize gives the response back by redirecting with the values in # the URL query @@ -233,9 +232,9 @@ def do_void(params) def make_headers(data, soap_call) { 'Content-Type' => 'text/xml; charset=utf-8', - 'Host' => API_HOST, + 'Host' => "ssl.ditonlinebetalingssystem.dk", 'Content-Length' => data.size.to_s, - 'SOAPAction' => self.live_url + '/' + soap_call + 'SOAPAction' => self.live_url + 'remote/payment/' + soap_call } end @@ -246,7 +245,7 @@ def xml_builder(params, soap_call) 'xmlns:xsd' => 'http://www.w3.org/2001/XMLSchema', 'xmlns:soap' => 'http://schemas.xmlsoap.org/soap/envelope/' } do xml.tag! 'soap:Body' do - xml.tag! soap_call, { 'xmlns' => self.live_url } do + xml.tag! soap_call, { 'xmlns' => "#{self.live_url}remote/payment" } do xml.tag! 'merchantnumber', @options[:login] xml.tag! 'transactionid', params[:transaction] xml.tag! 'amount', params[:amount].to_s if soap_call != 'delete' @@ -259,8 +258,8 @@ def xml_builder(params, soap_call) def authorize_post_data(params = {}) params[:language] = '2' params[:cms] = 'activemerchant' - params[:accepturl] = 'https://ssl.ditonlinebetalingssystem.dk/auth/default.aspx?accept=1' - params[:declineurl] = 'https://ssl.ditonlinebetalingssystem.dk/auth/default.aspx?decline=1' + params[:accepturl] = live_url + 'auth/default.aspx?accept=1' + params[:declineurl] = live_url + 'auth/default.aspx?decline=1' params[:merchantnumber] = @options[:login] params.collect { |key, value| "#{key}=#{CGI.escape(value.to_s)}" }.join("&") diff --git a/lib/active_merchant/billing/gateways/iridium.rb b/lib/active_merchant/billing/gateways/iridium.rb index 2de801489d4..110c7dc2c63 100644 --- a/lib/active_merchant/billing/gateways/iridium.rb +++ b/lib/active_merchant/billing/gateways/iridium.rb @@ -366,7 +366,7 @@ def add_merchant_data(xml, options) def commit(request, options) requires!(options, :action) response = parse(ssl_post(test? ? self.test_url : self.live_url, request, - {"SOAPAction" => "https://www.thepaymentgateway.net/#{options[:action]}", + {"SOAPAction" => "https://www.thepaymentgateway.net/" + options[:action], "Content-Type" => "text/xml; charset=utf-8" })) success = response[:transaction_result][:status_code] == "0" diff --git a/lib/active_merchant/billing/gateways/paymill.rb b/lib/active_merchant/billing/gateways/paymill.rb index 204a9d699ab..8c6669c827a 100644 --- a/lib/active_merchant/billing/gateways/paymill.rb +++ b/lib/active_merchant/billing/gateways/paymill.rb @@ -10,6 +10,7 @@ class PaymillGateway < Gateway self.display_name = 'PAYMILL' self.money_format = :cents self.default_currency = 'EUR' + self.live_url = "https://api.paymill.com/v2/" def initialize(options = {}) requires!(options, :public_key, :private_key) @@ -63,9 +64,9 @@ def headers { 'Authorization' => ('Basic ' + Base64.strict_encode64("#{@options[:private_key]}:X").chomp) } end - def commit(method, url, parameters=nil) + def commit(method, action, parameters=nil) begin - raw_response = ssl_request(method, "https://api.paymill.com/v2/#{url}", post_data(parameters), headers) + raw_response = ssl_request(method, live_url + action, post_data(parameters), headers) rescue ResponseError => e begin parsed = JSON.parse(e.response.body) diff --git a/lib/support/outbound_hosts.rb b/lib/support/outbound_hosts.rb index bac790662b6..844df856bb3 100644 --- a/lib/support/outbound_hosts.rb +++ b/lib/support/outbound_hosts.rb @@ -2,24 +2,27 @@ require 'set' class OutboundHosts - def self.list - uris = Set.new + def self.list + hosts = Set.new + invalid_lines = Set.new Dir['lib/**/*.rb'].each do |file| content = File.read(file) content.each_line do |line| next if line =~ /homepage_url/ - - if line =~ /("|')(https:\/\/.*)("|')/ - uri = URI.parse($2) - uris << [uri.host, uri.port] + + if line =~ /("|')(https:\/\/[^'"]*)("|')/ + begin + uri = URI.parse($2) + hosts << "#{uri.host}:#{uri.port}" + rescue URI::InvalidURIError + invalid_lines << line + end end end end - uris.each do |uri| - puts "#{uri.first} #{uri.last}" - end + [hosts, invalid_lines] end -end \ No newline at end of file +end diff --git a/test/remote/gateways/remote_epay_test.rb b/test/remote/gateways/remote_epay_test.rb index 8d150946904..6d755f78799 100644 --- a/test/remote/gateways/remote_epay_test.rb +++ b/test/remote/gateways/remote_epay_test.rb @@ -10,96 +10,63 @@ def setup @credit_card_declined = credit_card('3333333333333102') @amount = 100 - @options = { :order_id => '1' } + @options = {order_id: '1'} end - def test_successful_authorization - assert response = @gateway.authorize(@amount, @credit_card, @options) - assert_equal "1", response.params['accept'] - assert_not_nil response.params['tid'] - assert_not_nil response.params['cur'] - assert_not_nil response.params['amount'] - assert_not_nil response.params['orderid'] - assert !response.authorization.blank? + def test_successful_purchase + response = @gateway.purchase(@amount, @credit_card, @options) assert_success response + assert !response.authorization.blank? assert response.test? end - def test_failed_authorization - assert response = @gateway.authorize(@amount, @credit_card_declined, @options) - assert_equal '1', response.params['decline'] - assert_not_nil response.params['error'] - assert_not_nil response.params['errortext'] - assert_failure response - assert response.test? - end - - def test_successful_purchase - assert response = @gateway.purchase(@amount, @credit_card, @options) - assert_equal '1', response.params['accept'] - assert_not_nil response.params['tid'] - assert_not_nil response.params['cur'] - assert_not_nil response.params['amount'] - assert_not_nil response.params['orderid'] - assert !response.authorization.blank? + def test_successful_authorize_and_capture + response = @gateway.authorize(@amount, @credit_card, @options) assert_success response - assert response.test? + assert !response.authorization.blank? + + capture_response = @gateway.capture(@amount, response.authorization) + assert_success capture_response end - def test_failed_purchase - assert response = @gateway.purchase(@amount, @credit_card_declined, @options) - assert_equal '1', response.params['decline'] - assert_not_nil response.params['error'] - assert_not_nil response.params['errortext'] + def test_failed_authorization + response = @gateway.authorize(@amount, @credit_card_declined, @options) assert_failure response - assert response.test? end - def test_successful_capture - authorize_response = @gateway.authorize(@amount, @credit_card, @options) - - assert response = @gateway.capture(@amount, authorize_response.authorization) - assert_equal 'true', response.params['result'] - assert_success response - assert response.test? + def test_failed_purchase + response = @gateway.purchase(@amount, @credit_card_declined, @options) + assert_failure response end def test_failed_capture - assert response = @gateway.capture(@amount, 0) - assert_equal 'false', response.params['result'] + response = @gateway.capture(@amount, 0) assert_failure response - assert response.test? end def test_successful_refund - authorize_response = @gateway.purchase(@amount, @credit_card, @options) - - assert response = @gateway.refund(@amount, authorize_response.authorization) - assert_equal 'true', response.params['result'] + response = @gateway.purchase(@amount, @credit_card, @options) assert_success response - assert response.test? + + refund_response = @gateway.refund(@amount, response.authorization) + assert_success refund_response end def test_failed_refund - assert response_refund = @gateway.refund(@amount, 0) - assert_equal 'false', response_refund.params['result'] - assert_failure response_refund - assert response_refund.test? + response = @gateway.refund(@amount, 0) + assert_failure response end def test_successful_void - authorize_response = @gateway.authorize(@amount, @credit_card, @options) - - assert response = @gateway.void(authorize_response.authorization) - assert_equal 'true', response.params['result'] + response = @gateway.authorize(@amount, @credit_card, @options) assert_success response - assert response.test? + + void_response = @gateway.void(response.authorization) + assert_success void_response end def test_failed_void - assert response_void = @gateway.void(0) - assert_equal 'false', response_void.params['result'] - assert_failure response_void - assert response_void.test? + response = @gateway.void(0) + assert_failure response end end