summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/controllers/projects/merge_requests/diffs_controller.rb5
-rw-r--r--app/controllers/projects_controller.rb2
-rw-r--r--app/models/application_setting_implementation.rb1
-rw-r--r--spec/controllers/projects/merge_requests/diffs_controller_spec.rb22
-rw-r--r--spec/controllers/projects_controller_spec.rb17
-rw-r--r--spec/models/application_setting_spec.rb79
-rw-r--r--spec/services/submit_usage_ping_service_spec.rb8
7 files changed, 130 insertions, 4 deletions
diff --git a/app/controllers/projects/merge_requests/diffs_controller.rb b/app/controllers/projects/merge_requests/diffs_controller.rb
index 3eaabfbf33e..f125952cb97 100644
--- a/app/controllers/projects/merge_requests/diffs_controller.rb
+++ b/app/controllers/projects/merge_requests/diffs_controller.rb
@@ -163,7 +163,10 @@ class Projects::MergeRequests::DiffsController < Projects::MergeRequests::Applic
end
def render_merge_ref_head_diff?
- Gitlab::Utils.to_boolean(params[:diff_head]) && @merge_request.diffable_merge_ref? && @start_sha.nil?
+ params[:diff_id].blank? &&
+ Gitlab::Utils.to_boolean(params[:diff_head]) &&
+ @merge_request.diffable_merge_ref? &&
+ @start_sha.nil?
end
def note_positions
diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb
index e66893ac269..fb977a5ee42 100644
--- a/app/controllers/projects_controller.rb
+++ b/app/controllers/projects_controller.rb
@@ -510,7 +510,7 @@ class ProjectsController < Projects::ApplicationController
# `project` calls `find_routable!`, so this will trigger the usual not-found
# behaviour when the user isn't authorized to see the project
- return unless project
+ return if project.nil? || performed?
redirect_to(request.original_url.sub(%r{\.git/?\Z}, ''))
end
diff --git a/app/models/application_setting_implementation.rb b/app/models/application_setting_implementation.rb
index 5ff1c653f9e..bf9df3b9efc 100644
--- a/app/models/application_setting_implementation.rb
+++ b/app/models/application_setting_implementation.rb
@@ -374,6 +374,7 @@ module ApplicationSettingImplementation
def usage_ping_enabled
usage_ping_can_be_configured? && super
end
+ alias_method :usage_ping_enabled?, :usage_ping_enabled
def allowed_key_types
SUPPORTED_KEY_TYPES.select do |type|
diff --git a/spec/controllers/projects/merge_requests/diffs_controller_spec.rb b/spec/controllers/projects/merge_requests/diffs_controller_spec.rb
index 989f941caea..4fcb63ac616 100644
--- a/spec/controllers/projects/merge_requests/diffs_controller_spec.rb
+++ b/spec/controllers/projects/merge_requests/diffs_controller_spec.rb
@@ -69,6 +69,20 @@ RSpec.describe Projects::MergeRequests::DiffsController do
end
end
+ shared_examples 'show the right diff files with previous diff_id' do
+ context 'with previous diff_id' do
+ let!(:merge_request_diff_1) { merge_request.merge_request_diffs.create!(head_commit_sha: '6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9') }
+ let!(:merge_request_diff_2) { merge_request.merge_request_diffs.create!(head_commit_sha: '5937ac0a7beb003549fc5fd26fc247adbce4a52e', diff_type: :merge_head) }
+
+ subject { go(diff_id: merge_request_diff_1.id, diff_head: true) }
+
+ it 'shows the right diff files' do
+ subject
+ expect(json_response["diff_files"].size).to eq(merge_request_diff_1.files_count)
+ end
+ end
+ end
+
let(:project) { create(:project, :repository) }
let(:user) { create(:user) }
let(:merge_request) { create(:merge_request_with_diffs, target_project: project, source_project: project) }
@@ -142,6 +156,8 @@ RSpec.describe Projects::MergeRequests::DiffsController do
it_behaves_like '404 for unexistent diffable'
+ it_behaves_like 'show the right diff files with previous diff_id'
+
context 'when not authorized' do
let(:another_user) { create(:user) }
@@ -480,6 +496,8 @@ RSpec.describe Projects::MergeRequests::DiffsController do
it_behaves_like '404 for unexistent diffable'
+ it_behaves_like 'show the right diff files with previous diff_id'
+
context 'when not authorized' do
let(:other_user) { create(:user) }
@@ -499,7 +517,7 @@ RSpec.describe Projects::MergeRequests::DiffsController do
it_behaves_like 'serializes diffs with expected arguments' do
let(:collection) { Gitlab::Diff::FileCollection::MergeRequestDiffBatch }
- let(:expected_options) { collection_arguments(current_page: 1, total_pages: 1) }
+ let(:expected_options) { collection_arguments(current_page: 1, total_pages: 1).merge(merge_ref_head_diff: false) }
end
it_behaves_like 'successful request'
@@ -522,7 +540,7 @@ RSpec.describe Projects::MergeRequests::DiffsController do
it_behaves_like 'serializes diffs with expected arguments' do
let(:collection) { Gitlab::Diff::FileCollection::Compare }
- let(:expected_options) { collection_arguments }
+ let(:expected_options) { collection_arguments.merge(merge_ref_head_diff: false) }
end
it_behaves_like 'successful request'
diff --git a/spec/controllers/projects_controller_spec.rb b/spec/controllers/projects_controller_spec.rb
index ffe2d393b1e..fdc687496b7 100644
--- a/spec/controllers/projects_controller_spec.rb
+++ b/spec/controllers/projects_controller_spec.rb
@@ -375,6 +375,23 @@ RSpec.describe ProjectsController do
end
end
+ context 'when project is moved and git format is requested' do
+ let(:old_path) { project.path + 'old' }
+
+ before do
+ project.redirect_routes.create!(path: "#{project.namespace.full_path}/#{old_path}")
+
+ project.add_developer(user)
+ sign_in(user)
+ end
+
+ it 'redirects to new project path' do
+ get :show, params: { namespace_id: project.namespace, id: old_path }, format: :git
+
+ expect(response).to redirect_to(project_path(project, format: :git))
+ end
+ end
+
context 'when the project is forked and has a repository', :request_store do
let(:public_project) { create(:project, :public, :repository) }
let(:other_user) { create(:user) }
diff --git a/spec/models/application_setting_spec.rb b/spec/models/application_setting_spec.rb
index 4b4e7820f7a..c13d83d1685 100644
--- a/spec/models/application_setting_spec.rb
+++ b/spec/models/application_setting_spec.rb
@@ -363,6 +363,85 @@ RSpec.describe ApplicationSetting do
.is_less_than(65536)
end
+ describe 'usage_ping_enabled setting' do
+ shared_examples 'usage ping enabled' do
+ it do
+ expect(setting.usage_ping_enabled).to eq(true)
+ expect(setting.usage_ping_enabled?).to eq(true)
+ end
+ end
+
+ shared_examples 'usage ping disabled' do
+ it do
+ expect(setting.usage_ping_enabled).to eq(false)
+ expect(setting.usage_ping_enabled?).to eq(false)
+ end
+ end
+
+ context 'when setting is in database' do
+ context 'with usage_ping_enabled disabled' do
+ before do
+ setting.update!(usage_ping_enabled: false)
+ end
+
+ it_behaves_like 'usage ping disabled'
+ end
+
+ context 'with usage_ping_enabled enabled' do
+ before do
+ setting.update!(usage_ping_enabled: true)
+ end
+
+ it_behaves_like 'usage ping enabled'
+ end
+ end
+
+ context 'when setting is in GitLab config' do
+ context 'with usage_ping_enabled disabled' do
+ before do
+ allow(Settings.gitlab).to receive(:usage_ping_enabled).and_return(false)
+ end
+
+ it_behaves_like 'usage ping disabled'
+ end
+
+ context 'with usage_ping_enabled enabled' do
+ before do
+ allow(Settings.gitlab).to receive(:usage_ping_enabled).and_return(true)
+ end
+
+ it_behaves_like 'usage ping enabled'
+ end
+ end
+
+ context 'when setting in database false and setting in GitLab config true' do
+ before do
+ setting.update!(usage_ping_enabled: false)
+ allow(Settings.gitlab).to receive(:usage_ping_enabled).and_return(true)
+ end
+
+ it_behaves_like 'usage ping disabled'
+ end
+
+ context 'when setting database true and setting in GitLab config false' do
+ before do
+ setting.update!(usage_ping_enabled: true)
+ allow(Settings.gitlab).to receive(:usage_ping_enabled).and_return(false)
+ end
+
+ it_behaves_like 'usage ping disabled'
+ end
+
+ context 'when setting database true and setting in GitLab config true' do
+ before do
+ setting.update!(usage_ping_enabled: true)
+ allow(Settings.gitlab).to receive(:usage_ping_enabled).and_return(true)
+ end
+
+ it_behaves_like 'usage ping enabled'
+ end
+ end
+
context 'key restrictions' do
it 'supports all key types' do
expect(described_class::SUPPORTED_KEY_TYPES).to contain_exactly(:rsa, :dsa, :ecdsa, :ed25519)
diff --git a/spec/services/submit_usage_ping_service_spec.rb b/spec/services/submit_usage_ping_service_spec.rb
index a9f1b2c2b2d..7133dc35fc3 100644
--- a/spec/services/submit_usage_ping_service_spec.rb
+++ b/spec/services/submit_usage_ping_service_spec.rb
@@ -90,6 +90,14 @@ RSpec.describe SubmitUsagePingService do
it_behaves_like 'does not run'
end
+ context 'when usage ping is disabled from GitLab config file' do
+ before do
+ stub_config_setting(usage_ping_enabled: false)
+ end
+
+ it_behaves_like 'does not run'
+ end
+
context 'when usage ping is enabled' do
before do
stub_usage_data_connections