chef 13.1.31 → 13.2.20

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +68 -134
  3. data/Rakefile +1 -0
  4. data/VERSION +1 -1
  5. data/acceptance/.shared/kitchen_acceptance/.kitchen.ec2.yml +1 -0
  6. data/acceptance/top-cookbooks/.kitchen.docker.yml +4 -0
  7. data/lib/chef/application/client.rb +27 -18
  8. data/lib/chef/deprecated.rb +10 -0
  9. data/lib/chef/dsl/declare_resource.rb +9 -1
  10. data/lib/chef/knife.rb +5 -1
  11. data/lib/chef/knife/cookbook_test.rb +1 -1
  12. data/lib/chef/policy_builder/policyfile.rb +27 -1
  13. data/lib/chef/provider.rb +2 -2
  14. data/lib/chef/provider/group/aix.rb +1 -1
  15. data/lib/chef/provider/group/groupadd.rb +1 -1
  16. data/lib/chef/provider/package/chocolatey.rb +1 -1
  17. data/lib/chef/provider/user/pw.rb +1 -1
  18. data/lib/chef/provider/user/windows.rb +1 -1
  19. data/lib/chef/resource/breakpoint.rb +1 -1
  20. data/lib/chef/version.rb +3 -1
  21. data/lib/chef/version_string.rb +143 -0
  22. data/spec/functional/mixin/powershell_out_spec.rb +20 -4
  23. data/spec/functional/resource/group_spec.rb +19 -13
  24. data/spec/functional/resource/windows_task_spec.rb +2 -9
  25. data/spec/integration/knife/common_options_spec.rb +29 -11
  26. data/spec/integration/knife/cookbook_bulk_delete_spec.rb +2 -2
  27. data/spec/integration/knife/cookbook_show_spec.rb +2 -2
  28. data/spec/integration/knife/environment_compare_spec.rb +2 -2
  29. data/spec/integration/knife/environment_show_spec.rb +2 -2
  30. data/spec/integration/knife/role_show_spec.rb +2 -2
  31. data/spec/integration/recipes/accumulator_spec.rb +6 -6
  32. data/spec/integration/recipes/resource_action_spec.rb +18 -7
  33. data/spec/integration/recipes/resource_load_spec.rb +5 -21
  34. data/spec/spec_helper.rb +2 -0
  35. data/spec/support/platform_helpers.rb +5 -0
  36. data/spec/support/shared/unit/provider/useradd_based_user_provider.rb +1 -1
  37. data/spec/unit/application/client_spec.rb +2 -0
  38. data/spec/unit/knife_spec.rb +22 -0
  39. data/spec/unit/policy_builder/policyfile_spec.rb +50 -0
  40. data/spec/unit/provider/group/groupadd_spec.rb +1 -1
  41. data/spec/unit/provider/user/pw_spec.rb +1 -1
  42. data/spec/unit/version_string_spec.rb +79 -0
  43. data/tasks/dependencies.rb +1 -42
  44. metadata +6 -79
  45. data/acceptance/.bundle/config +0 -2
  46. data/acceptance/bin/aws.rb +0 -17
  47. data/acceptance/bin/berks +0 -17
  48. data/acceptance/bin/bundler +0 -17
  49. data/acceptance/bin/chef-acceptance +0 -17
  50. data/acceptance/bin/coderay +0 -17
  51. data/acceptance/bin/erubis +0 -17
  52. data/acceptance/bin/htmldiff +0 -17
  53. data/acceptance/bin/httpclient +0 -17
  54. data/acceptance/bin/inspec +0 -17
  55. data/acceptance/bin/kitchen +0 -17
  56. data/acceptance/bin/ldiff +0 -17
  57. data/acceptance/bin/nokogiri +0 -17
  58. data/acceptance/bin/pry +0 -17
  59. data/acceptance/bin/rake +0 -17
  60. data/acceptance/bin/rspec +0 -17
  61. data/acceptance/bin/rwinrm +0 -17
  62. data/acceptance/bin/rwinrmcp +0 -17
  63. data/acceptance/bin/safe_yaml +0 -17
  64. data/acceptance/bin/thor +0 -17
  65. data/acceptance/fips/.kitchen/fips-unit-functional-centos-6.yml +0 -7
  66. data/acceptance/fips/.kitchen/kitchen-vagrant/kitchen-fips-fips-unit-functional-centos-6/.vagrant/machines/default/virtualbox/action_set_name +0 -1
  67. data/acceptance/fips/.kitchen/kitchen-vagrant/kitchen-fips-fips-unit-functional-centos-6/.vagrant/machines/default/virtualbox/creator_uid +0 -1
  68. data/acceptance/fips/.kitchen/kitchen-vagrant/kitchen-fips-fips-unit-functional-centos-6/.vagrant/machines/default/virtualbox/id +0 -1
  69. data/acceptance/fips/.kitchen/kitchen-vagrant/kitchen-fips-fips-unit-functional-centos-6/.vagrant/machines/default/virtualbox/index_uuid +0 -1
  70. data/acceptance/fips/.kitchen/kitchen-vagrant/kitchen-fips-fips-unit-functional-centos-6/.vagrant/machines/default/virtualbox/private_key +0 -27
  71. data/acceptance/fips/.kitchen/kitchen-vagrant/kitchen-fips-fips-unit-functional-centos-6/.vagrant/machines/default/virtualbox/synced_folders +0 -1
  72. data/acceptance/fips/.kitchen/kitchen-vagrant/kitchen-fips-fips-unit-functional-centos-6/Vagrantfile +0 -11
  73. data/acceptance/fips/.kitchen/logs/fips-integration-centos-6.log +0 -0
  74. data/acceptance/fips/.kitchen/logs/fips-integration-windows-2012r2.log +0 -0
  75. data/acceptance/fips/.kitchen/logs/fips-unit-functional-centos-6.log +0 -80
  76. data/acceptance/fips/.kitchen/logs/kitchen.log +0 -4
  77. data/tasks/bundle.rb +0 -73
