chef 17.3.48-universal-mingw32 → 17.6.15-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 (125) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -2
  3. data/chef.gemspec +2 -0
  4. data/lib/chef/application/base.rb +11 -1
  5. data/lib/chef/application.rb +3 -1
  6. data/lib/chef/client.rb +1 -2
  7. data/lib/chef/compliance/default_attributes.rb +5 -3
  8. data/lib/chef/compliance/input.rb +115 -0
  9. data/lib/chef/compliance/input_collection.rb +139 -0
  10. data/lib/chef/compliance/profile.rb +122 -0
  11. data/lib/chef/compliance/profile_collection.rb +109 -0
  12. data/lib/chef/compliance/reporter/automate.rb +1 -1
  13. data/lib/chef/compliance/runner.rb +62 -6
  14. data/lib/chef/compliance/waiver.rb +115 -0
  15. data/lib/chef/compliance/waiver_collection.rb +143 -0
  16. data/lib/chef/dsl/compliance.rb +38 -0
  17. data/lib/chef/dsl/reader_helpers.rb +51 -0
  18. data/lib/chef/dsl/recipe.rb +4 -2
  19. data/lib/chef/dsl/secret.rb +5 -7
  20. data/lib/chef/dsl/universal.rb +2 -0
  21. data/lib/chef/event_dispatch/base.rb +44 -2
  22. data/lib/chef/exceptions.rb +0 -2
  23. data/lib/chef/formatters/doc.rb +60 -13
  24. data/lib/chef/formatters/error_mapper.rb +2 -2
  25. data/lib/chef/formatters/minimal.rb +6 -5
  26. data/lib/chef/http/basic_client.rb +15 -7
  27. data/lib/chef/http.rb +12 -8
  28. data/lib/chef/provider/execute.rb +1 -1
  29. data/lib/chef/provider/file.rb +2 -0
  30. data/lib/chef/provider/group/dscl.rb +1 -1
  31. data/lib/chef/provider/launchd.rb +6 -6
  32. data/lib/chef/provider/link.rb +2 -2
  33. data/lib/chef/provider/registry_key.rb +3 -2
  34. data/lib/chef/provider/remote_file/http.rb +1 -1
  35. data/lib/chef/provider/subversion.rb +4 -4
  36. data/lib/chef/provider/support/yum_repo.erb +1 -1
  37. data/lib/chef/provider/systemd_unit.rb +17 -16
  38. data/lib/chef/provider/template.rb +1 -1
  39. data/lib/chef/provider/user/mac.rb +3 -3
  40. data/lib/chef/provider/yum_repository.rb +27 -43
  41. data/lib/chef/provider/zypper_repository.rb +3 -3
  42. data/lib/chef/provider.rb +26 -1
  43. data/lib/chef/provider_resolver.rb +8 -2
  44. data/lib/chef/resource/archive_file.rb +17 -14
  45. data/lib/chef/resource/chef_client_scheduled_task.rb +45 -2
  46. data/lib/chef/resource/chocolatey_config.rb +13 -13
  47. data/lib/chef/resource/execute.rb +2 -2
  48. data/lib/chef/resource/file/verification/json.rb +50 -0
  49. data/lib/chef/resource/file/verification/yaml.rb +52 -0
  50. data/lib/chef/resource/homebrew_cask.rb +1 -1
  51. data/lib/chef/resource/inspec_input.rb +127 -0
  52. data/lib/chef/resource/inspec_waiver.rb +184 -0
  53. data/lib/chef/resource/inspec_waiver_file_entry.rb +2 -2
  54. data/lib/chef/resource/launchd.rb +3 -3
  55. data/lib/chef/resource/mount.rb +1 -1
  56. data/lib/chef/resource/openssl_x509_certificate.rb +1 -1
  57. data/lib/chef/resource/powershell_package_source.rb +234 -70
  58. data/lib/chef/resource/registry_key.rb +36 -48
  59. data/lib/chef/resource/remote_file.rb +99 -3
  60. data/lib/chef/resource/rhsm_subscription.rb +5 -5
  61. data/lib/chef/resource/ruby_block.rb +100 -0
  62. data/lib/chef/resource/scm/subversion.rb +1 -1
  63. data/lib/chef/resource/sysctl.rb +2 -2
  64. data/lib/chef/resource/systemd_unit.rb +3 -3
  65. data/lib/chef/resource/timezone.rb +2 -2
  66. data/lib/chef/resource/user_ulimit.rb +1 -0
  67. data/lib/chef/resource/windows_printer.rb +1 -1
  68. data/lib/chef/resource/windows_uac.rb +3 -1
  69. data/lib/chef/resource/windows_user_privilege.rb +1 -1
  70. data/lib/chef/resource/yum_package.rb +1 -5
  71. data/lib/chef/resource.rb +13 -17
  72. data/lib/chef/resource_inspector.rb +6 -2
  73. data/lib/chef/resources.rb +2 -0
  74. data/lib/chef/run_context/cookbook_compiler.rb +112 -28
  75. data/lib/chef/run_context.rb +31 -1
  76. data/lib/chef/secret_fetcher/akeyless_vault.rb +57 -0
  77. data/lib/chef/secret_fetcher/aws_secrets_manager.rb +17 -5
  78. data/lib/chef/secret_fetcher/azure_key_vault.rb +32 -10
  79. data/lib/chef/secret_fetcher/base.rb +6 -2
  80. data/lib/chef/secret_fetcher/hashi_vault.rb +100 -0
  81. data/lib/chef/secret_fetcher.rb +13 -6
  82. data/lib/chef/version.rb +1 -1
  83. data/lib/chef/win32/version.rb +2 -1
  84. data/spec/data/archive_file/test_archive.tar.gz +0 -0
  85. data/spec/functional/resource/archive_file_spec.rb +87 -0
  86. data/spec/functional/resource/group_spec.rb +5 -1
  87. data/spec/functional/resource/link_spec.rb +8 -0
  88. data/spec/functional/resource/powershell_package_source_spec.rb +5 -6
  89. data/spec/integration/compliance/compliance_spec.rb +61 -0
  90. data/spec/integration/recipes/resource_action_spec.rb +2 -2
  91. data/spec/spec_helper.rb +3 -0
  92. data/spec/support/platform_helpers.rb +4 -0
  93. data/spec/support/ruby_installer.rb +51 -0
  94. data/spec/unit/compliance/input_spec.rb +104 -0
  95. data/spec/unit/compliance/profile_spec.rb +120 -0
  96. data/spec/unit/compliance/runner_spec.rb +46 -2
  97. data/spec/unit/compliance/waiver_spec.rb +104 -0
  98. data/spec/unit/dsl/secret_spec.rb +8 -2
  99. data/spec/unit/formatters/doc_spec.rb +1 -1
  100. data/spec/unit/http/basic_client_spec.rb +30 -0
  101. data/spec/unit/http_spec.rb +8 -2
  102. data/spec/unit/provider/link_spec.rb +13 -7
  103. data/spec/unit/provider/remote_file/http_spec.rb +10 -0
  104. data/spec/unit/provider/template_spec.rb +2 -2
  105. data/spec/unit/provider_spec.rb +23 -0
  106. data/spec/unit/resource/archive_file_spec.rb +414 -3
  107. data/spec/unit/resource/chef_client_scheduled_task_spec.rb +69 -0
  108. data/spec/unit/resource/file/verification/json_spec.rb +72 -0
  109. data/spec/unit/resource/file/verification/yaml_spec.rb +67 -0
  110. data/spec/unit/resource/homebrew_cask_spec.rb +29 -11
  111. data/spec/unit/resource/inspec_input_spec.rb +300 -0
  112. data/spec/unit/resource/inspec_waiver_spec.rb +312 -0
  113. data/spec/unit/resource/mount_spec.rb +10 -0
  114. data/spec/unit/resource/powershell_package_source_spec.rb +63 -62
  115. data/spec/unit/resource/rhsm_subscription_spec.rb +50 -3
  116. data/spec/unit/resource/systemd_unit_spec.rb +1 -1
  117. data/spec/unit/resource/user_ulimit_spec.rb +14 -1
  118. data/spec/unit/resource_spec.rb +19 -8
  119. data/spec/unit/secret_fetcher/akeyless_vault_spec.rb +37 -0
  120. data/spec/unit/secret_fetcher/aws_secrets_manager_spec.rb +70 -0
  121. data/spec/unit/secret_fetcher/azure_key_vault_spec.rb +23 -16
  122. data/spec/unit/secret_fetcher/hashi_vault_spec.rb +80 -0
  123. data/spec/unit/secret_fetcher_spec.rb +9 -9
  124. data/tasks/rspec.rb +2 -1
  125. metadata +61 -6
