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
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright:: Copyright (c) Chef Software Inc.
|
|
3
|
+
# License:: Apache License, Version 2.0
|
|
4
|
+
#
|
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
# you may not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
# See the License for the specific language governing permissions and
|
|
15
|
+
# limitations under the License.
|
|
16
|
+
#
|
|
17
|
+
|
|
18
|
+
require "spec_helper"
|
|
19
|
+
|
|
20
|
+
describe Chef::Resource::ChocolateyInstaller do
|
|
21
|
+
include RecipeDSLHelper
|
|
22
|
+
|
|
23
|
+
let(:resource) { Chef::Resource::ChocolateyInstaller.new("fakey_fakerton") }
|
|
24
|
+
let(:config) do
|
|
25
|
+
<<-CONFIG
|
|
26
|
+
<?xml version="1.0" encoding="utf-8"?>
|
|
27
|
+
<chocolatey xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
|
28
|
+
<config>
|
|
29
|
+
<add key="containsLegacyPackageInstalls" value="true" description="Install has packages installed prior to 0.9.9 series." />
|
|
30
|
+
</config>
|
|
31
|
+
<sources>
|
|
32
|
+
<source id="chocolatey" value="https://chocolatey.org/api/v2/" disabled="false" bypassProxy="false" selfService="false" adminOnly="false" priority="0" />
|
|
33
|
+
</sources>
|
|
34
|
+
<features>
|
|
35
|
+
<feature name="checksumFiles" enabled="true" setExplicitly="false" description="Checksum files when pulled in from internet (based on package)." />
|
|
36
|
+
</features>
|
|
37
|
+
<apiKeys />
|
|
38
|
+
</chocolatey>
|
|
39
|
+
CONFIG
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# we save off the ENV and set ALLUSERSPROFILE so these specs will work on *nix and non-C drive Windows installs
|
|
43
|
+
before(:each) do
|
|
44
|
+
@original_env = ENV.to_hash
|
|
45
|
+
ENV["ALLUSERSPROFILE"] = "C:\\ProgramData"
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
after(:each) do
|
|
49
|
+
ENV.clear
|
|
50
|
+
ENV.update(@original_env)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
describe "Basic Resource Settings" do
|
|
54
|
+
context "on windows", :windows_only do
|
|
55
|
+
it "supports :install, :uninstall, :upgrade actions" do
|
|
56
|
+
expect { resource.action :install }.not_to raise_error
|
|
57
|
+
expect { resource.action :uninstall }.not_to raise_error
|
|
58
|
+
expect { resource.action :upgrade }.not_to raise_error
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
describe "Basic chocolatey settings" do
|
|
64
|
+
context "on windows", :windows_only do
|
|
65
|
+
it "has a resource name of :chocolatey_installer" do
|
|
66
|
+
expect(resource.resource_name).to eql(:chocolatey_installer)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
it "sets the default action as :install" do
|
|
70
|
+
expect(resource.action).to eql([:install])
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
it "supports :install and :uninstall actions" do
|
|
74
|
+
expect { resource.action :install }.not_to raise_error
|
|
75
|
+
expect { resource.action :uninstall }.not_to raise_error
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
it "does not support bologna install options" do
|
|
79
|
+
expect { resource.action :foo }.to raise_error(Chef::Exceptions::ValidationFailed)
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
describe "Installing chocolatey" do
|
|
85
|
+
context "on windows", :windows_only do
|
|
86
|
+
it "can install Chocolatey with parameters" do
|
|
87
|
+
resource.chocolatey_version = "1.4.0"
|
|
88
|
+
expect { resource.action :install }.not_to raise_error
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
it "logs a warning if a chocolatey install cannot be found" do
|
|
92
|
+
allow(::File).to receive(:exist?).with('C:\ProgramData\chocolatey\bin\choco.exe').and_return(false)
|
|
93
|
+
expect { Chef::Log.warn("Chocolatey is already uninstalled.") }.not_to output.to_stderr
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
describe "Chocolatey is idempotent because" do
|
|
99
|
+
context "on windows", :windows_only do
|
|
100
|
+
it "it does not install choco again if it is already installed" do
|
|
101
|
+
install_choco
|
|
102
|
+
chocolatey_installer "install" do
|
|
103
|
+
action :install
|
|
104
|
+
end.should_not_be_updated
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
describe "upgrading choco versions" do
|
|
110
|
+
|
|
111
|
+
context "on windows", :windows_only do
|
|
112
|
+
describe "when the versions do not match" do
|
|
113
|
+
it "upgrades if the proposed version is newer" do
|
|
114
|
+
allow(resource).to receive(:get_choco_version).and_return(Gem::Version.new("1.2.2"))
|
|
115
|
+
allow(resource).to receive(:chocolatey_version).and_return(Gem::Version.new("4.2.2"))
|
|
116
|
+
expect { resource.action :upgrade }.not_to raise_error
|
|
117
|
+
allow(resource).to receive(:get_choco_version).and_return(Gem::Version.new("4.2.2"))
|
|
118
|
+
expect(resource.get_choco_version).to eql(Gem::Version.new("4.2.2"))
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
describe "when the versions match" do
|
|
122
|
+
it "does not upgrade if the old version is identical" do
|
|
123
|
+
allow(resource).to receive(:get_choco_version).and_return(Gem::Version.new("2.2.2"))
|
|
124
|
+
allow(resource).to receive(:chocolatey_version).and_return(Gem::Version.new("2.2.2"))
|
|
125
|
+
expect { resource.action :upgrade }.not_to raise_error
|
|
126
|
+
expect(resource).not_to be_updated
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
describe "Uninstalling chocolatey" do
|
|
133
|
+
context "on windows", :windows_only do
|
|
134
|
+
it "doesn't error out uninstalling chocolatey if chocolatey is not installed" do
|
|
135
|
+
allow(::File).to receive(:exist?).with('C:\ProgramData\chocolatey\bin\choco.exe').and_return(false)
|
|
136
|
+
expect { resource.action :uninstall }.not_to raise_error
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
def install_choco
|
|
142
|
+
require "chef-powershell"
|
|
143
|
+
include ChefPowerShell::ChefPowerShellModule::PowerShellExec
|
|
144
|
+
powershell_code = <<-CODE
|
|
145
|
+
Set-ExecutionPolicy Bypass -Scope Process -Force;
|
|
146
|
+
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072;
|
|
147
|
+
iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
|
|
148
|
+
CODE
|
|
149
|
+
powershell_exec(powershell_code)
|
|
150
|
+
end
|
|
151
|
+
end
|
|
@@ -18,7 +18,11 @@
|
|
|
18
18
|
require "spec_helper"
|
|
19
19
|
|
|
20
20
|
describe Chef::Resource::CronD do
|
|
21
|
-
let(:
|
|
21
|
+
let(:node) { Chef::Node.new }
|
|
22
|
+
let(:events) { Chef::EventDispatch::Dispatcher.new }
|
|
23
|
+
let(:run_context) { Chef::RunContext.new(node, {}, events) }
|
|
24
|
+
let(:resource) { Chef::Resource::CronD.new("cronify", run_context) }
|
|
25
|
+
let(:provider) { resource.provider_for_action(:create) }
|
|
22
26
|
|
|
23
27
|
it "has a default action of [:create]" do
|
|
24
28
|
expect(resource.action).to eql([:create])
|
|
@@ -34,6 +38,38 @@ describe Chef::Resource::CronD do
|
|
|
34
38
|
expect(resource.cron_name).to eql("cronify")
|
|
35
39
|
end
|
|
36
40
|
|
|
41
|
+
context "on linux" do
|
|
42
|
+
before(:each) do
|
|
43
|
+
node.automatic_attrs[:os] = "linux"
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it "the cron_name property is valid" do
|
|
47
|
+
provider.define_resource_requirements
|
|
48
|
+
|
|
49
|
+
expect { resource.cron_name "cron-job"; provider.process_resource_requirements }.not_to raise_error
|
|
50
|
+
expect { resource.cron_name "cron_job_0"; provider.process_resource_requirements }.not_to raise_error
|
|
51
|
+
expect { resource.cron_name "CronJob"; provider.process_resource_requirements }.not_to raise_error
|
|
52
|
+
expect { resource.cron_name "cron!"; provider.process_resource_requirements }.to raise_error "The cron job name should contain letters, numbers, hyphens and underscores only."
|
|
53
|
+
expect { resource.cron_name "cron job"; provider.process_resource_requirements }.to raise_error "The cron job name should contain letters, numbers, hyphens and underscores only."
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
context "not on linux" do
|
|
58
|
+
before(:each) do
|
|
59
|
+
node.automatic_attrs[:os] = "aix"
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
it "all cron names are valid" do
|
|
63
|
+
provider.define_resource_requirements
|
|
64
|
+
|
|
65
|
+
expect { resource.cron_name "cron-job"; provider.process_resource_requirements }.not_to raise_error
|
|
66
|
+
expect { resource.cron_name "cron_job_0"; provider.process_resource_requirements }.not_to raise_error
|
|
67
|
+
expect { resource.cron_name "CronJob"; provider.process_resource_requirements }.not_to raise_error
|
|
68
|
+
expect { resource.cron_name "cron!"; provider.process_resource_requirements }.not_to raise_error
|
|
69
|
+
expect { resource.cron_name "cron job"; provider.process_resource_requirements }.not_to raise_error
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
37
73
|
it "the mode property defaults to '0600'" do
|
|
38
74
|
expect(resource.mode).to eql("0600")
|
|
39
75
|
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright:: Copyright (c) Chef Software Inc.
|
|
3
|
+
# License:: Apache License, Version 2.0
|
|
4
|
+
#
|
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
# you may not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
# See the License for the specific language governing permissions and
|
|
15
|
+
# limitations under the License.
|
|
16
|
+
#
|
|
17
|
+
|
|
18
|
+
require "spec_helper"
|
|
19
|
+
|
|
20
|
+
describe Chef::Resource::MacosPkg do
|
|
21
|
+
let(:resource) { Chef::Resource::MacosPkg.new("fakey_fakerton") }
|
|
22
|
+
|
|
23
|
+
it "has a resource name of :macos_pkg" do
|
|
24
|
+
expect(resource.resource_name).to eql(:macos_pkg)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it "sets the default action as :install" do
|
|
28
|
+
expect(resource.action).to eql([:install])
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it "supports :install action" do
|
|
32
|
+
expect { resource.action :install }.not_to raise_error
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it "target property defaults to /" do
|
|
36
|
+
expect(resource.target).to eql("/")
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -47,9 +47,9 @@ describe Chef::Resource::PowershellScript do
|
|
|
47
47
|
expect(resource.convert_boolean_return).to eq(false)
|
|
48
48
|
end
|
|
49
49
|
|
|
50
|
-
it "inherits exactly the :cwd, :domain, :environment, :group, :password, :path, :user, :umask, :architecture, :elevated, :interpreter, :login properties from a parent resource class" do
|
|
50
|
+
it "inherits exactly the :cwd, :domain, :environment, :group, :password, :path, :user, :umask, :architecture, :elevated, :interpreter, :login, :use_inline_powershell properties from a parent resource class" do
|
|
51
51
|
inherited_difference = Chef::Resource::PowershellScript.guard_inherited_attributes -
|
|
52
|
-
%i{cwd domain environment group password path user umask architecture elevated interpreter login}
|
|
52
|
+
%i{cwd domain environment group password path user umask architecture elevated interpreter login use_inline_powershell}
|
|
53
53
|
|
|
54
54
|
expect(inherited_difference).to eq([])
|
|
55
55
|
end
|
|
@@ -0,0 +1,381 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright:: Copyright 2008-2016, Chef, Inc.
|
|
3
|
+
# License:: Apache License, Version 2.0
|
|
4
|
+
#
|
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
# you may not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
# See the License for the specific language governing permissions and
|
|
15
|
+
# limitations under the License.
|
|
16
|
+
#
|
|
17
|
+
|
|
18
|
+
require "spec_helper"
|
|
19
|
+
require "train"
|
|
20
|
+
require "train-rest"
|
|
21
|
+
|
|
22
|
+
class RestResourceByQuery < Chef::Resource
|
|
23
|
+
use "core::rest_resource"
|
|
24
|
+
|
|
25
|
+
provides :rest_resource_by_query, target_mode: true
|
|
26
|
+
|
|
27
|
+
property :address, String, required: true
|
|
28
|
+
property :prefix, Integer, required: true
|
|
29
|
+
property :gateway, String
|
|
30
|
+
|
|
31
|
+
rest_api_collection "/api/v1/addresses"
|
|
32
|
+
rest_api_document "/api/v1/address/?ip={address}"
|
|
33
|
+
rest_property_map({
|
|
34
|
+
address: "address",
|
|
35
|
+
prefix: "prefix",
|
|
36
|
+
gateway: "gateway",
|
|
37
|
+
})
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
class RestResourceByPath < RestResourceByQuery
|
|
41
|
+
provides :rest_resource_by_path, target_mode: true
|
|
42
|
+
|
|
43
|
+
rest_api_document "/api/v1/address/{address}"
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
describe "rest_resource using query-based addressing" do
|
|
47
|
+
let(:train) {
|
|
48
|
+
Train.create(
|
|
49
|
+
"rest", {
|
|
50
|
+
endpoint: "https://api.example.com/api/v1/",
|
|
51
|
+
debug_rest: true,
|
|
52
|
+
logger: Chef::Log,
|
|
53
|
+
}
|
|
54
|
+
).connection
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
let(:run_context) do
|
|
58
|
+
cookbook_collection = Chef::CookbookCollection.new([])
|
|
59
|
+
node = Chef::Node.new
|
|
60
|
+
node.name "node1"
|
|
61
|
+
events = Chef::EventDispatch::Dispatcher.new
|
|
62
|
+
Chef::RunContext.new(node, cookbook_collection, events)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
let(:resource) do
|
|
66
|
+
RestResourceByQuery.new("set_address", run_context).tap do |resource|
|
|
67
|
+
resource.address = "192.0.2.1"
|
|
68
|
+
resource.prefix = 24
|
|
69
|
+
resource.action :configure
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
let(:provider) do
|
|
74
|
+
resource.provider_for_action(:configure).tap do |provider|
|
|
75
|
+
provider.current_resource = resource # for some stubby tests that don't call LCR
|
|
76
|
+
allow(provider).to receive(:api_connection).and_return(train)
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
before(:each) do
|
|
81
|
+
allow(Chef::Provider).to receive(:new).and_return(provider)
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
it "should include :configure action" do
|
|
85
|
+
expect(provider).to respond_to(:action_configure)
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
it "should include :delete action" do
|
|
89
|
+
expect(provider).to respond_to(:action_delete)
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
it "should include :nothing action" do
|
|
93
|
+
expect(provider).to respond_to(:action_nothing)
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
it "sets the default action as :configure" do
|
|
97
|
+
expect(resource.action).to eql([:configure])
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
it "supports :configure action" do
|
|
101
|
+
expect { resource.action :configure }.not_to raise_error
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
it "supports :delete action" do
|
|
105
|
+
expect { resource.action :delete }.not_to raise_error
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
it "should mixin RestResourceDSL" do
|
|
109
|
+
expect(resource.class.ancestors).to include(Chef::DSL::RestResource)
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
describe "#rest_postprocess" do
|
|
113
|
+
before do
|
|
114
|
+
provider.singleton_class.send(:public, :rest_postprocess)
|
|
115
|
+
end
|
|
116
|
+
it "should have a default rest_postprocess implementation" do
|
|
117
|
+
expect(provider).to respond_to(:rest_postprocess)
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
it "should have a non-mutating rest_postprocess implementation" do
|
|
121
|
+
response = "{ data: nil }"
|
|
122
|
+
|
|
123
|
+
expect(provider.rest_postprocess(response.dup)).to eq(response)
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
describe "#rest_errorhandler" do
|
|
128
|
+
before do
|
|
129
|
+
provider.singleton_class.send(:public, :rest_errorhandler)
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
it "should have a default rest_errorhandler implementation" do
|
|
133
|
+
expect(provider).to respond_to(:rest_errorhandler)
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
it "should have a non-mutating rest_errorhandler implementation" do
|
|
137
|
+
error_obj = StandardError.new
|
|
138
|
+
|
|
139
|
+
expect(provider.rest_errorhandler(error_obj.dup)).to eq(error_obj)
|
|
140
|
+
end
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
describe "#required_properties" do
|
|
144
|
+
before do
|
|
145
|
+
provider.singleton_class.send(:public, :required_properties)
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
it "should include required properties only" do
|
|
149
|
+
expect(provider.required_properties).to contain_exactly(:address, :prefix)
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
describe "#property_map" do
|
|
154
|
+
before do
|
|
155
|
+
provider.singleton_class.send(:public, :property_map)
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
it "should map resource properties to values properly" do
|
|
159
|
+
expect(provider.property_map).to eq({
|
|
160
|
+
address: "192.0.2.1",
|
|
161
|
+
prefix: 24,
|
|
162
|
+
gateway: nil,
|
|
163
|
+
name: "set_address",
|
|
164
|
+
})
|
|
165
|
+
end
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
describe "#rest_url_collection" do
|
|
169
|
+
before do
|
|
170
|
+
provider.singleton_class.send(:public, :rest_url_collection)
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
it "should return collection URLs properly" do
|
|
174
|
+
expect(provider.rest_url_collection).to eq("/api/v1/addresses")
|
|
175
|
+
end
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
describe "#rest_url_document" do
|
|
179
|
+
before do
|
|
180
|
+
provider.singleton_class.send(:public, :rest_url_document)
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
it "should apply URI templates to document URLs using query syntax properly" do
|
|
184
|
+
expect(provider.rest_url_document).to eq("/api/v1/address/?ip=192.0.2.1")
|
|
185
|
+
end
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
# TODO: Test with path-style URLs
|
|
189
|
+
describe "#rest_identity_implicit" do
|
|
190
|
+
before do
|
|
191
|
+
provider.singleton_class.send(:public, :rest_identity_implicit)
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
it "should return implicit identity properties properly" do
|
|
195
|
+
expect(provider.rest_identity_implicit).to eq({ "ip" => :address })
|
|
196
|
+
end
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
describe "#rest_identity_values" do
|
|
200
|
+
before do
|
|
201
|
+
provider.singleton_class.send(:public, :rest_identity_values)
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
it "should return implicit identity properties and values properly" do
|
|
205
|
+
expect(provider.rest_identity_values).to eq({ "ip" => "192.0.2.1" })
|
|
206
|
+
end
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
# TODO: changed_value
|
|
210
|
+
# TODO: load_current_value
|
|
211
|
+
|
|
212
|
+
# this might be a functional test, but it runs on any O/S so I leave it here
|
|
213
|
+
describe "when managing a resource" do
|
|
214
|
+
before { WebMock.disable_net_connect! }
|
|
215
|
+
let(:addresses_exists) { JSON.generate([{ "address": "192.0.2.1" }]) }
|
|
216
|
+
let(:addresses_other) { JSON.generate([{ "address": "172.16.32.85" }]) }
|
|
217
|
+
let(:address_exists) { JSON.generate({ "address": "192.0.2.1", "prefix": 24, "gateway": "192.0.2.1" }) }
|
|
218
|
+
let(:prefix_wrong) { JSON.generate({ "address": "192.0.2.1", "prefix": 25, "gateway": "192.0.2.1" }) }
|
|
219
|
+
|
|
220
|
+
it "should be idempotent" do
|
|
221
|
+
stub_request(:get, "https://api.example.com/api/v1/addresses")
|
|
222
|
+
.to_return(status: 200, body: addresses_exists, headers: { "Content-Type" => "application/json" })
|
|
223
|
+
stub_request(:get, "https://api.example.com/api/v1/address/?ip=192.0.2.1")
|
|
224
|
+
.to_return(status: 200, body: address_exists, headers: { "Content-Type" => "application/json" })
|
|
225
|
+
resource.run_action(:configure)
|
|
226
|
+
expect(resource.updated_by_last_action?).to be false
|
|
227
|
+
end
|
|
228
|
+
|
|
229
|
+
it "should PATCH if a property is incorrect" do
|
|
230
|
+
stub_request(:get, "https://api.example.com/api/v1/addresses")
|
|
231
|
+
.to_return(status: 200, body: addresses_exists, headers: { "Content-Type" => "application/json" })
|
|
232
|
+
stub_request(:get, "https://api.example.com/api/v1/address/?ip=192.0.2.1")
|
|
233
|
+
.to_return(status: 200, body: prefix_wrong, headers: { "Content-Type" => "application/json" })
|
|
234
|
+
stub_request(:patch, "https://api.example.com/api/v1/address/?ip=192.0.2.1")
|
|
235
|
+
.with(
|
|
236
|
+
body: "{\"address\":\"192.0.2.1\",\"prefix\":25}",
|
|
237
|
+
headers: {
|
|
238
|
+
"Accept" => "application/json",
|
|
239
|
+
"Content-Type" => "application/json",
|
|
240
|
+
}
|
|
241
|
+
)
|
|
242
|
+
.to_return(status: 200, body: address_exists, headers: { "Content-Type" => "application/json" })
|
|
243
|
+
resource.run_action(:configure)
|
|
244
|
+
expect(resource.updated_by_last_action?).to be true
|
|
245
|
+
end
|
|
246
|
+
|
|
247
|
+
it "should POST if there's no resources at all" do
|
|
248
|
+
stub_request(:get, "https://api.example.com/api/v1/addresses")
|
|
249
|
+
.to_return(status: 200, body: "[]", headers: { "Content-Type" => "application/json" })
|
|
250
|
+
stub_request(:post, "https://api.example.com/api/v1/addresses")
|
|
251
|
+
.with(
|
|
252
|
+
body: "{\"address\":\"192.0.2.1\",\"prefix\":24,\"ip\":\"192.0.2.1\"}"
|
|
253
|
+
)
|
|
254
|
+
.to_return(status: 200, body: address_exists, headers: { "Content-Type" => "application/json" })
|
|
255
|
+
resource.run_action(:configure)
|
|
256
|
+
expect(resource.updated_by_last_action?).to be true
|
|
257
|
+
end
|
|
258
|
+
|
|
259
|
+
it "should POST if the specific resource does not exist" do
|
|
260
|
+
stub_request(:get, "https://api.example.com/api/v1/addresses")
|
|
261
|
+
.to_return(status: 200, body: addresses_other, headers: { "Content-Type" => "application/json" })
|
|
262
|
+
stub_request(:get, "https://api.example.com/api/v1/address/?ip=192.0.2.1")
|
|
263
|
+
.to_return(status: 404, body: "", headers: {})
|
|
264
|
+
stub_request(:post, "https://api.example.com/api/v1/addresses")
|
|
265
|
+
.with(
|
|
266
|
+
body: "{\"address\":\"192.0.2.1\",\"prefix\":24,\"ip\":\"192.0.2.1\"}"
|
|
267
|
+
)
|
|
268
|
+
.to_return(status: 200, body: address_exists, headers: { "Content-Type" => "application/json" })
|
|
269
|
+
resource.run_action(:configure)
|
|
270
|
+
expect(resource.updated_by_last_action?).to be true
|
|
271
|
+
end
|
|
272
|
+
|
|
273
|
+
it "should be idempotent if the resouces needs deleting and there are no resources at all" do
|
|
274
|
+
stub_request(:get, "https://api.example.com/api/v1/addresses")
|
|
275
|
+
.to_return(status: 200, body: "[]", headers: { "Content-Type" => "application/json" })
|
|
276
|
+
resource.run_action(:delete)
|
|
277
|
+
expect(resource.updated_by_last_action?).to be false
|
|
278
|
+
end
|
|
279
|
+
|
|
280
|
+
it "should be idempotent if the resource doesn't exist" do
|
|
281
|
+
stub_request(:get, "https://api.example.com/api/v1/addresses")
|
|
282
|
+
.to_return(status: 200, body: addresses_other, headers: { "Content-Type" => "application/json" })
|
|
283
|
+
stub_request(:get, "https://api.example.com/api/v1/address/?ip=192.0.2.1")
|
|
284
|
+
.to_return(status: 404, body: "", headers: {})
|
|
285
|
+
resource.run_action(:delete)
|
|
286
|
+
expect(resource.updated_by_last_action?).to be false
|
|
287
|
+
end
|
|
288
|
+
|
|
289
|
+
it "should DELETE the resource if it exists and matches" do
|
|
290
|
+
stub_request(:get, "https://api.example.com/api/v1/addresses")
|
|
291
|
+
.to_return(status: 200, body: addresses_exists, headers: { "Content-Type" => "application/json" })
|
|
292
|
+
stub_request(:get, "https://api.example.com/api/v1/address/?ip=192.0.2.1")
|
|
293
|
+
.to_return(status: 200, body: address_exists, headers: { "Content-Type" => "application/json" })
|
|
294
|
+
stub_request(:delete, "https://api.example.com/api/v1/address/?ip=192.0.2.1")
|
|
295
|
+
.to_return(status: 200, body: "", headers: {})
|
|
296
|
+
resource.run_action(:delete)
|
|
297
|
+
expect(resource.updated_by_last_action?).to be true
|
|
298
|
+
end
|
|
299
|
+
|
|
300
|
+
it "should DELETE the resource if it exists and doesn't match" do
|
|
301
|
+
stub_request(:get, "https://api.example.com/api/v1/addresses")
|
|
302
|
+
.to_return(status: 200, body: addresses_exists, headers: { "Content-Type" => "application/json" })
|
|
303
|
+
stub_request(:get, "https://api.example.com/api/v1/address/?ip=192.0.2.1")
|
|
304
|
+
.to_return(status: 200, body: prefix_wrong, headers: { "Content-Type" => "application/json" })
|
|
305
|
+
stub_request(:delete, "https://api.example.com/api/v1/address/?ip=192.0.2.1")
|
|
306
|
+
.to_return(status: 200, body: "", headers: {})
|
|
307
|
+
resource.run_action(:delete)
|
|
308
|
+
expect(resource.updated_by_last_action?).to be true
|
|
309
|
+
end
|
|
310
|
+
end
|
|
311
|
+
end
|
|
312
|
+
|
|
313
|
+
describe "rest_resource using path-based addressing" do
|
|
314
|
+
let(:train) {
|
|
315
|
+
Train.create(
|
|
316
|
+
"rest", {
|
|
317
|
+
endpoint: "https://api.example.com/api/v1/",
|
|
318
|
+
debug_rest: true,
|
|
319
|
+
logger: Chef::Log,
|
|
320
|
+
}
|
|
321
|
+
).connection
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
let(:run_context) do
|
|
325
|
+
cookbook_collection = Chef::CookbookCollection.new([])
|
|
326
|
+
node = Chef::Node.new
|
|
327
|
+
node.name "node1"
|
|
328
|
+
events = Chef::EventDispatch::Dispatcher.new
|
|
329
|
+
Chef::RunContext.new(node, cookbook_collection, events)
|
|
330
|
+
end
|
|
331
|
+
|
|
332
|
+
let(:resource) do
|
|
333
|
+
RestResourceByPath.new("set_address", run_context).tap do |resource|
|
|
334
|
+
resource.address = "192.0.2.1"
|
|
335
|
+
resource.prefix = 24
|
|
336
|
+
resource.action :configure
|
|
337
|
+
end
|
|
338
|
+
end
|
|
339
|
+
|
|
340
|
+
let(:provider) do
|
|
341
|
+
resource.provider_for_action(:configure).tap do |provider|
|
|
342
|
+
provider.current_resource = resource # for some stubby tests that don't call LCR
|
|
343
|
+
allow(provider).to receive(:api_connection).and_return(train)
|
|
344
|
+
end
|
|
345
|
+
end
|
|
346
|
+
|
|
347
|
+
before(:each) do
|
|
348
|
+
allow(Chef::Provider).to receive(:new).and_return(provider)
|
|
349
|
+
end
|
|
350
|
+
|
|
351
|
+
describe "#rest_url_document" do
|
|
352
|
+
before do
|
|
353
|
+
provider.singleton_class.send(:public, :rest_url_document)
|
|
354
|
+
end
|
|
355
|
+
|
|
356
|
+
it "should apply URI templates to document URLs using path syntax properly" do
|
|
357
|
+
expect(provider.rest_url_document).to eq("/api/v1/address/192.0.2.1")
|
|
358
|
+
end
|
|
359
|
+
end
|
|
360
|
+
|
|
361
|
+
describe "#rest_identity_implicit" do
|
|
362
|
+
before do
|
|
363
|
+
provider.singleton_class.send(:public, :rest_identity_implicit)
|
|
364
|
+
end
|
|
365
|
+
|
|
366
|
+
it "should return implicit identity properties properly" do
|
|
367
|
+
expect(provider.rest_identity_implicit).to eq({ "address" => :address })
|
|
368
|
+
end
|
|
369
|
+
end
|
|
370
|
+
|
|
371
|
+
describe "#rest_identity_values" do
|
|
372
|
+
before do
|
|
373
|
+
provider.singleton_class.send(:public, :rest_identity_values)
|
|
374
|
+
end
|
|
375
|
+
|
|
376
|
+
it "should return implicit identity properties and values properly" do
|
|
377
|
+
expect(provider.rest_identity_values).to eq({ "address" => "192.0.2.1" })
|
|
378
|
+
end
|
|
379
|
+
end
|
|
380
|
+
|
|
381
|
+
end
|