chef 15.11.8 → 15.12.22

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -3
  3. data/README.md +3 -3
  4. data/chef.gemspec +3 -3
  5. data/lib/chef/application/apply.rb +1 -1
  6. data/lib/chef/chef_fs/path_utils.rb +3 -3
  7. data/lib/chef/cookbook/file_system_file_vendor.rb +1 -1
  8. data/lib/chef/data_bag.rb +2 -2
  9. data/lib/chef/data_collector/error_handlers.rb +1 -1
  10. data/lib/chef/deprecated.rb +8 -0
  11. data/lib/chef/dsl/declare_resource.rb +1 -1
  12. data/lib/chef/dsl/platform_introspection.rb +2 -0
  13. data/lib/chef/knife/bootstrap.rb +3 -6
  14. data/lib/chef/knife/bootstrap/templates/chef-full.erb +9 -9
  15. data/lib/chef/provider/package/cab.rb +1 -1
  16. data/lib/chef/provider/package/chocolatey.rb +1 -1
  17. data/lib/chef/provider/package/msu.rb +1 -0
  18. data/lib/chef/provider/package/powershell.rb +5 -1
  19. data/lib/chef/provider/package/snap.rb +96 -27
  20. data/lib/chef/provider/zypper_repository.rb +30 -10
  21. data/lib/chef/resource/archive_file.rb +28 -8
  22. data/lib/chef/resource/cron_access.rb +11 -3
  23. data/lib/chef/resource/hostname.rb +2 -1
  24. data/lib/chef/resource/msu_package.rb +5 -0
  25. data/lib/chef/version.rb +1 -1
  26. data/spec/functional/resource/msu_package_spec.rb +5 -2
  27. data/spec/functional/resource/windows_task_spec.rb +8 -8
  28. data/spec/unit/application_spec.rb +7 -0
  29. data/spec/unit/data_bag_spec.rb +1 -1
  30. data/spec/unit/knife/bootstrap_spec.rb +2 -2
  31. data/spec/unit/mixin/user_context_spec.rb +1 -9
  32. data/spec/unit/property_spec.rb +1 -1
  33. data/spec/unit/provider/package/powershell_spec.rb +95 -86
  34. data/spec/unit/provider/package/snap_spec.rb +1 -1
  35. data/spec/unit/provider/zypper_repository_spec.rb +75 -25
  36. data/spec/unit/resource/archive_file_spec.rb +11 -2
  37. data/spec/unit/resource/msu_package_spec.rb +4 -0
  38. data/spec/unit/resource/windows_dns_record_spec.rb +3 -3
  39. data/spec/unit/resource/windows_dns_zone_spec.rb +2 -2
  40. data/spec/unit/resource/windows_task_spec.rb +1 -1
  41. data/spec/unit/resource/windows_uac_spec.rb +2 -2
  42. data/spec/unit/resource/yum_repository_spec.rb +21 -21
  43. data/spec/unit/resource_spec.rb +1 -1
  44. data/spec/unit/util/threaded_job_queue_spec.rb +9 -0
  45. metadata +22 -16
@@ -115,28 +115,48 @@ class Chef
115
115
  end
116
116
  end
117
117
 
118
+ # the version of gpg installed on the system
119
+ #
120
+ # @return [Gem::Version] the version of GPG
121
+ def gpg_version
122
+ so = shell_out!("gpg --version")
123
+ # matches 2.0 and 2.2 versions from SLES 12 and 15: https://rubular.com/r/e6D0WfGK6SXvUp
124
+ version = /gpg \(GnuPG\)\s*(.*)/.match(so.stdout)[1]
125
+ logger.trace("GPG package version is #{version}")
126
+ Gem::Version.new(version)
127
+ end
128
+
118
129
  # is the provided key already installed
119
130
  # @param [String] key_path the path to the key on the local filesystem
120
131
  #
121
132
  # @return [boolean] is the key already known by rpm
122
133
  def key_installed?(key_path)
123
- so = shell_out("rpm -qa gpg-pubkey*")
134
+ so = shell_out("/bin/rpm -qa gpg-pubkey*")
124
135
  # expected output & match: http://rubular.com/r/RdF7EcXEtb
125
- status = /gpg-pubkey-#{key_fingerprint(key_path)}/.match(so.stdout)
136
+ status = /gpg-pubkey-#{short_key_id(key_path)}/.match(so.stdout)
126
137
  logger.trace("GPG key at #{key_path} is known by rpm? #{status ? "true" : "false"}")
127
138
  status
128
139
  end
129
140
 
130
- # extract the gpg key fingerprint from a local file
141
+ # extract the gpg key's short key id from a local file. Learning moment: This 8 hex value ID
142
+ # is sometimes incorrectly called the fingerprint. The fingerprint is the full length value
143
+ # and googling for that will just result in sad times.
144
+ #
131
145
  # @param [String] key_path the path to the key on the local filesystem
132
146
  #
133
- # @return [String] the fingerprint of the key
134
- def key_fingerprint(key_path)
135
- so = shell_out!("gpg --with-fingerprint #{key_path}")
136
- # expected output and match: http://rubular.com/r/BpfMjxySQM
137
- fingerprint = %r{pub\s*\S*/(\S*)}.match(so.stdout)[1].downcase
138
- logger.trace("GPG fingerprint of key at #{key_path} is #{fingerprint}")
139
- fingerprint
147
+ # @return [String] the short key id of the key
148
+ def short_key_id(key_path)
149
+ if gpg_version >= Gem::Version.new("2.2") # SLES 15+
150
+ so = shell_out!("gpg --import-options import-show --dry-run --import --with-colons #{key_path}")
151
+ # expected output and match: https://rubular.com/r/uXWJo3yfkli1qA
152
+ short_key_id = /fpr:*\h*(\h{8}):/.match(so.stdout)[1].downcase
153
+ else # SLES 12 and earlier
154
+ so = shell_out!("gpg --with-fingerprint #{key_path}")
155
+ # expected output and match: http://rubular.com/r/BpfMjxySQM
156
+ short_key_id = %r{pub\s*\S*/(\S*)}.match(so.stdout)[1].downcase
157
+ end
158
+ logger.trace("GPG short key ID of key at #{key_path} is #{short_key_id}")
159
+ short_key_id
140
160
  end
141
161
 
142
162
  # install the provided gpg key
@@ -19,6 +19,7 @@
19
19
  #
20
20
 
21
21
  require_relative "../resource"
22
+ require "fileutils" unless defined?(FileUtils)
22
23
 
23
24
  class Chef
24
25
  class Resource
@@ -38,6 +39,18 @@ class Chef
38
39
  destination '/srv/files'
39
40
  end
