summaryrefslogtreecommitdiff
path: root/spec/requests/api/projects_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/requests/api/projects_spec.rb')
-rw-r--r--spec/requests/api/projects_spec.rb31
1 files changed, 30 insertions, 1 deletions
diff --git a/spec/requests/api/projects_spec.rb b/spec/requests/api/projects_spec.rb
index dd6afa869e0..4f84e6f2562 100644
--- a/spec/requests/api/projects_spec.rb
+++ b/spec/requests/api/projects_spec.rb
@@ -48,6 +48,7 @@ end
RSpec.describe API::Projects do
include ProjectForksHelper
+ include StubRequests
let_it_be(:user) { create(:user) }
let_it_be(:user2) { create(:user) }
@@ -358,7 +359,7 @@ RSpec.describe API::Projects do
statistics = json_response.find { |p| p['id'] == project.id }['statistics']
expect(statistics).to be_present
- expect(statistics).to include('commit_count', 'storage_size', 'repository_size', 'wiki_size', 'lfs_objects_size', 'job_artifacts_size', 'snippets_size', 'packages_size')
+ expect(statistics).to include('commit_count', 'storage_size', 'repository_size', 'wiki_size', 'lfs_objects_size', 'job_artifacts_size', 'pipeline_artifacts_size', 'snippets_size', 'packages_size', 'uploads_size')
end
it "does not include license by default" do
@@ -1159,6 +1160,34 @@ RSpec.describe API::Projects do
expect(response).to have_gitlab_http_status(:forbidden)
end
+ it 'disallows creating a project with an import_url that is not reachable', :aggregate_failures do
+ url = 'http://example.com'
+ endpoint_url = "#{url}/info/refs?service=git-upload-pack"
+ stub_full_request(endpoint_url, method: :get).to_return({ status: 301, body: '', headers: nil })
+ project_params = { import_url: url, path: 'path-project-Foo', name: 'Foo Project' }
+
+ expect { post api('/projects', user), params: project_params }.not_to change { Project.count }
+
+ expect(response).to have_gitlab_http_status(:unprocessable_entity)
+ expect(json_response['message']).to eq("#{url} is not a valid HTTP Git repository")
+ end
+
+ it 'creates a project with an import_url that is valid', :aggregate_failures do
+ url = 'http://example.com'
+ endpoint_url = "#{url}/info/refs?service=git-upload-pack"
+ git_response = {
+ status: 200,
+ body: '001e# service=git-upload-pack',
+ headers: { 'Content-Type': 'application/x-git-upload-pack-advertisement' }
+ }
+ stub_full_request(endpoint_url, method: :get).to_return(git_response)
+ project_params = { import_url: url, path: 'path-project-Foo', name: 'Foo Project' }
+
+ expect { post api('/projects', user), params: project_params }.to change { Project.count }.by(1)
+
+ expect(response).to have_gitlab_http_status(:created)
+ end
+
it 'sets a project as public' do
project = attributes_for(:project, visibility: 'public')