summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorDouglas Barbosa Alexandre <dbalexandre@gmail.com>2018-10-11 17:45:07 -0300
committerDouglas Barbosa Alexandre <dbalexandre@gmail.com>2018-10-15 19:03:40 -0300
commit2e75e93c31848df37cb85043cc440ed8e1cce28b (patch)
treed1e5621391091959b8fdf535a808cff6cddaa3e9 /spec
parent0602fcb6bf0050f71e8b8f69e0328031f9386618 (diff)
downloadgitlab-ce-2e75e93c31848df37cb85043cc440ed8e1cce28b.tar.gz
Does not allow an import_url with SSH protocol
Diffstat (limited to 'spec')
-rw-r--r--spec/lib/gitlab/bitbucket_import/project_creator_spec.rb4
-rw-r--r--spec/models/project_spec.rb61
-rw-r--r--spec/services/projects/import_service_spec.rb2
3 files changed, 44 insertions, 23 deletions
diff --git a/spec/lib/gitlab/bitbucket_import/project_creator_spec.rb b/spec/lib/gitlab/bitbucket_import/project_creator_spec.rb
index ed6fa3d229f..e2bee22cf1f 100644
--- a/spec/lib/gitlab/bitbucket_import/project_creator_spec.rb
+++ b/spec/lib/gitlab/bitbucket_import/project_creator_spec.rb
@@ -11,7 +11,7 @@ describe Gitlab::BitbucketImport::ProjectCreator do
owner: "asd",
full_name: 'Vim repo',
visibility_level: Gitlab::VisibilityLevel::PRIVATE,
- clone_url: 'ssh://git@bitbucket.org/asd/vim.git',
+ clone_url: 'http://bitbucket.org/asd/vim.git',
has_wiki?: false)
end
@@ -32,7 +32,7 @@ describe Gitlab::BitbucketImport::ProjectCreator do
project_creator = described_class.new(repo, 'vim', namespace, user, access_params)
project = project_creator.execute
- expect(project.import_url).to eq("ssh://git@bitbucket.org/asd/vim.git")
+ expect(project.import_url).to eq("http://bitbucket.org/asd/vim.git")
expect(project.visibility_level).to eq(Gitlab::VisibilityLevel::PRIVATE)
end
end
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb
index 3fecddefff2..a807c336165 100644
--- a/spec/models/project_spec.rb
+++ b/spec/models/project_spec.rb
@@ -229,54 +229,75 @@ describe Project do
end
it 'does not allow an invalid URI as import_url' do
- project2 = build(:project, import_url: 'invalid://')
+ project = build(:project, import_url: 'invalid://')
- expect(project2).not_to be_valid
+ expect(project).not_to be_valid
+ end
+
+ it 'does allow a SSH URI as import_url for persisted projects' do
+ project = create(:project)
+ project.import_url = 'ssh://test@gitlab.com/project.git'
+
+ expect(project).to be_valid
+ end
+
+ it 'does not allow a SSH URI as import_url for new projects' do
+ project = build(:project, import_url: 'ssh://test@gitlab.com/project.git')
+
+ expect(project).not_to be_valid
end
it 'does allow a valid URI as import_url' do
- project2 = build(:project, import_url: 'ssh://test@gitlab.com/project.git')
+ project = build(:project, import_url: 'http://gitlab.com/project.git')
- expect(project2).to be_valid
+ expect(project).to be_valid
end
it 'allows an empty URI' do
- project2 = build(:project, import_url: '')
+ project = build(:project, import_url: '')
- expect(project2).to be_valid
+ expect(project).to be_valid
end
it 'does not produce import data on an empty URI' do
- project2 = build(:project, import_url: '')
+ project = build(:project, import_url: '')
- expect(project2.import_data).to be_nil
+ expect(project.import_data).to be_nil
end
it 'does not produce import data on an invalid URI' do
- project2 = build(:project, import_url: 'test://')
+ project = build(:project, import_url: 'test://')
- expect(project2.import_data).to be_nil
+ expect(project.import_data).to be_nil
end
it "does not allow import_url pointing to localhost" do
- project2 = build(:project, import_url: 'http://localhost:9000/t.git')
+ project = build(:project, import_url: 'http://localhost:9000/t.git')
+
+ expect(project).to be_invalid
+ expect(project.errors[:import_url].first).to include('Requests to localhost are not allowed')
+ end
+
+ it "does not allow import_url with invalid ports for new projects" do
+ project = build(:project, import_url: 'http://github.com:25/t.git')
- expect(project2).to be_invalid
- expect(project2.errors[:import_url].first).to include('Requests to localhost are not allowed')
+ expect(project).to be_invalid
+ expect(project.errors[:import_url].first).to include('Only allowed ports are 80, 443')
end
- it "does not allow import_url with invalid ports" do
- project2 = build(:project, import_url: 'http://github.com:25/t.git')
+ it "does not allow import_url with invalid ports for persisted projects" do
+ project = create(:project)
+ project.import_url = 'http://github.com:25/t.git'
- expect(project2).to be_invalid
- expect(project2.errors[:import_url].first).to include('Only allowed ports are 22, 80, 443')
+ expect(project).to be_invalid
+ expect(project.errors[:import_url].first).to include('Only allowed ports are 22, 80, 443')
end
it "does not allow import_url with invalid user" do
- project2 = build(:project, import_url: 'http://$user:password@github.com/t.git')
+ project = build(:project, import_url: 'http://$user:password@github.com/t.git')
- expect(project2).to be_invalid
- expect(project2.errors[:import_url].first).to include('Username needs to start with an alphanumeric character')
+ expect(project).to be_invalid
+ expect(project.errors[:import_url].first).to include('Username needs to start with an alphanumeric character')
end
describe 'project pending deletion' do
diff --git a/spec/services/projects/import_service_spec.rb b/spec/services/projects/import_service_spec.rb
index e2a600d12d1..e6ffa2b957b 100644
--- a/spec/services/projects/import_service_spec.rb
+++ b/spec/services/projects/import_service_spec.rb
@@ -235,7 +235,7 @@ describe Projects::ImportService do
result = described_class.new(project, user).execute
expect(result[:status]).to eq :error
- expect(result[:message]).to include('Only allowed ports are 22, 80, 443')
+ expect(result[:message]).to include('Only allowed ports are 80, 443')
end
end