diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-01-18 22:00:14 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-01-18 22:00:14 +0300 |
commit | 05f0ebba3a2c8ddf39e436f412dc2ab5bf1353b2 (patch) | |
tree | 11d0f2a6ec31c7793c184106cedc2ded3d9a2cc5 /spec/controllers/import/bulk_imports_controller_spec.rb | |
parent | ec73467c23693d0db63a797d10194da9e72a74af (diff) |
Add latest changes from gitlab-org/gitlab@15-8-stable-eev15.8.0-rc42
Diffstat (limited to 'spec/controllers/import/bulk_imports_controller_spec.rb')
-rw-r--r-- | spec/controllers/import/bulk_imports_controller_spec.rb | 85 |
1 files changed, 81 insertions, 4 deletions
diff --git a/spec/controllers/import/bulk_imports_controller_spec.rb b/spec/controllers/import/bulk_imports_controller_spec.rb index a0bb39f3e98..a0d5b576e74 100644 --- a/spec/controllers/import/bulk_imports_controller_spec.rb +++ b/spec/controllers/import/bulk_imports_controller_spec.rb @@ -2,10 +2,12 @@ require 'spec_helper' -RSpec.describe Import::BulkImportsController do +RSpec.describe Import::BulkImportsController, feature_category: :importers do let_it_be(:user) { create(:user) } before do + stub_application_setting(bulk_import_enabled: true) + sign_in(user) end @@ -16,6 +18,13 @@ RSpec.describe Import::BulkImportsController do end describe 'POST configure' do + before do + allow_next_instance_of(BulkImports::Clients::HTTP) do |instance| + allow(instance).to receive(:validate_instance_version!).and_return(true) + allow(instance).to receive(:validate_import_scopes!).and_return(true) + end + end + context 'when no params are passed in' do it 'clears out existing session' do post :configure @@ -28,8 +37,57 @@ RSpec.describe Import::BulkImportsController do end end + context 'when URL is invalid' do + it 'redirects to initial import page' do + token = 'token' + url = 'http://192.168.0.1' + + post :configure, params: { bulk_import_gitlab_access_token: token, bulk_import_gitlab_url: url } + + expect(response).to redirect_to new_group_path(anchor: 'import-group-pane') + expect(flash[:alert]).to include('Specified URL cannot be used') + end + end + + context 'when token scope is invalid' do + before do + allow_next_instance_of(BulkImports::Clients::HTTP) do |instance| + allow(instance).to receive(:validate_instance_version!).and_return(true) + allow(instance).to receive(:validate_import_scopes!).and_raise(BulkImports::Error.new('Error!')) + end + end + + it 'redirects to initial import page' do + token = 'token' + url = 'https://gitlab.example' + + post :configure, params: { bulk_import_gitlab_access_token: token, bulk_import_gitlab_url: url } + + expect(response).to redirect_to new_group_path(anchor: 'import-group-pane') + expect(flash[:alert]).to include('Error!') + end + end + + context 'when instance version is incompatible' do + before do + allow_next_instance_of(BulkImports::Clients::HTTP) do |instance| + allow(instance).to receive(:validate_instance_version!).and_raise(BulkImports::Error.new('Error!')) + end + end + + it 'redirects to initial import page' do + token = 'token' + url = 'https://gitlab.example' + + post :configure, params: { bulk_import_gitlab_access_token: token, bulk_import_gitlab_url: url } + + expect(response).to redirect_to new_group_path(anchor: 'import-group-pane') + expect(flash[:alert]).to include('Error!') + end + end + it 'sets the session variables' do - token = 'token' + token = 'invalid token' url = 'https://gitlab.example' post :configure, params: { bulk_import_gitlab_access_token: token, bulk_import_gitlab_url: url } @@ -100,6 +158,18 @@ RSpec.describe Import::BulkImportsController do ) end + let(:source_version) do + Gitlab::VersionInfo.new(::BulkImport::MIN_MAJOR_VERSION, + ::BulkImport::MIN_MINOR_VERSION_FOR_PROJECT) + end + + before do + allow_next_instance_of(BulkImports::Clients::HTTP) do |instance| + allow(instance).to receive(:instance_version).and_return(source_version) + allow(instance).to receive(:instance_enterprise).and_return(false) + end + end + it 'returns serialized group data' do get_status @@ -201,8 +271,15 @@ RSpec.describe Import::BulkImportsController do end context 'when connection error occurs' do + let(:source_version) do + Gitlab::VersionInfo.new(::BulkImport::MIN_MAJOR_VERSION, + ::BulkImport::MIN_MINOR_VERSION_FOR_PROJECT) + end + before do allow_next_instance_of(BulkImports::Clients::HTTP) do |instance| + allow(instance).to receive(:instance_version).and_return(source_version) + allow(instance).to receive(:instance_enterprise).and_return(false) allow(instance).to receive(:get).and_raise(BulkImports::Error) end end @@ -326,9 +403,9 @@ RSpec.describe Import::BulkImportsController do end end - context 'when bulk_import feature flag is disabled' do + context 'when feature is disabled' do before do - stub_feature_flags(bulk_import: false) + stub_application_setting(bulk_import_enabled: false) end context 'POST configure' do |