diff options
Diffstat (limited to 'spec/controllers/import/bulk_imports_controller_spec.rb')
-rw-r--r-- | spec/controllers/import/bulk_imports_controller_spec.rb | 65 |
1 files changed, 34 insertions, 31 deletions
diff --git a/spec/controllers/import/bulk_imports_controller_spec.rb b/spec/controllers/import/bulk_imports_controller_spec.rb index a3992ae850e..c5e5aa03669 100644 --- a/spec/controllers/import/bulk_imports_controller_spec.rb +++ b/spec/controllers/import/bulk_imports_controller_spec.rb @@ -121,12 +121,12 @@ RSpec.describe Import::BulkImportsController, feature_category: :importers do params = { page: 1, per_page: 20, filter: '' }.merge(params_override) get :status, - params: params, - format: format, - session: { - bulk_import_gitlab_url: 'https://gitlab.example.com', - bulk_import_gitlab_access_token: 'demo-pat' - } + params: params, + format: format, + session: { + bulk_import_gitlab_url: 'https://gitlab.example.com', + bulk_import_gitlab_access_token: 'demo-pat' + } end include_context 'bulk imports requests context', 'https://gitlab.example.com' @@ -157,8 +157,7 @@ RSpec.describe Import::BulkImportsController, feature_category: :importers do end let(:source_version) do - Gitlab::VersionInfo.new(::BulkImport::MIN_MAJOR_VERSION, - ::BulkImport::MIN_MINOR_VERSION_FOR_PROJECT) + Gitlab::VersionInfo.new(::BulkImport::MIN_MAJOR_VERSION, ::BulkImport::MIN_MINOR_VERSION_FOR_PROJECT) end before do @@ -214,36 +213,41 @@ RSpec.describe Import::BulkImportsController, feature_category: :importers do end end - context 'when host url is local or not http' do - %w[https://localhost:3000 http://192.168.0.1 ftp://testing].each do |url| - before do - stub_application_setting(allow_local_requests_from_web_hooks_and_services: false) - - session[:bulk_import_gitlab_access_token] = 'test' - session[:bulk_import_gitlab_url] = url - end + shared_examples 'unacceptable url' do |url, expected_error| + before do + stub_application_setting(allow_local_requests_from_web_hooks_and_services: false) - it 'denies network request' do - get :status + session[:bulk_import_gitlab_access_token] = 'test' + session[:bulk_import_gitlab_url] = url + end - expect(controller).to redirect_to(new_group_path(anchor: 'import-group-pane')) - expect(flash[:alert]).to eq('Specified URL cannot be used: "Only allowed schemes are http, https"') - end + it 'denies network request' do + get :status + expect(controller).to redirect_to(new_group_path(anchor: 'import-group-pane')) + expect(flash[:alert]).to eq("Specified URL cannot be used: \"#{expected_error}\"") end + end + + context 'when host url is local or not http' do + include_examples 'unacceptable url', 'https://localhost:3000', "Only allowed schemes are http, https" + include_examples 'unacceptable url', 'http://192.168.0.1', "Only allowed schemes are http, https" + include_examples 'unacceptable url', 'ftp://testing', "Only allowed schemes are http, https" context 'when local requests are allowed' do %w[https://localhost:3000 http://192.168.0.1].each do |url| - before do - stub_application_setting(allow_local_requests_from_web_hooks_and_services: true) + context "with #{url}" do + before do + stub_application_setting(allow_local_requests_from_web_hooks_and_services: true) - session[:bulk_import_gitlab_access_token] = 'test' - session[:bulk_import_gitlab_url] = url - end + session[:bulk_import_gitlab_access_token] = 'test' + session[:bulk_import_gitlab_url] = url + end - it 'allows network request' do - get :status + it 'allows network request' do + get :status - expect(response).to have_gitlab_http_status(:ok) + expect(response).to have_gitlab_http_status(:ok) + end end end end @@ -270,8 +274,7 @@ RSpec.describe Import::BulkImportsController, feature_category: :importers do context 'when connection error occurs' do let(:source_version) do - Gitlab::VersionInfo.new(::BulkImport::MIN_MAJOR_VERSION, - ::BulkImport::MIN_MINOR_VERSION_FOR_PROJECT) + Gitlab::VersionInfo.new(::BulkImport::MIN_MAJOR_VERSION, ::BulkImport::MIN_MINOR_VERSION_FOR_PROJECT) end before do |