@@ -33,14 +33,15 @@ describe Chef::Resource::PowershellPackageSource do
33
33
  expect(resource.action).to eql([:register])
34
34
  end
35
35
 
36
- it "supports :register and :unregister actions" do
36
+ it "supports :register, :set and :unregister actions" do
37
37
  expect { resource.action :register }.not_to raise_error
38
+ expect { resource.action :set }.not_to raise_error
38
39
  expect { resource.action :unregister }.not_to raise_error
39
40
  end
40
41
 
41
42
  it "the url property accepts strings" do
42
- resource.url("https://mygallery.company.co/api/v2/")
43
- expect(resource.url).to eql("https://mygallery.company.co/api/v2/")
43
+ resource.source_location("https://mygallery.company.co/api/v2/")
44
+ expect(resource.source_location).to eql("https://mygallery.company.co/api/v2/")
44
45
  end
45
46
 
46
47
  it "the trusted property accepts true and false" do
@@ -54,7 +55,7 @@ describe Chef::Resource::PowershellPackageSource do
54
55
  expect(resource.trusted).to eql(false)
55
56
  end
56
57
 
57
- it "provider_name accepts 'Programs', 'msi', 'NuGet', 'msu', 'PowerShellGet', 'psl', 'chocolatey'" do
58
+ it "provider_name accepts 'Programs', 'msi', 'NuGet', 'msu', 'PowerShellGet', 'psl', 'chocolatey', 'winget'" do
58
59
  expect { resource.provider_name("Programs") }.not_to raise_error
59
60
  expect { resource.provider_name("msi") }.not_to raise_error
60
61
  expect { resource.provider_name("NuGet") }.not_to raise_error
@@ -62,6 +63,7 @@ describe Chef::Resource::PowershellPackageSource do
62
63
  expect { resource.provider_name("PowerShellGet") }.not_to raise_error
63
64
  expect { resource.provider_name("psl") }.not_to raise_error
64
65
  expect { resource.provider_name("chocolatey") }.not_to raise_error
