Commit c90c0262 authored by Robert Speicher's avatar Robert Speicher

Merge branch '31034-fix-unsupported-routes' into 'master'

Fix unsupported routes in Rails 6

See merge request gitlab-org/gitlab!20896
parents 7a0325ce d370e11f
...@@ -58,7 +58,7 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do ...@@ -58,7 +58,7 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do
get :trace, defaults: { format: 'json' } get :trace, defaults: { format: 'json' }
get :raw get :raw
get :terminal get :terminal
get '/terminal.ws/authorize', to: 'jobs#terminal_websocket_authorize', constraints: { format: nil } get '/terminal.ws/authorize', to: 'jobs#terminal_websocket_authorize', format: false
end end
resource :artifacts, only: [] do resource :artifacts, only: [] do
...@@ -228,7 +228,7 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do ...@@ -228,7 +228,7 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do
get :metrics get :metrics
get :additional_metrics get :additional_metrics
get :metrics_dashboard get :metrics_dashboard
get '/terminal.ws/authorize', to: 'environments#terminal_websocket_authorize', constraints: { format: nil } get '/terminal.ws/authorize', to: 'environments#terminal_websocket_authorize', format: false
get '/prometheus/api/v1/*proxy_path', to: 'environments/prometheus_api#proxy', as: :prometheus_api get '/prometheus/api/v1/*proxy_path', to: 'environments/prometheus_api#proxy', as: :prometheus_api
end end
...@@ -328,13 +328,7 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do ...@@ -328,13 +328,7 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do
get :test_reports get :test_reports
get :exposed_artifacts get :exposed_artifacts
scope constraints: { format: nil }, action: :show do scope constraints: ->(req) { req.format == :json }, as: :json do
get :commits, defaults: { tab: 'commits' }
get :pipelines, defaults: { tab: 'pipelines' }
get :diffs, defaults: { tab: 'diffs' }
end
scope constraints: { format: 'json' }, as: :json do
get :commits get :commits
get :pipelines get :pipelines
get :diffs, to: 'merge_requests/diffs#show' get :diffs, to: 'merge_requests/diffs#show'
...@@ -344,6 +338,12 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do ...@@ -344,6 +338,12 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do
get :cached_widget, to: 'merge_requests/content#cached_widget' get :cached_widget, to: 'merge_requests/content#cached_widget'
end end
scope action: :show do
get :commits, defaults: { tab: 'commits' }
get :pipelines, defaults: { tab: 'pipelines' }
get :diffs, defaults: { tab: 'diffs' }
end
get :diff_for_path, controller: 'merge_requests/diffs' get :diff_for_path, controller: 'merge_requests/diffs'
scope controller: 'merge_requests/conflicts' do scope controller: 'merge_requests/conflicts' do
...@@ -372,16 +372,16 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do ...@@ -372,16 +372,16 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do
scope path: 'new', as: :new_merge_request do scope path: 'new', as: :new_merge_request do
get '', action: :new get '', action: :new
scope constraints: { format: nil }, action: :new do scope constraints: ->(req) { req.format == :json }, as: :json do
get :diffs, defaults: { tab: 'diffs' }
get :pipelines, defaults: { tab: 'pipelines' }
end
scope constraints: { format: 'json' }, as: :json do
get :diffs get :diffs
get :pipelines get :pipelines
end end
scope action: :new do
get :diffs, defaults: { tab: 'diffs' }
get :pipelines, defaults: { tab: 'pipelines' }
end
get :diff_for_path get :diff_for_path
get :branch_from get :branch_from
get :branch_to get :branch_to
......
...@@ -152,7 +152,7 @@ end ...@@ -152,7 +152,7 @@ end
# Dependency proxy for containers # Dependency proxy for containers
# Because docker adds v2 prefix to URI this need to be outside of usual group routes # Because docker adds v2 prefix to URI this need to be outside of usual group routes
scope constraints: { format: nil } do scope format: false do
get 'v2', to: proc { [200, {}, ['']] } get 'v2', to: proc { [200, {}, ['']] }
constraints image: Gitlab::PathRegex.container_image_regex do constraints image: Gitlab::PathRegex.container_image_regex do
......
...@@ -25,7 +25,7 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do ...@@ -25,7 +25,7 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do
resources :jobs, only: [], constraints: { id: /\d+/ } do resources :jobs, only: [], constraints: { id: /\d+/ } do
member do member do
get '/proxy.ws/authorize', to: 'jobs#proxy_websocket_authorize', constraints: { format: nil } get '/proxy.ws/authorize', to: 'jobs#proxy_websocket_authorize', format: false
get :proxy get :proxy
end end
end end
......
...@@ -11,7 +11,7 @@ module EE ...@@ -11,7 +11,7 @@ module EE
end end
def container_image_regex def container_image_regex
@container_image_regex ||= %r{\A([\w\.-]+\/){0,1}([\w\.-]+)\z}.freeze @container_image_regex ||= %r{([\w\.-]+\/){0,1}[\w\.-]+}.freeze
end end
end end
end end
......
...@@ -10,7 +10,13 @@ describe Gitlab::PathRegex do ...@@ -10,7 +10,13 @@ describe Gitlab::PathRegex do
it { is_expected.to match('gitlab_foss') } it { is_expected.to match('gitlab_foss') }
it { is_expected.to match('gitlab-org/gitlab-foss') } it { is_expected.to match('gitlab-org/gitlab-foss') }
it { is_expected.to match('100px.com/100px.ruby') } it { is_expected.to match('100px.com/100px.ruby') }
it { is_expected.not_to match('foo/bar/baz') }
it { is_expected.not_to match('ruby:2.3.6') } it 'only matches at most one slash' do
expect(subject.match('foo/bar/baz')[0]).to eq('foo/bar')
end
it 'does not match other non-word characters' do
expect(subject.match('ruby:2.3.6')[0]).to eq('ruby')
end
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment