Commit d370e11f authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Fix unsupported routes in Rails 6

`nil` format is not supported and throws an exception

Regex anchors in constraints are also not supported anymore. These
shouldn't be needed anyway
parent 240f55f9
......@@ -58,7 +58,7 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do
get :trace, defaults: { format: 'json' }
get :raw
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
resource :artifacts, only: [] do
......@@ -228,7 +228,7 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do
get :metrics
get :additional_metrics
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
end
......@@ -328,13 +328,7 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do
get :test_reports
get :exposed_artifacts
scope constraints: { format: nil }, action: :show do
get :commits, defaults: { tab: 'commits' }
get :pipelines, defaults: { tab: 'pipelines' }
get :diffs, defaults: { tab: 'diffs' }
end
scope constraints: { format: 'json' }, as: :json do
scope constraints: ->(req) { req.format == :json }, as: :json do
get :commits
get :pipelines
get :diffs, to: 'merge_requests/diffs#show'
......@@ -344,6 +338,12 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do
get :cached_widget, to: 'merge_requests/content#cached_widget'
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'
scope controller: 'merge_requests/conflicts' do
......@@ -372,16 +372,16 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do
scope path: 'new', as: :new_merge_request do
get '', action: :new
scope constraints: { format: nil }, action: :new do
get :diffs, defaults: { tab: 'diffs' }
get :pipelines, defaults: { tab: 'pipelines' }
end
scope constraints: { format: 'json' }, as: :json do
scope constraints: ->(req) { req.format == :json }, as: :json do
get :diffs
get :pipelines
end
scope action: :new do
get :diffs, defaults: { tab: 'diffs' }
get :pipelines, defaults: { tab: 'pipelines' }
end
get :diff_for_path
get :branch_from
get :branch_to
......
......@@ -152,7 +152,7 @@ end
# Dependency proxy for containers
# 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, {}, ['']] }
constraints image: Gitlab::PathRegex.container_image_regex do
......
......@@ -25,7 +25,7 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do
resources :jobs, only: [], constraints: { id: /\d+/ } 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
end
end
......
......@@ -11,7 +11,7 @@ module EE
end
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
......
......@@ -10,7 +10,13 @@ describe Gitlab::PathRegex do
it { is_expected.to match('gitlab_foss') }
it { is_expected.to match('gitlab-org/gitlab-foss') }
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
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