66
+ expect { resource.provider_name("winget") }.not_to raise_error
65
67
  end
66
68
 
67
69
  it "the publish_location property accepts strings" do
@@ -70,75 +72,76 @@ describe Chef::Resource::PowershellPackageSource do
70
72
  end
71
73
 
72
74
  it "the script_source_location property accepts strings" do
73
- resource.publish_location("https://mygallery.company.co/api/v2/scripts")
74
- expect(resource.publish_location).to eql("https://mygallery.company.co/api/v2/scripts")
75
+ resource.script_source_location("https://mygallery.company.co/api/v2/scripts")
76
+ expect(resource.script_source_location).to eql("https://mygallery.company.co/api/v2/scripts")
75
77
  end
76
78
 
77
79
  it "the script_publish_location property accepts strings" do
78
- resource.publish_location("https://mygallery.company.co/api/v2/scripts")
79
- expect(resource.publish_location).to eql("https://mygallery.company.co/api/v2/scripts")
80
+ resource.script_publish_location("https://mygallery.company.co/api/v2/scripts")
81
+ expect(resource.script_publish_location).to eql("https://mygallery.company.co/api/v2/scripts")
80
82
  end
81
83
 
82
84
  describe "#build_ps_repository_command" do
83
85
  before do
84
86
  resource.source_name("MyGallery")
85
- resource.url("https://mygallery.company.co/api/v2/")
87
+ resource.source_location("https://github.com/chef/powershell_test")
88
+ resource.provider_name("PowerShellGet")
86
89
  end
87
90
 
88
91
  context "#register" do
89
92
  it "builds a minimal command" do
90
- expect(provider.build_ps_repository_command("Register", resource)).to eql("Register-PSRepository -Name 'MyGallery' -SourceLocation 'https://mygallery.company.co/api/v2/' -InstallationPolicy 'Untrusted' | Out-Null")
93
+ expect(provider.build_ps_repository_command("Register", resource)).to eql("Register-PSRepository -Name 'MyGallery' -SourceLocation 'https://github.com/chef/powershell_test' -InstallationPolicy 'Untrusted' | Out-Null")
91
94
  end
92
95
 
93
96
  it "builds a command with trusted set to true" do
94
97
  resource.trusted(true)
95
- expect(provider.build_ps_repository_command("Register", resource)).to eql("Register-PSRepository -Name 'MyGallery' -SourceLocation 'https://mygallery.company.co/api/v2/' -InstallationPolicy 'Trusted' | Out-Null")
98
+ expect(provider.build_ps_repository_command("Register", resource)).to eql("Register-PSRepository -Name 'MyGallery' -SourceLocation 'https://github.com/chef/powershell_test' -InstallationPolicy 'Trusted' | Out-Null")
96
99
  end
97
100
 
98
101
  it "builds a command with a publish location" do
99
- resource.publish_location("https://mygallery.company.co/api/v2/package")
100
- expect(provider.build_ps_repository_command("Register", resource)).to eql("Register-PSRepository -Name 'MyGallery' -SourceLocation 'https://mygallery.company.co/api/v2/' -InstallationPolicy 'Untrusted' -PublishLocation 'https://mygallery.company.co/api/v2/package' | Out-Null")
102
+ resource.publish_location("https://github.com/chef/powershell_test/package")
103
+ expect(provider.build_ps_repository_command("Register", resource)).to eql("Register-PSRepository -Name 'MyGallery' -SourceLocation 'https://github.com/chef/powershell_test' -InstallationPolicy 'Untrusted' -PublishLocation 'https://github.com/chef/powershell_test/package' | Out-Null")
101
104
  end
102
105
 
103
106
  it "builds a command with a script source location" do
104
- resource.script_source_location("https://mygallery.company.co/api/v2/scripts")
105
- expect(provider.build_ps_repository_command("Register", resource)).to eql("Register-PSRepository -Name 'MyGallery' -SourceLocation 'https://mygallery.company.co/api/v2/' -InstallationPolicy 'Untrusted' -ScriptSourceLocation 'https://mygallery.company.co/api/v2/scripts' | Out-Null")
107
+ resource.script_source_location("https://github.com/chef/powershell_test/scripts")
108
+ expect(provider.build_ps_repository_command("Register", resource)).to eql("Register-PSRepository -Name 'MyGallery' -SourceLocation 'https://github.com/chef/powershell_test' -InstallationPolicy 'Untrusted' -ScriptSourceLocation 'https://github.com/chef/powershell_test/scripts' | Out-Null")
106
109
  end
107
110
 
108
111
  it "builds a command with a script publish location" do
109
- resource.script_publish_location("https://mygallery.company.co/api/v2/scripts/package")
110
- expect(provider.build_ps_repository_command("Register", resource)).to eql("Register-PSRepository -Name 'MyGallery' -SourceLocation 'https://mygallery.company.co/api/v2/' -InstallationPolicy 'Untrusted' -ScriptPublishLocation 'https://mygallery.company.co/api/v2/scripts/package' | Out-Null")
112
+ resource.script_publish_location("https://github.com/chef/powershell_test/scripts/package")
113
+ expect(provider.build_ps_repository_command("Register", resource)).to eql("Register-PSRepository -Name 'MyGallery' -SourceLocation 'https://github.com/chef/powershell_test' -InstallationPolicy 'Untrusted' -ScriptPublishLocation 'https://github.com/chef/powershell_test/scripts/package' | Out-Null")
111
114
  end
112
115
  end
113
116
 
114
117
  context "#set" do
115
118
  it "builds a minimal command" do
116
- expect(provider.build_ps_repository_command("Set", resource)).to eql("Set-PSRepository -Name 'MyGallery' -SourceLocation 'https://mygallery.company.co/api/v2/' -InstallationPolicy 'Untrusted' | Out-Null")
119
+ expect(provider.build_ps_repository_command("Set", resource)).to eql("Set-PSRepository -Name 'MyGallery' -SourceLocation 'https://github.com/chef/powershell_test' -InstallationPolicy 'Untrusted' | Out-Null")
117
120
  end
118
121
 
119
122
  it "builds a command to change the url" do
120
- resource.url("https://othergallery.company.co/api/v2/")
123
+ resource.source_location("https://othergallery.company.co/api/v2/")
121
124
  expect(provider.build_ps_repository_command("Set", resource)).to eql("Set-PSRepository -Name 'MyGallery' -SourceLocation 'https://othergallery.company.co/api/v2/' -InstallationPolicy 'Untrusted' | Out-Null")
122
125
  end
123
126
 
124
127
  it "builds a command with trusted set to true" do
125
128
  resource.trusted(true)
126
- expect(provider.build_ps_repository_command("Set", resource)).to eql("Set-PSRepository -Name 'MyGallery' -SourceLocation 'https://mygallery.company.co/api/v2/' -InstallationPolicy 'Trusted' | Out-Null")
129
+ expect(provider.build_ps_repository_command("Set", resource)).to eql("Set-PSRepository -Name 'MyGallery' -SourceLocation 'https://github.com/chef/powershell_test' -InstallationPolicy 'Trusted' | Out-Null")
127
130
  end
128
131
 
129
132
  it "builds a command with a publish location" do
130
- resource.publish_location("https://mygallery.company.co/api/v2/package")
131
- expect(provider.build_ps_repository_command("Set", resource)).to eql("Set-PSRepository -Name 'MyGallery' -SourceLocation 'https://mygallery.company.co/api/v2/' -InstallationPolicy 'Untrusted' -PublishLocation 'https://mygallery.company.co/api/v2/package' | Out-Null")
133
+ resource.publish_location("https://github.com/chef/powershell_test/package")
134
+ expect(provider.build_ps_repository_command("Set", resource)).to eql("Set-PSRepository -Name 'MyGallery' -SourceLocation 'https://github.com/chef/powershell_test' -InstallationPolicy 'Untrusted' -PublishLocation 'https://github.com/chef/powershell_test/package' | Out-Null")
132
135
  end
133
136
 
134
137
  it "builds a command with a script source location" do
135
- resource.script_source_location("https://mygallery.company.co/api/v2/scripts")
136
- expect(provider.build_ps_repository_command("Set", resource)).to eql("Set-PSRepository -Name 'MyGallery' -SourceLocation 'https://mygallery.company.co/api/v2/' -InstallationPolicy 'Untrusted' -ScriptSourceLocation 'https://mygallery.company.co/api/v2/scripts' | Out-Null")
138
+ resource.script_source_location("https://github.com/chef/powershell_test/scripts")
139
+ expect(provider.build_ps_repository_command("Set", resource)).to eql("Set-PSRepository -Name 'MyGallery' -SourceLocation 'https://github.com/chef/powershell_test' -InstallationPolicy 'Untrusted' -ScriptSourceLocation 'https://github.com/chef/powershell_test/scripts' | Out-Null")
137
140
  end
138
141
 
139
142
  it "builds a command with a script publish location" do
140
- resource.script_publish_location("https://mygallery.company.co/api/v2/scripts/package")
141
- expect(provider.build_ps_repository_command("Set", resource)).to eql("Set-PSRepository -Name 'MyGallery' -SourceLocation 'https://mygallery.company.co/api/v2/' -InstallationPolicy 'Untrusted' -ScriptPublishLocation 'https://mygallery.company.co/api/v2/scripts/package' | Out-Null")
143
+ resource.script_publish_location("https://github.com/chef/powershell_test/scripts/package")
144
+ expect(provider.build_ps_repository_command("Set", resource)).to eql("Set-PSRepository -Name 'MyGallery' -SourceLocation 'https://github.com/chef/powershell_test' -InstallationPolicy 'Untrusted' -ScriptPublishLocation 'https://github.com/chef/powershell_test/scripts/package' | Out-Null")
142
145
  end
143
146
  end
144
147
  end
@@ -146,74 +149,72 @@ describe Chef::Resource::PowershellPackageSource do
146
149
  describe "#build_package_source_command" do
147
150
  before do
148
151
  resource.source_name("NuGet")
149
- resource.url("http://nuget.org/api/v2/")
152
+ resource.source_location("http://nuget.org/api/v2/")
150
153
  end
151
154
 
152
155
  context "#register" do
153
156
  it "builds a minimal command" do
154
- expect(provider.build_package_source_command("Register", resource)).to eql("Register-PackageSource -Name 'NuGet' -Location 'http://nuget.org/api/v2/' -Trusted:$false -ProviderName 'NuGet' | Out-Null")
157
+ expect(provider.build_package_source_command("Register", resource)).to eql("Register-PackageSource -Name 'NuGet' -Location 'http://nuget.org/api/v2/' -ProviderName 'NuGet' | Out-Null")
155
158
  end
156
159
 
157
160
  it "builds a command with trusted set to true" do
