Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-10-20 12:40:42 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-10-20 12:40:42 +0300
commitee664acb356f8123f4f6b00b73c1e1cf0866c7fb (patch)
treef8479f94a28f66654c6a4f6fb99bad6b4e86a40e /spec/controllers/import
parent62f7d5c5b69180e82ae8196b7b429eeffc8e7b4f (diff)
Add latest changes from gitlab-org/gitlab@15-5-stable-eev15.5.0-rc42
Diffstat (limited to 'spec/controllers/import')
-rw-r--r--spec/controllers/import/bulk_imports_controller_spec.rb23
-rw-r--r--spec/controllers/import/github_controller_spec.rb103
2 files changed, 100 insertions, 26 deletions
diff --git a/spec/controllers/import/bulk_imports_controller_spec.rb b/spec/controllers/import/bulk_imports_controller_spec.rb
index 3be12717664..a0bb39f3e98 100644
--- a/spec/controllers/import/bulk_imports_controller_spec.rb
+++ b/spec/controllers/import/bulk_imports_controller_spec.rb
@@ -247,10 +247,10 @@ RSpec.describe Import::BulkImportsController do
"source_full_path" => "full_path",
"destination_slug" => "destination_name",
"destination_namespace" => "root" },
- { "source_type" => "group_entity2",
- "source_full_path" => "full_path2",
- "destination_slug" => "destination_name2",
- "destination_namespace" => "root" }]
+ { "source_type" => "group_entity",
+ "source_full_path" => "full_path",
+ "destination_slug" => "destination_name",
+ "destination_namespace" => "invalid-namespace" }]
end
before do
@@ -308,6 +308,21 @@ RSpec.describe Import::BulkImportsController do
expect(json_response).to match_array([{ "success" => true, "id" => bulk_import.id, "message" => nil }])
end
end
+
+ context 'when source type is project' do
+ let(:bulk_import_params) do
+ [{ "source_type" => "project_entity",
+ "source_full_path" => "full_path",
+ "destination_slug" => "destination_name",
+ "destination_namespace" => "root" }]
+ end
+
+ it 'returns 422' do
+ post :create, params: { bulk_import: bulk_import_params }
+
+ expect(response).to have_gitlab_http_status(:unprocessable_entity)
+ end
+ end
end
end
diff --git a/spec/controllers/import/github_controller_spec.rb b/spec/controllers/import/github_controller_spec.rb
index 269eb62cae6..f3632e7370c 100644
--- a/spec/controllers/import/github_controller_spec.rb
+++ b/spec/controllers/import/github_controller_spec.rb
@@ -44,13 +44,6 @@ RSpec.describe Import::GithubController do
end
describe "GET callback" do
- before do
- allow(controller).to receive(:get_token).and_return(token)
- allow(controller).to receive(:oauth_options).and_return({})
-
- stub_omniauth_provider('github')
- end
-
context "when auth state param is missing from session" do
it "reports an error" do
get :callback
@@ -63,17 +56,31 @@ RSpec.describe Import::GithubController do
context "when auth state param is present in session" do
let(:valid_auth_state) { "secret-state" }
- before do
- session[:github_auth_state_key] = valid_auth_state
- end
+ context 'when remove_legacy_github_client feature is disabled' do
+ before do
+ stub_feature_flags(remove_legacy_github_client: false)
+ allow_next_instance_of(Gitlab::LegacyGithubImport::Client) do |client|
+ allow(client).to receive(:get_token).and_return(token)
+ end
+ session[:github_auth_state_key] = valid_auth_state
+ end
+
+ it "updates access token if state param is valid" do
+ token = "asdasd12345"
- it "updates access token if state param is valid" do
- token = "asdasd12345"
+ get :callback, params: { state: valid_auth_state }
- get :callback, params: { state: valid_auth_state }
+ expect(session[:github_access_token]).to eq(token)
+ expect(controller).to redirect_to(status_import_github_url)
+ end
+
+ it "includes namespace_id from query params if it is present" do
+ namespace_id = 1
+
+ get :callback, params: { state: valid_auth_state, namespace_id: namespace_id }
- expect(session[:github_access_token]).to eq(token)
- expect(controller).to redirect_to(status_import_github_url)
+ expect(controller).to redirect_to(status_import_github_url(namespace_id: namespace_id))
+ end
end
it "reports an error if state param is invalid" do
@@ -83,12 +90,31 @@ RSpec.describe Import::GithubController do
expect(flash[:alert]).to eq('Access denied to your GitHub account.')
end
- it "includes namespace_id from query params if it is present" do
- namespace_id = 1
+ context 'when remove_legacy_github_client feature is enabled' do
+ before do
+ stub_feature_flags(remove_legacy_github_client: true)
+ allow_next_instance_of(OAuth2::Client) do |client|
+ allow(client).to receive_message_chain(:auth_code, :get_token, :token).and_return(token)
+ end
+ session[:github_auth_state_key] = valid_auth_state
+ end
+
+ it "updates access token if state param is valid" do
+ token = "asdasd12345"
- get :callback, params: { state: valid_auth_state, namespace_id: namespace_id }
+ get :callback, params: { state: valid_auth_state }
+
+ expect(session[:github_access_token]).to eq(token)
+ expect(controller).to redirect_to(status_import_github_url)
+ end
- expect(controller).to redirect_to(status_import_github_url(namespace_id: namespace_id))
+ it "includes namespace_id from query params if it is present" do
+ namespace_id = 1
+
+ get :callback, params: { state: valid_auth_state, namespace_id: namespace_id }
+
+ expect(controller).to redirect_to(status_import_github_url(namespace_id: namespace_id))
+ end
end
end
end
@@ -218,7 +244,7 @@ RSpec.describe Import::GithubController do
it 'makes request to github search api' do
expect_next_instance_of(Octokit::Client) do |client|
- expect(client).to receive(:user).and_return(double(login: user_login))
+ expect(client).to receive(:user).and_return({ login: user_login })
expect(client).to receive(:search_repositories).with(search_query, { page: 1, per_page: 25 }).and_return({ items: [].to_enum })
end
@@ -234,7 +260,7 @@ RSpec.describe Import::GithubController do
context 'when no page is specified' do
it 'requests first page' do
expect_next_instance_of(Octokit::Client) do |client|
- expect(client).to receive(:user).and_return(double(login: user_login))
+ expect(client).to receive(:user).and_return({ login: user_login })
expect(client).to receive(:search_repositories).with(search_query, { page: 1, per_page: 25 }).and_return({ items: [].to_enum })
end
@@ -250,7 +276,7 @@ RSpec.describe Import::GithubController do
context 'when page is specified' do
it 'requests repos with specified page' do
expect_next_instance_of(Octokit::Client) do |client|
- expect(client).to receive(:user).and_return(double(login: user_login))
+ expect(client).to receive(:user).and_return({ login: user_login })
expect(client).to receive(:search_repositories).with(search_query, { page: 2, per_page: 25 }).and_return({ items: [].to_enum })
end
@@ -321,4 +347,37 @@ RSpec.describe Import::GithubController do
expect(json_response[0]['stats']).to include('imported')
end
end
+
+ describe "POST cancel" do
+ let_it_be(:project) { create(:project, :import_started, import_type: 'github', import_url: 'https://fake.url') }
+
+ context 'when project import was canceled' do
+ before do
+ allow(Import::Github::CancelProjectImportService)
+ .to receive(:new).with(project, user)
+ .and_return(double(execute: { status: :success, project: project }))
+ end
+
+ it 'returns success' do
+ post :cancel, params: { project_id: project.id }
+
+ expect(response).to have_gitlab_http_status(:ok)
+ end
+ end
+
+ context 'when project import was not canceled' do
+ before do
+ allow(Import::Github::CancelProjectImportService)
+ .to receive(:new).with(project, user)
+ .and_return(double(execute: { status: :error, message: 'The import cannot be canceled because it is finished', http_status: :bad_request }))
+ end
+
+ it 'returns error' do
+ post :cancel, params: { project_id: project.id }
+
+ expect(response).to have_gitlab_http_status(:bad_request)
+ expect(json_response['errors']).to eq('The import cannot be canceled because it is finished')
+ end
+ end
+ end
end