From 09f032ecdda0cb2f6636b521888890aedafbea46 Mon Sep 17 00:00:00 2001 From: Heitor Reis Date: Mon, 23 Nov 2015 15:47:10 -0200 Subject: [PATCH] Restrict format of GitLab Hook request to json --- app/controllers/repositories_controller.rb | 2 +- config/routes.rb | 6 ++++-- spec/controllers/repositories_controller_spec.rb | 4 ++-- spec/routing/repositories_routing_spec.rb | 3 ++- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 40359d8..d0418b2 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -102,7 +102,7 @@ class RepositoriesController < ApplicationController return render nothing: true, status: :unprocessable_entity end set_repository - @repository.cancel_processing_of_repository unless %w(READY, ERROR).include? @repository.last_processing_state + @repository.cancel_processing_of_repository unless %w(READY ERROR).include? @repository.last_processing_state @repository.process render nothing: true, status: :ok end diff --git a/config/routes.rb b/config/routes.rb index 6e7a85c..1d51e61 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -14,10 +14,12 @@ Rails.application.routes.draw do put '/repositories/:id' => 'repositories#update', as: :repository_update # This route should be a POST to be semantically correct. But, RepositoriesController#create relies on a redirect to it which is not possible with a POST get '/repositories/:id/process' => 'repositories#process_repository', as: :repository_process - post '/repositories/:id/notify_push' => 'repositories#notify_push', as: :repository_notify_push - get '/repository_branches' => 'repositories#branches', as: :repository_branches + scope :format => false, :constraints => { :format => 'json' } do + post '/repositories/:id/notify_push' => 'repositories#notify_push', as: :repository_notify_push, format: :json + end + resources :kalibro_configurations do get '/metric_configurations/choose_metric' => 'metric_configurations#choose_metric', as: :choose_metric resources :metric_configurations, except: [:update, :new] do diff --git a/spec/controllers/repositories_controller_spec.rb b/spec/controllers/repositories_controller_spec.rb index 02f6c5e..fd50378 100644 --- a/spec/controllers/repositories_controller_spec.rb +++ b/spec/controllers/repositories_controller_spec.rb @@ -479,7 +479,7 @@ describe RepositoriesController, :type => :controller do def post_push @request.env['HTTP_X_GITLAB_EVENT'] = ['Push Hook', 'Tag Push Hook'].sample - post :notify_push, id: repository.id + post :notify_push, id: repository.id, format: :json end context 'with a valid repository' do @@ -530,7 +530,7 @@ describe RepositoriesController, :type => :controller do context 'with an invalid header' do before :each do - post :notify_push, id: repository.id + post :notify_push, id: repository.id, format: :json end it { is_expected.to respond_with(:unprocessable_entity) } diff --git a/spec/routing/repositories_routing_spec.rb b/spec/routing/repositories_routing_spec.rb index 5868642..aa70d03 100644 --- a/spec/routing/repositories_routing_spec.rb +++ b/spec/routing/repositories_routing_spec.rb @@ -32,5 +32,6 @@ describe RepositoriesController, :type => :routing do to(controller: :repositories, action: :create, project_id: 1) } it { is_expected.to route(:post, '/repositories/1/notify_push'). to(controller: :repositories, action: :notify_push, id: 1) } - end + it { expect(post: '/repositories/1/notify_push.html').not_to be_routable } + end end -- libgit2 0.21.2