158
161
  resource.trusted(true)
159
- expect(provider.build_package_source_command("Register", resource)).to eql("Register-PackageSource -Name 'NuGet' -Location 'http://nuget.org/api/v2/' -Trusted:$true -ProviderName 'NuGet' | Out-Null")
162
+ expect(provider.build_package_source_command("Register", resource)).to eql("Register-PackageSource -Name 'NuGet' -Location 'http://nuget.org/api/v2/' -Trusted -ProviderName 'NuGet' | Out-Null")
160
163
  end
161
164
 
162
165
  it "builds a command with a different provider" do
163
166
  resource.source_name("choco")
164
- resource.url("https://chocolatey.org/api/v2/")
167
+ resource.source_location("https://chocolatey.org/api/v2/")
165
168
  resource.provider_name("chocolatey")
166
- expect(provider.build_package_source_command("Register", resource)).to eql("Register-PackageSource -Name 'choco' -Location 'https://chocolatey.org/api/v2/' -Trusted:$false -ProviderName 'chocolatey' | Out-Null")
169
+ expect(provider.build_package_source_command("Register", resource)).to eql("Register-PackageSource -Name 'choco' -Location 'https://chocolatey.org/api/v2/' -ProviderName 'chocolatey' | Out-Null")
167
170
  end
168
171
  end
169
172
 
170
173
  context "#set" do
171
174
  it "builds a minimal command" do
172
- expect(provider.build_package_source_command("Set", resource)).to eql("Set-PackageSource -Name 'NuGet' -Location 'http://nuget.org/api/v2/' -Trusted:$false -ProviderName 'NuGet' | Out-Null")
175
+ expect(provider.build_package_source_command("Set", resource)).to eql("Set-PackageSource -Name 'NuGet' -Location 'http://nuget.org/api/v2/' -ProviderName 'NuGet' | Out-Null")
173
176
  end
174
177
 
175
178
  it "builds a command to change the url" do
176
- resource.url("https://nuget.company.co/api/v2/")
177
- expect(provider.build_package_source_command("Set", resource)).to eql("Set-PackageSource -Name 'NuGet' -Location 'https://nuget.company.co/api/v2/' -Trusted:$false -ProviderName 'NuGet' | Out-Null")
179
+ resource.source_location("https://nuget.company.co/api/v2/")
180
+ expect(provider.build_package_source_command("Set", resource)).to eql("Set-PackageSource -Name 'NuGet' -Location 'https://nuget.company.co/api/v2/' -ProviderName 'NuGet' | Out-Null")
178
181
  end
179
182
 
180
183
  it "builds a command with trusted set to true" do
181
184
  resource.trusted(true)
182
- expect(provider.build_package_source_command("Set", resource)).to eql("Set-PackageSource -Name 'NuGet' -Location 'http://nuget.org/api/v2/' -Trusted:$true -ProviderName 'NuGet' | Out-Null")
185
+ expect(provider.build_package_source_command("Set", resource)).to eql("Set-PackageSource -Name 'NuGet' -Location 'http://nuget.org/api/v2/' -Trusted -ProviderName 'NuGet' | Out-Null")
183
186
  end
184
187
 
185
188
  it "builds a command with a different provider" do
186
189
  resource.source_name("choco")
187
- resource.url("https://chocolatey.org/api/v2/")
190
+ resource.source_location("https://chocolatey.org/api/v2/")
188
191
  resource.provider_name("chocolatey")
189
- expect(provider.build_package_source_command("Set", resource)).to eql("Set-PackageSource -Name 'choco' -Location 'https://chocolatey.org/api/v2/' -Trusted:$false -ProviderName 'chocolatey' | Out-Null")
192
+ expect(provider.build_package_source_command("Set", resource)).to eql("Set-PackageSource -Name 'choco' -Location 'https://chocolatey.org/api/v2/' -ProviderName 'chocolatey' | Out-Null")
190
193
  end
191
194
  end
192
195
  end
193
196
 
194
- describe "#psrepository_cmdlet_appropriate?" do
195
- it "returns true if the provider_name is 'PowerShellGet'" do
196
- resource.provider_name("PowerShellGet")
197
- expect(provider.psrepository_cmdlet_appropriate?).to eql(true)
198
- end
199
-
200
- it "returns false if the provider_name is something else" do
201
- resource.provider_name("NuGet")
202
- expect(provider.psrepository_cmdlet_appropriate?).to eql(false)
203
- end
204
- end
205
-
206
- describe "#package_source_exists?" do
207
- it "returns true if it exists" do
208
- allow(provider).to receive(:powershell_exec!).with("(Get-PackageSource -Name 'MyGallery' -ErrorAction SilentlyContinue).Name").and_return(double("powershell_exec!", result: "MyGallery\r\n"))
209
- resource.source_name("MyGallery")
210
- expect(provider.package_source_exists?).to eql(true)
211
- end
212
-
213
- it "returns false if it doesn't exist" do
214
- allow(provider).to receive(:powershell_exec!).with("(Get-PackageSource -Name 'MyGallery' -ErrorAction SilentlyContinue).Name").and_return(double("powershell_exec!", result: ""))
215
- resource.source_name("MyGallery")
216
- expect(provider.package_source_exists?).to eql(false)
217
- end
218
- end
197
+ # describe "get_package_source_details" do
198
+ # before do
199
+ # resource.source_name("MyGallery")
200
+ # resource.source_location("http://nuget.org/api/v2/")
201
+ # provider.build_package_source_command("Register", resource)
202
+ # end
203
+
204
+ # # stub a call to the package_source_details
205
+ # expect(provider).to receive(:get_package_source_details).and_return("PackageSource")
206
+ # it "returns packagesource if it exists" do
207
+ # # dbl = double("testing PackageSource")
208
+ # # let(source_name)
209
+ # # # allow(provider).to receive(:powershell_exec!).with("(Get-PackageSource -Name 'MyGallery' -ErrorAction SilentlyContinue).Name").and_return(double("powershell_exec!", result: "PackageSource"))
210
+ # # resource.source_name("MyGallery")
211
+ # expect(provider.get_package_source_details.result).to eql("PackageSource")
212
+ # end
213
+
214
+ # it "returns unregistered if it doesn't exist" do
215
+ # # allow(provider).to receive(:powershell_exec!).with("(Get-PackageSource -Name 'Foo' -ErrorAction SilentlyContinue).Name").and_return(double("powershell_exec!", result: ""))
216
+ # resource.source_name("Foo")
217
+ # expect(provider.get_package_source_details.result).to eql("Unregistered")
218
+ # end
219
+ # end
219
220
  end
@@ -18,15 +18,24 @@
18
18
  require "spec_helper"
19
19
 
20
20
  describe Chef::Resource::RhsmSubscription do
21
- let(:resource) { Chef::Resource::RhsmSubscription.new("fakey_fakerton") }
22
- let(:provider) { resource.provider_for_action(:attach) }
21
+ let(:event_dispatch) { Chef::EventDispatch::Dispatcher.new }
22
+ let(:node) { Chef::Node.new }
23
+ let(:run_context) { Chef::RunContext.new(node, {}, event_dispatch) }
24
+
25
+ let(:pool_id) { "8a8dd78c766232550226b46e59404aba" }
26
+ let(:resource) { Chef::Resource::RhsmSubscription.new(pool_id, run_context) }
27
+ let(:provider) { resource.provider_for_action(Array(resource.action).first) }
28
+
29
+ before do
30
+ allow(resource).to receive(:provider_for_action).with(:attach).and_return(provider)
31
+ end
23
32
 
24
33
  it "has a resource name of :rhsm_subscription" do
25
34
  expect(resource.resource_name).to eql(:rhsm_subscription)
26
35
  end
27
36
 
28
37
  it "the pool_id property is the name_property" do
29
- expect(resource.pool_id).to eql("fakey_fakerton")
38
+ expect(resource.pool_id).to eql(pool_id)
30
39
  end
31
40
 
32
41
  it "sets the default action as :attach" do
@@ -38,6 +47,44 @@ describe Chef::Resource::RhsmSubscription do
38
47
  expect { resource.action :remove }.not_to raise_error
39
48
  end
40
49
 
50
+ describe "#action_attach" do
51
+ let(:yum_package_double) { instance_double("Chef::Resource::YumPackage") }
52
+ let(:so_double) { instance_double("Mixlib::ShellOut", stdout: "Successfully attached a subscription for: My Subscription", exitstatus: 0, error?: false) }
53
+
54
+ before do
55
+ allow(provider).to receive(:shell_out!).with("subscription-manager attach --pool=#{resource.pool_id}").and_return(so_double)
56
+ allow(provider).to receive(:build_resource).with(:package, "rhsm_subscription-#{pool_id}-flush_cache").and_return(yum_package_double)
57
+ allow(yum_package_double).to receive(:run_action).with(:flush_cache)
58
+ end
59
+
60
+ context "when already attached to pool" do
61
+ before do
62
+ allow(provider).to receive(:subscription_attached?).with(resource.pool_id).and_return(true)
63
+ end
64
+
65
+ it "does not attach to pool" do
66
+ expect(provider).not_to receive(:shell_out!)
67
+ resource.run_action(:attach)
68
+ end
69
+ end
70
+
71
+ context "when not attached to pool" do
72
+ before do
73
+ allow(provider).to receive(:subscription_attached?).with(resource.pool_id).and_return(false)
74
+ end
75
+
76
+ it "attaches to pool" do
77
+ expect(provider).to receive(:shell_out!).with("subscription-manager attach --pool=#{resource.pool_id}")
78
+ resource.run_action(:attach)
79
+ end
80
+
81
+ it "flushes package provider cache" do
82
+ expect(yum_package_double).to receive(:run_action).with(:flush_cache)
83
+ resource.run_action(:attach)
84
+ end
85
+ end
86
+ end
87
+
41
88
  describe "#subscription_attached?" do
42
89
  let(:cmd) { double("cmd") }
43
90
  let(:output) { "Pool ID: pool123" }
@@ -20,7 +20,7 @@ require "spec_helper"
20
20
 
21
21
  describe Chef::Resource::SystemdUnit do
22
22
  let(:resource) { Chef::Resource::SystemdUnit.new("sysstat-collect.timer") }
23
- let(:unit_content_string) { "[Unit]\nDescription = Run system activity accounting tool every 10 minutes\nDocumentation = foo\nDocumentation = bar\n\n[Timer]\nOnCalendar = *:00/10\n\n[Install]\nWantedBy = sysstat.service\n" }
23
+ let(:unit_content_string) { "[Unit]\nDescription=Run system activity accounting tool every 10 minutes\nDocumentation=foo\nDocumentation=bar\n\n[Timer]\nOnCalendar=*:00/10\n\n[Install]\nWantedBy=sysstat.service\n" }
24
24
  let(:unit_content_hash) do
25
25
  {
26
26
  "Unit" => {
@@ -17,7 +17,6 @@
17
17
  #
18
18
 
19
19
  require "spec_helper"
20
-
21
20
  describe Chef::Resource::UserUlimit do
22
21
  let(:node) { Chef::Node.new }
23
22
  let(:events) { Chef::EventDispatch::Dispatcher.new }
@@ -50,4 +49,18 @@ describe Chef::Resource::UserUlimit do
50
49
  expect { resource.action :create }.not_to raise_error
51
50
  expect { resource.action :delete }.not_to raise_error
52
51
  end
52
+
53
+ describe "sensitive attribute" do
54
+ context "should be insensitive by default" do
55
+ it { expect(resource.sensitive).to(be_falsey) }
56
+ end
57
+
58
+ context "when set" do
59
+ before { resource.sensitive(true) }
60
+
61
+ it "should be set on the resource" do
62
+ expect(resource.sensitive).to(be_truthy)
63
+ end
64
+ end
65
+ end
53
66
  end
@@ -1172,21 +1172,23 @@ describe Chef::Resource do
1172
1172
  action :base_action3, description: "unmodified base action 3 desc" do; end
1173
1173
  end
1174
1174
 
1175
+ let(:resource_inst) { TestResource.new("TestResource", nil) }
1176
+
1175
1177
  it "returns nil when no description was provided for the action" do
1176
- expect(TestResource.action_description(:base_action0)).to eql(nil)
1178
+ expect(resource_inst.action_description(:base_action0)).to eql(nil)
1177
1179
  end
1178
1180
 
1179
1181
  context "when action definition is a string" do
1180
1182
  it "returns the description whether a symbol or string is used to look it up" do
1181
- expect(TestResource.action_description("string_action")).to eql("a string test")
1182
- expect(TestResource.action_description(:string_action)).to eql("a string test")
1183
+ expect(resource_inst.action_description("string_action")).to eql("a string test")
1184
+ expect(resource_inst.action_description(:string_action)).to eql("a string test")
1183
1185
  end
1184
1186
  end
1185
1187
 
1186
1188
  context "when action definition is a symbol" do
1187
1189
  it "returns the description whether a symbol or string is used to look up" do
1188
- expect(TestResource.action_description("symbol_action")).to eql("a symbol test")
1189
- expect(TestResource.action_description(:symbol_action)).to eql("a symbol test")
1190
+ expect(resource_inst.action_description("symbol_action")).to eql("a symbol test")
1191
+ expect(resource_inst.action_description(:symbol_action)).to eql("a symbol test")
1190
1192
  end
1191
1193
  end
1192
1194
 
@@ -1196,14 +1198,23 @@ describe Chef::Resource do
1196
1198
  action :base_action3 do; end
1197
1199
  end
1198
1200
 
1201
+ class TestResourceChild2 < TestResource
1202
+ # We should never see this description
1203
+ action :base_action2, description: "if you see this in an error, TestResourceChild was polluted with this description" do; end
1204
+ end
1205
+ let(:resource_inst) { TestResourceChild.new("TestResource", nil) }
1206
+
1199
1207
  it "returns original description when a described action is not overridden in child resource" do
1200
- expect(TestResourceChild.action_description(:base_action1)).to eq "unmodified base action 1 desc"
1208
+ expect(resource_inst.action_description(:base_action1)).to eq "unmodified base action 1 desc"
1201
1209
  end
1202
1210
  it "returns original description when the child resource overrides an inherited action but NOT its description" do
1203
- expect(TestResourceChild.action_description(:base_action3)).to eq "unmodified base action 3 desc"
1211
+ expect(resource_inst.action_description(:base_action3)).to eq "unmodified base action 3 desc"
1212
+ end
1213
+ it "returns new description when the child resource overrides an inherited action and its description" do
1214
+ expect(resource_inst.action_description(:base_action2)).to eq "modified base action 2 desc"
1204
1215
  end
1205
1216
  it "returns new description when the child resource overrides an inherited action and its description" do
1206
- expect(TestResourceChild.action_description(:base_action2)).to eq "modified base action 2 desc"
1217
+ expect(resource_inst.action_description(:base_action2)).to eq "modified base action 2 desc"
1207
1218
  end
1208
1219
  end
1209
1220
  end
@@ -0,0 +1,37 @@
1
+ #
2
+ # Author:: Marc Paradise <marc@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_relative "../../spec_helper"
20
+ require "chef/secret_fetcher/akeyless_vault"
21
+
22
+ describe Chef::SecretFetcher::AKeylessVault do
23
+ let(:node) { {} }
24
+ let(:run_context) { double("run_context", node: node) }
25
+
26
+ context "when validating provided AKeyless Vault configuration" do
27
+ it "raises ConfigurationInvalid when :secret_access_key is not provided" do
28
+ fetcher = Chef::SecretFetcher::AKeylessVault.new( { access_id: "provided" }, run_context)
29
+ expect { fetcher.validate! }.to raise_error(Chef::Exceptions::Secret::ConfigurationInvalid, /:secret_access_key/)
30
+ end
31
+
32
+ it "raises ConfigurationInvalid when :access_key_id is not provided" do
33
+ fetcher = Chef::SecretFetcher::AKeylessVault.new( { access_key: "provided" }, run_context)
34
+ expect { fetcher.validate! }.to raise_error(Chef::Exceptions::Secret::ConfigurationInvalid, /:access_key_id/)
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,70 @@
1
+ #
2
+ # Author:: Marc Paradise <marc@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
+
20
+ require_relative "../../spec_helper"
21
+ require "chef/secret_fetcher/aws_secrets_manager"
22
+
23
+ describe Chef::SecretFetcher::AWSSecretsManager do
24
+ let(:node) { {} }
25
+ let(:aws_global_config) { {} }
26
+ let(:fetcher_config) { {} }
27
+ let(:run_context) { double("run_context", node: node) }
28
+ let(:fetcher) {
29
+ Chef::SecretFetcher::AWSSecretsManager.new( fetcher_config, run_context )
30
+ }
31
+
32
+ before do
33
+ allow(Aws).to receive(:config).and_return(aws_global_config)
34
+ end
35
+
36
+ context "when region is provided" do
37
+ let(:fetcher_config) { { region: "region-from-caller" } }
38
+ it "uses the provided region" do
39
+ fetcher.validate!
40
+ expect(fetcher.config[:region]).to eq "region-from-caller"
41
+ end
42
+ end
43
+
44
+ context "when region is not provided" do
45
+ context "and no region exists in AWS config or node attributes" do
46
+ it "raises a ConfigurationInvalid error" do
47
+ expect { fetcher.validate! }.to raise_error Chef::Exceptions::Secret::ConfigurationInvalid
48
+ end
49
+ end
50
+
51
+ context "and region exists in AWS config and node attributes" do
52
+ let(:aws_global_config) { { region: "region-from-aws-global-config" } }
53
+ let(:node) { { "ec2" => { "region" => "region-from-ohai-data" } } }
54
+ it "uses the region from AWS config" do
55
+ fetcher.validate!
56
+ expect(fetcher.config[:region]).to eq "region-from-aws-global-config"
57
+ end
58
+ end
59
+
60
+ context "and region exists only in node attributes" do
61
+ let(:node) { { "ec2" => { "region" => "region-from-ohai-data" } } }
62
+ it "uses the region from AWS config" do
63
+ fetcher.validate!
64
+ expect(fetcher.config[:region]).to eq "region-from-ohai-data"
65
+ end
66
+
67
+ end
68
+
69
+ end
70
+ end
@@ -22,20 +22,11 @@ require "chef/secret_fetcher"
22
22
  require "chef/secret_fetcher/azure_key_vault"
23
23
 
24
24
  describe Chef::SecretFetcher::AzureKeyVault do
25
- let(:config) { { vault: "myvault" } }
26
- let(:fetcher) { Chef::SecretFetcher::AzureKeyVault.new(config) }
27
-
28
- context "when validating configuration and configuration is missing :vault" do
29
- context "and configuration does not have a 'vault'" do
30
- let(:config) { {} }
31
- it "raises a MissingVaultError error on validate!" do
32
- expect { fetcher.validate! }.to raise_error(Chef::Exceptions::Secret::MissingVaultName)
33
- end
34
- end
35
- end
25
+ let(:config) { { vault: "my_vault" } }
26
+ let(:fetcher) { Chef::SecretFetcher::AzureKeyVault.new(config, nil) }
36
27
 
37
28
  context "when performing a fetch" do
38
- let(:body) { "" }
29
+ let(:body) { '{ "value" : "my secret value" }' }
39
30
  let(:response_mock) { double("response", body: body) }
40
31
  let(:http_mock) { double("http", :get => response_mock, :use_ssl= => nil) }
41
32
 
@@ -44,20 +35,36 @@ describe Chef::SecretFetcher::AzureKeyVault do
44
35
  allow(Net::HTTP).to receive(:new).and_return(http_mock)
45
36
  end
46
37
 
47
- context "and a valid response is received" do
38
+ context "and vault name is only provided in the secret name" do
48
39
  let(:body) { '{ "value" : "my secret value" }' }
49
- it "returns the expected response" do
50
- expect(fetcher.fetch("value")).to eq "my secret value"
40
+ let(:config) { {} }
41
+ it "fetches the value" do
42
+ expect(fetcher.fetch("my_vault/value")).to eq "my secret value"
51
43
  end
52
44
  end
53
45
 
46
+ context "and vault name is not provided in the secret name" do
47
+ context "and vault name is not provided in config" do
48
+ let(:config) { {} }
49
+ it "raises a ConfigurationInvalid exception" do
50
+ expect { fetcher.fetch("value") }.to raise_error(Chef::Exceptions::Secret::ConfigurationInvalid)
51
+ end
52
+ end
53
+
54
+ context "and vault name is provided in config" do
55
+ let(:config) { { vault: "my_vault" } }
56
+ it "fetches the value" do
57
+ expect(fetcher.fetch("value")).to eq "my secret value"
58
+ end
59
+ end
60
+ end
54
61
  context "and an error response is received in the body" do
62
+ let(:config) { { vault: "my_vault" } }
55
63
  let(:body) { '{ "error" : { "code" : 404, "message" : "secret not found" } }' }
56
64
  it "raises FetchFailed" do
57
65
  expect { fetcher.fetch("value") }.to raise_error(Chef::Exceptions::Secret::FetchFailed)
58
66
  end
59
67
  end
60
-
61
68
  end
62
69
  end
63
70