diff --git a/lib/active_merchant/billing/gateways/quickpay/quickpay_v4to7.rb b/lib/active_merchant/billing/gateways/quickpay/quickpay_v4to7.rb index 48f3c431f6a..6ff7854b422 100644 --- a/lib/active_merchant/billing/gateways/quickpay/quickpay_v4to7.rb +++ b/lib/active_merchant/billing/gateways/quickpay/quickpay_v4to7.rb @@ -90,6 +90,18 @@ def store(creditcard, options = {}) commit(:subscribe, post) end + def supports_scrubbing? + true + end + + def scrub(transcript) + transcript. + gsub(%r((cardnumber=)\d+), '\1[FILTERED]'). + gsub(%r((cvd=)\d+), '\1[FILTERED]'). + gsub(%r((merchant=)\d+), '\1[FILTERED]'). + gsub(%r((apikey=).*?(&)), '\1[FILTERED]\2') + end + private def add_amount(post, money, options = {}) diff --git a/test/remote/gateways/remote_quickpay_v4_test.rb b/test/remote/gateways/remote_quickpay_v4_test.rb index a17b1a15c12..4e68e53a1c2 100644 --- a/test/remote/gateways/remote_quickpay_v4_test.rb +++ b/test/remote/gateways/remote_quickpay_v4_test.rb @@ -206,4 +206,15 @@ def test_invalid_login assert_equal 'Invalid merchant id', response.message assert_failure response end + + def test_transcript_scrubbing + transcript = capture_transcript(@gateway) do + @gateway.purchase(@amount, @visa, @options) + end + transcript = @gateway.scrub(transcript) + + assert_scrubbed(@visa.number, transcript) + assert_scrubbed(@visa.verification_value, transcript) + assert_scrubbed(@gateway.options[:login], transcript) + end end diff --git a/test/remote/gateways/remote_quickpay_v5_test.rb b/test/remote/gateways/remote_quickpay_v5_test.rb index 4b4c3795ad8..16a6a7ca5ab 100644 --- a/test/remote/gateways/remote_quickpay_v5_test.rb +++ b/test/remote/gateways/remote_quickpay_v5_test.rb @@ -206,4 +206,15 @@ def test_invalid_login assert_equal 'Invalid merchant id', response.message assert_failure response end + + def test_transcript_scrubbing + transcript = capture_transcript(@gateway) do + @gateway.purchase(@amount, @visa, @options) + end + transcript = @gateway.scrub(transcript) + + assert_scrubbed(@visa.number, transcript) + assert_scrubbed(@visa.verification_value, transcript) + assert_scrubbed(@gateway.options[:login], transcript) + end end diff --git a/test/remote/gateways/remote_quickpay_v6_test.rb b/test/remote/gateways/remote_quickpay_v6_test.rb index 817cdef9bdd..71b749615ec 100644 --- a/test/remote/gateways/remote_quickpay_v6_test.rb +++ b/test/remote/gateways/remote_quickpay_v6_test.rb @@ -206,4 +206,15 @@ def test_invalid_login assert_equal 'Invalid merchant id', response.message assert_failure response end + + def test_transcript_scrubbing + transcript = capture_transcript(@gateway) do + @gateway.purchase(@amount, @visa, @options) + end + transcript = @gateway.scrub(transcript) + + assert_scrubbed(@visa.number, transcript) + assert_scrubbed(@visa.verification_value, transcript) + assert_scrubbed(@gateway.options[:login], transcript) + end end diff --git a/test/remote/gateways/remote_quickpay_v7_test.rb b/test/remote/gateways/remote_quickpay_v7_test.rb index 8af4cc14267..f08af837c4f 100644 --- a/test/remote/gateways/remote_quickpay_v7_test.rb +++ b/test/remote/gateways/remote_quickpay_v7_test.rb @@ -226,4 +226,15 @@ def test_invalid_login assert_equal 'Invalid merchant id', response.message assert_failure response end + + def test_transcript_scrubbing + transcript = capture_transcript(@gateway) do + @gateway.purchase(@amount, @visa, @options) + end + transcript = @gateway.scrub(transcript) + + assert_scrubbed(@visa.number, transcript) + assert_scrubbed(@visa.verification_value, transcript) + assert_scrubbed(@gateway.options[:login], transcript) + end end diff --git a/test/unit/gateways/quickpay_v4to7_test.rb b/test/unit/gateways/quickpay_v4to7_test.rb index 8a632213856..e9f2b22bb6c 100644 --- a/test/unit/gateways/quickpay_v4to7_test.rb +++ b/test/unit/gateways/quickpay_v4to7_test.rb @@ -2,11 +2,11 @@ class QuickpayV4to7Test < Test::Unit::TestCase include CommStub - + def merchant_id - "80000000000" + "80000000000" end - + def setup @gateway = QuickpayGateway.new( :login => merchant_id, @@ -132,18 +132,6 @@ def test_supported_card_types assert_equal [ :dankort, :forbrugsforeningen, :visa, :master, :american_express, :diners_club, :jcb, :maestro ], klass.supported_cardtypes end - def test_add_testmode_does_not_add_testmode_if_transaction_id_present - post_hash = {:transaction => "12345"} - @gateway.send(:add_testmode, post_hash) - assert_equal nil, post_hash[:testmode] - end - - def test_add_testmode_adds_a_testmode_param_if_transaction_id_not_present - post_hash = {} - @gateway.send(:add_testmode, post_hash) - assert_equal '1', post_hash[:testmode] - end - def test_finalize_is_disabled_by_default stub_comms(@gateway, :ssl_request) do @gateway.capture(@amount, "12345") @@ -160,6 +148,14 @@ def test_finalize_is_enabled end.respond_with(successful_capture_response) end + def test_scrub + assert_equal @gateway.scrub(pre_scrubbed), post_scrubbed + end + + def test_supports_scrubbing? + assert @gateway.supports_scrubbing? + end + private def error_response @@ -199,7 +195,6 @@ def expected_store_parameters_v6 "expirationdate"=>[expected_expiration_date], "ordernumber"=>["fa73664073e23597bbdd"], "description"=>["Storing Card"], - "testmode"=>["1"], "protocol"=>["6"], "msgtype"=>["subscribe"], "merchant"=>[merchant_id], @@ -216,7 +211,6 @@ def expected_store_parameters_v7 "expirationdate"=>[expected_expiration_date], "ordernumber"=>["ed7546cb4ceb8f017ea4"], "description"=>["Storing Card"], - "testmode"=>["1"], "protocol"=>["7"], "msgtype"=>["subscribe"], "merchant"=>[merchant_id], @@ -231,4 +225,64 @@ def expected_expiration_date def mock_md5_hash "mock_hash" end + + def pre_scrubbed + <<-PRE_SCRUBBED + opening connection to secure.quickpay.dk:443... + opened + starting SSL for secure.quickpay.dk:443... + SSL established + <- "POST /api HTTP/1.1\r\nContent-Type: application/x-www-form-urlencoded\r\nAccept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3\r\nAccept: */*\r\nUser-Agent: Ruby\r\nConnection: close\r\nHost: secure.quickpay.dk\r\nContent-Length: 227\r\n\r\n" + <- "cardnumber=1000000000000008&cvd=111&expirationdate=2402&amount=0¤cy=USD&ordernumber=2019101013403177aa25&description=Longbob+Longsen&protocol=3&msgtype=subscribe&merchant=12345677777&apikey=fB46983ZwRadzy46A3r6ngDx7P37N5YTu1F4S9W2JKCs9v4t5L9m2Q8Mlbjpa2I1&md5check=ea118e189f9dc81d18c1c90f4c29b680" + -> "HTTP/1.1 200 OK\r\n" + -> "Server: nginx\r\n" + -> "Date: Thu, 10 Oct 2019 13:40:33 GMT\r\n" + -> "Content-Type: application/xml; charset=utf-8\r\n" + -> "Transfer-Encoding: chunked\r\n" + -> "Connection: close\r\n" + -> "Strict-Transport-Security: max-age=15768000\r\n" + -> "Strict-Transport-Security: max-age=15768000\r\n" + -> "\r\n" + -> "27e\r\n" + reading 638 bytes... + -> "subscribe2019101013403177aa250USD9000OK20000ApprovedChargify QuickPay Proxydev+quickpay-proxy@chargify.com162719766visa-dkXXXXXXXXXXXX000824021a480503384c5d3103a2081e852a83634" + read 638 bytes + reading 2 bytes... + -> "\r\n" + read 2 bytes + -> "0\r\n" + -> "\r\n" + Conn close + PRE_SCRUBBED + end + + def post_scrubbed + <<-POST_SCRUBBED + opening connection to secure.quickpay.dk:443... + opened + starting SSL for secure.quickpay.dk:443... + SSL established + <- "POST /api HTTP/1.1\r\nContent-Type: application/x-www-form-urlencoded\r\nAccept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3\r\nAccept: */*\r\nUser-Agent: Ruby\r\nConnection: close\r\nHost: secure.quickpay.dk\r\nContent-Length: 227\r\n\r\n" + <- "cardnumber=[FILTERED]&cvd=[FILTERED]&expirationdate=2402&amount=0¤cy=USD&ordernumber=2019101013403177aa25&description=Longbob+Longsen&protocol=3&msgtype=subscribe&merchant=[FILTERED]&apikey=[FILTERED]&md5check=ea118e189f9dc81d18c1c90f4c29b680" + -> "HTTP/1.1 200 OK\r\n" + -> "Server: nginx\r\n" + -> "Date: Thu, 10 Oct 2019 13:40:33 GMT\r\n" + -> "Content-Type: application/xml; charset=utf-8\r\n" + -> "Transfer-Encoding: chunked\r\n" + -> "Connection: close\r\n" + -> "Strict-Transport-Security: max-age=15768000\r\n" + -> "Strict-Transport-Security: max-age=15768000\r\n" + -> "\r\n" + -> "27e\r\n" + reading 638 bytes... + -> "subscribe2019101013403177aa250USD9000OK20000ApprovedChargify QuickPay Proxydev+quickpay-proxy@chargify.com162719766visa-dkXXXXXXXXXXXX000824021a480503384c5d3103a2081e852a83634" + read 638 bytes + reading 2 bytes... + -> "\r\n" + read 2 bytes + -> "0\r\n" + -> "\r\n" + Conn close + POST_SCRUBBED + end end