40
41
  ```
42
+
43
+ **Set specific permissions on the extracted files**:
44
+
45
+ ```ruby
46
+ archive_file 'Precompiled.zip' do
47
+ owner 'tsmith'
48
+ group 'staff'
49
+ mode '700'
50
+ path '/tmp/Precompiled.zip'
51
+ destination '/srv/files'
52
+ end
53
+ ```
41
54
  DOC
42
55
 
43
56
  property :path, String,
@@ -52,7 +65,7 @@ class Chef
52
65
  description: "The group of the extracted files."
53
66
 
54
67
  property :mode, [String, Integer],
55
- description: "The mode of the extracted files.",
68
+ description: "The mode of the extracted files. Integer values are deprecated as octal values (ex. 0755) would not be interpreted correctly.",
56
69
  default: "755"
57
70
 
58
71
  property :destination, String,
@@ -71,11 +84,11 @@ class Chef
71
84
  alias_method :extract_options, :options
72
85
  alias_method :extract_to, :destination
73
86
 
74
- require "fileutils" unless defined?(FileUtils)
75
-
76
87
  action :extract do
77
88
  description "Extract and archive file."
78
89
 
90
+ require_libarchive
91
+
79
92
  unless ::File.exist?(new_resource.path)
80
93
  raise Errno::ENOENT, "No archive found at #{new_resource.path}! Cannot continue."
81
94
  end
@@ -84,7 +97,8 @@ class Chef
84
97
  Chef::Log.trace("File or directory does not exist at destination path: #{new_resource.destination}")
85
98
 
86
99
  converge_by("create directory #{new_resource.destination}") do
87
- FileUtils.mkdir_p(new_resource.destination, mode: new_resource.mode.to_i)
100
+ # @todo when we remove the ability for mode to be an int we can remove the .to_s below
101
+ FileUtils.mkdir_p(new_resource.destination, mode: new_resource.mode.to_s.to_i(8))
88
102
  end
89
103
 
90
104
  extract(new_resource.path, new_resource.destination, Array(new_resource.options))
@@ -112,6 +126,16 @@ class Chef
112
126
  end
113
127
 
114
128
  action_class do
129
+ def require_libarchive
130
+ require "ffi-libarchive"
131
+ end
132
+
133
+ def define_resource_requirements
134
+ if new_resource.mode.is_a?(Integer)
135
+ Chef.deprecated(:archive_file_integer_file_mode, "The mode property should be passed to archive_file resources as a String and not an Integer to ensure the value is properly interpreted.")
136
+ end
137
+ end
138
+
115
139
  # This can't be a constant since we might not have required 'ffi-libarchive' yet.
116
140
  def extract_option_map
117
141
  {
@@ -135,8 +159,6 @@ class Chef
135
159
  #
136
160
  # @return [Boolean]
137
161
  def archive_differs_from_disk?(src, dest)
138
- require "ffi-libarchive"
139
-
140
162
  modified = false
141
163
  Dir.chdir(dest) do
142
164
  archive = Archive::Reader.open_filename(src)
@@ -163,8 +185,6 @@ class Chef
163
185
  #
164
186
  # @return [void]
165
187
  def extract(src, dest, options = [])
166
- require "ffi-libarchive"
167
-
168
188
  converge_by("extract #{src} to #{dest}") do
169
189
  flags = [options].flatten.map { |option| extract_option_map[option] }.compact.reduce(:|)
170
190
 
@@ -27,7 +27,7 @@ class Chef
27
27
  provides(:cron_manage) # legacy name @todo in Chef 15 we should { true } this so it wins over the cookbook
28
28
 
29
29
  introduced "14.4"
30
- description "Use the cron_access resource to manage the /etc/cron.allow and /etc/cron.deny files."
30
+ description "Use the **cron_access** resource to manage cron's cron.allow and cron.deny files. Note: This resource previously shipped in the `cron` cookbook as `cron_manage`, which it can still be used as for backwards compatibility with existing Chef Infra Client releases."
31
31
  examples <<~DOC
32
32
  Add the mike user to cron.allow
33
33
  ```ruby
@@ -54,11 +54,18 @@ class Chef
54
54
  description: "An optional property to set the user name if it differs from the resource block's name.",
55
55
  name_property: true
56
56
 
57
+ CRON_PATHS = {
58
+ "aix" => "/var/adm/cron",
59
+ "solaris" => "/etc/cron.d",
60
+ "default" => "/etc",
61
+ }.freeze
62
+
57
63
  action :allow do
58
64
  description "Add the user to the cron.allow file."
65
+ allow_path = ::File.join(value_for_platform_family(CRON_PATHS), "cron.allow")
59
66
 
60
67
  with_run_context :root do
61
- edit_resource(:template, "/etc/cron.allow") do |new_resource|
68
+ edit_resource(:template, allow_path) do |new_resource|
62
69
  source ::File.expand_path("../support/cron_access.erb", __FILE__)
63
70
  local true
64
71
  mode "0600"
@@ -72,9 +79,10 @@ class Chef
72
79
 
73
80
  action :deny do
74
81
  description "Add the user to the cron.deny file."
82
+ deny_path = ::File.join(value_for_platform_family(CRON_PATHS), "cron.deny")
75
83
 
76
84
  with_run_context :root do
77
- edit_resource(:template, "/etc/cron.deny") do |new_resource|
85
+ edit_resource(:template, deny_path) do |new_resource|
78
86
  source ::File.expand_path("../support/cron_access.erb", __FILE__)
79
87
  local true
80
88
  mode "0600"
@@ -13,6 +13,7 @@
13
13
  #
14
14
 
15
15
  require_relative "../resource"
16
+ require_relative "../dist"
16
17
 
17
18
  class Chef
18
19
  class Resource
@@ -245,7 +246,7 @@ class Chef
245
246
 
246
247
  # reboot because $windows
247
248
  declare_resource(:reboot, "setting hostname") do
248
- reason "chef setting hostname"
249
+ reason "#{Chef::Dist::PRODUCT} updated system hostname"
249
250
  action :nothing
250
251
  only_if { new_resource.windows_reboot }
251
252
  end
@@ -44,6 +44,11 @@ class Chef
44
44
 
45
45
  property :checksum, String, desired_state: false,
46
46
  description: "SHA-256 digest used to verify the checksum of the downloaded MSU package."
47
+
48
+ property :timeout, [String, Integer],
49
+ default: 3600,
50
+ description: "The amount of time (in seconds) to wait before timing out.",
51
+ desired_state: false
47
52
  end
48
53
  end
49
54
  end
@@ -23,7 +23,7 @@ require_relative "version_string"
23
23
 
24
24
  class Chef
25
25
  CHEF_ROOT = File.expand_path("../..", __FILE__)
26
- VERSION = Chef::VersionString.new("15.11.8")
26
+ VERSION = Chef::VersionString.new("15.12.22")
27
27
  end
28
28
 
29
29
  #
@@ -23,6 +23,8 @@ describe Chef::Resource::MsuPackage, :win2012r2_only do
23
23
 
24
24
  let(:package_name) { "Package_for_KB2959977" }
25
25
  let(:package_source) { "https://download.microsoft.com/download/3/B/3/3B320C07-B7B1-41E5-81F4-79EBC02DF7D3/Windows8.1-KB2959977-x64.msu" }
26
+ let(:package_identity) { "Package_for_KB2959977~31bf3856ad364e35~amd64~~6.3.1.1" }
27
+ let(:timeout) { 3600 }
26
28
 
27
29
  let(:new_resource) { Chef::Resource::CabPackage.new("windows_test_pkg") }
28
30
  let(:cab_provider) do
@@ -36,6 +38,7 @@ describe Chef::Resource::MsuPackage, :win2012r2_only do
36
38
  new_resource = Chef::Resource::MsuPackage.new("test msu package", run_context)
37
39
  new_resource.package_name package_name
38
40
  new_resource.source package_source
41
+ new_resource.timeout timeout
39
42
  new_resource
40
43
  end
41
44
 
@@ -44,7 +47,7 @@ describe Chef::Resource::MsuPackage, :win2012r2_only do
44
47
 
45
48
  it "installs the package successfully" do
46
49
  subject.run_action(:install)
