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 )
end
if response.success? def new
@policy = response.payload redirect_to new_project_security_policy_path(project)
else
render_404
end
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 subject
stub_licensed_features(threat_monitoring: true)
end
it 'renders the new template' do
subject
expect(response).to have_gitlab_http_status(:ok)
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) expect(response).to redirect_to(new_project_security_policy_path(project))
end
end end
end end
...@@ -110,16 +92,10 @@ RSpec.describe Projects::ThreatMonitoringController do ...@@ -110,16 +92,10 @@ RSpec.describe Projects::ThreatMonitoringController do
sign_in(user) sign_in(user)
end end
context 'when feature is available' do it 'returns 404' do
before do subject
stub_licensed_features(threat_monitoring: true)
end
it 'returns 404' do
subject
expect(response).to have_gitlab_http_status(:not_found) expect(response).to have_gitlab_http_status(:not_found)
end
end end
end end
...@@ -144,96 +120,40 @@ RSpec.describe Projects::ThreatMonitoringController do ...@@ -144,96 +120,40 @@ RSpec.describe Projects::ThreatMonitoringController do
let(:kind) { 'CiliumNetworkPolicy' } let(:kind) { 'CiliumNetworkPolicy' }
context 'with authorized user' do context 'with authorized user' do
before do let(:service) { instance_double('NetworkPolicies::FindResourceService', execute: ServiceResponse.success(payload: policy)) }
project.add_developer(user) let(:policy) do
sign_in(user) Gitlab::Kubernetes::CiliumNetworkPolicy.new(
name: 'policy',
namespace: 'another',
selector: { matchLabels: { role: 'db' } },
ingress: [{ from: [{ namespaceSelector: { matchLabels: { project: 'myproject' } } }] }]
)
end end
context 'when feature is available' do before do
let(:service) { instance_double('NetworkPolicies::FindResourceService', execute: ServiceResponse.success(payload: policy)) } stub_licensed_features(threat_monitoring: true)
let(:policy) do
Gitlab::Kubernetes::CiliumNetworkPolicy.new(
name: 'policy',
namespace: 'another',
selector: { matchLabels: { role: 'db' } },
ingress: [{ from: [{ namespaceSelector: { matchLabels: { project: 'myproject' } } }] }]
)
end
before do
stub_licensed_features(threat_monitoring: true)
allow(NetworkPolicies::FindResourceService).to(
receive(:new)
.with(resource_name: 'policy', environment: environment, kind: Gitlab::Kubernetes::CiliumNetworkPolicy::KIND)
.and_return(service)
)
end
it 'renders the new template' do
subject
expect(response).to have_gitlab_http_status(:ok)
expect(response).to render_template(:edit)
end
context 'when different policy kind is requested' do
let(:policy) do
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
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 allow(NetworkPolicies::FindResourceService).to(
subject receive(:new)
.with(resource_name: 'policy', environment: environment, kind: Gitlab::Kubernetes::CiliumNetworkPolicy::KIND)
.and_return(service)
)
expect(response).to have_gitlab_http_status(:not_found) project.add_developer(user)
end sign_in(user)
end
end end
context 'when feature is not available' do it 'redirects to policies#edit page' do
before do subject
stub_licensed_features(threat_monitoring: false)
end
it 'returns 404' do
subject
expect(response).to have_gitlab_http_status(:not_found) expect(response).to redirect_to(
end edit_project_security_policy_path(
project,
environment_id: environment_id,
id: 'policy',
kind: kind
)
)
end end
end end
...@@ -242,16 +162,10 @@ RSpec.describe Projects::ThreatMonitoringController do ...@@ -242,16 +162,10 @@ RSpec.describe Projects::ThreatMonitoringController do
sign_in(user) sign_in(user)
end end
context 'when feature is available' do it 'returns 404' do
before do subject
stub_licensed_features(threat_monitoring: true)
end
it 'returns 404' do
subject
expect(response).to have_gitlab_http_status(:not_found) expect(response).to have_gitlab_http_status(:not_found)
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