From 16f534ed025d712bfee96c74842ecbc2cdf301c8 Mon Sep 17 00:00:00 2001 From: John Maxwell Date: Thu, 16 Feb 2023 15:02:07 -0500 Subject: [PATCH 01/13] Spec cleanup --- .../aamva/verification_client_spec.rb | 57 ++++++++++--------- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/spec/services/proofing/aamva/verification_client_spec.rb b/spec/services/proofing/aamva/verification_client_spec.rb index 46348a8a73e..85cce3505e4 100644 --- a/spec/services/proofing/aamva/verification_client_spec.rb +++ b/spec/services/proofing/aamva/verification_client_spec.rb @@ -19,11 +19,13 @@ subject(:verification_client) { described_class.new(AamvaFixtures.example_config) } describe '#send_verification_request' do - it 'should get the auth token from the auth client' do + before do auth_client = instance_double(Proofing::Aamva::AuthenticationClient) allow(auth_client).to receive(:fetch_token).and_return('ThisIsTheToken') allow(Proofing::Aamva::AuthenticationClient).to receive(:new).and_return(auth_client) + end + it 'gets the auth token from the auth client' do verification_stub = stub_request(:post, AamvaFixtures.example_config.verification_url). to_return(body: AamvaFixtures.verification_response, status: 200). with do |request| @@ -37,43 +39,44 @@ expect(verification_stub).to have_been_requested end + end - context 'when verification is successful' do - it 'should return a successful response' do - auth_client = instance_double(Proofing::Aamva::AuthenticationClient) - allow(auth_client).to receive(:fetch_token).and_return('ThisIsTheToken') - allow(Proofing::Aamva::AuthenticationClient).to receive(:new).and_return(auth_client) - stub_request(:post, AamvaFixtures.example_config.verification_url). - to_return(body: AamvaFixtures.verification_response, status: 200) + describe '#send_verification_request' do + let(:response_body) { AamvaFixtures.verification_response } - response = verification_client.send_verification_request( - applicant: applicant, - session_id: '1234-abcd-efgh', - ) + before do + auth_client = instance_double(Proofing::Aamva::AuthenticationClient) + allow(auth_client).to receive(:fetch_token).and_return('ThisIsTheToken') + allow(Proofing::Aamva::AuthenticationClient).to receive(:new).and_return(auth_client) + + stub_request(:post, AamvaFixtures.example_config.verification_url). + to_return(body: response_body, status: 200) + end + let(:response) do + verification_client.send_verification_request( + applicant: applicant, + session_id: '1234-abcd-efgh', + ) + end + + context 'when verification is successful' do + it 'returns a successful response' do expect(response).to be_a Proofing::Aamva::Response::VerificationResponse expect(response.success?).to eq(true) end end context 'when verification is not successful' do - it 'should return an unsuccessful response with errors' do - auth_client = instance_double(Proofing::Aamva::AuthenticationClient) - allow(auth_client).to receive(:fetch_token).and_return('ThisIsTheToken') - allow(Proofing::Aamva::AuthenticationClient).to receive(:new).and_return(auth_client) - - stub_request(:post, AamvaFixtures.example_config.verification_url). - to_return(status: 200, body: modify_xml_at_xpath( - AamvaFixtures.verification_response, - '//PersonBirthDateMatchIndicator', - 'false', - )) - - response = verification_client.send_verification_request( - applicant: applicant, - session_id: '1234-abcd-efgh', + let(:response_body) do + modify_xml_at_xpath( + AamvaFixtures.verification_response, + '//PersonBirthDateMatchIndicator', + 'false', ) + end + it 'returns an unsuccessful response with errors' do expect(response).to be_a Proofing::Aamva::Response::VerificationResponse expect(response.success?).to eq(false) end From a60662a4d096e7ed25b97eb154a2e938881c24a0 Mon Sep 17 00:00:00 2001 From: John Maxwell Date: Wed, 22 Feb 2023 12:36:28 -0500 Subject: [PATCH 02/13] Specs to ensure we attempt XML parsing for non-200 HTTP statuses. --- .../aamva/response/verification_response.rb | 23 ++++--- .../aamva/verification_client_spec.rb | 63 ++++++++++++++++--- 2 files changed, 67 insertions(+), 19 deletions(-) diff --git a/app/services/proofing/aamva/response/verification_response.rb b/app/services/proofing/aamva/response/verification_response.rb index a5784fcd868..87efaea6e7f 100644 --- a/app/services/proofing/aamva/response/verification_response.rb +++ b/app/services/proofing/aamva/response/verification_response.rb @@ -33,9 +33,13 @@ def initialize(http_response) @missing_attributes = [] @verification_results = {} @http_response = http_response - handle_http_error - handle_soap_error - parse_response + http_error = handle_http_error + soap_error = handle_soap_error + begin + parse_response + end + + raise soap_error if soap_error end def reasons @@ -63,8 +67,8 @@ def success? def handle_http_error status = http_response.status - return if status == 200 - raise VerificationError, "Unexpected status code in response: #{status}" + return nil if status == 200 + return VerificationError.new("Unexpected status code in response: #{status}") end def handle_missing_attribute(attribute_name) @@ -74,11 +78,11 @@ def handle_missing_attribute(attribute_name) def handle_soap_error error_handler = SoapErrorHandler.new(http_response) - return unless error_handler.error_present? + return nil unless error_handler.error_present? msg = error_handler.error_message - raise ::Proofing::TimeoutError, msg if mva_timeout?(msg) - raise VerificationError, msg + return ::Proofing::TimeoutError.new(msg) if mva_timeout?(msg) + return VerificationError.new(msg) end def node_for_match_indicator(match_indicator_name) @@ -104,7 +108,8 @@ def parse_response end def rexml_document - @rexml_document ||= REXML::Document.new(http_response.body) + return @rexml_document if @rexml_document + @rexml_document = REXML::Document.new(http_response.body) end def mva_timeout?(error_message) diff --git a/spec/services/proofing/aamva/verification_client_spec.rb b/spec/services/proofing/aamva/verification_client_spec.rb index 85cce3505e4..717c1f826b7 100644 --- a/spec/services/proofing/aamva/verification_client_spec.rb +++ b/spec/services/proofing/aamva/verification_client_spec.rb @@ -43,6 +43,7 @@ describe '#send_verification_request' do let(:response_body) { AamvaFixtures.verification_response } + let(:response_http_status) { 200 } before do auth_client = instance_double(Proofing::Aamva::AuthenticationClient) @@ -50,7 +51,7 @@ allow(Proofing::Aamva::AuthenticationClient).to receive(:new).and_return(auth_client) stub_request(:post, AamvaFixtures.example_config.verification_url). - to_return(body: response_body, status: 200) + to_return(body: response_body, status: response_http_status) end let(:response) do @@ -68,17 +69,59 @@ end context 'when verification is not successful' do - let(:response_body) do - modify_xml_at_xpath( - AamvaFixtures.verification_response, - '//PersonBirthDateMatchIndicator', - 'false', - ) + before { allow(REXML::Document).to receive(:new).and_call_original } + + context 'because we have a valid response and a 200 status, but the response says "no"' do + let(:response_body) do + modify_xml_at_xpath( + AamvaFixtures.verification_response, + '//PersonBirthDateMatchIndicator', + 'false', + ) + end + + it 'returns an unsuccessful response with errors' do + expect(response).to be_a Proofing::Aamva::Response::VerificationResponse + expect(response.success?).to eq(false) + end end - it 'returns an unsuccessful response with errors' do - expect(response).to be_a Proofing::Aamva::Response::VerificationResponse - expect(response.success?).to eq(false) + context 'because we have a valid response and a non-200 status, and the response says "no"' do + let(:response_body) do + modify_xml_at_xpath( + AamvaFixtures.verification_response, + '//PersonBirthDateMatchIndicator', + 'false', + ) + end + let(:response_http_status) { 500 } + + it 'parses the raw response body and returns an unsuccessful response with errors' do + expect(response).to be_a Proofing::Aamva::Response::VerificationResponse + expect(response.success?).to eq(false) + expect(REXML::Document).to have_received(:new).with(response_body).at_least(:once) + end + end + + context 'because we have an invalid response and a 200 status' do + let(:response_body) { '

error: computer has no brain.

' } + + it 'parses the raw response body and returns an unsuccessful response with errors' do + expect(response).to be_a Proofing::Aamva::Response::VerificationResponse + expect(response.success?).to eq(false) + expect(REXML::Document).to have_received(:new).with(response_body).at_least(:once) + end + end + + context 'because we have an invalid response and a non-200 status' do + let(:response_body) { '

I\'m a teapot

' } + let(:response_http_status) { 418 } + + it 'parses the raw response body and returns an unsuccessful response with errors' do + expect(response).to be_a Proofing::Aamva::Response::VerificationResponse + expect(response.success?).to eq(false) + expect(REXML::Document).to have_received(:new).with(response_body).at_least(:once) + end end end end From 1368401be015e4c144699b942048bfb81c37ea19 Mon Sep 17 00:00:00 2001 From: John Maxwell Date: Wed, 22 Feb 2023 15:49:43 -0500 Subject: [PATCH 03/13] Code cleanup [skip changelog] --- .../proofing/aamva/response/verification_response.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/services/proofing/aamva/response/verification_response.rb b/app/services/proofing/aamva/response/verification_response.rb index 87efaea6e7f..b4fd8a092ba 100644 --- a/app/services/proofing/aamva/response/verification_response.rb +++ b/app/services/proofing/aamva/response/verification_response.rb @@ -35,10 +35,9 @@ def initialize(http_response) @http_response = http_response http_error = handle_http_error soap_error = handle_soap_error - begin - parse_response - end + parse_response + raise http_error if http_error raise soap_error if soap_error end From 5bf80bdfcaf2de5947fec2c054bc16461b7fa093 Mon Sep 17 00:00:00 2001 From: John Maxwell Date: Fri, 24 Feb 2023 11:39:33 -0500 Subject: [PATCH 04/13] Specs for thrown errors. --- .../aamva/response/verification_response.rb | 10 +++++-- .../proofing/aamva/soap_error_handler.rb | 3 +++ .../aamva/verification_client_spec.rb | 26 ++++++++++++------- 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/app/services/proofing/aamva/response/verification_response.rb b/app/services/proofing/aamva/response/verification_response.rb index b4fd8a092ba..5d2fc22ca42 100644 --- a/app/services/proofing/aamva/response/verification_response.rb +++ b/app/services/proofing/aamva/response/verification_response.rb @@ -33,12 +33,14 @@ def initialize(http_response) @missing_attributes = [] @verification_results = {} @http_response = http_response + http_error = handle_http_error soap_error = handle_soap_error + parse_response - raise http_error if http_error raise soap_error if soap_error + raise http_error if http_error end def reasons @@ -85,7 +87,11 @@ def handle_soap_error end def node_for_match_indicator(match_indicator_name) - REXML::XPath.first(rexml_document, "//#{match_indicator_name}") + begin + REXML::XPath.first(rexml_document, "//#{match_indicator_name}") + rescue REXML::ParseException + nil + end end def parse_response diff --git a/app/services/proofing/aamva/soap_error_handler.rb b/app/services/proofing/aamva/soap_error_handler.rb index e498bf0be24..b8bbaf704f2 100644 --- a/app/services/proofing/aamva/soap_error_handler.rb +++ b/app/services/proofing/aamva/soap_error_handler.rb @@ -9,6 +9,9 @@ class SoapErrorHandler def initialize(http_response) @document = REXML::Document.new(http_response.body) parse_error_message + rescue REXML::ParseException => e + @error_present = true + @error_message = e.to_s end def error_present? diff --git a/spec/services/proofing/aamva/verification_client_spec.rb b/spec/services/proofing/aamva/verification_client_spec.rb index 717c1f826b7..e443ab47b53 100644 --- a/spec/services/proofing/aamva/verification_client_spec.rb +++ b/spec/services/proofing/aamva/verification_client_spec.rb @@ -96,30 +96,36 @@ end let(:response_http_status) { 500 } - it 'parses the raw response body and returns an unsuccessful response with errors' do - expect(response).to be_a Proofing::Aamva::Response::VerificationResponse - expect(response.success?).to eq(false) + it 'parses the raw response body and throws an HTTP exception' do + expect { response }.to raise_error( + Proofing::Aamva::VerificationError, + 'Unexpected status code in response: 500', + ) expect(REXML::Document).to have_received(:new).with(response_body).at_least(:once) end end context 'because we have an invalid response and a 200 status' do - let(:response_body) { '

error: computer has no brain.

' } + let(:response_body) { 'error: computer has no brain.
' } - it 'parses the raw response body and returns an unsuccessful response with errors' do - expect(response).to be_a Proofing::Aamva::Response::VerificationResponse - expect(response.success?).to eq(false) + it 'parses the raw response body and throws a SOAP exception' do + expect { response }.to raise_error( + Proofing::Aamva::VerificationError, + /No close tag for \/br/, + ) expect(REXML::Document).to have_received(:new).with(response_body).at_least(:once) end end context 'because we have an invalid response and a non-200 status' do - let(:response_body) { '

I\'m a teapot

' } + let(:response_body) { '

I\'m a teapot' } let(:response_http_status) { 418 } it 'parses the raw response body and returns an unsuccessful response with errors' do - expect(response).to be_a Proofing::Aamva::Response::VerificationResponse - expect(response.success?).to eq(false) + expect { response }.to raise_error( + Proofing::Aamva::VerificationError, + /No close tag for \/h1/, + ) expect(REXML::Document).to have_received(:new).with(response_body).at_least(:once) end end From 3b039f238f5b34b1a34746eefc8e19f8d7eb6713 Mon Sep 17 00:00:00 2001 From: John Maxwell Date: Sat, 25 Feb 2023 04:34:22 -0500 Subject: [PATCH 05/13] Push for test run --- .../aamva/response/verification_response.rb | 19 ++++++----- .../aamva/verification_client_spec.rb | 34 ++++++++++++++++--- 2 files changed, 40 insertions(+), 13 deletions(-) diff --git a/app/services/proofing/aamva/response/verification_response.rb b/app/services/proofing/aamva/response/verification_response.rb index 5d2fc22ca42..77216042624 100644 --- a/app/services/proofing/aamva/response/verification_response.rb +++ b/app/services/proofing/aamva/response/verification_response.rb @@ -33,14 +33,18 @@ def initialize(http_response) @missing_attributes = [] @verification_results = {} @http_response = http_response + @errors = [] - http_error = handle_http_error - soap_error = handle_soap_error + handle_http_error + handle_soap_error parse_response - raise soap_error if soap_error - raise http_error if http_error + return if @errors.empty? + + error_message = @errors.join('; ') + raise ::Proofing::TimeoutError.new(msg) if mva_timeout?(error_message) + raise VerificationError.new(error_message) end def reasons @@ -68,8 +72,7 @@ def success? def handle_http_error status = http_response.status - return nil if status == 200 - return VerificationError.new("Unexpected status code in response: #{status}") + @errors.push("Unexpected status code in response: #{status}") if status != 200 end def handle_missing_attribute(attribute_name) @@ -79,10 +82,10 @@ def handle_missing_attribute(attribute_name) def handle_soap_error error_handler = SoapErrorHandler.new(http_response) - return nil unless error_handler.error_present? + return unless error_handler.error_present? + @errors.push(error_handler.error_message) msg = error_handler.error_message - return ::Proofing::TimeoutError.new(msg) if mva_timeout?(msg) return VerificationError.new(msg) end diff --git a/spec/services/proofing/aamva/verification_client_spec.rb b/spec/services/proofing/aamva/verification_client_spec.rb index e443ab47b53..e7b6da4208a 100644 --- a/spec/services/proofing/aamva/verification_client_spec.rb +++ b/spec/services/proofing/aamva/verification_client_spec.rb @@ -96,10 +96,10 @@ end let(:response_http_status) { 500 } - it 'parses the raw response body and throws an HTTP exception' do + it 'parses the raw response body and throws an exception which complains about the status code' do expect { response }.to raise_error( Proofing::Aamva::VerificationError, - 'Unexpected status code in response: 500', + /Unexpected status code in response: 500/, ) expect(REXML::Document).to have_received(:new).with(response_body).at_least(:once) end @@ -108,7 +108,16 @@ context 'because we have an invalid response and a 200 status' do let(:response_body) { 'error: computer has no brain.
' } - it 'parses the raw response body and throws a SOAP exception' do + it 'tries to parse the raw response body and throws a SOAP exception' do + begin + response + rescue Proofing::Aamva::VerificationError + end + + expect(REXML::Document).to have_received(:new).with(response_body).at_least(:once) + end + + it 'tries to parse the raw response body and throws a SOAP exception' do expect { response }.to raise_error( Proofing::Aamva::VerificationError, /No close tag for \/br/, @@ -121,12 +130,27 @@ let(:response_body) { '

I\'m a teapot' } let(:response_http_status) { 418 } - it 'parses the raw response body and returns an unsuccessful response with errors' do + it 'tries to parse the raw response body' do + begin + response + rescue Proofing::Aamva::VerificationError + end + + expect(REXML::Document).to have_received(:new).with(response_body).at_least(:once) + end + + it 'throws an error which complains about the invalid response' do expect { response }.to raise_error( Proofing::Aamva::VerificationError, /No close tag for \/h1/, ) - expect(REXML::Document).to have_received(:new).with(response_body).at_least(:once) + end + + it 'throws an error which complains about the HTTP error code' do + expect { response }.to raise_error( + Proofing::Aamva::VerificationError, + /Unexpected status code in response: 418/, + ) end end end From 5eee27a88c13732a53f9bb3d1c74e94220a53dbc Mon Sep 17 00:00:00 2001 From: John Maxwell Date: Sat, 25 Feb 2023 04:44:07 -0500 Subject: [PATCH 06/13] Lint foolishness. --- spec/services/proofing/aamva/verification_client_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/services/proofing/aamva/verification_client_spec.rb b/spec/services/proofing/aamva/verification_client_spec.rb index e7b6da4208a..e2f66c6978e 100644 --- a/spec/services/proofing/aamva/verification_client_spec.rb +++ b/spec/services/proofing/aamva/verification_client_spec.rb @@ -96,7 +96,7 @@ end let(:response_http_status) { 500 } - it 'parses the raw response body and throws an exception which complains about the status code' do + it 'parses the raw response body and throws an exception about the status code' do expect { response }.to raise_error( Proofing::Aamva::VerificationError, /Unexpected status code in response: 500/, From 9fe364a3d0b0fb5545b6fe9714eda84991b06670 Mon Sep 17 00:00:00 2001 From: John Maxwell Date: Sat, 25 Feb 2023 05:13:37 -0500 Subject: [PATCH 07/13] Spec cleanup. --- .../aamva/response/verification_response.rb | 2 -- .../response/verification_response_spec.rb | 2 +- .../proofing/aamva/verification_client_spec.rb | 17 ++++++++++++----- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/app/services/proofing/aamva/response/verification_response.rb b/app/services/proofing/aamva/response/verification_response.rb index 77216042624..d31edb895f2 100644 --- a/app/services/proofing/aamva/response/verification_response.rb +++ b/app/services/proofing/aamva/response/verification_response.rb @@ -85,8 +85,6 @@ def handle_soap_error return unless error_handler.error_present? @errors.push(error_handler.error_message) - msg = error_handler.error_message - return VerificationError.new(msg) end def node_for_match_indicator(match_indicator_name) diff --git a/spec/services/proofing/aamva/response/verification_response_spec.rb b/spec/services/proofing/aamva/response/verification_response_spec.rb index 5f5aeff4348..39ff9c207ba 100644 --- a/spec/services/proofing/aamva/response/verification_response_spec.rb +++ b/spec/services/proofing/aamva/response/verification_response_spec.rb @@ -49,7 +49,7 @@ it 'raises a VerificationError' do expect { subject }.to raise_error( Proofing::Aamva::VerificationError, - 'Unexpected status code in response: 504', + /Unexpected status code in response: 504/, ) end end diff --git a/spec/services/proofing/aamva/verification_client_spec.rb b/spec/services/proofing/aamva/verification_client_spec.rb index e2f66c6978e..fc5e56f42f6 100644 --- a/spec/services/proofing/aamva/verification_client_spec.rb +++ b/spec/services/proofing/aamva/verification_client_spec.rb @@ -96,19 +96,27 @@ end let(:response_http_status) { 500 } - it 'parses the raw response body and throws an exception about the status code' do + it 'parses the raw response body' do + begin + subject + rescue Proofing::Aamva::VerificationError + end + + expect(REXML::Document).to have_received(:new).with(response_body).at_least(:once) + end + + it 'throws an exception about the status code' do expect { response }.to raise_error( Proofing::Aamva::VerificationError, /Unexpected status code in response: 500/, ) - expect(REXML::Document).to have_received(:new).with(response_body).at_least(:once) end end context 'because we have an invalid response and a 200 status' do let(:response_body) { 'error: computer has no brain.
' } - it 'tries to parse the raw response body and throws a SOAP exception' do + it 'tries to parse the raw response body' do begin response rescue Proofing::Aamva::VerificationError @@ -117,12 +125,11 @@ expect(REXML::Document).to have_received(:new).with(response_body).at_least(:once) end - it 'tries to parse the raw response body and throws a SOAP exception' do + it 'throws a SOAP exception' do expect { response }.to raise_error( Proofing::Aamva::VerificationError, /No close tag for \/br/, ) - expect(REXML::Document).to have_received(:new).with(response_body).at_least(:once) end end From a711ed087ab897fc7bbd9cac6a6f6dc390419597 Mon Sep 17 00:00:00 2001 From: John Maxwell Date: Sat, 25 Feb 2023 05:37:37 -0500 Subject: [PATCH 08/13] Fix typo --- spec/services/proofing/aamva/verification_client_spec.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spec/services/proofing/aamva/verification_client_spec.rb b/spec/services/proofing/aamva/verification_client_spec.rb index fc5e56f42f6..11e0d8d335a 100644 --- a/spec/services/proofing/aamva/verification_client_spec.rb +++ b/spec/services/proofing/aamva/verification_client_spec.rb @@ -98,7 +98,8 @@ it 'parses the raw response body' do begin - subject + + response rescue Proofing::Aamva::VerificationError end From 0e214e8f4db06de754576e7f2b52a28b0532fff7 Mon Sep 17 00:00:00 2001 From: John Maxwell Date: Sat, 25 Feb 2023 05:38:30 -0500 Subject: [PATCH 09/13] Another typo --- spec/services/proofing/aamva/verification_client_spec.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/services/proofing/aamva/verification_client_spec.rb b/spec/services/proofing/aamva/verification_client_spec.rb index 11e0d8d335a..9e159db9d54 100644 --- a/spec/services/proofing/aamva/verification_client_spec.rb +++ b/spec/services/proofing/aamva/verification_client_spec.rb @@ -98,7 +98,6 @@ it 'parses the raw response body' do begin - response rescue Proofing::Aamva::VerificationError end From 8c958b60f5e8028b8984dd7f97ca0a0c15587d9a Mon Sep 17 00:00:00 2001 From: John Maxwell Date: Sat, 25 Feb 2023 11:07:20 -0500 Subject: [PATCH 10/13] Review comments. --- .../proofing/aamva/response/verification_response.rb | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/app/services/proofing/aamva/response/verification_response.rb b/app/services/proofing/aamva/response/verification_response.rb index d31edb895f2..edf22be2aa5 100644 --- a/app/services/proofing/aamva/response/verification_response.rb +++ b/app/services/proofing/aamva/response/verification_response.rb @@ -88,11 +88,9 @@ def handle_soap_error end def node_for_match_indicator(match_indicator_name) - begin - REXML::XPath.first(rexml_document, "//#{match_indicator_name}") - rescue REXML::ParseException - nil - end + REXML::XPath.first(rexml_document, "//#{match_indicator_name}") + rescue REXML::ParseException + nil end def parse_response @@ -114,8 +112,7 @@ def parse_response end def rexml_document - return @rexml_document if @rexml_document - @rexml_document = REXML::Document.new(http_response.body) + return @rexml_document ||= REXML::Document.new(http_response.body) end def mva_timeout?(error_message) From 698528f4c48599b2dc3a8216214116dc822ba964 Mon Sep 17 00:00:00 2001 From: John Maxwell Date: Tue, 28 Feb 2023 16:49:37 -0500 Subject: [PATCH 11/13] Test for Aaamva 'timed out talking to state agency' responses. --- .../aamva/response/verification_response.rb | 1 - .../aamva/verification_client_spec.rb | 49 +++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/app/services/proofing/aamva/response/verification_response.rb b/app/services/proofing/aamva/response/verification_response.rb index edf22be2aa5..c1e748f9f6c 100644 --- a/app/services/proofing/aamva/response/verification_response.rb +++ b/app/services/proofing/aamva/response/verification_response.rb @@ -43,7 +43,6 @@ def initialize(http_response) return if @errors.empty? error_message = @errors.join('; ') - raise ::Proofing::TimeoutError.new(msg) if mva_timeout?(error_message) raise VerificationError.new(error_message) end diff --git a/spec/services/proofing/aamva/verification_client_spec.rb b/spec/services/proofing/aamva/verification_client_spec.rb index 9e159db9d54..eba4e6bc63a 100644 --- a/spec/services/proofing/aamva/verification_client_spec.rb +++ b/spec/services/proofing/aamva/verification_client_spec.rb @@ -113,6 +113,55 @@ end end + context 'because we have an MVA timeout and 500 status' do + let(:response_body) { AamvaFixtures.soap_fault_response } + let(:response_http_status) { 500 } + + it 'parses the raw response body' do + begin + response + rescue Proofing::Aamva::VerificationError + end + + expect(REXML::Document).to have_received(:new).with(response_body).at_least(:once) + end + + it 'throws an exception about the MVA timeout' do + expect { response }.to raise_error( + Proofing::Aamva::VerificationError, + /#{Proofing::Aamva::Response::VerificationResponse::MVA_TIMEOUT_EXCEPTION}/o, + ) + end + + it 'throws an exception about the status code' do + expect { response }.to raise_error( + Proofing::Aamva::VerificationError, + /Unexpected status code in response: 500/, + ) + end + end + + context 'because we have an MVA timeout and 200 status' do + let(:response_body) { AamvaFixtures.soap_fault_response } + let(:response_http_status) { 200 } + + it 'parses the raw response body' do + begin + response + rescue Proofing::Aamva::VerificationError + end + + expect(REXML::Document).to have_received(:new).with(response_body).at_least(:once) + end + + it 'throws an exception about the MVA timeout' do + expect { response }.to raise_error( + Proofing::Aamva::VerificationError, + /#{Proofing::Aamva::Response::VerificationResponse::MVA_TIMEOUT_EXCEPTION}/o, + ) + end + end + context 'because we have an invalid response and a 200 status' do let(:response_body) { 'error: computer has no brain.
' } From 21896c35ad0bb3c2e2b73baf0e97ee640b461425 Mon Sep 17 00:00:00 2001 From: John Maxwell Date: Mon, 6 Mar 2023 14:44:32 -0500 Subject: [PATCH 12/13] Review comments. Removed explict checks for calls to REXML methods; it is enough to make sure we get the correct information out of the XML when it's available. --- .../aamva/verification_client_spec.rb | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/spec/services/proofing/aamva/verification_client_spec.rb b/spec/services/proofing/aamva/verification_client_spec.rb index eba4e6bc63a..cedeb73dd4c 100644 --- a/spec/services/proofing/aamva/verification_client_spec.rb +++ b/spec/services/proofing/aamva/verification_client_spec.rb @@ -69,8 +69,6 @@ end context 'when verification is not successful' do - before { allow(REXML::Document).to receive(:new).and_call_original } - context 'because we have a valid response and a 200 status, but the response says "no"' do let(:response_body) do modify_xml_at_xpath( @@ -96,15 +94,6 @@ end let(:response_http_status) { 500 } - it 'parses the raw response body' do - begin - response - rescue Proofing::Aamva::VerificationError - end - - expect(REXML::Document).to have_received(:new).with(response_body).at_least(:once) - end - it 'throws an exception about the status code' do expect { response }.to raise_error( Proofing::Aamva::VerificationError, @@ -122,8 +111,6 @@ response rescue Proofing::Aamva::VerificationError end - - expect(REXML::Document).to have_received(:new).with(response_body).at_least(:once) end it 'throws an exception about the MVA timeout' do @@ -150,8 +137,6 @@ response rescue Proofing::Aamva::VerificationError end - - expect(REXML::Document).to have_received(:new).with(response_body).at_least(:once) end it 'throws an exception about the MVA timeout' do @@ -170,8 +155,6 @@ response rescue Proofing::Aamva::VerificationError end - - expect(REXML::Document).to have_received(:new).with(response_body).at_least(:once) end it 'throws a SOAP exception' do @@ -191,8 +174,6 @@ response rescue Proofing::Aamva::VerificationError end - - expect(REXML::Document).to have_received(:new).with(response_body).at_least(:once) end it 'throws an error which complains about the invalid response' do From e8997a7d12f03466d4f54bf1363512be99a6fb85 Mon Sep 17 00:00:00 2001 From: John Maxwell Date: Mon, 6 Mar 2023 15:42:42 -0500 Subject: [PATCH 13/13] Review comments One more REXML spec removed. --- spec/services/proofing/aamva/verification_client_spec.rb | 7 ------- 1 file changed, 7 deletions(-) diff --git a/spec/services/proofing/aamva/verification_client_spec.rb b/spec/services/proofing/aamva/verification_client_spec.rb index cedeb73dd4c..1412531714a 100644 --- a/spec/services/proofing/aamva/verification_client_spec.rb +++ b/spec/services/proofing/aamva/verification_client_spec.rb @@ -106,13 +106,6 @@ let(:response_body) { AamvaFixtures.soap_fault_response } let(:response_http_status) { 500 } - it 'parses the raw response body' do - begin - response - rescue Proofing::Aamva::VerificationError - end - end - it 'throws an exception about the MVA timeout' do expect { response }.to raise_error( Proofing::Aamva::VerificationError,