chef 17.10.163 → 18.7.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +25 -21
- data/README.md +7 -7
- data/Rakefile +3 -22
- data/{chef-universal-mingw32.gemspec → chef-universal-mingw-ucrt.gemspec} +7 -6
- data/chef.gemspec +33 -27
- data/lib/chef/api_client_v1.rb +9 -1
- data/lib/chef/application/base.rb +20 -2
- data/lib/chef/application/exit_code.rb +3 -3
- data/lib/chef/chef_fs/file_pattern.rb +1 -1
- data/lib/chef/chef_fs/file_system.rb +21 -7
- data/lib/chef/chef_fs/path_utils.rb +7 -9
- data/lib/chef/client.rb +186 -2
- data/lib/chef/compliance/default_attributes.rb +2 -2
- 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/runner.rb +6 -1
- data/lib/chef/compliance/waiver.rb +1 -1
- data/lib/chef/cookbook/chefignore.rb +4 -1
- data/lib/chef/cookbook/cookbook_version_loader.rb +1 -1
- data/lib/chef/cookbook/metadata.rb +1 -1
- data/lib/chef/cookbook/remote_file_vendor.rb +1 -3
- data/lib/chef/cookbook/synchronizer.rb +21 -3
- data/lib/chef/cookbook/syntax_check.rb +2 -2
- data/lib/chef/cookbook_manifest.rb +2 -2
- data/lib/chef/cookbook_version.rb +1 -1
- data/lib/chef/data_collector.rb +14 -0
- data/lib/chef/delayed_evaluator.rb +4 -0
- 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/event_dispatch/dispatcher.rb +0 -1
- data/lib/chef/exceptions.rb +9 -1
- data/lib/chef/file_access_control/windows.rb +4 -1
- data/lib/chef/file_cache.rb +17 -2
- data/lib/chef/formatters/doc.rb +1 -1
- data/lib/chef/guard_interpreter/resource_guard_interpreter.rb +2 -0
- data/lib/chef/http/authenticator.rb +253 -3
- data/lib/chef/http/ssl_policies.rb +2 -2
- data/lib/chef/mixin/{homebrew_user.rb → homebrew.rb} +13 -16
- data/lib/chef/mixin/openssl_helper.rb +1 -16
- data/lib/chef/mixin/powershell_exec.rb +5 -28
- data/lib/chef/monkey_patches/net-http.rb +127 -0
- data/lib/chef/node/attribute.rb +3 -11
- data/lib/chef/node/attribute_collections.rb +10 -1
- data/lib/chef/node/immutable_collections.rb +17 -6
- data/lib/chef/node/mixin/immutablize_array.rb +1 -0
- data/lib/chef/node/mixin/state_tracking.rb +7 -4
- data/lib/chef/node/mixin/state_tracking_array.rb +41 -0
- data/lib/chef/node.rb +23 -1
- data/lib/chef/platform/query_helpers.rb +4 -2
- data/lib/chef/policy_builder/policyfile.rb +8 -0
- data/lib/chef/property.rb +13 -6
- data/lib/chef/provider/group/windows.rb +1 -1
- data/lib/chef/provider/http_request.rb +11 -9
- data/lib/chef/provider/launchd.rb +2 -1
- data/lib/chef/provider/mount/linux.rb +6 -1
- data/lib/chef/provider/mount/mount.rb +13 -5
- data/lib/chef/provider/mount/windows.rb +1 -1
- data/lib/chef/provider/package/apt.rb +11 -2
- data/lib/chef/provider/package/chocolatey.rb +260 -22
- data/lib/chef/provider/package/dnf/dnf_helper.py +7 -0
- data/lib/chef/provider/package/homebrew.rb +6 -9
- data/lib/chef/provider/package/powershell.rb +1 -0
- data/lib/chef/provider/package/rubygems.rb +5 -1
- data/lib/chef/provider/package/snap.rb +3 -2
- 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/yum/yum_helper.py +3 -3
- data/lib/chef/provider/package/zypper/version.rb +60 -0
- data/lib/chef/provider/package/zypper.rb +47 -3
- data/lib/chef/provider/powershell_script.rb +96 -6
- data/lib/chef/provider/registry_key.rb +2 -0
- data/lib/chef/provider/remote_file/http.rb +1 -1
- data/lib/chef/provider/service/systemd.rb +23 -8
- data/lib/chef/provider/service/windows.rb +1 -1
- data/lib/chef/provider/service.rb +14 -0
- 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/windows.rb +5 -0
- data/lib/chef/provider/user.rb +45 -9
- data/lib/chef/provider/yum_repository.rb +13 -1
- data/lib/chef/provider.rb +1 -1
- data/lib/chef/recipe.rb +4 -12
- data/lib/chef/resource/_rest_resource.rb +389 -0
- data/lib/chef/resource/alternatives.rb +0 -1
- data/lib/chef/resource/apt_package.rb +21 -1
- data/lib/chef/resource/apt_preference.rb +0 -1
- data/lib/chef/resource/apt_repository.rb +138 -18
- data/lib/chef/resource/apt_update.rb +0 -1
- data/lib/chef/resource/archive_file.rb +0 -1
- data/lib/chef/resource/bash.rb +13 -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 +12 -14
- 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 +5 -1
- data/lib/chef/resource/chef_client_trusted_certificate.rb +0 -1
- data/lib/chef/resource/chef_gem.rb +1 -2
- 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_installer.rb +207 -0
- data/lib/chef/resource/chocolatey_package.rb +8 -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 +2 -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 +1 -2
- data/lib/chef/resource/execute.rb +8 -7
- data/lib/chef/resource/file.rb +0 -1
- data/lib/chef/resource/freebsd_package.rb +2 -1
- data/lib/chef/resource/gem_package.rb +2 -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 +2 -2
- 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 +21 -33
- data/lib/chef/resource/homebrew_package.rb +3 -2
- data/lib/chef/resource/homebrew_tap.rb +32 -18
- data/lib/chef/resource/homebrew_update.rb +4 -6
- 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 +9 -3
- data/lib/chef/resource/link.rb +0 -1
- data/lib/chef/resource/locale.rb +0 -1
- data/lib/chef/resource/log.rb +0 -1
- data/lib/chef/resource/lwrp_base.rb +0 -4
- data/lib/chef/resource/macos_pkg.rb +111 -0
- data/lib/chef/resource/macos_userdefaults.rb +3 -4
- data/lib/chef/resource/macosx_service.rb +0 -1
- data/lib/chef/resource/macports_package.rb +2 -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 +2 -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 +2 -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 +2 -1
- data/lib/chef/resource/powershell_package.rb +4 -1
- data/lib/chef/resource/powershell_package_source.rb +0 -1
- data/lib/chef/resource/powershell_script.rb +5 -2
- data/lib/chef/resource/python.rb +0 -1
- data/lib/chef/resource/reboot.rb +0 -1
- data/lib/chef/resource/registry_key.rb +6 -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 +2 -4
- 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 +2 -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_login.rb +129 -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/selinux_user.rb +137 -0
- data/lib/chef/resource/service.rb +4 -2
- data/lib/chef/resource/smartos_package.rb +2 -1
- data/lib/chef/resource/snap_package.rb +25 -1
- data/lib/chef/resource/solaris_package.rb +2 -1
- data/lib/chef/resource/ssh_known_hosts_entry.rb +0 -1
- data/lib/chef/resource/sudo.rb +37 -3
- data/lib/chef/resource/support/client.erb +2 -2
- data/lib/chef/resource/support/ulimit.erb +40 -0
- data/lib/chef/resource/swap_file.rb +0 -1
- data/lib/chef/resource/sysctl.rb +2 -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 +38 -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_certificate.rb +1 -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 +3 -4
- 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 +2 -3
- 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 +14 -11
- data/lib/chef/resource/windows_workgroup.rb +0 -1
- data/lib/chef/resource/yum_package.rb +2 -1
- data/lib/chef/resource/yum_repository.rb +4 -1
- data/lib/chef/resource/zypper_package.rb +2 -1
- data/lib/chef/resource/zypper_repository.rb +0 -1
- data/lib/chef/resource.rb +23 -5
- data/lib/chef/resource_inspector.rb +25 -7
- data/lib/chef/resource_reporter.rb +4 -0
- data/lib/chef/resources.rb +11 -0
- data/lib/chef/run_context.rb +3 -3
- data/lib/chef/secret_fetcher/azure_key_vault.rb +1 -1
- data/lib/chef/util/powershell/ps_credential.rb +10 -0
- data/lib/chef/version.rb +1 -1
- data/lib/chef/win32/handle.rb +6 -7
- data/lib/chef/win32/registry.rb +12 -4
- data/lib/chef/win32/security.rb +16 -1
- data/spec/data/rubygems.org/sexp_processor-info +2 -1
- data/spec/data/trusted_certs/intermediate.pem +38 -27
- data/spec/functional/resource/cookbook_file_spec.rb +1 -1
- data/spec/functional/resource/dsc_script_spec.rb +1 -1
- data/spec/functional/resource/execute_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/plist_spec.rb +25 -0
- data/spec/functional/resource/registry_spec.rb +233 -609
- data/spec/functional/resource/remote_file_spec.rb +1 -1
- data/spec/functional/resource/user/linux_user_spec.rb +127 -0
- data/spec/functional/resource/windows_certificate_spec.rb +1 -1
- data/spec/functional/resource/windows_font_spec.rb +12 -9
- data/spec/functional/resource/yum_package_spec.rb +1 -1
- data/spec/functional/resource/zypper_package_spec.rb +12 -0
- 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 +88 -3
- data/spec/integration/client/exit_code_spec.rb +1 -1
- data/spec/integration/client/fips_spec.rb +5 -5
- data/spec/integration/client/ipv6_spec.rb +1 -1
- data/spec/integration/client/open_ssl_spec.rb +3 -3
- 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 +7 -4
- data/spec/support/chef_helpers.rb +2 -2
- data/spec/support/platform_helpers.rb +28 -7
- data/spec/support/ruby_installer.rb +1 -1
- data/spec/support/shared/functional/file_resource.rb +3 -3
- data/spec/support/shared/functional/windows_script.rb +2 -2
- data/spec/tiny_server.rb +5 -2
- data/spec/unit/application/client_spec.rb +0 -10
- data/spec/unit/chef_fs/file_system_spec.rb +2 -0
- data/spec/unit/client_spec.rb +80 -4
- data/spec/unit/compliance/runner_spec.rb +8 -0
- data/spec/unit/cookbook/syntax_check_spec.rb +3 -0
- data/spec/unit/data_collector_spec.rb +106 -2
- data/spec/unit/delayed_evaluator_spec.rb +35 -0
- data/spec/unit/file_cache_spec.rb +64 -0
- data/spec/unit/http/authenticator_spec.rb +121 -0
- data/spec/unit/mixin/homebrew_spec.rb +118 -0
- data/spec/unit/mixin/openssl_helper_spec.rb +5 -0
- data/spec/unit/mixin/powershell_exec_spec.rb +5 -5
- data/spec/unit/node/vivid_mash_spec.rb +42 -0
- data/spec/unit/node_spec.rb +6 -0
- data/spec/unit/platform/query_helpers_spec.rb +2 -17
- data/spec/unit/property/validation_spec.rb +30 -0
- data/spec/unit/provider/apt_repository_spec.rb +48 -12
- data/spec/unit/provider/cron_spec.rb +2 -0
- data/spec/unit/provider/http_request_spec.rb +60 -72
- data/spec/unit/provider/launchd_spec.rb +2 -2
- data/spec/unit/provider/mount/aix_spec.rb +2 -2
- data/spec/unit/provider/mount/linux_spec.rb +15 -4
- data/spec/unit/provider/mount/mount_spec.rb +8 -8
- data/spec/unit/provider/package/apt_spec.rb +18 -13
- data/spec/unit/provider/package/chocolatey_spec.rb +41 -9
- data/spec/unit/provider/package/homebrew_spec.rb +4 -1
- data/spec/unit/provider/package/rpm_spec.rb +2 -2
- data/spec/unit/provider/package/rubygems_spec.rb +1 -1
- data/spec/unit/provider/package/windows_spec.rb +5 -5
- data/spec/unit/provider/package/zypper_spec.rb +32 -0
- data/spec/unit/provider/powershell_script_spec.rb +100 -4
- data/spec/unit/provider/registry_key_spec.rb +17 -17
- data/spec/unit/provider/remote_file/http_spec.rb +4 -4
- data/spec/unit/provider/service/systemd_service_spec.rb +1 -0
- data/spec/unit/provider/user/linux_spec.rb +51 -1
- data/spec/unit/provider/user/windows_spec.rb +1 -0
- data/spec/unit/provider/user_spec.rb +24 -6
- data/spec/unit/resource/apt_repository_spec.rb +5 -0
- 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 +1 -1
- data/spec/unit/resource/chocolatey_installer_spec.rb +151 -0
- data/spec/unit/resource/cron_d_spec.rb +37 -1
- data/spec/unit/resource/macos_pkg_spec.rb +38 -0
- data/spec/unit/resource/powershell_script_spec.rb +2 -2
- 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_login_spec.rb +73 -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/selinux_user_spec.rb +92 -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/yum_repository_spec.rb +4 -0
- data/spec/unit/resource_inspector_spec.rb +36 -0
- data/spec/unit/resource_reporter_spec.rb +57 -3
- data/spec/unit/resource_spec.rb +94 -2
- data/spec/unit/util/dsc/local_configuration_manager_spec.rb +1 -1
- data/spec/unit/util/powershell/ps_credential_spec.rb +6 -0
- data/tasks/rspec.rb +1 -1
- metadata +126 -44
- data/lib/chef/powershell.rb +0 -81
- data/spec/unit/mixin/homebrew_user_spec.rb +0 -119
- /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,6 +18,123 @@
|
|
|
18
18
|
|
|
19
19
|
require "spec_helper"
|
|
20
20
|
require "chef/http/authenticator"
|
|
21
|
+
require "chef/mixin/powershell_exec"
|
|
22
|
+
|
|
23
|
+
require_relative "../../../lib/chef/win32/registry"
|
|
24
|
+
|
|
25
|
+
describe Chef::HTTP::Authenticator, :windows_only do
|
|
26
|
+
let(:class_instance) { Chef::HTTP::Authenticator.new(client_name: "test") }
|
|
27
|
+
let(:method) { "GET" }
|
|
28
|
+
let(:url) { URI("https://chef.example.com/organizations/test") }
|
|
29
|
+
let(:headers) { {} }
|
|
30
|
+
let(:data) { "" }
|
|
31
|
+
let(:node_name) { "test" }
|
|
32
|
+
let(:passwrd) { "some_insecure_password" }
|
|
33
|
+
|
|
34
|
+
before(:each) do
|
|
35
|
+
Chef::Config[:node_name] = node_name
|
|
36
|
+
cert_name = "chef-#{node_name}"
|
|
37
|
+
d = Time.now
|
|
38
|
+
end_date = Time.new + (3600 * 24 * 90)
|
|
39
|
+
end_date = end_date.utc.iso8601
|
|
40
|
+
|
|
41
|
+
my_client = Chef::Client.new
|
|
42
|
+
class_instance.get_cert_password
|
|
43
|
+
pfx = my_client.generate_pfx_package(cert_name, end_date)
|
|
44
|
+
my_client.import_pfx_to_store(pfx)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
after(:each) do
|
|
48
|
+
require "chef/mixin/powershell_exec"
|
|
49
|
+
extend Chef::Mixin::PowershellExec
|
|
50
|
+
cert_name = "chef-#{node_name}"
|
|
51
|
+
delete_certificate(cert_name)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
context "when retrieving a certificate from the certificate store it" do
|
|
55
|
+
it "properly creates the password hive in the registry when it doesn't exist" do
|
|
56
|
+
delete_registry_hive
|
|
57
|
+
class_instance.get_cert_password
|
|
58
|
+
win32registry = Chef::Win32::Registry.new
|
|
59
|
+
expected_path = "HKEY_LOCAL_MACHINE\\Software\\Progress\\Authentication"
|
|
60
|
+
path_created = win32registry.key_exists?(expected_path)
|
|
61
|
+
expect(path_created).to be(true)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
it "retrieves a certificate password from the registry when the hive does not already exist" do
|
|
65
|
+
delete_registry_hive
|
|
66
|
+
password = class_instance.get_cert_password
|
|
67
|
+
expect { class_instance.get_cert_password }.not_to raise_error
|
|
68
|
+
expect(password).not_to be(nil)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
it "should return a password of at least 14 characters in length" do
|
|
72
|
+
password = class_instance.get_cert_password
|
|
73
|
+
expect(password.length).to eql(14)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
it "will retrieve a password from a partial registry hive and upgrades it while using the old decryptor" do
|
|
77
|
+
delete_registry_hive
|
|
78
|
+
load_partial_registry_hive
|
|
79
|
+
password = class_instance.get_cert_password
|
|
80
|
+
expect(password).to eql(passwrd)
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
it "verifies that the new password is now using a vector" do
|
|
84
|
+
win32registry = Chef::Win32::Registry.new
|
|
85
|
+
path = "HKEY_LOCAL_MACHINE\\Software\\Progress\\Authentication"
|
|
86
|
+
password_blob = win32registry.get_values(path)
|
|
87
|
+
if password_blob.nil? || password_blob.empty?
|
|
88
|
+
raise Chef::Exceptions::Win32RegKeyMissing
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
raw_data = password_blob.map { |x| x[:data] }
|
|
92
|
+
vector = raw_data[2]
|
|
93
|
+
expect(vector).not_to be(nil)
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
it "correctly retrieves a valid certificate in pem format from the LocalMachine certstore" do
|
|
97
|
+
require "openssl"
|
|
98
|
+
certificate = class_instance.retrieve_certificate_key(node_name)
|
|
99
|
+
cert_object = OpenSSL::PKey::RSA.new(certificate)
|
|
100
|
+
expect(cert_object.to_s).to match(/BEGIN RSA PRIVATE KEY/)
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def load_partial_registry_hive
|
|
105
|
+
extend Chef::Mixin::PowershellExec
|
|
106
|
+
password = "some_insecure_password"
|
|
107
|
+
powershell_code = <<~CODE
|
|
108
|
+
$encrypted_string = ConvertTo-SecureString "#{password}" -AsPlainText -Force
|
|
109
|
+
$secure_string = ConvertFrom-SecureString $encrypted_string
|
|
110
|
+
return $secure_string
|
|
111
|
+
CODE
|
|
112
|
+
encrypted_pass = powershell_exec!(powershell_code).result
|
|
113
|
+
Chef::Config[:auth_key_registry_type] == "user" ? store = "HKEY_CURRENT_USER" : store = "HKEY_LOCAL_MACHINE"
|
|
114
|
+
hive_path = "#{store}\\Software\\Progress\\Authentication"
|
|
115
|
+
win32registry = Chef::Win32::Registry.new
|
|
116
|
+
unless win32registry.key_exists?(hive_path)
|
|
117
|
+
win32registry.create_key(hive_path, true)
|
|
118
|
+
end
|
|
119
|
+
values = { name: "PfxPass", type: :string, data: encrypted_pass }
|
|
120
|
+
win32registry.set_value(hive_path, values)
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
def delete_registry_hive
|
|
124
|
+
win32registry = Chef::Win32::Registry.new
|
|
125
|
+
hive_path = "HKEY_LOCAL_MACHINE\\Software\\Progress"
|
|
126
|
+
if win32registry.key_exists?(hive_path)
|
|
127
|
+
win32registry.delete_key(hive_path, true)
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
def delete_certificate(cert_name)
|
|
132
|
+
powershell_code = <<~CODE
|
|
133
|
+
Get-ChildItem -path cert:\\LocalMachine\\My -Recurse -Force | Where-Object { $_.Subject -Match "#{cert_name}" } | Remove-item
|
|
134
|
+
CODE
|
|
135
|
+
powershell_exec!(powershell_code)
|
|
136
|
+
end
|
|
137
|
+
end
|
|
21
138
|
|
|
22
139
|
describe Chef::HTTP::Authenticator do
|
|
23
140
|
let(:class_instance) { Chef::HTTP::Authenticator.new(client_name: "test") }
|
|
@@ -26,6 +143,10 @@ describe Chef::HTTP::Authenticator do
|
|
|
26
143
|
let(:headers) { {} }
|
|
27
144
|
let(:data) { "" }
|
|
28
145
|
|
|
146
|
+
before do
|
|
147
|
+
::Chef::Config[:node_name] = "foo"
|
|
148
|
+
end
|
|
149
|
+
|
|
29
150
|
context "when handle_request is called" do
|
|
30
151
|
shared_examples_for "merging the server API version into the headers" do
|
|
31
152
|
before do
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Author:: Joshua Timberman (<joshua@chef.io>)
|
|
3
|
+
#
|
|
4
|
+
# Copyright:: Copyright (c) Chef Software Inc.
|
|
5
|
+
#
|
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
# you may not use this file except in compliance with the License.
|
|
8
|
+
# You may obtain a copy of the License at
|
|
9
|
+
#
|
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
#
|
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
# See the License for the specific language governing permissions and
|
|
16
|
+
# limitations under the License.
|
|
17
|
+
|
|
18
|
+
require "spec_helper"
|
|
19
|
+
|
|
20
|
+
describe Chef::Mixin::Homebrew do
|
|
21
|
+
let(:homebrew) { Class.new { include Chef::Mixin::Homebrew }.new }
|
|
22
|
+
let(:uid) { 1001 }
|
|
23
|
+
let(:username) { "foobar" }
|
|
24
|
+
let(:alt_brew_path) { "/foo" }
|
|
25
|
+
|
|
26
|
+
describe "#find_homebrew_uid" do
|
|
27
|
+
it "returns the provided UID when an integer is given" do
|
|
28
|
+
expect(File).to receive(:exist?).exactly(0).times
|
|
29
|
+
expect(homebrew.find_homebrew_uid(uid)).to eq(uid)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it "returns the provided UID when username is given" do
|
|
33
|
+
expect(File).to receive(:exist?).exactly(0).times
|
|
34
|
+
allow(Etc).to receive(:getpwnam).with(username).and_return(OpenStruct.new(uid: uid))
|
|
35
|
+
expect(homebrew.find_homebrew_uid(username)).to eq(uid)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it "raises an error when the brew executable is not found" do
|
|
39
|
+
allow(homebrew).to receive(:homebrew_bin_path).and_raise(Chef::Exceptions::CannotDetermineHomebrewPath)
|
|
40
|
+
expect { homebrew.find_homebrew_uid }.to raise_error(Chef::Exceptions::CannotDetermineHomebrewPath)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it "returns the UID of the owner based on the brew executable" do
|
|
44
|
+
allow(homebrew).to receive(:homebrew_bin_path).and_return(alt_brew_path)
|
|
45
|
+
allow(File).to receive(:stat).with(alt_brew_path).and_return(OpenStruct.new(uid: uid))
|
|
46
|
+
allow(Etc).to receive(:getpwuid).with(uid).and_return(OpenStruct.new(name: username))
|
|
47
|
+
expect(homebrew.find_homebrew_uid).to eq(uid)
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
describe "#find_homebrew_username" do
|
|
52
|
+
it "returns the username for the provided UID" do
|
|
53
|
+
allow(homebrew).to receive(:find_homebrew_uid).and_return(uid)
|
|
54
|
+
allow(Etc).to receive(:getpwuid).with(uid).and_return(OpenStruct.new(name: username))
|
|
55
|
+
expect(homebrew.find_homebrew_username(uid)).to eq(username)
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
describe "#homebrew_bin_path" do
|
|
60
|
+
it "returns the correct path when a valid path is provided" do
|
|
61
|
+
allow(File).to receive(:exist?).with(alt_brew_path).and_return(true)
|
|
62
|
+
expect(homebrew.homebrew_bin_path(alt_brew_path)).to eq(alt_brew_path)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it "raises an error when the brew executable is not found" do
|
|
66
|
+
allow(homebrew).to receive(:which).and_return(false)
|
|
67
|
+
expect { homebrew.homebrew_bin_path }.to raise_error(Chef::Exceptions::CannotDetermineHomebrewPath)
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
shared_examples "successfully find executable" do
|
|
72
|
+
let(:default_brew_path) { "/usr/local/bin/brew" }
|
|
73
|
+
let(:default_brew_path_arm) { "/opt/homebrew/bin/brew" }
|
|
74
|
+
let(:default_brew_path_linux) { "/home/linuxbrew/.linuxbrew/bin/brew" }
|
|
75
|
+
|
|
76
|
+
context "debug statement prints owner name" do
|
|
77
|
+
|
|
78
|
+
before do
|
|
79
|
+
expect(Etc).to receive(:getpwuid).with(uid).and_return(OpenStruct.new(name: username))
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
it "returns the owner of the brew executable when it is at a default location for x86_64 machines" do
|
|
83
|
+
allow(homebrew).to receive(:homebrew_bin_path).and_return(default_brew_path)
|
|
84
|
+
allow(File).to receive(:stat).with(default_brew_path).and_return(OpenStruct.new(uid: uid))
|
|
85
|
+
expect(homebrew.find_homebrew_uid).to eq(uid)
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
it "returns the owner of the brew executable when it is at a default location for arm machines" do
|
|
89
|
+
allow(homebrew).to receive(:homebrew_bin_path).and_return(default_brew_path_arm)
|
|
90
|
+
allow(File).to receive(:stat).with(default_brew_path_arm).and_return(OpenStruct.new(uid: uid))
|
|
91
|
+
expect(homebrew.find_homebrew_uid).to eq(uid)
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
it "returns the owner of the brew executable when it is at a default location for linux machines" do
|
|
95
|
+
allow(homebrew).to receive(:homebrew_bin_path).and_return(default_brew_path_linux)
|
|
96
|
+
allow(File).to receive(:stat).with(default_brew_path_linux).and_return(OpenStruct.new(uid: uid))
|
|
97
|
+
expect(homebrew.find_homebrew_uid).to eq(uid)
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
it "returns the owner of the brew executable when it is not at a default location" do
|
|
101
|
+
allow(homebrew).to receive(:homebrew_bin_path).and_return(alt_brew_path)
|
|
102
|
+
allow(File).to receive(:stat).with(alt_brew_path).and_return(OpenStruct.new(uid: uid))
|
|
103
|
+
expect(homebrew.find_homebrew_uid).to eq(uid)
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
describe "#When the homebrew user is not provided" do
|
|
109
|
+
|
|
110
|
+
include_examples "successfully find executable"
|
|
111
|
+
|
|
112
|
+
context "the executable is owned by root" do
|
|
113
|
+
include_examples "successfully find executable" do
|
|
114
|
+
let(:uid) { 0 }
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
end
|
|
@@ -92,6 +92,11 @@ describe Chef::Mixin::OpenSSLHelper do
|
|
|
92
92
|
|
|
93
93
|
context "When the dhparam.pem file does exist, and does contain a vaild dhparam key" do
|
|
94
94
|
it "returns true" do
|
|
95
|
+
# bumped this from 256 to 1024 because OpenSSL 3.x will enforce
|
|
96
|
+
# size
|
|
97
|
+
# OpenSSL::PKey::PKeyError:
|
|
98
|
+
# EVP_PKEY_paramgen: modulus too small
|
|
99
|
+
# need to double check that the mixin itself doesn't allow smaller
|
|
95
100
|
@dhparam_file.puts(::OpenSSL::PKey::DH.new(1024).to_pem)
|
|
96
101
|
@dhparam_file.close
|
|
97
102
|
expect(instance.dhparam_pem_valid?(@dhparam_file.path)).to be_truthy
|
|
@@ -26,7 +26,7 @@ describe Chef::Mixin::PowershellExec, :windows_only do
|
|
|
26
26
|
describe "#powershell_exec" do
|
|
27
27
|
context "not specifying an interpreter" do
|
|
28
28
|
it "runs a basic command and returns a Chef::PowerShell object" do
|
|
29
|
-
expect(object.powershell_exec("$PSVersionTable")).to be_kind_of(
|
|
29
|
+
expect(object.powershell_exec("$PSVersionTable")).to be_kind_of(ChefPowerShell::PowerShell)
|
|
30
30
|
end
|
|
31
31
|
|
|
32
32
|
it "uses less than version 6" do
|
|
@@ -37,7 +37,7 @@ describe Chef::Mixin::PowershellExec, :windows_only do
|
|
|
37
37
|
|
|
38
38
|
context "using pwsh interpreter" do
|
|
39
39
|
it "runs a basic command and returns a Chef::PowerShell object" do
|
|
40
|
-
expect(object.powershell_exec("$PSVersionTable", :pwsh)).to be_kind_of(
|
|
40
|
+
expect(object.powershell_exec("$PSVersionTable", :pwsh)).to be_kind_of(ChefPowerShell::Pwsh)
|
|
41
41
|
end
|
|
42
42
|
|
|
43
43
|
it "uses greater than version 6" do
|
|
@@ -48,7 +48,7 @@ describe Chef::Mixin::PowershellExec, :windows_only do
|
|
|
48
48
|
|
|
49
49
|
context "using powershell interpreter" do
|
|
50
50
|
it "runs a basic command and returns a Chef::PowerShell object" do
|
|
51
|
-
expect(object.powershell_exec("$PSVersionTable", :powershell)).to be_kind_of(
|
|
51
|
+
expect(object.powershell_exec("$PSVersionTable", :powershell)).to be_kind_of(ChefPowerShell::PowerShell)
|
|
52
52
|
end
|
|
53
53
|
|
|
54
54
|
it "uses less than version 6" do
|
|
@@ -76,11 +76,11 @@ describe Chef::Mixin::PowershellExec, :windows_only do
|
|
|
76
76
|
|
|
77
77
|
describe "#powershell_exec!" do
|
|
78
78
|
it "runs a basic command and returns a Chef::PowerShell object" do
|
|
79
|
-
expect(object.powershell_exec!("$PSVersionTable")).to be_kind_of(
|
|
79
|
+
expect(object.powershell_exec!("$PSVersionTable")).to be_kind_of(ChefPowerShell::PowerShell)
|
|
80
80
|
end
|
|
81
81
|
|
|
82
82
|
it "raises an error if the command fails" do
|
|
83
|
-
expect { object.powershell_exec!("this-should-error") }.to raise_error(
|
|
83
|
+
expect { object.powershell_exec!("this-should-error") }.to raise_error(ChefPowerShell::PowerShellExceptions::PowerShellCommandFailed)
|
|
84
84
|
end
|
|
85
85
|
|
|
86
86
|
it "raises an error if the interpreter is invalid" do
|
|
@@ -364,20 +364,53 @@ describe Chef::Node::AttrArray do
|
|
|
364
364
|
|
|
365
365
|
context "#<<" do
|
|
366
366
|
it "converts a Hash appended with #<< to a VividMash" do
|
|
367
|
+
expect(root).to receive(:reset_cache).with(nil)
|
|
367
368
|
array << { "three" => "four" }
|
|
368
369
|
expect(array[3].class).to eql(Chef::Node::VividMash)
|
|
369
370
|
end
|
|
370
371
|
|
|
371
372
|
it "deeply converts objects appended with #<<" do
|
|
373
|
+
expect(root).to receive(:reset_cache).with(nil)
|
|
372
374
|
array << [ { "three" => [ 0, 1] } ]
|
|
373
375
|
expect(array[3].class).to eql(Chef::Node::AttrArray)
|
|
374
376
|
expect(array[3][0].class).to eql(Chef::Node::VividMash)
|
|
375
377
|
expect(array[3][0]["three"].class).to eql(Chef::Node::AttrArray)
|
|
376
378
|
end
|
|
379
|
+
|
|
380
|
+
it "does not invalidate root DeepMergeCache if VividMash top-level key" do
|
|
381
|
+
# We're checking that __path__ is used to avoid full DeepMergeCache invalidation
|
|
382
|
+
expect(root).to receive(:reset_cache).with("array")
|
|
383
|
+
expect(root).not_to receive(:reset_cache).with(nil)
|
|
384
|
+
|
|
385
|
+
attr_array = Chef::Node::AttrArray.new([ 0, 1, 2 ])
|
|
386
|
+
vivid = Chef::Node::VividMash.new(
|
|
387
|
+
{ "one" => { "two" => { "three" => "four" } }, "array" => attr_array },
|
|
388
|
+
root
|
|
389
|
+
)
|
|
390
|
+
vivid["array"] << 3
|
|
391
|
+
end
|
|
392
|
+
|
|
393
|
+
it "does not send reset_cache with nil if VividMashi nested key" do
|
|
394
|
+
# We're checking that __path__ is used to avoid full DeepMergeCache invalidation,
|
|
395
|
+
# and that it is invalidating the top-level key
|
|
396
|
+
expect(root).to receive(:reset_cache).with("array")
|
|
397
|
+
expect(root).not_to receive(:reset_cache).with(nil)
|
|
398
|
+
|
|
399
|
+
attr_array = Chef::Node::AttrArray.new([ 0, 1, 2 ])
|
|
400
|
+
vivid = Chef::Node::VividMash.new(
|
|
401
|
+
{
|
|
402
|
+
"one" => { "two" => { "three" => "four" } },
|
|
403
|
+
"array" => { "nested" => attr_array },
|
|
404
|
+
},
|
|
405
|
+
root
|
|
406
|
+
)
|
|
407
|
+
vivid["array"]["nested"] << 3
|
|
408
|
+
end
|
|
377
409
|
end
|
|
378
410
|
|
|
379
411
|
context "#[]=" do
|
|
380
412
|
it "assigning a Hash into an array converts it to VividMash" do
|
|
413
|
+
expect(root).to receive(:reset_cache).with(nil)
|
|
381
414
|
array[0] = { "zero" => "zero2" }
|
|
382
415
|
expect(array[0].class).to eql(Chef::Node::VividMash)
|
|
383
416
|
end
|
|
@@ -385,6 +418,7 @@ describe Chef::Node::AttrArray do
|
|
|
385
418
|
|
|
386
419
|
context "#push" do
|
|
387
420
|
it "pushing a Hash into an array converts it to VividMash" do
|
|
421
|
+
expect(root).to receive(:reset_cache).with(nil)
|
|
388
422
|
array.push({ "three" => "four" })
|
|
389
423
|
expect(array[3].class).to eql(Chef::Node::VividMash)
|
|
390
424
|
end
|
|
@@ -392,6 +426,7 @@ describe Chef::Node::AttrArray do
|
|
|
392
426
|
|
|
393
427
|
context "#unshift" do
|
|
394
428
|
it "unshifting a Hash into an array converts it to VividMash" do
|
|
429
|
+
expect(root).to receive(:reset_cache).with(nil)
|
|
395
430
|
array.unshift({ "zero" => "zero2" })
|
|
396
431
|
expect(array[0].class).to eql(Chef::Node::VividMash)
|
|
397
432
|
end
|
|
@@ -399,6 +434,7 @@ describe Chef::Node::AttrArray do
|
|
|
399
434
|
|
|
400
435
|
context "#insert" do
|
|
401
436
|
it "inserting a Hash into an array converts it to VividMash" do
|
|
437
|
+
expect(root).to receive(:reset_cache).with(nil)
|
|
402
438
|
array.insert(1, { "zero" => "zero2" })
|
|
403
439
|
expect(array[1].class).to eql(Chef::Node::VividMash)
|
|
404
440
|
end
|
|
@@ -406,6 +442,7 @@ describe Chef::Node::AttrArray do
|
|
|
406
442
|
|
|
407
443
|
context "#collect!" do
|
|
408
444
|
it "converts Hashes" do
|
|
445
|
+
expect(root).to receive(:reset_cache).at_least(:once).with(nil)
|
|
409
446
|
array.collect! { |x| { "zero" => "zero2" } }
|
|
410
447
|
expect(array[1].class).to eql(Chef::Node::VividMash)
|
|
411
448
|
end
|
|
@@ -413,6 +450,7 @@ describe Chef::Node::AttrArray do
|
|
|
413
450
|
|
|
414
451
|
context "#map!" do
|
|
415
452
|
it "converts Hashes" do
|
|
453
|
+
expect(root).to receive(:reset_cache).with(nil)
|
|
416
454
|
array.map! { |x| { "zero" => "zero2" } }
|
|
417
455
|
expect(array[1].class).to eql(Chef::Node::VividMash)
|
|
418
456
|
end
|
|
@@ -420,6 +458,7 @@ describe Chef::Node::AttrArray do
|
|
|
420
458
|
|
|
421
459
|
context "#compact!" do
|
|
422
460
|
it "VividMashes remain VividMashes" do
|
|
461
|
+
expect(root).to receive(:reset_cache).with(nil)
|
|
423
462
|
array = Chef::Node::AttrArray.new(
|
|
424
463
|
[ nil, { "one" => "two" }, nil ],
|
|
425
464
|
root
|
|
@@ -432,6 +471,7 @@ describe Chef::Node::AttrArray do
|
|
|
432
471
|
|
|
433
472
|
context "#fill" do
|
|
434
473
|
it "inserts VividMashes for Hashes" do
|
|
474
|
+
expect(root).to receive(:reset_cache).at_least(:once).with(nil)
|
|
435
475
|
array.fill({ "one" => "two" })
|
|
436
476
|
expect(array[0].class).to eql(Chef::Node::VividMash)
|
|
437
477
|
end
|
|
@@ -439,6 +479,7 @@ describe Chef::Node::AttrArray do
|
|
|
439
479
|
|
|
440
480
|
context "#flatten!" do
|
|
441
481
|
it "flattens sub-arrays maintaining VividMashes in them" do
|
|
482
|
+
expect(root).to receive(:reset_cache).with(nil)
|
|
442
483
|
array = Chef::Node::AttrArray.new(
|
|
443
484
|
[ [ { "one" => "two" } ], [ { "one" => "two" } ] ],
|
|
444
485
|
root
|
|
@@ -451,6 +492,7 @@ describe Chef::Node::AttrArray do
|
|
|
451
492
|
|
|
452
493
|
context "#replace" do
|
|
453
494
|
it "replaces the array converting hashes to mashes" do
|
|
495
|
+
expect(root).to receive(:reset_cache).with(nil)
|
|
454
496
|
array.replace([ { "foo" => "bar" } ])
|
|
455
497
|
expect(array[0].class).to eql(Chef::Node::VividMash)
|
|
456
498
|
end
|
data/spec/unit/node_spec.rb
CHANGED
|
@@ -303,6 +303,12 @@ describe Chef::Node do
|
|
|
303
303
|
expect(node["tags"]).to eq(%w{one two three four})
|
|
304
304
|
end
|
|
305
305
|
|
|
306
|
+
it "should let you use untag as a convince method for the tags attribute" do
|
|
307
|
+
node.normal["tags"] = %w{one two three four}
|
|
308
|
+
node.untag("three", "four")
|
|
309
|
+
expect(node["tags"]).to eq(%w{one two})
|
|
310
|
+
end
|
|
311
|
+
|
|
306
312
|
it "normal_unless sets a value even if default or override attrs are set" do
|
|
307
313
|
node.default[:decontamination] = true
|
|
308
314
|
node.override[:decontamination] = false
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
|
|
19
19
|
require "spec_helper"
|
|
20
20
|
|
|
21
|
-
describe "Chef::Platform#supports_dsc_invoke_resource?" do
|
|
21
|
+
describe "Chef::Platform#supports_dsc_invoke_resource?", :windows_only do
|
|
22
22
|
it "returns false if powershell is not present" do
|
|
23
23
|
node = Chef::Node.new
|
|
24
24
|
expect(Chef::Platform.supports_dsc_invoke_resource?(node)).to be_falsey
|
|
@@ -39,25 +39,10 @@ describe "Chef::Platform#supports_dsc_invoke_resource?" do
|
|
|
39
39
|
end
|
|
40
40
|
end
|
|
41
41
|
|
|
42
|
-
describe "Chef::Platform#dsc_refresh_mode_disabled?" do
|
|
42
|
+
describe "Chef::Platform#dsc_refresh_mode_disabled?", :windows_only do
|
|
43
43
|
let(:node) { instance_double("Chef::Node") }
|
|
44
|
-
let(:powershell) { instance_double("Chef::PowerShell") }
|
|
45
44
|
|
|
46
45
|
it "returns true when RefreshMode is Disabled" do
|
|
47
|
-
expect(Chef::PowerShell).to receive(:new)
|
|
48
|
-
.with("Get-DscLocalConfigurationManager")
|
|
49
|
-
.and_return(powershell)
|
|
50
|
-
expect(powershell).to receive(:error!)
|
|
51
|
-
expect(powershell).to receive(:result).and_return({ "RefreshMode" => "Disabled" })
|
|
52
|
-
expect(Chef::Platform.dsc_refresh_mode_disabled?(node)).to be true
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
it "returns false when RefreshMode is not Disabled" do
|
|
56
|
-
expect(Chef::PowerShell).to receive(:new)
|
|
57
|
-
.with("Get-DscLocalConfigurationManager")
|
|
58
|
-
.and_return(powershell)
|
|
59
|
-
expect(powershell).to receive(:error!)
|
|
60
|
-
expect(powershell).to receive(:result).and_return({ "RefreshMode" => "LaLaLa" })
|
|
61
46
|
expect(Chef::Platform.dsc_refresh_mode_disabled?(node)).to be false
|
|
62
47
|
end
|
|
63
48
|
end
|
|
@@ -600,6 +600,36 @@ describe "Chef::Resource.property validation" do
|
|
|
600
600
|
it "does not fail if it is not specified, on running the doit2 action" do
|
|
601
601
|
expect { resource.run_action(:doit2) }.not_to raise_error
|
|
602
602
|
end
|
|
603
|
+
|
|
604
|
+
context "when an action does not require it" do
|
|
605
|
+
before do
|
|
606
|
+
resource.action(:doit2)
|
|
607
|
+
end
|
|
608
|
+
|
|
609
|
+
it "retrieval succeeds if x is not set when resource uses the doit2 action" do
|
|
610
|
+
expect { resource.x }.not_to raise_error
|
|
611
|
+
end
|
|
612
|
+
|
|
613
|
+
it "succeeds with set to nil when resource uses the doit2 action" do
|
|
614
|
+
expect { resource.x nil }.not_to raise_error
|
|
615
|
+
end
|
|
616
|
+
end
|
|
617
|
+
|
|
618
|
+
context "when an action requires it" do
|
|
619
|
+
before do
|
|
620
|
+
# NOTE: this is already the default action, but it doesn't
|
|
621
|
+
# hurt to be clear about the situation.
|
|
622
|
+
resource.action(:doit)
|
|
623
|
+
end
|
|
624
|
+
|
|
625
|
+
it "if x is not specified, retrieval fails for the doit action" do
|
|
626
|
+
expect { resource.x }.to raise_error Chef::Exceptions::ValidationFailed
|
|
627
|
+
end
|
|
628
|
+
|
|
629
|
+
it "value nil is not valid for the doit action (required means 'not nil')" do
|
|
630
|
+
expect { resource.x nil }.to raise_error Chef::Exceptions::ValidationFailed
|
|
631
|
+
end
|
|
632
|
+
end
|
|
603
633
|
end
|
|
604
634
|
|
|
605
635
|
with_property ":x, String, required: true" do
|
|
@@ -82,6 +82,15 @@ C5986B4F1257FFA86632CBA746181433FBB75451
|
|
|
82
82
|
843938DF228D22F7B3742BC0D94AA3F0EFE21092}
|
|
83
83
|
end
|
|
84
84
|
|
|
85
|
+
let(:apt_public_keys) do
|
|
86
|
+
%w{
|
|
87
|
+
pub:-:1024:17:40976EAF437D05B5:2004-09-12
|
|
88
|
+
pub:-:1024:17:46181433FBB75451:2004-12-30
|
|
89
|
+
pub:-:4096:1:3B4FE6ACC0B21F32:2012-05-11
|
|
90
|
+
pub:-:4096:1:D94AA3F0EFE21092:2012-05-11
|
|
91
|
+
}
|
|
92
|
+
end
|
|
93
|
+
|
|
85
94
|
it "responds to load_current_resource" do
|
|
86
95
|
expect(provider).to respond_to(:load_current_resource)
|
|
87
96
|
end
|
|
@@ -113,6 +122,18 @@ C5986B4F1257FFA86632CBA746181433FBB75451
|
|
|
113
122
|
end
|
|
114
123
|
end
|
|
115
124
|
|
|
125
|
+
describe "#extract_public_keys_from_cmd" do
|
|
126
|
+
it "runs the desired command" do
|
|
127
|
+
expect(provider).to receive(:shell_out).and_return(apt_key_finger)
|
|
128
|
+
provider.extract_public_keys_from_cmd(*apt_key_finger_cmd)
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
it "returns a list of key fingerprints" do
|
|
132
|
+
expect(provider).to receive(:shell_out).and_return(apt_key_finger)
|
|
133
|
+
expect(provider.extract_public_keys_from_cmd(*apt_key_finger_cmd)).to eql(apt_public_keys)
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
|
|
116
137
|
describe "#cookbook_name" do
|
|
117
138
|
it "returns 'test' when the cookbook property is set" do
|
|
118
139
|
new_resource.cookbook("test")
|
|
@@ -122,22 +143,22 @@ C5986B4F1257FFA86632CBA746181433FBB75451
|
|
|
122
143
|
|
|
123
144
|
describe "#no_new_keys?" do
|
|
124
145
|
before do
|
|
125
|
-
allow(provider).to receive(:
|
|
146
|
+
allow(provider).to receive(:extract_public_keys_from_cmd).with(*apt_key_finger_cmd).and_return(apt_public_keys)
|
|
126
147
|
end
|
|
127
148
|
|
|
128
149
|
let(:file) { "/tmp/remote-gpg-keyfile" }
|
|
129
150
|
|
|
130
151
|
it "matches a set of keys" do
|
|
131
|
-
allow(provider).to receive(:
|
|
152
|
+
allow(provider).to receive(:extract_public_keys_from_cmd)
|
|
132
153
|
.with("gpg", "--with-fingerprint", "--with-colons", file)
|
|
133
|
-
.and_return(
|
|
154
|
+
.and_return([apt_public_keys.first])
|
|
134
155
|
expect(provider.no_new_keys?(file)).to be_truthy
|
|
135
156
|
end
|
|
136
157
|
|
|
137
158
|
it "notices missing keys" do
|
|
138
|
-
allow(provider).to receive(:
|
|
159
|
+
allow(provider).to receive(:extract_public_keys_from_cmd)
|
|
139
160
|
.with("gpg", "--with-fingerprint", "--with-colons", file)
|
|
140
|
-
.and_return(%w{
|
|
161
|
+
.and_return(%w{pub:-:4096:1:871920D1991BC93C:1537196506})
|
|
141
162
|
expect(provider.no_new_keys?(file)).to be_falsey
|
|
142
163
|
end
|
|
143
164
|
end
|
|
@@ -225,33 +246,48 @@ C5986B4F1257FFA86632CBA746181433FBB75451
|
|
|
225
246
|
describe "#build_repo" do
|
|
226
247
|
it "creates a repository string" do
|
|
227
248
|
target = "deb http://test/uri unstable main\n"
|
|
228
|
-
expect(provider.build_repo("http://test/uri", "unstable", "main", false, nil)).to eql(target)
|
|
249
|
+
expect(provider.build_repo("http://test/uri", "unstable", "main", false, nil, nil, [])).to eql(target)
|
|
229
250
|
end
|
|
230
251
|
|
|
231
252
|
it "creates a repository string with spaces" do
|
|
232
253
|
target = "deb http://test/uri%20with%20spaces unstable main\n"
|
|
233
|
-
expect(provider.build_repo("http://test/uri with spaces", "unstable", "main", false, nil)).to eql(target)
|
|
254
|
+
expect(provider.build_repo("http://test/uri with spaces", "unstable", "main", false, nil, nil, [])).to eql(target)
|
|
234
255
|
end
|
|
235
256
|
|
|
236
257
|
it "creates a repository string with no distribution" do
|
|
237
258
|
target = "deb http://test/uri main\n"
|
|
238
|
-
expect(provider.build_repo("http://test/uri", nil, "main", false, nil)).to eql(target)
|
|
259
|
+
expect(provider.build_repo("http://test/uri", nil, "main", false, nil, nil, [])).to eql(target)
|
|
239
260
|
end
|
|
240
261
|
|
|
241
262
|
it "creates a repository string with source" do
|
|
242
263
|
target = "deb http://test/uri unstable main\ndeb-src http://test/uri unstable main\n"
|
|
243
|
-
expect(provider.build_repo("http://test/uri", "unstable", "main", false, nil, true)).to eql(target)
|
|
264
|
+
expect(provider.build_repo("http://test/uri", "unstable", "main", false, nil, nil, [], true)).to eql(target)
|
|
244
265
|
end
|
|
245
266
|
|
|
246
|
-
it "creates a repository string with
|
|
267
|
+
it "creates a repository string with trusted" do
|
|
247
268
|
target = "deb [trusted=yes] http://test/uri unstable main\n"
|
|
248
|
-
expect(provider.build_repo("http://test/uri", "unstable", "main", true, nil)).to eql(target)
|
|
269
|
+
expect(provider.build_repo("http://test/uri", "unstable", "main", true, nil, nil, [])).to eql(target)
|
|
270
|
+
end
|
|
271
|
+
|
|
272
|
+
it "creates a repository string with signed-by" do
|
|
273
|
+
target = "deb [signed-by=/etc/apt/keyrings/test.gpg] http://test/uri unstable main\n"
|
|
274
|
+
expect(provider.build_repo("http://test/uri", "unstable", "main", false, nil, "/etc/apt/keyrings/test.gpg", [])).to eql(target)
|
|
275
|
+
end
|
|
276
|
+
|
|
277
|
+
it "creates a repository string with custom options" do
|
|
278
|
+
target = "deb [by-hash=no] http://test/uri unstable main\n"
|
|
279
|
+
expect(provider.build_repo("http://test/uri", "unstable", "main", false, nil, nil, ["by-hash=no"])).to eql(target)
|
|
280
|
+
end
|
|
281
|
+
|
|
282
|
+
it "creates a repository string with trusted, arch, and custom options" do
|
|
283
|
+
target = "deb [arch=amd64 trusted=yes by-hash=no] http://test/uri unstable main\n"
|
|
284
|
+
expect(provider.build_repo("http://test/uri", "unstable", "main", true, "amd64", nil, ["by-hash=no"])).to eql(target)
|
|
249
285
|
end
|
|
250
286
|
|
|
251
287
|
it "handles a ppa repo" do
|
|
252
288
|
target = "deb http://ppa.launchpad.net/chef/main/ubuntu unstable main\n"
|
|
253
289
|
expect(provider).to receive(:make_ppa_url).with("ppa:chef/main").and_return("http://ppa.launchpad.net/chef/main/ubuntu")
|
|
254
|
-
expect(provider.build_repo("ppa:chef/main", "unstable", "main", false, nil)).to eql(target)
|
|
290
|
+
expect(provider.build_repo("ppa:chef/main", "unstable", "main", false, nil, nil, [])).to eql(target)
|
|
255
291
|
end
|
|
256
292
|
end
|
|
257
293
|
end
|
|
@@ -779,6 +779,7 @@ describe Chef::Provider::Cron do
|
|
|
779
779
|
allow(@provider).to receive(:read_crontab).and_return(<<~CRONTAB)
|
|
780
780
|
# Chef Name: cronhole some stuff
|
|
781
781
|
1 1 1 1 1 /bin/true
|
|
782
|
+
|
|
782
783
|
CRONTAB
|
|
783
784
|
|
|
784
785
|
@provider.run_action(:create)
|
|
@@ -796,6 +797,7 @@ describe Chef::Provider::Cron do
|
|
|
796
797
|
allow(@provider).to receive(:read_crontab).and_return(<<~CRONTAB)
|
|
797
798
|
# Chef Name: cronhole some stuff
|
|
798
799
|
1 1 1 1 1 /bin/true
|
|
800
|
+
|
|
799
801
|
CRONTAB
|
|
800
802
|
|
|
801
803
|
@provider.run_action(:create)
|