Commit a71fb931 authored by Ash McKenzie's avatar Ash McKenzie

Ensure params contains the expected user data

parent 9944ee53
......@@ -15,13 +15,6 @@ class RegistrationsController < Devise::RegistrationsController
end
def create
# To avoid duplicate form fields on the login page, the registration form
# names fields using `new_user`, but Devise still wants the params in
# `user`.
if params["new_#{resource_name}"].present? && params[resource_name].blank?
params[resource_name] = params.delete(:"new_#{resource_name}")
end
accept_pending_invitations
super do |new_user|
......@@ -85,8 +78,19 @@ class RegistrationsController < Devise::RegistrationsController
private
def ensure_correct_params!
# To avoid duplicate form fields on the login page, the registration form
# names fields using `new_user`, but Devise still wants the params in
# `user`.
if params["new_#{resource_name}"].present? && params[resource_name].blank?
params[resource_name] = params.delete(:"new_#{resource_name}")
end
end
def check_captcha
return unless Feature.enabled?(:registrations_recaptcha, default_enabled: true)
ensure_correct_params!
return unless Feature.enabled?(:registrations_recaptcha, default_enabled: true) # reCAPTCHA on the UI will still display however
return unless Gitlab::Recaptcha.load_configurations!
return if verify_recaptcha
......
......@@ -6,7 +6,8 @@ describe RegistrationsController do
include TermsHelper
describe '#create' do
let(:user_params) { { user: { name: 'new_user', username: 'new_username', email: 'new@user.com', password: 'Any_password' } } }
let(:base_user_params) { { name: 'new_user', username: 'new_username', email: 'new@user.com', password: 'Any_password' } }
let(:user_params) { { user: base_user_params } }
context 'email confirmation' do
around do |example|
......@@ -105,6 +106,12 @@ describe RegistrationsController do
expect(subject.current_user.terms_accepted?).to be(true)
end
end
it 'handles when params are new_user' do
post(:create, params: { new_user: base_user_params })
expect(subject.current_user).not_to be_nil
end
end
describe '#destroy' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment