diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-03-19 09:08:53 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-03-19 09:08:53 +0000 |
commit | 472a7da0e565894f7128becb5b1cf67572a13491 (patch) | |
tree | b97da413901b64dbe6b422362cae6ec9396cf639 /spec/controllers/groups_controller_spec.rb | |
parent | 0f26d7c7fb43f3fbc1ba0ee5b1c5537e7646dffd (diff) | |
download | gitlab-ce-472a7da0e565894f7128becb5b1cf67572a13491.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/controllers/groups_controller_spec.rb')
-rw-r--r-- | spec/controllers/groups_controller_spec.rb | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/spec/controllers/groups_controller_spec.rb b/spec/controllers/groups_controller_spec.rb index cce61c4534b..931f08e17ce 100644 --- a/spec/controllers/groups_controller_spec.rb +++ b/spec/controllers/groups_controller_spec.rb @@ -312,6 +312,64 @@ RSpec.describe GroupsController, factory_default: :keep do end end end + + context 'when creating a group with captcha protection' do + before do + sign_in(user) + + stub_application_setting(recaptcha_enabled: true) + end + + after do + # Avoid test ordering issue and ensure `verify_recaptcha` returns true + unless Recaptcha.configuration.skip_verify_env.include?('test') + Recaptcha.configuration.skip_verify_env << 'test' + end + end + + it 'displays an error when the reCAPTCHA is not solved' do + allow(controller).to receive(:verify_recaptcha).and_return(false) + + post :create, params: { group: { name: 'new_group', path: "new_group" } } + + expect(response).to render_template(:new) + expect(flash[:alert]).to eq(_('There was an error with the reCAPTCHA. Please solve the reCAPTCHA again.')) + end + + it 'allows creating a group when the reCAPTCHA is solved' do + expect do + post :create, params: { group: { name: 'new_group', path: "new_group" } } + end.to change { Group.count }.by(1) + + expect(response).to have_gitlab_http_status(:found) + end + + it 'allows creating a sub-group without checking the captcha' do + expect(controller).not_to receive(:verify_recaptcha) + + expect do + post :create, params: { group: { name: 'new_group', path: "new_group", parent_id: group.id } } + end.to change { Group.count }.by(1) + + expect(response).to have_gitlab_http_status(:found) + end + + context 'with feature flag switched off' do + before do + stub_feature_flags(recaptcha_on_top_level_group_creation: false) + end + + it 'allows creating a group without the reCAPTCHA' do + expect(controller).not_to receive(:verify_recaptcha) + + expect do + post :create, params: { group: { name: 'new_group', path: "new_group" } } + end.to change { Group.count }.by(1) + + expect(response).to have_gitlab_http_status(:found) + end + end + end end describe 'GET #index' do |