From de33a5bd535d6f4a1dc6cbdb2bd1b208ab6475e7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Alejandro=20Rodr=C3=ADguez?= <alejorro70@gmail.com>
Date: Thu, 18 May 2017 15:33:43 -0400
Subject: [PATCH] Prevent errors from non-functional notify_post_receive
 endpoint

---
 GITLAB_SHELL_VERSION               |   2 +-
 lib/api/internal.rb                |  17 +--
 spec/requests/api/internal_spec.rb | 161 +++++++++++++++--------------
 3 files changed, 91 insertions(+), 89 deletions(-)

diff --git a/GITLAB_SHELL_VERSION b/GITLAB_SHELL_VERSION
index 50e2274e6d3..2d6c0bcf19c 100644
--- a/GITLAB_SHELL_VERSION
+++ b/GITLAB_SHELL_VERSION
@@ -1 +1 @@
-5.0.3
+5.0.4
diff --git a/lib/api/internal.rb b/lib/api/internal.rb
index 96aaaf868ea..9ebd4841296 100644
--- a/lib/api/internal.rb
+++ b/lib/api/internal.rb
@@ -136,14 +136,15 @@ module API
       post "/notify_post_receive" do
         status 200
 
-        return unless Gitlab::GitalyClient.enabled?
-
-        begin
-          repository = wiki? ? project.wiki.repository : project.repository
-          Gitlab::GitalyClient::Notifications.new(repository.raw_repository).post_receive
-        rescue GRPC::Unavailable => e
-          render_api_error!(e, 500)
-        end
+        # TODO: Re-enable when Gitaly is processing the post-receive notification
+        # return unless Gitlab::GitalyClient.enabled?
+        #
+        # begin
+        #   repository = wiki? ? project.wiki.repository : project.repository
+        #   Gitlab::GitalyClient::Notifications.new(repository.raw_repository).post_receive
+        # rescue GRPC::Unavailable => e
+        #   render_api_error!(e, 500)
+        # end
       end
     end
   end
diff --git a/spec/requests/api/internal_spec.rb b/spec/requests/api/internal_spec.rb
index 2ceb4648ece..cf232e7ff69 100644
--- a/spec/requests/api/internal_spec.rb
+++ b/spec/requests/api/internal_spec.rb
@@ -466,86 +466,87 @@ describe API::Internal do
     end
   end
 
-  describe 'POST /notify_post_receive' do
-    let(:valid_params) do
-      { 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 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
-
-    it "returns 500 if the gitaly call fails" do
-      expect_any_instance_of(Gitlab::GitalyClient::Notifications).
-        to receive(:post_receive).and_raise(GRPC::Unavailable)
-
-      post api("/internal/notify_post_receive"), valid_params
-
-      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
+  # TODO: Uncomment when the end-point is reenabled
+  # describe 'POST /notify_post_receive' do
+  #   let(:valid_params) do
+  #     { 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 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
+  #
+  #   it "returns 500 if the gitaly call fails" do
+  #     expect_any_instance_of(Gitlab::GitalyClient::Notifications).
+  #       to receive(:post_receive).and_raise(GRPC::Unavailable)
+  #
+  #     post api("/internal/notify_post_receive"), valid_params
+  #
+  #     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)
     double().tap do |fake_project|
-- 
GitLab