Skip to content

Commit

Permalink
more system probe tests to system probe rspecs
Browse files Browse the repository at this point in the history
  • Loading branch information
paulcacheux committed Jan 25, 2024
1 parent be483f9 commit f31685e
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 40 deletions.
40 changes: 0 additions & 40 deletions spec/security-agent_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,33 +50,10 @@
end
end

it 'system-probe.yaml is created' do
expect(chef_run).to create_template('/etc/datadog-agent/system-probe.yaml')
end

it 'security-agent.yaml is created' do
expect(chef_run).to create_template('/etc/datadog-agent/security-agent.yaml')
end

it 'system-probe.yaml contains expected YAML configuration' do
expected_yaml = <<-EOF
runtime_security_config:
enabled: true
activity_dump:
enabled: true
system_probe_config:
enabled: false
bpf_debug: false
debug_port: 0
enable_conntrack: false
sysprobe_socket: '/opt/datadog-agent/run/sysprobe.sock'
EOF

expect(chef_run).to(render_file('/etc/datadog-agent/system-probe.yaml').with_content { |content|
expect(YAML.safe_load(content).to_json).to be_json_eql(YAML.safe_load(expected_yaml).to_json)
})
end

it 'security-agent.yaml contains expected YAML configuration' do
expected_yaml = <<-EOF
compliance_config:
Expand Down Expand Up @@ -128,27 +105,10 @@
end
end

it 'system-probe.yaml is created' do
expect(chef_run).to create_template('C:/ProgramData/Datadog/system-probe.yaml')
end

it 'security-agent.yaml is created' do
expect(chef_run).to create_template('C:/ProgramData/Datadog/security-agent.yaml')
end

it 'system-probe.yaml contains expected YAML configuration' do
expected_yaml = <<-EOF
runtime_security_config:
enabled: true
activity_dump:
enabled: true
EOF

expect(chef_run).to(render_file('C:/ProgramData/Datadog/system-probe.yaml').with_content { |content|
expect(YAML.safe_load(content).to_json).to be_json_eql(YAML.safe_load(expected_yaml).to_json)
})
end

it 'security-agent.yaml contains expected YAML configuration' do
expected_yaml = <<-EOF
compliance_config:
Expand Down
107 changes: 107 additions & 0 deletions spec/system-probe_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -240,4 +240,111 @@
})
end
end

context 'with CWS enabled' do
cached(:solo) do
ChefSpec::SoloRunner.new(
platform: 'ubuntu',
version: '16.04'
) do |node|
node.name 'chef-nodename' # expected to be used as the hostname in `datadog.yaml`
node.normal['datadog'] = {
'api_key' => 'somethingnotnil',
'agent_major_version' => 6,
'security_agent' => {
'cws' => {
'enabled' => true,
}
},
'extra_config' => {
'security_agent' => {
'runtime_security_config' => {
'activity_dump' => {
'enabled' => true,
}
}
}
}
}
end
end

cached(:chef_run) do
solo.converge(described_recipe) do
solo.resource_collection.insert(
Chef::Resource::Service.new('datadog-agent', solo.run_context))
end
end

it 'system-probe.yaml is created' do
expect(chef_run).to create_template('/etc/datadog-agent/system-probe.yaml')
end

it 'system-probe.yaml contains expected YAML configuration' do
expected_yaml = <<-EOF
runtime_security_config:
enabled: true
activity_dump:
enabled: true
system_probe_config:
enabled: false
bpf_debug: false
debug_port: 0
enable_conntrack: false
sysprobe_socket: '/opt/datadog-agent/run/sysprobe.sock'
EOF

expect(chef_run).to(render_file('/etc/datadog-agent/system-probe.yaml').with_content { |content|
expect(YAML.safe_load(content).to_json).to be_json_eql(YAML.safe_load(expected_yaml).to_json)
})
end
end

context 'with CWS enabled on Windows' do
cached(:solo) do
ChefSpec::SoloRunner.new(
platform: 'windows',
version: '2012R2'
) do |node|
node.name 'chef-nodename' # expected to be used as the hostname in `datadog.yaml`
node.normal['datadog'] = {
'api_key' => 'somethingnotnil',
'agent_major_version' => 6,
'security_agent' => {
'cws' => {
'enabled' => true,
}
}
}
end
end

cached(:chef_run) do
solo.converge(described_recipe) do
solo.resource_collection.insert(
Chef::Resource::Service.new('datadog-agent', solo.run_context))
end
end

it 'system-probe.yaml is created' do
expect(chef_run).to create_template('C:/ProgramData/Datadog/system-probe.yaml')
end

it 'system-probe.yaml contains expected YAML configuration' do
expected_yaml = <<-EOF
runtime_security_config:
enabled: true
system_probe_config:
enabled: false
bpf_debug: false
debug_port: 0
enable_conntrack: false
sysprobe_socket: 'localhost:3333'
EOF

expect(chef_run).to(render_file('C:/ProgramData/Datadog/system-probe.yaml').with_content { |content|
expect(YAML.safe_load(content).to_json).to be_json_eql(YAML.safe_load(expected_yaml).to_json)
})
end
end
end

0 comments on commit f31685e

Please sign in to comment.