chef 17.10.163 → 18.0.169
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +19 -20
- data/README.md +7 -7
- data/Rakefile +3 -22
- data/{chef-universal-mingw32.gemspec → chef-universal-mingw-ucrt.gemspec} +8 -7
- data/chef.gemspec +17 -15
- data/lib/chef/api_client_v1.rb +9 -1
- data/lib/chef/application/exit_code.rb +3 -3
- data/lib/chef/client.rb +182 -0
- data/lib/chef/compliance/input.rb +1 -1
- data/lib/chef/compliance/profile.rb +1 -1
- data/lib/chef/compliance/profile_collection.rb +0 -1
- data/lib/chef/compliance/waiver.rb +1 -1
- data/lib/chef/cookbook/syntax_check.rb +2 -2
- data/lib/chef/dsl/reader_helpers.rb +1 -1
- data/lib/chef/dsl/rest_resource.rb +77 -0
- data/lib/chef/event_dispatch/base.rb +3 -0
- data/lib/chef/exceptions.rb +8 -0
- data/lib/chef/http/authenticator.rb +170 -3
- data/lib/chef/http/ssl_policies.rb +4 -4
- data/lib/chef/mixin/checksum.rb +0 -6
- data/lib/chef/mixin/homebrew_user.rb +5 -15
- data/lib/chef/mixin/openssl_helper.rb +13 -17
- data/lib/chef/mixin/powershell_exec.rb +5 -28
- data/lib/chef/node/mixin/immutablize_array.rb +1 -0
- data/lib/chef/property.rb +5 -3
- data/lib/chef/provider/cron.rb +1 -5
- data/lib/chef/provider/file.rb +2 -2
- data/lib/chef/provider/group/windows.rb +1 -1
- data/lib/chef/provider/http_request.rb +11 -9
- data/lib/chef/provider/mount/linux.rb +5 -0
- data/lib/chef/provider/mount/mount.rb +8 -0
- data/lib/chef/provider/mount/windows.rb +1 -1
- data/lib/chef/provider/package/chocolatey.rb +1 -14
- data/lib/chef/provider/package/rubygems.rb +1 -1
- data/lib/chef/provider/package/windows/msi.rb +2 -2
- data/lib/chef/provider/package/windows/registry_uninstall_entry.rb +1 -1
- data/lib/chef/provider/package/windows.rb +1 -1
- data/lib/chef/provider/package/yum/yum_helper.py +14 -2
- data/lib/chef/provider/package/zypper/version.rb +60 -0
- data/lib/chef/provider/package/zypper.rb +47 -8
- data/lib/chef/provider/service/windows.rb +1 -1
- data/lib/chef/provider/user/aix.rb +5 -0
- data/lib/chef/provider/user/linux.rb +29 -0
- data/lib/chef/provider/user/mac.rb +1 -1
- data/lib/chef/provider/user.rb +46 -14
- data/lib/chef/provider.rb +1 -1
- data/lib/chef/recipe.rb +1 -1
- data/lib/chef/resource/_rest_resource.rb +389 -0
- data/lib/chef/resource/alternatives.rb +0 -1
- data/lib/chef/resource/apt_package.rb +0 -1
- data/lib/chef/resource/apt_preference.rb +0 -1
- data/lib/chef/resource/apt_repository.rb +0 -1
- data/lib/chef/resource/apt_update.rb +0 -1
- data/lib/chef/resource/archive_file.rb +0 -1
- data/lib/chef/resource/bash.rb +0 -1
- data/lib/chef/resource/batch.rb +0 -1
- data/lib/chef/resource/bff_package.rb +0 -1
- data/lib/chef/resource/breakpoint.rb +0 -1
- data/lib/chef/resource/build_essential.rb +0 -1
- data/lib/chef/resource/cab_package.rb +0 -1
- data/lib/chef/resource/chef_client_config.rb +14 -18
- data/lib/chef/resource/chef_client_cron.rb +1 -2
- data/lib/chef/resource/chef_client_launchd.rb +2 -2
- data/lib/chef/resource/chef_client_scheduled_task.rb +3 -3
- data/lib/chef/resource/chef_client_systemd_timer.rb +1 -2
- data/lib/chef/resource/chef_client_trusted_certificate.rb +0 -1
- data/lib/chef/resource/chef_gem.rb +0 -1
- data/lib/chef/resource/chef_handler.rb +0 -1
- data/lib/chef/resource/chef_sleep.rb +1 -3
- data/lib/chef/resource/chef_vault_secret.rb +0 -1
- data/lib/chef/resource/chocolatey_config.rb +0 -1
- data/lib/chef/resource/chocolatey_feature.rb +0 -1
- data/lib/chef/resource/chocolatey_package.rb +0 -1
- data/lib/chef/resource/chocolatey_source.rb +0 -1
- data/lib/chef/resource/cookbook_file.rb +0 -1
- data/lib/chef/resource/cron/_cron_shared.rb +0 -1
- data/lib/chef/resource/cron/cron.rb +0 -1
- data/lib/chef/resource/cron/cron_d.rb +15 -1
- data/lib/chef/resource/cron_access.rb +0 -1
- data/lib/chef/resource/csh.rb +0 -1
- data/lib/chef/resource/directory.rb +0 -1
- data/lib/chef/resource/dmg_package.rb +0 -1
- data/lib/chef/resource/dnf_package.rb +0 -1
- data/lib/chef/resource/dpkg_package.rb +0 -1
- data/lib/chef/resource/dsc_resource.rb +0 -1
- data/lib/chef/resource/dsc_script.rb +0 -1
- data/lib/chef/resource/execute.rb +0 -1
- data/lib/chef/resource/file.rb +0 -1
- data/lib/chef/resource/freebsd_package.rb +0 -1
- data/lib/chef/resource/gem_package.rb +0 -1
- data/lib/chef/resource/group.rb +25 -2
- data/lib/chef/resource/habitat/habitat_package.rb +0 -1
- data/lib/chef/resource/habitat/habitat_sup.rb +6 -7
- data/lib/chef/resource/habitat/habitat_sup_windows.rb +1 -1
- data/lib/chef/resource/habitat_config.rb +0 -1
- data/lib/chef/resource/habitat_install.rb +0 -1
- data/lib/chef/resource/habitat_service.rb +0 -1
- data/lib/chef/resource/habitat_user_toml.rb +0 -1
- data/lib/chef/resource/homebrew_cask.rb +8 -8
- data/lib/chef/resource/homebrew_package.rb +1 -2
- data/lib/chef/resource/homebrew_tap.rb +5 -6
- data/lib/chef/resource/homebrew_update.rb +0 -2
- data/lib/chef/resource/hostname.rb +0 -1
- data/lib/chef/resource/http_request.rb +0 -1
- data/lib/chef/resource/ifconfig.rb +0 -1
- data/lib/chef/resource/inspec_input.rb +0 -1
- data/lib/chef/resource/inspec_waiver.rb +0 -1
- data/lib/chef/resource/inspec_waiver_file_entry.rb +2 -3
- data/lib/chef/resource/ips_package.rb +0 -1
- data/lib/chef/resource/kernel_module.rb +0 -1
- data/lib/chef/resource/ksh.rb +0 -1
- data/lib/chef/resource/launchd.rb +0 -1
- data/lib/chef/resource/link.rb +0 -1
- data/lib/chef/resource/locale.rb +2 -6
- data/lib/chef/resource/log.rb +0 -1
- data/lib/chef/resource/lwrp_base.rb +0 -4
- data/lib/chef/resource/macos_userdefaults.rb +5 -10
- data/lib/chef/resource/macosx_service.rb +0 -1
- data/lib/chef/resource/macports_package.rb +0 -1
- data/lib/chef/resource/mdadm.rb +0 -1
- data/lib/chef/resource/mount.rb +0 -1
- data/lib/chef/resource/msu_package.rb +0 -1
- data/lib/chef/resource/notify_group.rb +0 -2
- data/lib/chef/resource/ohai.rb +0 -1
- data/lib/chef/resource/ohai_hint.rb +0 -1
- data/lib/chef/resource/openbsd_package.rb +0 -1
- data/lib/chef/resource/openssl_dhparam.rb +0 -2
- data/lib/chef/resource/openssl_ec_private_key.rb +0 -2
- data/lib/chef/resource/openssl_ec_public_key.rb +0 -2
- data/lib/chef/resource/openssl_rsa_private_key.rb +0 -2
- data/lib/chef/resource/openssl_rsa_public_key.rb +0 -2
- data/lib/chef/resource/openssl_x509_certificate.rb +0 -2
- data/lib/chef/resource/openssl_x509_crl.rb +0 -2
- data/lib/chef/resource/openssl_x509_request.rb +0 -2
- data/lib/chef/resource/osx_profile.rb +0 -1
- data/lib/chef/resource/package.rb +0 -1
- data/lib/chef/resource/pacman_package.rb +0 -1
- data/lib/chef/resource/paludis_package.rb +0 -1
- data/lib/chef/resource/perl.rb +0 -1
- data/lib/chef/resource/plist.rb +7 -3
- data/lib/chef/resource/portage_package.rb +0 -1
- data/lib/chef/resource/powershell_package.rb +0 -1
- data/lib/chef/resource/powershell_package_source.rb +0 -1
- data/lib/chef/resource/powershell_script.rb +0 -1
- data/lib/chef/resource/python.rb +0 -1
- data/lib/chef/resource/reboot.rb +0 -1
- data/lib/chef/resource/registry_key.rb +0 -1
- data/lib/chef/resource/remote_directory.rb +0 -1
- data/lib/chef/resource/remote_file.rb +0 -1
- data/lib/chef/resource/rhsm_errata.rb +0 -1
- data/lib/chef/resource/rhsm_errata_level.rb +0 -1
- data/lib/chef/resource/rhsm_register.rb +0 -3
- data/lib/chef/resource/rhsm_repo.rb +0 -1
- data/lib/chef/resource/rhsm_subscription.rb +0 -1
- data/lib/chef/resource/route.rb +0 -1
- data/lib/chef/resource/rpm_package.rb +0 -1
- data/lib/chef/resource/ruby.rb +0 -1
- data/lib/chef/resource/ruby_block.rb +0 -1
- data/lib/chef/resource/scm/_scm.rb +0 -2
- data/lib/chef/resource/scm/git.rb +0 -2
- data/lib/chef/resource/scm/subversion.rb +0 -2
- data/lib/chef/resource/script.rb +0 -1
- data/lib/chef/resource/selinux/common_helpers.rb +47 -0
- data/lib/chef/resource/selinux/selinux_debian.erb +18 -0
- data/lib/chef/resource/selinux/selinux_default.erb +15 -0
- data/lib/chef/resource/selinux_boolean.rb +101 -0
- data/lib/chef/resource/selinux_fcontext.rb +160 -0
- data/lib/chef/resource/selinux_install.rb +107 -0
- data/lib/chef/resource/selinux_module.rb +143 -0
- data/lib/chef/resource/selinux_permissive.rb +64 -0
- data/lib/chef/resource/selinux_port.rb +118 -0
- data/lib/chef/resource/selinux_state.rb +166 -0
- data/lib/chef/resource/service.rb +0 -1
- data/lib/chef/resource/smartos_package.rb +0 -1
- data/lib/chef/resource/snap_package.rb +0 -1
- data/lib/chef/resource/solaris_package.rb +0 -1
- data/lib/chef/resource/ssh_known_hosts_entry.rb +0 -1
- data/lib/chef/resource/sudo.rb +0 -1
- data/lib/chef/resource/support/client.erb +5 -6
- data/lib/chef/resource/swap_file.rb +0 -1
- data/lib/chef/resource/sysctl.rb +1 -2
- data/lib/chef/resource/systemd_unit.rb +0 -1
- data/lib/chef/resource/template.rb +0 -1
- data/lib/chef/resource/timezone.rb +0 -1
- data/lib/chef/resource/user/aix_user.rb +0 -1
- data/lib/chef/resource/user/linux_user.rb +0 -1
- data/lib/chef/resource/user/mac_user.rb +0 -1
- data/lib/chef/resource/user/pw_user.rb +0 -1
- data/lib/chef/resource/user/solaris_user.rb +0 -1
- data/lib/chef/resource/user/windows_user.rb +0 -1
- data/lib/chef/resource/user.rb +10 -1
- data/lib/chef/resource/user_ulimit.rb +0 -1
- data/lib/chef/resource/whyrun_safe_ruby_block.rb +0 -1
- data/lib/chef/resource/windows_ad_join.rb +0 -2
- data/lib/chef/resource/windows_audit_policy.rb +0 -2
- data/lib/chef/resource/windows_auto_run.rb +0 -1
- data/lib/chef/resource/windows_defender.rb +0 -1
- data/lib/chef/resource/windows_defender_exclusion.rb +0 -1
- data/lib/chef/resource/windows_dfs_folder.rb +0 -1
- data/lib/chef/resource/windows_dfs_namespace.rb +0 -1
- data/lib/chef/resource/windows_dfs_server.rb +0 -1
- data/lib/chef/resource/windows_dns_record.rb +0 -1
- data/lib/chef/resource/windows_dns_zone.rb +0 -1
- data/lib/chef/resource/windows_env.rb +0 -1
- data/lib/chef/resource/windows_feature.rb +0 -1
- data/lib/chef/resource/windows_feature_dism.rb +0 -1
- data/lib/chef/resource/windows_feature_powershell.rb +0 -1
- data/lib/chef/resource/windows_firewall_profile.rb +0 -2
- data/lib/chef/resource/windows_firewall_rule.rb +0 -1
- data/lib/chef/resource/windows_font.rb +2 -3
- data/lib/chef/resource/windows_package.rb +0 -1
- data/lib/chef/resource/windows_pagefile.rb +0 -2
- data/lib/chef/resource/windows_path.rb +0 -1
- data/lib/chef/resource/windows_printer.rb +0 -1
- data/lib/chef/resource/windows_printer_port.rb +0 -1
- data/lib/chef/resource/windows_script.rb +0 -2
- data/lib/chef/resource/windows_security_policy.rb +0 -1
- data/lib/chef/resource/windows_service.rb +0 -1
- data/lib/chef/resource/windows_share.rb +0 -1
- data/lib/chef/resource/windows_shortcut.rb +1 -2
- data/lib/chef/resource/windows_task.rb +0 -1
- data/lib/chef/resource/windows_uac.rb +0 -1
- data/lib/chef/resource/windows_update_settings.rb +0 -1
- data/lib/chef/resource/windows_user_privilege.rb +0 -1
- data/lib/chef/resource/windows_workgroup.rb +0 -1
- data/lib/chef/resource/yum_package.rb +0 -1
- data/lib/chef/resource/yum_repository.rb +0 -1
- data/lib/chef/resource/zypper_package.rb +0 -1
- data/lib/chef/resource/zypper_repository.rb +0 -1
- data/lib/chef/resource.rb +12 -5
- data/lib/chef/resources.rb +7 -0
- data/lib/chef/run_context.rb +3 -3
- data/lib/chef/secret_fetcher/azure_key_vault.rb +1 -1
- data/lib/chef/version.rb +1 -1
- data/lib/chef/win32/handle.rb +6 -7
- data/lib/chef/win32/registry.rb +7 -3
- data/spec/data/rubygems.org/sexp_processor-info +2 -1
- data/spec/data/trusted_certs/example.crt +20 -29
- data/spec/data/trusted_certs/example_no_cn.crt +34 -30
- data/spec/data/trusted_certs/opscode.pem +54 -33
- data/spec/functional/resource/chocolatey_package_spec.rb +20 -32
- data/spec/functional/resource/dsc_script_spec.rb +1 -1
- data/spec/functional/resource/group_spec.rb +26 -42
- data/spec/functional/resource/link_spec.rb +8 -8
- data/spec/functional/resource/macos_userdefaults_spec.rb +4 -4
- data/spec/functional/resource/plist_spec.rb +25 -0
- data/spec/functional/resource/user/linux_user_spec.rb +127 -0
- data/spec/functional/resource/windows_certificate_spec.rb +1 -26
- data/spec/functional/resource/windows_font_spec.rb +12 -9
- data/spec/functional/resource/yum_package_spec.rb +1 -17
- data/spec/functional/resource/zypper_package_spec.rb +12 -10
- data/spec/functional/shell_spec.rb +1 -2
- data/spec/functional/version_spec.rb +1 -1
- data/spec/functional/win32/registry_spec.rb +0 -3
- data/spec/integration/client/client_spec.rb +82 -3
- data/spec/integration/client/exit_code_spec.rb +1 -1
- data/spec/integration/client/ipv6_spec.rb +1 -1
- data/spec/integration/compliance/compliance_spec.rb +1 -1
- data/spec/integration/recipes/accumulator_spec.rb +1 -1
- data/spec/integration/recipes/lwrp_inline_resources_spec.rb +1 -1
- data/spec/integration/recipes/lwrp_spec.rb +1 -1
- data/spec/integration/recipes/notifies_spec.rb +1 -1
- data/spec/integration/recipes/notifying_block_spec.rb +1 -1
- data/spec/integration/recipes/remote_directory.rb +1 -1
- data/spec/integration/recipes/unified_mode_spec.rb +1 -1
- data/spec/integration/recipes/use_partial_spec.rb +2 -1
- data/spec/integration/solo/solo_spec.rb +2 -2
- data/spec/spec_helper.rb +1 -5
- data/spec/support/platform_helpers.rb +0 -4
- data/spec/support/ruby_installer.rb +1 -1
- data/spec/support/shared/functional/windows_script.rb +2 -2
- data/spec/unit/application/client_spec.rb +0 -10
- data/spec/unit/client_spec.rb +70 -2
- data/spec/unit/compliance/reporter/chef_server_automate_spec.rb +1 -1
- data/spec/unit/cookbook/syntax_check_spec.rb +3 -0
- data/spec/unit/http/authenticator_spec.rb +68 -0
- data/spec/unit/mixin/checksum_spec.rb +0 -28
- data/spec/unit/mixin/homebrew_user_spec.rb +7 -30
- data/spec/unit/mixin/openssl_helper_spec.rb +1 -1
- data/spec/unit/mixin/powershell_exec_spec.rb +5 -5
- data/spec/unit/platform/query_helpers_spec.rb +2 -17
- data/spec/unit/provider/cron_spec.rb +0 -34
- data/spec/unit/provider/http_request_spec.rb +60 -72
- data/spec/unit/provider/mount/linux_spec.rb +10 -0
- data/spec/unit/provider/package/chocolatey_spec.rb +3 -20
- data/spec/unit/provider/package/rubygems_spec.rb +1 -1
- data/spec/unit/provider/package/zypper_spec.rb +32 -0
- data/spec/unit/provider/user/linux_spec.rb +51 -11
- data/spec/unit/provider/user_spec.rb +24 -6
- data/spec/unit/resource/archive_file_spec.rb +1 -1
- data/spec/unit/resource/chef_client_cron_spec.rb +5 -0
- data/spec/unit/resource/chef_client_launchd_spec.rb +5 -0
- data/spec/unit/resource/chef_client_scheduled_task_spec.rb +5 -0
- data/spec/unit/resource/chef_client_systemd_timer_spec.rb +2 -2
- data/spec/unit/resource/cron_d_spec.rb +37 -1
- data/spec/unit/resource/macos_user_defaults_spec.rb +4 -4
- data/spec/unit/resource/rest_resource_spec.rb +381 -0
- data/spec/unit/resource/selinux_boolean_spec.rb +92 -0
- data/spec/unit/resource/selinux_fcontext_spec.rb +65 -0
- data/spec/unit/resource/selinux_install_spec.rb +60 -0
- data/spec/unit/resource/selinux_module_spec.rb +55 -0
- data/spec/unit/resource/selinux_permissive_spec.rb +39 -0
- data/spec/unit/resource/selinux_port_spec.rb +42 -0
- data/spec/unit/resource/selinux_state_spec.rb +46 -0
- data/spec/unit/resource/sysctl_spec.rb +2 -2
- data/spec/unit/resource/user/linux_user_spec.rb +42 -0
- data/spec/unit/resource_spec.rb +8 -2
- data/spec/unit/util/dsc/local_configuration_manager_spec.rb +1 -1
- data/tasks/rspec.rb +1 -1
- metadata +106 -55
- data/spec/functional/assets/yumrepo-empty/repodata/01a3b-filelists.sqlite.bz2 +0 -0
- data/spec/functional/assets/yumrepo-empty/repodata/401dc-filelists.xml.gz +0 -0
- data/spec/functional/assets/yumrepo-empty/repodata/5dc1e-primary.sqlite.bz2 +0 -0
- data/spec/functional/assets/yumrepo-empty/repodata/6bf96-other.xml.gz +0 -0
- data/spec/functional/assets/yumrepo-empty/repodata/7c365-other.sqlite.bz2 +0 -0
- data/spec/functional/assets/yumrepo-empty/repodata/dabe2-primary.xml.gz +0 -0
- data/spec/functional/assets/yumrepo-empty/repodata/repomd.xml +0 -55
- data/spec/integration/client/fips_spec.rb +0 -29
- data/spec/integration/client/open_ssl_spec.rb +0 -20
- /data/spec/functional/assets/chocolatey_feed/{test-A.1.0.0.nupkg → test-A.1.0.nupkg} +0 -0
- /data/spec/functional/assets/chocolatey_feed/{test-A.1.5.0.nupkg → test-A.1.5.nupkg} +0 -0
- /data/spec/functional/assets/chocolatey_feed/{test-A.2.0.0.nupkg → test-A.2.0.nupkg} +0 -0
- /data/spec/functional/assets/chocolatey_feed/{test-B.1.0.0.nupkg → test-B.1.0.nupkg} +0 -0
- /data/spec/functional/assets/yumrepo/repodata/{01a3b-filelists.sqlite.bz2 → 4632d67cb92636e7575d911c24f0e04d3505a944e97c483abe0c3e73a7c62d33-filelists.sqlite.bz2} +0 -0
- /data/spec/functional/assets/yumrepo/repodata/{6bf96-other.xml.gz → 74599b793e54d877323837d2d81a1c3c594c44e4335f9528234bb490f7b9b439-other.xml.gz} +0 -0
- /data/spec/functional/assets/yumrepo/repodata/{5dc1e-primary.sqlite.bz2 → a845d418f919d2115ab95a56b2c76f6825ad0d0bede49181a55c04f58995d057-primary.sqlite.bz2} +0 -0
- /data/spec/functional/assets/yumrepo/repodata/{7c365-other.sqlite.bz2 → af9b7cf9ef23bd7b43068d74a460f3b5d06753d638e58e4a0c9edc35bfb9cdc4-other.sqlite.bz2} +0 -0
- /data/spec/functional/assets/yumrepo/repodata/{401dc-filelists.xml.gz → bdb4f5f1492a3b9532f22c43110a81500dd744f23da0aec5c33b2a41317c737d-filelists.xml.gz} +0 -0
- /data/spec/functional/assets/yumrepo/repodata/{dabe2-primary.xml.gz → c10d1d34ce99e02f12ec96ef68360543ab1bb7c3cb81a4a2bf78df7d8597e9df-primary.xml.gz} +0 -0
@@ -18,7 +18,11 @@
|
|
18
18
|
require "spec_helper"
|
19
19
|
|
20
20
|
describe Chef::Resource::CronD do
|
21
|
-
let(:
|
21
|
+
let(:node) { Chef::Node.new }
|
22
|
+
let(:events) { Chef::EventDispatch::Dispatcher.new }
|
23
|
+
let(:run_context) { Chef::RunContext.new(node, {}, events) }
|
24
|
+
let(:resource) { Chef::Resource::CronD.new("cronify", run_context) }
|
25
|
+
let(:provider) { resource.provider_for_action(:create) }
|
22
26
|
|
23
27
|
it "has a default action of [:create]" do
|
24
28
|
expect(resource.action).to eql([:create])
|
@@ -34,6 +38,38 @@ describe Chef::Resource::CronD do
|
|
34
38
|
expect(resource.cron_name).to eql("cronify")
|
35
39
|
end
|
36
40
|
|
41
|
+
context "on linux" do
|
42
|
+
before(:each) do
|
43
|
+
node.automatic_attrs[:os] = "linux"
|
44
|
+
end
|
45
|
+
|
46
|
+
it "the cron_name property is valid" do
|
47
|
+
provider.define_resource_requirements
|
48
|
+
|
49
|
+
expect { resource.cron_name "cron-job"; provider.process_resource_requirements }.not_to raise_error
|
50
|
+
expect { resource.cron_name "cron_job_0"; provider.process_resource_requirements }.not_to raise_error
|
51
|
+
expect { resource.cron_name "CronJob"; provider.process_resource_requirements }.not_to raise_error
|
52
|
+
expect { resource.cron_name "cron!"; provider.process_resource_requirements }.to raise_error "The cron job name should contain letters, numbers, hyphens and underscores only."
|
53
|
+
expect { resource.cron_name "cron job"; provider.process_resource_requirements }.to raise_error "The cron job name should contain letters, numbers, hyphens and underscores only."
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context "not on linux" do
|
58
|
+
before(:each) do
|
59
|
+
node.automatic_attrs[:os] = "aix"
|
60
|
+
end
|
61
|
+
|
62
|
+
it "all cron names are valid" do
|
63
|
+
provider.define_resource_requirements
|
64
|
+
|
65
|
+
expect { resource.cron_name "cron-job"; provider.process_resource_requirements }.not_to raise_error
|
66
|
+
expect { resource.cron_name "cron_job_0"; provider.process_resource_requirements }.not_to raise_error
|
67
|
+
expect { resource.cron_name "CronJob"; provider.process_resource_requirements }.not_to raise_error
|
68
|
+
expect { resource.cron_name "cron!"; provider.process_resource_requirements }.not_to raise_error
|
69
|
+
expect { resource.cron_name "cron job"; provider.process_resource_requirements }.not_to raise_error
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
37
73
|
it "the mode property defaults to '0600'" do
|
38
74
|
expect(resource.mode).to eql("0600")
|
39
75
|
end
|
@@ -39,12 +39,12 @@ describe Chef::Resource::MacosUserDefaults, :macos_only do
|
|
39
39
|
expect(resource.domain).to eq("NSGlobalDomain")
|
40
40
|
end
|
41
41
|
|
42
|
-
it "
|
43
|
-
expect(resource.host).to
|
42
|
+
it "nil for the host property" do
|
43
|
+
expect(resource.host).to be_nil
|
44
44
|
end
|
45
45
|
|
46
|
-
it "
|
47
|
-
expect(resource.user).to
|
46
|
+
it "nil for the user property" do
|
47
|
+
expect(resource.user).to be_nil
|
48
48
|
end
|
49
49
|
|
50
50
|
it ":write for resource action" do
|
@@ -0,0 +1,381 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: Copyright 2008-2016, Chef, Inc.
|
3
|
+
# License:: Apache License, Version 2.0
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
|
18
|
+
require "spec_helper"
|
19
|
+
require "train"
|
20
|
+
require "train-rest"
|
21
|
+
|
22
|
+
class RestResourceByQuery < Chef::Resource
|
23
|
+
use "core::rest_resource"
|
24
|
+
|
25
|
+
provides :rest_resource_by_query, target_mode: true
|
26
|
+
|
27
|
+
property :address, String, required: true
|
28
|
+
property :prefix, Integer, required: true
|
29
|
+
property :gateway, String
|
30
|
+
|
31
|
+
rest_api_collection "/api/v1/addresses"
|
32
|
+
rest_api_document "/api/v1/address/?ip={address}"
|
33
|
+
rest_property_map({
|
34
|
+
address: "address",
|
35
|
+
prefix: "prefix",
|
36
|
+
gateway: "gateway",
|
37
|
+
})
|
38
|
+
end
|
39
|
+
|
40
|
+
class RestResourceByPath < RestResourceByQuery
|
41
|
+
provides :rest_resource_by_path, target_mode: true
|
42
|
+
|
43
|
+
rest_api_document "/api/v1/address/{address}"
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "rest_resource using query-based addressing" do
|
47
|
+
let(:train) {
|
48
|
+
Train.create(
|
49
|
+
"rest", {
|
50
|
+
endpoint: "https://api.example.com/api/v1/",
|
51
|
+
debug_rest: true,
|
52
|
+
logger: Chef::Log,
|
53
|
+
}
|
54
|
+
).connection
|
55
|
+
}
|
56
|
+
|
57
|
+
let(:run_context) do
|
58
|
+
cookbook_collection = Chef::CookbookCollection.new([])
|
59
|
+
node = Chef::Node.new
|
60
|
+
node.name "node1"
|
61
|
+
events = Chef::EventDispatch::Dispatcher.new
|
62
|
+
Chef::RunContext.new(node, cookbook_collection, events)
|
63
|
+
end
|
64
|
+
|
65
|
+
let(:resource) do
|
66
|
+
RestResourceByQuery.new("set_address", run_context).tap do |resource|
|
67
|
+
resource.address = "192.0.2.1"
|
68
|
+
resource.prefix = 24
|
69
|
+
resource.action :configure
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
let(:provider) do
|
74
|
+
resource.provider_for_action(:configure).tap do |provider|
|
75
|
+
provider.current_resource = resource # for some stubby tests that don't call LCR
|
76
|
+
allow(provider).to receive(:api_connection).and_return(train)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
before(:each) do
|
81
|
+
allow(Chef::Provider).to receive(:new).and_return(provider)
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should include :configure action" do
|
85
|
+
expect(provider).to respond_to(:action_configure)
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should include :delete action" do
|
89
|
+
expect(provider).to respond_to(:action_delete)
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should include :nothing action" do
|
93
|
+
expect(provider).to respond_to(:action_nothing)
|
94
|
+
end
|
95
|
+
|
96
|
+
it "sets the default action as :configure" do
|
97
|
+
expect(resource.action).to eql([:configure])
|
98
|
+
end
|
99
|
+
|
100
|
+
it "supports :configure action" do
|
101
|
+
expect { resource.action :configure }.not_to raise_error
|
102
|
+
end
|
103
|
+
|
104
|
+
it "supports :delete action" do
|
105
|
+
expect { resource.action :delete }.not_to raise_error
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should mixin RestResourceDSL" do
|
109
|
+
expect(resource.class.ancestors).to include(Chef::DSL::RestResource)
|
110
|
+
end
|
111
|
+
|
112
|
+
describe "#rest_postprocess" do
|
113
|
+
before do
|
114
|
+
provider.singleton_class.send(:public, :rest_postprocess)
|
115
|
+
end
|
116
|
+
it "should have a default rest_postprocess implementation" do
|
117
|
+
expect(provider).to respond_to(:rest_postprocess)
|
118
|
+
end
|
119
|
+
|
120
|
+
it "should have a non-mutating rest_postprocess implementation" do
|
121
|
+
response = "{ data: nil }"
|
122
|
+
|
123
|
+
expect(provider.rest_postprocess(response.dup)).to eq(response)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
describe "#rest_errorhandler" do
|
128
|
+
before do
|
129
|
+
provider.singleton_class.send(:public, :rest_errorhandler)
|
130
|
+
end
|
131
|
+
|
132
|
+
it "should have a default rest_errorhandler implementation" do
|
133
|
+
expect(provider).to respond_to(:rest_errorhandler)
|
134
|
+
end
|
135
|
+
|
136
|
+
it "should have a non-mutating rest_errorhandler implementation" do
|
137
|
+
error_obj = StandardError.new
|
138
|
+
|
139
|
+
expect(provider.rest_errorhandler(error_obj.dup)).to eq(error_obj)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
describe "#required_properties" do
|
144
|
+
before do
|
145
|
+
provider.singleton_class.send(:public, :required_properties)
|
146
|
+
end
|
147
|
+
|
148
|
+
it "should include required properties only" do
|
149
|
+
expect(provider.required_properties).to contain_exactly(:address, :prefix)
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
describe "#property_map" do
|
154
|
+
before do
|
155
|
+
provider.singleton_class.send(:public, :property_map)
|
156
|
+
end
|
157
|
+
|
158
|
+
it "should map resource properties to values properly" do
|
159
|
+
expect(provider.property_map).to eq({
|
160
|
+
address: "192.0.2.1",
|
161
|
+
prefix: 24,
|
162
|
+
gateway: nil,
|
163
|
+
name: "set_address",
|
164
|
+
})
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
describe "#rest_url_collection" do
|
169
|
+
before do
|
170
|
+
provider.singleton_class.send(:public, :rest_url_collection)
|
171
|
+
end
|
172
|
+
|
173
|
+
it "should return collection URLs properly" do
|
174
|
+
expect(provider.rest_url_collection).to eq("/api/v1/addresses")
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
describe "#rest_url_document" do
|
179
|
+
before do
|
180
|
+
provider.singleton_class.send(:public, :rest_url_document)
|
181
|
+
end
|
182
|
+
|
183
|
+
it "should apply URI templates to document URLs using query syntax properly" do
|
184
|
+
expect(provider.rest_url_document).to eq("/api/v1/address/?ip=192.0.2.1")
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
# TODO: Test with path-style URLs
|
189
|
+
describe "#rest_identity_implicit" do
|
190
|
+
before do
|
191
|
+
provider.singleton_class.send(:public, :rest_identity_implicit)
|
192
|
+
end
|
193
|
+
|
194
|
+
it "should return implicit identity properties properly" do
|
195
|
+
expect(provider.rest_identity_implicit).to eq({ "ip" => :address })
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
describe "#rest_identity_values" do
|
200
|
+
before do
|
201
|
+
provider.singleton_class.send(:public, :rest_identity_values)
|
202
|
+
end
|
203
|
+
|
204
|
+
it "should return implicit identity properties and values properly" do
|
205
|
+
expect(provider.rest_identity_values).to eq({ "ip" => "192.0.2.1" })
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
# TODO: changed_value
|
210
|
+
# TODO: load_current_value
|
211
|
+
|
212
|
+
# this might be a functional test, but it runs on any O/S so I leave it here
|
213
|
+
describe "when managing a resource" do
|
214
|
+
before { WebMock.disable_net_connect! }
|
215
|
+
let(:addresses_exists) { JSON.generate([{ "address": "192.0.2.1" }]) }
|
216
|
+
let(:addresses_other) { JSON.generate([{ "address": "172.16.32.85" }]) }
|
217
|
+
let(:address_exists) { JSON.generate({ "address": "192.0.2.1", "prefix": 24, "gateway": "192.0.2.1" }) }
|
218
|
+
let(:prefix_wrong) { JSON.generate({ "address": "192.0.2.1", "prefix": 25, "gateway": "192.0.2.1" }) }
|
219
|
+
|
220
|
+
it "should be idempotent" do
|
221
|
+
stub_request(:get, "https://api.example.com/api/v1/addresses")
|
222
|
+
.to_return(status: 200, body: addresses_exists, headers: { "Content-Type" => "application/json" })
|
223
|
+
stub_request(:get, "https://api.example.com/api/v1/address/?ip=192.0.2.1")
|
224
|
+
.to_return(status: 200, body: address_exists, headers: { "Content-Type" => "application/json" })
|
225
|
+
resource.run_action(:configure)
|
226
|
+
expect(resource.updated_by_last_action?).to be false
|
227
|
+
end
|
228
|
+
|
229
|
+
it "should PATCH if a property is incorrect" do
|
230
|
+
stub_request(:get, "https://api.example.com/api/v1/addresses")
|
231
|
+
.to_return(status: 200, body: addresses_exists, headers: { "Content-Type" => "application/json" })
|
232
|
+
stub_request(:get, "https://api.example.com/api/v1/address/?ip=192.0.2.1")
|
233
|
+
.to_return(status: 200, body: prefix_wrong, headers: { "Content-Type" => "application/json" })
|
234
|
+
stub_request(:patch, "https://api.example.com/api/v1/address/?ip=192.0.2.1")
|
235
|
+
.with(
|
236
|
+
body: "{\"address\":\"192.0.2.1\",\"prefix\":25}",
|
237
|
+
headers: {
|
238
|
+
"Accept" => "application/json",
|
239
|
+
"Content-Type" => "application/json",
|
240
|
+
}
|
241
|
+
)
|
242
|
+
.to_return(status: 200, body: address_exists, headers: { "Content-Type" => "application/json" })
|
243
|
+
resource.run_action(:configure)
|
244
|
+
expect(resource.updated_by_last_action?).to be true
|
245
|
+
end
|
246
|
+
|
247
|
+
it "should POST if there's no resources at all" do
|
248
|
+
stub_request(:get, "https://api.example.com/api/v1/addresses")
|
249
|
+
.to_return(status: 200, body: "[]", headers: { "Content-Type" => "application/json" })
|
250
|
+
stub_request(:post, "https://api.example.com/api/v1/addresses")
|
251
|
+
.with(
|
252
|
+
body: "{\"address\":\"192.0.2.1\",\"prefix\":24,\"ip\":\"192.0.2.1\"}"
|
253
|
+
)
|
254
|
+
.to_return(status: 200, body: address_exists, headers: { "Content-Type" => "application/json" })
|
255
|
+
resource.run_action(:configure)
|
256
|
+
expect(resource.updated_by_last_action?).to be true
|
257
|
+
end
|
258
|
+
|
259
|
+
it "should POST if the specific resource does not exist" do
|
260
|
+
stub_request(:get, "https://api.example.com/api/v1/addresses")
|
261
|
+
.to_return(status: 200, body: addresses_other, headers: { "Content-Type" => "application/json" })
|
262
|
+
stub_request(:get, "https://api.example.com/api/v1/address/?ip=192.0.2.1")
|
263
|
+
.to_return(status: 404, body: "", headers: {})
|
264
|
+
stub_request(:post, "https://api.example.com/api/v1/addresses")
|
265
|
+
.with(
|
266
|
+
body: "{\"address\":\"192.0.2.1\",\"prefix\":24,\"ip\":\"192.0.2.1\"}"
|
267
|
+
)
|
268
|
+
.to_return(status: 200, body: address_exists, headers: { "Content-Type" => "application/json" })
|
269
|
+
resource.run_action(:configure)
|
270
|
+
expect(resource.updated_by_last_action?).to be true
|
271
|
+
end
|
272
|
+
|
273
|
+
it "should be idempotent if the resouces needs deleting and there are no resources at all" do
|
274
|
+
stub_request(:get, "https://api.example.com/api/v1/addresses")
|
275
|
+
.to_return(status: 200, body: "[]", headers: { "Content-Type" => "application/json" })
|
276
|
+
resource.run_action(:delete)
|
277
|
+
expect(resource.updated_by_last_action?).to be false
|
278
|
+
end
|
279
|
+
|
280
|
+
it "should be idempotent if the resource doesn't exist" do
|
281
|
+
stub_request(:get, "https://api.example.com/api/v1/addresses")
|
282
|
+
.to_return(status: 200, body: addresses_other, headers: { "Content-Type" => "application/json" })
|
283
|
+
stub_request(:get, "https://api.example.com/api/v1/address/?ip=192.0.2.1")
|
284
|
+
.to_return(status: 404, body: "", headers: {})
|
285
|
+
resource.run_action(:delete)
|
286
|
+
expect(resource.updated_by_last_action?).to be false
|
287
|
+
end
|
288
|
+
|
289
|
+
it "should DELETE the resource if it exists and matches" do
|
290
|
+
stub_request(:get, "https://api.example.com/api/v1/addresses")
|
291
|
+
.to_return(status: 200, body: addresses_exists, headers: { "Content-Type" => "application/json" })
|
292
|
+
stub_request(:get, "https://api.example.com/api/v1/address/?ip=192.0.2.1")
|
293
|
+
.to_return(status: 200, body: address_exists, headers: { "Content-Type" => "application/json" })
|
294
|
+
stub_request(:delete, "https://api.example.com/api/v1/address/?ip=192.0.2.1")
|
295
|
+
.to_return(status: 200, body: "", headers: {})
|
296
|
+
resource.run_action(:delete)
|
297
|
+
expect(resource.updated_by_last_action?).to be true
|
298
|
+
end
|
299
|
+
|
300
|
+
it "should DELETE the resource if it exists and doesn't match" do
|
301
|
+
stub_request(:get, "https://api.example.com/api/v1/addresses")
|
302
|
+
.to_return(status: 200, body: addresses_exists, headers: { "Content-Type" => "application/json" })
|
303
|
+
stub_request(:get, "https://api.example.com/api/v1/address/?ip=192.0.2.1")
|
304
|
+
.to_return(status: 200, body: prefix_wrong, headers: { "Content-Type" => "application/json" })
|
305
|
+
stub_request(:delete, "https://api.example.com/api/v1/address/?ip=192.0.2.1")
|
306
|
+
.to_return(status: 200, body: "", headers: {})
|
307
|
+
resource.run_action(:delete)
|
308
|
+
expect(resource.updated_by_last_action?).to be true
|
309
|
+
end
|
310
|
+
end
|
311
|
+
end
|
312
|
+
|
313
|
+
describe "rest_resource using path-based addressing" do
|
314
|
+
let(:train) {
|
315
|
+
Train.create(
|
316
|
+
"rest", {
|
317
|
+
endpoint: "https://api.example.com/api/v1/",
|
318
|
+
debug_rest: true,
|
319
|
+
logger: Chef::Log,
|
320
|
+
}
|
321
|
+
).connection
|
322
|
+
}
|
323
|
+
|
324
|
+
let(:run_context) do
|
325
|
+
cookbook_collection = Chef::CookbookCollection.new([])
|
326
|
+
node = Chef::Node.new
|
327
|
+
node.name "node1"
|
328
|
+
events = Chef::EventDispatch::Dispatcher.new
|
329
|
+
Chef::RunContext.new(node, cookbook_collection, events)
|
330
|
+
end
|
331
|
+
|
332
|
+
let(:resource) do
|
333
|
+
RestResourceByPath.new("set_address", run_context).tap do |resource|
|
334
|
+
resource.address = "192.0.2.1"
|
335
|
+
resource.prefix = 24
|
336
|
+
resource.action :configure
|
337
|
+
end
|
338
|
+
end
|
339
|
+
|
340
|
+
let(:provider) do
|
341
|
+
resource.provider_for_action(:configure).tap do |provider|
|
342
|
+
provider.current_resource = resource # for some stubby tests that don't call LCR
|
343
|
+
allow(provider).to receive(:api_connection).and_return(train)
|
344
|
+
end
|
345
|
+
end
|
346
|
+
|
347
|
+
before(:each) do
|
348
|
+
allow(Chef::Provider).to receive(:new).and_return(provider)
|
349
|
+
end
|
350
|
+
|
351
|
+
describe "#rest_url_document" do
|
352
|
+
before do
|
353
|
+
provider.singleton_class.send(:public, :rest_url_document)
|
354
|
+
end
|
355
|
+
|
356
|
+
it "should apply URI templates to document URLs using path syntax properly" do
|
357
|
+
expect(provider.rest_url_document).to eq("/api/v1/address/192.0.2.1")
|
358
|
+
end
|
359
|
+
end
|
360
|
+
|
361
|
+
describe "#rest_identity_implicit" do
|
362
|
+
before do
|
363
|
+
provider.singleton_class.send(:public, :rest_identity_implicit)
|
364
|
+
end
|
365
|
+
|
366
|
+
it "should return implicit identity properties properly" do
|
367
|
+
expect(provider.rest_identity_implicit).to eq({ "address" => :address })
|
368
|
+
end
|
369
|
+
end
|
370
|
+
|
371
|
+
describe "#rest_identity_values" do
|
372
|
+
before do
|
373
|
+
provider.singleton_class.send(:public, :rest_identity_values)
|
374
|
+
end
|
375
|
+
|
376
|
+
it "should return implicit identity properties and values properly" do
|
377
|
+
expect(provider.rest_identity_values).to eq({ "address" => "192.0.2.1" })
|
378
|
+
end
|
379
|
+
end
|
380
|
+
|
381
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: Copyright (c) Chef Software Inc.
|
3
|
+
# License:: Apache License, Version 2.0
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
|
18
|
+
require "spec_helper"
|
19
|
+
|
20
|
+
describe Chef::Resource::SelinuxBoolean do
|
21
|
+
let(:node) { Chef::Node.new }
|
22
|
+
let(:events) { Chef::EventDispatch::Dispatcher.new }
|
23
|
+
let(:run_context) { Chef::RunContext.new(node, {}, events) }
|
24
|
+
let(:resource) { Chef::Resource::SelinuxBoolean.new("fakey_fakerton", run_context) }
|
25
|
+
let(:provider) { resource.provider_for_action(:set) }
|
26
|
+
let(:selinux_state) { double("shellout!", stdout: "permissive") }
|
27
|
+
|
28
|
+
it "sets boolean proprty as name_property" do
|
29
|
+
expect(resource.boolean).to eql("fakey_fakerton")
|
30
|
+
end
|
31
|
+
|
32
|
+
it "sets the default action as :set" do
|
33
|
+
expect(resource.action).to eql([:set])
|
34
|
+
end
|
35
|
+
|
36
|
+
it "supports :set action" do
|
37
|
+
expect { resource.action :set }.not_to raise_error
|
38
|
+
end
|
39
|
+
|
40
|
+
context "coercing value property" do
|
41
|
+
it "should set value properly to 'on' when valid parameter is sent and is literal positive" do
|
42
|
+
resource.value = 1
|
43
|
+
expect(resource.value).to eql("on")
|
44
|
+
|
45
|
+
resource.value = "true"
|
46
|
+
expect(resource.value).to eql("on")
|
47
|
+
|
48
|
+
resource.value = true
|
49
|
+
expect(resource.value).to eql("on")
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should set value properly to 'off' when valid parameter is sent and is literal negative" do
|
53
|
+
resource.value = 0
|
54
|
+
expect(resource.value).to eql("off")
|
55
|
+
|
56
|
+
resource.value = "false"
|
57
|
+
expect(resource.value).to eql("off")
|
58
|
+
|
59
|
+
resource.value = false
|
60
|
+
expect(resource.value).to eql("off")
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should raise an exception if invalid parameter is sent" do
|
64
|
+
expect do
|
65
|
+
resource.value = "ON"
|
66
|
+
end.to raise_error(ArgumentError)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe "#Chef::SELinux::CommonHelpers" do
|
71
|
+
context "#selinux_permissive?" do
|
72
|
+
it "should return true if selinux_state is :permissive" do
|
73
|
+
allow(provider).to receive(:shell_out!).and_return(selinux_state)
|
74
|
+
expect(provider.selinux_permissive?).to eql(true)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
context "#selinux_disabled?" do
|
79
|
+
it "should return false if selinux_state is :permissive" do
|
80
|
+
allow(provider).to receive(:shell_out!).and_return(selinux_state)
|
81
|
+
expect(provider.selinux_disabled?).to eql(false)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
context "#selinux_enforcing?" do
|
86
|
+
it "should return false if selinux_state is :permissive" do
|
87
|
+
allow(provider).to receive(:shell_out!).and_return(selinux_state)
|
88
|
+
expect(provider.selinux_enforcing?).to eql(false)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: Copyright (c) Chef Software Inc.
|
3
|
+
# License:: Apache License, Version 2.0
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
|
18
|
+
require "spec_helper"
|
19
|
+
|
20
|
+
describe Chef::Resource::SelinuxFcontext do
|
21
|
+
let(:node) { Chef::Node.new }
|
22
|
+
let(:events) { Chef::EventDispatch::Dispatcher.new }
|
23
|
+
let(:run_context) { Chef::RunContext.new(node, {}, events) }
|
24
|
+
let(:resource) { Chef::Resource::SelinuxFcontext.new("fakey_fakerton", run_context) }
|
25
|
+
let(:provider) { resource.provider_for_action(:manage) }
|
26
|
+
let(:restoreconf) { double("shellout", stdout: "restorecon reset /var/www/html/index.html context unconfined_u:object_r:user_home_t:s0->unconfined_u:object_r:httpd_sys_content_t:s0") }
|
27
|
+
|
28
|
+
it "sets file_spec proprty as name_property" do
|
29
|
+
expect(resource.file_spec).to eql("fakey_fakerton")
|
30
|
+
end
|
31
|
+
|
32
|
+
it "sets the default action as :manage" do
|
33
|
+
expect(resource.action).to eql([:manage])
|
34
|
+
end
|
35
|
+
|
36
|
+
it "supports :manage, :addormodify, :add, :modify, :delete actions" do
|
37
|
+
expect { resource.action :manage }.not_to raise_error
|
38
|
+
expect { resource.action :addormodify }.not_to raise_error
|
39
|
+
expect { resource.action :add }.not_to raise_error
|
40
|
+
expect { resource.action :modify }.not_to raise_error
|
41
|
+
expect { resource.action :delete }.not_to raise_error
|
42
|
+
end
|
43
|
+
|
44
|
+
it "checks 'a', 'f', 'd', 'c', 'b', 's', 'l', 'p' as valid file_type property values" do
|
45
|
+
expect { resource.file_type "a" }.not_to raise_error
|
46
|
+
expect { resource.file_type "f" }.not_to raise_error
|
47
|
+
expect { resource.file_type "d" }.not_to raise_error
|
48
|
+
expect { resource.file_type "c" }.not_to raise_error
|
49
|
+
expect { resource.file_type "b" }.not_to raise_error
|
50
|
+
expect { resource.file_type "s" }.not_to raise_error
|
51
|
+
expect { resource.file_type "l" }.not_to raise_error
|
52
|
+
expect { resource.file_type "p" }.not_to raise_error
|
53
|
+
end
|
54
|
+
|
55
|
+
it "sets default value for file_type property to 'a'" do
|
56
|
+
expect(resource.file_type).to eql("a")
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "#relabel_files" do
|
60
|
+
it "returns verbose output with details of the file for which SELinux config is restored" do
|
61
|
+
allow(provider).to receive(:shell_out!).and_return(restoreconf)
|
62
|
+
expect(provider.relabel_files).to eql(restoreconf)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: Copyright (c) Chef Software Inc.
|
3
|
+
# License:: Apache License, Version 2.0
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
|
18
|
+
require "spec_helper"
|
19
|
+
|
20
|
+
describe Chef::Resource::SelinuxInstall do
|
21
|
+
let(:node) { Chef::Node.new }
|
22
|
+
let(:events) { Chef::EventDispatch::Dispatcher.new }
|
23
|
+
let(:run_context) { Chef::RunContext.new(node, {}, events) }
|
24
|
+
let(:resource) { Chef::Resource::SelinuxInstall.new("fakey_fakerton", run_context) }
|
25
|
+
let(:provider) { resource.provider_for_action(:install) }
|
26
|
+
|
27
|
+
it "sets the default action as :install" do
|
28
|
+
expect(resource.action).to eql([:install])
|
29
|
+
end
|
30
|
+
|
31
|
+
it "supports :install, :upgrade, :remove actions" do
|
32
|
+
expect { resource.action :install }.not_to raise_error
|
33
|
+
expect { resource.action :upgrade }.not_to raise_error
|
34
|
+
expect { resource.action :remove }.not_to raise_error
|
35
|
+
end
|
36
|
+
|
37
|
+
it "sets default packages on 'rhel', 'fedora', 'amazon' platforms" do
|
38
|
+
node.automatic_attrs[:platform_family] = "rhel"
|
39
|
+
expect(resource.packages).to eql(%w{make policycoreutils selinux-policy selinux-policy-targeted selinux-policy-devel libselinux-utils setools-console})
|
40
|
+
end
|
41
|
+
|
42
|
+
it "sets default packages on debian irrespective of platform_version" do
|
43
|
+
node.automatic_attrs[:platform_family] = "debian"
|
44
|
+
expect(resource.packages).to eql(%w{make policycoreutils selinux-basics selinux-policy-default selinux-policy-dev auditd setools})
|
45
|
+
end
|
46
|
+
|
47
|
+
it "sets default packages on ubuntu 18.04 platforms" do
|
48
|
+
node.automatic_attrs[:platform_family] = "debian"
|
49
|
+
node.automatic_attrs[:platform] = "ubuntu"
|
50
|
+
node.automatic_attrs[:platform_version] = 18.04
|
51
|
+
expect(resource.packages).to eql(%w{make policycoreutils selinux selinux-basics selinux-policy-default selinux-policy-dev auditd setools})
|
52
|
+
end
|
53
|
+
|
54
|
+
it "sets default packages on ubuntu platforms and versions other than 18.04" do
|
55
|
+
node.automatic_attrs[:platform_family] = "debian"
|
56
|
+
node.automatic_attrs[:platform] = "ubuntu"
|
57
|
+
node.automatic_attrs[:platform_version] = 20.04
|
58
|
+
expect(resource.packages).to eql(%w{make policycoreutils selinux-basics selinux-policy-default selinux-policy-dev auditd setools})
|
59
|
+
end
|
60
|
+
end
|