diff --git a/app/controllers/import/uploads_controller.rb b/app/controllers/import/uploads_controller.rb index bd08c3e2a..076452a88 100644 --- a/app/controllers/import/uploads_controller.rb +++ b/app/controllers/import/uploads_controller.rb @@ -41,8 +41,8 @@ class Import::UploadsController < ApplicationController return end - if uploaded.size > SureImport::MAX_NDJSON_SIZE - flash.now[:alert] = t("imports.create.file_too_large", max_size: SureImport::MAX_NDJSON_SIZE / 1.megabyte) + if uploaded.size > SureImport.max_ndjson_size + flash.now[:alert] = t("imports.create.file_too_large", max_size: SureImport.max_ndjson_size / 1.megabyte) render :show, status: :unprocessable_entity return end diff --git a/app/controllers/imports_controller.rb b/app/controllers/imports_controller.rb index cc1b0f286..356956168 100644 --- a/app/controllers/imports_controller.rb +++ b/app/controllers/imports_controller.rb @@ -251,8 +251,8 @@ class ImportsController < ApplicationController end def create_sure_import(file) - if file.size > SureImport::MAX_NDJSON_SIZE - redirect_to new_import_path, alert: t("imports.create.file_too_large", max_size: SureImport::MAX_NDJSON_SIZE / 1.megabyte) + if file.size > SureImport.max_ndjson_size + redirect_to new_import_path, alert: t("imports.create.file_too_large", max_size: SureImport.max_ndjson_size / 1.megabyte) return end diff --git a/app/models/sure_import.rb b/app/models/sure_import.rb index 096b3771d..4593ec4d3 100644 --- a/app/models/sure_import.rb +++ b/app/models/sure_import.rb @@ -4,7 +4,6 @@ class SureImport < Import DEFAULT_MAX_NDJSON_SIZE_MB = 10 DEFAULT_MAX_ROW_COUNT = 100_000 - MAX_NDJSON_SIZE = DEFAULT_MAX_NDJSON_SIZE_MB.megabytes IMPORTABLE_NDJSON_TYPES = { "Account" => :accounts, "Balance" => :balances, diff --git a/test/controllers/import/uploads_controller_test.rb b/test/controllers/import/uploads_controller_test.rb index 1836ac95d..fd203a23e 100644 --- a/test/controllers/import/uploads_controller_test.rb +++ b/test/controllers/import/uploads_controller_test.rb @@ -47,6 +47,25 @@ class Import::UploadsControllerTest < ActionDispatch::IntegrationTest assert_select 'select[name="import[account_id]"] option', text: "Plaid Depository Account", count: 0 end + test "respects SURE_IMPORT_MAX_NDJSON_SIZE_MB when uploading Sure import file (#3010)" do + configured_limit = 2.megabytes + SureImport.stubs(:max_ndjson_size).returns(configured_limit) + + sure_import = imports(:sure) + oversized_file = Rack::Test::UploadedFile.new( + StringIO.new("x" * (configured_limit + 1)), + "application/x-ndjson", + original_filename: "all.ndjson" + ) + + patch import_upload_url(sure_import), params: { + import: { ndjson_file: oversized_file } + } + + assert_response :unprocessable_entity + assert_equal I18n.t("imports.create.file_too_large", max_size: configured_limit / 1.megabyte), flash[:alert] + end + test "invalid csv cannot be uploaded" do patch import_upload_url(@import), params: { import: { diff --git a/test/controllers/imports_controller_test.rb b/test/controllers/imports_controller_test.rb index eb6ad3cd4..10d34ae0b 100644 --- a/test/controllers/imports_controller_test.rb +++ b/test/controllers/imports_controller_test.rb @@ -411,6 +411,29 @@ class ImportsControllerTest < ActionDispatch::IntegrationTest assert_redirected_to imports_path end + test "respects SURE_IMPORT_MAX_NDJSON_SIZE_MB when creating Sure import (#3010)" do + configured_limit = 2.megabytes + SureImport.stubs(:max_ndjson_size).returns(configured_limit) + + oversized_file = Rack::Test::UploadedFile.new( + StringIO.new("x" * (configured_limit + 1)), + "application/x-ndjson", + original_filename: "all.ndjson" + ) + + assert_no_difference "Import.count" do + post imports_url, params: { + import: { + type: "SureImport", + import_file: oversized_file + } + } + end + + assert_redirected_to new_import_url + assert_equal I18n.t("imports.create.file_too_large", max_size: configured_limit / 1.megabyte), flash[:alert] + end + test "PDF import account select does not leak unshared family accounts (#1803)" do sign_in users(:family_member) pdf_import = imports(:pdf_with_rows)