@@ -22,6 +22,14 @@ describe "knife common options", :workstation do
22
22
  include IntegrationSupport
23
23
  include KnifeSupport
24
24
 
25
+ before do
26
+ # Allow this for testing the various port binding stuffs. Remove when
27
+ # we kill off --listen.
28
+ Chef::Config.treat_deprecation_warnings_as_errors(false)
29
+ end
30
+
31
+ let(:local_listen_warning) { /\Awarn:.*local.*listen.*$/i }
32
+
25
33
  when_the_repository "has a node" do
26
34
  before { file "nodes/x.json", {} }
27
35
 
@@ -30,15 +38,20 @@ describe "knife common options", :workstation do
30
38
  Chef::Config.chef_zero.enabled = true
31
39
  end
32
40
 
33
- it "knife raw /nodes/x should retrieve the node" do
41
+ it "knife raw /nodes/x should retrieve the node in socketless mode" do
42
+ Chef::Config.treat_deprecation_warnings_as_errors(true)
34
43
  knife("raw /nodes/x").should_succeed( /"name": "x"/ )
35
44
  end
36
45
 
46
+ it "knife raw /nodes/x should retrieve the node" do
47
+ knife("raw --listen /nodes/x").should_succeed( /"name": "x"/, stderr: local_listen_warning )
48
+ end
49
+
37
50
  context "And chef_zero.port is 9999" do
38
51
  before(:each) { Chef::Config.chef_zero.port = 9999 }
39
52
 
40
53
  it "knife raw /nodes/x should retrieve the node" do
41
- knife("raw /nodes/x").should_succeed( /"name": "x"/ )
54
+ knife("raw --listen /nodes/x").should_succeed( /"name": "x"/, stderr: local_listen_warning )
42
55
  expect(Chef::Config.chef_server_url).to eq("chefzero://localhost:9999")
43
56
  end
44
57
  end
@@ -48,7 +61,7 @@ describe "knife common options", :workstation do
48
61
  before(:each) { Chef::Config.chef_zero.host = "0.0.0.0" }
49
62
 
50
63
  it "knife raw /nodes/x should retrieve the role" do
51
- knife("raw /nodes/x").should_succeed( /"name": "x"/ )
64
+ knife("raw --listen /nodes/x").should_succeed( /"name": "x"/, stderr: local_listen_warning )
52
65
  end
