summaryrefslogtreecommitdiff
path: root/spec/controllers/import
diff options
context:
space:
mode:
Diffstat (limited to 'spec/controllers/import')
-rw-r--r--spec/controllers/import/available_namespaces_controller_spec.rb109
-rw-r--r--spec/controllers/import/bulk_imports_controller_spec.rb85
-rw-r--r--spec/controllers/import/github_controller_spec.rb41
-rw-r--r--spec/controllers/import/phabricator_controller_spec.rb13
4 files changed, 118 insertions, 130 deletions
diff --git a/spec/controllers/import/available_namespaces_controller_spec.rb b/spec/controllers/import/available_namespaces_controller_spec.rb
deleted file mode 100644
index 26ea1d92189..00000000000
--- a/spec/controllers/import/available_namespaces_controller_spec.rb
+++ /dev/null
@@ -1,109 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-
-RSpec.describe Import::AvailableNamespacesController do
- let_it_be(:user) { create(:user) }
-
- before do
- sign_in(user)
- end
-
- describe "GET index" do
- context "when having group with role never allowed to create projects" do
- using RSpec::Parameterized::TableSyntax
-
- where(
- role: [:guest, :reporter],
- default_project_creation_access: [::Gitlab::Access::MAINTAINER_PROJECT_ACCESS, ::Gitlab::Access::DEVELOPER_MAINTAINER_PROJECT_ACCESS],
- group_project_creation_level: [nil, ::Gitlab::Access::MAINTAINER_PROJECT_ACCESS, ::Gitlab::Access::DEVELOPER_MAINTAINER_PROJECT_ACCESS])
-
- with_them do
- before do
- stub_application_setting(default_project_creation: default_project_creation_access)
- end
-
- it "does not include group with access level #{params[:role]} in list" do
- group = create(:group, project_creation_level: group_project_creation_level)
- group.add_member(user, role)
- get :index
-
- expect(response).to have_gitlab_http_status(:ok)
- expect(json_response).not_to include({
- 'id' => group.id,
- 'full_path' => group.full_path
- })
- end
- end
- end
-
- context "when having group with role always allowed to create projects" do
- using RSpec::Parameterized::TableSyntax
-
- where(
- role: [:maintainer, :owner],
- default_project_creation_access: [::Gitlab::Access::MAINTAINER_PROJECT_ACCESS, ::Gitlab::Access::DEVELOPER_MAINTAINER_PROJECT_ACCESS],
- group_project_creation_level: [nil, ::Gitlab::Access::MAINTAINER_PROJECT_ACCESS, ::Gitlab::Access::DEVELOPER_MAINTAINER_PROJECT_ACCESS])
-
- with_them do
- before do
- stub_application_setting(default_project_creation: default_project_creation_access)
- end
-
- it "does not include group with access level #{params[:role]} in list" do
- group = create(:group, project_creation_level: group_project_creation_level)
- group.add_member(user, role)
- get :index
-
- expect(response).to have_gitlab_http_status(:ok)
- expect(json_response).to include({
- 'id' => group.id,
- 'full_path' => group.full_path
- })
- end
- end
- end
-
- context "when having developer role" do
- using RSpec::Parameterized::TableSyntax
-
- where(:default_project_creation_access, :project_creation_level, :is_visible) do
- ::Gitlab::Access::MAINTAINER_PROJECT_ACCESS | nil | false
- ::Gitlab::Access::MAINTAINER_PROJECT_ACCESS | ::Gitlab::Access::DEVELOPER_MAINTAINER_PROJECT_ACCESS | true
- ::Gitlab::Access::DEVELOPER_MAINTAINER_PROJECT_ACCESS | nil | true
- ::Gitlab::Access::DEVELOPER_MAINTAINER_PROJECT_ACCESS | ::Gitlab::Access::MAINTAINER_PROJECT_ACCESS | false
- end
-
- with_them do
- before do
- stub_application_setting(default_project_creation: default_project_creation_access)
- end
-
- it "#{params[:is_visible] ? 'includes' : 'does not include'} group with access level #{params[:role]} in list" do
- group = create(:group, project_creation_level: project_creation_level)
- group.add_member(user, :developer)
-
- get :index
-
- expect(response).to have_gitlab_http_status(:ok)
- expect(json_response).send(is_visible ? 'to' : 'not_to', include({
- 'id' => group.id,
- 'full_path' => group.full_path
- }))
- end
- end
- end
-
- context "with an anonymous user" do
- before do
- sign_out(user)
- end
-
- it "redirects to sign-in page" do
- get :index
-
- expect(response).to redirect_to(new_user_session_path)
- end
- end
- end
-end
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
diff --git a/spec/controllers/import/github_controller_spec.rb b/spec/controllers/import/github_controller_spec.rb
index a85af89b262..c1a61a78d80 100644
--- a/spec/controllers/import/github_controller_spec.rb
+++ b/spec/controllers/import/github_controller_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-RSpec.describe Import::GithubController do
+RSpec.describe Import::GithubController, feature_category: :import do
include ImportSpecHelper
let(:provider) { :github }
@@ -138,7 +138,7 @@ RSpec.describe Import::GithubController do
it 'calls repos list from provider with expected args' do
expect_next_instance_of(Gitlab::GithubImport::Clients::Proxy) do |client|
expect(client).to receive(:repos)
- .with(expected_filter, expected_pagination_options)
+ .with(expected_filter, expected_options)
.and_return({ repos: [], page_info: {} })
end
@@ -155,11 +155,16 @@ RSpec.describe Import::GithubController do
let(:provider_token) { 'asdasd12345' }
let(:client_auth_success) { true }
let(:client_stub) { instance_double(Gitlab::GithubImport::Client, user: { login: 'user' }) }
- let(:expected_pagination_options) { pagination_params.merge(first: 25, page: 1, per_page: 25) }
- let(:expected_filter) { nil }
let(:params) { nil }
let(:pagination_params) { { before: nil, after: nil } }
+ let(:relation_params) { { relation_type: nil, organization_login: '' } }
let(:provider_repos) { [] }
+ let(:expected_filter) { '' }
+ let(:expected_options) do
+ pagination_params.merge(relation_params).merge(
+ first: 25, page: 1, per_page: 25
+ )
+ end
before do
allow_next_instance_of(Gitlab::GithubImport::Clients::Proxy) do |proxy|
@@ -277,8 +282,34 @@ RSpec.describe Import::GithubController do
context 'when page is specified' do
let(:pagination_params) { { before: nil, after: nil, page: 2 } }
- let(:expected_pagination_options) { pagination_params.merge(first: 25, page: 2, per_page: 25) }
let(:params) { pagination_params }
+ let(:expected_options) do
+ pagination_params.merge(relation_params).merge(first: 25, page: 2, per_page: 25)
+ end
+
+ it_behaves_like 'calls repos through Clients::Proxy with expected args'
+ end
+ end
+
+ context 'when relation type params present' do
+ let(:organization_login) { 'test-login' }
+ let(:params) { pagination_params.merge(relation_type: 'organization', organization_login: organization_login) }
+ let(:pagination_defaults) { { first: 25, page: 1, per_page: 25 } }
+ let(:expected_options) do
+ pagination_defaults.merge(pagination_params).merge(
+ relation_type: 'organization', organization_login: organization_login
+ )
+ end
+
+ it_behaves_like 'calls repos through Clients::Proxy with expected args'
+
+ context 'when organization_login is too long and with ":"' do
+ let(:organization_login) { ":#{Array.new(270) { ('a'..'z').to_a.sample }.join}" }
+ let(:expected_options) do
+ pagination_defaults.merge(pagination_params).merge(
+ relation_type: 'organization', organization_login: organization_login.slice(1, 254)
+ )
+ end
it_behaves_like 'calls repos through Clients::Proxy with expected args'
end
diff --git a/spec/controllers/import/phabricator_controller_spec.rb b/spec/controllers/import/phabricator_controller_spec.rb
index 9827a6d077c..9be85a40d82 100644
--- a/spec/controllers/import/phabricator_controller_spec.rb
+++ b/spec/controllers/import/phabricator_controller_spec.rb
@@ -14,25 +14,14 @@ RSpec.describe Import::PhabricatorController do
context 'when the import source is not available' do
before do
- stub_feature_flags(phabricator_import: true)
stub_application_setting(import_sources: [])
end
it { is_expected.to have_gitlab_http_status(:not_found) }
end
- context 'when the feature is disabled' do
+ context 'when the import source is available' do
before do
- stub_feature_flags(phabricator_import: false)
- stub_application_setting(import_sources: ['phabricator'])
- end
-
- it { is_expected.to have_gitlab_http_status(:not_found) }
- end
-
- context 'when the import is available' do
- before do
- stub_feature_flags(phabricator_import: true)
stub_application_setting(import_sources: ['phabricator'])
end