summaryrefslogtreecommitdiff
path: root/spec/requests/api/internal_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/requests/api/internal_spec.rb')
-rw-r--r--spec/requests/api/internal_spec.rb116
1 files changed, 109 insertions, 7 deletions
diff --git a/spec/requests/api/internal_spec.rb b/spec/requests/api/internal_spec.rb
index eed45d37444..2ceb4648ece 100644
--- a/spec/requests/api/internal_spec.rb
+++ b/spec/requests/api/internal_spec.rb
@@ -1,7 +1,6 @@
require 'spec_helper'
-describe API::Internal, api: true do
- include ApiHelpers
+describe API::Internal do
let(:user) { create(:user) }
let(:key) { create(:key, user: user) }
let(:project) { create(:project, :repository) }
@@ -147,10 +146,31 @@ describe API::Internal, api: true do
end
end
- describe "POST /internal/allowed" do
+ describe "POST /internal/allowed", :redis do
context "access granted" do
before do
project.team << [user, :developer]
+ Timecop.freeze
+ end
+
+ after do
+ Timecop.return
+ end
+
+ context 'with env passed as a JSON' do
+ it 'sets env in RequestStore' do
+ expect(Gitlab::Git::Env).to receive(:set).with({
+ 'GIT_OBJECT_DIRECTORY' => 'foo',
+ 'GIT_ALTERNATE_OBJECT_DIRECTORIES' => 'bar'
+ })
+
+ push(key, project.wiki, env: {
+ GIT_OBJECT_DIRECTORY: 'foo',
+ GIT_ALTERNATE_OBJECT_DIRECTORIES: 'bar'
+ }.to_json)
+
+ expect(response).to have_http_status(200)
+ end
end
context "git push with project.wiki" do
@@ -160,6 +180,8 @@ describe API::Internal, api: true do
expect(response).to have_http_status(200)
expect(json_response["status"]).to be_truthy
expect(json_response["repository_path"]).to eq(project.wiki.repository.path_to_repo)
+ expect(json_response["gl_repository"]).to eq("wiki-#{project.id}")
+ expect(user).not_to have_an_activity_record
end
end
@@ -170,6 +192,8 @@ describe API::Internal, api: true do
expect(response).to have_http_status(200)
expect(json_response["status"]).to be_truthy
expect(json_response["repository_path"]).to eq(project.wiki.repository.path_to_repo)
+ expect(json_response["gl_repository"]).to eq("wiki-#{project.id}")
+ expect(user).to have_an_activity_record
end
end
@@ -180,6 +204,8 @@ describe API::Internal, api: true do
expect(response).to have_http_status(200)
expect(json_response["status"]).to be_truthy
expect(json_response["repository_path"]).to eq(project.repository.path_to_repo)
+ expect(json_response["gl_repository"]).to eq("project-#{project.id}")
+ expect(user).to have_an_activity_record
end
end
@@ -190,6 +216,8 @@ describe API::Internal, api: true do
expect(response).to have_http_status(200)
expect(json_response["status"]).to be_truthy
expect(json_response["repository_path"]).to eq(project.repository.path_to_repo)
+ expect(json_response["gl_repository"]).to eq("project-#{project.id}")
+ expect(user).not_to have_an_activity_record
end
context 'project as /namespace/project' do
@@ -199,6 +227,7 @@ describe API::Internal, api: true do
expect(response).to have_http_status(200)
expect(json_response["status"]).to be_truthy
expect(json_response["repository_path"]).to eq(project.repository.path_to_repo)
+ expect(json_response["gl_repository"]).to eq("project-#{project.id}")
end
end
@@ -209,6 +238,7 @@ describe API::Internal, api: true do
expect(response).to have_http_status(200)
expect(json_response["status"]).to be_truthy
expect(json_response["repository_path"]).to eq(project.repository.path_to_repo)
+ expect(json_response["gl_repository"]).to eq("project-#{project.id}")
end
end
end
@@ -225,6 +255,7 @@ describe API::Internal, api: true do
expect(response).to have_http_status(200)
expect(json_response["status"]).to be_falsey
+ expect(user).not_to have_an_activity_record
end
end
@@ -234,6 +265,7 @@ describe API::Internal, api: true do
expect(response).to have_http_status(200)
expect(json_response["status"]).to be_falsey
+ expect(user).not_to have_an_activity_record
end
end
end
@@ -251,6 +283,7 @@ describe API::Internal, api: true do
expect(response).to have_http_status(200)
expect(json_response["status"]).to be_falsey
+ expect(user).not_to have_an_activity_record
end
end
@@ -260,6 +293,7 @@ describe API::Internal, api: true do
expect(response).to have_http_status(200)
expect(json_response["status"]).to be_falsey
+ expect(user).not_to have_an_activity_record
end
end
end
@@ -416,18 +450,39 @@ describe API::Internal, api: true do
expect(json_response).to eq([])
end
+
+ context 'with a gl_repository parameter' do
+ let(:gl_repository) { "project-#{project.id}" }
+
+ it 'returns link to create new merge request' do
+ get api("/internal/merge_request_urls?gl_repository=#{gl_repository}&changes=#{changes}"), secret_token: secret_token
+
+ expect(json_response).to match [{
+ "branch_name" => "new_branch",
+ "url" => "http://#{Gitlab.config.gitlab.host}/#{project.namespace.name}/#{project.path}/merge_requests/new?merge_request%5Bsource_branch%5D=new_branch",
+ "new_merge_request" => true
+ }]
+ end
+ end
end
describe 'POST /notify_post_receive' do
let(:valid_params) do
- { repo_path: project.repository.path, secret_token: secret_token }
+ { project: project.repository.path, secret_token: secret_token }
+ end
+
+ let(:valid_wiki_params) do
+ { project: project.wiki.repository.path, secret_token: secret_token }
end
before do
allow(Gitlab.config.gitaly).to receive(:enabled).and_return(true)
end
- it "calls the Gitaly client if it's enabled" do
+ it "calls the Gitaly client with the project's repository" do
+ expect(Gitlab::GitalyClient::Notifications).
+ to receive(:new).with(gitlab_git_repository_with(path: project.repository.path)).
+ and_call_original
expect_any_instance_of(Gitlab::GitalyClient::Notifications).
to receive(:post_receive)
@@ -436,6 +491,18 @@ describe API::Internal, api: true do
expect(response).to have_http_status(200)
end
+ it "calls the Gitaly client with the wiki's repository if it's a wiki" do
+ expect(Gitlab::GitalyClient::Notifications).
+ to receive(:new).with(gitlab_git_repository_with(path: project.wiki.repository.path)).
+ and_call_original
+ expect_any_instance_of(Gitlab::GitalyClient::Notifications).
+ to receive(:post_receive)
+
+ post api("/internal/notify_post_receive"), valid_wiki_params
+
+ expect(response).to have_http_status(200)
+ end
+
it "returns 500 if the gitaly call fails" do
expect_any_instance_of(Gitlab::GitalyClient::Notifications).
to receive(:post_receive).and_raise(GRPC::Unavailable)
@@ -444,6 +511,40 @@ describe API::Internal, api: true do
expect(response).to have_http_status(500)
end
+
+ context 'with a gl_repository parameter' do
+ let(:valid_params) do
+ { gl_repository: "project-#{project.id}", secret_token: secret_token }
+ end
+
+ let(:valid_wiki_params) do
+ { gl_repository: "wiki-#{project.id}", secret_token: secret_token }
+ end
+
+ it "calls the Gitaly client with the project's repository" do
+ expect(Gitlab::GitalyClient::Notifications).
+ to receive(:new).with(gitlab_git_repository_with(path: project.repository.path)).
+ and_call_original
+ expect_any_instance_of(Gitlab::GitalyClient::Notifications).
+ to receive(:post_receive)
+
+ post api("/internal/notify_post_receive"), valid_params
+
+ expect(response).to have_http_status(200)
+ end
+
+ it "calls the Gitaly client with the wiki's repository if it's a wiki" do
+ expect(Gitlab::GitalyClient::Notifications).
+ to receive(:new).with(gitlab_git_repository_with(path: project.wiki.repository.path)).
+ and_call_original
+ expect_any_instance_of(Gitlab::GitalyClient::Notifications).
+ to receive(:post_receive)
+
+ post api("/internal/notify_post_receive"), valid_wiki_params
+
+ expect(response).to have_http_status(200)
+ end
+ end
end
def project_with_repo_path(path)
@@ -463,7 +564,7 @@ describe API::Internal, api: true do
)
end
- def push(key, project, protocol = 'ssh')
+ def push(key, project, protocol = 'ssh', env: nil)
post(
api("/internal/allowed"),
changes: 'd14d6c0abdd253381df51a723d58691b2ee1ab08 570e7b2abdd848b95f2f578043fc23bd6f6fd24d refs/heads/master',
@@ -471,7 +572,8 @@ describe API::Internal, api: true do
project: project.repository.path_to_repo,
action: 'git-receive-pack',
secret_token: secret_token,
- protocol: protocol
+ protocol: protocol,
+ env: env
)
end