53
66
  end
54
67
 
@@ -86,21 +99,26 @@ EOM
86
99
  end
87
100
 
88
101
  it "knife raw /nodes/x should retrieve the node" do
89
- knife("raw /nodes/x").should_succeed( /"name": "x"/ )
102
+ knife("raw --listen /nodes/x").should_succeed( /"name": "x"/, stderr: local_listen_warning )
90
103
  end
91
104
  end
92
105
  end
93
106
 
94
- it "knife raw -z /nodes/x retrieves the node" do
107
+ it "knife raw -z /nodes/x retrieves the node in socketless mode" do
108
+ Chef::Config.treat_deprecation_warnings_as_errors(true)
95
109
  knife("raw -z /nodes/x").should_succeed( /"name": "x"/ )
96
110
  end
97
111
 
112
+ it "knife raw -z /nodes/x retrieves the node" do
113
+ knife("raw -z --listen /nodes/x").should_succeed( /"name": "x"/, stderr: local_listen_warning )
114
+ end
115
+
98
116
  it "knife raw --local-mode /nodes/x retrieves the node" do
99
- knife("raw --local-mode /nodes/x").should_succeed( /"name": "x"/ )
117
+ knife("raw --local-mode --listen /nodes/x").should_succeed( /"name": "x"/, stderr: local_listen_warning )
100
118
  end
101
119
 
102
120
  it "knife raw -z --chef-zero-port=9999 /nodes/x retrieves the node" do
103
- knife("raw -z --chef-zero-port=9999 /nodes/x").should_succeed( /"name": "x"/ )
121
+ knife("raw -z --chef-zero-port=9999 --listen /nodes/x").should_succeed( /"name": "x"/, stderr: local_listen_warning )
104
122
  expect(Chef::Config.chef_server_url).to eq("chefzero://localhost:9999")
105
123
  end
106
124
 
@@ -118,7 +136,7 @@ EOM
118
136
  end
119
137
 
120
138
  it "knife raw -z /nodes/x retrieves the node" do
121
- knife("raw -z /nodes/x").should_succeed( /"name": "x"/ )
139
+ knife("raw -z --listen /nodes/x").should_succeed( /"name": "x"/, stderr: local_listen_warning )
122
140
  expect(URI(Chef::Config.chef_server_url).port).to be > 8889
123
141
  end
124
142
  end
@@ -137,18 +155,18 @@ EOM
137
155
  end
138
156
 
139
157
  it "knife raw -z --chef-zero-port=9999-20000 /nodes/x" do
140
- knife("raw -z --chef-zero-port=9999-20000 /nodes/x").should_succeed( /"name": "x"/ )
158
+ knife("raw -z --chef-zero-port=9999-20000 --listen /nodes/x").should_succeed( /"name": "x"/, stderr: local_listen_warning )
141
159
  expect(URI(Chef::Config.chef_server_url).port).to be > 9999
142
160
  end
143
161
 
144
162
  it "knife raw -z --chef-zero-port=9999-9999,19423" do
145
- knife("raw -z --chef-zero-port=9999-9999,19423 /nodes/x").should_succeed( /"name": "x"/ )
163
+ knife("raw -z --chef-zero-port=9999-9999,19423 --listen /nodes/x").should_succeed( /"name": "x"/, stderr: local_listen_warning )
146
164
  expect(URI(Chef::Config.chef_server_url).port).to be == 19423
147
165
  end
148
166
  end
149
167
 
150
168
  it "knife raw -z --chef-zero-port=9999 /nodes/x retrieves the node" do
151
- knife("raw -z --chef-zero-port=9999 /nodes/x").should_succeed( /"name": "x"/ )
169
+ knife("raw -z --chef-zero-port=9999 --listen /nodes/x").should_succeed( /"name": "x"/, stderr: local_listen_warning )
152
170
  expect(Chef::Config.chef_server_url).to eq("chefzero://localhost:9999")
153
171
  end
154
172
  end
@@ -34,7 +34,7 @@ describe "knife cookbook bulk delete", :workstation do
34
34
  cookbook "zfa", "0.6.5"
35
35
  end
36
36
 
