Commit a07a65b5 authored by Alexander Turinske's avatar Alexander Turinske

Redirect threat_monitoring policies endpoints

- redirect threat monitoring policies endpoints to the
  policies controller
- update tests

Changelog: changed
EE: true
parent ec74935e
...@@ -6,10 +6,6 @@ module Projects ...@@ -6,10 +6,6 @@ module Projects
before_action :authorize_read_threat_monitoring! before_action :authorize_read_threat_monitoring!
before_action do
push_frontend_feature_flag(:security_orchestration_policies_configuration, @project, default_enabled: :yaml)
end
feature_category :not_owned feature_category :not_owned
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
...@@ -19,19 +15,17 @@ module Projects ...@@ -19,19 +15,17 @@ module Projects
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
def edit def edit
@environment = project.environments.find(params[:environment_id]) redirect_to edit_project_security_policy_path(
@policy_name = params[:id] project,
response = NetworkPolicies::FindResourceService.new( environment_id: params[:environment_id],
resource_name: @policy_name, id: params[:id],
environment: @environment, type: params[:type],
kind: params[:kind].presence || Gitlab::Kubernetes::CiliumNetworkPolicy::KIND kind: params[:kind]
).execute )
if response.success?
@policy = response.payload
else
render_404
end end
def new
redirect_to new_project_security_policy_path(project)
end end
end end
end end
...@@ -75,33 +75,15 @@ RSpec.describe Projects::ThreatMonitoringController do ...@@ -75,33 +75,15 @@ RSpec.describe Projects::ThreatMonitoringController do
context 'with authorized user' do context 'with authorized user' do
before do before do
stub_licensed_features(threat_monitoring: true)
project.add_developer(user) project.add_developer(user)
sign_in(user) sign_in(user)
end end
context 'when feature is available' do it 'redirects to policies#new page' do
before do
stub_licensed_features(threat_monitoring: true)
end
it 'renders the new template' do
subject subject
expect(response).to have_gitlab_http_status(:ok) expect(response).to redirect_to(new_project_security_policy_path(project))
expect(response).to render_template(:new)
end
end
context 'when feature is not available' do
before do
stub_licensed_features(threat_monitoring: false)
end
it 'returns 404' do
subject
expect(response).to have_gitlab_http_status(:not_found)
end
end end
end end
...@@ -110,18 +92,12 @@ RSpec.describe Projects::ThreatMonitoringController do ...@@ -110,18 +92,12 @@ RSpec.describe Projects::ThreatMonitoringController do
sign_in(user) sign_in(user)
end end
context 'when feature is available' do
before do
stub_licensed_features(threat_monitoring: true)
end
it 'returns 404' do it 'returns 404' do
subject subject
expect(response).to have_gitlab_http_status(:not_found) expect(response).to have_gitlab_http_status(:not_found)
end end
end end
end
context 'with anonymous user' do context 'with anonymous user' do
it 'returns 302' do it 'returns 302' do
...@@ -144,12 +120,6 @@ RSpec.describe Projects::ThreatMonitoringController do ...@@ -144,12 +120,6 @@ RSpec.describe Projects::ThreatMonitoringController do
let(:kind) { 'CiliumNetworkPolicy' } let(:kind) { 'CiliumNetworkPolicy' }
context 'with authorized user' do context 'with authorized user' do
before do
project.add_developer(user)
sign_in(user)
end
context 'when feature is available' do
let(:service) { instance_double('NetworkPolicies::FindResourceService', execute: ServiceResponse.success(payload: policy)) } let(:service) { instance_double('NetworkPolicies::FindResourceService', execute: ServiceResponse.success(payload: policy)) }
let(:policy) do let(:policy) do
Gitlab::Kubernetes::CiliumNetworkPolicy.new( Gitlab::Kubernetes::CiliumNetworkPolicy.new(
...@@ -168,73 +138,23 @@ RSpec.describe Projects::ThreatMonitoringController do ...@@ -168,73 +138,23 @@ RSpec.describe Projects::ThreatMonitoringController do
.with(resource_name: 'policy', environment: environment, kind: Gitlab::Kubernetes::CiliumNetworkPolicy::KIND) .with(resource_name: 'policy', environment: environment, kind: Gitlab::Kubernetes::CiliumNetworkPolicy::KIND)
.and_return(service) .and_return(service)
) )
project.add_developer(user)
sign_in(user)
end end
it 'renders the new template' do it 'redirects to policies#edit page' do
subject subject
expect(response).to have_gitlab_http_status(:ok) expect(response).to redirect_to(
expect(response).to render_template(:edit) edit_project_security_policy_path(
end project,
environment_id: environment_id,
context 'when different policy kind is requested' do id: 'policy',
let(:policy) do kind: kind
Gitlab::Kubernetes::NetworkPolicy.new(
name: 'not-cilium-policy',
namespace: 'another',
selector: { matchLabels: { role: 'db' } },
ingress: [{ from: [{ namespaceSelector: { matchLabels: { project: 'myproject' } } }] }]
) )
end
before do
allow(NetworkPolicies::FindResourceService).to(
receive(:new)
.with(resource_name: 'policy', environment: environment, kind: Gitlab::Kubernetes::NetworkPolicy::KIND)
.and_return(service)
) )
end end
it 'renders the new template' do
subject
expect(response).to have_gitlab_http_status(:ok)
expect(response).to render_template(:edit)
end
end
context 'when environment is missing' do
let(:environment_id) { 'missing' }
it 'returns 404' do
subject
expect(response).to have_gitlab_http_status(:not_found)
end
end
context 'when service failed' do
let(:service) { instance_double('NetworkPolicies::FindResourceService', execute: ServiceResponse.error(message: 'error')) }
it 'returns 404' do
subject
expect(response).to have_gitlab_http_status(:not_found)
end
end
end
context 'when feature is not available' do
before do
stub_licensed_features(threat_monitoring: false)
end
it 'returns 404' do
subject
expect(response).to have_gitlab_http_status(:not_found)
end
end
end end
context 'with unauthorized user' do context 'with unauthorized user' do
...@@ -242,18 +162,12 @@ RSpec.describe Projects::ThreatMonitoringController do ...@@ -242,18 +162,12 @@ RSpec.describe Projects::ThreatMonitoringController do
sign_in(user) sign_in(user)
end end
context 'when feature is available' do
before do
stub_licensed_features(threat_monitoring: true)
end
it 'returns 404' do it 'returns 404' do
subject subject
expect(response).to have_gitlab_http_status(:not_found) expect(response).to have_gitlab_http_status(:not_found)
end end
end end
end
context 'with anonymous user' do context 'with anonymous user' do
it 'returns 302' do it 'returns 302' do
......
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