diff --git a/config/features.yml b/config/features.yml index 5f3af88b8a6..3da0dee1c29 100644 --- a/config/features.yml +++ b/config/features.yml @@ -776,9 +776,9 @@ features: va_view_dependents_access: actor_type: user description: Allows us to gate the View/ Modify dependents content in a progressive rollout - vba_documents_larger_page_size_limit: + vba_documents_skip_dimension_check: actor_type: user - description: Allows Benefits Intake to accept PDFs up to 78x101 inches (instead of the default 21x21) + description: Allows Benefits Intake to accept any size of PDF, skipping the check for page dimensions yellow_ribbon_mvp_enhancement: actor_type: user description: Enhances Yellow Ribbon MVP. diff --git a/lib/central_mail/upload_error.rb b/lib/central_mail/upload_error.rb index 15e903f5b75..7bebd21a37e 100644 --- a/lib/central_mail/upload_error.rb +++ b/lib/central_mail/upload_error.rb @@ -1,23 +1,20 @@ # frozen_string_literal: true -require 'pdf_utilities/pdf_validator' require 'central_mail/upload_error' module CentralMail class UploadError < StandardError attr_accessor :code, :detail - DEFAULT_MESSAGE = 'Internal Server Error' - # DOC1xx errors: client errors, invalid submissions DOC101 = 'Invalid multipart payload' DOC102 = 'Invalid metadata part' DOC103 = 'Invalid content part' DOC104 = 'Upload rejected by upstream system' DOC105 = 'Invalid or unknown id' - DOC106 = 'Maximum document size exceeded.' + DOC106 = 'Maximum document size exceeded. Limit is 100MB per document' DOC107 = 'Empty payload' - DOC108 = 'Maximum page size exceeded.' + DOC108 = 'Maximum page size exceeded. Limit is 21 in x 21 in.' # DOC2xx errors: server errors either local or upstream # not unambiguously related to submitted content @@ -26,30 +23,15 @@ class UploadError < StandardError STATSD_UPLOAD_FAIL_KEY = 'api.central_mail.upload.fail' - def self.extra_message_text(code, pdf_validator_options) - opts = PDFUtilities::PDFValidator::Validator::DEFAULT_OPTIONS.merge(pdf_validator_options.to_h) - - case code.to_s - when 'DOC106' - "Limit is #{PDFUtilities.formatted_file_size(opts[:size_limit_in_bytes])} per document." - when 'DOC108' - "Limit is #{opts[:width_limit_in_inches]} in x #{opts[:height_limit_in_inches]} in." - else - '' - end - end - - def initialize(message = nil, code: nil, detail: nil, pdf_validator_options: {}) - if message.nil? && code.present? + def initialize(message = nil, code: nil, detail: nil) + if message.nil? begin - message = UploadError.const_get code.to_sym - extra = UploadError.extra_message_text(code, pdf_validator_options) - message += " #{extra}" if extra.present? + message = UploadError.const_get code if code.present? rescue NameError - message = DEFAULT_MESSAGE + message = 'Internal Server Error' end end - super(message || DEFAULT_MESSAGE) + super(message) @code = code @detail = detail diff --git a/lib/pdf_info.rb b/lib/pdf_info.rb index d43dc5cb3e6..eed559d6db7 100644 --- a/lib/pdf_info.rb +++ b/lib/pdf_info.rb @@ -43,8 +43,13 @@ def pages end def page_size - width, height = self['Page size'].scan(/\d+/).map(&:to_i) - { width:, height: } + page_size_str = self['Page size'] + height = page_size_str.split('x')[0].strip.to_i + width = page_size_str.split('x')[1].strip.split[0].to_i + { + height:, + width: + } end def page_size_inches diff --git a/lib/pdf_utilities/pdf_validator.rb b/lib/pdf_utilities/pdf_validator.rb index 7511c1058e1..cb7beee0ae6 100644 --- a/lib/pdf_utilities/pdf_validator.rb +++ b/lib/pdf_utilities/pdf_validator.rb @@ -3,22 +3,6 @@ require 'pdf_info' module PDFUtilities - def self.formatted_file_size(file_size_in_bytes) - bytes_per_gb = 1_000_000_000 - bytes_per_mb = 1_000_000 - bytes_per_kb = 1_000 - - if file_size_in_bytes >= bytes_per_gb - "#{format('%g', (file_size_in_bytes.to_f / bytes_per_gb))} GB" - elsif file_size_in_bytes >= bytes_per_mb - "#{format('%g', (file_size_in_bytes.to_f / bytes_per_mb))} MB" - elsif file_size_in_bytes >= bytes_per_kb - "#{format('%g', (file_size_in_bytes.to_f / bytes_per_kb))} KB" - else - "#{file_size_in_bytes} bytes" - end - end - module PDFValidator FILE_SIZE_LIMIT_EXCEEDED_MSG = 'Document exceeds the file size limit' PAGE_SIZE_LIMIT_EXCEEDED_MSG = 'Document exceeds the page size limit' @@ -46,10 +30,9 @@ class Validator DEFAULT_OPTIONS = { size_limit_in_bytes: 100_000_000, # 100 MB check_page_dimensions: true, - check_encryption: true, - # Height/width limits are ignored if the check_page_dimensions option is false. - width_limit_in_inches: 21, - height_limit_in_inches: 21 + width_limit_in_inches: 21, # Ignored if check_page_dimensions: false + height_limit_in_inches: 21, # Ignored if check_page_dimensions: false + check_encryption: true }.freeze attr_accessor :result, :pdf_metadata @@ -77,8 +60,7 @@ def validate def check_file_size size_limit = @options[:size_limit_in_bytes].to_i if File.size(@file) > size_limit - message = "#{FILE_SIZE_LIMIT_EXCEEDED_MSG} of #{PDFUtilities.formatted_file_size(size_limit)}" - @result.add_error(message) + @result.add_error("#{FILE_SIZE_LIMIT_EXCEEDED_MSG} of #{formatted_file_size(size_limit)}") end end @@ -107,6 +89,22 @@ def check_page_size end end end + + def formatted_file_size(file_size_in_bytes) + bytes_per_gb = 1_000_000_000 + bytes_per_mb = 1_000_000 + bytes_per_kb = 1_000 + + if file_size_in_bytes >= bytes_per_gb + "#{format('%g', (file_size_in_bytes.to_f / bytes_per_gb))} GB" + elsif file_size_in_bytes >= bytes_per_mb + "#{format('%g', (file_size_in_bytes.to_f / bytes_per_mb))} MB" + elsif file_size_in_bytes >= bytes_per_kb + "#{format('%g', (file_size_in_bytes.to_f / bytes_per_kb))} KB" + else + "#{file_size_in_bytes} bytes" + end + end end end end diff --git a/modules/vba_documents/app/workers/vba_documents/upload_processor.rb b/modules/vba_documents/app/workers/vba_documents/upload_processor.rb index 6c07266f4a6..8e1429a0de2 100644 --- a/modules/vba_documents/app/workers/vba_documents/upload_processor.rb +++ b/modules/vba_documents/app/workers/vba_documents/upload_processor.rb @@ -70,8 +70,7 @@ def download_and_process validate_metadata(parts[META_PART_NAME], submission_version: @upload.metadata['version'].to_i) metadata = perfect_metadata(@upload, parts, timestamp) - pdf_validator_options = VBADocuments::DocumentRequestValidator.pdf_validator_options - pdf_validator_options[:check_page_dimensions] = false if metadata['skipDimensionCheck'].present? + pdf_validator_options = metadata['skipDimensionCheck'] ? { check_page_dimensions: false } : {} validate_documents(parts, pdf_validator_options) response = submit(metadata, parts) diff --git a/modules/vba_documents/lib/vba_documents/document_request_validator.rb b/modules/vba_documents/lib/vba_documents/document_request_validator.rb index 74f1476def4..336367cd0dd 100644 --- a/modules/vba_documents/lib/vba_documents/document_request_validator.rb +++ b/modules/vba_documents/lib/vba_documents/document_request_validator.rb @@ -10,22 +10,13 @@ class DocumentRequestValidator MAX_FILE_SIZE_IN_BYTES = 100_000_000 # 100 MB DOCUMENT_NOT_PROVIDED_MSG = 'Document was not provided' DOCUMENT_NOT_A_PDF_MSG = 'Document is not a PDF' - FILE_SIZE_LIMIT_EXCEEDED_MSG = \ - "Document exceeds the file size limit of #{MAX_FILE_SIZE_IN_BYTES / 1_000_000} MB".freeze + FILE_SIZE_LIMIT_EXCEEDED_MSG = 'Document exceeds the file size limit of 100 MB' DOCUMENT_FAILED_VALIDATION_MSG = 'Document failed validation' - attr_accessor :result - - def self.pdf_validator_options - larger_limit = Flipper.enabled?(:vba_documents_larger_page_size_limit) + # Skip the check for owner/permissions password - only a user password invalidates the PDF + PDF_VALIDATOR_OPTIONS = { check_encryption: false }.freeze - { - check_encryption: false, # Owner passwords are allowed, user passwords are not - size_limit_in_bytes: MAX_FILE_SIZE_IN_BYTES, - width_limit_in_inches: larger_limit ? 78 : 21, - height_limit_in_inches: larger_limit ? 101 : 21 - } - end + attr_accessor :result def initialize(request) @request = request @@ -78,7 +69,8 @@ def validate_body Tempfile.create("vba-documents-validate-#{SecureRandom.hex}.pdf", binmode: true) do |tempfile| tempfile << @request.body.read tempfile.rewind - validator = PDFValidator::Validator.new(tempfile, DocumentRequestValidator.pdf_validator_options) + options = Flipper.enabled?(:vba_documents_skip_dimension_check) ? { check_page_dimensions: false } : {} + validator = PDFValidator::Validator.new(tempfile, PDF_VALIDATOR_OPTIONS.merge(options)) result = validator.validate unless result.valid_pdf? diff --git a/modules/vba_documents/lib/vba_documents/pdf_inspector.rb b/modules/vba_documents/lib/vba_documents/pdf_inspector.rb index 8dafb20cab4..90fbc593435 100644 --- a/modules/vba_documents/lib/vba_documents/pdf_inspector.rb +++ b/modules/vba_documents/lib/vba_documents/pdf_inspector.rb @@ -1,10 +1,8 @@ # frozen_string_literal: true -require 'central_mail/utilities' -require 'pdf_info' -require 'pdf_utilities/pdf_validator' -require 'vba_documents/document_request_validator' require 'vba_documents/multipart_parser' +require 'pdf_info' +require 'central_mail/utilities' module VBADocuments class PDFInspector @@ -84,16 +82,13 @@ def add_line_of_business(data, parts_metadata) def pdf_metadata(pdf) metadata = PdfInfo::Metadata.read(pdf) dimensions = metadata.page_size_inches - max_width, max_height = VBADocuments::DocumentRequestValidator.pdf_validator_options.values_at( - :width_limit_in_inches, :height_limit_in_inches - ) { page_count: metadata.pages, dimensions: { height: dimensions[:height].round(2), width: dimensions[:width].round(2), - oversized_pdf: dimensions[:height] > max_height || dimensions[:width] > max_width + oversized_pdf: dimensions[:height] > 21 || dimensions[:width] > 21 }, sha256_checksum: Digest::SHA256.file(pdf).hexdigest } diff --git a/modules/vba_documents/lib/vba_documents/upload_validator.rb b/modules/vba_documents/lib/vba_documents/upload_validator.rb index 3310dfb9aad..7f0db952986 100644 --- a/modules/vba_documents/lib/vba_documents/upload_validator.rb +++ b/modules/vba_documents/lib/vba_documents/upload_validator.rb @@ -59,7 +59,7 @@ def validate_metadata(metadata_input, submission_version:) raise VBADocuments::UploadError.new(code: 'DOC102', detail: 'Invalid JSON object') end - def validate_documents(parts, pdf_validator_options = VBADocuments::DocumentRequestValidator.pdf_validator_options) + def validate_documents(parts, pdf_validator_options = {}) # Validate 'content' document validate_document(parts[DOC_PART_NAME], DOC_PART_NAME, pdf_validator_options) @@ -112,24 +112,32 @@ def validate_line_of_business(lob, submission_version) end end + DEFAULT_PDF_VALIDATOR_OPTIONS = { + check_encryption: false # Owner passwords are allowed, user passwords are not + }.freeze + def validate_document(file_path, part_name, pdf_validator_options = {}) - result = PDFValidator::Validator.new(file_path, pdf_validator_options).validate + options = DEFAULT_PDF_VALIDATOR_OPTIONS.merge(pdf_validator_options) + options.merge!({ check_page_dimensions: false }) if Flipper.enabled?(:vba_documents_skip_dimension_check) + + result = PDFValidator::Validator.new(file_path, options).validate unless result.valid_pdf? errors = result.errors if errors.grep(/#{PDFValidator::FILE_SIZE_LIMIT_EXCEEDED_MSG}/).any? - raise VBADocuments::UploadError.new(code: 'DOC106', pdf_validator_options:) + raise VBADocuments::UploadError.new(code: 'DOC106', + detail: 'Maximum document size exceeded. Limit is 100MB per document') end if errors.grep(/#{PDFValidator::USER_PASSWORD_MSG}|#{PDFValidator::INVALID_PDF_MSG}/).any? raise VBADocuments::UploadError.new(code: 'DOC103', - detail: "Invalid PDF content, part #{part_name}", - pdf_validator_options:) + detail: "Invalid PDF content, part #{part_name}") end if errors.grep(/#{PDFValidator::PAGE_SIZE_LIMIT_EXCEEDED_MSG}/).any? - raise VBADocuments::UploadError.new(code: 'DOC108', pdf_validator_options:) + raise VBADocuments::UploadError.new(code: 'DOC108', + detail: VBADocuments::UploadError::DOC108) end end end diff --git a/modules/vba_documents/spec/factories/upload_submissions.rb b/modules/vba_documents/spec/factories/upload_submissions.rb index ba7d3f6a4b8..8c174906a03 100644 --- a/modules/vba_documents/spec/factories/upload_submissions.rb +++ b/modules/vba_documents/spec/factories/upload_submissions.rb @@ -5,12 +5,12 @@ source: nil, doc_type: 'Unknown', total_documents: 2, total_pages: 2, content: { page_count: 1, - dimensions: { height: 11.0, width: 8.5, oversized_pdf: false }, + dimensions: { height: 8.5, width: 11.0, oversized_pdf: false }, sha256_checksum: 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855', attachments: [ { page_count: 1, - dimensions: { height: 11.0, width: 8.5, oversized_pdf: false }, + dimensions: { height: 8.5, width: 11.0, oversized_pdf: false }, sha256_checksum: 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855' } ] diff --git a/modules/vba_documents/spec/fixtures/10x102.pdf b/modules/vba_documents/spec/fixtures/10x102.pdf deleted file mode 100644 index 68a51b26f54..00000000000 Binary files a/modules/vba_documents/spec/fixtures/10x102.pdf and /dev/null differ diff --git a/modules/vba_documents/spec/fixtures/79x10.pdf b/modules/vba_documents/spec/fixtures/79x10.pdf deleted file mode 100644 index 9fda975651f..00000000000 Binary files a/modules/vba_documents/spec/fixtures/79x10.pdf and /dev/null differ diff --git a/modules/vba_documents/spec/lib/document_request_validator_spec.rb b/modules/vba_documents/spec/lib/document_request_validator_spec.rb index bc2519833c5..bb6ffc815a7 100644 --- a/modules/vba_documents/spec/lib/document_request_validator_spec.rb +++ b/modules/vba_documents/spec/lib/document_request_validator_spec.rb @@ -25,42 +25,21 @@ describe 'given a document with large pages' do let(:fixture_name) { '18x22.pdf' } - context 'when vba_documents_larger_page_size_limit flag is off' do - before { Flipper.disable(:vba_documents_larger_page_size_limit) } + context 'when vba_documents_skip_dimension_check flag is off' do + before { Flipper.disable(:vba_documents_skip_dimension_check) } - describe 'with large PDF' do - it 'errors' do - expect(result[:errors].length).to eq(1) - expect(result[:errors].first[:status]).to eq('422') - end - end - - describe 'with extra large PDF' do - let(:fixture_name) { '10x102.pdf' } - - it 'errors' do - expect(result[:errors].length).to eq(1) - expect(result[:errors].first[:status]).to eq('422') - end + it 'considers the PDF invalid' do + errors = result[:errors] + expect(errors.length).to eq(1) + expect(errors.first[:status]).to eq('422') end end - context 'when vba_documents_larger_page_size_limit flag is on' do - before { Flipper.enable(:vba_documents_larger_page_size_limit) } - - describe 'with large PDF' do - it 'considers the PDF valid' do - expect(result.dig(:data, :attributes, :status)).to eq('valid') - end - end - - describe 'with extra large PDF' do - let(:fixture_name) { '10x102.pdf' } + context 'when vba_documents_skip_dimension_check flag is on' do + before { Flipper.enable(:vba_documents_skip_dimension_check) } - it 'errors' do - expect(result[:errors].length).to eq(1) - expect(result[:errors].first[:status]).to eq('422') - end + it 'considers the PDF valid' do + expect(result.dig(:data, :attributes, :status)).to eq('valid') end end end diff --git a/modules/vba_documents/spec/lib/pdf_inspector_spec.rb b/modules/vba_documents/spec/lib/pdf_inspector_spec.rb index d3b741f2cea..31c5fa680fb 100644 --- a/modules/vba_documents/spec/lib/pdf_inspector_spec.rb +++ b/modules/vba_documents/spec/lib/pdf_inspector_spec.rb @@ -18,8 +18,8 @@ subject { @inspector.pdf_data } let(:sha256_char_length) { 64 } - let(:page_height) { 11.0 } - let(:page_width) { 8.5 } + let(:page_height) { 8.5 } + let(:page_width) { 11.0 } it 'returns a hash' do expect(subject).to be_a(Hash) diff --git a/modules/vba_documents/spec/request/v2/uploads_request_submission_spec.rb b/modules/vba_documents/spec/request/v2/uploads_request_submission_spec.rb index 89ec2bbd67d..09cdca6d2cc 100644 --- a/modules/vba_documents/spec/request/v2/uploads_request_submission_spec.rb +++ b/modules/vba_documents/spec/request/v2/uploads_request_submission_spec.rb @@ -75,11 +75,6 @@ def invalidate_metadata(key, value = nil, delete_key = false) attachment2: build_fixture('valid_doc.pdf') } end - let(:invalid_attachment_extra_oversized) do - { attachment1: build_fixture('10x102.pdf'), - attachment2: build_fixture('valid_doc.pdf') } - end - let(:invalid_content_missing) do { content: nil } end @@ -126,8 +121,8 @@ def invalidate_metadata(key, value = nil, delete_key = false) describe 'when an attachment is oversized' do let(:params) { {}.merge(valid_metadata).merge(valid_content).merge(invalid_attachment_oversized) } - context 'with the "vba_documents_larger_page_size_limit" flag turned off' do - before { Flipper.disable :vba_documents_larger_page_size_limit } + context 'with the "vba_documents_skip_dimension_check" flag turned off' do + before { Flipper.disable :vba_documents_skip_dimension_check } it 'returns a UUID with status of error' do post(SUBMIT_ENDPOINT, params:) @@ -144,8 +139,8 @@ def invalidate_metadata(key, value = nil, delete_key = false) end end - context 'with the "vba_documents_larger_page_size_limit" flag turned on' do - before { Flipper.enable :vba_documents_larger_page_size_limit } + context 'with the "vba_documents_skip_dimension_check" flag turned on' do + before { Flipper.enable :vba_documents_skip_dimension_check } it 'allows the upload, returning a UUID with a status of uploaded and correct metadata' do post(SUBMIT_ENDPOINT, params:) @@ -157,27 +152,9 @@ def invalidate_metadata(key, value = nil, delete_key = false) uploaded_pdf = @attributes['uploaded_pdf'] expect(uploaded_pdf['total_documents']).to eq(3) expect(uploaded_pdf['content']['dimensions']['oversized_pdf']).to eq(false) - expect(uploaded_pdf['content']['attachments'].first['dimensions']['oversized_pdf']).to eq(false) + expect(uploaded_pdf['content']['attachments'].first['dimensions']['oversized_pdf']).to eq(true) expect(uploaded_pdf['content']['attachments'].last['dimensions']['oversized_pdf']).to eq(false) end - - context 'when the document has extra large pages' do - let(:params) { {}.merge(valid_metadata).merge(valid_content).merge(invalid_attachment_extra_oversized) } - - it 'rejects the extra large document' do - post(SUBMIT_ENDPOINT, params:) - expect(response).to have_http_status(:bad_request) - json = JSON.parse(response.body) - @attributes = json['data']['attributes'] - expect(@attributes).to have_key('guid') - expect(@attributes['status']).to eq('error') - uploaded_pdf = @attributes['uploaded_pdf'] - expect(uploaded_pdf['total_documents']).to eq(3) - expect(uploaded_pdf['content']['dimensions']['oversized_pdf']).to eq(false) - expect(uploaded_pdf['content']['attachments'].first['dimensions']['oversized_pdf']).to eq(true) - expect(uploaded_pdf['content']['attachments'].last['dimensions']['oversized_pdf']).to eq(false) - end - end end end diff --git a/modules/vba_documents/spec/workers/upload_processor_spec.rb b/modules/vba_documents/spec/workers/upload_processor_spec.rb index 85e5dd4a4c2..3ea5ee867a3 100644 --- a/modules/vba_documents/spec/workers/upload_processor_spec.rb +++ b/modules/vba_documents/spec/workers/upload_processor_spec.rb @@ -496,11 +496,13 @@ end context 'with invalid sizes' do - context 'when vba_documents_larger_page_size_limit flag is off' do - before { Flipper.disable(:vba_documents_larger_page_size_limit) } + invalid_sizes = %w[18x22 22x18] - %w[18x22 22x18].each do |invalid_size| - it "sets an error status for invalid size of #{invalid_size}" do + context 'when vba_documents_skip_dimension_check flag is off' do + before { Flipper.disable(:vba_documents_skip_dimension_check) } + + it 'sets an error status for invalid size' do + invalid_sizes.each do |invalid_size| allow(VBADocuments::MultipartParser).to receive(:parse) { { 'metadata' => valid_metadata, 'content' => get_fixture("#{invalid_size}.pdf") } } @@ -513,7 +515,7 @@ context 'when metadata.json contains skipDimensionCheck = true' do let(:special_metadata) { JSON.parse(valid_metadata).merge({ 'skipDimensionCheck' => true }).to_json } - let(:content) { get_fixture('18x22.pdf') } + let(:content) { get_fixture("#{invalid_sizes.first}.pdf") } before do allow(CentralMail::Service).to receive(:new) { client_stub } @@ -535,41 +537,26 @@ end end - context 'when vba_documents_larger_page_size_limit flag is on' do + context 'when vba_documents_skip_dimension_check flag is on' do + let(:content) { get_fixture("#{invalid_sizes.first}.pdf") } + before do - Flipper.enable(:vba_documents_larger_page_size_limit) + Flipper.enable(:vba_documents_skip_dimension_check) allow(CentralMail::Service).to receive(:new) { client_stub } allow(faraday_response).to receive(:status).and_return(200) allow(faraday_response).to receive(:body).and_return('') allow(faraday_response).to receive(:success?).and_return(true) allow(client_stub).to receive(:upload).and_return(faraday_response) + end + + it 'allows the upload' do allow(VBADocuments::MultipartParser).to receive(:parse) { { 'metadata' => valid_metadata, 'content' => content } } - end - - context 'with large but not-too-large PDF' do - let(:content) { get_fixture('18x22.pdf') } - - it 'allows the upload' do - described_class.new.perform(upload.guid, test_caller) - updated = VBADocuments::UploadSubmission.find_by(guid: upload.guid) - expect(updated.uploaded_pdf.dig('content', 'dimensions', 'oversized_pdf')).to eq(false) - expect(updated.status).to eq('received') - end - end - - context 'with a too large PDF' do - %w[10x102 79x10].each do |invalid_size| - let(:content) { get_fixture("#{invalid_size}.pdf") } - - it "sets an error status for an invalid size of #{invalid_size}" do - described_class.new.perform(upload.guid, test_caller) - updated = VBADocuments::UploadSubmission.find_by(guid: upload.guid) - expect(updated.status).to eq('error') - expect(updated.code).to eq('DOC108') - end - end + described_class.new.perform(upload.guid, test_caller) + updated = VBADocuments::UploadSubmission.find_by(guid: upload.guid) + expect(updated.uploaded_pdf.dig('content', 'dimensions', 'oversized_pdf')).to eq(true) + expect(updated.status).to eq('received') end end end diff --git a/spec/fixtures/pdf_utilities/pdf_validator/10x102.pdf b/spec/fixtures/pdf_utilities/pdf_validator/10x102.pdf deleted file mode 100644 index 68a51b26f54..00000000000 Binary files a/spec/fixtures/pdf_utilities/pdf_validator/10x102.pdf and /dev/null differ diff --git a/spec/fixtures/pdf_utilities/pdf_validator/79x10.pdf b/spec/fixtures/pdf_utilities/pdf_validator/79x10.pdf deleted file mode 100644 index 9fda975651f..00000000000 Binary files a/spec/fixtures/pdf_utilities/pdf_validator/79x10.pdf and /dev/null differ diff --git a/spec/lib/central_mail/upload_error_spec.rb b/spec/lib/central_mail/upload_error_spec.rb deleted file mode 100644 index f3b245124c2..00000000000 --- a/spec/lib/central_mail/upload_error_spec.rb +++ /dev/null @@ -1,90 +0,0 @@ -# frozen_string_literal: true - -require 'rails_helper' -require 'central_mail/upload_error' - -RSpec.describe CentralMail::UploadError do - before { expect(StatsD).to receive(:increment).with('api.central_mail.upload.fail', { tags: ["status:#{code}"] }) } - - let(:message) {} - let(:code) {} - let(:detail) {} - let(:pdf_validator_options) {} - let(:error) { described_class.new(message, code:, detail:, pdf_validator_options:) } - - describe 'default values' do - it 'has a generic message with no code or detail' do - expect(error).to have_attributes(code: nil, detail: nil, message: 'Internal Server Error') - end - end - - describe 'with custom message, detail, code' do - let(:message) { 'banana' } - let(:detail) { 'orange' } - let(:code) { 'apple' } - - it 'uses the values as provided' do - expect(error).to have_attributes(code:, detail:, message:) - end - end - - describe 'with recognized error code and no message' do - let(:code) { 'DOC101' } - - it 'has a default message based on the code' do - expect(error).to have_attributes(code:, detail:, message: 'Invalid multipart payload') - end - end - - describe 'DOC108' do - let(:code) { 'DOC108' } - - it 'has a default message based on the code and the default pdf validator default settings' do - expect(error).to have_attributes(code:, detail:, message: 'Maximum page size exceeded. Limit is 21 in x 21 in.') - end - - context 'with custom settings' do - let(:pdf_validator_options) { { width_limit_in_inches: 111, height_limit_in_inches: 222 } } - - it 'has a custom message based on the code and settings' do - expect(error) - .to have_attributes(code:, detail:, message: 'Maximum page size exceeded. Limit is 111 in x 222 in.') - end - end - - context 'with custom message' do - let(:message) { 'banana' } - - it 'uses the message as provided' do - expect(error).to have_attributes(code:, detail:, message:) - end - end - end - - describe 'DOC106' do - let(:code) { 'DOC106' } - - it 'has a default message based on the code and the default pdf validator default settings' do - expect(error) - .to have_attributes(code:, detail:, message: 'Maximum document size exceeded. Limit is 100 MB per document.') - end - - context 'with custom settings' do - let(:pdf_validator_options) { { size_limit_in_bytes: 987_654_321 } } - - it 'has a custom message based on the code and settings' do - expect(error).to have_attributes(code:, - detail:, - message: 'Maximum document size exceeded. Limit is 987.654 MB per document.') - end - end - - context 'with custom message' do - let(:message) { 'banana' } - - it 'uses the message as provided' do - expect(error).to have_attributes(code:, detail:, message:) - end - end - end -end diff --git a/spec/lib/pdf_info/metadata_spec.rb b/spec/lib/pdf_info/metadata_spec.rb index 56be20952c0..313d5374cdf 100644 --- a/spec/lib/pdf_info/metadata_spec.rb +++ b/spec/lib/pdf_info/metadata_spec.rb @@ -91,13 +91,6 @@ end end - describe '#page_size' do - it 'returns the page dimensions in points' do - metadata = described_class.read('/tmp/file.pdf') - expect(metadata.page_size).to eq({ width: 612, height: 792 }) - end - end - describe '#encrypted?' do it 'returns encryption as a boolean' do metadata = described_class.read('/tmp/file.pdf')