37
- # rubocop:disable Style/TrailingWhitespace
37
+ # rubocop:disable Layout/TrailingWhitespace
38
38
  it "knife cookbook bulk delete deletes all matching cookbooks" do
39
39
  stdout = <<EOM
40
40
  All versions of the following cookbooks will be deleted:
@@ -58,7 +58,7 @@ fax 0.6.0
58
58
  zfa 0.6.5
59
59
  EOM
60
60
  end
61
- # rubocop:enable Style/TrailingWhitespace
61
+ # rubocop:enable Layout/TrailingWhitespace
62
62
 
63
63
  end
64
64
  end
@@ -34,7 +34,7 @@ describe "knife cookbook show", :workstation do
34
34
  knife("cookbook show x").should_succeed "x 1.0.0 0.6.5\n"
35
35
  end
36
36
 
37
- # rubocop:disable Style/TrailingWhitespace
37
+ # rubocop:disable Layout/TrailingWhitespace
38
38
  it "knife cookbook show x 1.0.0 shows the correct version" do
39
39
  knife("cookbook show x 1.0.0").should_succeed <<EOM
40
40
  cookbook_name: x
@@ -127,7 +127,7 @@ specificity: default
127
127
  url: http://127.0.0.1:8900/file_store/checksums/d41d8cd98f00b204e9800998ecf8427e
128
128
  EOM
129
129
  end
130
- # rubocop:enable Style/TrailingWhitespace
130
+ # rubocop:enable Layout/TrailingWhitespace
131
131
 
132
132
  it "knife cookbook show x 1.0.0 recipes default.rb shows the default recipe" do
133
133
  knife("cookbook show x 1.0.0 recipes default.rb").should_succeed "file 'n'\n"
@@ -42,7 +42,7 @@ describe "knife environment compare", :workstation do
42
42
  }
43
43
  end
44
44
 
45
- # rubocop:disable Style/TrailingWhitespace
45
+ # rubocop:disable Layout/TrailingWhitespace
46
46
  it "displays the cookbooks for a single environment" do
47
47
  knife("environment compare x").should_succeed <<EOM
48
48
  x
@@ -69,6 +69,6 @@ krad >= 1.0.0 >= 1.0.0
69
69
 
70
70
  EOM
71
71
  end
72
- # rubocop:enable Style/TrailingWhitespace
72
+ # rubocop:enable Layout/TrailingWhitespace
73
73
  end
74
74
  end
@@ -30,7 +30,7 @@ describe "knife environment show", :workstation do
30
30
  }
31
31
  end
32
32
 
33
- # rubocop:disable Style/TrailingWhitespace
33
+ # rubocop:disable Layout/TrailingWhitespace
34
34
  it "shows an environment" do
35
35
  knife("environment show b").should_succeed <<EOM
36
36
  chef_type: environment
@@ -45,7 +45,7 @@ name: b
45
45
  override_attributes:
46
46
  EOM
47
47
  end
48
- # rubocop:enable Style/TrailingWhitespace
48
+ # rubocop:enable Layout/TrailingWhitespace
49
49
 
50
50
  it "shows the requested attribute of an environment" do
51
51
  knife("environment show b -a default_attributes").should_succeed <<EOM
@@ -31,7 +31,7 @@ describe "knife role show", :workstation do
31
31
  role "cat", {}
32
32
  end
33
33
 
34
- # rubocop:disable Style/TrailingWhitespace
34
+ # rubocop:disable Layout/TrailingWhitespace
35
35
  it "shows a cookbook" do
36
36
  knife("role show cons").should_succeed <<EOM
37
37
  chef_type: role
@@ -44,7 +44,7 @@ override_attributes:
44
44
  run_list:
45
45
  EOM
46
46
  end
47
- # rubocop:enable Style/TrailingWhitespace
47
+ # rubocop:enable Layout/TrailingWhitespace
48
48
 
49
49
  end
50
50
  end
@@ -62,7 +62,7 @@ describe "Accumulators" do
62
62
  default_action :create
63
63
 
64
64
  action :create do
65
- email_alias address do
65
+ email_alias new_resource.address do
66
66
  recipients new_resource.recipients
67
67
  end
68
68
  end
