Skip to content

Commit

Permalink
MIGS: Add unit test for scrub
Browse files Browse the repository at this point in the history
Closes activemerchant#2747

Remote:
12 tests, 38 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed

Unit:
5 tests, 17 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed
  • Loading branch information
curiousepic authored and molejnik-mergebit committed Feb 22, 2018
1 parent 58d0ee6 commit bccf16c
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Expand Up @@ -14,6 +14,7 @@
* WorldPay: Remove Israel from supported country list [dtykocki] #2746
* Optimal Payments: Scrub sensitive data [curiousepic] #2743
* USA Epay Transaction: Scrub sensitive data [curiousepic] #2745
* MIGS: Add unit test for scrub [curiousepic] #2747

== Version 1.77.0 (January 31, 2018)
* Authorize.net: Allow Transaction Id to be passed for refuds [nfarve] #2698
Expand Down
77 changes: 67 additions & 10 deletions test/unit/gateways/migs_test.rb
Expand Up @@ -11,32 +11,32 @@ def setup

@credit_card = credit_card
@amount = 100
@options = {

@options = {
:order_id => '1',
:billing_address => address,
:description => 'Store Purchase'
}
end

def test_successful_purchase
@gateway.expects(:ssl_post).returns(successful_purchase_response)

assert response = @gateway.purchase(@amount, @credit_card, @options)
assert_instance_of Response, response
assert_success response

# Replace with authorization number from the successful response
assert_equal '123456', response.authorization
end

def test_unsuccessful_request
@gateway.expects(:ssl_post).returns(failed_purchase_response)

assert response = @gateway.purchase(@amount, @credit_card, @options)
assert_instance_of Response, response
assert_failure response

assert_equal '654321', response.authorization
end

Expand Down Expand Up @@ -70,25 +70,82 @@ def test_purchase_offsite_response
assert_raise(SecurityError){@gateway.purchase_offsite_response(tampered_response2)}
end

def test_scrub
assert @gateway.supports_scrubbing?
assert_equal @gateway.scrub(pre_scrubbed), post_scrubbed
end

private

# Place raw successful response from gateway here
def successful_purchase_response
build_response(
:TxnResponseCode => '0',
:TransactionNo => '123456'
)
end

# Place raw failed response from gateway here
def failed_purchase_response
build_response(
:TxnResponseCode => '3',
:TransactionNo => '654321'
)
end

def build_response(options)
options.collect { |key, value| "vpc_#{key}=#{CGI.escape(value.to_s)}"}.join('&')
end

def pre_scrubbed
<<-EOS
opening connection to migs.mastercard.com.au:443...
opened
starting SSL for migs.mastercard.com.au:443...
SSL established
<- "POST /vpcdps 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: migs.mastercard.com.au\r\nContent-Length: 354\r\n\r\n"
<- "vpc_Amount=100&vpc_Currency=SAR&vpc_OrderInfo=1&vpc_CardNum=4987654321098769&vpc_CardSecurityCode=123&vpc_CardExp=2105&vpc_Version=1&vpc_Merchant=TESTH-STATION&vpc_AccessCode=F1CE6F32&vpc_Command=pay&vpc_MerchTxnRef=84c1f31ded35dea26ac297fd7ba092da&vpc_SecureHash=CD1B2B8BC325C6C8FC1A041AD6AC90821984277113DF708B16B37809E7B0EC33&vpc_SecureHashType=SHA256"
-> "HTTP/1.1 200 OK\r\n"
-> "Date: Tue, 13 Feb 2018 19:02:18 GMT\r\n"
-> "Expires: Sun, 15 Jul 1990 00:00:00 GMT\r\n"
-> "Pragma: no-cache\r\n"
-> "Cache-Control: no-cache\r\n"
-> "Content-Length: 595\r\n"
-> "P3P: CP=\"NOI DSP COR CURa ADMa TA1a OUR BUS IND UNI COM NAV INT\"\r\n"
-> "Content-Type: text/plain;charset=iso-8859-1\r\n"
-> "Connection: close\r\n"
-> "Set-Cookie: TS01c4b9ca=01fb8d8de2ba6ffaf7439497dd78d9b3348c82bcf24d4619e65a406161e57276b6b293e77732a293be63bf750213e588797bc86f05; Path=/; Secure; HTTPOnly\r\n"
-> "\r\n"
reading 595 bytes...
-> "vpc_AVSResultCode=Unsupported&vpc_AcqAVSRespCode=Unsupported&vpc_AcqCSCRespCode=Unsupported&vpc_AcqResponseCode=00&vpc_Amount=100&vpc_AuthorizeId=239491&vpc_BatchNo=20180214&vpc_CSCResultCode=Unsupported&vpc_Card=VC&vpc_Command=pay&vpc_Currency=SAR&vpc_Locale=en_SA&vpc_MerchTxnRef=84c1f31ded35dea26ac297fd7ba092da&vpc_Merchant=TESTH-STATION&vpc_Message=Approved&vpc_OrderInfo=1&vpc_ReceiptNo=804506239491&vpc_RiskOverallResult=ACC&vpc_SecureHash=99993E000461810D9F71B1A4FC5EA2D68DF6BA1F7EBA6A9FC544DA035627C03C&vpc_SecureHashType=SHA256&vpc_TransactionNo=372&vpc_TxnResponseCode=0&vpc_Version=1"
read 595 bytes
Conn close
EOS
end

def post_scrubbed
<<-EOS
opening connection to migs.mastercard.com.au:443...
opened
starting SSL for migs.mastercard.com.au:443...
SSL established
<- "POST /vpcdps 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: migs.mastercard.com.au\r\nContent-Length: 354\r\n\r\n"
<- "vpc_Amount=100&vpc_Currency=SAR&vpc_OrderInfo=1&vpc_CardNum=[FILTERED]&vpc_CardSecurityCode=[FILTERED]&vpc_CardExp=2105&vpc_Version=1&vpc_Merchant=TESTH-STATION&vpc_AccessCode=[FILTERED]&vpc_Command=pay&vpc_MerchTxnRef=84c1f31ded35dea26ac297fd7ba092da&vpc_SecureHash=CD1B2B8BC325C6C8FC1A041AD6AC90821984277113DF708B16B37809E7B0EC33&vpc_SecureHashType=SHA256"
-> "HTTP/1.1 200 OK\r\n"
-> "Date: Tue, 13 Feb 2018 19:02:18 GMT\r\n"
-> "Expires: Sun, 15 Jul 1990 00:00:00 GMT\r\n"
-> "Pragma: no-cache\r\n"
-> "Cache-Control: no-cache\r\n"
-> "Content-Length: 595\r\n"
-> "P3P: CP=\"NOI DSP COR CURa ADMa TA1a OUR BUS IND UNI COM NAV INT\"\r\n"
-> "Content-Type: text/plain;charset=iso-8859-1\r\n"
-> "Connection: close\r\n"
-> "Set-Cookie: TS01c4b9ca=01fb8d8de2ba6ffaf7439497dd78d9b3348c82bcf24d4619e65a406161e57276b6b293e77732a293be63bf750213e588797bc86f05; Path=/; Secure; HTTPOnly\r\n"
-> "\r\n"
reading 595 bytes...
-> "vpc_AVSResultCode=Unsupported&vpc_AcqAVSRespCode=Unsupported&vpc_AcqCSCRespCode=Unsupported&vpc_AcqResponseCode=00&vpc_Amount=100&vpc_AuthorizeId=239491&vpc_BatchNo=20180214&vpc_CSCResultCode=Unsupported&vpc_Card=VC&vpc_Command=pay&vpc_Currency=SAR&vpc_Locale=en_SA&vpc_MerchTxnRef=84c1f31ded35dea26ac297fd7ba092da&vpc_Merchant=TESTH-STATION&vpc_Message=Approved&vpc_OrderInfo=1&vpc_ReceiptNo=804506239491&vpc_RiskOverallResult=ACC&vpc_SecureHash=99993E000461810D9F71B1A4FC5EA2D68DF6BA1F7EBA6A9FC544DA035627C03C&vpc_SecureHashType=SHA256&vpc_TransactionNo=372&vpc_TxnResponseCode=0&vpc_Version=1"
read 595 bytes
Conn close
EOS
end
end

0 comments on commit bccf16c

Please sign in to comment.