mirror of
https://github.com/inspec/inspec
synced 2024-11-22 20:53:11 +00:00
BACKPORT 6262: Prevent negative status from crashing launchd service resource (#6751)
* Prevent negative status from crashing launchd service resource (#6262) Signed-off-by: dtheyer <davidheyer2016@gmail.com> Signed-off-by: dtheyer <davidheyer2016@gmail.com> * Add missing resource_id for service resource Signed-off-by: Sonu Saha <sonu.saha@progress.com> * Rebase with inspec-4 to get hab pipeline changes Signed-off-by: Sonu Saha <sonu.saha@progress.com> --------- Signed-off-by: dtheyer <davidheyer2016@gmail.com> Signed-off-by: Sonu Saha <sonu.saha@progress.com> Co-authored-by: dtheyer <davidheyer2016@gmail.com> Co-authored-by: Sonu Saha <sonu.saha@progress.com>
This commit is contained in:
parent
7bb16c3c22
commit
8e6395e037
3 changed files with 21 additions and 1 deletions
|
@ -273,6 +273,10 @@ module Inspec::Resources
|
|||
info[:startname]
|
||||
end
|
||||
|
||||
def resource_id
|
||||
@service_name || "Service"
|
||||
end
|
||||
|
||||
def to_s
|
||||
"Service #{@service_name}"
|
||||
end
|
||||
|
@ -605,7 +609,7 @@ module Inspec::Resources
|
|||
return nil if srv.nil? || srv[0].nil?
|
||||
|
||||
# extract values from service
|
||||
parsed_srv = /^(?<pid>[0-9-]+)\t(?<exit>[0-9]+)\t(?<name>\S*)$/.match(srv[0])
|
||||
parsed_srv = /^(?<pid>[0-9-]+)\t(?<exit>[\-0-9]+)\t(?<name>\S*)$/.match(srv[0])
|
||||
enabled = !parsed_srv["name"].nil? # it's in the list
|
||||
|
||||
# check if the service is running
|
||||
|
|
1
test/fixtures/cmd/launchctl-list
vendored
1
test/fixtures/cmd/launchctl-list
vendored
|
@ -1,3 +1,4 @@
|
|||
PID Status Label
|
||||
2892 0 org.openbsd.ssh-agent
|
||||
- 0 com.apple.FilesystemUI
|
||||
- -15 org.example.killed-agent
|
||||
|
|
|
@ -463,6 +463,21 @@ describe "Inspec::Resources::Service" do
|
|||
_(resource.params).must_equal params
|
||||
end
|
||||
|
||||
it "verify mac osx service parsing with negative status launchd_service" do
|
||||
resource = MockLoader.new(:macos10_10).load_resource(
|
||||
"launchd_service", "org.example.killed-agent"
|
||||
)
|
||||
params = Hashie::Mash.new({})
|
||||
_(resource.type).must_equal "darwin"
|
||||
_(resource.name).must_equal "org.example.killed-agent"
|
||||
_(resource.description).must_be_nil
|
||||
_(resource.installed?).must_equal true
|
||||
_(resource.enabled?).must_equal true
|
||||
_(resource.running?).must_equal false
|
||||
_(resource.params).must_equal params
|
||||
_(resource.resource_id).must_equal "org.example.killed-agent"
|
||||
end
|
||||
|
||||
# wrlinux
|
||||
it "verify wrlinux service parsing" do
|
||||
resource = MockLoader.new(:wrlinux).load_resource("service", "sshd")
|
||||
|
|
Loading…
Reference in a new issue