summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2018-12-05 16:43:29 -0800
committerStan Hu <stanhu@gmail.com>2019-01-28 13:06:27 -0800
commiteafccaad7346d6e1f8d13024bb5295bc683ab046 (patch)
tree433d6ed6404f8c2edd77a03a6254c2884300974f /spec
parentc2b3f64cb44114e69ddeeb453412ad4dd762baf9 (diff)
downloadgitlab-ce-eafccaad7346d6e1f8d13024bb5295bc683ab046.tar.gz
Fix Bitbucket Server import not allowing personal projects
Bitbucket Server places personal projects in a namespace called `~username`. This change allows those projects and also strips them from the GitLab namespace. Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/53419
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/import/bitbucket_server_controller_spec.rb22
-rw-r--r--spec/helpers/import_helper_spec.rb4
2 files changed, 23 insertions, 3 deletions
diff --git a/spec/controllers/import/bitbucket_server_controller_spec.rb b/spec/controllers/import/bitbucket_server_controller_spec.rb
index bb282db5a41..a125e6ed16d 100644
--- a/spec/controllers/import/bitbucket_server_controller_spec.rb
+++ b/spec/controllers/import/bitbucket_server_controller_spec.rb
@@ -28,9 +28,11 @@ describe Import::BitbucketServerController do
end
describe 'POST create' do
+ let(:project_name) { "my-project_123" }
+
before do
allow(controller).to receive(:bitbucket_client).and_return(client)
- repo = double(name: 'my-project')
+ repo = double(name: project_name)
allow(client).to receive(:repo).with(project_key, repo_slug).and_return(repo)
assign_session_tokens
end
@@ -39,7 +41,7 @@ describe Import::BitbucketServerController do
it 'returns the new project' do
allow(Gitlab::BitbucketServerImport::ProjectCreator)
- .to receive(:new).with(project_key, repo_slug, anything, 'my-project', user.namespace, user, anything)
+ .to receive(:new).with(project_key, repo_slug, anything, project_name, user.namespace, user, anything)
.and_return(double(execute: project))
post :create, params: { project: project_key, repository: repo_slug }, format: :json
@@ -47,6 +49,20 @@ describe Import::BitbucketServerController do
expect(response).to have_gitlab_http_status(200)
end
+ context 'with project key with tildes' do
+ let(:project_key) { '~someuser_123' }
+
+ it 'successfully creates a project' do
+ allow(Gitlab::BitbucketServerImport::ProjectCreator)
+ .to receive(:new).with(project_key, repo_slug, anything, project_name, user.namespace, user, anything)
+ .and_return(double(execute: project))
+
+ post :create, params: { project: project_key, repository: repo_slug, format: :json }
+
+ expect(response).to have_gitlab_http_status(200)
+ end
+ end
+
it 'returns an error when an invalid project key is used' do
post :create, params: { project: 'some&project' }
@@ -69,7 +85,7 @@ describe Import::BitbucketServerController do
it 'returns an error when the project cannot be saved' do
allow(Gitlab::BitbucketServerImport::ProjectCreator)
- .to receive(:new).with(project_key, repo_slug, anything, 'my-project', user.namespace, user, anything)
+ .to receive(:new).with(project_key, repo_slug, anything, project_name, user.namespace, user, anything)
.and_return(double(execute: build(:project)))
post :create, params: { project: project_key, repository: repo_slug }, format: :json
diff --git a/spec/helpers/import_helper_spec.rb b/spec/helpers/import_helper_spec.rb
index cb0ea4e26ba..af4931e3370 100644
--- a/spec/helpers/import_helper_spec.rb
+++ b/spec/helpers/import_helper_spec.rb
@@ -2,6 +2,10 @@ require 'rails_helper'
describe ImportHelper do
describe '#sanitize_project_name' do
+ it 'removes leading tildes' do
+ expect(helper.sanitize_project_name('~~root')).to eq('root')
+ end
+
it 'removes whitespace' do
expect(helper.sanitize_project_name('my test repo')).to eq('my-test-repo')
end