Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions app/components/password_confirmation_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,4 @@
>
<%= t('components.password_confirmation.toggle_label') %>
</label>

<%= form.hidden_field :confirmation_enabled, value: true %>
<% end %>
3 changes: 1 addition & 2 deletions app/controllers/sign_up/passwords_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ def track_analytics(result)

def permitted_params
params.require(:password_form).permit(
:confirmation_token, :password, :password_confirmation,
:confirmation_enabled
:confirmation_token, :password, :password_confirmation
)
end

Expand Down
1 change: 0 additions & 1 deletion app/forms/password_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ def submit(params)
@password = params[:password]
@password_confirmation = params[:password_confirmation]
@request_id = params.fetch(:request_id, '')
@confirmation_enabled = params[:confirmation_enabled].presence

FormResponse.new(success: valid?, errors: errors, extra: extra_analytics_attributes)
end
Expand Down
6 changes: 3 additions & 3 deletions app/validators/form_password_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module FormPasswordValidator
extend ActiveSupport::Concern

included do
attr_accessor :password, :password_confirmation, :validate_confirmation, :confirmation_enabled
attr_accessor :password, :password_confirmation, :validate_confirmation
attr_reader :user

validates :password,
Expand All @@ -11,7 +11,7 @@ module FormPasswordValidator
validates :password_confirmation,
presence: true,
length: { in: Devise.password_length },
if: -> { confirmation_enabled && validate_confirmation }
if: -> { validate_confirmation }

validate :password_graphemes_length, :strong_password, :not_pwned, :passwords_match
end
Expand Down Expand Up @@ -54,7 +54,7 @@ def not_pwned
end

def passwords_match
return unless confirmation_enabled && validate_confirmation
return unless validate_confirmation

if password != password_confirmation
errors.add(
Expand Down
134 changes: 63 additions & 71 deletions spec/controllers/sign_up/passwords_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
password_form: {
password: password,
password_confirmation: password_confirmation,
confirmation_enabled: true,
},
confirmation_token: token,
}
Expand Down Expand Up @@ -77,80 +76,73 @@
stub_attempts_tracker
end

context 'with temporary param confirmation_enabled' do
before do
params.merge(confirmation_enabled: true)
context 'with a password that is too short' do
let(:password) { 'NewVal' }
let(:password_confirmation) { 'NewVal' }
let(:errors) do
{
password:
[t(
'errors.attributes.password.too_short.other',
count: Devise.password_length.first,
)],
password_confirmation:
["is too short (minimum is #{Devise.password_length.first} characters)"],
}
end
let(:error_details) do
{
password: [:too_short],
password_confirmation: [:too_short],
}
end

it 'tracks an invalid password event' do
expect(@analytics).to receive(:track_event).
with(
'User Registration: Email Confirmation',
{ errors: {}, error_details: nil, success: true, user_id: user.uuid },
)
expect(@analytics).to receive(:track_event).
with('Password Creation', analytics_hash)

expect(@irs_attempts_api_tracker).to receive(:user_registration_password_submitted).
with(
success: false,
failure_reason: error_details,
)
expect(@irs_attempts_api_tracker).not_to receive(:user_registration_email_confirmation)

subject
end
end

# modify this test
context 'with a password that is too short' do
let(:password) { 'NewVal' }
let(:password_confirmation) { 'NewVal' }
let(:errors) do
{
password:
[t(
'errors.attributes.password.too_short.other',
count: Devise.password_length.first,
)],
password_confirmation:
["is too short (minimum is #{Devise.password_length.first} characters)"],
}
end
let(:error_details) do
{
password: [:too_short],
password_confirmation: [:too_short],
}
end

it 'tracks an invalid password event' do
expect(@analytics).to receive(:track_event).
with(
'User Registration: Email Confirmation',
{ errors: {}, error_details: nil, success: true, user_id: user.uuid },
)
expect(@analytics).to receive(:track_event).
with('Password Creation', analytics_hash)

expect(@irs_attempts_api_tracker).to receive(:user_registration_password_submitted).
with(
success: false,
failure_reason: error_details,
)
expect(@irs_attempts_api_tracker).not_to receive(:user_registration_email_confirmation)

subject
end
context 'when password confirmation does not match' do
let(:password) { 'NewVal!dPassw0rd' }
let(:password_confirmation) { 'bad match password' }
let(:errors) do
{
password_confirmation:
[t('errors.messages.password_mismatch')],
}
end
let(:error_details) do
{
password_confirmation: [t('errors.messages.password_mismatch')],
}
end

it 'tracks invalid password_confirmation error' do
expect(@analytics).to receive(:track_event).
with(
'User Registration: Email Confirmation',
{ errors: {}, error_details: nil, success: true, user_id: user.uuid },
)

expect(@analytics).to receive(:track_event).
with('Password Creation', analytics_hash)

context 'when password confirmation does not match' do
let(:password) { 'NewVal!dPassw0rd' }
let(:password_confirmation) { 'bad match password' }
let(:errors) do
{
password_confirmation:
[t('errors.messages.password_mismatch')],
}
end
let(:error_details) do
{
password_confirmation: [t('errors.messages.password_mismatch')],
}
end

it 'tracks invalid password_confirmation error' do
expect(@analytics).to receive(:track_event).
with(
'User Registration: Email Confirmation',
{ errors: {}, error_details: nil, success: true, user_id: user.uuid },
)

expect(@analytics).to receive(:track_event).
with('Password Creation', analytics_hash)

subject
end
subject
end
end
end
Expand Down
1 change: 0 additions & 1 deletion spec/forms/password_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
{
password: password,
password_confirmation: password_confirmation,
confirmation_enabled: true,
}
end

Expand Down