chef 12.4.0-universal-mingw32 → 12.4.1-universal-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/chef/api_client.rb +31 -129
- data/lib/chef/api_client_v1.rb +325 -0
- data/lib/chef/chef_class.rb +15 -7
- data/lib/chef/chef_fs/file_system/chef_server_root_dir.rb +2 -2
- data/lib/chef/dsl/resources.rb +6 -4
- data/lib/chef/exceptions.rb +2 -2
- data/lib/chef/guard_interpreter/resource_guard_interpreter.rb +2 -1
- data/lib/chef/knife/bootstrap/templates/chef-full.erb +4 -4
- data/lib/chef/knife/client_bulk_delete.rb +2 -2
- data/lib/chef/knife/client_create.rb +4 -4
- data/lib/chef/knife/client_delete.rb +3 -3
- data/lib/chef/knife/client_edit.rb +10 -2
- data/lib/chef/knife/client_list.rb +2 -2
- data/lib/chef/knife/client_reregister.rb +2 -2
- data/lib/chef/knife/client_show.rb +2 -2
- data/lib/chef/knife/osc_user_create.rb +3 -3
- data/lib/chef/knife/osc_user_delete.rb +2 -2
- data/lib/chef/knife/osc_user_edit.rb +3 -3
- data/lib/chef/knife/osc_user_list.rb +2 -2
- data/lib/chef/knife/osc_user_reregister.rb +2 -2
- data/lib/chef/knife/osc_user_show.rb +2 -2
- data/lib/chef/knife/user_create.rb +3 -3
- data/lib/chef/knife/user_delete.rb +4 -4
- data/lib/chef/knife/user_edit.rb +3 -3
- data/lib/chef/knife/user_list.rb +2 -2
- data/lib/chef/knife/user_reregister.rb +2 -2
- data/lib/chef/knife/user_show.rb +2 -2
- data/lib/chef/node_map.rb +14 -18
- data/lib/chef/platform/handler_map.rb +45 -0
- data/lib/chef/platform/priority_map.rb +19 -32
- data/lib/chef/platform/provider_handler_map.rb +29 -0
- data/lib/chef/platform/provider_mapping.rb +3 -2
- data/lib/chef/platform/resource_handler_map.rb +29 -0
- data/lib/chef/platform/resource_priority_map.rb +0 -6
- data/lib/chef/provider.rb +1 -1
- data/lib/chef/provider/dsc_resource.rb +2 -2
- data/lib/chef/provider/dsc_script.rb +1 -1
- data/lib/chef/provider/mount/aix.rb +1 -1
- data/lib/chef/provider/package.rb +0 -31
- data/lib/chef/provider/package/aix.rb +1 -0
- data/lib/chef/provider/package/apt.rb +1 -0
- data/lib/chef/provider/package/homebrew.rb +1 -0
- data/lib/chef/provider/package/ips.rb +1 -0
- data/lib/chef/provider/package/macports.rb +1 -0
- data/lib/chef/provider/package/openbsd.rb +1 -0
- data/lib/chef/provider/package/pacman.rb +1 -0
- data/lib/chef/provider/package/paludis.rb +1 -0
- data/lib/chef/provider/package/portage.rb +2 -0
- data/lib/chef/provider/package/smartos.rb +1 -0
- data/lib/chef/provider/package/solaris.rb +2 -0
- data/lib/chef/provider/package/yum.rb +1 -0
- data/lib/chef/provider/package/zypper.rb +1 -0
- data/lib/chef/provider/service.rb +4 -22
- data/lib/chef/provider/service/debian.rb +2 -0
- data/lib/chef/provider/service/insserv.rb +2 -0
- data/lib/chef/provider/service/invokercd.rb +2 -0
- data/lib/chef/provider/service/openbsd.rb +1 -1
- data/lib/chef/provider/service/redhat.rb +2 -0
- data/lib/chef/provider/service/upstart.rb +3 -0
- data/lib/chef/provider_resolver.rb +59 -53
- data/lib/chef/resource.rb +22 -73
- data/lib/chef/resource/dsc_script.rb +1 -1
- data/lib/chef/resource/ips_package.rb +1 -0
- data/lib/chef/resource/mount.rb +8 -0
- data/lib/chef/resource/openbsd_package.rb +0 -11
- data/lib/chef/resource/solaris_package.rb +1 -4
- data/lib/chef/resource_resolver.rb +54 -26
- data/lib/chef/run_list/versioned_recipe_list.rb +6 -5
- data/lib/chef/user.rb +52 -188
- data/lib/chef/user_v1.rb +335 -0
- data/lib/chef/version.rb +1 -1
- data/spec/data/trusted_certs/opscode.pem +53 -56
- data/spec/functional/provider/whyrun_safe_ruby_block_spec.rb +1 -1
- data/spec/functional/resource/package_spec.rb +0 -2
- data/spec/integration/recipes/recipe_dsl_spec.rb +661 -126
- data/spec/spec_helper.rb +19 -13
- data/spec/support/shared/unit/api_versioning.rb +2 -2
- data/spec/unit/api_client_spec.rb +22 -201
- data/spec/unit/api_client_v1_spec.rb +457 -0
- data/spec/unit/knife/client_bulk_delete_spec.rb +4 -4
- data/spec/unit/knife/client_create_spec.rb +1 -1
- data/spec/unit/knife/client_delete_spec.rb +3 -3
- data/spec/unit/knife/client_edit_spec.rb +14 -1
- data/spec/unit/knife/client_list_spec.rb +1 -1
- data/spec/unit/knife/client_reregister_spec.rb +2 -2
- data/spec/unit/knife/client_show_spec.rb +2 -2
- data/spec/unit/knife/osc_user_create_spec.rb +5 -5
- data/spec/unit/knife/osc_user_delete_spec.rb +1 -1
- data/spec/unit/knife/osc_user_edit_spec.rb +1 -1
- data/spec/unit/knife/osc_user_list_spec.rb +1 -1
- data/spec/unit/knife/osc_user_reregister_spec.rb +1 -1
- data/spec/unit/knife/osc_user_show_spec.rb +1 -1
- data/spec/unit/knife/user_create_spec.rb +1 -1
- data/spec/unit/knife/user_delete_spec.rb +2 -2
- data/spec/unit/knife/user_edit_spec.rb +2 -2
- data/spec/unit/knife/user_list_spec.rb +1 -1
- data/spec/unit/knife/user_reregister_spec.rb +1 -1
- data/spec/unit/knife/user_show_spec.rb +2 -2
- data/spec/unit/lwrp_spec.rb +146 -134
- data/spec/unit/node_map_spec.rb +12 -0
- data/spec/unit/platform_spec.rb +1 -1
- data/spec/unit/provider/deploy_spec.rb +1 -1
- data/spec/unit/provider/dsc_resource_spec.rb +3 -3
- data/spec/unit/provider/dsc_script_spec.rb +2 -2
- data/spec/unit/provider_resolver_spec.rb +170 -135
- data/spec/unit/recipe_spec.rb +3 -3
- data/spec/unit/resource/breakpoint_spec.rb +1 -1
- data/spec/unit/resource/cron_spec.rb +1 -1
- data/spec/unit/resource/directory_spec.rb +1 -1
- data/spec/unit/resource/dsc_resource_spec.rb +1 -1
- data/spec/unit/resource/dsc_script_spec.rb +2 -2
- data/spec/unit/resource/env_spec.rb +1 -1
- data/spec/unit/resource/erl_call_spec.rb +1 -1
- data/spec/unit/resource/file_spec.rb +1 -1
- data/spec/unit/resource/group_spec.rb +1 -1
- data/spec/unit/resource/link_spec.rb +1 -1
- data/spec/unit/resource/mdadm_spec.rb +1 -1
- data/spec/unit/resource/mount_spec.rb +1 -1
- data/spec/unit/resource/ohai_spec.rb +1 -1
- data/spec/unit/resource/registry_key_spec.rb +1 -1
- data/spec/unit/resource/route_spec.rb +1 -1
- data/spec/unit/resource/ruby_block_spec.rb +3 -3
- data/spec/unit/resource/user_spec.rb +1 -1
- data/spec/unit/resource/windows_service_spec.rb +1 -1
- data/spec/unit/resource_resolver_spec.rb +8 -4
- data/spec/unit/resource_spec.rb +89 -3
- data/spec/unit/run_list/versioned_recipe_list_spec.rb +115 -48
- data/spec/unit/user_spec.rb +97 -405
- data/spec/unit/user_v1_spec.rb +584 -0
- metadata +11 -6
- data/lib/chef/osc_user.rb +0 -194
- data/spec/unit/osc_user_spec.rb +0 -276
data/spec/unit/user_spec.rb
CHANGED
@@ -16,6 +16,11 @@
|
|
16
16
|
# limitations under the License.
|
17
17
|
#
|
18
18
|
|
19
|
+
# DEPRECATION NOTE
|
20
|
+
# This code only remains to support users still operating with
|
21
|
+
# Open Source Chef Server 11 and should be removed once support
|
22
|
+
# for OSC 11 ends. New development should occur in user_spec.rb.
|
23
|
+
|
19
24
|
require 'spec_helper'
|
20
25
|
|
21
26
|
require 'chef/user'
|
@@ -26,141 +31,98 @@ describe Chef::User do
|
|
26
31
|
@user = Chef::User.new
|
27
32
|
end
|
28
33
|
|
29
|
-
shared_examples_for "string fields with no contraints" do
|
30
|
-
it "should let you set the public key" do
|
31
|
-
expect(@user.send(method, "some_string")).to eq("some_string")
|
32
|
-
end
|
33
|
-
|
34
|
-
it "should return the current public key" do
|
35
|
-
@user.send(method, "some_string")
|
36
|
-
expect(@user.send(method)).to eq("some_string")
|
37
|
-
end
|
38
|
-
|
39
|
-
it "should throw an ArgumentError if you feed it something lame" do
|
40
|
-
expect { @user.send(method, Hash.new) }.to raise_error(ArgumentError)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
shared_examples_for "boolean fields with no constraints" do
|
45
|
-
it "should let you set the field" do
|
46
|
-
expect(@user.send(method, true)).to eq(true)
|
47
|
-
end
|
48
|
-
|
49
|
-
it "should return the current field value" do
|
50
|
-
@user.send(method, true)
|
51
|
-
expect(@user.send(method)).to eq(true)
|
52
|
-
end
|
53
|
-
|
54
|
-
it "should return the false value when false" do
|
55
|
-
@user.send(method, false)
|
56
|
-
expect(@user.send(method)).to eq(false)
|
57
|
-
end
|
58
|
-
|
59
|
-
it "should throw an ArgumentError if you feed it anything but true or false" do
|
60
|
-
expect { @user.send(method, Hash.new) }.to raise_error(ArgumentError)
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
34
|
describe "initialize" do
|
65
35
|
it "should be a Chef::User" do
|
66
36
|
expect(@user).to be_a_kind_of(Chef::User)
|
67
37
|
end
|
68
38
|
end
|
69
39
|
|
70
|
-
describe "
|
71
|
-
it "should let you set the
|
72
|
-
expect(@user.
|
40
|
+
describe "name" do
|
41
|
+
it "should let you set the name to a string" do
|
42
|
+
expect(@user.name("ops_master")).to eq("ops_master")
|
73
43
|
end
|
74
44
|
|
75
|
-
it "should return the current
|
76
|
-
@user.
|
77
|
-
expect(@user.
|
45
|
+
it "should return the current name" do
|
46
|
+
@user.name "ops_master"
|
47
|
+
expect(@user.name).to eq("ops_master")
|
78
48
|
end
|
79
49
|
|
80
50
|
# It is not feasible to check all invalid characters. Here are a few
|
81
51
|
# that we probably care about.
|
82
52
|
it "should not accept invalid characters" do
|
83
53
|
# capital letters
|
84
|
-
expect { @user.
|
54
|
+
expect { @user.name "Bar" }.to raise_error(ArgumentError)
|
85
55
|
# slashes
|
86
|
-
expect { @user.
|
56
|
+
expect { @user.name "foo/bar" }.to raise_error(ArgumentError)
|
87
57
|
# ?
|
88
|
-
expect { @user.
|
58
|
+
expect { @user.name "foo?" }.to raise_error(ArgumentError)
|
89
59
|
# &
|
90
|
-
expect { @user.
|
60
|
+
expect { @user.name "foo&" }.to raise_error(ArgumentError)
|
91
61
|
end
|
92
62
|
|
93
63
|
|
94
64
|
it "should not accept spaces" do
|
95
|
-
expect { @user.
|
65
|
+
expect { @user.name "ops master" }.to raise_error(ArgumentError)
|
96
66
|
end
|
97
67
|
|
98
68
|
it "should throw an ArgumentError if you feed it anything but a string" do
|
99
|
-
expect { @user.
|
69
|
+
expect { @user.name Hash.new }.to raise_error(ArgumentError)
|
100
70
|
end
|
101
71
|
end
|
102
72
|
|
103
|
-
describe "
|
104
|
-
|
105
|
-
|
106
|
-
let(:method) { :create_key }
|
107
|
-
end
|
73
|
+
describe "admin" do
|
74
|
+
it "should let you set the admin bit" do
|
75
|
+
expect(@user.admin(true)).to eq(true)
|
108
76
|
end
|
109
|
-
end
|
110
77
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
let(:method) { :public_key }
|
115
|
-
end
|
78
|
+
it "should return the current admin value" do
|
79
|
+
@user.admin true
|
80
|
+
expect(@user.admin).to eq(true)
|
116
81
|
end
|
117
82
|
|
118
|
-
|
119
|
-
|
120
|
-
let(:method) { :private_key }
|
121
|
-
end
|
83
|
+
it "should default to false" do
|
84
|
+
expect(@user.admin).to eq(false)
|
122
85
|
end
|
123
86
|
|
124
|
-
|
125
|
-
|
126
|
-
let(:method) { :display_name }
|
127
|
-
end
|
87
|
+
it "should throw an ArgumentError if you feed it anything but true or false" do
|
88
|
+
expect { @user.name Hash.new }.to raise_error(ArgumentError)
|
128
89
|
end
|
90
|
+
end
|
129
91
|
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
end
|
92
|
+
describe "public_key" do
|
93
|
+
it "should let you set the public key" do
|
94
|
+
expect(@user.public_key("super public")).to eq("super public")
|
134
95
|
end
|
135
96
|
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
end
|
97
|
+
it "should return the current public key" do
|
98
|
+
@user.public_key("super public")
|
99
|
+
expect(@user.public_key).to eq("super public")
|
140
100
|
end
|
141
101
|
|
142
|
-
|
143
|
-
|
144
|
-
let(:method) { :last_name }
|
145
|
-
end
|
102
|
+
it "should throw an ArgumentError if you feed it something lame" do
|
103
|
+
expect { @user.public_key Hash.new }.to raise_error(ArgumentError)
|
146
104
|
end
|
105
|
+
end
|
147
106
|
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
end
|
107
|
+
describe "private_key" do
|
108
|
+
it "should let you set the private key" do
|
109
|
+
expect(@user.private_key("super private")).to eq("super private")
|
152
110
|
end
|
153
111
|
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
112
|
+
it "should return the private key" do
|
113
|
+
@user.private_key("super private")
|
114
|
+
expect(@user.private_key).to eq("super private")
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should throw an ArgumentError if you feed it something lame" do
|
118
|
+
expect { @user.private_key Hash.new }.to raise_error(ArgumentError)
|
158
119
|
end
|
159
120
|
end
|
160
121
|
|
161
122
|
describe "when serializing to JSON" do
|
162
123
|
before(:each) do
|
163
|
-
@user.
|
124
|
+
@user.name("black")
|
125
|
+
@user.public_key("crowes")
|
164
126
|
@json = @user.to_json
|
165
127
|
end
|
166
128
|
|
@@ -168,62 +130,16 @@ describe Chef::User do
|
|
168
130
|
expect(@json).to match(/^\{.+\}$/)
|
169
131
|
end
|
170
132
|
|
171
|
-
it "includes the
|
172
|
-
expect(@json).to include(%q{"
|
173
|
-
end
|
174
|
-
|
175
|
-
it "includes the display name when present" do
|
176
|
-
@user.display_name("get_displayed")
|
177
|
-
expect(@user.to_json).to include(%{"display_name":"get_displayed"})
|
178
|
-
end
|
179
|
-
|
180
|
-
it "does not include the display name if not present" do
|
181
|
-
expect(@json).not_to include("display_name")
|
182
|
-
end
|
183
|
-
|
184
|
-
it "includes the first name when present" do
|
185
|
-
@user.first_name("char")
|
186
|
-
expect(@user.to_json).to include(%{"first_name":"char"})
|
187
|
-
end
|
188
|
-
|
189
|
-
it "does not include the first name if not present" do
|
190
|
-
expect(@json).not_to include("first_name")
|
191
|
-
end
|
192
|
-
|
193
|
-
it "includes the middle name when present" do
|
194
|
-
@user.middle_name("man")
|
195
|
-
expect(@user.to_json).to include(%{"middle_name":"man"})
|
196
|
-
end
|
197
|
-
|
198
|
-
it "does not include the middle name if not present" do
|
199
|
-
expect(@json).not_to include("middle_name")
|
200
|
-
end
|
201
|
-
|
202
|
-
it "includes the last name when present" do
|
203
|
-
@user.last_name("der")
|
204
|
-
expect(@user.to_json).to include(%{"last_name":"der"})
|
205
|
-
end
|
206
|
-
|
207
|
-
it "does not include the last name if not present" do
|
208
|
-
expect(@json).not_to include("last_name")
|
209
|
-
end
|
210
|
-
|
211
|
-
it "includes the email when present" do
|
212
|
-
@user.email("charmander@pokemon.poke")
|
213
|
-
expect(@user.to_json).to include(%{"email":"charmander@pokemon.poke"})
|
214
|
-
end
|
215
|
-
|
216
|
-
it "does not include the email if not present" do
|
217
|
-
expect(@json).not_to include("email")
|
133
|
+
it "includes the name value" do
|
134
|
+
expect(@json).to include(%q{"name":"black"})
|
218
135
|
end
|
219
136
|
|
220
|
-
it "includes the public key
|
221
|
-
@
|
222
|
-
expect(@user.to_json).to include(%{"public_key":"crowes"})
|
137
|
+
it "includes the public key value" do
|
138
|
+
expect(@json).to include(%{"public_key":"crowes"})
|
223
139
|
end
|
224
140
|
|
225
|
-
it "
|
226
|
-
expect(@json).
|
141
|
+
it "includes the 'admin' flag" do
|
142
|
+
expect(@json).to include(%q{"admin":false})
|
227
143
|
end
|
228
144
|
|
229
145
|
it "includes the private key when present" do
|
@@ -251,18 +167,11 @@ describe Chef::User do
|
|
251
167
|
|
252
168
|
describe "when deserializing from JSON" do
|
253
169
|
before(:each) do
|
254
|
-
user = {
|
255
|
-
"username" => "mr_spinks",
|
256
|
-
"display_name" => "displayed",
|
257
|
-
"first_name" => "char",
|
258
|
-
"middle_name" => "man",
|
259
|
-
"last_name" => "der",
|
260
|
-
"email" => "charmander@pokemon.poke",
|
261
|
-
"password" => "password",
|
170
|
+
user = { "name" => "mr_spinks",
|
262
171
|
"public_key" => "turtles",
|
263
172
|
"private_key" => "pandas",
|
264
|
-
"
|
265
|
-
|
173
|
+
"password" => "password",
|
174
|
+
"admin" => true }
|
266
175
|
@user = Chef::User.from_json(Chef::JSONCompat.to_json(user))
|
267
176
|
end
|
268
177
|
|
@@ -270,277 +179,34 @@ describe Chef::User do
|
|
270
179
|
expect(@user).to be_a_kind_of(Chef::User)
|
271
180
|
end
|
272
181
|
|
273
|
-
it "preserves the
|
274
|
-
expect(@user.
|
275
|
-
end
|
276
|
-
|
277
|
-
it "preserves the display name if present" do
|
278
|
-
expect(@user.display_name).to eq("displayed")
|
182
|
+
it "preserves the name" do
|
183
|
+
expect(@user.name).to eq("mr_spinks")
|
279
184
|
end
|
280
185
|
|
281
|
-
it "preserves the
|
282
|
-
expect(@user.
|
283
|
-
end
|
284
|
-
|
285
|
-
it "preserves the middle name if present" do
|
286
|
-
expect(@user.middle_name).to eq("man")
|
186
|
+
it "preserves the public key" do
|
187
|
+
expect(@user.public_key).to eq("turtles")
|
287
188
|
end
|
288
189
|
|
289
|
-
it "preserves the
|
290
|
-
expect(@user.
|
190
|
+
it "preserves the admin status" do
|
191
|
+
expect(@user.admin).to be_truthy
|
291
192
|
end
|
292
193
|
|
293
|
-
it "
|
294
|
-
expect(@user.
|
194
|
+
it "includes the private key if present" do
|
195
|
+
expect(@user.private_key).to eq("pandas")
|
295
196
|
end
|
296
197
|
|
297
198
|
it "includes the password if present" do
|
298
199
|
expect(@user.password).to eq("password")
|
299
200
|
end
|
300
201
|
|
301
|
-
it "preserves the public key if present" do
|
302
|
-
expect(@user.public_key).to eq("turtles")
|
303
|
-
end
|
304
|
-
|
305
|
-
it "includes the private key if present" do
|
306
|
-
expect(@user.private_key).to eq("pandas")
|
307
|
-
end
|
308
|
-
|
309
|
-
it "includes the create key status if not nil" do
|
310
|
-
expect(@user.create_key).to be_falsey
|
311
|
-
end
|
312
202
|
end
|
313
203
|
|
314
|
-
describe "Versioned API Interactions" do
|
315
|
-
let(:response_406) { OpenStruct.new(:code => '406') }
|
316
|
-
let(:exception_406) { Net::HTTPServerException.new("406 Not Acceptable", response_406) }
|
317
|
-
|
318
|
-
before (:each) do
|
319
|
-
@user = Chef::User.new
|
320
|
-
allow(@user).to receive(:chef_root_rest_v0).and_return(double('chef rest root v0 object'))
|
321
|
-
allow(@user).to receive(:chef_root_rest_v1).and_return(double('chef rest root v1 object'))
|
322
|
-
end
|
323
|
-
|
324
|
-
describe "update" do
|
325
|
-
before do
|
326
|
-
# populate all fields that are valid between V0 and V1
|
327
|
-
@user.username "some_username"
|
328
|
-
@user.display_name "some_display_name"
|
329
|
-
@user.first_name "some_first_name"
|
330
|
-
@user.middle_name "some_middle_name"
|
331
|
-
@user.last_name "some_last_name"
|
332
|
-
@user.email "some_email"
|
333
|
-
@user.password "some_password"
|
334
|
-
end
|
335
|
-
|
336
|
-
let(:payload) {
|
337
|
-
{
|
338
|
-
:username => "some_username",
|
339
|
-
:display_name => "some_display_name",
|
340
|
-
:first_name => "some_first_name",
|
341
|
-
:middle_name => "some_middle_name",
|
342
|
-
:last_name => "some_last_name",
|
343
|
-
:email => "some_email",
|
344
|
-
:password => "some_password"
|
345
|
-
}
|
346
|
-
}
|
347
|
-
|
348
|
-
context "when server API V1 is valid on the Chef Server receiving the request" do
|
349
|
-
context "when the user submits valid data" do
|
350
|
-
it "properly updates the user" do
|
351
|
-
expect(@user.chef_root_rest_v1).to receive(:put).with("users/some_username", payload).and_return({})
|
352
|
-
@user.update
|
353
|
-
end
|
354
|
-
end
|
355
|
-
end
|
356
|
-
|
357
|
-
context "when server API V1 is not valid on the Chef Server receiving the request" do
|
358
|
-
let(:payload) {
|
359
|
-
{
|
360
|
-
:username => "some_username",
|
361
|
-
:display_name => "some_display_name",
|
362
|
-
:first_name => "some_first_name",
|
363
|
-
:middle_name => "some_middle_name",
|
364
|
-
:last_name => "some_last_name",
|
365
|
-
:email => "some_email",
|
366
|
-
:password => "some_password",
|
367
|
-
:public_key => "some_public_key"
|
368
|
-
}
|
369
|
-
}
|
370
|
-
|
371
|
-
before do
|
372
|
-
@user.public_key "some_public_key"
|
373
|
-
allow(@user.chef_root_rest_v1).to receive(:put)
|
374
|
-
end
|
375
|
-
|
376
|
-
context "when the server returns a 400" do
|
377
|
-
let(:response_400) { OpenStruct.new(:code => '400') }
|
378
|
-
let(:exception_400) { Net::HTTPServerException.new("400 Bad Request", response_400) }
|
379
|
-
|
380
|
-
context "when the 400 was due to public / private key fields no longer being supported" do
|
381
|
-
let(:response_body_400) { '{"error":["Since Server API v1, all keys must be updated via the keys endpoint. "]}' }
|
382
|
-
|
383
|
-
before do
|
384
|
-
allow(response_400).to receive(:body).and_return(response_body_400)
|
385
|
-
allow(@user.chef_root_rest_v1).to receive(:put).and_raise(exception_400)
|
386
|
-
end
|
387
|
-
|
388
|
-
it "proceeds with the V0 PUT since it can handle public / private key fields" do
|
389
|
-
expect(@user.chef_root_rest_v0).to receive(:put).with("users/some_username", payload).and_return({})
|
390
|
-
@user.update
|
391
|
-
end
|
392
|
-
|
393
|
-
it "does not call server_client_api_version_intersection, since we know to proceed with V0 in this case" do
|
394
|
-
expect(@user).to_not receive(:server_client_api_version_intersection)
|
395
|
-
allow(@user.chef_root_rest_v0).to receive(:put).and_return({})
|
396
|
-
@user.update
|
397
|
-
end
|
398
|
-
end # when the 400 was due to public / private key fields
|
399
|
-
|
400
|
-
context "when the 400 was NOT due to public / private key fields no longer being supported" do
|
401
|
-
let(:response_body_400) { '{"error":["Some other error. "]}' }
|
402
|
-
|
403
|
-
before do
|
404
|
-
allow(response_400).to receive(:body).and_return(response_body_400)
|
405
|
-
allow(@user.chef_root_rest_v1).to receive(:put).and_raise(exception_400)
|
406
|
-
end
|
407
|
-
|
408
|
-
it "will not proceed with the V0 PUT since the original bad request was not key related" do
|
409
|
-
expect(@user.chef_root_rest_v0).to_not receive(:put).with("users/some_username", payload)
|
410
|
-
expect { @user.update }.to raise_error(exception_400)
|
411
|
-
end
|
412
|
-
|
413
|
-
it "raises the original error" do
|
414
|
-
expect { @user.update }.to raise_error(exception_400)
|
415
|
-
end
|
416
|
-
|
417
|
-
end
|
418
|
-
end # when the server returns a 400
|
419
|
-
|
420
|
-
context "when the server returns a 406" do
|
421
|
-
# from spec/support/shared/unit/api_versioning.rb
|
422
|
-
it_should_behave_like "version handling" do
|
423
|
-
let(:object) { @user }
|
424
|
-
let(:method) { :update }
|
425
|
-
let(:http_verb) { :put }
|
426
|
-
let(:rest_v1) { @user.chef_root_rest_v1 }
|
427
|
-
end
|
428
|
-
|
429
|
-
context "when the server supports API V0" do
|
430
|
-
before do
|
431
|
-
allow(@user).to receive(:server_client_api_version_intersection).and_return([0])
|
432
|
-
allow(@user.chef_root_rest_v1).to receive(:put).and_raise(exception_406)
|
433
|
-
end
|
434
|
-
|
435
|
-
it "properly updates the user" do
|
436
|
-
expect(@user.chef_root_rest_v0).to receive(:put).with("users/some_username", payload).and_return({})
|
437
|
-
@user.update
|
438
|
-
end
|
439
|
-
end # when the server supports API V0
|
440
|
-
end # when the server returns a 406
|
441
|
-
|
442
|
-
end # when server API V1 is not valid on the Chef Server receiving the request
|
443
|
-
end # update
|
444
|
-
|
445
|
-
describe "create" do
|
446
|
-
let(:payload) {
|
447
|
-
{
|
448
|
-
:username => "some_username",
|
449
|
-
:display_name => "some_display_name",
|
450
|
-
:first_name => "some_first_name",
|
451
|
-
:last_name => "some_last_name",
|
452
|
-
:email => "some_email",
|
453
|
-
:password => "some_password"
|
454
|
-
}
|
455
|
-
}
|
456
|
-
before do
|
457
|
-
@user.username "some_username"
|
458
|
-
@user.display_name "some_display_name"
|
459
|
-
@user.first_name "some_first_name"
|
460
|
-
@user.last_name "some_last_name"
|
461
|
-
@user.email "some_email"
|
462
|
-
@user.password "some_password"
|
463
|
-
end
|
464
|
-
|
465
|
-
# from spec/support/shared/unit/user_and_client_shared.rb
|
466
|
-
it_should_behave_like "user or client create" do
|
467
|
-
let(:object) { @user }
|
468
|
-
let(:error) { Chef::Exceptions::InvalidUserAttribute }
|
469
|
-
let(:rest_v0) { @user.chef_root_rest_v0 }
|
470
|
-
let(:rest_v1) { @user.chef_root_rest_v1 }
|
471
|
-
let(:url) { "users" }
|
472
|
-
end
|
473
|
-
|
474
|
-
context "when handling API V1" do
|
475
|
-
it "creates a new user via the API with a middle_name when it exists" do
|
476
|
-
@user.middle_name "some_middle_name"
|
477
|
-
expect(@user.chef_root_rest_v1).to receive(:post).with("users", payload.merge({:middle_name => "some_middle_name"})).and_return({})
|
478
|
-
@user.create
|
479
|
-
end
|
480
|
-
end # when server API V1 is valid on the Chef Server receiving the request
|
481
|
-
|
482
|
-
context "when API V1 is not supported by the server" do
|
483
|
-
# from spec/support/shared/unit/api_versioning.rb
|
484
|
-
it_should_behave_like "version handling" do
|
485
|
-
let(:object) { @user }
|
486
|
-
let(:method) { :create }
|
487
|
-
let(:http_verb) { :post }
|
488
|
-
let(:rest_v1) { @user.chef_root_rest_v1 }
|
489
|
-
end
|
490
|
-
end
|
491
|
-
|
492
|
-
context "when handling API V0" do
|
493
|
-
before do
|
494
|
-
allow(@user).to receive(:server_client_api_version_intersection).and_return([0])
|
495
|
-
allow(@user.chef_root_rest_v1).to receive(:post).and_raise(exception_406)
|
496
|
-
end
|
497
|
-
|
498
|
-
it "creates a new user via the API with a middle_name when it exists" do
|
499
|
-
@user.middle_name "some_middle_name"
|
500
|
-
expect(@user.chef_root_rest_v0).to receive(:post).with("users", payload.merge({:middle_name => "some_middle_name"})).and_return({})
|
501
|
-
@user.create
|
502
|
-
end
|
503
|
-
end # when server API V1 is not valid on the Chef Server receiving the request
|
504
|
-
|
505
|
-
end # create
|
506
|
-
|
507
|
-
# DEPRECATION
|
508
|
-
# This can be removed after API V0 support is gone
|
509
|
-
describe "reregister" do
|
510
|
-
let(:payload) {
|
511
|
-
{
|
512
|
-
"username" => "some_username",
|
513
|
-
}
|
514
|
-
}
|
515
|
-
|
516
|
-
before do
|
517
|
-
@user.username "some_username"
|
518
|
-
end
|
519
|
-
|
520
|
-
context "when server API V0 is valid on the Chef Server receiving the request" do
|
521
|
-
it "creates a new object via the API" do
|
522
|
-
expect(@user.chef_root_rest_v0).to receive(:put).with("users/#{@user.username}", payload.merge({"private_key" => true})).and_return({})
|
523
|
-
@user.reregister
|
524
|
-
end
|
525
|
-
end # when server API V0 is valid on the Chef Server receiving the request
|
526
|
-
|
527
|
-
context "when server API V0 is not supported by the Chef Server" do
|
528
|
-
# from spec/support/shared/unit/api_versioning.rb
|
529
|
-
it_should_behave_like "user and client reregister" do
|
530
|
-
let(:object) { @user }
|
531
|
-
let(:rest_v0) { @user.chef_root_rest_v0 }
|
532
|
-
end
|
533
|
-
end # when server API V0 is not supported by the Chef Server
|
534
|
-
end # reregister
|
535
|
-
|
536
|
-
end # Versioned API Interactions
|
537
|
-
|
538
204
|
describe "API Interactions" do
|
539
205
|
before (:each) do
|
540
206
|
@user = Chef::User.new
|
541
|
-
@user.
|
542
|
-
@http_client = double("Chef::
|
543
|
-
allow(Chef::
|
207
|
+
@user.name "foobar"
|
208
|
+
@http_client = double("Chef::ServerAPI mock")
|
209
|
+
allow(Chef::ServerAPI).to receive(:new).and_return(@http_client)
|
544
210
|
end
|
545
211
|
|
546
212
|
describe "list" do
|
@@ -552,6 +218,16 @@ describe Chef::User do
|
|
552
218
|
@osc_inflated_response = { "admin" => @user }
|
553
219
|
end
|
554
220
|
|
221
|
+
it "lists all clients on an OSC server" do
|
222
|
+
allow(@http_client).to receive(:get).with("users").and_return(@osc_response)
|
223
|
+
expect(Chef::User.list).to eq(@osc_response)
|
224
|
+
end
|
225
|
+
|
226
|
+
it "inflate all clients on an OSC server" do
|
227
|
+
allow(@http_client).to receive(:get).with("users").and_return(@osc_response)
|
228
|
+
expect(Chef::User.list(true)).to eq(@osc_inflated_response)
|
229
|
+
end
|
230
|
+
|
555
231
|
it "lists all clients on an OHC/OPC server" do
|
556
232
|
allow(@http_client).to receive(:get).with("users").and_return(@ohc_response)
|
557
233
|
# We expect that Chef::User.list will give a consistent response
|
@@ -565,15 +241,31 @@ describe Chef::User do
|
|
565
241
|
end
|
566
242
|
end
|
567
243
|
|
244
|
+
describe "create" do
|
245
|
+
it "creates a new user via the API" do
|
246
|
+
@user.password "password"
|
247
|
+
expect(@http_client).to receive(:post).with("users", {:name => "foobar", :admin => false, :password => "password"}).and_return({})
|
248
|
+
@user.create
|
249
|
+
end
|
250
|
+
end
|
251
|
+
|
568
252
|
describe "read" do
|
569
253
|
it "loads a named user from the API" do
|
570
|
-
expect(@http_client).to receive(:get).with("users/foobar").and_return({"
|
254
|
+
expect(@http_client).to receive(:get).with("users/foobar").and_return({"name" => "foobar", "admin" => true, "public_key" => "pubkey"})
|
571
255
|
user = Chef::User.load("foobar")
|
572
|
-
expect(user.
|
256
|
+
expect(user.name).to eq("foobar")
|
257
|
+
expect(user.admin).to eq(true)
|
573
258
|
expect(user.public_key).to eq("pubkey")
|
574
259
|
end
|
575
260
|
end
|
576
261
|
|
262
|
+
describe "update" do
|
263
|
+
it "updates an existing user on via the API" do
|
264
|
+
expect(@http_client).to receive(:put).with("users/foobar", {:name => "foobar", :admin => false}).and_return({})
|
265
|
+
@user.update
|
266
|
+
end
|
267
|
+
end
|
268
|
+
|
577
269
|
describe "destroy" do
|
578
270
|
it "deletes the specified user via the API" do
|
579
271
|
expect(@http_client).to receive(:delete).with("users/foobar")
|