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-06-03 00:59:19 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-06-03 00:59:19 +0300
commit1385478346704d03ab9d3a9bf8ae3812cea0b6b5 (patch)
treec2b68728119200c48fbfe09bb09397d4e31659b7 /spec/controllers/projects_controller_spec.rb
parent361d9dae8bafae8c830d68d16ea0f76482ba9343 (diff)
Add latest changes from gitlab-org/security/gitlab@16-0-stable-ee
Diffstat (limited to 'spec/controllers/projects_controller_spec.rb')
-rw-r--r--spec/controllers/projects_controller_spec.rb83
1 files changed, 62 insertions, 21 deletions
diff --git a/spec/controllers/projects_controller_spec.rb b/spec/controllers/projects_controller_spec.rb
index b652aba1fff..577f10b961c 100644
--- a/spec/controllers/projects_controller_spec.rb
+++ b/spec/controllers/projects_controller_spec.rb
@@ -193,38 +193,79 @@ RSpec.describe ProjectsController, feature_category: :projects do
end
end
- context 'when the default branch name can resolve to another ref' do
- let!(:project_with_default_branch) do
- create(:project, :public, :custom_repo, files: ['somefile']).tap do |p|
- p.repository.create_branch("refs/heads/refs/heads/#{other_ref}", 'master')
- p.change_head("refs/heads/#{other_ref}")
- end.reload
+ context 'when the default branch name is ambiguous' do
+ let_it_be(:project_with_default_branch) do
+ create(:project, :public, :custom_repo, files: ['somefile'])
end
- let(:other_ref) { 'branch-name' }
+ shared_examples 'ambiguous ref redirects' do
+ let(:project) { project_with_default_branch }
+ let(:branch_ref) { "refs/heads/#{ref}" }
+ let(:repo) { project.repository }
- context 'but there is no other ref' do
- it 'responds with ok' do
- get :show, params: { namespace_id: project_with_default_branch.namespace, id: project_with_default_branch }
- expect(response).to be_ok
+ before do
+ repo.create_branch(branch_ref, 'master')
+ repo.change_head(ref)
end
- end
- context 'and that other ref exists' do
- let(:tree_with_default_branch) do
- branch = project_with_default_branch.repository.find_branch(project_with_default_branch.default_branch)
- project_tree_path(project_with_default_branch, branch.target)
+ after do
+ repo.change_head('master')
+ repo.delete_branch(branch_ref)
end
- before do
- project_with_default_branch.repository.create_branch(other_ref, 'master')
+ subject do
+ get(
+ :show,
+ params: {
+ namespace_id: project.namespace,
+ id: project
+ }
+ )
+ end
+
+ context 'when there is no conflicting ref' do
+ let(:other_ref) { 'non-existent-ref' }
+
+ it { is_expected.to have_gitlab_http_status(:ok) }
end
- it 'redirects to tree view for the default branch' do
- get :show, params: { namespace_id: project_with_default_branch.namespace, id: project_with_default_branch }
- expect(response).to redirect_to(tree_with_default_branch)
+ context 'and that other ref exists' do
+ let(:other_ref) { 'master' }
+
+ let(:project_default_root_tree_path) do
+ sha = repo.find_branch(project.default_branch).target
+ project_tree_path(project, sha)
+ end
+
+ it 'redirects to tree view for the default branch' do
+ is_expected.to redirect_to(project_default_root_tree_path)
+ end
end
end
+
+ context 'when ref starts with ref/heads/' do
+ let(:ref) { "refs/heads/#{other_ref}" }
+
+ include_examples 'ambiguous ref redirects'
+ end
+
+ context 'when ref starts with ref/tags/' do
+ let(:ref) { "refs/tags/#{other_ref}" }
+
+ include_examples 'ambiguous ref redirects'
+ end
+
+ context 'when ref starts with heads/' do
+ let(:ref) { "heads/#{other_ref}" }
+
+ include_examples 'ambiguous ref redirects'
+ end
+
+ context 'when ref starts with tags/' do
+ let(:ref) { "tags/#{other_ref}" }
+
+ include_examples 'ambiguous ref redirects'
+ end
end
end