summaryrefslogtreecommitdiff
path: root/spec/requests/api/internal/base_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/requests/api/internal/base_spec.rb')
-rw-r--r--spec/requests/api/internal/base_spec.rb206
1 files changed, 171 insertions, 35 deletions
diff --git a/spec/requests/api/internal/base_spec.rb b/spec/requests/api/internal/base_spec.rb
index fe0a3ffebd3..1f20a088e4f 100644
--- a/spec/requests/api/internal/base_spec.rb
+++ b/spec/requests/api/internal/base_spec.rb
@@ -10,6 +10,9 @@ describe API::Internal::Base do
let(:gl_repository) { "project-#{project.id}" }
let(:reference_counter) { double('ReferenceCounter') }
+ let_it_be(:personal_snippet) { create(:personal_snippet, :repository, author: user) }
+ let_it_be(:project_snippet) { create(:project_snippet, :repository, author: user, project: project) }
+
describe "GET /internal/check" do
it do
expect_any_instance_of(Redis).to receive(:ping).and_return('PONG')
@@ -312,6 +315,54 @@ describe API::Internal::Base do
end
end
+ context 'git push with personal snippet' do
+ it 'responds with success' do
+ push(key, personal_snippet)
+
+ expect(response).to have_gitlab_http_status(:ok)
+ expect(json_response["status"]).to be_truthy
+ expect(json_response["gl_project_path"]).to eq(personal_snippet.repository.full_path)
+ expect(json_response["gl_repository"]).to eq("snippet-#{personal_snippet.id}")
+ expect(user.reload.last_activity_on).to be_nil
+ end
+ end
+
+ context 'git pull with personal snippet' do
+ it 'responds with success' do
+ pull(key, personal_snippet)
+
+ expect(response).to have_gitlab_http_status(:ok)
+ expect(json_response["status"]).to be_truthy
+ expect(json_response["gl_project_path"]).to eq(personal_snippet.repository.full_path)
+ expect(json_response["gl_repository"]).to eq("snippet-#{personal_snippet.id}")
+ expect(user.reload.last_activity_on).to eql(Date.today)
+ end
+ end
+
+ context 'git push with project snippet' do
+ it 'responds with success' do
+ push(key, project_snippet)
+
+ expect(response).to have_gitlab_http_status(:ok)
+ expect(json_response["status"]).to be_truthy
+ expect(json_response["gl_project_path"]).to eq(project_snippet.repository.full_path)
+ expect(json_response["gl_repository"]).to eq("snippet-#{project_snippet.id}")
+ expect(user.reload.last_activity_on).to be_nil
+ end
+ end
+
+ context 'git pull with project snippet' do
+ it 'responds with success' do
+ pull(key, project_snippet)
+
+ expect(response).to have_gitlab_http_status(:ok)
+ expect(json_response["status"]).to be_truthy
+ expect(json_response["gl_project_path"]).to eq(project_snippet.repository.full_path)
+ expect(json_response["gl_repository"]).to eq("snippet-#{project_snippet.id}")
+ expect(user.reload.last_activity_on).to eql(Date.today)
+ end
+ end
+
context "git pull" do
before do
allow(Feature).to receive(:persisted_names).and_return(%w[gitaly_mep_mep])
@@ -393,10 +444,28 @@ describe API::Internal::Base do
end
end
- it_behaves_like 'storing arguments in the application context' do
- let(:expected_params) { { user: key.user.username, project: project.full_path } }
+ context 'with Project' do
+ it_behaves_like 'storing arguments in the application context' do
+ let(:expected_params) { { user: key.user.username, project: project.full_path } }
+
+ subject { push(key, project) }
+ end
+ end
+
+ context 'with PersonalSnippet' do
+ it_behaves_like 'storing arguments in the application context' do
+ let(:expected_params) { { user: key.user.username } }
+
+ subject { push(key, personal_snippet) }
+ end
+ end
- subject { push(key, project) }
+ context 'with ProjectSnippet' do
+ it_behaves_like 'storing arguments in the application context' do
+ let(:expected_params) { { user: key.user.username, project: project_snippet.project.full_path } }
+
+ subject { push(key, project_snippet) }
+ end
end
end
@@ -450,7 +519,7 @@ describe API::Internal::Base do
{
authentication_abilities: [:read_project, :download_code, :push_code],
namespace_path: project.namespace.path,
- project_path: project.path,
+ repository_path: project.path,
redirected_path: nil
}
).and_return(access_checker)
@@ -835,22 +904,60 @@ describe API::Internal::Base do
allow_any_instance_of(Gitlab::Identifier).to receive(:identify).and_return(user)
end
- it 'executes PostReceiveService' do
- message = <<~MESSAGE.strip
- To create a merge request for #{branch_name}, visit:
- http://#{Gitlab.config.gitlab.host}/#{project.full_path}/-/merge_requests/new?merge_request%5Bsource_branch%5D=#{branch_name}
- MESSAGE
+ context 'with Project' do
+ it 'executes PostReceiveService' do
+ message = <<~MESSAGE.strip
+ To create a merge request for #{branch_name}, visit:
+ http://#{Gitlab.config.gitlab.host}/#{project.full_path}/-/merge_requests/new?merge_request%5Bsource_branch%5D=#{branch_name}
+ MESSAGE
+
+ subject
- subject
+ expect(json_response).to eq({
+ 'messages' => [{ 'message' => message, 'type' => 'basic' }],
+ 'reference_counter_decreased' => true
+ })
+ end
- expect(json_response).to eq({
- 'messages' => [{ 'message' => message, 'type' => 'basic' }],
- 'reference_counter_decreased' => true
- })
+ it_behaves_like 'storing arguments in the application context' do
+ let(:expected_params) { { user: user.username, project: project.full_path } }
+ end
end
- it_behaves_like 'storing arguments in the application context' do
- let(:expected_params) { { user: user.username, project: project.full_path } }
+ context 'with PersonalSnippet' do
+ let(:gl_repository) { "snippet-#{personal_snippet.id}" }
+
+ it 'executes PostReceiveService' do
+ subject
+
+ expect(json_response).to eq({
+ 'messages' => [],
+ 'reference_counter_decreased' => true
+ })
+ end
+
+ it_behaves_like 'storing arguments in the application context' do
+ let(:expected_params) { { user: key.user.username } }
+ let(:gl_repository) { "snippet-#{personal_snippet.id}" }
+ end
+ end
+
+ context 'with ProjectSnippet' do
+ let(:gl_repository) { "snippet-#{project_snippet.id}" }
+
+ it 'executes PostReceiveService' do
+ subject
+
+ expect(json_response).to eq({
+ 'messages' => [],
+ 'reference_counter_decreased' => true
+ })
+ end
+
+ it_behaves_like 'storing arguments in the application context' do
+ let(:expected_params) { { user: key.user.username, project: project_snippet.project.full_path } }
+ let(:gl_repository) { "snippet-#{project_snippet.id}" }
+ end
end
context 'with an orphaned write deploy key' do
@@ -866,16 +973,32 @@ describe API::Internal::Base do
end
context 'when project is nil' do
- let(:gl_repository) { 'project-foo' }
+ context 'with Project' do
+ let(:gl_repository) { 'project-foo' }
- it 'does not try to notify that project moved' do
- allow(Gitlab::GlRepository).to receive(:parse).and_return([nil, Gitlab::GlRepository::PROJECT])
+ it 'does not try to notify that project moved' do
+ allow(Gitlab::GlRepository).to receive(:parse).and_return([nil, nil, Gitlab::GlRepository::PROJECT])
- expect(Gitlab::Checks::ProjectMoved).not_to receive(:fetch_message)
+ expect(Gitlab::Checks::ProjectMoved).not_to receive(:fetch_message)
- subject
+ subject
- expect(response).to have_gitlab_http_status(:ok)
+ expect(response).to have_gitlab_http_status(:ok)
+ end
+ end
+
+ context 'with PersonalSnippet' do
+ let(:gl_repository) { "snippet-#{personal_snippet.id}" }
+
+ it 'does not try to notify that project moved' do
+ allow(Gitlab::GlRepository).to receive(:parse).and_return([personal_snippet, nil, Gitlab::GlRepository::PROJECT])
+
+ expect(Gitlab::Checks::ProjectMoved).not_to receive(:fetch_message)
+
+ subject
+
+ expect(response).to have_gitlab_http_status(:ok)
+ end
end
end
end
@@ -896,24 +1019,37 @@ describe API::Internal::Base do
end
end
- def gl_repository_for(project_or_wiki)
- case project_or_wiki
+ def gl_repository_for(container)
+ case container
when ProjectWiki
- Gitlab::GlRepository::WIKI.identifier_for_container(project_or_wiki.project)
+ Gitlab::GlRepository::WIKI.identifier_for_container(container.project)
when Project
- Gitlab::GlRepository::PROJECT.identifier_for_container(project_or_wiki)
+ Gitlab::GlRepository::PROJECT.identifier_for_container(container)
+ when Snippet
+ Gitlab::GlRepository::SNIPPET.identifier_for_container(container)
else
nil
end
end
- def pull(key, project, protocol = 'ssh')
+ def full_path_for(container)
+ case container
+ when PersonalSnippet
+ "snippets/#{container.id}"
+ when ProjectSnippet
+ "#{container.project.full_path}/snippets/#{container.id}"
+ else
+ container.full_path
+ end
+ end
+
+ def pull(key, container, protocol = 'ssh')
post(
api("/internal/allowed"),
params: {
key_id: key.id,
- project: project.full_path,
- gl_repository: gl_repository_for(project),
+ project: full_path_for(container),
+ gl_repository: gl_repository_for(container),
action: 'git-upload-pack',
secret_token: secret_token,
protocol: protocol
@@ -921,12 +1057,12 @@ describe API::Internal::Base do
)
end
- def push(key, project, protocol = 'ssh', env: nil)
+ def push(key, container, protocol = 'ssh', env: nil)
params = {
changes: 'd14d6c0abdd253381df51a723d58691b2ee1ab08 570e7b2abdd848b95f2f578043fc23bd6f6fd24d refs/heads/master',
key_id: key.id,
- project: project.full_path,
- gl_repository: gl_repository_for(project),
+ project: full_path_for(container),
+ gl_repository: gl_repository_for(container),
action: 'git-receive-pack',
secret_token: secret_token,
protocol: protocol,
@@ -939,14 +1075,14 @@ describe API::Internal::Base do
)
end
- def archive(key, project)
+ def archive(key, container)
post(
api("/internal/allowed"),
params: {
ref: 'master',
key_id: key.id,
- project: project.full_path,
- gl_repository: gl_repository_for(project),
+ project: full_path_for(container),
+ gl_repository: gl_repository_for(container),
action: 'git-upload-archive',
secret_token: secret_token,
protocol: 'ssh'