47
- found_packages = cab_provider.installed_packages.select { |p| p["package_identity"] =~ /^#{package_name}~/ }
50
+ found_packages = cab_provider.installed_packages.select { |p| p["package_identity"] == package_identity }
48
51
  expect(found_packages.length).to be == 1
49
52
  end
50
53
  end
@@ -53,7 +56,7 @@ describe Chef::Resource::MsuPackage, :win2012r2_only do
53
56
  it "removes an installed package" do
54
57
  subject.run_action(:install)
55
58
  remove_package
56
- found_packages = cab_provider.installed_packages.select { |p| p["package_identity"] =~ /^#{package_name}~/ }
59
+ found_packages = cab_provider.installed_packages.select { |p| p["package_identity"] == package_identity }
57
60
  expect(found_packages.length).to be == 0
58
61
  end
59
62
  end
@@ -513,13 +513,13 @@ describe Chef::Resource::WindowsTask, :windows_only do
513
513
  it "not raises any Argument error if frequency_modifier set as 'first, second, third' and day is provided" do
514
514
  subject.frequency_modifier "first, second, third"
515
515
  subject.day "Mon, Fri"
516
- expect { subject.after_created }.not_to raise_error(ArgumentError)
516
+ expect { subject.after_created }.not_to raise_error
517
517
  end
518
518
 
519
519
  it "not raises any Argument error if frequency_modifier 2 " do
520
520
  subject.frequency_modifier 2
521
521
  subject.day "Mon, Sun"
522
- expect { subject.after_created }.not_to raise_error(ArgumentError)
522
+ expect { subject.after_created }.not_to raise_error
523
523
  end
524
524
 
525
525
  it "raises argument error if frequency_modifier > 12" do
@@ -535,7 +535,7 @@ describe Chef::Resource::WindowsTask, :windows_only do
535
535
  it "creates scheduled task to run task monthly on Monday and Friday of first, second and thrid week of month" do
536
536
  subject.frequency_modifier "first, second, third"
537
537
  subject.day "Mon, Fri"
538
- expect { subject.after_created }.not_to raise_error(ArgumentError)
538
+ expect { subject.after_created }.not_to raise_error
539
539
  call_for_create_action
540
540
  current_resource = call_for_load_current_resource
541
541
  expect(current_resource.exists).to eq(true)
@@ -558,7 +558,7 @@ describe Chef::Resource::WindowsTask, :windows_only do
558
558
  it "creates scheduled task to run task monthly on every 6 months when frequency_modifier is 6 and to run on 1st and 2nd day of month" do
559
559
  subject.frequency_modifier 6
560
560
  subject.day "1, 2"
561
- expect { subject.after_created }.not_to raise_error(ArgumentError)
561
+ expect { subject.after_created }.not_to raise_error
562
562
  call_for_create_action
563
563
  current_resource = call_for_load_current_resource
564
564
  expect(current_resource.exists).to eq(true)
@@ -590,7 +590,7 @@ describe Chef::Resource::WindowsTask, :windows_only do
590
590
 
591
591
  it "creates scheduled task to run monthly to run last day of the month" do
592
592
  subject.day "last"
593
- expect { subject.after_created }.not_to raise_error(ArgumentError)
593
+ expect { subject.after_created }.not_to raise_error
594
594
  call_for_create_action
595
595
  current_resource = call_for_load_current_resource
596
596
  expect(current_resource.exists).to eq(true)
@@ -611,7 +611,7 @@ describe Chef::Resource::WindowsTask, :windows_only do
611
611
 
612
612
  it "day property set as 'lastday' creates scheduled task to run monthly to run last day of the month" do
613
613
  subject.day "lastday"
614
- expect { subject.after_created }.not_to raise_error(ArgumentError)
614
+ expect { subject.after_created }.not_to raise_error
615
615
  call_for_create_action
616
616
  current_resource = call_for_load_current_resource
617
617
  expect(current_resource.exists).to eq(true)
@@ -635,7 +635,7 @@ describe Chef::Resource::WindowsTask, :windows_only do
635
635
  it "creates scheduled task to run monthly on last week of the month" do
636
636
  subject.frequency_modifier "last"
637
637
  subject.day "Mon, Fri"
638
- expect { subject.after_created }.not_to raise_error(ArgumentError)
638
+ expect { subject.after_created }.not_to raise_error
639
639
  call_for_create_action
640
640
  current_resource = call_for_load_current_resource
641
641
  expect(current_resource.exists).to eq(true)
@@ -659,7 +659,7 @@ describe Chef::Resource::WindowsTask, :windows_only do
659
659
  context "when wild card (*) set as months" do
660
660
  it "creates the scheduled task to run on 1st day of the all months" do
661
661
  subject.months "*"
662
- expect { subject.after_created }.not_to raise_error(ArgumentError)
662
+ expect { subject.after_created }.not_to raise_error
663
663
  call_for_create_action
664
664
  current_resource = call_for_load_current_resource
665
665
  expect(current_resource.exists).to eq(true)
@@ -94,6 +94,13 @@ describe Chef::Application do
94
94
  end
95
95
  end
96
96
 
97
+ describe "when enforce_license is set to false" do
98
+ it "should not check the license acceptance" do
99
+ expect(@app).to_not receive(:check_license_acceptance)
100
+ @app.run(enforce_license: false)
101
+ end
102
+ end
103
+
97
104
  it "should run the actual application" do
98
105
  expect(@app).to receive(:run_application).and_return(true)
99
106
  @app.run
@@ -243,7 +243,7 @@ describe Chef::DataBag do
243
243
 
244
244
  expect do
245
245
  Chef::DataBag.load("foo")
246
- end.to raise_error Chef::Exceptions::InvalidDataBagPath, "Data bag path '/var/chef/data_bags' is invalid"
246
+ end.to raise_error Chef::Exceptions::InvalidDataBagPath, "Data bag path '/var/chef/data_bags' not found. Please create this directory."
247
247
  end
248
248
 
249
249
  end
@@ -1747,8 +1747,8 @@ describe Chef::Knife::Bootstrap do
1747
1747
  allow(vault_handler_mock).to receive(:doing_chef_vault?).and_return false
1748
1748
  end
1749
1749
 
1750
- it "shows a message" do
1751
- expect(knife.ui).to receive(:info)
1750
+ it "shows a warning message" do
1751
+ expect(knife.ui).to receive(:warn).twice
1752
1752
  knife.register_client
1753
1753
  end
1754
1754
  end
@@ -77,17 +77,9 @@ describe "a class that mixes in user_context" do
77
77
  end
78
78
 
79
79
  context "when the block raises an exception" do
80
- class UserContextTestException < RuntimeError
81
- end
82
- let(:block_parameter) { Proc.new { raise UserContextTextException } }
83
-
84
- it "raises the exception raised by the block" do
85
- expect { instance_with_user_context.with_context("kamilah", nil, "chef4life", &block_parameter) }.not_to raise_error(UserContextTestException)
86
- end
87
-
88
80
  it "closes the logon session so resources are not leaked" do
89
81
  expect(logon_session).to receive(:close)
90
- expect { instance_with_user_context.with_context("kamilah", nil, "chef4life", &block_parameter) }.not_to raise_error(UserContextTestException)
82
+ expect { instance_with_user_context.with_context("kamilah", nil, "chef4life") { 1 / 0 } }.to raise_error(ZeroDivisionError)
91
83
  end
92
84
  end
93
85
  end
@@ -121,7 +121,7 @@ describe "Chef::Resource.property" do
121
121
 
122
122
  context "deprecated properties" do
123
123
  it "does not create a deprecation warning on definition" do
124
- expect { resource_class.class_eval { property :x, String, deprecated: 10 } }.not_to raise_error Chef::Exceptions::DeprecatedFeatureError
124
+ expect { resource_class.class_eval { property :x, String, deprecated: 10 } }.not_to raise_error
125
125
  end
126
126
 
127
127
  with_property ":x, deprecated: 'a deprecated property'" do
@@ -93,19 +93,19 @@ describe Chef::Provider::Package::Powershell do
93
93
  double("powershell_out", stdout: "5")
94
94
  end
95
95
 
96
- let(:generated_command) { "( Get-Package posh-git -Force -ForceBootstrap ).Version" }
97
- let(:generated_get_cmdlet) { "( Get-Package xNetworking -Force -ForceBootstrap ).Version" }
98
- let(:generated_get_cmdlet_with_version) { "( Get-Package xNetworking -Force -ForceBootstrap -RequiredVersion 1.0.0.0 ).Version" }
99
- let(:generated_find_cmdlet) { "( Find-Package xNetworking -Force -ForceBootstrap ).Version" }
100
- let(:generated_find_cmdlet_with_version) { "( Find-Package xNetworking -Force -ForceBootstrap -RequiredVersion 1.0.0.0 ).Version" }
101
- let(:generated_find_cmdlet_with_source) { "( Find-Package xNetworking -Force -ForceBootstrap -Source MyGallery ).Version" }
102
- let(:generated_find_cmdlet_with_source_and_version) { "( Find-Package xNetworking -Force -ForceBootstrap -RequiredVersion 1.0.0.0 -Source MyGallery ).Version" }
103
- let(:generated_install_cmdlet) { "( Install-Package xNetworking -Force -ForceBootstrap ).Version" }
104
- let(:generated_install_cmdlet_with_version) { "( Install-Package xNetworking -Force -ForceBootstrap -RequiredVersion 1.0.0.0 ).Version" }
105
- let(:generated_install_cmdlet_with_source) { "( Install-Package xNetworking -Force -ForceBootstrap -Source MyGallery ).Version" }
106
- let(:generated_install_cmdlet_with_source_and_version) { "( Install-Package xNetworking -Force -ForceBootstrap -RequiredVersion 1.0.0.0 -Source MyGallery ).Version" }
107
- let(:generated_uninstall_cmdlet) { "( Uninstall-Package xNetworking -Force -ForceBootstrap ).Version" }
108
- let(:generated_uninstall_cmdlet_with_version) { "( Uninstall-Package xNetworking -Force -ForceBootstrap -RequiredVersion 1.0.0.0 ).Version" }
96
+ let(:generated_command) { "( Get-Package posh-git -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version" }
97
+ let(:generated_get_cmdlet) { "( Get-Package xNetworking -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version" }
98
+ let(:generated_get_cmdlet_with_version) { "( Get-Package xNetworking -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 1.0.0.0 ).Version" }
99
+ let(:generated_find_cmdlet) { "( Find-Package xNetworking -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version" }
100
+ let(:generated_find_cmdlet_with_version) { "( Find-Package xNetworking -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 1.0.0.0 ).Version" }
101
+ let(:generated_find_cmdlet_with_source) { "( Find-Package xNetworking -Force -ForceBootstrap -WarningAction SilentlyContinue -Source MyGallery ).Version" }
102
+ let(:generated_find_cmdlet_with_source_and_version) { "( Find-Package xNetworking -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 1.0.0.0 -Source MyGallery ).Version" }
103
+ let(:generated_install_cmdlet) { "( Install-Package xNetworking -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version" }
104
+ let(:generated_install_cmdlet_with_version) { "( Install-Package xNetworking -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 1.0.0.0 ).Version" }
105
+ let(:generated_install_cmdlet_with_source) { "( Install-Package xNetworking -Force -ForceBootstrap -WarningAction SilentlyContinue -Source MyGallery ).Version" }
106
+ let(:generated_install_cmdlet_with_source_and_version) { "( Install-Package xNetworking -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 1.0.0.0 -Source MyGallery ).Version" }
107
+ let(:generated_uninstall_cmdlet) { "( Uninstall-Package xNetworking -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version" }
108
+ let(:generated_uninstall_cmdlet_with_version) { "( Uninstall-Package xNetworking -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 1.0.0.0 ).Version" }
109
109
 
110
110
  describe "#initialize" do
111
111
  it "should return the correct class" do
@@ -116,14 +116,14 @@ describe Chef::Provider::Package::Powershell do
116
116
  describe "#candidate_version" do
117
117
 
118
118
  it "should set the candidate_version to the latest version when not pinning" do
119
- allow(provider).to receive(:powershell_out).with("( Find-Package 'xNetworking' -Force -ForceBootstrap ).Version", { timeout: new_resource.timeout }).and_return(package_xnetworking_available)
119
+ allow(provider).to receive(:powershell_out).with("( Find-Package 'xNetworking' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xnetworking_available)
120
120
  new_resource.package_name(["xNetworking"])
121
121
  new_resource.version(nil)
122
122
  expect(provider.candidate_version).to eql(["2.12.0.0"])
123
123
  end
124
124
 
125
125
  it "should use the candidate_version from the correct source" do
126
- allow(provider).to receive(:powershell_out).with("( Find-Package 'xNetworking' -Force -ForceBootstrap -Source MyGallery ).Version", { timeout: new_resource.timeout }).and_return(package_xnetworking_available)
126
+ allow(provider).to receive(:powershell_out).with("( Find-Package 'xNetworking' -Force -ForceBootstrap -WarningAction SilentlyContinue -Source MyGallery ).Version", { timeout: new_resource.timeout }).and_return(package_xnetworking_available)
127
127
  new_resource.package_name(["xNetworking"])
128
128
  new_resource.version(nil)
129
129
  new_resource.source("MyGallery")
@@ -131,60 +131,60 @@ describe Chef::Provider::Package::Powershell do
131
131
  end
132
132
 
133
133
  it "should set the candidate_version to the latest version when not pinning and package name is space seperated" do
134
- allow(provider).to receive(:powershell_out).with("( Find-Package '7-Zip 16.02 (x64)' -Force -ForceBootstrap ).Version", { timeout: new_resource.timeout }).and_return(package_7zip_available)
134
+ allow(provider).to receive(:powershell_out).with("( Find-Package '7-Zip 16.02 (x64)' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_7zip_available)
135
135
  new_resource.package_name(["7-Zip 16.02 (x64)"])
136
136
  new_resource.version(nil)
137
137
  expect(provider.candidate_version).to eql(["16.02"])
138
138
  end
139
139
 
140
140
  it "should set the candidate_version to pinned version if available" do
141
- allow(provider).to receive(:powershell_out).with("( Find-Package 'xCertificate' -Force -ForceBootstrap -RequiredVersion 2.0.0.0 ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available_2_0_0_0)
141
+ allow(provider).to receive(:powershell_out).with("( Find-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.0.0.0 ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available_2_0_0_0)
142
142
  new_resource.package_name(["xCertificate"])
143
143
  new_resource.version(["2.0.0.0"])
144
144
  expect(provider.candidate_version).to eql(["2.0.0.0"])
145
145
  end
146
146
 
147
147
  it "should set the candidate_version to nil if there is no candidate" do
148
- allow(provider).to receive(:powershell_out).with("( Find-Package 'xCertificate' -Force -ForceBootstrap ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_not_available)
148
+ allow(provider).to receive(:powershell_out).with("( Find-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_not_available)
149
149
  new_resource.package_name(["xCertificate"])
150
150
  expect(provider.candidate_version).to eql([nil])
151
151
  end
152
152
 
153
153
  it "should set the candidate_version correctly when there are two packages to install" do
154
- allow(provider).to receive(:powershell_out).with("( Find-Package 'xCertificate' -Force -ForceBootstrap ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
155
- allow(provider).to receive(:powershell_out).with("( Find-Package 'xNetworking' -Force -ForceBootstrap ).Version", { timeout: new_resource.timeout }).and_return(package_xnetworking_available)
154
+ allow(provider).to receive(:powershell_out).with("( Find-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
155
+ allow(provider).to receive(:powershell_out).with("( Find-Package 'xNetworking' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xnetworking_available)
156
156
  new_resource.package_name(%w{xCertificate xNetworking})
157
157
  new_resource.version(nil)
158
158
  expect(provider.candidate_version).to eql(["2.1.0.0", "2.12.0.0"])
159
159
  end
160
160
 
161
161
  it "should set the candidate_version correctly when only the first is installable" do
162
- allow(provider).to receive(:powershell_out).with("( Find-Package 'xCertificate' -Force -ForceBootstrap ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
163
- allow(provider).to receive(:powershell_out).with("( Find-Package 'xNetworking' -Force -ForceBootstrap ).Version", { timeout: new_resource.timeout }).and_return(package_xnetworking_not_available)
162
+ allow(provider).to receive(:powershell_out).with("( Find-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
163
+ allow(provider).to receive(:powershell_out).with("( Find-Package 'xNetworking' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xnetworking_not_available)
164
164
  new_resource.package_name(%w{xCertificate xNetworking})
165
165
  new_resource.version(nil)
166
166
  expect(provider.candidate_version).to eql(["2.1.0.0", nil])
167
167
  end
168
168
 
169
169
  it "should set the candidate_version correctly when only the last is installable" do
170
- allow(provider).to receive(:powershell_out).with("( Find-Package 'xCertificate' -Force -ForceBootstrap ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_not_available)
171
- allow(provider).to receive(:powershell_out).with("( Find-Package 'xNetworking' -Force -ForceBootstrap ).Version", { timeout: new_resource.timeout }).and_return(package_xnetworking_available)
170
+ allow(provider).to receive(:powershell_out).with("( Find-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_not_available)
171
+ allow(provider).to receive(:powershell_out).with("( Find-Package 'xNetworking' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xnetworking_available)
172
172
  new_resource.package_name(%w{xCertificate xNetworking})
173
173
  new_resource.version(nil)
174
174
  expect(provider.candidate_version).to eql([nil, "2.12.0.0"])
175
175
  end
176
176
 
177
177
  it "should set the candidate_version correctly when neither are is installable and version is passed as nil array" do
178
- allow(provider).to receive(:powershell_out).with("( Find-Package 'xCertificate' -Force -ForceBootstrap ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_not_available)
179
- allow(provider).to receive(:powershell_out).with("( Find-Package 'xNetworking' -Force -ForceBootstrap ).Version", { timeout: new_resource.timeout }).and_return(package_xnetworking_not_available)
178
+ allow(provider).to receive(:powershell_out).with("( Find-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_not_available)
179
+ allow(provider).to receive(:powershell_out).with("( Find-Package 'xNetworking' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xnetworking_not_available)
180
180
  new_resource.package_name(%w{xNetworking xCertificate})
181
181
  new_resource.version([nil, nil])
182
182
  expect(provider.candidate_version).to eql([nil, nil])
183
183
  end
184
184
 
185
185
  it "should set the candidate_version correctly when neither are is installable and version is not passed" do
186
- allow(provider).to receive(:powershell_out).with("( Find-Package 'xCertificate' -Force -ForceBootstrap ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_not_available)
187
- allow(provider).to receive(:powershell_out).with("( Find-Package 'xNetworking' -Force -ForceBootstrap ).Version", { timeout: new_resource.timeout }).and_return(package_xnetworking_not_available)
186
+ allow(provider).to receive(:powershell_out).with("( Find-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_not_available)
187
+ allow(provider).to receive(:powershell_out).with("( Find-Package 'xNetworking' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xnetworking_not_available)
188
188
  new_resource.package_name(%w{xNetworking xCertificate})
189
189
  new_resource.version(nil)
190
190
  expect(provider.candidate_version).to eql([nil, nil])
@@ -283,10 +283,11 @@ describe Chef::Provider::Package::Powershell do
283
283
  provider.load_current_resource
284
284
  new_resource.package_name(["xCertificate"])
285
285
  new_resource.version(nil)
286
- allow(provider).to receive(:powershell_out).with("( Find-Package 'xCertificate' -Force -ForceBootstrap ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
287
- allow(provider).to receive(:powershell_out).with("( Get-Package 'xCertificate' -Force -ForceBootstrap ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_not_available)
286
+ allow(provider).to receive(:powershell_out).with("( Find-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
287
+ allow(provider).to receive(:powershell_out).with("( Get-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_not_available)
288
288
  allow(provider).to receive(:powershell_out).with("$PSVersionTable.PSVersion.Major").and_return(powershell_installed_version)
289
- expect(provider).to receive(:powershell_out).with("( Install-Package 'xCertificate' -Force -ForceBootstrap -RequiredVersion 2.1.0.0 ).Version", { timeout: new_resource.timeout })
289
+ allow(provider).to receive(:powershell_out).with("[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12")
290
+ expect(provider).to receive(:powershell_out).with("( Install-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.1.0.0 ).Version", { timeout: new_resource.timeout })
290
291
  provider.run_action(:install)
291
292
  expect(new_resource).to be_updated_by_last_action
292
293
  end
@@ -296,10 +297,11 @@ describe Chef::Provider::Package::Powershell do
296
297
  new_resource.package_name(["xCertificate"])
297
298
  new_resource.version(nil)
298
299
  new_resource.source("MyGallery")
299
- allow(provider).to receive(:powershell_out).with("( Find-Package 'xCertificate' -Force -ForceBootstrap -Source MyGallery ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
300
- allow(provider).to receive(:powershell_out).with("( Get-Package 'xCertificate' -Force -ForceBootstrap ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_not_available)
300
+ allow(provider).to receive(:powershell_out).with("( Find-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue -Source MyGallery ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
301
+ allow(provider).to receive(:powershell_out).with("( Get-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_not_available)
301
302
  allow(provider).to receive(:powershell_out).with("$PSVersionTable.PSVersion.Major").and_return(powershell_installed_version)
302
- expect(provider).to receive(:powershell_out).with("( Install-Package 'xCertificate' -Force -ForceBootstrap -RequiredVersion 2.1.0.0 -Source MyGallery ).Version", { timeout: new_resource.timeout })
303
+ allow(provider).to receive(:powershell_out).with("[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12")
304
+ expect(provider).to receive(:powershell_out).with("( Install-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.1.0.0 -Source MyGallery ).Version", { timeout: new_resource.timeout })
303
305
  provider.run_action(:install)
304
306
  expect(new_resource).to be_updated_by_last_action
305
307
  end
@@ -309,10 +311,11 @@ describe Chef::Provider::Package::Powershell do
309
311
  new_resource.package_name(["xCertificate"])
310
312
  new_resource.version(nil)
311
313
  new_resource.skip_publisher_check(true)
312
- allow(provider).to receive(:powershell_out).with("( Find-Package 'xCertificate' -Force -ForceBootstrap ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
313
- allow(provider).to receive(:powershell_out).with("( Get-Package 'xCertificate' -Force -ForceBootstrap -SkipPublisherCheck ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_not_available)
314
+ allow(provider).to receive(:powershell_out).with("( Find-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
315
+ allow(provider).to receive(:powershell_out).with("( Get-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue -SkipPublisherCheck ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_not_available)
314
316
  allow(provider).to receive(:powershell_out).with("$PSVersionTable.PSVersion.Major").and_return(powershell_installed_version)
315
- expect(provider).to receive(:powershell_out).with("( Install-Package 'xCertificate' -Force -ForceBootstrap -RequiredVersion 2.1.0.0 -SkipPublisherCheck ).Version", { timeout: new_resource.timeout })
317
+ allow(provider).to receive(:powershell_out).with("[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12")
318
+ expect(provider).to receive(:powershell_out).with("( Install-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.1.0.0 -SkipPublisherCheck ).Version", { timeout: new_resource.timeout })
316
319
  provider.run_action(:install)
317
320
  expect(new_resource).to be_updated_by_last_action
318
321
  end
@@ -321,10 +324,11 @@ describe Chef::Provider::Package::Powershell do
321
324
  provider.load_current_resource
322
325
  new_resource.package_name(["7-Zip 16.02 (x64)"])
323
326
  new_resource.version(nil)
324
- allow(provider).to receive(:powershell_out).with("( Find-Package '7-Zip 16.02 (x64)' -Force -ForceBootstrap ).Version", { timeout: new_resource.timeout }).and_return(package_7zip_available)
325
- allow(provider).to receive(:powershell_out).with("( Get-Package '7-Zip 16.02 (x64)' -Force -ForceBootstrap ).Version", { timeout: new_resource.timeout }).and_return(package_7zip_not_installed)
327
+ allow(provider).to receive(:powershell_out).with("( Find-Package '7-Zip 16.02 (x64)' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_7zip_available)
328
+ allow(provider).to receive(:powershell_out).with("( Get-Package '7-Zip 16.02 (x64)' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_7zip_not_installed)
326
329
  allow(provider).to receive(:powershell_out).with("$PSVersionTable.PSVersion.Major").and_return(powershell_installed_version)
327
- expect(provider).to receive(:powershell_out).with("( Install-Package '7-Zip 16.02 (x64)' -Force -ForceBootstrap -RequiredVersion 16.02 ).Version", { timeout: new_resource.timeout })
330
+ allow(provider).to receive(:powershell_out).with("[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12")
331
+ expect(provider).to receive(:powershell_out).with("( Install-Package '7-Zip 16.02 (x64)' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 16.02 ).Version", { timeout: new_resource.timeout })
328
332
  provider.run_action(:install)
329
333
  expect(new_resource).to be_updated_by_last_action
330
334
  end
@@ -336,10 +340,11 @@ describe Chef::Provider::Package::Powershell do
336
340
  provider.load_current_resource
337
341
  new_resource.package_name(["xCertificate"])
338
342
  new_resource.version(nil)
339
- allow(provider).to receive(:powershell_out).with("( Find-Package 'xCertificate' -Force -ForceBootstrap ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
340
- allow(provider).to receive(:powershell_out).with("( Get-Package 'xCertificate' -Force -ForceBootstrap ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_not_available)
343
+ allow(provider).to receive(:powershell_out).with("( Find-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
344
+ allow(provider).to receive(:powershell_out).with("( Get-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_not_available)
341
345
  allow(provider).to receive(:powershell_out).with("$PSVersionTable.PSVersion.Major").and_return(powershell_installed_version)
342
- expect(provider).to receive(:powershell_out).with("( Install-Package 'xCertificate' -Force -ForceBootstrap -RequiredVersion 2.1.0.0 ).Version", { timeout: new_resource.timeout })
346
+ allow(provider).to receive(:powershell_out).with("[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12")
347
+ expect(provider).to receive(:powershell_out).with("( Install-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.1.0.0 ).Version", { timeout: new_resource.timeout })
343
348
  provider.run_action(:install)
344
349
  expect(new_resource).to be_updated_by_last_action
345
350
  end
@@ -348,8 +353,8 @@ describe Chef::Provider::Package::Powershell do
348
353
  it "should not install packages that are up-to-date" do
349
354
  new_resource.package_name(["xCertificate"])
350
355
  new_resource.version(nil)
351
- allow(provider).to receive(:powershell_out).with("( Find-Package 'xCertificate' -Force -ForceBootstrap ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
352
- allow(provider).to receive(:powershell_out).with("( Get-Package 'xCertificate' -Force -ForceBootstrap ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
356
+ allow(provider).to receive(:powershell_out).with("( Find-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
357
+ allow(provider).to receive(:powershell_out).with("( Get-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
353
358
  allow(provider).to receive(:powershell_out).with("$PSVersionTable.PSVersion.Major").and_return(powershell_installed_version)
354
359
  provider.load_current_resource
355
360
  expect(provider).not_to receive(:install_package)
@@ -360,8 +365,8 @@ describe Chef::Provider::Package::Powershell do
360
365
  it "should not install packages that are up-to-date" do
361
366
  new_resource.package_name(["xNetworking"])
362
367
  new_resource.version(["2.11.0.0"])
363
- allow(provider).to receive(:powershell_out).with("( Find-Package 'xNetworking' -Force -ForceBootstrap -RequiredVersion 2.11.0.0 ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
364
- allow(provider).to receive(:powershell_out).with("( Get-Package 'xNetworking' -Force -ForceBootstrap -RequiredVersion 2.11.0.0 ).Version", { timeout: new_resource.timeout }).and_return(package_xnetworking_available_2_11_0_0)
368
+ allow(provider).to receive(:powershell_out).with("( Find-Package 'xNetworking' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.11.0.0 ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
369
+ allow(provider).to receive(:powershell_out).with("( Get-Package 'xNetworking' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.11.0.0 ).Version", { timeout: new_resource.timeout }).and_return(package_xnetworking_available_2_11_0_0)
365
370
  allow(provider).to receive(:powershell_out).with("$PSVersionTable.PSVersion.Major").and_return(powershell_installed_version)
366
371
  provider.load_current_resource
367
372
  expect(provider).not_to receive(:install_package)
@@ -374,13 +379,14 @@ describe Chef::Provider::Package::Powershell do
374
379
  # new_version.resource[0]
375
380
  new_resource.package_name(%w{xCertificate xNetworking})
376
381
  new_resource.version([nil, "2.11.0.0"])
377
- allow(provider).to receive(:powershell_out).with("( Find-Package 'xCertificate' -Force -ForceBootstrap ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
378
- allow(provider).to receive(:powershell_out).with("( Get-Package 'xCertificate' -Force -ForceBootstrap ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_not_available)
379
- allow(provider).to receive(:powershell_out).with("( Find-Package 'xNetworking' -Force -ForceBootstrap -RequiredVersion 2.11.0.0 ).Version", { timeout: new_resource.timeout }).and_return(package_xnetworking_available_2_11_0_0)
380
- allow(provider).to receive(:powershell_out).with("( Get-Package 'xNetworking' -Force -ForceBootstrap -RequiredVersion 2.11.0.0 ).Version", { timeout: new_resource.timeout }).and_return(package_xnetworking_not_available)
382
+ allow(provider).to receive(:powershell_out).with("( Find-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
383
+ allow(provider).to receive(:powershell_out).with("( Get-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_not_available)
384
+ allow(provider).to receive(:powershell_out).with("( Find-Package 'xNetworking' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.11.0.0 ).Version", { timeout: new_resource.timeout }).and_return(package_xnetworking_available_2_11_0_0)
385
+ allow(provider).to receive(:powershell_out).with("( Get-Package 'xNetworking' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.11.0.0 ).Version", { timeout: new_resource.timeout }).and_return(package_xnetworking_not_available)
381
386
  allow(provider).to receive(:powershell_out).with("$PSVersionTable.PSVersion.Major").and_return(powershell_installed_version)
382
- expect(provider).to receive(:powershell_out).with("( Install-Package 'xCertificate' -Force -ForceBootstrap -RequiredVersion 2.1.0.0 ).Version", { timeout: new_resource.timeout })
383
- expect(provider).to receive(:powershell_out).with("( Install-Package 'xNetworking' -Force -ForceBootstrap -RequiredVersion 2.11.0.0 ).Version", { timeout: new_resource.timeout })
387
+ allow(provider).to receive(:powershell_out).with("[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12")
388
+ expect(provider).to receive(:powershell_out).with("( Install-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.1.0.0 ).Version", { timeout: new_resource.timeout })
389
+ expect(provider).to receive(:powershell_out).with("( Install-Package 'xNetworking' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.11.0.0 ).Version", { timeout: new_resource.timeout })
384
390
  provider.load_current_resource
385
391
  provider.run_action(:install)
386
392
  expect(new_resource).to be_updated_by_last_action
@@ -389,13 +395,14 @@ describe Chef::Provider::Package::Powershell do
389
395
  it "should split up commands when given two packages, one with a version pin" do
390
396
  new_resource.package_name(%w{xCertificate xNetworking})
391
397
  new_resource.version(["2.1.0.0", nil])
392
- allow(provider).to receive(:powershell_out).with("( Find-Package 'xCertificate' -Force -ForceBootstrap -RequiredVersion 2.1.0.0 ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
393
- allow(provider).to receive(:powershell_out).with("( Get-Package 'xCertificate' -Force -ForceBootstrap -RequiredVersion 2.1.0.0 ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_not_available)
394
- allow(provider).to receive(:powershell_out).with("( Find-Package 'xNetworking' -Force -ForceBootstrap ).Version", { timeout: new_resource.timeout }).and_return(package_xnetworking_available)
395
- allow(provider).to receive(:powershell_out).with("( Get-Package 'xNetworking' -Force -ForceBootstrap ).Version", { timeout: new_resource.timeout }).and_return(package_xnetworking_not_available)
398
+ allow(provider).to receive(:powershell_out).with("( Find-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.1.0.0 ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
399
+ allow(provider).to receive(:powershell_out).with("( Get-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.1.0.0 ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_not_available)
400
+ allow(provider).to receive(:powershell_out).with("( Find-Package 'xNetworking' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xnetworking_available)
401
+ allow(provider).to receive(:powershell_out).with("( Get-Package 'xNetworking' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xnetworking_not_available)
396
402
  allow(provider).to receive(:powershell_out).with("$PSVersionTable.PSVersion.Major").and_return(powershell_installed_version)
397
- expect(provider).to receive(:powershell_out).with("( Install-Package 'xCertificate' -Force -ForceBootstrap -RequiredVersion 2.1.0.0 ).Version", { timeout: new_resource.timeout })
398
- expect(provider).to receive(:powershell_out).with("( Install-Package 'xNetworking' -Force -ForceBootstrap -RequiredVersion 2.12.0.0 ).Version", { timeout: new_resource.timeout })
403
+ allow(provider).to receive(:powershell_out).with("[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12")
404
+ expect(provider).to receive(:powershell_out).with("( Install-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.1.0.0 ).Version", { timeout: new_resource.timeout })
405
+ expect(provider).to receive(:powershell_out).with("( Install-Package 'xNetworking' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.12.0.0 ).Version", { timeout: new_resource.timeout })
399
406
 
400
407
  provider.load_current_resource
401
408
  provider.run_action(:install)
@@ -405,13 +412,14 @@ describe Chef::Provider::Package::Powershell do
405
412
  it "should do multipackage installs when given two packages without constraints" do
406
413
  new_resource.package_name(%w{xCertificate xNetworking})
407
414
  new_resource.version(nil)
408
- allow(provider).to receive(:powershell_out).with("( Find-Package 'xCertificate' -Force -ForceBootstrap ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
409
- allow(provider).to receive(:powershell_out).with("( Get-Package 'xCertificate' -Force -ForceBootstrap ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_not_available)
410
- allow(provider).to receive(:powershell_out).with("( Find-Package 'xNetworking' -Force -ForceBootstrap ).Version", { timeout: new_resource.timeout }).and_return(package_xnetworking_available)
411
- allow(provider).to receive(:powershell_out).with("( Get-Package 'xNetworking' -Force -ForceBootstrap ).Version", { timeout: new_resource.timeout }).and_return(package_xnetworking_not_available)
415
+ allow(provider).to receive(:powershell_out).with("( Find-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
416
+ allow(provider).to receive(:powershell_out).with("( Get-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_not_available)
417
+ allow(provider).to receive(:powershell_out).with("( Find-Package 'xNetworking' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xnetworking_available)
418
+ allow(provider).to receive(:powershell_out).with("( Get-Package 'xNetworking' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xnetworking_not_available)
412
419
  allow(provider).to receive(:powershell_out).with("$PSVersionTable.PSVersion.Major").and_return(powershell_installed_version)
413
- expect(provider).to receive(:powershell_out).with("( Install-Package 'xCertificate' -Force -ForceBootstrap -RequiredVersion 2.1.0.0 ).Version", { timeout: new_resource.timeout })
414
- expect(provider).to receive(:powershell_out).with("( Install-Package 'xNetworking' -Force -ForceBootstrap -RequiredVersion 2.12.0.0 ).Version", { timeout: new_resource.timeout })
420
+ allow(provider).to receive(:powershell_out).with("[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12")
421
+ expect(provider).to receive(:powershell_out).with("( Install-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.1.0.0 ).Version", { timeout: new_resource.timeout })
422
+ expect(provider).to receive(:powershell_out).with("( Install-Package 'xNetworking' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.12.0.0 ).Version", { timeout: new_resource.timeout })
415
423
  provider.load_current_resource
416
424
  provider.run_action(:install)
417
425
  expect(new_resource).to be_updated_by_last_action
@@ -421,13 +429,14 @@ describe Chef::Provider::Package::Powershell do
421
429
  new_resource.package_name(%w{xCertificate xNetworking})
422
430
  new_resource.version(nil)
423
431
  new_resource.source("MyGallery")
424
- allow(provider).to receive(:powershell_out).with("( Find-Package 'xCertificate' -Force -ForceBootstrap -Source MyGallery ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
425
- allow(provider).to receive(:powershell_out).with("( Get-Package 'xCertificate' -Force -ForceBootstrap ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_not_available)
426
- allow(provider).to receive(:powershell_out).with("( Find-Package 'xNetworking' -Force -ForceBootstrap -Source MyGallery ).Version", { timeout: new_resource.timeout }).and_return(package_xnetworking_available)
427
- allow(provider).to receive(:powershell_out).with("( Get-Package 'xNetworking' -Force -ForceBootstrap ).Version", { timeout: new_resource.timeout }).and_return(package_xnetworking_not_available)
432
+ allow(provider).to receive(:powershell_out).with("( Find-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue -Source MyGallery ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
433
+ allow(provider).to receive(:powershell_out).with("( Get-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_not_available)
434
+ allow(provider).to receive(:powershell_out).with("( Find-Package 'xNetworking' -Force -ForceBootstrap -WarningAction SilentlyContinue -Source MyGallery ).Version", { timeout: new_resource.timeout }).and_return(package_xnetworking_available)
435
+ allow(provider).to receive(:powershell_out).with("( Get-Package 'xNetworking' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xnetworking_not_available)
428
436
  allow(provider).to receive(:powershell_out).with("$PSVersionTable.PSVersion.Major").and_return(powershell_installed_version)
429
- expect(provider).to receive(:powershell_out).with("( Install-Package 'xCertificate' -Force -ForceBootstrap -RequiredVersion 2.1.0.0 -Source MyGallery ).Version", { timeout: new_resource.timeout })
430
- expect(provider).to receive(:powershell_out).with("( Install-Package 'xNetworking' -Force -ForceBootstrap -RequiredVersion 2.12.0.0 -Source MyGallery ).Version", { timeout: new_resource.timeout })
437
+ allow(provider).to receive(:powershell_out).with("[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12")
438
+ expect(provider).to receive(:powershell_out).with("( Install-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.1.0.0 -Source MyGallery ).Version", { timeout: new_resource.timeout })
439
+ expect(provider).to receive(:powershell_out).with("( Install-Package 'xNetworking' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.12.0.0 -Source MyGallery ).Version", { timeout: new_resource.timeout })
431
440
  provider.load_current_resource
432
441
  provider.run_action(:install)
433
442
  expect(new_resource).to be_updated_by_last_action
@@ -439,8 +448,8 @@ describe Chef::Provider::Package::Powershell do
439
448
  provider.load_current_resource
440
449
  new_resource.package_name(["xCertificate"])
441
450
  new_resource.version(["2.1.0.0"])
442
- allow(provider).to receive(:powershell_out).with("( Find-Package 'xCertificate' -Force -ForceBootstrap -RequiredVersion 2.1.0.0 ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
443
- allow(provider).to receive(:powershell_out).with("( Get-Package 'xCertificate' -Force -ForceBootstrap -RequiredVersion 2.1.0.0 ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_not_available)
451
+ allow(provider).to receive(:powershell_out).with("( Find-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.1.0.0 ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
452
+ allow(provider).to receive(:powershell_out).with("( Get-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.1.0.0 ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_not_available)
444
453
  allow(provider).to receive(:powershell_out).with("$PSVersionTable.PSVersion.Major").and_return(powershell_installed_version)
445
454
  expect(provider).not_to receive(:remove_package)
446
455
  provider.run_action(:remove)
@@ -451,11 +460,11 @@ describe Chef::Provider::Package::Powershell do
451
460
  new_resource.package_name(["xCertificate"])
452
461
  new_resource.version(["2.1.0.0"])
453
462
  new_resource.source("MyGallery")
454
- allow(provider).to receive(:powershell_out).with("( Find-Package 'xCertificate' -Force -ForceBootstrap -RequiredVersion 2.1.0.0 -Source MyGallery).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
455
- allow(provider).to receive(:powershell_out).with("( Get-Package 'xCertificate' -Force -ForceBootstrap -RequiredVersion 2.1.0.0 ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
463
+ allow(provider).to receive(:powershell_out).with("( Find-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.1.0.0 -Source MyGallery).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
464
+ allow(provider).to receive(:powershell_out).with("( Get-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.1.0.0 ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
456
465
  allow(provider).to receive(:powershell_out).with("$PSVersionTable.PSVersion.Major").and_return(powershell_installed_version)
457
466
  provider.load_current_resource
458
- expect(provider).to receive(:powershell_out).with("( Uninstall-Package 'xCertificate' -Force -ForceBootstrap -RequiredVersion 2.1.0.0 ).Version", { timeout: new_resource.timeout })
467
+ expect(provider).to receive(:powershell_out).with("( Uninstall-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.1.0.0 ).Version", { timeout: new_resource.timeout })
459
468
  provider.run_action(:remove)
460
469
  expect(new_resource).to be_updated_by_last_action
461
470
  end
@@ -463,10 +472,10 @@ describe Chef::Provider::Package::Powershell do
463
472
  it "does nothing when all the packages are already removed" do
464
473
  new_resource.package_name(%w{xCertificate xNetworking})
465
474
  new_resource.version(nil)
466
- allow(provider).to receive(:powershell_out).with("( Find-Package 'xCertificate' -Force -ForceBootstrap ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
467
- allow(provider).to receive(:powershell_out).with("( Get-Package 'xCertificate' -Force -ForceBootstrap ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_not_available)
468
- allow(provider).to receive(:powershell_out).with("( Find-Package 'xNetworking' -Force -ForceBootstrap ).Version", { timeout: new_resource.timeout }).and_return(package_xnetworking_available)
469
- allow(provider).to receive(:powershell_out).with("( Get-Package 'xNetworking' -Force -ForceBootstrap ).Version", { timeout: new_resource.timeout }).and_return(package_xnetworking_not_available)
475
+ allow(provider).to receive(:powershell_out).with("( Find-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
476
+ allow(provider).to receive(:powershell_out).with("( Get-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_not_available)
477
+ allow(provider).to receive(:powershell_out).with("( Find-Package 'xNetworking' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xnetworking_available)
478
+ allow(provider).to receive(:powershell_out).with("( Get-Package 'xNetworking' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xnetworking_not_available)
470
479
  allow(provider).to receive(:powershell_out).with("$PSVersionTable.PSVersion.Major").and_return(powershell_installed_version)
471
480
  provider.load_current_resource
472
481
  expect(provider).not_to receive(:remove_package)
@@ -477,11 +486,11 @@ describe Chef::Provider::Package::Powershell do
477
486
  it "removes a package when version is specified" do
478
487
  new_resource.package_name(["xCertificate"])
479
488
  new_resource.version(["2.1.0.0"])
480
- allow(provider).to receive(:powershell_out).with("( Find-Package 'xCertificate' -Force -ForceBootstrap -RequiredVersion 2.1.0.0 ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
481
- allow(provider).to receive(:powershell_out).with("( Get-Package 'xCertificate' -Force -ForceBootstrap -RequiredVersion 2.1.0.0 ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
489
+ allow(provider).to receive(:powershell_out).with("( Find-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.1.0.0 ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
490
+ allow(provider).to receive(:powershell_out).with("( Get-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.1.0.0 ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
482
491
  allow(provider).to receive(:powershell_out).with("$PSVersionTable.PSVersion.Major").and_return(powershell_installed_version)
483
492
  provider.load_current_resource
484
- expect(provider).to receive(:powershell_out).with("( Uninstall-Package 'xCertificate' -Force -ForceBootstrap -RequiredVersion 2.1.0.0 ).Version", { timeout: new_resource.timeout })
493
+ expect(provider).to receive(:powershell_out).with("( Uninstall-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.1.0.0 ).Version", { timeout: new_resource.timeout })
485
494
  provider.run_action(:remove)
486
495
  expect(new_resource).to be_updated_by_last_action
487
496
  end
@@ -489,11 +498,11 @@ describe Chef::Provider::Package::Powershell do
489
498
  it "removes a package when version is not specified" do
490
499
  new_resource.package_name(["xCertificate"])
491
500
  new_resource.version(nil)
492
- allow(provider).to receive(:powershell_out).with("( Find-Package 'xCertificate' -Force -ForceBootstrap ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
493
- allow(provider).to receive(:powershell_out).with("( Get-Package 'xCertificate' -Force -ForceBootstrap ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
501
+ allow(provider).to receive(:powershell_out).with("( Find-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
502
+ allow(provider).to receive(:powershell_out).with("( Get-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
494
503
  allow(provider).to receive(:powershell_out).with("$PSVersionTable.PSVersion.Major").and_return(powershell_installed_version)
495
504
  provider.load_current_resource
496
- expect(provider).to receive(:powershell_out).with("( Uninstall-Package 'xCertificate' -Force -ForceBootstrap ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_not_available)
505
+ expect(provider).to receive(:powershell_out).with("( Uninstall-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_not_available)
497
506
  provider.run_action(:remove)
498
507
  expect(new_resource).to be_updated_by_last_action
499
508
  end