mirror of
https://github.com/inspec/inspec
synced 2024-11-10 07:04:15 +00:00
CFINSPEC-81: Add unit test for php_config
Signed-off-by: Sonu Saha <sonu.saha@progress.com>
This commit is contained in:
parent
7c3cddbc84
commit
b4f52dff23
3 changed files with 48 additions and 0 deletions
1
test/fixtures/cmd/get-cfg-var
vendored
Normal file
1
test/fixtures/cmd/get-cfg-var
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
text/html
|
|
@ -401,6 +401,12 @@ class MockLoader
|
|||
%{sh -c 'type "cgget"'} => empty.call,
|
||||
# mail_alias
|
||||
"cat /etc/aliases | grep '^daemon:'" => cmd.call("mail-alias"),
|
||||
# php_config
|
||||
%{sh -c 'type "php"'} => empty.call,
|
||||
'Get-Command "php"' => empty.call,
|
||||
'type "php"' => empty.call,
|
||||
"php -r 'echo get_cfg_var(\"default_mimetype\");'" => cmd.call("get-cfg-var"),
|
||||
"php -c /etc/php/7.4/cli/php.ini -r 'echo get_cfg_var(\"default_mimetype\");'" => cmd.call("get-cfg-var"),
|
||||
# routing_table
|
||||
"netstat -rn" => cmd.call("netstat-rn-linux"),
|
||||
%{sh -c 'type "netstat"'} => empty.call,
|
||||
|
|
41
test/unit/resources/php_config_test.rb
Normal file
41
test/unit/resources/php_config_test.rb
Normal file
|
@ -0,0 +1,41 @@
|
|||
# If we can load the InSpec globals definition file...
|
||||
require "inspec/globals"
|
||||
require "#{Inspec.src_root}/test/helper"
|
||||
require_relative "../../../lib/inspec/resources/php_config"
|
||||
|
||||
describe Inspec::Resources::PhpConfig do
|
||||
# ubuntu
|
||||
it "checks php config parameters on ubuntu from default ini file." do
|
||||
resource = MockLoader.new("ubuntu".to_sym).load_resource("php_config", "default_mimetype")
|
||||
_(resource.value).must_equal "text/html"
|
||||
_(resource.resource_id).must_equal "default_mimetype"
|
||||
end
|
||||
|
||||
# ubuntu with custom ini file.
|
||||
it "checks php config parameters on ubuntu from default ini file." do
|
||||
resource = MockLoader.new("ubuntu".to_sym).load_resource("php_config", "default_mimetype", { "ini" => "/etc/php/7.4/cli/php.ini" })
|
||||
_(resource.value).must_equal "text/html"
|
||||
_(resource.resource_id).must_equal "default_mimetype"
|
||||
end
|
||||
|
||||
# windows
|
||||
it "checks php config parameters on windows from default ini file." do
|
||||
resource = MockLoader.new("windows".to_sym).load_resource("php_config", "default_mimetype")
|
||||
_(resource.value).must_equal "text/html"
|
||||
_(resource.resource_id).must_equal "default_mimetype"
|
||||
end
|
||||
|
||||
# macos10_10
|
||||
it "checks php config parameters on darwin from default ini file." do
|
||||
resource = MockLoader.new("macos10_10".to_sym).load_resource("php_config", "default_mimetype")
|
||||
_(resource.value).must_equal "text/html"
|
||||
_(resource.resource_id).must_equal "default_mimetype"
|
||||
end
|
||||
|
||||
# ubuntu with invalid config param
|
||||
it "checks invalid php config parameters on ubuntu from default ini file." do
|
||||
resource = MockLoader.new("ubuntu".to_sym).load_resource("php_config", "an_invalid_param")
|
||||
ex = _ { resource.value }.must_raise(Inspec::Exceptions::ResourceFailed)
|
||||
_(ex.message).must_include "Executing php -r 'echo get_cfg_var(\"an_invalid_param\");' failed"
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue