chef 16.7.61-universal-mingw32 → 16.9.20-universal-mingw32

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.
Files changed (122) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +3 -5
  3. data/README.md +2 -2
  4. data/chef.gemspec +12 -2
  5. data/distro/ruby_bin_folder/AMD64/Chef.PowerShell.Wrapper.dll +0 -0
  6. data/distro/ruby_bin_folder/AMD64/Chef.PowerShell.dll +0 -0
  7. data/distro/ruby_bin_folder/AMD64/shared/Microsoft.NETCore.App/5.0.0/Chef.PowerShell.Wrapper.Core.dll +0 -0
  8. data/distro/ruby_bin_folder/AMD64/shared/Microsoft.NETCore.App/5.0.0/Chef.Powershell.Core.dll +0 -0
  9. data/distro/ruby_bin_folder/AMD64/shared/Microsoft.NETCore.App/5.0.0/Chef.Powershell.Core.pdb +0 -0
  10. data/distro/ruby_bin_folder/x86/Chef.PowerShell.dll +0 -0
  11. data/distro/ruby_bin_folder/x86/Chef.Powershell.Wrapper.dll +0 -0
  12. data/distro/ruby_bin_folder/x86/shared/Microsoft.NETCore.App/5.0.0/Chef.PowerShell.Wrapper.Core.dll +0 -0
  13. data/distro/ruby_bin_folder/x86/shared/Microsoft.NETCore.App/5.0.0/Chef.Powershell.Core.dll +0 -0
  14. data/distro/ruby_bin_folder/x86/shared/Microsoft.NETCore.App/5.0.0/Chef.Powershell.Core.pdb +0 -0
  15. data/lib/chef/application/base.rb +1 -1
  16. data/lib/chef/client.rb +3 -0
  17. data/lib/chef/compliance/default_attributes.rb +93 -0
  18. data/lib/chef/compliance/fetcher/automate.rb +69 -0
  19. data/lib/chef/compliance/fetcher/chef_server.rb +134 -0
  20. data/lib/chef/compliance/reporter/automate.rb +201 -0
  21. data/lib/chef/compliance/reporter/chef_server_automate.rb +94 -0
  22. data/lib/chef/compliance/reporter/compliance_enforcer.rb +20 -0
  23. data/lib/chef/compliance/reporter/json_file.rb +19 -0
  24. data/lib/chef/compliance/runner.rb +262 -0
  25. data/lib/chef/cookbook_manifest.rb +1 -0
  26. data/lib/chef/encrypted_data_bag_item/assertions.rb +1 -1
  27. data/lib/chef/exceptions.rb +4 -0
  28. data/lib/chef/http/ssl_policies.rb +33 -14
  29. data/lib/chef/knife/bootstrap/train_connector.rb +1 -1
  30. data/lib/chef/knife/core/formatting_options.rb +49 -0
  31. data/lib/chef/knife/core/node_presenter.rb +0 -25
  32. data/lib/chef/knife/core/status_presenter.rb +1 -26
  33. data/lib/chef/knife/core/ui.rb +4 -1
  34. data/lib/chef/knife/core/windows_bootstrap_context.rb +1 -1
  35. data/lib/chef/knife/node_show.rb +2 -1
  36. data/lib/chef/knife/search.rb +2 -1
  37. data/lib/chef/knife/ssh.rb +3 -1
  38. data/lib/chef/knife/status.rb +8 -11
  39. data/lib/chef/mixin/powershell_exec.rb +3 -1
  40. data/lib/chef/platform/query_helpers.rb +4 -4
  41. data/lib/chef/policy_builder/policyfile.rb +1 -1
  42. data/lib/chef/powershell.rb +2 -0
  43. data/lib/chef/provider/dsc_resource.rb +12 -24
  44. data/lib/chef/provider/dsc_script.rb +16 -20
  45. data/lib/chef/provider/git.rb +5 -5
  46. data/lib/chef/provider/package.rb +53 -19
  47. data/lib/chef/provider/package/dnf.rb +39 -12
  48. data/lib/chef/provider/package/dnf/dnf_helper.py +18 -5
  49. data/lib/chef/provider/package/dnf/python_helper.rb +6 -6
  50. data/lib/chef/provider/package/freebsd/pkgng.rb +3 -1
  51. data/lib/chef/provider/yum_repository.rb +2 -2
  52. data/lib/chef/resource/chef_client_config.rb +1 -1
  53. data/lib/chef/resource/chef_gem.rb +2 -2
  54. data/lib/chef/resource/cron/cron_d.rb +1 -0
  55. data/lib/chef/resource/dsc_script.rb +8 -1
  56. data/lib/chef/resource/file.rb +1 -1
  57. data/lib/chef/resource/gem_package.rb +2 -2
  58. data/lib/chef/resource/homebrew_cask.rb +3 -3
  59. data/lib/chef/resource/hostname.rb +3 -3
  60. data/lib/chef/resource/http_request.rb +1 -1
  61. data/lib/chef/resource/locale.rb +1 -1
  62. data/lib/chef/resource/mdadm.rb +2 -2
  63. data/lib/chef/resource/osx_profile.rb +7 -7
  64. data/lib/chef/resource/remote_directory.rb +1 -1
  65. data/lib/chef/resource/ruby.rb +1 -5
  66. data/lib/chef/resource/ruby_block.rb +1 -1
  67. data/lib/chef/resource/template.rb +2 -2
  68. data/lib/chef/resource/user/windows_user.rb +5 -0
  69. data/lib/chef/resource/windows_certificate.rb +9 -13
  70. data/lib/chef/resource/yum_repository.rb +5 -0
  71. data/lib/chef/resource_collection/resource_set.rb +1 -1
  72. data/lib/chef/util/dsc/configuration_generator.rb +52 -11
  73. data/lib/chef/util/dsc/lcm_output_parser.rb +3 -4
  74. data/lib/chef/util/dsc/local_configuration_manager.rb +17 -14
  75. data/lib/chef/util/dsc/resource_store.rb +5 -11
  76. data/lib/chef/version.rb +1 -1
  77. data/lib/chef/win32/api/file.rb +4 -0
  78. data/spec/data/rubygems.org/latest_specs.4.8.gz +0 -0
  79. data/spec/data/rubygems.org/nonexistent_gem +0 -0
  80. data/spec/data/rubygems.org/sexp_processor +0 -0
  81. data/spec/data/rubygems.org/sexp_processor-4.15.1.gemspec.rz +0 -0
  82. data/spec/data/ssl/binary/chef-rspec-der.cert +0 -0
  83. data/spec/data/ssl/binary/chef-rspec-der.key +0 -0
  84. data/spec/functional/resource/dnf_package_spec.rb +319 -16
  85. data/spec/functional/resource/dsc_script_spec.rb +3 -6
  86. data/spec/functional/resource/windows_certificate_spec.rb +204 -384
  87. data/spec/integration/client/client_spec.rb +2 -1
  88. data/spec/integration/compliance/compliance_spec.rb +81 -0
  89. data/spec/integration/recipes/recipe_dsl_spec.rb +1 -0
  90. data/spec/spec_helper.rb +1 -1
  91. data/spec/unit/client_spec.rb +1 -0
  92. data/spec/unit/compliance/fetcher/automate_spec.rb +134 -0
  93. data/spec/unit/compliance/fetcher/chef_server_spec.rb +93 -0
  94. data/spec/unit/compliance/reporter/automate_spec.rb +427 -0
  95. data/spec/unit/compliance/reporter/chef_server_automate_spec.rb +177 -0
  96. data/spec/unit/compliance/reporter/compliance_enforcer_spec.rb +48 -0
  97. data/spec/unit/compliance/runner_spec.rb +167 -0
  98. data/spec/unit/http/ssl_policies_spec.rb +107 -68
  99. data/spec/unit/knife/bootstrap_spec.rb +5 -17
  100. data/spec/unit/knife/core/node_editor_spec.rb +1 -1
  101. data/spec/unit/knife/core/status_presenter_spec.rb +54 -0
  102. data/spec/unit/mixin/openssl_helper_spec.rb +0 -7
  103. data/spec/unit/mixin/powershell_exec_spec.rb +1 -1
  104. data/spec/unit/platform/query_helpers_spec.rb +11 -12
  105. data/spec/unit/provider/dsc_resource_spec.rb +10 -27
  106. data/spec/unit/provider/dsc_script_spec.rb +1 -1
  107. data/spec/unit/provider/mount/windows_spec.rb +1 -0
  108. data/spec/unit/provider/package/freebsd/pkgng_spec.rb +1 -1
  109. data/spec/unit/provider/package/rubygems_spec.rb +39 -7
  110. data/spec/unit/provider/systemd_unit_spec.rb +1 -1
  111. data/spec/unit/resource/user/windows_user_spec.rb +36 -0
  112. data/spec/unit/resource/windows_certificate_spec.rb +12 -0
  113. data/spec/unit/util/dsc/configuration_generator_spec.rb +79 -0
  114. data/spec/unit/util/dsc/local_configuration_manager_spec.rb +27 -35
  115. metadata +55 -18
  116. data/lib/chef/util/powershell/cmdlet.rb +0 -169
  117. data/lib/chef/util/powershell/cmdlet_result.rb +0 -61
  118. data/spec/data/trusted_certs_empty/.gitkeep +0 -0
  119. data/spec/data/trusted_certs_empty/README.md +0 -1
  120. data/spec/functional/util/powershell/cmdlet_spec.rb +0 -111
  121. data/spec/scripts/ssl-serve.rb +0 -47
  122. data/spec/unit/util/powershell/cmdlet_spec.rb +0 -106
@@ -1,169 +0,0 @@
1
- #
2
- # Author:: Adam Edwards (<adamed@chef.io>)
3
- #
4
- # Copyright:: Copyright (c) Chef Software Inc.
5
- #
6
- # Licensed under the Apache License, Version 2.0 (the "License");
7
- # you may not use this file except in compliance with the License.
8
- # You may obtain a copy of the License at
9
- #
10
- # http://www.apache.org/licenses/LICENSE-2.0
11
- #
12
- # Unless required by applicable law or agreed to in writing, software
13
- # distributed under the License is distributed on an "AS IS" BASIS,
14
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- # See the License for the specific language governing permissions and
16
- # limitations under the License.
17
- #
18
-
19
- module Mixlib
20
- autoload :ShellOut, "mixlib/shellout"
21
- end
22
- require_relative "../../mixin/windows_architecture_helper"
23
- require_relative "cmdlet_result"
24
-
25
- class Chef
26
- class Util
27
- class Powershell
28
- class Cmdlet
29
- def initialize(node, cmdlet, output_format = nil, output_format_options = {})
30
- @output_format = output_format
31
- @node = node
32
-
33
- case output_format
34
- when nil, :text
35
- @json_format = false
36
- when :json, :object
37
- @json_format = true
38
- else
39
- raise ArgumentError, "Invalid output format #{output_format} specified"
40
- end
41
-
42
- @cmdlet = cmdlet
43
- @output_format_options = output_format_options
44
- end
45
-
46
- attr_reader :output_format
47
-
48
- def run(switches = {}, execution_options = {}, *arguments)
49
- streams = { json: CmdletStream.new("json"),
50
- verbose: CmdletStream.new("verbose"),
51
- }
52
-
53
- arguments_string = arguments.join(" ")
54
-
55
- switches_string = command_switches_string(switches)
56
-
57
- json_depth = 5
58
-
59
- if @json_format && @output_format_options.key?(:depth)
60
- json_depth = @output_format_options[:depth]
61
- end
62
-
63
- json_command = if @json_format
64
- " | convertto-json -compress -depth #{json_depth} > #{streams[:json].path}"
65
- else
66
- ""
67
- end
68
- redirections = "4> '#{streams[:verbose].path}'"
69
- command_string = "powershell.exe -executionpolicy bypass -noprofile -noninteractive "\
70
- "-command \"trap [Exception] {write-error -exception "\
71
- "($_.Exception.Message);exit 1};#{@cmdlet} #{switches_string} "\
72
- "#{arguments_string} #{redirections}"\
73
- "#{json_command}\";if ( ! $? ) { exit 1 }"
74
-
75
- augmented_options = { returns: [0], live_stream: false }.merge(execution_options)
76
- command = Mixlib::ShellOut.new(command_string, augmented_options)
77
-
78
- status = nil
79
-
80
- with_os_architecture(@node) do
81
- status = command.run_command
82
- end
83
-
84
- CmdletResult.new(status, streams, @output_format)
85
- end
86
-
87
- def run!(switches = {}, execution_options = {}, *arguments)
88
- result = run(switches, execution_options, arguments)
89
-
90
- unless result.succeeded?
91
- raise Chef::Exceptions::PowershellCmdletException, "PowerShell Cmdlet failed: #{result.stderr}"
92
- end
93
-
94
- result
95
- end
96
-
97
- protected
98
-
99
- include Chef::Mixin::WindowsArchitectureHelper
100
-
101
- def validate_switch_name!(switch_parameter_name)
102
- if !!(switch_parameter_name =~ /\A[A-Za-z]+[_a-zA-Z0-9]*\Z/) == false
103
- raise ArgumentError, "`#{switch_parameter_name}` is not a valid PowerShell cmdlet switch parameter name"
104
- end
105
- end
106
-
107
- def escape_parameter_value(parameter_value)
108
- parameter_value.gsub(/(`|'|"|#)/, '`\1')
109
- end
110
-
111
- def escape_string_parameter_value(parameter_value)
112
- "'#{escape_parameter_value(parameter_value)}'"
113
- end
114
-
115
- def command_switches_string(switches)
116
- command_switches = switches.map do |switch_name, switch_value|
117
- if switch_name.class != Symbol
118
- raise ArgumentError, "Invalid type `#{switch_name} `for PowerShell switch '#{switch_name}'. The switch must be specified as a Symbol'"
119
- end
120
-
121
- validate_switch_name!(switch_name)
122
-
123
- switch_argument = ""
124
- switch_present = true
125
-
126
- case switch_value
127
- when Numeric, Float
128
- switch_argument = switch_value.to_s
129
- when FalseClass
130
- switch_present = false
131
- when TrueClass
132
- when String
133
- switch_argument = escape_string_parameter_value(switch_value)
134
- else
135
- raise ArgumentError, "Invalid argument type `#{switch_value.class}` specified for PowerShell switch `:#{switch_name}`. Arguments to PowerShell must be of type `String`, `Numeric`, `Float`, `FalseClass`, or `TrueClass`"
136
- end
137
-
138
- switch_present ? ["-#{switch_name.to_s.downcase}", switch_argument].join(" ").strip : ""
139
- end
140
-
141
- command_switches.join(" ")
142
- end
143
-
144
- class CmdletStream
145
- def initialize(name)
146
- @filename = Dir::Tmpname.create(name) {}
147
- ObjectSpace.define_finalizer(self, self.class.destroy(@filename))
148
- end
149
-
150
- def path
151
- @filename
152
- end
153
-
154
- def read
155
- if File.exist? @filename
156
- File.open(@filename, "rb:bom|UTF-16LE") do |f|
157
- f.read.encode("UTF-8")
158
- end
159
- end
160
- end
161
-
162
- def self.destroy(name)
163
- proc { File.delete(name) if File.exist? name }
164
- end
165
- end
166
- end
167
- end
168
- end
169
- end
@@ -1,61 +0,0 @@
1
- #
2
- # Author:: Adam Edwards (<adamed@chef.io>)
3
- #
4
- # Copyright:: Copyright (c) Chef Software Inc.
5
- #
6
- # Licensed under the Apache License, Version 2.0 (the "License");
7
- # you may not use this file except in compliance with the License.
8
- # You may obtain a copy of the License at
9
- #
10
- # http://www.apache.org/licenses/LICENSE-2.0
11
- #
12
- # Unless required by applicable law or agreed to in writing, software
13
- # distributed under the License is distributed on an "AS IS" BASIS,
14
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- # See the License for the specific language governing permissions and
16
- # limitations under the License.
17
- #
18
-
19
- require_relative "../../json_compat"
20
-
21
- class Chef
22
- class Util
23
- class Powershell
24
- class CmdletResult
25
- attr_reader :output_format
26
-
27
- def initialize(status, streams, output_format)
28
- @status = status
29
- @output_format = output_format
30
- @streams = streams
31
- end
32
-
33
- def stdout
34
- @status.stdout
35
- end
36
-
37
- def stderr
38
- @status.stderr
39
- end
40
-
41
- def stream(name)
42
- @streams[name].read
43
- end
44
-
45
- def return_value
46
- if output_format == :object
47
- Chef::JSONCompat.parse(stream(:json))
48
- elsif output_format == :json
49
- stream(:json)
50
- else
51
- @status.stdout
52
- end
53
- end
54
-
55
- def succeeded?
56
- @succeeded = @status.status.exitstatus == 0
57
- end
58
- end
59
- end
60
- end
61
- end
File without changes
@@ -1 +0,0 @@
1
- A directory with no certs. Used for testing directories with no certs during bootstrap.
@@ -1,111 +0,0 @@
1
- #
2
- # Author:: Adam Edwards (<adamed@chef.io>)
3
- #
4
- # Copyright:: Copyright (c) Chef Software Inc.
5
- #
6
- # Licensed under the Apache License, Version 2.0 (the "License");
7
- # you may not use this file except in compliance with the License.
8
- # You may obtain a copy of the License at
9
- #
10
- # http://www.apache.org/licenses/LICENSE-2.0
11
- #
12
- # Unless required by applicable law or agreed to in writing, software
13
- # distributed under the License is distributed on an "AS IS" BASIS,
14
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- # See the License for the specific language governing permissions and
16
- # limitations under the License.
17
- #
18
-
19
- require "chef/json_compat"
20
- require "spec_helper"
21
-
22
- describe Chef::Util::Powershell::Cmdlet, :windows_powershell_dsc_only do
23
- before(:all) do
24
- @node = Chef::Node.new
25
- @node.consume_external_attrs(OHAI_SYSTEM.data, {})
26
- end
27
- let(:cmd_output_format) { :text }
28
- let(:simple_cmdlet) { Chef::Util::Powershell::Cmdlet.new(@node, "get-childitem", cmd_output_format, { depth: 2 }) }
29
- let(:invalid_cmdlet) { Chef::Util::Powershell::Cmdlet.new(@node, "get-idontexist", cmd_output_format) }
30
- let(:cmdlet_get_item_requires_switch_or_argument) { Chef::Util::Powershell::Cmdlet.new(@node, "get-item", cmd_output_format, { depth: 2 }) }
31
- let(:cmdlet_alias_requires_switch_or_argument) { Chef::Util::Powershell::Cmdlet.new(@node, "alias", cmd_output_format, { depth: 2 }) }
32
- let(:etc_directory) { "#{ENV["systemroot"]}\\system32\\drivers\\etc" }
33
- let(:architecture_cmdlet) { Chef::Util::Powershell::Cmdlet.new(@node, "$env:PROCESSOR_ARCHITECTURE") }
34
-
35
- it "executes a simple process" do
36
- result = simple_cmdlet.run
37
- expect(result.succeeded?).to eq(true)
38
- end
39
-
40
- it "#run does not raise a PowershellCmdletException exception if the command cannot be executed" do
41
- expect { invalid_cmdlet.run }.not_to raise_error
42
- end
43
-
44
- it "#run! raises a PowershellCmdletException exception if the command cannot be executed" do
45
- expect { invalid_cmdlet.run! }.to raise_error(Chef::Exceptions::PowershellCmdletException)
46
- end
47
-
48
- it "executes a 64-bit command on a 64-bit OS, 32-bit otherwise" do
49
- os_arch = ENV["PROCESSOR_ARCHITEW6432"]
50
- if os_arch.nil?
51
- os_arch = ENV["PROCESSOR_ARCHITECTURE"]
52
- end
53
-
54
- result = architecture_cmdlet.run
55
- execution_arch = result.return_value
56
- execution_arch.strip!
57
- expect(execution_arch).to eq(os_arch)
58
- end
59
-
60
- it "passes command line switches to the command" do
61
- result = cmdlet_alias_requires_switch_or_argument.run({ name: "ls" })
62
- expect(result.succeeded?).to eq(true)
63
- end
64
-
65
- it "passes command line arguments to the command" do
66
- result = cmdlet_alias_requires_switch_or_argument.run({}, {}, "ls")
67
- expect(result.succeeded?).to eq(true)
68
- end
69
-
70
- it "passes command line arguments and switches to the command" do
71
- result = cmdlet_get_item_requires_switch_or_argument.run({ path: etc_directory }, {}, " | select-object -property fullname | format-table -hidetableheaders")
72
- expect(result.succeeded?).to eq(true)
73
- returned_directory = result.return_value
74
- returned_directory.strip!
75
- expect(returned_directory).to eq(etc_directory)
76
- end
77
-
78
- it "passes execution options to the command" do
79
- result = cmdlet_get_item_requires_switch_or_argument.run({}, { cwd: etc_directory }, ". | select-object -property fullname | format-table -hidetableheaders")
80
- expect(result.succeeded?).to eq(true)
81
- returned_directory = result.return_value
82
- returned_directory.strip!
83
- expect(returned_directory).to eq(etc_directory)
84
- end
85
-
86
- context "when returning json" do
87
- let(:cmd_output_format) { :json }
88
- it "returns json format data" do
89
- result = cmdlet_alias_requires_switch_or_argument.run({}, {}, "ls")
90
- expect(result.succeeded?).to eq(true)
91
- expect { Chef::JSONCompat.parse(result.return_value) }.not_to raise_error
92
- end
93
- end
94
-
95
- context "when returning Ruby objects" do
96
- let(:cmd_output_format) { :object }
97
- it "returns object format data" do
98
- result = simple_cmdlet.run({}, { cwd: etc_directory }, "hosts")
99
- expect(result.succeeded?).to eq(true)
100
- data = result.return_value
101
- expect(data["Name"]).to eq("hosts")
102
- end
103
- end
104
-
105
- context "when constructor is given invalid arguments" do
106
- let(:cmd_output_format) { :invalid }
107
- it "throws an exception if an invalid format is passed to the constructor" do
108
- expect { simple_cmdlet }.to raise_error(ArgumentError)
109
- end
110
- end
111
- end
@@ -1,47 +0,0 @@
1
- # ssl-serve.rb
2
- # USAGE: ruby ssl-serve.rb
3
- #
4
- # ssl-serve is a script that serves a local directory over SSL.
5
- # You can use it to test various HTTP behaviors in chef, like chef-client's
6
- # `-j` and `-c` options and remote_file with https connections.
7
- #
8
- require "pp"
9
- require "openssl"
10
- require "webrick"
11
- require "webrick/https"
12
-
13
- $ssl = true
14
-
15
- CHEF_SPEC_DATA = File.expand_path("../data", __dir__)
16
- cert_text = File.read(File.expand_path("ssl/chef-rspec.cert", CHEF_SPEC_DATA))
17
- cert = OpenSSL::X509::Certificate.new(cert_text)
18
- key_text = File.read(File.expand_path("ssl/chef-rspec.key", CHEF_SPEC_DATA))
19
- key = OpenSSL::PKey::RSA.new(key_text)
20
-
21
- server_opts = {}
22
- if $ssl
23
- server_opts.merge!( { SSLEnable: true,
24
- SSLVerifyClient: OpenSSL::SSL::VERIFY_NONE,
25
- SSLCertificate: cert,
26
- SSLPrivateKey: key })
27
- end
28
-
29
- # 5 == debug, 3 == warning
30
- LOGGER = WEBrick::Log.new(STDOUT, 5)
31
- DEFAULT_OPTIONS = {
32
- server: "webrick",
33
- Port: 9000,
34
- Host: "localhost",
35
- environment: :none,
36
- Logger: LOGGER,
37
- DocumentRoot: File.expand_path("#{Dir.tmpdir}/chef-118-sampledata"),
38
- #:AccessLog => [] # Remove this option to enable the access log when debugging.
39
- }.freeze
40
-
41
- webrick_opts = DEFAULT_OPTIONS.merge(server_opts)
42
- pp webrick_opts: webrick_opts
43
-
44
- server = WEBrick::HTTPServer.new(webrick_opts)
45
- trap("INT") { server.shutdown }
46
-
47
- server.start
@@ -1,106 +0,0 @@
1
- #
2
- # Author:: Jay Mundrawala <jdm@chef.io>
3
- # Copyright:: Copyright (c) Chef Software Inc.
4
- # License:: Apache License, Version 2.0
5
- #
6
- # Licensed under the Apache License, Version 2.0 (the "License");
7
- # you may not use this file except in compliance with the License.
8
- # You may obtain a copy of the License at
9
- #
10
- # http://www.apache.org/licenses/LICENSE-2.0
11
- #
12
- # Unless required by applicable law or agreed to in writing, software
13
- # distributed under the License is distributed on an "AS IS" BASIS,
14
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- # See the License for the specific language governing permissions and
16
- # limitations under the License.
17
- #
18
-
19
- require "chef"
20
- require "chef/util/powershell/cmdlet"
21
-
22
- describe Chef::Util::Powershell::Cmdlet do
23
- before (:all) do
24
- @node = Chef::Node.new
25
- @cmdlet = Chef::Util::Powershell::Cmdlet.new(@node, "Some-Commandlet")
26
- end
27
-
28
- describe "#validate_switch_name!" do
29
- it "should not raise an error if a name contains all upper case letters" do
30
- @cmdlet.send(:validate_switch_name!, "HELLO")
31
- end
32
-
33
- it "should not raise an error if the name contains all lower case letters" do
34
- @cmdlet.send(:validate_switch_name!, "hello")
35
- end
36
-
37
- it "should not raise an error if no special characters are used except _" do
38
- @cmdlet.send(:validate_switch_name!, "hello_world")
39
- end
40
-
41
- %w{! @ # $ % ^ & * & * ( ) - = + \{ \} . ? < > \\ /}.each do |sym|
42
- it "raises an Argument error if it configuration name contains #{sym}" do
43
- expect do
44
- @cmdlet.send(:validate_switch_name!, "Hello#{sym}")
45
- end.to raise_error(ArgumentError)
46
- end
47
- end
48
- end
49
-
50
- describe "#escape_parameter_value" do
51
- # Is this list really complete?
52
- %w{` " # '}.each do |c|
53
- it "escapse #{c}" do
54
- expect(@cmdlet.send(:escape_parameter_value, "stuff #{c}")).to eql("stuff `#{c}")
55
- end
56
- end
57
-
58
- it "does not do anything to a string without special characters" do
59
- expect(@cmdlet.send(:escape_parameter_value, "stuff")).to eql("stuff")
60
- end
61
- end
62
-
63
- describe "#escape_string_parameter_value" do
64
- it "surrounds a string with ''" do
65
- expect(@cmdlet.send(:escape_string_parameter_value, "stuff")).to eql("'stuff'")
66
- end
67
- end
68
-
69
- describe "#command_switches_string" do
70
- it "raises an ArgumentError if the key is not a symbol" do
71
- expect do
72
- @cmdlet.send(:command_switches_string, { "foo" => "bar" })
73
- end.to raise_error(ArgumentError)
74
- end
75
-
76
- it "does not allow invalid switch names" do
77
- expect do
78
- @cmdlet.send(:command_switches_string, { foo!: "bar" })
79
- end.to raise_error(ArgumentError)
80
- end
81
-
82
- it "ignores switches with a false value" do
83
- expect(@cmdlet.send(:command_switches_string, { foo: false })).to eql("")
84
- end
85
-
86
- it "should correctly handle a value type of string" do
87
- expect(@cmdlet.send(:command_switches_string, { foo: "bar" })).to eql("-foo 'bar'")
88
- end
89
-
90
- it "should correctly handle a value type of string even when it is 0 length" do
91
- expect(@cmdlet.send(:command_switches_string, { foo: "" })).to eql("-foo ''")
92
- end
93
-
94
- it "should not quote integers" do
95
- expect(@cmdlet.send(:command_switches_string, { foo: 1 })).to eql("-foo 1")
96
- end
97
-
98
- it "should not quote floats" do
99
- expect(@cmdlet.send(:command_switches_string, { foo: 1.0 })).to eql("-foo 1.0")
100
- end
101
-
102
- it "has just the switch when the value is true" do
103
- expect(@cmdlet.send(:command_switches_string, { foo: true })).to eql("-foo")
104
- end
105
- end
106
- end