@@ -78,7 +78,7 @@ describe "Accumulators" do
78
78
  default_action :create
79
79
 
80
80
  action :create do
81
- nested address do
81
+ nested new_resource.address do
82
82
  recipients new_resource.recipients
83
83
  end
84
84
  end
@@ -149,8 +149,8 @@ describe "Accumulators" do
149
149
  delayed_action :create
150
150
  end
151
151
  end
152
- r.variables[:aliases][address] ||= []
153
- r.variables[:aliases][address] += new_resource.recipients
152
+ r.variables[:aliases][new_resource.address] ||= []
153
+ r.variables[:aliases][new_resource.address] += new_resource.recipients
154
154
  end
155
155
  EOM
156
156
 
@@ -164,7 +164,7 @@ describe "Accumulators" do
164
164
  default_action :create
165
165
 
166
166
  action :create do
167
- email_alias address do
167
+ email_alias new_resource.address do
168
168
  recipients new_resource.recipients
169
169
  end
170
170
  end
@@ -180,7 +180,7 @@ describe "Accumulators" do
180
180
  default_action :create
181
181
 
182
182
  action :create do
183
- nested address do
183
+ nested new_resource.address do
184
184
  recipients new_resource.recipients
185
185
  end
186
186
  end
@@ -416,6 +416,7 @@ module ResourceActionSpec
416
416
  attr_reader :x_warning_line
417
417
 
418
418
  it "Using the enclosing resource to set x to x emits a warning that you're using the wrong x" do
419
+ Chef::Config[:treat_deprecation_warnings_as_errors] = false
419
420
  recipe = converge do
420
421
  resource_action_spec_also_with_x "hi" do
421
422
  x 1
@@ -423,34 +424,43 @@ module ResourceActionSpec
423
424
  end
424
425
  end
425
426
  warnings = recipe.logs.lines.select { |l| l =~ /warn/i }
426
- expect(warnings.size).to eq 1
427
+ expect(warnings.size).to eq 2
427
428
  expect(warnings[0]).to match(/property x is declared in both resource_action_spec_with_x\[hi\] and resource_action_spec_also_with_x\[hi\] action :set_x_to_x. Use new_resource.x instead. At #{__FILE__}:#{ResourceActionSpecAlsoWithX.x_warning_line}/)
428
429
  end
429
430
 
430
431
  it "Using the enclosing resource to set x to x outside the initializer emits no warning" do
431
- expect_recipe do
432
+ Chef::Config[:treat_deprecation_warnings_as_errors] = false
433
+ recipe = converge do
432
434
  resource_action_spec_also_with_x "hi" do
433
435
  x 1
434
436
  action :set_x_to_x_in_non_initializer
435
437
  end
436
- end.to emit_no_warnings_or_errors
438
+ end
439
+ warnings = recipe.logs.lines.select { |l| l =~ /warn/i }
440
+ expect(warnings.size).to eq 1 # the deprecation warning, not the property masking one
437
441
  end
438
442
 
439
443
  it "Using the enclosing resource to set x to 10 emits no warning" do
440
- expect_recipe do
444
+ Chef::Config[:treat_deprecation_warnings_as_errors] = false
445
+ recipe = converge do
441
446
  resource_action_spec_also_with_x "hi" do
442
447
  x 1
443
448
  action :set_x_to_10
444
449
  end
445
- end.to emit_no_warnings_or_errors
450
+ end
451
+ warnings = recipe.logs.lines.select { |l| l =~ /warn/i }
452
+ expect(warnings.size).to eq 1 # the deprecation warning, not the property masking one
446
453
  end
447
454
 
448
455
  it "Using the enclosing resource to set x to 10 emits no warning" do
449
- expect_recipe do
456
+ Chef::Config[:treat_deprecation_warnings_as_errors] = false
457
+ recipe = converge do
450
458
  r = resource_action_spec_also_with_x "hi"
451
459
  r.x 1
452
460
  r.action :set_x_to_10
453
- end.to emit_no_warnings_or_errors
461
+ end
462
+ warnings = recipe.logs.lines.select { |l| l =~ /warn/i }
463
+ expect(warnings.size).to eq 1 # the deprecation warning, not the property masking one
454
464
  end
455
465
  end
456
466
 
@@ -496,6 +506,7 @@ module ResourceActionSpec
496
506
  end
497
507
 
498
508
  it "Raises an error when attempting to use a template in the action" do
509
+ Chef::Config[:treat_deprecation_warnings_as_errors] = false
499
510
  expect_converge do
500
511
  has_property_named_template "hi"
501
512
  end.to raise_error(/Property `template` of `has_property_named_template\[hi\]` was incorrectly passed a block. Possible property-resource collision. To call a resource named `template` either rename the property or else use `declare_resource\(:template, ...\)`/)
@@ -32,7 +32,7 @@ describe "Resource.load_current_value" do
32
32
  @created
33
33
  end
34
34
  action :create do
35
- new_resource.class.created_x = x
35
+ new_resource.class.created_x = new_resource.x
36
36
  end
37
37
  end
38
38
  result.resource_name resource_name
@@ -45,10 +45,10 @@ describe "Resource.load_current_value" do
45
45
  context "with a resource with load_current_value" do
46
46
  before :each do
47
47
  resource_class.load_current_value do
48
- x "loaded #{Namer.incrementing_value} (#{self.class.properties.sort_by { |name, p| name }.
49
- select { |name, p| p.is_set?(self) }.
50
- map { |name, p| "#{name}=#{p.get(self)}" }.
51
- join(", ")})"
48
+ x "loaded #{Namer.incrementing_value} (#{self.class.properties.sort_by { |name, p| name }
49
+ .select { |name, p| p.is_set?(self) }
50
+ .map { |name, p| "#{name}=#{p.get(self)}" }
51
+ .join(", ")})"
52
52
  end
53
53
  end
54
54
 
@@ -119,22 +119,6 @@ describe "Resource.load_current_value" do
119
119
  end
120
120
  end
121
121
 
122
- context "and a resource with no values set" do
123
- let(:resource) do
124
- e = self
125
- r = nil
126
- converge do
127
- r = public_send(e.resource_name, "blah") do
128
- end
129
- end
130
- r
131
- end
132
-
133
- it "the provider accesses values from load_current_value" do
134
- expect(resource.class.created_x).to eq "loaded 1 (name=blah)"
135
- end
136
- end
137
-
138
122
  let (:subresource_name) do
139
123
  :"load_current_value_subresource_dsl#{Namer.current_index}"
140
124
  end
@@ -149,6 +149,8 @@ RSpec.configure do |config|
149
149
  config.filter_run_excluding :windows64_only => true unless windows64?
150
150
  config.filter_run_excluding :windows32_only => true unless windows32?
151
151
  config.filter_run_excluding :windows_nano_only => true unless windows_nano_server?
152
+ config.filter_run_excluding :windows_gte_10 => true unless windows_gte_10?
153
+ config.filter_run_excluding :windows_lt_10 => true if windows_gte_10?
152
154
  config.filter_run_excluding :ruby64_only => true unless ruby_64bit?
153
155
  config.filter_run_excluding :ruby32_only => true unless ruby_32bit?
154
156
  config.filter_run_excluding :windows_powershell_dsc_only => true unless windows_powershell_dsc?
@@ -70,6 +70,11 @@ def windows_2012r2?
70
70
  (host_version && host_version.start_with?("6.3"))
71
71
  end
72
72
 
73
+ def windows_gte_10?
74
+ return false unless windows?
75
+ Gem::Requirement.new(">= 10").satisfied_by?(Gem::Version.new(host_version))
76
+ end
77
+
73
78
  def host_version
74
79
  @host_version ||= begin
75
80
  wmi = WmiLite::Wmi.new
@@ -85,7 +85,7 @@ shared_examples_for "a useradd-based user provider" do |supported_useradd_option
85
85
 
86
86
  it "should combine all the possible options" do
87
87
  combined_opts = []
88
- supported_useradd_options.sort { |a, b| a[0] <=> b[0] }.each do |attribute, option|
88
+ supported_useradd_options.sort_by { |a| a[0] }.each do |attribute, option|
89
89
  allow(@new_resource).to receive(attribute).and_return("hola")
90
90
  combined_opts << option << "hola"
91
91
  end
