Commit a4d9af49 authored by Alexander Turinske's avatar Alexander Turinske

Update policies#new view to pass up new data

- update helper to account for a new policy
  as well as editing a policy
parent 7ecb8fd2
......@@ -15,20 +15,24 @@ module Projects::Security::PoliciesHelper
}
end
def orchestration_policy_data(project, policy_type, policy, environment = nil)
return unless project && policy
def orchestration_policy_data(project, policy_type = nil, policy = nil, environment = nil)
return unless project
disable_scan_execution_update = !can_update_security_orchestration_policy_project?(project)
{
assigned_policy_project: assigned_policy_project(project).to_json,
disable_scan_execution_update: disable_scan_execution_update.to_s,
network_policies_endpoint: project_security_network_policies_path(project),
configure_agent_help_path: help_page_url('user/clusters/agent/repository.html'),
create_agent_help_path: help_page_url('user/clusters/agent/index.md', anchor: 'create-an-agent-record-in-gitlab'),
environments_endpoint: project_environments_path(project),
environment_id: environment&.id,
policy: policy&.to_json,
policy_type: policy_type,
project_path: project.full_path,
project_id: project.id,
policy: policy.to_json,
policy_type: policy_type,
threat_monitoring_path: project_threat_monitoring_path(project)
threat_monitoring_path: project_security_policies_path(project)
}
end
end
- add_to_breadcrumbs s_("SecurityOrchestration|Policies"), project_security_policies_path(@project)
- breadcrumb_title s_("SecurityOrchestration|New policy")
- page_title s_("SecurityOrchestration|Policy editor")
- policy_details = policy_details(@project)
- data = orchestration_policy_data(@project)
#js-policy-builder-app{ data: policy_details }
#js-policy-builder-app{ data: data }
......@@ -3,9 +3,9 @@
require 'spec_helper'
RSpec.describe Projects::Security::PoliciesHelper do
describe '#assigned_policy_project' do
let(:project) { create(:project) }
let(:project) { create(:project, :repository, :public) }
describe '#assigned_policy_project' do
context 'when a project does have a security policy project' do
let(:policy_management_project) { create(:project) }
......@@ -33,4 +33,66 @@ RSpec.describe Projects::Security::PoliciesHelper do
}
end
end
describe '#orchestration_policy_data' do
let(:owner) { project.owner }
let(:base_data) do
{
assigned_policy_project: "null",
disable_scan_execution_update: "false",
network_policies_endpoint: kind_of(String),
configure_agent_help_path: kind_of(String),
create_agent_help_path: kind_of(String),
environments_endpoint: kind_of(String),
project_path: project.full_path,
project_id: project.id,
threat_monitoring_path: kind_of(String)
}
end
before do
allow(helper).to receive(:current_user) { owner }
allow(helper).to receive(:can?).with(owner, :update_security_orchestration_policy_project, project) { true }
end
context 'when a new policy is being created' do
subject { helper.orchestration_policy_data(project) }
it 'returns expected policy data' do
expect(subject).to match(
base_data.merge(
environment_id: nil,
policy: nil,
policy_type: nil
)
)
end
end
context 'when an existing policy is being edited' do
let(:environment) { create(:environment, project: project) }
let(:policy_type) { 'container_policy' }
let(:policy) do
Gitlab::Kubernetes::CiliumNetworkPolicy.new(
name: 'policy',
namespace: 'another',
selector: { matchLabels: { role: 'db' } },
ingress: [{ from: [{ namespaceSelector: { matchLabels: { project: 'myproject' } } }] }]
)
end
subject { helper.orchestration_policy_data(project, policy_type, policy, environment) }
it 'returns expected policy data' do
expect(subject).to match(
base_data.merge(
environment_id: environment.id,
policy: policy.to_json,
policy_type: policy_type
)
)
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