Commit 09f032ecdda0cb2f6636b521888890aedafbea46
1 parent
96c08aed
Exists in
colab
and in
4 other branches
Restrict format of GitLab Hook request to json
Signed off by: Daniel Miranda <danielkza2@gmail.com>
Showing
4 changed files
with
9 additions
and
6 deletions
Show diff stats
app/controllers/repositories_controller.rb
... | ... | @@ -102,7 +102,7 @@ class RepositoriesController < ApplicationController |
102 | 102 | return render nothing: true, status: :unprocessable_entity |
103 | 103 | end |
104 | 104 | set_repository |
105 | - @repository.cancel_processing_of_repository unless %w(READY, ERROR).include? @repository.last_processing_state | |
105 | + @repository.cancel_processing_of_repository unless %w(READY ERROR).include? @repository.last_processing_state | |
106 | 106 | @repository.process |
107 | 107 | render nothing: true, status: :ok |
108 | 108 | end | ... | ... |
config/routes.rb
... | ... | @@ -14,10 +14,12 @@ Rails.application.routes.draw do |
14 | 14 | put '/repositories/:id' => 'repositories#update', as: :repository_update |
15 | 15 | # 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 |
16 | 16 | get '/repositories/:id/process' => 'repositories#process_repository', as: :repository_process |
17 | - post '/repositories/:id/notify_push' => 'repositories#notify_push', as: :repository_notify_push | |
18 | - | |
19 | 17 | get '/repository_branches' => 'repositories#branches', as: :repository_branches |
20 | 18 | |
19 | + scope :format => false, :constraints => { :format => 'json' } do | |
20 | + post '/repositories/:id/notify_push' => 'repositories#notify_push', as: :repository_notify_push, format: :json | |
21 | + end | |
22 | + | |
21 | 23 | resources :kalibro_configurations do |
22 | 24 | get '/metric_configurations/choose_metric' => 'metric_configurations#choose_metric', as: :choose_metric |
23 | 25 | resources :metric_configurations, except: [:update, :new] do | ... | ... |
spec/controllers/repositories_controller_spec.rb
... | ... | @@ -479,7 +479,7 @@ describe RepositoriesController, :type => :controller do |
479 | 479 | |
480 | 480 | def post_push |
481 | 481 | @request.env['HTTP_X_GITLAB_EVENT'] = ['Push Hook', 'Tag Push Hook'].sample |
482 | - post :notify_push, id: repository.id | |
482 | + post :notify_push, id: repository.id, format: :json | |
483 | 483 | end |
484 | 484 | |
485 | 485 | context 'with a valid repository' do |
... | ... | @@ -530,7 +530,7 @@ describe RepositoriesController, :type => :controller do |
530 | 530 | |
531 | 531 | context 'with an invalid header' do |
532 | 532 | before :each do |
533 | - post :notify_push, id: repository.id | |
533 | + post :notify_push, id: repository.id, format: :json | |
534 | 534 | end |
535 | 535 | |
536 | 536 | it { is_expected.to respond_with(:unprocessable_entity) } | ... | ... |
spec/routing/repositories_routing_spec.rb
... | ... | @@ -32,5 +32,6 @@ describe RepositoriesController, :type => :routing do |
32 | 32 | to(controller: :repositories, action: :create, project_id: 1) } |
33 | 33 | it { is_expected.to route(:post, '/repositories/1/notify_push'). |
34 | 34 | to(controller: :repositories, action: :notify_push, id: 1) } |
35 | - end | |
35 | + it { expect(post: '/repositories/1/notify_push.html').not_to be_routable } | |
36 | + end | |
36 | 37 | end | ... | ... |