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>2023-01-18 22:00:14 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-01-18 22:00:14 +0300
commit05f0ebba3a2c8ddf39e436f412dc2ab5bf1353b2 (patch)
tree11d0f2a6ec31c7793c184106cedc2ded3d9a2cc5 /spec/services/import
parentec73467c23693d0db63a797d10194da9e72a74af (diff)
Add latest changes from gitlab-org/gitlab@15-8-stable-eev15.8.0-rc42
Diffstat (limited to 'spec/services/import')
-rw-r--r--spec/services/import/github/gists_import_service_spec.rb26
-rw-r--r--spec/services/import/github_service_spec.rb56
2 files changed, 75 insertions, 7 deletions
diff --git a/spec/services/import/github/gists_import_service_spec.rb b/spec/services/import/github/gists_import_service_spec.rb
index c5d73e6479d..32d04a580da 100644
--- a/spec/services/import/github/gists_import_service_spec.rb
+++ b/spec/services/import/github/gists_import_service_spec.rb
@@ -2,16 +2,19 @@
require 'spec_helper'
-RSpec.describe Import::Github::GistsImportService, feature_category: :importer do
- subject(:import) { described_class.new(user, params) }
+RSpec.describe Import::Github::GistsImportService, feature_category: :importers do
+ subject(:import) { described_class.new(user, client, params) }
let_it_be(:user) { create(:user) }
let(:params) { { github_access_token: 'token' } }
let(:import_status) { instance_double('Gitlab::GithubGistsImport::Status') }
+ let(:client) { Gitlab::GithubImport::Client.new(params[:github_access_token]) }
+ let(:octokit_user) { { login: 'user_login' } }
describe '#execute', :aggregate_failures do
before do
allow(Gitlab::GithubGistsImport::Status).to receive(:new).and_return(import_status)
+ allow(client.octokit).to receive(:user).and_return(octokit_user)
end
context 'when import in progress' do
@@ -43,5 +46,24 @@ RSpec.describe Import::Github::GistsImportService, feature_category: :importer d
expect(import.execute).to eq({ status: :success })
end
end
+
+ context 'when user token is invalid' do
+ before do
+ allow(client.octokit).to receive(:user).and_raise(Octokit::Unauthorized)
+ allow(import_status).to receive(:started?).and_return(false)
+ end
+
+ let(:expected_result) do
+ {
+ http_status: 401,
+ message: 'Access denied to the GitHub account.',
+ status: :error
+ }
+ end
+
+ it 'returns 401 error' do
+ expect(import.execute).to eq(expected_result)
+ end
+ end
end
end
diff --git a/spec/services/import/github_service_spec.rb b/spec/services/import/github_service_spec.rb
index d1b372c5e87..293e247c140 100644
--- a/spec/services/import/github_service_spec.rb
+++ b/spec/services/import/github_service_spec.rb
@@ -7,22 +7,19 @@ RSpec.describe Import::GithubService do
let_it_be(:token) { 'complex-token' }
let_it_be(:access_params) { { github_access_token: 'github-complex-token' } }
let(:settings) { instance_double(Gitlab::GithubImport::Settings) }
+ let(:user_namespace_path) { user.namespace_path }
let(:optional_stages) { nil }
let(:params) do
{
repo_id: 123,
new_name: 'new_repo',
- target_namespace: 'root',
+ target_namespace: user_namespace_path,
optional_stages: optional_stages
}
end
subject(:github_importer) { described_class.new(client, user, params) }
- before do
- allow(subject).to receive(:authorized?).and_return(true)
- end
-
shared_examples 'handles errors' do |klass|
let(:client) { klass.new(token) }
let(:project_double) { instance_double(Project, persisted?: true) }
@@ -74,6 +71,7 @@ RSpec.describe Import::GithubService do
let(:repository_double) { { name: 'repository', size: 99 } }
before do
+ allow(subject).to receive(:authorized?).and_return(true)
expect(client).to receive(:repository).and_return(repository_double)
allow_next_instance_of(Gitlab::LegacyGithubImport::ProjectCreator) do |creator|
@@ -215,6 +213,38 @@ RSpec.describe Import::GithubService do
end
end
end
+
+ context 'when target_namespace is blank' do
+ before do
+ params[:target_namespace] = ''
+ end
+
+ it 'raises an exception' do
+ expect { subject.execute(access_params, :github) }.to raise_error(ArgumentError, 'Target namespace is required')
+ end
+ end
+
+ context 'when namespace to import repository into does not exist' do
+ before do
+ params[:target_namespace] = 'unknown_path'
+ end
+
+ it 'returns an error' do
+ expect(github_importer.execute(access_params, :github)).to include(not_existed_namespace_error)
+ end
+ end
+
+ context 'when user has no permissions to import repository into the specified namespace' do
+ let_it_be(:group) { create(:group) }
+
+ before do
+ params[:target_namespace] = group.full_path
+ end
+
+ it 'returns an error' do
+ expect(github_importer.execute(access_params, :github)).to include(taken_namespace_error)
+ end
+ end
end
context 'when remove_legacy_github_client feature flag is enabled' do
@@ -248,4 +278,20 @@ RSpec.describe Import::GithubService do
message: "Invalid URL: #{url}"
}
end
+
+ def not_existed_namespace_error
+ {
+ status: :error,
+ http_status: :unprocessable_entity,
+ message: 'Namespace or group to import repository into does not exist.'
+ }
+ end
+
+ def taken_namespace_error
+ {
+ status: :error,
+ http_status: :unprocessable_entity,
+ message: 'This namespace has already been taken. Choose a different one.'
+ }
+ end
end