From 4995a8a476cdbe4e0d8ab619f56aa3e8a3f35a35 Mon Sep 17 00:00:00 2001 From: Aurora <19178435+aurora-a-k-a-lightning@users.noreply.github.com> Date: Tue, 23 Apr 2024 14:57:32 -0700 Subject: [PATCH] bdex/80773: Toxic Exposure - [Lighthouse API] generatePdf hook up (#16411) * dbex/80773: enable benefits_claims/service#submit526 to call LH's /generatePDF endpoint * bdex/80773: enable benefits_claims/service#submit526 to call LH's /generatePDF endpoint * bdex/80773: enable benefits_claims/service#submit526 to call LH's /generatePDF endpoint * linting fix * bdex/80773: add removal of unicode carriage return and new line characters * bdex/80773: add generate pdf option unit test --------- Co-authored-by: Seth Darr <92405130+sethdarragile6@users.noreply.github.com> Co-authored-by: Seth Darr --- .../benefits_claims/configuration.rb | 2 +- lib/lighthouse/benefits_claims/service.rb | 42 +++++++-- .../benefits_claims/service_spec.rb | 9 ++ .../submit526/200_response_generate_pdf.yml | 85 +++++++++++++++++++ 4 files changed, 128 insertions(+), 10 deletions(-) create mode 100644 spec/support/vcr_cassettes/lighthouse/benefits_claims/submit526/200_response_generate_pdf.yml diff --git a/lib/lighthouse/benefits_claims/configuration.rb b/lib/lighthouse/benefits_claims/configuration.rb index 394611f02d8..72e714d2f80 100644 --- a/lib/lighthouse/benefits_claims/configuration.rb +++ b/lib/lighthouse/benefits_claims/configuration.rb @@ -13,7 +13,7 @@ module BenefitsClaims class Configuration < Common::Client::Configuration::REST self.read_timeout = Settings.lighthouse.benefits_claims.timeout || 20 - API_SCOPES = %w[system/claim.read system/claim.write].freeze + API_SCOPES = %w[system/claim.read system/claim.write system/526-pdf.override].freeze CLAIMS_PATH = 'services/claims/v2/veterans' TOKEN_PATH = 'oauth2/claims/system/v1/token' diff --git a/lib/lighthouse/benefits_claims/service.rb b/lib/lighthouse/benefits_claims/service.rb index 46f200a43ea..57a8f83f54b 100644 --- a/lib/lighthouse/benefits_claims/service.rb +++ b/lib/lighthouse/benefits_claims/service.rb @@ -102,7 +102,8 @@ def create_intent_to_file(type, claimant_ssn, lighthouse_client_id = nil, lighth handle_error(e, lighthouse_client_id, endpoint) end - # submit form526 to Lighthouse API endpoint: /services/claims/v2/veterans/{veteranId}/526 + # submit form526 to Lighthouse API endpoint: /services/claims/v2/veterans/{veteranId}/526 or + # /services/claims/v2/veterans/{veteranId}/526/generatePdf # @param [hash || Requests::Form526] body: a hash representing the form526 # attributes in the Lighthouse request schema # @param [string] lighthouse_client_id: the lighthouse_client_id requested from Lighthouse @@ -111,28 +112,31 @@ def create_intent_to_file(type, claimant_ssn, lighthouse_client_id = nil, lighth # @option options [hash] :body_only only return the body from the request # @option options [string] :aud_claim_url option to override the aud_claim_url for LH Veteran Verification APIs # @option options [hash] :auth_params a hash to send in auth params to create the access token + # @option options [hash] :generate_pdf call the generatePdf endpoint to receive the 526 pdf def submit526(body, lighthouse_client_id = nil, lighthouse_rsa_key_path = nil, options = {}) - endpoint = 'benefits_claims/form/526' + endpoint = '{icn}/526' path = "#{@icn}/526" + if options[:generate_pdf].present? + path += '/generatePDF/minimum-validations' + endpoint += '/generatePDF/minimum-validations' + end + # if we're coming straight from the transformation service without # making this a jsonapi request body first ({data: {type:, attributes}}), # this will put it in the correct format for transmission - body = { - data: { - type: 'form/526', - attributes: body - } - }.as_json.deep_transform_keys { |k| k.camelize(:lower) } + body = build_request_body(body) # Inflection settings force 'current_va_employee' to render as 'currentVAEmployee' in the above camelize() call # Since Lighthouse needs 'currentVaEmployee', the following workaround renames it. fix_current_va_employee(body) + json_body = remove_unicode_characters(body) + response = config.post( path, - body, + json_body, lighthouse_client_id, lighthouse_rsa_key_path, options ) @@ -143,6 +147,26 @@ def submit526(body, lighthouse_client_id = nil, lighthouse_rsa_key_path = nil, o private + def build_request_body(body) + { + data: { + type: 'form/526', + attributes: body + } + }.as_json.deep_transform_keys { |k| k.camelize(:lower) } + end + + # this gsubbing is to fix an issue where the service that generates the 526PDF was failing due to + # unicoded carriage returns: + # i.e.: \n was throwing: "U+000A ('controlLF') is not available in the font Helvetica, encoding: WinAnsiEncoding" + def remove_unicode_characters(body) + body.to_json + .gsub('\\n', ' ') + .gsub('\\r', ' ') + .gsub('\\\\n', ' ') + .gsub('\\\\r', ' ') + end + def fix_current_va_employee(body) if body.dig('data', 'attributes', 'veteranIdentification')&.select do |field| field['currentVAEmployee'] diff --git a/spec/lib/lighthouse/benefits_claims/service_spec.rb b/spec/lib/lighthouse/benefits_claims/service_spec.rb index d5ecd4fe022..05d1fe2e084 100644 --- a/spec/lib/lighthouse/benefits_claims/service_spec.rb +++ b/spec/lib/lighthouse/benefits_claims/service_spec.rb @@ -113,6 +113,15 @@ expect(response.claim_id).to eq(1_234_567_890) end end + + context 'when given the option to use generate pdf' do + it 'calls the generate pdf endpoint' do + VCR.use_cassette('lighthouse/benefits_claims/submit526/200_response_generate_pdf') do + raw_response = @service.submit526({}, '', '', { generate_pdf: true }) + expect(raw_response.body).to eq('No example available') + end + end + end end end end diff --git a/spec/support/vcr_cassettes/lighthouse/benefits_claims/submit526/200_response_generate_pdf.yml b/spec/support/vcr_cassettes/lighthouse/benefits_claims/submit526/200_response_generate_pdf.yml new file mode 100644 index 00000000000..19741d9cff9 --- /dev/null +++ b/spec/support/vcr_cassettes/lighthouse/benefits_claims/submit526/200_response_generate_pdf.yml @@ -0,0 +1,85 @@ +--- +http_interactions: +- request: + method: post + uri: https://sandbox-api.va.gov/services/claims/v2/veterans/123498767V234859/526/generatePDF/minimum-validations + body: + encoding: US-ASCII + string: '' + headers: + Accept: + - application/json + Content-Type: + - application/json + User-Agent: + - Vets.gov Agent + Authorization: + - Bearer blahblahblah + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + response: + status: + code: 200 + message: OK + headers: + Date: + - Tue, 28 Feb 2023 21:02:39 GMT + Content-Type: + - text/html; charset=utf-8 + Connection: + - keep-alive + X-Ratelimit-Remaining-Minute: + - '59' + X-Ratelimit-Limit-Minute: + - '60' + Ratelimit-Remaining: + - '59' + Ratelimit-Limit: + - '60' + Ratelimit-Reset: + - '25' + Etag: + - W/"6571c42e57529000188d704a3cd1f46a" + Referrer-Policy: + - strict-origin-when-cross-origin + Vary: + - Origin + X-Content-Type-Options: + - nosniff + X-Download-Options: + - noopen + X-Frame-Options: + - SAMEORIGIN + X-Git-Sha: + - b20885293917fd081d24899644d2718d2ab4ccf9 + X-Github-Repository: + - https://github.com/department-of-veterans-affairs/vets-api + X-Permitted-Cross-Domain-Policies: + - none + X-Request-Id: + - d687047e-5004-43c1-babb-c2f52f2fda40 + X-Runtime: + - '3.569014' + X-Xss-Protection: + - 1; mode=block + Access-Control-Allow-Origin: + - "*" + X-Kong-Upstream-Latency: + - '3573' + X-Kong-Proxy-Latency: + - '24' + Via: + - kong/3.0.2 + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Cache-Control: + - no-cache, no-store + Pragma: + - no-cache + Transfer-Encoding: + - chunked + body: + encoding: ASCII-8BIT + string: 'No example available' + recorded_at: Tue, 28 Feb 2023 21:02:39 GMT +recorded_with: VCR 6.1.0