Commit 0923ca06 authored by Sashi's avatar Sashi

Add constraint to id param for ThreatMonitoringController

This change fixes the bug while trying to edit Cilium policies.
The reason for the bug was that rails does not accept dots
in routes by default for id params.
Changelog: fixed
EE: true
parent 6d55b31f
...@@ -41,7 +41,7 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do ...@@ -41,7 +41,7 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do
resource :threat_monitoring, only: [:show], controller: :threat_monitoring do resource :threat_monitoring, only: [:show], controller: :threat_monitoring do
get '/alerts/:iid', action: 'alert_details', constraints: { iid: /\d+/ }, as: :threat_monitoring_alert get '/alerts/:iid', action: 'alert_details', constraints: { iid: /\d+/ }, as: :threat_monitoring_alert
resources :policies, only: [:new, :edit], controller: :threat_monitoring resources :policies, only: [:new, :edit], controller: :threat_monitoring, constraints: { id: %r{[^/]+} }
end end
resources :protected_environments, only: [:create, :update, :destroy], constraints: { id: /\d+/ } do resources :protected_environments, only: [:create, :update, :destroy], constraints: { id: /\d+/ } do
......
...@@ -70,4 +70,16 @@ RSpec.describe 'EE-specific project routing' do ...@@ -70,4 +70,16 @@ RSpec.describe 'EE-specific project routing' do
expect(get('/gitlab/gitlabhq/-/security/policy')).to route_to('projects/security/policies#show', namespace_id: 'gitlab', project_id: 'gitlabhq') expect(get('/gitlab/gitlabhq/-/security/policy')).to route_to('projects/security/policies#show', namespace_id: 'gitlab', project_id: 'gitlabhq')
end end
end end
describe Projects::ThreatMonitoringController, 'routing' do
where(:id) do
%w[test.1.2 test-policy test:policy]
end
with_them do
it "to #edit" do
expect(get("/gitlab/gitlabhq/-/threat_monitoring/policies/#{id}/edit")).to route_to('projects/threat_monitoring#edit', namespace_id: 'gitlab', project_id: 'gitlabhq', id: id)
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