From 717232501a796d4defd5e352b83098a834351072 Mon Sep 17 00:00:00 2001 From: Alma Malambo Date: Tue, 22 Aug 2023 09:57:01 -0500 Subject: [PATCH] Revert "Adding Oauth Response for access tokens" This reverts commit 00fd53ff9b9fb59ec5e0ad244947e93bcfa0ba4a. --- CHANGELOG | 1 - .../billing/gateways/airwallex.rb | 12 +++------ lib/active_merchant/billing/gateways/alelo.rb | 26 +++---------------- .../billing/gateways/checkout_v2.rb | 19 +++----------- .../billing/gateways/pay_trace.rb | 21 +++++---------- .../billing/gateways/quickbooks.rb | 19 ++++---------- .../billing/gateways/simetrik.rb | 18 +++++-------- lib/active_merchant/errors.rb | 6 +---- test/remote/gateways/remote_airwallex_test.rb | 7 ----- test/remote/gateways/remote_alelo_test.rb | 10 +++---- .../gateways/remote_checkout_v2_test.rb | 16 ------------ test/remote/gateways/remote_pay_trace_test.rb | 17 ------------ .../remote/gateways/remote_quickbooks_test.rb | 17 ------------ test/remote/gateways/remote_simetrik_test.rb | 16 ------------ test/unit/gateways/airwallex_test.rb | 21 ++++++++------- test/unit/gateways/alelo_test.rb | 9 ------- test/unit/gateways/checkout_v2_test.rb | 22 ++++++++-------- test/unit/gateways/pay_trace_test.rb | 25 ++++++++---------- test/unit/gateways/quickbooks_test.rb | 9 ------- test/unit/gateways/simetrik_test.rb | 22 ++++++++-------- 20 files changed, 77 insertions(+), 236 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index e47c57f8496..bbbc58ec63e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -20,7 +20,6 @@ * IPG: Change credentials inputs to use a combined store and user ID string as the user ID input [kylene-spreedly] #4854 * Braintree Blue: Update the credit card details transaction hash [yunnydang] #4865 * VisaNet Peru: Update generate_purchase_number_stamp [almalee24] #4855 -* Adding Oauth Response for access tokens [almalee24] #4851 == Version 1.134.0 (July 25, 2023) * Update required Ruby version [almalee24] #4823 diff --git a/lib/active_merchant/billing/gateways/airwallex.rb b/lib/active_merchant/billing/gateways/airwallex.rb index d9faced5ac2..fd1e06f427d 100644 --- a/lib/active_merchant/billing/gateways/airwallex.rb +++ b/lib/active_merchant/billing/gateways/airwallex.rb @@ -32,7 +32,7 @@ def initialize(options = {}) @client_id = options[:client_id] @client_api_key = options[:client_api_key] super - @access_token = options[:access_token] || setup_access_token + @access_token = setup_access_token end def purchase(money, card, options = {}) @@ -133,14 +133,8 @@ def setup_access_token 'x-client-id' => @client_id, 'x-api-key' => @client_api_key } - raw_response = ssl_post(build_request_url(:login), nil, token_headers) - response = JSON.parse(raw_response) - if (token = response['token']) - token - else - oauth_response = Response.new(false, response['message']) - raise OAuthResponseError.new(oauth_response) - end + response = ssl_post(build_request_url(:login), nil, token_headers) + JSON.parse(response)['token'] end def build_request_url(action, id = nil) diff --git a/lib/active_merchant/billing/gateways/alelo.rb b/lib/active_merchant/billing/gateways/alelo.rb index 381b5859372..fd1cfc11a5f 100644 --- a/lib/active_merchant/billing/gateways/alelo.rb +++ b/lib/active_merchant/billing/gateways/alelo.rb @@ -110,18 +110,8 @@ def fetch_access_token 'Content-Type' => 'application/x-www-form-urlencoded' } - begin - raw_response = ssl_post(url('captura-oauth-provider/oauth/token'), post_data(params), headers) - rescue ResponseError => e - raise OAuthResponseError.new(e) - else - response = parse(raw_response) - if (access_token = response[:access_token]) - Response.new(true, access_token, response) - else - raise OAuthResponseError.new(response) - end - end + parsed = parse(ssl_post(url('captura-oauth-provider/oauth/token'), post_data(params), headers)) + Response.new(true, parsed[:access_token], parsed) end def remote_encryption_key(access_token) @@ -154,11 +144,9 @@ def ensure_credentials(try_again = true) access_token: access_token, multiresp: multiresp.responses.present? ? multiresp : nil } - rescue ActiveMerchant::OAuthResponseError => e - raise e rescue ResponseError => e # retry to generate a new access_token when the provided one is expired - raise e unless retry?(try_again, e, :access_token) + raise e unless try_again && %w(401 404).include?(e.response.code) && @options[:access_token].present? @options.delete(:access_token) @options.delete(:encryption_key) @@ -218,11 +206,9 @@ def commit(action, body, options, try_again = true) multiresp.process { resp } multiresp - rescue ActiveMerchant::OAuthResponseError => e - raise OAuthResponseError.new(e) rescue ActiveMerchant::ResponseError => e # Retry on a possible expired encryption key - if retry?(try_again, e, :encryption_key) + if try_again && %w(401 404).include?(e.response.code) && @options[:encryption_key].present? @options.delete(:encryption_key) commit(action, body, options, false) else @@ -231,10 +217,6 @@ def commit(action, body, options, try_again = true) end end - def retry?(try_again, error, key) - try_again && %w(401 404).include?(error.response.code) && @options[key].present? - end - def success_from(action, response) case action when 'capture/transaction/refund' diff --git a/lib/active_merchant/billing/gateways/checkout_v2.rb b/lib/active_merchant/billing/gateways/checkout_v2.rb index 4634966eda6..13f6f7e757f 100644 --- a/lib/active_merchant/billing/gateways/checkout_v2.rb +++ b/lib/active_merchant/billing/gateways/checkout_v2.rb @@ -18,13 +18,13 @@ class CheckoutV2Gateway < Gateway def initialize(options = {}) @options = options - @access_token = options[:access_token] || nil + @access_token = nil if options.has_key?(:secret_key) requires!(options, :secret_key) else requires!(options, :client_id, :client_secret) - @access_token ||= setup_access_token + @access_token = setup_access_token end super @@ -341,19 +341,8 @@ def access_token_url def setup_access_token request = 'grant_type=client_credentials' - begin - raw_response = ssl_post(access_token_url, request, access_token_header) - rescue ResponseError => e - raise OAuthResponseError.new(e) - else - response = parse(raw_response) - - if (access_token = response['access_token']) - access_token - else - raise OAuthResponseError.new(response) - end - end + response = parse(ssl_post(access_token_url, request, access_token_header)) + response['access_token'] end def commit(action, post, options, authorization = nil, method = :post) diff --git a/lib/active_merchant/billing/gateways/pay_trace.rb b/lib/active_merchant/billing/gateways/pay_trace.rb index 8c338687df1..53203d51f96 100644 --- a/lib/active_merchant/billing/gateways/pay_trace.rb +++ b/lib/active_merchant/billing/gateways/pay_trace.rb @@ -46,7 +46,7 @@ class PayTraceGateway < Gateway def initialize(options = {}) requires!(options, :username, :password, :integrator_id) super - acquire_access_token unless options[:access_token] + acquire_access_token end def purchase(money, payment_or_customer_id, options = {}) @@ -187,15 +187,10 @@ def acquire_access_token 'Content-Type' => 'application/x-www-form-urlencoded' } response = ssl_post(url, data, oauth_headers) - json_response = parse(response) + json_response = JSON.parse(response) - if json_response.include?('error') - oauth_response = Response.new(false, json_response['error_description']) - raise OAuthResponseError.new(oauth_response) - else - @options[:access_token] = json_response['access_token'] if json_response['access_token'] - response - end + @options[:access_token] = json_response['access_token'] if json_response['access_token'] + response end private @@ -378,12 +373,6 @@ def commit(action, parameters) url = base_url + '/v1/' + action raw_response = ssl_post(url, post_data(parameters), headers) response = parse(raw_response) - handle_final_response(action, response) - rescue JSON::ParserError - unparsable_response(raw_response) - end - - def handle_final_response(action, response) success = success_from(response) Response.new( @@ -396,6 +385,8 @@ def handle_final_response(action, response) test: test?, error_code: success ? nil : error_code_from(response) ) + rescue JSON::ParserError + unparsable_response(raw_response) end def unparsable_response(raw_response) diff --git a/lib/active_merchant/billing/gateways/quickbooks.rb b/lib/active_merchant/billing/gateways/quickbooks.rb index 6197581bbe7..6d9f14f3445 100644 --- a/lib/active_merchant/billing/gateways/quickbooks.rb +++ b/lib/active_merchant/billing/gateways/quickbooks.rb @@ -305,17 +305,12 @@ def refresh_access_token 'Authorization' => "Basic #{basic_auth}" } - begin - response = ssl_post(REFRESH_URI, data, headers) - rescue ResponseError => e - raise OAuthResponseError.new(e) - else - json_response = JSON.parse(response) + response = ssl_post(REFRESH_URI, data, headers) + json_response = JSON.parse(response) - @options[:access_token] = json_response['access_token'] if json_response['access_token'] - @options[:refresh_token] = json_response['refresh_token'] if json_response['refresh_token'] - response - end + @options[:access_token] = json_response['access_token'] if json_response['access_token'] + @options[:refresh_token] = json_response['refresh_token'] if json_response['refresh_token'] + response end def cvv_code_from(response) @@ -363,10 +358,6 @@ def extract_response_body_or_raise(response_error) rescue JSON::ParserError raise response_error end - - error_code = JSON.parse(response_error.response.body)['code'] - raise OAuthResponseError.new(response_error, error_code) if error_code == 'AuthenticationFailed' - response_error.response.body end diff --git a/lib/active_merchant/billing/gateways/simetrik.rb b/lib/active_merchant/billing/gateways/simetrik.rb index f3b0863eef8..5c436acab95 100644 --- a/lib/active_merchant/billing/gateways/simetrik.rb +++ b/lib/active_merchant/billing/gateways/simetrik.rb @@ -44,7 +44,7 @@ class SimetrikGateway < Gateway def initialize(options = {}) requires!(options, :client_id, :client_secret) super - @access_token = options[:access_token] || {} + @access_token = {} sign_access_token() end @@ -356,18 +356,12 @@ def fetch_access_token login_info[:client_secret] = @options[:client_secret] login_info[:audience] = test? ? test_audience : live_audience login_info[:grant_type] = 'client_credentials' + response = parse(ssl_post(auth_url(), login_info.to_json, { + 'content-Type' => 'application/json' + })) - begin - raw_response = ssl_post(auth_url(), login_info.to_json, { - 'content-Type' => 'application/json' - }) - rescue ResponseError => e - raise OAuthResponseError.new(e) - else - response = parse(raw_response) - @access_token[:access_token] = response['access_token'] - @access_token[:expires_at] = Time.new.to_i + response['expires_in'] - end + @access_token[:access_token] = response['access_token'] + @access_token[:expires_at] = Time.new.to_i + response['expires_in'] end end end diff --git a/lib/active_merchant/errors.rb b/lib/active_merchant/errors.rb index 882095d0358..b017c45114a 100644 --- a/lib/active_merchant/errors.rb +++ b/lib/active_merchant/errors.rb @@ -23,11 +23,7 @@ def initialize(response, message = nil) end def to_s - if response&.message&.start_with?('Failed with') - response.message - else - "Failed with #{response.code if response.respond_to?(:code)} #{response.message if response.respond_to?(:message)}" - end + "Failed with #{response.code if response.respond_to?(:code)} #{response.message if response.respond_to?(:message)}" end end diff --git a/test/remote/gateways/remote_airwallex_test.rb b/test/remote/gateways/remote_airwallex_test.rb index 24aa9fe3b61..5cbc4053c7d 100644 --- a/test/remote/gateways/remote_airwallex_test.rb +++ b/test/remote/gateways/remote_airwallex_test.rb @@ -14,13 +14,6 @@ def setup @stored_credential_mit_options = { initial_transaction: false, initiator: 'merchant', reason_type: 'recurring' } end - def test_failed_access_token - assert_raises(ActiveMerchant::OAuthResponseError) do - gateway = AirwallexGateway.new({ client_id: 'YOUR_CLIENT_ID', client_api_key: 'YOUR_API_KEY' }) - gateway.send :setup_access_token - end - end - def test_successful_purchase response = @gateway.purchase(@amount, @credit_card, @options) assert_success response diff --git a/test/remote/gateways/remote_alelo_test.rb b/test/remote/gateways/remote_alelo_test.rb index 8a4fef24e7b..be4d9ae9059 100644 --- a/test/remote/gateways/remote_alelo_test.rb +++ b/test/remote/gateways/remote_alelo_test.rb @@ -26,7 +26,7 @@ def test_access_token_success end def test_failure_access_token_with_invalid_keys - error = assert_raises(ActiveMerchant::OAuthResponseError) do + error = assert_raises(ActiveMerchant::ResponseError) do gateway = AleloGateway.new({ client_id: 'abc123', client_secret: 'abc456' }) gateway.send :fetch_access_token end @@ -145,11 +145,9 @@ def test_successful_purchase_with_geolocalitation def test_invalid_login gateway = AleloGateway.new(client_id: 'asdfghj', client_secret: '1234rtytre') - error = assert_raises(ActiveMerchant::OAuthResponseError) do - gateway.purchase(@amount, @credit_card, @options) - end - - assert_match(/401/, error.message) + response = gateway.purchase(@amount, @credit_card, @options) + assert_failure response + assert_match %r{invalid_client}, response.message end def test_transcript_scrubbing diff --git a/test/remote/gateways/remote_checkout_v2_test.rb b/test/remote/gateways/remote_checkout_v2_test.rb index 9ca1b89629d..e8b1d0c1e90 100644 --- a/test/remote/gateways/remote_checkout_v2_test.rb +++ b/test/remote/gateways/remote_checkout_v2_test.rb @@ -118,22 +118,6 @@ def setup ) end - def test_failed_access_token - assert_raises(ActiveMerchant::OAuthResponseError) do - gateway = CheckoutV2Gateway.new({ client_id: 'YOUR_CLIENT_ID', client_secret: 'YOUR_CLIENT_SECRET' }) - gateway.send :setup_access_token - end - end - - def test_failed_purchase_with_failed_access_token - error = assert_raises(ActiveMerchant::OAuthResponseError) do - gateway = CheckoutV2Gateway.new({ client_id: 'YOUR_CLIENT_ID', client_secret: 'YOUR_CLIENT_SECRET' }) - gateway.purchase(@amount, @credit_card, @options) - end - - assert_equal error.message, 'Failed with 400 Bad Request' - end - def test_transcript_scrubbing declined_card = credit_card('4000300011112220', verification_value: '423') transcript = capture_transcript(@gateway) do diff --git a/test/remote/gateways/remote_pay_trace_test.rb b/test/remote/gateways/remote_pay_trace_test.rb index 6c56f840353..b10e5119e3a 100644 --- a/test/remote/gateways/remote_pay_trace_test.rb +++ b/test/remote/gateways/remote_pay_trace_test.rb @@ -39,23 +39,6 @@ def test_acquire_token assert_not_nil response['access_token'] end - def test_failed_access_token - assert_raises(ActiveMerchant::OAuthResponseError) do - gateway = PayTraceGateway.new(username: 'username', password: 'password', integrator_id: 'uniqueintegrator') - gateway.send :acquire_access_token - end - end - - def test_failed_purchase_with_failed_access_token - gateway = PayTraceGateway.new(username: 'username', password: 'password', integrator_id: 'uniqueintegrator') - - error = assert_raises(ActiveMerchant::OAuthResponseError) do - gateway.purchase(1000, @credit_card, @options) - end - - assert_equal error.message, 'Failed with The provided authorization grant is invalid, expired, revoked, does not match the redirection URI used in the authorization request, or was issued to another client.' - end - def test_successful_purchase response = @gateway.purchase(1000, @credit_card, @options) assert_success response diff --git a/test/remote/gateways/remote_quickbooks_test.rb b/test/remote/gateways/remote_quickbooks_test.rb index 6b295967b22..f3457706af5 100644 --- a/test/remote/gateways/remote_quickbooks_test.rb +++ b/test/remote/gateways/remote_quickbooks_test.rb @@ -18,23 +18,6 @@ def setup } end - def test_failed_access_token - assert_raises(ActiveMerchant::OAuthResponseError) do - gateway = QuickbooksGateway.new({ client_id: 'YOUR_CLIENT_ID', client_secret: 'YOUR_CLIENT_SECRET', refresh_token: 'YOUR_REFRESH_TOKEN', access_token: 'YOUR_ACCESS_TOKEN' }) - gateway.send :refresh_access_token - end - end - - def test_failed_purchase_with_failed_access_token - gateway = QuickbooksGateway.new({ client_id: 'YOUR_CLIENT_ID', client_secret: 'YOUR_CLIENT_SECRET', refresh_token: 'YOUR_REFRESH_TOKEN', access_token: 'YOUR_ACCESS_TOKEN' }) - - error = assert_raises(ActiveMerchant::OAuthResponseError) do - gateway.purchase(@amount, @credit_card, @options) - end - - assert_equal error.message, 'Failed with 401 Unauthorized' - end - def test_successful_purchase response = @gateway.purchase(@amount, @credit_card, @options) assert_success response diff --git a/test/remote/gateways/remote_simetrik_test.rb b/test/remote/gateways/remote_simetrik_test.rb index 90f66e2f844..b1e2eb24daf 100644 --- a/test/remote/gateways/remote_simetrik_test.rb +++ b/test/remote/gateways/remote_simetrik_test.rb @@ -78,22 +78,6 @@ def setup } end - def test_failed_access_token - assert_raises(ActiveMerchant::OAuthResponseError) do - gateway = SimetrikGateway.new({ client_id: 'YOUR_CLIENT_ID', client_secret: 'YOUR_API_KEY', audience: 'audience_url' }) - gateway.send :fetch_access_token - end - end - - def test_failed_authorize_with_failed_access_token - error = assert_raises(ActiveMerchant::OAuthResponseError) do - gateway = SimetrikGateway.new({ client_id: 'YOUR_CLIENT_ID', client_secret: 'YOUR_API_KEY', audience: 'audience_url' }) - gateway.authorize(@amount, @credit_card, @authorize_options_success) - end - - assert_equal error.message, 'Failed with 401 Unauthorized' - end - def test_success_authorize response = @gateway.authorize(@amount, @credit_card, @authorize_options_success) assert_success response diff --git a/test/unit/gateways/airwallex_test.rb b/test/unit/gateways/airwallex_test.rb index 9d707bcba1c..ade541ce88e 100644 --- a/test/unit/gateways/airwallex_test.rb +++ b/test/unit/gateways/airwallex_test.rb @@ -1,10 +1,20 @@ require 'test_helper' +module ActiveMerchant #:nodoc: + module Billing #:nodoc: + class AirwallexGateway + def setup_access_token + '12345678' + end + end + end +end + class AirwallexTest < Test::Unit::TestCase include CommStub def setup - @gateway = AirwallexGateway.new(client_id: 'login', client_api_key: 'password', access_token: '12345678') + @gateway = AirwallexGateway.new(client_id: 'login', client_api_key: 'password') @credit_card = credit_card @declined_card = credit_card('2223 0000 1018 1375') @amount = 100 @@ -18,15 +28,6 @@ def setup @stored_credential_mit_options = { initial_transaction: false, initiator: 'merchant', reason_type: 'recurring' } end - def test_setup_access_token_should_rise_an_exception_under_unauthorized - error = assert_raises(ActiveMerchant::OAuthResponseError) do - @gateway.expects(:ssl_post).returns({ code: 'invalid_argument', message: "Failed to convert 'YOUR_CLIENT_ID' to UUID", source: '' }.to_json) - @gateway.send(:setup_access_token) - end - - assert_match(/Failed with Failed to convert 'YOUR_CLIENT_ID' to UUID/, error.message) - end - def test_gateway_has_access_token assert @gateway.instance_variable_defined?(:@access_token) end diff --git a/test/unit/gateways/alelo_test.rb b/test/unit/gateways/alelo_test.rb index 86e35e917f3..3e6c9f0c1c9 100644 --- a/test/unit/gateways/alelo_test.rb +++ b/test/unit/gateways/alelo_test.rb @@ -19,15 +19,6 @@ def setup } end - def test_fetch_access_token_should_rise_an_exception_under_unauthorized - error = assert_raises(ActiveMerchant::OAuthResponseError) do - @gateway .expects(:raw_ssl_request).returns(Net::HTTPBadRequest.new(1.0, 401, 'Unauthorized')) - @gateway .send(:fetch_access_token) - end - - assert_match(/Failed with 401 Unauthorized/, error.message) - end - def test_required_client_id_and_client_secret error = assert_raises ArgumentError do AleloGateway.new diff --git a/test/unit/gateways/checkout_v2_test.rb b/test/unit/gateways/checkout_v2_test.rb index 8b74716e1be..7256db54e3f 100644 --- a/test/unit/gateways/checkout_v2_test.rb +++ b/test/unit/gateways/checkout_v2_test.rb @@ -1,5 +1,15 @@ require 'test_helper' +module ActiveMerchant #:nodoc: + module Billing #:nodoc: + class CheckoutV2Gateway + def setup_access_token + '12345678' + end + end + end +end + class CheckoutV2Test < Test::Unit::TestCase include CommStub @@ -7,7 +17,7 @@ def setup @gateway = CheckoutV2Gateway.new( secret_key: '1111111111111' ) - @gateway_oauth = CheckoutV2Gateway.new({ client_id: 'abcd', client_secret: '1234', access_token: '12345678' }) + @gateway_oauth = CheckoutV2Gateway.new({ client_id: 'abcd', client_secret: '1234' }) @gateway_api = CheckoutV2Gateway.new({ secret_key: '1111111111111', public_key: '2222222222222' @@ -17,15 +27,6 @@ def setup @token = '2MPedsuenG2o8yFfrsdOBWmOuEf' end - def test_setup_access_token_should_rise_an_exception_under_bad_request - error = assert_raises(ActiveMerchant::OAuthResponseError) do - @gateway.expects(:raw_ssl_request).returns(Net::HTTPBadRequest.new(1.0, 400, 'Bad Request')) - @gateway.send(:setup_access_token) - end - - assert_match(/Failed with 400 Bad Request/, error.message) - end - def test_successful_purchase response = stub_comms(@gateway, :ssl_request) do @gateway.purchase(@amount, @credit_card) @@ -258,7 +259,6 @@ def test_successful_purchase_using_google_pay_pan_only_network_token def test_successful_render_for_oauth processing_channel_id = 'abcd123' - response = stub_comms(@gateway_oauth, :ssl_request) do @gateway_oauth.purchase(@amount, @credit_card, { processing_channel_id: processing_channel_id }) end.check_request do |_method, _endpoint, data, headers| diff --git a/test/unit/gateways/pay_trace_test.rb b/test/unit/gateways/pay_trace_test.rb index 42be462bbf0..09f13807e83 100644 --- a/test/unit/gateways/pay_trace_test.rb +++ b/test/unit/gateways/pay_trace_test.rb @@ -1,10 +1,20 @@ require 'test_helper' +module ActiveMerchant #:nodoc: + module Billing #:nodoc: + class PayTraceGateway < Gateway + def acquire_access_token + @options[:access_token] = SecureRandom.hex(16) + end + end + end +end + class PayTraceTest < Test::Unit::TestCase include CommStub def setup - @gateway = PayTraceGateway.new(username: 'username', password: 'password', integrator_id: 'uniqueintegrator', access_token: SecureRandom.hex(16)) + @gateway = PayTraceGateway.new(username: 'username', password: 'password', integrator_id: 'uniqueintegrator') @credit_card = credit_card @echeck = check(account_number: '123456', routing_number: '325070760') @amount = 100 @@ -14,19 +24,6 @@ def setup } end - def test_setup_access_token_should_rise_an_exception_under_bad_request - error = assert_raises(ActiveMerchant::OAuthResponseError) do - access_token_response = { - error: 'invalid_grant', - error_description: 'The provided authorization grant is invalid, expired, revoked, does not match the redirection URI used in the authorization request, or was issued to another client.' - }.to_json - @gateway.expects(:ssl_post).returns(access_token_response) - @gateway.send(:acquire_access_token) - end - - assert_match(/Failed with The provided authorization grant is invalid/, error.message) - end - def test_successful_purchase @gateway.expects(:ssl_post).returns(successful_purchase_response) diff --git a/test/unit/gateways/quickbooks_test.rb b/test/unit/gateways/quickbooks_test.rb index 9b7a6f94a5b..7e48cce44ef 100644 --- a/test/unit/gateways/quickbooks_test.rb +++ b/test/unit/gateways/quickbooks_test.rb @@ -32,15 +32,6 @@ def setup @authorization_no_request_id = 'ECZ7U0SO423E' end - def test_refresh_access_token_should_rise_an_exception_under_unauthorized - error = assert_raises(ActiveMerchant::OAuthResponseError) do - @oauth_2_gateway .expects(:raw_ssl_request).returns(Net::HTTPBadRequest.new(1.0, 401, 'Unauthorized')) - @oauth_2_gateway .send(:refresh_access_token) - end - - assert_match(/Failed with 401 Unauthorized/, error.message) - end - def test_successful_purchase [@oauth_1_gateway, @oauth_2_gateway].each do |gateway| gateway.expects(:ssl_post).returns(successful_purchase_response) diff --git a/test/unit/gateways/simetrik_test.rb b/test/unit/gateways/simetrik_test.rb index f47a31203a9..c120b2e99fe 100644 --- a/test/unit/gateways/simetrik_test.rb +++ b/test/unit/gateways/simetrik_test.rb @@ -1,5 +1,15 @@ require 'test_helper' +module ActiveMerchant #:nodoc: + module Billing #:nodoc: + class SimetrikGateway < Gateway + def fetch_access_token + @access_token[:access_token] = SecureRandom.hex(16) + end + end + end +end + class SimetrikTest < Test::Unit::TestCase def setup @token_acquirer = 'ea890fd1-49f3-4a34-a150-192bf9a59205' @@ -7,8 +17,7 @@ def setup @gateway = SimetrikGateway.new( client_id: 'client_id', client_secret: 'client_secret_key', - audience: 'audience_url', - access_token: { expires_at: Time.new.to_i } + audience: 'audience_url' ) @credit_card = CreditCard.new( first_name: 'sergiod', @@ -161,15 +170,6 @@ def test_success_purchase_with_billing_address assert response.test? end - def test_fetch_access_token_should_rise_an_exception_under_bad_request - error = assert_raises(ActiveMerchant::OAuthResponseError) do - @gateway.expects(:raw_ssl_request).returns(Net::HTTPBadRequest.new(1.0, 401, 'Unauthorized')) - @gateway.send(:fetch_access_token) - end - - assert_match(/Failed with 401 Unauthorized/, error.message) - end - def test_success_purchase_with_shipping_address expected_body = JSON.parse(@authorize_capture_expected_body.dup) expected_body['forward_payload']['order']['shipping_address'] = address