From 138edc437bab74e664dda9dc719949e9e6d57445 Mon Sep 17 00:00:00 2001 From: Mantas Date: Tue, 6 Oct 2020 13:34:36 +0300 Subject: [PATCH] Fixes #3189 - Unable to create inital admin user via web installer --- .../app/controllers/getting_started.coffee | 13 +++---------- .../javascripts/app/controllers/signup.coffee | 2 +- app/controllers/users_controller.rb | 6 ++++-- spec/requests/user_spec.rb | 3 +-- spec/system/getting_started/admin_spec.rb | 19 +++++++++++++++++++ spec/system/getting_started/agents_spec.rb | 18 ++++++++++++++++++ spec/system/signup_spec.rb | 8 +++++--- 7 files changed, 51 insertions(+), 18 deletions(-) create mode 100644 spec/system/getting_started/admin_spec.rb create mode 100644 spec/system/getting_started/agents_spec.rb diff --git a/app/assets/javascripts/app/controllers/getting_started.coffee b/app/assets/javascripts/app/controllers/getting_started.coffee index 6fb2cd5cd..45ced174c 100644 --- a/app/assets/javascripts/app/controllers/getting_started.coffee +++ b/app/assets/javascripts/app/controllers/getting_started.coffee @@ -238,10 +238,7 @@ class Admin extends App.WizardFullScreen fail: (settings, details) => @formEnable(e) - if _.isArray(details.error) - @form.showAlert( App.i18n.translateInline( details.error[0], details.error[1] ) ) - else - @form.showAlert(details.error_human || details.error || 'Unable to create user!') + @form.showAlert(details.error_human || details.error || 'Unable to create user!') ) relogin: (data, status, xhr) => @@ -965,7 +962,7 @@ class Agent extends App.WizardFullScreen @html App.view('getting_started/agent')() - new App.ControllerForm( + @form = new App.ControllerForm( el: @$('.js-agent-form') model: App.User screen: 'invite_agent' @@ -1012,11 +1009,7 @@ class Agent extends App.WizardFullScreen fail: (settings, details) => @formEnable(e) - App.Event.trigger 'notify', { - type: 'error' - msg: App.i18n.translateContent(details.error_human || 'Can\'t create user!') - timeout: 2500 - } + @form.showAlert details.error_human || 'Can\'t create user!' ) App.Config.set('getting_started/agents', Agent, 'Routes') diff --git a/app/assets/javascripts/app/controllers/signup.coffee b/app/assets/javascripts/app/controllers/signup.coffee index 4b2762a68..ae75bd56b 100644 --- a/app/assets/javascripts/app/controllers/signup.coffee +++ b/app/assets/javascripts/app/controllers/signup.coffee @@ -75,7 +75,7 @@ class Index extends App.ControllerContent ) fail: (settings, details) => @formEnable(e) - @form.showAlert(details.error_human || details.error || 'Unable to update object!') + @form.showAlert(details.error_human || details.error || 'Unable to create user!') ) resend: (e) => diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index fdb8eab86..4eea0d051 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -968,7 +968,8 @@ curl http://localhost/api/v1/users/avatar -v -u #{login}:#{password} -H "Content result = PasswordPolicy.new(clean_user_params[:password]) if !result.valid? - raise Exceptions::UnprocessableEntity, result.error + render json: { error: result.error }, status: :unprocessable_entity + return end user = User.new(clean_user_params) @@ -1026,7 +1027,8 @@ curl http://localhost/api/v1/users/avatar -v -u #{login}:#{password} -H "Content # check password policy result = PasswordPolicy.new(clean_user_params[:password]) if !result.valid? - raise Exceptions::UnprocessableEntity, result.error + render json: { error: result.error }, status: :unprocessable_entity + return end user = User.new(clean_user_params) diff --git a/spec/requests/user_spec.rb b/spec/requests/user_spec.rb index a44fbc4d0..0e96ffcf5 100644 --- a/spec/requests/user_spec.rb +++ b/spec/requests/user_spec.rb @@ -168,8 +168,7 @@ RSpec.describe 'User', type: :request do params = { email: 'some_new_customer@example.com', password: 'asdasdasdasd', signup: true } post '/api/v1/users', params: params, headers: headers, as: :json expect(response).to have_http_status(:unprocessable_entity) - expect(json_response['error']).to be_truthy - expect(json_response['error']).to include('Invalid password') + expect(json_response['error']).to be_a(Array).and(include(match(/Invalid password/))) end it 'verified with no current user', authenticated_as: :admin do diff --git a/spec/system/getting_started/admin_spec.rb b/spec/system/getting_started/admin_spec.rb new file mode 100644 index 000000000..a69ba5395 --- /dev/null +++ b/spec/system/getting_started/admin_spec.rb @@ -0,0 +1,19 @@ +require 'rails_helper' + +RSpec.describe 'Getting Started > Admin', type: :system, authenticated_as: false, set_up: false do + it 'shows password strength error' do + visit 'getting_started/admin' + + fill_in 'firstname', with: 'Test' + fill_in 'lastname', with: 'Test' + fill_in 'email', with: 'test@example.com' + fill_in 'password', with: 'asdasdasdasd' + fill_in 'password_confirm', with: 'asdasdasdasd' + + click '.btn--success' + + within '.js-danger' do + expect(page).to have_text('Invalid password,').and(have_no_text('["')) + end + end +end diff --git a/spec/system/getting_started/agents_spec.rb b/spec/system/getting_started/agents_spec.rb new file mode 100644 index 000000000..184be9ff5 --- /dev/null +++ b/spec/system/getting_started/agents_spec.rb @@ -0,0 +1,18 @@ +require 'rails_helper' + +RSpec.describe 'Getting Started > Agents', type: :system do + it 'shows password strength error' do + visit 'getting_started/agents' + + fill_in 'firstname', with: 'Test' + fill_in 'lastname', with: 'Test' + fill_in 'email', with: 'master@example.com' + + click '.btn--success' + + within '.js-danger' do + expect(page) + .to have_text("Email address 'master@example.com' is already used for other user.") + end + end +end diff --git a/spec/system/signup_spec.rb b/spec/system/signup_spec.rb index f9c805174..9a742d18b 100644 --- a/spec/system/signup_spec.rb +++ b/spec/system/signup_spec.rb @@ -7,11 +7,13 @@ RSpec.describe 'Signup', type: :system, authenticated_as: false do fill_in 'firstname', with: 'Test' fill_in 'lastname', with: 'Test' fill_in 'email', with: 'test@example.com' - fill_in 'password', with: 'badpw' - fill_in 'password_confirm', with: 'badpw' + fill_in 'password', with: 'asdasdasdasd' + fill_in 'password_confirm', with: 'asdasdasdasd' click '.js-submit' - expect(page).to have_text 'Invalid password,' + within '.js-danger' do + expect(page).to have_text('Invalid password,').and(have_no_text('["')) + end end end