@@ -257,6 +257,7 @@ Enable chef-client interval runs by setting `:client_fork = true` in your config
257
257
  before do
258
258
  allow(@app).to receive(:interval_sleep).with(wait_secs).and_return true
259
259
  allow(@app).to receive(:interval_sleep).with(0).and_call_original
260
+ allow(@app).to receive(:time_to_sleep).and_return(1)
260
261
  end
261
262
 
262
263
  it "sleeps for the amount of time passed" do
@@ -519,6 +520,7 @@ describe Chef::Application::Client, "run_application", :unix_only do
519
520
  end
520
521
 
521
522
  it "shouldn't sleep when sent USR1" do
523
+ allow(@app).to receive(:interval_sleep).and_return true
522
524
  allow(@app).to receive(:interval_sleep).with(0).and_call_original
523
525
  pid = fork do
524
526
  @app.run_application
@@ -439,6 +439,28 @@ describe Chef::Knife do
439
439
  expect(stderr.string).to match(%r{Response: y u no administrator})
440
440
  end
441
441
 
442
+ context "when proxy servers are set" do
443
+ before do
444
+ ENV["http_proxy"] = "xyz"
445
+ end
446
+
447
+ after do
448
+ ENV.delete("http_proxy")
449
+ end
450
+
451
+ it "formats proxy errors nicely" do
452
+ response = Net::HTTPForbidden.new("1.1", "403", "Forbidden")
453
+ response.instance_variable_set(:@read, true)
454
+ allow(response).to receive(:body).and_return(Chef::JSONCompat.to_json(:error => "y u no administrator"))
455
+ allow(knife).to receive(:run).and_raise(Net::HTTPServerException.new("403 Forbidden", response))
456
+ allow(knife).to receive(:username).and_return("sadpanda")
457
+ knife.run_with_pretty_exceptions
458
+ expect(stderr.string).to match(%r{ERROR: You authenticated successfully to http.+ as sadpanda but you are not authorized for this action})
459
+ expect(stderr.string).to match(%r{ERROR: There are proxy servers configured, your Chef server may need to be added to NO_PROXY.})
460
+ expect(stderr.string).to match(%r{Response: y u no administrator})
461
+ end
462
+ end
463
+
442
464
  it "formats 400s nicely" do
443
465
  response = Net::HTTPBadRequest.new("1.1", "400", "Bad Request")
444
466
  response.instance_variable_set(:@read, true) # I hate you, net/http.
@@ -330,6 +330,56 @@ describe Chef::PolicyBuilder::Policyfile do
330
330
 
331
331
  end
332
332
 
333
+ describe "#build_node" do
334
+
335
+ let(:node) do
336
+ node = Chef::Node.new
337
+ node.name(node_name)
338
+ node
339
+ end
340
+
341
+ before do
342
+ allow(policy_builder).to receive(:node).and_return(node)
343
+ end
344
+
345
+ context "when the run is successful" do
346
+ let(:run_list) do
347
+ ["recipe[test::default]",
348
+ "recipe[test::other]"]
349
+ end
350
+
351
+ let(:version_hash) do
352
+ {
353
+ "version" => "0.1.0",
354
+ "identifier" => "012345678",
355
+ }
356
+ end
357
+
358
+ let(:run_list_for_data_collector) do
359
+ {
360
+ :id => "_policy_node",
361
+ :run_list => [
362
+ { :type => "recipe", :name => "test::default", :skipped => false, :version => nil },
363
+ { :type => "recipe", :name => "test::other", :skipped => false, :version => nil },
364
+ ],
365
+ }
366
+ end
367
+
368
+ before do
369
+ allow(policy_builder).to receive(:run_list)
370
+ .and_return(run_list)
371
+ allow(policy_builder).to receive(:cookbook_lock_for)
372
+ .and_return(version_hash)
373
+ end
374
+
375
+ it "sends the run_list_expanded event" do
376
+ policy_builder.build_node
377
+ expect(policy_builder.run_list_expansion_ish.to_hash)
378
+ .to eq(run_list_for_data_collector)
379
+ end
380
+ end
381
+ end
382
+
333
383
  describe "building the node object" do
334
384
 
335
385
  let(:extra_chef_config) { {} }