diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-06-22 18:06:55 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-06-22 18:06:55 +0300 |
commit | 793034a90509193ebf2ad14ed8e5eea10f7c6b4a (patch) | |
tree | c6326ec316c71dad77ab8f40b4eedf5093544403 /spec/lib/gitlab | |
parent | e2d00f9148a5c87fe4f56e4fd3c90a9b3574f03b (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib/gitlab')
-rw-r--r-- | spec/lib/gitlab/checks/container_moved_spec.rb (renamed from spec/lib/gitlab/checks/project_moved_spec.rb) | 44 | ||||
-rw-r--r-- | spec/lib/gitlab/checks/project_created_spec.rb | 31 | ||||
-rw-r--r-- | spec/lib/gitlab/git_access_spec.rb | 2 | ||||
-rw-r--r-- | spec/lib/gitlab/repo_path_spec.rb | 36 |
4 files changed, 80 insertions, 33 deletions
diff --git a/spec/lib/gitlab/checks/project_moved_spec.rb b/spec/lib/gitlab/checks/container_moved_spec.rb index 469aea8d093..00ef5604e1d 100644 --- a/spec/lib/gitlab/checks/project_moved_spec.rb +++ b/spec/lib/gitlab/checks/container_moved_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::Checks::ProjectMoved, :clean_gitlab_redis_shared_state do +RSpec.describe Gitlab::Checks::ContainerMoved, :clean_gitlab_redis_shared_state do let_it_be(:user) { create(:user) } let_it_be(:project) { create(:project, :repository, :wiki_repo, namespace: user.namespace) } @@ -14,27 +14,48 @@ RSpec.describe Gitlab::Checks::ProjectMoved, :clean_gitlab_redis_shared_state do subject { described_class.new(repository, git_user, protocol, redirect_path) } describe '.fetch_message' do + let(:key) { "redirect_namespace:#{user.id}:#{project.repository.gl_repository}" } + let(:legacy_key) { "redirect_namespace:#{user.id}:#{project.id}" } + context 'with a redirect message queue' do before do subject.add_message end it 'returns the redirect message' do - expect(described_class.fetch_message(user.id, project.id)).to eq(subject.message) + expect(described_class.fetch_message(user, project.repository)).to eq(subject.message) end it 'deletes the redirect message from redis' do - expect(Gitlab::Redis::SharedState.with { |redis| redis.get("redirect_namespace:#{user.id}:#{project.id}") }).not_to be_nil + expect(Gitlab::Redis::SharedState.with { |redis| redis.get(key) }).not_to be_nil - described_class.fetch_message(user.id, project.id) + described_class.fetch_message(user, project.repository) - expect(Gitlab::Redis::SharedState.with { |redis| redis.get("redirect_namespace:#{user.id}:#{project.id}") }).to be_nil + expect(Gitlab::Redis::SharedState.with { |redis| redis.get(key) }).to be_nil + end + + context 'with a message in the legacy key' do + before do + Gitlab::Redis::SharedState.with do |redis| + redis.set(legacy_key, 'legacy message') + end + end + + it 'returns and deletes the legacy message' do + expect(Gitlab::Redis::SharedState.with { |redis| redis.get(key) }).not_to be_nil + expect(Gitlab::Redis::SharedState.with { |redis| redis.get(legacy_key) }).not_to be_nil + + expect(described_class.fetch_message(user, project.repository)).to eq('legacy message') + + expect(Gitlab::Redis::SharedState.with { |redis| redis.get(key) }).to be_nil + expect(Gitlab::Redis::SharedState.with { |redis| redis.get(legacy_key) }).to be_nil + end end end context 'with no redirect message queue' do it 'returns nil' do - expect(described_class.fetch_message(1, 2)).to be_nil + expect(described_class.fetch_message(user, project.repository)).to be_nil end end end @@ -58,7 +79,7 @@ RSpec.describe Gitlab::Checks::ProjectMoved, :clean_gitlab_redis_shared_state do shared_examples 'returns redirect message' do it do message = <<~MSG - Project '#{redirect_path}' was moved to '#{project.full_path}'. + #{container_label} '#{redirect_path}' was moved to '#{repository.container.full_path}'. Please update your Git remote: @@ -86,6 +107,7 @@ RSpec.describe Gitlab::Checks::ProjectMoved, :clean_gitlab_redis_shared_state do context 'with project' do it_behaves_like 'errors per protocol' do + let(:container_label) { 'Project' } let(:http_url_to_repo) { project.http_url_to_repo } let(:ssh_url_to_repo) { project.ssh_url_to_repo } end @@ -95,6 +117,7 @@ RSpec.describe Gitlab::Checks::ProjectMoved, :clean_gitlab_redis_shared_state do let(:repository) { project.wiki.repository } it_behaves_like 'errors per protocol' do + let(:container_label) { 'Project wiki' } let(:http_url_to_repo) { project.wiki.http_url_to_repo } let(:ssh_url_to_repo) { project.wiki.ssh_url_to_repo } end @@ -106,6 +129,7 @@ RSpec.describe Gitlab::Checks::ProjectMoved, :clean_gitlab_redis_shared_state do let(:repository) { snippet.repository } it_behaves_like 'errors per protocol' do + let(:container_label) { 'Project snippet' } let(:http_url_to_repo) { snippet.http_url_to_repo } let(:ssh_url_to_repo) { snippet.ssh_url_to_repo } end @@ -116,8 +140,10 @@ RSpec.describe Gitlab::Checks::ProjectMoved, :clean_gitlab_redis_shared_state do let(:repository) { snippet.repository } - it 'returns nil' do - expect(subject.add_message).to be_nil + it_behaves_like 'errors per protocol' do + let(:container_label) { 'Personal snippet' } + let(:http_url_to_repo) { snippet.http_url_to_repo } + let(:ssh_url_to_repo) { snippet.ssh_url_to_repo } end end end diff --git a/spec/lib/gitlab/checks/project_created_spec.rb b/spec/lib/gitlab/checks/project_created_spec.rb index 74e43b04b6b..6a2e4201030 100644 --- a/spec/lib/gitlab/checks/project_created_spec.rb +++ b/spec/lib/gitlab/checks/project_created_spec.rb @@ -13,27 +13,48 @@ RSpec.describe Gitlab::Checks::ProjectCreated, :clean_gitlab_redis_shared_state subject { described_class.new(repository, git_user, 'http') } describe '.fetch_message' do + let(:key) { "project_created:#{user.id}:#{project.repository.gl_repository}" } + let(:legacy_key) { "project_created:#{user.id}:#{project.id}" } + context 'with a project created message queue' do before do subject.add_message end it 'returns project created message' do - expect(described_class.fetch_message(user.id, project.id)).to eq(subject.message) + expect(described_class.fetch_message(user, project.repository)).to eq(subject.message) end it 'deletes the project created message from redis' do - expect(Gitlab::Redis::SharedState.with { |redis| redis.get("project_created:#{user.id}:#{project.id}") }).not_to be_nil + expect(Gitlab::Redis::SharedState.with { |redis| redis.get(key) }).not_to be_nil + + described_class.fetch_message(user, project.repository) + + expect(Gitlab::Redis::SharedState.with { |redis| redis.get(key) }).to be_nil + end + + context 'with a message in the legacy key' do + before do + Gitlab::Redis::SharedState.with do |redis| + redis.set(legacy_key, 'legacy message') + end + end + + it 'returns and deletes the legacy message' do + expect(Gitlab::Redis::SharedState.with { |redis| redis.get(key) }).not_to be_nil + expect(Gitlab::Redis::SharedState.with { |redis| redis.get(legacy_key) }).not_to be_nil - described_class.fetch_message(user.id, project.id) + expect(described_class.fetch_message(user, project.repository)).to eq('legacy message') - expect(Gitlab::Redis::SharedState.with { |redis| redis.get("project_created:#{user.id}:#{project.id}") }).to be_nil + expect(Gitlab::Redis::SharedState.with { |redis| redis.get(key) }).to be_nil + expect(Gitlab::Redis::SharedState.with { |redis| redis.get(legacy_key) }).to be_nil + end end end context 'with no project created message queue' do it 'returns nil' do - expect(described_class.fetch_message(1, 2)).to be_nil + expect(described_class.fetch_message(user, project.repository)).to be_nil end end end diff --git a/spec/lib/gitlab/git_access_spec.rb b/spec/lib/gitlab/git_access_spec.rb index 3ee0310a9a2..3a10ce1a30e 100644 --- a/spec/lib/gitlab/git_access_spec.rb +++ b/spec/lib/gitlab/git_access_spec.rb @@ -265,7 +265,7 @@ RSpec.describe Gitlab::GitAccess do it 'enqueues a redirected message for pushing' do push_access_check - expect(Gitlab::Checks::ProjectMoved.fetch_message(user.id, project.id)).not_to be_nil + expect(Gitlab::Checks::ContainerMoved.fetch_message(user, project.repository)).not_to be_nil end it 'allows push and pull access' do diff --git a/spec/lib/gitlab/repo_path_spec.rb b/spec/lib/gitlab/repo_path_spec.rb index 912efa6a5db..6cff0eff7e8 100644 --- a/spec/lib/gitlab/repo_path_spec.rb +++ b/spec/lib/gitlab/repo_path_spec.rb @@ -13,11 +13,11 @@ RSpec.describe ::Gitlab::RepoPath do describe '.parse' do context 'a repository storage path' do - it 'parses a full repository project path' do + it 'parses a full project repository path' do expect(described_class.parse(project.repository.full_path)).to eq([project, project, Gitlab::GlRepository::PROJECT, nil]) end - it 'parses a full wiki project path' do + it 'parses a full project wiki repository path' do expect(described_class.parse(project.wiki.repository.full_path)).to eq([project.wiki, project, Gitlab::GlRepository::WIKI, nil]) end @@ -49,7 +49,7 @@ RSpec.describe ::Gitlab::RepoPath do end it 'parses a relative wiki path' do - expect(described_class.parse(redirect.path + '.wiki.git')).to eq([project.wiki, project, Gitlab::GlRepository::WIKI, redirect_route]) + expect(described_class.parse(redirect.path + '.wiki.git')).to eq([project.wiki, project, Gitlab::GlRepository::WIKI, "#{redirect_route}.wiki"]) end it 'parses a relative path starting with /' do @@ -57,7 +57,7 @@ RSpec.describe ::Gitlab::RepoPath do end it 'parses a redirected project snippet repository path' do - expect(described_class.parse(redirect.path + "/snippets/#{project_snippet.id}.git")).to eq([project_snippet, project, Gitlab::GlRepository::SNIPPET, redirect_route]) + expect(described_class.parse(redirect.path + "/snippets/#{project_snippet.id}.git")).to eq([project_snippet, project, Gitlab::GlRepository::SNIPPET, "#{redirect_route}/snippets/#{project_snippet.id}"]) end end end @@ -70,8 +70,8 @@ RSpec.describe ::Gitlab::RepoPath do describe '.find_project' do context 'when finding a project by its canonical path' do context 'when the cases match' do - it 'returns the project and nil' do - expect(described_class.find_project(project.full_path)).to eq([project, nil]) + it 'returns the project' do + expect(described_class.find_project(project.full_path)).to eq(project) end end @@ -80,45 +80,45 @@ RSpec.describe ::Gitlab::RepoPath do # easy and safe to redirect someone to the correctly-cased URL. For git # requests, we should accept wrongly-cased URLs because it is a pain to # block people's git operations and force them to update remote URLs. - it 'returns the project and nil' do - expect(described_class.find_project(project.full_path.upcase)).to eq([project, nil]) + it 'returns the project' do + expect(described_class.find_project(project.full_path.upcase)).to eq(project) end end end context 'when finding a project via a redirect' do - it 'returns the project and nil' do - expect(described_class.find_project(redirect.path)).to eq([project, redirect.path]) + it 'returns the project' do + expect(described_class.find_project(redirect.path)).to eq(project) end end end describe '.find_snippet' do it 'extracts path and id from personal snippet route' do - expect(described_class.find_snippet("snippets/#{personal_snippet.id}")).to eq([personal_snippet, nil]) + expect(described_class.find_snippet("snippets/#{personal_snippet.id}")).to eq(personal_snippet) end it 'extracts path and id from project snippet route' do - expect(described_class.find_snippet("#{project.full_path}/snippets/#{project_snippet.id}")).to eq([project_snippet, nil]) + expect(described_class.find_snippet("#{project.full_path}/snippets/#{project_snippet.id}")).to eq(project_snippet) end it 'returns nil for invalid snippet paths' do aggregate_failures do - expect(described_class.find_snippet("snippets/#{project_snippet.id}")).to eq([nil, nil]) - expect(described_class.find_snippet("#{project.full_path}/snippets/#{personal_snippet.id}")).to eq([nil, nil]) - expect(described_class.find_snippet('')).to eq([nil, nil]) + expect(described_class.find_snippet("snippets/#{project_snippet.id}")).to be_nil + expect(described_class.find_snippet("#{project.full_path}/snippets/#{personal_snippet.id}")).to be_nil + expect(described_class.find_snippet('')).to be_nil end end it 'returns nil for snippets not associated with the project' do snippet = create(:project_snippet) - expect(described_class.find_snippet("#{project.full_path}/snippets/#{snippet.id}")).to eq([nil, nil]) + expect(described_class.find_snippet("#{project.full_path}/snippets/#{snippet.id}")).to be_nil end context 'when finding a project snippet via a redirect' do - it 'returns the project and true' do - expect(described_class.find_snippet("#{redirect.path}/snippets/#{project_snippet.id}")).to eq([project_snippet, redirect.path]) + it 'returns the project snippet' do + expect(described_class.find_snippet("#{redirect.path}/snippets/#{project_snippet.id}")).to eq(project_snippet) end end end |