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
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
#
|
|
2
|
-
# Author::
|
|
3
|
-
#
|
|
4
|
-
# Copyright:: Copyright (c) Chef Software Inc.
|
|
2
|
+
# Author:: Thomas Powell (<powell@progress.com>)
|
|
3
|
+
# Copyright:: Copyright (c) 2025 Progress Chef Software Inc.
|
|
5
4
|
# License:: Apache License, Version 2.0
|
|
6
5
|
#
|
|
7
6
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
@@ -17,53 +16,67 @@
|
|
|
17
16
|
# limitations under the License.
|
|
18
17
|
#
|
|
19
18
|
|
|
20
|
-
require "chef/win32/registry"
|
|
21
|
-
require "chef/resource_reporter"
|
|
22
19
|
require "spec_helper"
|
|
23
20
|
|
|
24
|
-
describe Chef::Resource::RegistryKey
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
ohai.all_plugins
|
|
30
|
-
node.consume_external_attrs(ohai.data, {})
|
|
31
|
-
run_context = Chef::RunContext.new(node, {}, events)
|
|
32
|
-
@resource = Chef::Resource::RegistryKey.new("HKCU\\Software", run_context)
|
|
33
|
-
end
|
|
34
|
-
context "when load_current_resource is run on a non-windows node" do
|
|
35
|
-
it "throws an exception because you don't have a windows registry (derp)" do
|
|
36
|
-
@resource.key("HKCU\\Software\\Opscode")
|
|
37
|
-
@resource.values([{ name: "Color", type: :string, data: "Orange" }])
|
|
38
|
-
expect { @resource.run_action(:create) }.to raise_error(Chef::Exceptions::Win32NotWindows)
|
|
21
|
+
describe Chef::Resource::RegistryKey do
|
|
22
|
+
around(:example) do |example|
|
|
23
|
+
original_method = described_class.instance_method(:scrub_values)
|
|
24
|
+
described_class.define_method(:scrub_values) do |values|
|
|
25
|
+
values
|
|
39
26
|
end
|
|
27
|
+
example.run
|
|
28
|
+
described_class.define_method(original_method.name, original_method)
|
|
40
29
|
end
|
|
41
|
-
end
|
|
42
30
|
|
|
43
|
-
|
|
31
|
+
let(:events) { Chef::EventDispatch::Dispatcher.new }
|
|
32
|
+
let(:node) { Chef::Node.new }
|
|
33
|
+
let(:ohai) { Ohai::System.new }
|
|
34
|
+
let(:run_context) { Chef::RunContext.new(node, {}, events) }
|
|
35
|
+
let(:new_resource) { Chef::Resource::RegistryKey.new(resource_name, run_context) }
|
|
44
36
|
|
|
45
|
-
# parent and key must be single keys, not paths
|
|
46
37
|
let(:parent) { "Opscode" }
|
|
47
38
|
let(:child) { "Whatever" }
|
|
48
|
-
let(:key_parent) { "
|
|
49
|
-
let(:key_child) { "
|
|
50
|
-
|
|
51
|
-
let(:
|
|
52
|
-
let(:reg_child) { "HKLM\\" + key_child }
|
|
39
|
+
let(:key_parent) { "Software\\#{parent}" }
|
|
40
|
+
let(:key_child) { "#{key_parent}\\#{child}" }
|
|
41
|
+
let(:reg_parent) { "HKLM\\#{key_parent}" }
|
|
42
|
+
let(:reg_child) { "HKLM\\#{key_child}" }
|
|
53
43
|
let(:hive_class) { ::Win32::Registry::HKEY_LOCAL_MACHINE }
|
|
54
44
|
let(:resource_name) { "This is the name of my Resource" }
|
|
55
45
|
|
|
46
|
+
let(:events) { Chef::EventDispatch::Dispatcher.new }
|
|
47
|
+
let(:run_context) { Chef::RunContext.new(node, {}, events) }
|
|
48
|
+
let(:registry) { Chef::Win32::Registry.new(run_context) }
|
|
49
|
+
|
|
50
|
+
let(:node_name) { "windowsbox" }
|
|
51
|
+
let(:run_id) { SecureRandom.uuid }
|
|
52
|
+
let(:events) { Chef::EventDispatch::Dispatcher.new }
|
|
53
|
+
let(:run_status) { Chef::RunStatus.new(node, events) }
|
|
54
|
+
let(:action_collection) { Chef::ActionCollection.new(events) }
|
|
55
|
+
|
|
56
|
+
let(:rest_client) do
|
|
57
|
+
rest_client = double("Chef::ServerAPI")
|
|
58
|
+
|
|
59
|
+
# allow().to receive(:message).with(::any arguments::) syntax seems to be broken here
|
|
60
|
+
allow(rest_client).to receive(:post).and_return("uri" => "https://example.com/reports/nodes/#{node_name}/runs/#{run_id}")
|
|
61
|
+
allow(rest_client).to receive(:create_url).and_return("reports/nodes/#{node_name}/run/#{run_id}")
|
|
62
|
+
allow(rest_client).to receive(:raw_http_request).and_return({ "result" => "ok" })
|
|
63
|
+
|
|
64
|
+
rest_client
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
let(:resource_reporter) { Chef::ResourceReporter.new(rest_client) }
|
|
68
|
+
|
|
56
69
|
def clean_registry
|
|
57
70
|
if windows64?
|
|
58
71
|
# clean 64-bit space on WOW64
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
72
|
+
registry.architecture = :x86_64
|
|
73
|
+
registry.delete_key(reg_parent, true)
|
|
74
|
+
registry.architecture = :machine
|
|
62
75
|
end
|
|
63
76
|
# clean 32-bit space on WOW64
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
77
|
+
registry.architecture = :i386
|
|
78
|
+
registry.delete_key(reg_parent, true)
|
|
79
|
+
registry.architecture = :machine
|
|
67
80
|
end
|
|
68
81
|
|
|
69
82
|
def reset_registry
|
|
@@ -72,604 +85,215 @@ describe Chef::Resource::RegistryKey, :windows_only, broken: true do
|
|
|
72
85
|
hive_class.create(key_parent, Win32::Registry::KEY_WRITE | 0x0200)
|
|
73
86
|
end
|
|
74
87
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
[
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
reg["AKA", Win32::Registry::REG_SZ] = "OC"
|
|
83
|
-
end
|
|
84
|
-
hive_class.create(key_parent + "\\ReportKey", Win32::Registry::KEY_WRITE | flag)
|
|
85
|
-
hive_class.open(key_parent + "\\ReportKey", Win32::Registry::KEY_ALL_ACCESS | flag) do |reg|
|
|
86
|
-
reg["ReportVal4", Win32::Registry::REG_SZ] = "report4"
|
|
87
|
-
reg["ReportVal5", Win32::Registry::REG_SZ] = "report5"
|
|
88
|
-
end
|
|
89
|
-
hive_class.create(key_parent + "\\OpscodeWhyRun", Win32::Registry::KEY_WRITE | flag)
|
|
90
|
-
hive_class.open(key_parent + "\\OpscodeWhyRun", Win32::Registry::KEY_ALL_ACCESS | flag) do |reg|
|
|
91
|
-
reg["BriskWalk", Win32::Registry::REG_SZ] = "is good for health"
|
|
92
|
-
end
|
|
93
|
-
end
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
before(:all) do
|
|
97
|
-
@events = Chef::EventDispatch::Dispatcher.new
|
|
98
|
-
@node = Chef::Node.new
|
|
99
|
-
ohai = Ohai::System.new
|
|
100
|
-
ohai.all_plugins
|
|
101
|
-
@node.consume_external_attrs(ohai.data, {})
|
|
102
|
-
@run_context = Chef::RunContext.new(@node, {}, @events)
|
|
103
|
-
|
|
104
|
-
@new_resource = Chef::Resource::RegistryKey.new(resource_name, @run_context)
|
|
105
|
-
@registry = Chef::Win32::Registry.new(@run_context)
|
|
106
|
-
|
|
107
|
-
reset_registry
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
# Reporting setup
|
|
111
|
-
before do
|
|
112
|
-
@node.name("windowsbox")
|
|
113
|
-
|
|
114
|
-
@rest_client = double("Chef::ServerAPI (mock)")
|
|
115
|
-
allow(@rest_client).to receive(:create_url).and_return("reports/nodes/windowsbox/runs/#{@run_id}")
|
|
116
|
-
allow(@rest_client).to receive(:raw_http_request).and_return({ "result" => "ok" })
|
|
117
|
-
allow(@rest_client).to receive(:post_rest).and_return({ "uri" => "https://example.com/reports/nodes/windowsbox/runs/#{@run_id}" })
|
|
118
|
-
|
|
119
|
-
@resource_reporter = Chef::ResourceReporter.new(@rest_client)
|
|
120
|
-
@events.register(@resource_reporter)
|
|
121
|
-
@run_status = Chef::RunStatus.new(@node, @events)
|
|
122
|
-
@resource_reporter.run_started(@run_status)
|
|
123
|
-
@run_id = @resource_reporter.run_id
|
|
124
|
-
|
|
125
|
-
@new_resource.cookbook_name = "monkey"
|
|
126
|
-
@cookbook_version = double("Cookbook::Version", version: "1.2.3")
|
|
127
|
-
@new_resource.cookbook_version(@cookbook_version)
|
|
128
|
-
end
|
|
129
|
-
|
|
130
|
-
after(:all) do
|
|
131
|
-
clean_registry
|
|
132
|
-
end
|
|
133
|
-
|
|
134
|
-
context "when action is create" do
|
|
135
|
-
before(:all) do
|
|
136
|
-
reset_registry
|
|
137
|
-
end
|
|
138
|
-
it "creates registry key, value if the key is missing" do
|
|
139
|
-
@new_resource.key(reg_child)
|
|
140
|
-
@new_resource.values([{ name: "Color", type: :string, data: "Orange" }])
|
|
141
|
-
@new_resource.run_action(:create)
|
|
142
|
-
|
|
143
|
-
expect(@registry.key_exists?(reg_child)).to eq(true)
|
|
144
|
-
expect(@registry.data_exists?(reg_child, { name: "Color", type: :string, data: "Orange" })).to eq(true)
|
|
88
|
+
context "when running on non-Windows", :unix_only do
|
|
89
|
+
let(:registry_key) { "HKCU\\Software\\Opscode" }
|
|
90
|
+
let(:registry_key_values) { [{ name: "Color", type: :string, data: "Orange" }] }
|
|
91
|
+
subject do
|
|
92
|
+
new_resource.key(registry_key)
|
|
93
|
+
new_resource.values(registry_key_values)
|
|
94
|
+
new_resource.run_action(:create)
|
|
145
95
|
end
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
@new_resource.key(reg_child)
|
|
149
|
-
@new_resource.values([{ name: "Color", type: :string, data: "Orange" }])
|
|
150
|
-
@new_resource.run_action(:create)
|
|
151
|
-
|
|
152
|
-
expect(@registry.key_exists?(reg_child)).to eq(true)
|
|
153
|
-
expect(@registry.data_exists?(reg_child, { name: "Color", type: :string, data: "Orange" })).to eq(true)
|
|
154
|
-
end
|
|
155
|
-
|
|
156
|
-
it "does not create the key if it already exists with same value and type but datatype of data differs" do
|
|
157
|
-
@new_resource.key(reg_child)
|
|
158
|
-
@new_resource.values([{ name: "number", type: :dword, data: "12345" }])
|
|
159
|
-
@new_resource.run_action(:create)
|
|
160
|
-
|
|
161
|
-
expect(@new_resource).not_to be_updated_by_last_action
|
|
162
|
-
expect(@registry.key_exists?(reg_child)).to eq(true)
|
|
163
|
-
expect(@registry.data_exists?(reg_child, { name: "number", type: :dword, data: 12344 })).to eq(true)
|
|
164
|
-
end
|
|
165
|
-
|
|
166
|
-
it "creates a value if it does not exist" do
|
|
167
|
-
@new_resource.key(reg_child)
|
|
168
|
-
@new_resource.values([{ name: "Mango", type: :string, data: "Yellow" }])
|
|
169
|
-
@new_resource.run_action(:create)
|
|
170
|
-
|
|
171
|
-
expect(@registry.data_exists?(reg_child, { name: "Mango", type: :string, data: "Yellow" })).to eq(true)
|
|
172
|
-
end
|
|
173
|
-
|
|
174
|
-
it "modifies the data if the key and value exist and type matches" do
|
|
175
|
-
@new_resource.key(reg_child)
|
|
176
|
-
@new_resource.values([{ name: "Color", type: :string, data: "Not just Orange - OpscodeOrange!" }])
|
|
177
|
-
@new_resource.run_action(:create)
|
|
178
|
-
|
|
179
|
-
expect(@registry.data_exists?(reg_child, { name: "Color", type: :string, data: "Not just Orange - OpscodeOrange!" })).to eq(true)
|
|
180
|
-
end
|
|
181
|
-
|
|
182
|
-
it "modifys the type if the key and value exist and the type does not match" do
|
|
183
|
-
@new_resource.key(reg_child)
|
|
184
|
-
@new_resource.values([{ name: "Color", type: :multi_string, data: ["Not just Orange - OpscodeOrange!"] }])
|
|
185
|
-
@new_resource.run_action(:create)
|
|
186
|
-
|
|
187
|
-
expect(@registry.data_exists?(reg_child, { name: "Color", type: :multi_string, data: ["Not just Orange - OpscodeOrange!"] })).to eq(true)
|
|
188
|
-
end
|
|
189
|
-
|
|
190
|
-
it "creates subkey if parent exists" do
|
|
191
|
-
@new_resource.key(reg_child + "\\OpscodeTest")
|
|
192
|
-
@new_resource.values([{ name: "Chef", type: :multi_string, data: %w{OpscodeOrange Rules} }])
|
|
193
|
-
@new_resource.recursive(false)
|
|
194
|
-
@new_resource.run_action(:create)
|
|
195
|
-
|
|
196
|
-
expect(@registry.key_exists?(reg_child + "\\OpscodeTest")).to eq(true)
|
|
197
|
-
expect(@registry.value_exists?(reg_child + "\\OpscodeTest", { name: "Chef", type: :multi_string, data: %w{OpscodeOrange Rules} })).to eq(true)
|
|
198
|
-
end
|
|
199
|
-
|
|
200
|
-
it "raises an error if action create and parent does not exist and recursive is set to false" do
|
|
201
|
-
@new_resource.key(reg_child + '\Missing1\Missing2')
|
|
202
|
-
@new_resource.values([{ name: "OC", type: :string, data: "MissingData" }])
|
|
203
|
-
@new_resource.recursive(false)
|
|
204
|
-
expect { @new_resource.run_action(:create) }.to raise_error(Chef::Exceptions::Win32RegNoRecursive)
|
|
205
|
-
end
|
|
206
|
-
|
|
207
|
-
it "raises an error if action create and type key missing in values hash" do
|
|
208
|
-
@new_resource.key(reg_child)
|
|
209
|
-
@new_resource.values([{ name: "OC", data: "my_data" }])
|
|
210
|
-
expect { @new_resource.run_action(:create) }.to raise_error(Chef::Exceptions::RegKeyValuesTypeMissing)
|
|
211
|
-
end
|
|
212
|
-
|
|
213
|
-
it "raises an error if action create and data key missing in values hash" do
|
|
214
|
-
@new_resource.key(reg_child)
|
|
215
|
-
@new_resource.values([{ name: "OC", type: :string }])
|
|
216
|
-
expect { @new_resource.run_action(:create) }.to raise_error(Chef::Exceptions::RegKeyValuesDataMissing)
|
|
217
|
-
end
|
|
218
|
-
|
|
219
|
-
it "raises an error if action create and only name key present in values hash" do
|
|
220
|
-
@new_resource.key(reg_child)
|
|
221
|
-
@new_resource.values([{ name: "OC" }])
|
|
222
|
-
expect { @new_resource.run_action(:create) }.to raise_error(Chef::Exceptions::RegKeyValuesTypeMissing)
|
|
223
|
-
end
|
|
224
|
-
|
|
225
|
-
it "does not raise an error if action create and all keys are present in values hash" do
|
|
226
|
-
@new_resource.key(reg_child)
|
|
227
|
-
@new_resource.values([{ name: "OC", type: :string, data: "my_data" }])
|
|
228
|
-
expect { @new_resource.run_action(:create) }.to_not raise_error
|
|
229
|
-
end
|
|
230
|
-
|
|
231
|
-
it "creates missing keys if action create and parent does not exist and recursive is set to true" do
|
|
232
|
-
@new_resource.key(reg_child + '\Missing1\Missing2')
|
|
233
|
-
@new_resource.values([{ name: "OC", type: :string, data: "MissingData" }])
|
|
234
|
-
@new_resource.recursive(true)
|
|
235
|
-
@new_resource.run_action(:create)
|
|
236
|
-
|
|
237
|
-
expect(@registry.key_exists?(reg_child + '\Missing1\Missing2')).to eq(true)
|
|
238
|
-
expect(@registry.value_exists?(reg_child + '\Missing1\Missing2', { name: "OC", type: :string, data: "MissingData" })).to eq(true)
|
|
239
|
-
end
|
|
240
|
-
|
|
241
|
-
it "creates key with multiple value as specified" do
|
|
242
|
-
@new_resource.key(reg_child)
|
|
243
|
-
@new_resource.values([{ name: "one", type: :string, data: "1" }, { name: "two", type: :string, data: "2" }, { name: "three", type: :string, data: "3" }])
|
|
244
|
-
@new_resource.recursive(true)
|
|
245
|
-
@new_resource.run_action(:create)
|
|
246
|
-
|
|
247
|
-
@new_resource.each_value do |value|
|
|
248
|
-
expect(@registry.value_exists?(reg_child, value)).to eq(true)
|
|
249
|
-
end
|
|
250
|
-
end
|
|
251
|
-
|
|
252
|
-
context "when running on 64-bit server", :windows64_only do
|
|
253
|
-
before(:all) do
|
|
254
|
-
reset_registry
|
|
255
|
-
end
|
|
256
|
-
after(:all) do
|
|
257
|
-
@new_resource.architecture(:machine)
|
|
258
|
-
@registry.architecture = :machine
|
|
259
|
-
end
|
|
260
|
-
it "creates a key in a 32-bit registry that is not viewable in 64-bit" do
|
|
261
|
-
@new_resource.key(reg_child + "\\Atraxi" )
|
|
262
|
-
@new_resource.values([{ name: "OC", type: :string, data: "Data" }])
|
|
263
|
-
@new_resource.recursive(true)
|
|
264
|
-
@new_resource.architecture(:i386)
|
|
265
|
-
@new_resource.run_action(:create)
|
|
266
|
-
@registry.architecture = :i386
|
|
267
|
-
expect(@registry.data_exists?(reg_child + "\\Atraxi", { name: "OC", type: :string, data: "Data" })).to eq(true)
|
|
268
|
-
@registry.architecture = :x86_64
|
|
269
|
-
expect(@registry.key_exists?(reg_child + "\\Atraxi")).to eq(false)
|
|
270
|
-
end
|
|
271
|
-
end
|
|
272
|
-
|
|
273
|
-
it "prepares the reporting data for action :create" do
|
|
274
|
-
@new_resource.key(reg_child + "\\Ood")
|
|
275
|
-
@new_resource.values([{ name: "ReportingVal1", type: :string, data: "report1" }, { name: "ReportingVal2", type: :string, data: "report2" }])
|
|
276
|
-
@new_resource.recursive(true)
|
|
277
|
-
@new_resource.run_action(:create)
|
|
278
|
-
@report = @resource_reporter.prepare_run_data
|
|
279
|
-
|
|
280
|
-
expect(@report["action"]).to eq("end")
|
|
281
|
-
expect(@report["resources"][0]["type"]).to eq("registry_key")
|
|
282
|
-
expect(@report["resources"][0]["name"]).to eq(resource_name)
|
|
283
|
-
expect(@report["resources"][0]["id"]).to eq(reg_child + "\\Ood")
|
|
284
|
-
expect(@report["resources"][0]["after"][:values]).to eq([{ name: "ReportingVal1", type: :string, data: "report1" },
|
|
285
|
-
{ name: "ReportingVal2", type: :string, data: "report2" }])
|
|
286
|
-
expect(@report["resources"][0]["before"][:values]).to eq([])
|
|
287
|
-
expect(@report["resources"][0]["result"]).to eq("create")
|
|
288
|
-
expect(@report["status"]).to eq("success")
|
|
289
|
-
expect(@report["total_res_count"]).to eq("1")
|
|
290
|
-
end
|
|
291
|
-
|
|
292
|
-
context "while running in whyrun mode" do
|
|
293
|
-
before(:each) do
|
|
294
|
-
Chef::Config[:why_run] = true
|
|
295
|
-
end
|
|
296
|
-
|
|
297
|
-
it "does not raise an exception if the keys do not exist but recursive is set to false" do
|
|
298
|
-
@new_resource.key(reg_child + "\\Slitheen\\Raxicoricofallapatorius")
|
|
299
|
-
@new_resource.values([{ name: "BriskWalk", type: :string, data: "is good for health" }])
|
|
300
|
-
@new_resource.recursive(false)
|
|
301
|
-
@new_resource.run_action(:create) # should not raise_error
|
|
302
|
-
expect(@registry.key_exists?(reg_child + "\\Slitheen")).to eq(false)
|
|
303
|
-
expect(@registry.key_exists?(reg_child + "\\Slitheen\\Raxicoricofallapatorius")).to eq(false)
|
|
304
|
-
end
|
|
305
|
-
|
|
306
|
-
it "does not create key if the action is create" do
|
|
307
|
-
@new_resource.key(reg_child + "\\Slitheen")
|
|
308
|
-
@new_resource.values([{ name: "BriskWalk", type: :string, data: "is good for health" }])
|
|
309
|
-
@new_resource.recursive(false)
|
|
310
|
-
@new_resource.run_action(:create)
|
|
311
|
-
expect(@registry.key_exists?(reg_child + "\\Slitheen")).to eq(false)
|
|
312
|
-
end
|
|
313
|
-
|
|
314
|
-
it "does not raise an exception if the action create and type key missing in values hash" do
|
|
315
|
-
@new_resource.key(reg_child + "\\Slitheen")
|
|
316
|
-
@new_resource.values([{ name: "BriskWalk", data: "my_data" }])
|
|
317
|
-
@new_resource.run_action(:create) # should not raise_error
|
|
318
|
-
expect(@registry.key_exists?(reg_child + "\\Slitheen")).to eq(false)
|
|
319
|
-
end
|
|
320
|
-
|
|
321
|
-
it "does not raise an exception if the action create and data key missing in values hash" do
|
|
322
|
-
@new_resource.key(reg_child + "\\Slitheen")
|
|
323
|
-
@new_resource.values([{ name: "BriskWalk", type: :string }])
|
|
324
|
-
@new_resource.run_action(:create) # should not raise_error
|
|
325
|
-
expect(@registry.key_exists?(reg_child + "\\Slitheen")).to eq(false)
|
|
326
|
-
end
|
|
327
|
-
|
|
328
|
-
it "does not raise an exception if the action create and only name key present in values hash" do
|
|
329
|
-
@new_resource.key(reg_child + "\\Slitheen")
|
|
330
|
-
@new_resource.values([{ name: "BriskWalk" }])
|
|
331
|
-
@new_resource.run_action(:create) # should not raise_error
|
|
332
|
-
expect(@registry.key_exists?(reg_child + "\\Slitheen")).to eq(false)
|
|
333
|
-
end
|
|
334
|
-
|
|
335
|
-
it "does not raise an exception if the action create and all keys are present in values hash" do
|
|
336
|
-
@new_resource.key(reg_child + "\\Slitheen")
|
|
337
|
-
@new_resource.values([{ name: "BriskWalk", type: :string, data: "my_data" }])
|
|
338
|
-
@new_resource.run_action(:create) # should not raise_error
|
|
339
|
-
expect(@registry.key_exists?(reg_child + "\\Slitheen")).to eq(false)
|
|
340
|
-
end
|
|
96
|
+
it "raise an exception because we don't have a windows registry on non-Windows" do
|
|
97
|
+
expect { subject }.to raise_error(Chef::Exceptions::Win32NotWindows)
|
|
341
98
|
end
|
|
342
99
|
end
|
|
343
100
|
|
|
344
|
-
context "when
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
it "does not create the key if it already exists with same value, type and data" do
|
|
360
|
-
@new_resource.key(reg_child)
|
|
361
|
-
@new_resource.values([{ name: "Color", type: :string, data: "Orange" }])
|
|
362
|
-
@new_resource.run_action(:create_if_missing)
|
|
363
|
-
|
|
364
|
-
expect(@registry.key_exists?(reg_child)).to eq(true)
|
|
365
|
-
expect(@registry.data_exists?(reg_child, { name: "Color", type: :string, data: "Orange" })).to eq(true)
|
|
366
|
-
end
|
|
367
|
-
|
|
368
|
-
it "creates a value if it does not exist" do
|
|
369
|
-
@new_resource.key(reg_child)
|
|
370
|
-
@new_resource.values([{ name: "Mango", type: :string, data: "Yellow" }])
|
|
371
|
-
@new_resource.run_action(:create_if_missing)
|
|
372
|
-
|
|
373
|
-
expect(@registry.data_exists?(reg_child, { name: "Mango", type: :string, data: "Yellow" })).to eq(true)
|
|
374
|
-
end
|
|
375
|
-
|
|
376
|
-
it "creates subkey if parent exists" do
|
|
377
|
-
@new_resource.key(reg_child + "\\Pyrovile")
|
|
378
|
-
@new_resource.values([{ name: "Chef", type: :multi_string, data: %w{OpscodeOrange Rules} }])
|
|
379
|
-
@new_resource.recursive(false)
|
|
380
|
-
@new_resource.run_action(:create_if_missing)
|
|
381
|
-
|
|
382
|
-
expect(@registry.key_exists?(reg_child + "\\Pyrovile")).to eq(true)
|
|
383
|
-
expect(@registry.value_exists?(reg_child + "\\Pyrovile", { name: "Chef", type: :multi_string, data: %w{OpscodeOrange Rules} })).to eq(true)
|
|
384
|
-
end
|
|
385
|
-
|
|
386
|
-
it "raises an error if action create and parent does not exist and recursive is set to false" do
|
|
387
|
-
@new_resource.key(reg_child + "\\Sontaran\\Sontar")
|
|
388
|
-
@new_resource.values([{ name: "OC", type: :string, data: "MissingData" }])
|
|
389
|
-
@new_resource.recursive(false)
|
|
390
|
-
expect { @new_resource.run_action(:create_if_missing) }.to raise_error(Chef::Exceptions::Win32RegNoRecursive)
|
|
391
|
-
end
|
|
392
|
-
|
|
393
|
-
it "raises an error if action create_if_missing and type key missing in values hash" do
|
|
394
|
-
@new_resource.key(reg_child)
|
|
395
|
-
@new_resource.values([{ name: "OC", data: "my_data" }])
|
|
396
|
-
expect { @new_resource.run_action(:create_if_missing) }.to raise_error(Chef::Exceptions::RegKeyValuesTypeMissing)
|
|
397
|
-
end
|
|
101
|
+
context "when running on Windows", :windows_only do
|
|
102
|
+
# this is moderately brittle, but it seems to be the order of operations
|
|
103
|
+
# necessary to get a report out of the resource reporter
|
|
104
|
+
before do
|
|
105
|
+
events
|
|
106
|
+
node
|
|
107
|
+
node.name(node_name)
|
|
108
|
+
ohai
|
|
109
|
+
ohai.all_plugins
|
|
110
|
+
node.consume_external_attrs(ohai.data, {})
|
|
111
|
+
run_context
|
|
112
|
+
action_collection
|
|
113
|
+
new_resource
|
|
114
|
+
registry
|
|
398
115
|
|
|
399
|
-
|
|
400
|
-
@new_resource.key(reg_child)
|
|
401
|
-
@new_resource.values([{ name: "OC", type: :string }])
|
|
402
|
-
expect { @new_resource.run_action(:create_if_missing) }.to raise_error(Chef::Exceptions::RegKeyValuesDataMissing)
|
|
403
|
-
end
|
|
404
|
-
|
|
405
|
-
it "raises an error if action create_if_missing and only name key present in values hash" do
|
|
406
|
-
@new_resource.key(reg_child)
|
|
407
|
-
@new_resource.values([{ name: "OC" }])
|
|
408
|
-
expect { @new_resource.run_action(:create_if_missing) }.to raise_error(Chef::Exceptions::RegKeyValuesTypeMissing)
|
|
409
|
-
end
|
|
410
|
-
|
|
411
|
-
it "does not raise an error if action create_if_missing and all keys are present in values hash" do
|
|
412
|
-
@new_resource.key(reg_child)
|
|
413
|
-
@new_resource.values([{ name: "OC", type: :string, data: "my_data" }])
|
|
414
|
-
expect { @new_resource.run_action(:create_if_missing) }.to_not raise_error
|
|
415
|
-
end
|
|
416
|
-
|
|
417
|
-
it "creates missing keys if action create and parent does not exist and recursive is set to true" do
|
|
418
|
-
@new_resource.key(reg_child + "\\Sontaran\\Sontar")
|
|
419
|
-
@new_resource.values([{ name: "OC", type: :string, data: "MissingData" }])
|
|
420
|
-
@new_resource.recursive(true)
|
|
421
|
-
@new_resource.run_action(:create_if_missing)
|
|
422
|
-
|
|
423
|
-
expect(@registry.key_exists?(reg_child + "\\Sontaran\\Sontar")).to eq(true)
|
|
424
|
-
expect(@registry.value_exists?(reg_child + "\\Sontaran\\Sontar", { name: "OC", type: :string, data: "MissingData" })).to eq(true)
|
|
425
|
-
end
|
|
426
|
-
|
|
427
|
-
it "creates key with multiple value as specified" do
|
|
428
|
-
@new_resource.key(reg_child + "\\Adipose")
|
|
429
|
-
@new_resource.values([{ name: "one", type: :string, data: "1" }, { name: "two", type: :string, data: "2" }, { name: "three", type: :string, data: "3" }])
|
|
430
|
-
@new_resource.recursive(true)
|
|
431
|
-
@new_resource.run_action(:create_if_missing)
|
|
432
|
-
|
|
433
|
-
@new_resource.each_value do |value|
|
|
434
|
-
expect(@registry.value_exists?(reg_child + "\\Adipose", value)).to eq(true)
|
|
435
|
-
end
|
|
436
|
-
end
|
|
437
|
-
|
|
438
|
-
it "prepares the reporting data for :create_if_missing" do
|
|
439
|
-
@new_resource.key(reg_child + "\\Judoon")
|
|
440
|
-
@new_resource.values([{ name: "ReportingVal3", type: :string, data: "report3" }])
|
|
441
|
-
@new_resource.recursive(true)
|
|
442
|
-
@new_resource.run_action(:create_if_missing)
|
|
443
|
-
@report = @resource_reporter.prepare_run_data
|
|
444
|
-
|
|
445
|
-
expect(@report["action"]).to eq("end")
|
|
446
|
-
expect(@report["resources"][0]["type"]).to eq("registry_key")
|
|
447
|
-
expect(@report["resources"][0]["name"]).to eq(resource_name)
|
|
448
|
-
expect(@report["resources"][0]["id"]).to eq(reg_child + "\\Judoon")
|
|
449
|
-
expect(@report["resources"][0]["after"][:values]).to eq([{ name: "ReportingVal3", type: :string, data: "report3" }])
|
|
450
|
-
expect(@report["resources"][0]["before"][:values]).to eq([])
|
|
451
|
-
expect(@report["resources"][0]["result"]).to eq("create_if_missing")
|
|
452
|
-
expect(@report["status"]).to eq("success")
|
|
453
|
-
expect(@report["total_res_count"]).to eq("1")
|
|
116
|
+
reset_registry
|
|
454
117
|
end
|
|
455
118
|
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
119
|
+
after do
|
|
120
|
+
clean_registry
|
|
121
|
+
end
|
|
122
|
+
subject do
|
|
123
|
+
resource_reporter
|
|
124
|
+
events.register(resource_reporter)
|
|
125
|
+
events.register(action_collection)
|
|
126
|
+
resource_reporter.action_collection_registration(action_collection)
|
|
127
|
+
resource_reporter.run_started(run_status)
|
|
128
|
+
new_resource.key(registry_key)
|
|
129
|
+
new_resource.values(registry_key_values)
|
|
130
|
+
new_resource.run_action(action)
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
context "action :create" do
|
|
134
|
+
let(:action) { :create }
|
|
135
|
+
let(:registry_key_values) { [{ name: "Color", type: :string, data: "Orange" }] }
|
|
136
|
+
let(:registry_key) { reg_child }
|
|
137
|
+
before { reset_registry }
|
|
138
|
+
it "creates a registry key if the key is missing" do
|
|
139
|
+
subject
|
|
140
|
+
expect(registry.key_exists?(registry_key)).to be true
|
|
141
|
+
expect(registry.get_values(registry_key)).to eq(registry_key_values)
|
|
142
|
+
report = resource_reporter.prepare_run_data
|
|
143
|
+
expect(report["resources"][0]["after"][:values]).to eq(registry_key_values)
|
|
468
144
|
end
|
|
469
145
|
|
|
470
|
-
it "does
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
146
|
+
it "does not create a registry key if it already exists" do
|
|
147
|
+
registry.create_key(registry_key, true)
|
|
148
|
+
registry_key_values.each do |rkv|
|
|
149
|
+
registry.set_value(registry_key, rkv)
|
|
150
|
+
end
|
|
151
|
+
subject
|
|
152
|
+
report = resource_reporter.prepare_run_data
|
|
153
|
+
expect(report["total_res_count"]).to eq("0")
|
|
476
154
|
end
|
|
477
155
|
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
156
|
+
let(:prepopulated_values) do
|
|
157
|
+
[
|
|
158
|
+
{ name: "TheBefore", type: :multi_string, data: %w{abc def} },
|
|
159
|
+
{ name: "ReportingVal1", type: :dword, data: 1234 },
|
|
160
|
+
]
|
|
483
161
|
end
|
|
484
162
|
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
@new_resource.values([{ name: "BriskWalk", type: :string }])
|
|
488
|
-
@new_resource.run_action(:create_if_missing) # should not raise_error
|
|
489
|
-
expect(@registry.key_exists?(reg_child + "\\Zygons")).to eq(false)
|
|
490
|
-
end
|
|
163
|
+
def prepopulate(key, values)
|
|
164
|
+
registry.create_key(key, true)
|
|
491
165
|
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
@new_resource.run_action(:create_if_missing) # should not raise_error
|
|
496
|
-
expect(@registry.key_exists?(reg_child + "\\Zygons")).to eq(false)
|
|
166
|
+
values.each do |value|
|
|
167
|
+
registry.set_value(registry_key, value)
|
|
168
|
+
end
|
|
497
169
|
end
|
|
498
170
|
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
expect(@registry.key_exists?(reg_child + "\\Zygons")).to eq(false)
|
|
504
|
-
end
|
|
505
|
-
end
|
|
506
|
-
end
|
|
507
|
-
|
|
508
|
-
context "when the action is delete" do
|
|
509
|
-
before(:all) do
|
|
510
|
-
reset_registry
|
|
511
|
-
create_deletable_keys
|
|
512
|
-
end
|
|
513
|
-
|
|
514
|
-
it "takes no action if the specified key path does not exist in the system" do
|
|
515
|
-
expect(@registry.key_exists?(reg_parent + "\\Osirian")).to eq(false)
|
|
516
|
-
|
|
517
|
-
@new_resource.key(reg_parent + "\\Osirian")
|
|
518
|
-
@new_resource.recursive(false)
|
|
519
|
-
@new_resource.run_action(:delete)
|
|
520
|
-
|
|
521
|
-
expect(@registry.key_exists?(reg_parent + "\\Osirian")).to eq(false)
|
|
522
|
-
end
|
|
523
|
-
|
|
524
|
-
it "takes no action if the key exists but the value does not" do
|
|
525
|
-
expect(@registry.data_exists?(reg_parent + "\\Opscode", { name: "Color", type: :string, data: "Orange" })).to eq(true)
|
|
526
|
-
|
|
527
|
-
@new_resource.key(reg_parent + "\\Opscode")
|
|
528
|
-
@new_resource.values([{ name: "LooksLike", type: :multi_string, data: %w{SeattleGrey OCOrange} }])
|
|
529
|
-
@new_resource.recursive(false)
|
|
530
|
-
@new_resource.run_action(:delete)
|
|
531
|
-
|
|
532
|
-
expect(@registry.data_exists?(reg_parent + "\\Opscode", { name: "Color", type: :string, data: "Orange" })).to eq(true)
|
|
533
|
-
end
|
|
171
|
+
describe "new key" do
|
|
172
|
+
before { new_resource.recursive(true) }
|
|
173
|
+
let(:registry_key) { "#{reg_child}\\NewValues" }
|
|
174
|
+
let(:registry_key_values) { [{ name: "SomeValue", type: :string, data: "Blue" }] }
|
|
534
175
|
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
expect(@registry.data_exists?(reg_parent + "\\Opscode", { name: "Color", type: :string, data: "Orange" })).to eq(true)
|
|
542
|
-
expect(@registry.value_exists?(reg_parent + "\\Opscode", { name: "AKA", type: :string, data: "OC" })).to eq(false)
|
|
543
|
-
expect(@registry.value_exists?(reg_parent + "\\Opscode", { name: "Opscode", type: :multi_string, data: %w{Seattle Washington} })).to eq(false)
|
|
544
|
-
end
|
|
545
|
-
|
|
546
|
-
it "it deletes the values with the same name irrespective of it type and data" do
|
|
547
|
-
@new_resource.key(reg_parent + "\\Opscode")
|
|
548
|
-
@new_resource.values([{ name: "Color", type: :multi_string, data: %w{Black Orange} }])
|
|
549
|
-
@new_resource.recursive(false)
|
|
550
|
-
@new_resource.run_action(:delete)
|
|
551
|
-
|
|
552
|
-
expect(@registry.value_exists?(reg_parent + "\\Opscode", { name: "Color", type: :string, data: "Orange" })).to eq(false)
|
|
553
|
-
end
|
|
554
|
-
|
|
555
|
-
it "prepares the reporting data for action :delete" do
|
|
556
|
-
@new_resource.key(reg_parent + "\\ReportKey")
|
|
557
|
-
@new_resource.values([{ name: "ReportVal4", type: :string, data: "report4" }, { name: "ReportVal5", type: :string, data: "report5" }])
|
|
558
|
-
@new_resource.recursive(true)
|
|
559
|
-
@new_resource.run_action(:delete)
|
|
560
|
-
|
|
561
|
-
@report = @resource_reporter.prepare_run_data
|
|
562
|
-
|
|
563
|
-
expect(@registry.value_exists?(reg_parent + "\\ReportKey", [{ name: "ReportVal4", type: :string, data: "report4" }, { name: "ReportVal5", type: :string, data: "report5" }])).to eq(false)
|
|
564
|
-
|
|
565
|
-
expect(@report["action"]).to eq("end")
|
|
566
|
-
expect(@report["resources"].count).to eq(1)
|
|
567
|
-
expect(@report["resources"][0]["type"]).to eq("registry_key")
|
|
568
|
-
expect(@report["resources"][0]["name"]).to eq(resource_name)
|
|
569
|
-
expect(@report["resources"][0]["id"]).to eq(reg_parent + "\\ReportKey")
|
|
570
|
-
expect(@report["resources"][0]["before"][:values]).to eq([{ name: "ReportVal4", type: :string, data: "report4" },
|
|
571
|
-
{ name: "ReportVal5", type: :string, data: "report5" }])
|
|
572
|
-
# Not testing for after values to match since after -> new_resource values.
|
|
573
|
-
expect(@report["resources"][0]["result"]).to eq("delete")
|
|
574
|
-
expect(@report["status"]).to eq("success")
|
|
575
|
-
expect(@report["total_res_count"]).to eq("1")
|
|
576
|
-
end
|
|
577
|
-
|
|
578
|
-
context "while running in whyrun mode" do
|
|
579
|
-
before(:each) do
|
|
580
|
-
Chef::Config[:why_run] = true
|
|
176
|
+
it "creates the new registry key with the specified values" do
|
|
177
|
+
subject
|
|
178
|
+
expect(registry.key_exists?(registry_key)).to be true
|
|
179
|
+
expect(registry.value_exists?(registry_key, registry_key_values[-1])).to be true
|
|
180
|
+
end
|
|
581
181
|
end
|
|
582
|
-
it "does nothing if the action is delete" do
|
|
583
|
-
@new_resource.key(reg_parent + "\\OpscodeWhyRun")
|
|
584
|
-
@new_resource.values([{ name: "BriskWalk", type: :string, data: "is good for health" }])
|
|
585
|
-
@new_resource.recursive(false)
|
|
586
|
-
@new_resource.run_action(:delete)
|
|
587
182
|
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
183
|
+
context "an existing key" do
|
|
184
|
+
let(:registry_key) { "#{reg_child}\\ExistingValue" }
|
|
185
|
+
let(:initial_values) { [{ name: "SomeValue", type: :dword, data: 3321 }] }
|
|
186
|
+
|
|
187
|
+
before do
|
|
188
|
+
prepopulate(registry_key, initial_values)
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
context "same value, type, and data" do
|
|
192
|
+
let(:registry_key_values) { initial_values }
|
|
193
|
+
|
|
194
|
+
it "doesn't update the key if the values are the same" do
|
|
195
|
+
subject
|
|
196
|
+
expect(new_resource).not_to be_updated_by_last_action
|
|
197
|
+
expect(registry.key_exists?(registry_key)).to be true
|
|
198
|
+
expect(registry.value_exists?(registry_key, initial_values[-1])).to be true
|
|
199
|
+
end
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
context "same value, type, but datatype of data differs" do
|
|
203
|
+
let(:registry_key_values) { [{ name: "SomeValue", type: :dword, data: "3321" }] }
|
|
204
|
+
|
|
205
|
+
it "updates the key if the value type is different" do
|
|
206
|
+
subject
|
|
207
|
+
expect(new_resource).not_to be_updated_by_last_action
|
|
208
|
+
expect(registry.key_exists?(registry_key)).to be true
|
|
209
|
+
expect(registry.value_exists?(registry_key, initial_values[-1])).to be true
|
|
210
|
+
end
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
context "same value, different type, data type differs" do
|
|
214
|
+
let(:registry_key_values) { [{ name: "SomeValue", type: :multi_string, data: %w{3321 2231} }] }
|
|
215
|
+
|
|
216
|
+
it "updates the key if the value type is different" do
|
|
217
|
+
subject
|
|
218
|
+
expect(new_resource).to be_updated_by_last_action
|
|
219
|
+
expect(registry.key_exists?(registry_key)).to be true
|
|
220
|
+
expect(registry.value_exists?(registry_key, registry_key_values[-1])).to be true
|
|
221
|
+
end
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
context "parent exists, but not child" do
|
|
225
|
+
let(:registry_key) { "#{reg_child}\\DoesNotExist" }
|
|
226
|
+
before { new_resource.recursive(false) }
|
|
227
|
+
it "creates the child if the parent exists" do
|
|
228
|
+
subject
|
|
229
|
+
expect(registry.key_exists?(registry_key)).to eq(true)
|
|
230
|
+
expect(registry.value_exists?(registry_key, registry_key_values[-1])).to be true
|
|
231
|
+
end
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
context "missing type key" do
|
|
235
|
+
let(:registry_key) { "#{reg_child}\\MissingTypeKey" }
|
|
236
|
+
let(:registry_key_values) { [{ name: "SomeValue", data: "3321" }] }
|
|
237
|
+
it "raises RegKeyValuesTypeMissing" do
|
|
238
|
+
expect { subject }.to raise_error(Chef::Exceptions::RegKeyValuesTypeMissing)
|
|
239
|
+
end
|
|
240
|
+
end
|
|
241
|
+
|
|
242
|
+
context "missing data key" do
|
|
243
|
+
let(:registry_key) { "#{reg_child}\\MissingDataKey" }
|
|
244
|
+
let(:registry_key_values) { [{ name: "SomeValue", type: :string }] }
|
|
245
|
+
it "raises RegKeyValuesTypeMissing" do
|
|
246
|
+
expect { subject }.to raise_error(Chef::Exceptions::RegKeyValuesDataMissing)
|
|
247
|
+
end
|
|
248
|
+
end
|
|
249
|
+
|
|
250
|
+
context "new value" do
|
|
251
|
+
let(:registry_key_values) { [{ name: "NewValue", type: :string, data: "Green" }] }
|
|
252
|
+
|
|
253
|
+
it "creates a value if it does not exist" do
|
|
254
|
+
subject
|
|
255
|
+
expect(new_resource).to be_updated_by_last_action
|
|
256
|
+
expect(registry.key_exists?(registry_key)).to be true
|
|
257
|
+
expect(registry.value_exists?(registry_key, registry_key_values[-1])).to be true
|
|
258
|
+
end
|
|
259
|
+
end
|
|
658
260
|
end
|
|
659
261
|
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
262
|
+
context "two deep" do
|
|
263
|
+
let(:registry_key) { "#{reg_child}\\#{rand(1000..2000)}\\#{rand(1000..3000)}}" }
|
|
264
|
+
context "recursive true" do
|
|
265
|
+
before { new_resource.recursive(true) }
|
|
266
|
+
it "creates the child" do
|
|
267
|
+
subject
|
|
268
|
+
expect(registry.key_exists?(registry_key)).to eq(true)
|
|
269
|
+
expect(registry.value_exists?(registry_key, registry_key_values[-1])).to be true
|
|
270
|
+
end
|
|
271
|
+
end
|
|
272
|
+
|
|
273
|
+
context "recursive false" do
|
|
274
|
+
before { new_resource.recursive(false) }
|
|
275
|
+
it "raises Win32RegNoRecursive" do
|
|
276
|
+
expect { subject }.to raise_error(Chef::Exceptions::Win32RegNoRecursive)
|
|
277
|
+
end
|
|
278
|
+
end
|
|
665
279
|
end
|
|
666
|
-
it "does nothing if the action is delete_key" do
|
|
667
|
-
@new_resource.key(reg_parent + "\\OpscodeWhyRun")
|
|
668
|
-
@new_resource.values([{ name: "BriskWalk", type: :string, data: "is good for health" }])
|
|
669
|
-
@new_resource.recursive(false)
|
|
670
|
-
@new_resource.run_action(:delete_key)
|
|
671
280
|
|
|
672
|
-
|
|
281
|
+
context "create key with multiple values" do
|
|
282
|
+
before { new_resource.recursive(true) }
|
|
283
|
+
let(:registry_key) { "#{reg_child}\\MultipleValueKey" }
|
|
284
|
+
let(:registry_key_values) do
|
|
285
|
+
[
|
|
286
|
+
{ name: "SomeValue", type: :string, data: "Blue" },
|
|
287
|
+
{ name: "AnotherValue", type: :string, data: "Green" },
|
|
288
|
+
]
|
|
289
|
+
end
|
|
290
|
+
it "creates all the values" do
|
|
291
|
+
subject
|
|
292
|
+
expect(registry.key_exists?(registry_key)).to eq(true)
|
|
293
|
+
registry_key_values.each do |value|
|
|
294
|
+
expect(registry.value_exists?(registry_key, value)).to be true
|
|
295
|
+
end
|
|
296
|
+
end
|
|
673
297
|
end
|
|
674
298
|
end
|
|
675
299
|
end
|