2015-07-15 13:15:18 +00:00
|
|
|
# encoding: utf-8
|
|
|
|
# copyright: 2015, Vulcano Security GmbH
|
2015-10-06 16:55:44 +00:00
|
|
|
# author: Christoph Hartmann
|
|
|
|
# author: Dominik Richter
|
2015-07-15 13:15:18 +00:00
|
|
|
# license: All rights reserved
|
|
|
|
|
2015-09-05 18:09:55 +00:00
|
|
|
# Usage:
|
|
|
|
#
|
|
|
|
# describe os_env('PATH') do |dirs|
|
|
|
|
# its(:split) { should_not include('') }
|
|
|
|
# its(:split) { should_not include('.') }
|
|
|
|
# end
|
|
|
|
|
2015-08-28 20:02:18 +00:00
|
|
|
class OsEnv < Vulcano.resource(1)
|
|
|
|
name 'os_env'
|
2015-07-14 22:47:04 +00:00
|
|
|
|
2015-08-28 20:02:18 +00:00
|
|
|
attr_reader :content
|
2015-09-04 07:59:30 +00:00
|
|
|
def initialize(env)
|
|
|
|
@osenv = env
|
2015-10-05 16:54:47 +00:00
|
|
|
@command_result = vulcano.command("su - root -c 'echo $#{env}'")
|
2015-08-28 20:02:18 +00:00
|
|
|
@content = @command_result.stdout.chomp
|
2015-07-26 10:30:12 +00:00
|
|
|
end
|
2015-07-14 22:47:04 +00:00
|
|
|
|
2015-07-26 10:30:12 +00:00
|
|
|
def split
|
|
|
|
# -1 is required to catch cases like dir1::dir2:
|
|
|
|
# where we have a trailing :
|
2015-08-28 20:02:18 +00:00
|
|
|
@content.split(':', -1)
|
2015-07-26 10:30:12 +00:00
|
|
|
end
|
2015-08-03 00:40:08 +00:00
|
|
|
|
2015-07-26 10:30:12 +00:00
|
|
|
def stderr
|
2015-08-28 20:02:18 +00:00
|
|
|
@command_result.stderr
|
2015-07-26 10:30:12 +00:00
|
|
|
end
|
2015-07-14 22:47:04 +00:00
|
|
|
|
2015-07-26 10:30:12 +00:00
|
|
|
def exit_status
|
2015-08-28 20:02:18 +00:00
|
|
|
@command_result.exit_status.to_i
|
2015-07-26 10:30:12 +00:00
|
|
|
end
|
2015-07-14 22:47:04 +00:00
|
|
|
|
2015-07-26 10:30:12 +00:00
|
|
|
def to_s
|
2015-09-04 07:59:30 +00:00
|
|
|
"Environment variable #{@osenv}"
|
2015-07-14 22:47:04 +00:00
|
|
|
end
|
2015-07-26 10:30:12 +00:00
|
|
|
end
|