diff --git a/app/validators/idv/form_profile_validator.rb b/app/validators/idv/form_profile_validator.rb index 371b7ad22ad..986ed1c844b 100644 --- a/app/validators/idv/form_profile_validator.rb +++ b/app/validators/idv/form_profile_validator.rb @@ -3,8 +3,7 @@ module FormProfileValidator extend ActiveSupport::Concern included do - validates :address1, :city, :dob, :first_name, :last_name, :ssn, :state, :zipcode, - presence: true + validates :dob, :ssn, :state, :zipcode, presence: true validate :dob_is_sane, :ssn_is_unique @@ -16,6 +15,12 @@ module FormProfileValidator with: /\A\d{3}-?\d{2}-?\d{4}\z/, message: I18n.t('idv.errors.pattern_mismatch.ssn'), allow_blank: true + + validates :city, presence: true, length: { maximum: 255 } + validates :first_name, presence: true, length: { maximum: 255 } + validates :last_name, presence: true, length: { maximum: 255 } + validates :address1, presence: true, length: { maximum: 255 } + validates :address2, length: { maximum: 255 } end def duplicate_ssn? diff --git a/app/views/idv/sessions/new.html.slim b/app/views/idv/sessions/new.html.slim index 5e7d089184e..3922f160cb4 100644 --- a/app/views/idv/sessions/new.html.slim +++ b/app/views/idv/sessions/new.html.slim @@ -10,8 +10,8 @@ p = link_to t('links.access_help'), html: { autocomplete: 'off', method: :put, role: 'form' }) do |f| = f.error_notification fieldset.ml0.p0.border-none - = f.input :first_name, label: t('idv.form.first_name'), required: true - = f.input :last_name, label: t('idv.form.last_name'), required: true + = f.input :first_name, label: t('idv.form.first_name'), required: true, maxlength: 255 + = f.input :last_name, label: t('idv.form.last_name'), required: true, maxlength: 255 .clearfix.mxn1 .sm-col.sm-col-6.px1 / using :tel for mobile numeric keypad @@ -52,9 +52,9 @@ p = link_to t('links.access_help'), pattern: '^.{0,25}$', input_html: { class: 'sm-col-8 state_id_number', value: @idv_form.state_id_number } = f.input :address1, label: t('idv.form.address1'), wrapper_html: { class: 'mb1' }, - required: true - = f.input :address2, label: t('idv.form.address2') - = f.input :city, label: t('idv.form.city'), required: true + required: true, maxlength: 255 + = f.input :address2, label: t('idv.form.address2'), maxlength: 255 + = f.input :city, label: t('idv.form.city'), required: true, maxlength: 255 .clearfix.mxn1 .sm-col.sm-col-8.px1 diff --git a/spec/forms/idv/profile_form_spec.rb b/spec/forms/idv/profile_form_spec.rb index 456559263e8..cf4b4fe09b3 100644 --- a/spec/forms/idv/profile_form_spec.rb +++ b/spec/forms/idv/profile_form_spec.rb @@ -197,4 +197,18 @@ expect(subject.errors).to include(:state_id_number) end end + + describe 'field lengths' do + it 'populates error for invalid lengths' do + %i[city first_name last_name address1 address2]. each do |symbol| + max_length(symbol) + end + end + end + + def max_length(symbol) + subject.submit(profile_attrs.merge(symbol => 'a' * 256)) + expect(subject.valid?).to eq false + expect(subject.errors).to include(symbol) + end end