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.
Files changed (133) hide show
  1. checksums.yaml +4 -4
  2. data/lib/chef/api_client.rb +31 -129
  3. data/lib/chef/api_client_v1.rb +325 -0
  4. data/lib/chef/chef_class.rb +15 -7
  5. data/lib/chef/chef_fs/file_system/chef_server_root_dir.rb +2 -2
  6. data/lib/chef/dsl/resources.rb +6 -4
  7. data/lib/chef/exceptions.rb +2 -2
  8. data/lib/chef/guard_interpreter/resource_guard_interpreter.rb +2 -1
  9. data/lib/chef/knife/bootstrap/templates/chef-full.erb +4 -4
  10. data/lib/chef/knife/client_bulk_delete.rb +2 -2
  11. data/lib/chef/knife/client_create.rb +4 -4
  12. data/lib/chef/knife/client_delete.rb +3 -3
  13. data/lib/chef/knife/client_edit.rb +10 -2
  14. data/lib/chef/knife/client_list.rb +2 -2
  15. data/lib/chef/knife/client_reregister.rb +2 -2
  16. data/lib/chef/knife/client_show.rb +2 -2
  17. data/lib/chef/knife/osc_user_create.rb +3 -3
  18. data/lib/chef/knife/osc_user_delete.rb +2 -2
  19. data/lib/chef/knife/osc_user_edit.rb +3 -3
  20. data/lib/chef/knife/osc_user_list.rb +2 -2
  21. data/lib/chef/knife/osc_user_reregister.rb +2 -2
  22. data/lib/chef/knife/osc_user_show.rb +2 -2
  23. data/lib/chef/knife/user_create.rb +3 -3
  24. data/lib/chef/knife/user_delete.rb +4 -4
  25. data/lib/chef/knife/user_edit.rb +3 -3
  26. data/lib/chef/knife/user_list.rb +2 -2
  27. data/lib/chef/knife/user_reregister.rb +2 -2
  28. data/lib/chef/knife/user_show.rb +2 -2
  29. data/lib/chef/node_map.rb +14 -18
  30. data/lib/chef/platform/handler_map.rb +45 -0
  31. data/lib/chef/platform/priority_map.rb +19 -32
  32. data/lib/chef/platform/provider_handler_map.rb +29 -0
  33. data/lib/chef/platform/provider_mapping.rb +3 -2
  34. data/lib/chef/platform/resource_handler_map.rb +29 -0
  35. data/lib/chef/platform/resource_priority_map.rb +0 -6
  36. data/lib/chef/provider.rb +1 -1
  37. data/lib/chef/provider/dsc_resource.rb +2 -2
  38. data/lib/chef/provider/dsc_script.rb +1 -1
  39. data/lib/chef/provider/mount/aix.rb +1 -1
  40. data/lib/chef/provider/package.rb +0 -31
  41. data/lib/chef/provider/package/aix.rb +1 -0
  42. data/lib/chef/provider/package/apt.rb +1 -0
  43. data/lib/chef/provider/package/homebrew.rb +1 -0
  44. data/lib/chef/provider/package/ips.rb +1 -0
  45. data/lib/chef/provider/package/macports.rb +1 -0
  46. data/lib/chef/provider/package/openbsd.rb +1 -0
  47. data/lib/chef/provider/package/pacman.rb +1 -0
  48. data/lib/chef/provider/package/paludis.rb +1 -0
  49. data/lib/chef/provider/package/portage.rb +2 -0
  50. data/lib/chef/provider/package/smartos.rb +1 -0
  51. data/lib/chef/provider/package/solaris.rb +2 -0
  52. data/lib/chef/provider/package/yum.rb +1 -0
  53. data/lib/chef/provider/package/zypper.rb +1 -0
  54. data/lib/chef/provider/service.rb +4 -22
  55. data/lib/chef/provider/service/debian.rb +2 -0
  56. data/lib/chef/provider/service/insserv.rb +2 -0
  57. data/lib/chef/provider/service/invokercd.rb +2 -0
  58. data/lib/chef/provider/service/openbsd.rb +1 -1
  59. data/lib/chef/provider/service/redhat.rb +2 -0
  60. data/lib/chef/provider/service/upstart.rb +3 -0
  61. data/lib/chef/provider_resolver.rb +59 -53
  62. data/lib/chef/resource.rb +22 -73
  63. data/lib/chef/resource/dsc_script.rb +1 -1
  64. data/lib/chef/resource/ips_package.rb +1 -0
  65. data/lib/chef/resource/mount.rb +8 -0
  66. data/lib/chef/resource/openbsd_package.rb +0 -11
  67. data/lib/chef/resource/solaris_package.rb +1 -4
  68. data/lib/chef/resource_resolver.rb +54 -26
  69. data/lib/chef/run_list/versioned_recipe_list.rb +6 -5
  70. data/lib/chef/user.rb +52 -188
  71. data/lib/chef/user_v1.rb +335 -0
  72. data/lib/chef/version.rb +1 -1
  73. data/spec/data/trusted_certs/opscode.pem +53 -56
  74. data/spec/functional/provider/whyrun_safe_ruby_block_spec.rb +1 -1
  75. data/spec/functional/resource/package_spec.rb +0 -2
  76. data/spec/integration/recipes/recipe_dsl_spec.rb +661 -126
  77. data/spec/spec_helper.rb +19 -13
  78. data/spec/support/shared/unit/api_versioning.rb +2 -2
  79. data/spec/unit/api_client_spec.rb +22 -201
  80. data/spec/unit/api_client_v1_spec.rb +457 -0
  81. data/spec/unit/knife/client_bulk_delete_spec.rb +4 -4
  82. data/spec/unit/knife/client_create_spec.rb +1 -1
  83. data/spec/unit/knife/client_delete_spec.rb +3 -3
  84. data/spec/unit/knife/client_edit_spec.rb +14 -1
  85. data/spec/unit/knife/client_list_spec.rb +1 -1
  86. data/spec/unit/knife/client_reregister_spec.rb +2 -2
  87. data/spec/unit/knife/client_show_spec.rb +2 -2
  88. data/spec/unit/knife/osc_user_create_spec.rb +5 -5
  89. data/spec/unit/knife/osc_user_delete_spec.rb +1 -1
  90. data/spec/unit/knife/osc_user_edit_spec.rb +1 -1
  91. data/spec/unit/knife/osc_user_list_spec.rb +1 -1
  92. data/spec/unit/knife/osc_user_reregister_spec.rb +1 -1
  93. data/spec/unit/knife/osc_user_show_spec.rb +1 -1
  94. data/spec/unit/knife/user_create_spec.rb +1 -1
  95. data/spec/unit/knife/user_delete_spec.rb +2 -2
  96. data/spec/unit/knife/user_edit_spec.rb +2 -2
  97. data/spec/unit/knife/user_list_spec.rb +1 -1
  98. data/spec/unit/knife/user_reregister_spec.rb +1 -1
  99. data/spec/unit/knife/user_show_spec.rb +2 -2
  100. data/spec/unit/lwrp_spec.rb +146 -134
  101. data/spec/unit/node_map_spec.rb +12 -0
  102. data/spec/unit/platform_spec.rb +1 -1
  103. data/spec/unit/provider/deploy_spec.rb +1 -1
  104. data/spec/unit/provider/dsc_resource_spec.rb +3 -3
  105. data/spec/unit/provider/dsc_script_spec.rb +2 -2
  106. data/spec/unit/provider_resolver_spec.rb +170 -135
  107. data/spec/unit/recipe_spec.rb +3 -3
  108. data/spec/unit/resource/breakpoint_spec.rb +1 -1
  109. data/spec/unit/resource/cron_spec.rb +1 -1
  110. data/spec/unit/resource/directory_spec.rb +1 -1
  111. data/spec/unit/resource/dsc_resource_spec.rb +1 -1
  112. data/spec/unit/resource/dsc_script_spec.rb +2 -2
  113. data/spec/unit/resource/env_spec.rb +1 -1
  114. data/spec/unit/resource/erl_call_spec.rb +1 -1
  115. data/spec/unit/resource/file_spec.rb +1 -1
  116. data/spec/unit/resource/group_spec.rb +1 -1
  117. data/spec/unit/resource/link_spec.rb +1 -1
  118. data/spec/unit/resource/mdadm_spec.rb +1 -1
  119. data/spec/unit/resource/mount_spec.rb +1 -1
  120. data/spec/unit/resource/ohai_spec.rb +1 -1
  121. data/spec/unit/resource/registry_key_spec.rb +1 -1
  122. data/spec/unit/resource/route_spec.rb +1 -1
  123. data/spec/unit/resource/ruby_block_spec.rb +3 -3
  124. data/spec/unit/resource/user_spec.rb +1 -1
  125. data/spec/unit/resource/windows_service_spec.rb +1 -1
  126. data/spec/unit/resource_resolver_spec.rb +8 -4
  127. data/spec/unit/resource_spec.rb +89 -3
  128. data/spec/unit/run_list/versioned_recipe_list_spec.rb +115 -48
  129. data/spec/unit/user_spec.rb +97 -405
  130. data/spec/unit/user_v1_spec.rb +584 -0
  131. metadata +11 -6
  132. data/lib/chef/osc_user.rb +0 -194
  133. data/spec/unit/osc_user_spec.rb +0 -276
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chef
3
3
  version: !ruby/object:Gem::Version
4
- version: 12.4.0
4
+ version: 12.4.1
5
5
  platform: universal-mingw32
6
6
  authors:
7
7
  - Adam Jacob
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-24 00:00:00.000000000 Z
11
+ date: 2015-07-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chef-config
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 12.4.0
19
+ version: 12.4.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 12.4.0
26
+ version: 12.4.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: mixlib-cli
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -750,6 +750,7 @@ files:
750
750
  - lib/chef.rb
751
751
  - lib/chef/api_client.rb
752
752
  - lib/chef/api_client/registration.rb
753
+ - lib/chef/api_client_v1.rb
753
754
  - lib/chef/application.rb
754
755
  - lib/chef/application/apply.rb
755
756
  - lib/chef/application/client.rb
@@ -1133,13 +1134,15 @@ files:
1133
1134
  - lib/chef/node_map.rb
1134
1135
  - lib/chef/null_logger.rb
1135
1136
  - lib/chef/org.rb
1136
- - lib/chef/osc_user.rb
1137
1137
  - lib/chef/platform.rb
1138
+ - lib/chef/platform/handler_map.rb
1138
1139
  - lib/chef/platform/priority_map.rb
1140
+ - lib/chef/platform/provider_handler_map.rb
1139
1141
  - lib/chef/platform/provider_mapping.rb
1140
1142
  - lib/chef/platform/provider_priority_map.rb
1141
1143
  - lib/chef/platform/query_helpers.rb
1142
1144
  - lib/chef/platform/rebooter.rb
1145
+ - lib/chef/platform/resource_handler_map.rb
1143
1146
  - lib/chef/platform/resource_priority_map.rb
1144
1147
  - lib/chef/platform/service_helpers.rb
1145
1148
  - lib/chef/policy_builder.rb
@@ -1375,6 +1378,7 @@ files:
1375
1378
  - lib/chef/shell_out.rb
1376
1379
  - lib/chef/tasks/chef_repo.rake
1377
1380
  - lib/chef/user.rb
1381
+ - lib/chef/user_v1.rb
1378
1382
  - lib/chef/util/backup.rb
1379
1383
  - lib/chef/util/diff.rb
1380
1384
  - lib/chef/util/dsc/configuration_generator.rb
@@ -1868,6 +1872,7 @@ files:
1868
1872
  - spec/tiny_server.rb
1869
1873
  - spec/unit/api_client/registration_spec.rb
1870
1874
  - spec/unit/api_client_spec.rb
1875
+ - spec/unit/api_client_v1_spec.rb
1871
1876
  - spec/unit/application/agent_spec.rb
1872
1877
  - spec/unit/application/apply_spec.rb
1873
1878
  - spec/unit/application/client_spec.rb
@@ -2082,7 +2087,6 @@ files:
2082
2087
  - spec/unit/node_map_spec.rb
2083
2088
  - spec/unit/node_spec.rb
2084
2089
  - spec/unit/org_spec.rb
2085
- - spec/unit/osc_user_spec.rb
2086
2090
  - spec/unit/platform/query_helpers_spec.rb
2087
2091
  - spec/unit/platform_spec.rb
2088
2092
  - spec/unit/policy_builder/expand_node_object_spec.rb
@@ -2291,6 +2295,7 @@ files:
2291
2295
  - spec/unit/shell_out_spec.rb
2292
2296
  - spec/unit/shell_spec.rb
2293
2297
  - spec/unit/user_spec.rb
2298
+ - spec/unit/user_v1_spec.rb
2294
2299
  - spec/unit/util/backup_spec.rb
2295
2300
  - spec/unit/util/diff_spec.rb
2296
2301
  - spec/unit/util/dsc/configuration_generator_spec.rb
data/lib/chef/osc_user.rb DELETED
@@ -1,194 +0,0 @@
1
- #
2
- # Author:: Steven Danna (steve@opscode.com)
3
- # Copyright:: Copyright 2012 Opscode, 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
- require 'chef/config'
19
- require 'chef/mixin/params_validate'
20
- require 'chef/mixin/from_file'
21
- require 'chef/mash'
22
- require 'chef/json_compat'
23
- require 'chef/search/query'
24
-
25
- # TODO
26
- # DEPRECATION NOTE
27
- # This class was previously Chef::User. It is the code to support the User object
28
- # corrosponding to the Open Source Chef Server 11 and only still exists to support
29
- # users still on OSC 11.
30
- #
31
- # Chef::User now supports Chef Server 12.
32
- #
33
- # New development should occur in Chef::User.
34
- # This file and corrosponding osc_user knife files
35
- # should be removed once client support for Open Source Chef Server 11 expires.
36
- class Chef
37
- class OscUser
38
-
39
- include Chef::Mixin::FromFile
40
- include Chef::Mixin::ParamsValidate
41
-
42
- def initialize
43
- @name = ''
44
- @public_key = nil
45
- @private_key = nil
46
- @password = nil
47
- @admin = false
48
- end
49
-
50
- def name(arg=nil)
51
- set_or_return(:name, arg,
52
- :regex => /^[a-z0-9\-_]+$/)
53
- end
54
-
55
- def admin(arg=nil)
56
- set_or_return(:admin,
57
- arg, :kind_of => [TrueClass, FalseClass])
58
- end
59
-
60
- def public_key(arg=nil)
61
- set_or_return(:public_key,
62
- arg, :kind_of => String)
63
- end
64
-
65
- def private_key(arg=nil)
66
- set_or_return(:private_key,
67
- arg, :kind_of => String)
68
- end
69
-
70
- def password(arg=nil)
71
- set_or_return(:password,
72
- arg, :kind_of => String)
73
- end
74
-
75
- def to_hash
76
- result = {
77
- "name" => @name,
78
- "public_key" => @public_key,
79
- "admin" => @admin
80
- }
81
- result["private_key"] = @private_key if @private_key
82
- result["password"] = @password if @password
83
- result
84
- end
85
-
86
- def to_json(*a)
87
- Chef::JSONCompat.to_json(to_hash, *a)
88
- end
89
-
90
- def destroy
91
- Chef::REST.new(Chef::Config[:chef_server_url]).delete_rest("users/#{@name}")
92
- end
93
-
94
- def create
95
- payload = {:name => self.name, :admin => self.admin, :password => self.password }
96
- payload[:public_key] = public_key if public_key
97
- new_user =Chef::REST.new(Chef::Config[:chef_server_url]).post_rest("users", payload)
98
- Chef::OscUser.from_hash(self.to_hash.merge(new_user))
99
- end
100
-
101
- def update(new_key=false)
102
- payload = {:name => name, :admin => admin}
103
- payload[:private_key] = new_key if new_key
104
- payload[:password] = password if password
105
- updated_user = Chef::REST.new(Chef::Config[:chef_server_url]).put_rest("users/#{name}", payload)
106
- Chef::OscUser.from_hash(self.to_hash.merge(updated_user))
107
- end
108
-
109
- def save(new_key=false)
110
- begin
111
- create
112
- rescue Net::HTTPServerException => e
113
- if e.response.code == "409"
114
- update(new_key)
115
- else
116
- raise e
117
- end
118
- end
119
- end
120
-
121
- def reregister
122
- r = Chef::REST.new(Chef::Config[:chef_server_url])
123
- reregistered_self = r.put_rest("users/#{name}", { :name => name, :admin => admin, :private_key => true })
124
- private_key(reregistered_self["private_key"])
125
- self
126
- end
127
-
128
- def to_s
129
- "user[#{@name}]"
130
- end
131
-
132
- def inspect
133
- "Chef::OscUser name:'#{name}' admin:'#{admin.inspect}'" +
134
- "public_key:'#{public_key}' private_key:#{private_key}"
135
- end
136
-
137
- # Class Methods
138
-
139
- def self.from_hash(user_hash)
140
- user = Chef::OscUser.new
141
- user.name user_hash['name']
142
- user.private_key user_hash['private_key'] if user_hash.key?('private_key')
143
- user.password user_hash['password'] if user_hash.key?('password')
144
- user.public_key user_hash['public_key']
145
- user.admin user_hash['admin']
146
- user
147
- end
148
-
149
- def self.from_json(json)
150
- Chef::OscUser.from_hash(Chef::JSONCompat.from_json(json))
151
- end
152
-
153
- class << self
154
- alias_method :json_create, :from_json
155
- end
156
-
157
- def self.list(inflate=false)
158
- response = Chef::REST.new(Chef::Config[:chef_server_url]).get_rest('users')
159
- users = if response.is_a?(Array)
160
- transform_ohc_list_response(response) # OHC/OPC
161
- else
162
- response # OSC
163
- end
164
- if inflate
165
- users.inject({}) do |user_map, (name, _url)|
166
- user_map[name] = Chef::OscUser.load(name)
167
- user_map
168
- end
169
- else
170
- users
171
- end
172
- end
173
-
174
- def self.load(name)
175
- response = Chef::REST.new(Chef::Config[:chef_server_url]).get_rest("users/#{name}")
176
- Chef::OscUser.from_hash(response)
177
- end
178
-
179
- # Gross. Transforms an API response in the form of:
180
- # [ { "user" => { "username" => USERNAME }}, ...]
181
- # into the form
182
- # { "USERNAME" => "URI" }
183
- def self.transform_ohc_list_response(response)
184
- new_response = Hash.new
185
- response.each do |u|
186
- name = u['user']['username']
187
- new_response[name] = Chef::Config[:chef_server_url] + "/users/#{name}"
188
- end
189
- new_response
190
- end
191
-
192
- private_class_method :transform_ohc_list_response
193
- end
194
- end
@@ -1,276 +0,0 @@
1
- #
2
- # Author:: Steven Danna (steve@opscode.com)
3
- # Copyright:: Copyright (c) 2012 Opscode, 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
- # 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
-
24
- require 'spec_helper'
25
-
26
- require 'chef/osc_user'
27
- require 'tempfile'
28
-
29
- describe Chef::OscUser do
30
- before(:each) do
31
- @user = Chef::OscUser.new
32
- end
33
-
34
- describe "initialize" do
35
- it "should be a Chef::OscUser" do
36
- expect(@user).to be_a_kind_of(Chef::OscUser)
37
- end
38
- end
39
-
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")
43
- end
44
-
45
- it "should return the current name" do
46
- @user.name "ops_master"
47
- expect(@user.name).to eq("ops_master")
48
- end
49
-
50
- # It is not feasible to check all invalid characters. Here are a few
51
- # that we probably care about.
52
- it "should not accept invalid characters" do
53
- # capital letters
54
- expect { @user.name "Bar" }.to raise_error(ArgumentError)
55
- # slashes
56
- expect { @user.name "foo/bar" }.to raise_error(ArgumentError)
57
- # ?
58
- expect { @user.name "foo?" }.to raise_error(ArgumentError)
59
- # &
60
- expect { @user.name "foo&" }.to raise_error(ArgumentError)
61
- end
62
-
63
-
64
- it "should not accept spaces" do
65
- expect { @user.name "ops master" }.to raise_error(ArgumentError)
66
- end
67
-
68
- it "should throw an ArgumentError if you feed it anything but a string" do
69
- expect { @user.name Hash.new }.to raise_error(ArgumentError)
70
- end
71
- end
72
-
73
- describe "admin" do
74
- it "should let you set the admin bit" do
75
- expect(@user.admin(true)).to eq(true)
76
- end
77
-
78
- it "should return the current admin value" do
79
- @user.admin true
80
- expect(@user.admin).to eq(true)
81
- end
82
-
83
- it "should default to false" do
84
- expect(@user.admin).to eq(false)
85
- end
86
-
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)
89
- end
90
- end
91
-
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")
95
- end
96
-
97
- it "should return the current public key" do
98
- @user.public_key("super public")
99
- expect(@user.public_key).to eq("super public")
100
- end
101
-
102
- it "should throw an ArgumentError if you feed it something lame" do
103
- expect { @user.public_key Hash.new }.to raise_error(ArgumentError)
104
- end
105
- end
106
-
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")
110
- end
111
-
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)
119
- end
120
- end
121
-
122
- describe "when serializing to JSON" do
123
- before(:each) do
124
- @user.name("black")
125
- @user.public_key("crowes")
126
- @json = @user.to_json
127
- end
128
-
129
- it "serializes as a JSON object" do
130
- expect(@json).to match(/^\{.+\}$/)
131
- end
132
-
133
- it "includes the name value" do
134
- expect(@json).to include(%q{"name":"black"})
135
- end
136
-
137
- it "includes the public key value" do
138
- expect(@json).to include(%{"public_key":"crowes"})
139
- end
140
-
141
- it "includes the 'admin' flag" do
142
- expect(@json).to include(%q{"admin":false})
143
- end
144
-
145
- it "includes the private key when present" do
146
- @user.private_key("monkeypants")
147
- expect(@user.to_json).to include(%q{"private_key":"monkeypants"})
148
- end
149
-
150
- it "does not include the private key if not present" do
151
- expect(@json).not_to include("private_key")
152
- end
153
-
154
- it "includes the password if present" do
155
- @user.password "password"
156
- expect(@user.to_json).to include(%q{"password":"password"})
157
- end
158
-
159
- it "does not include the password if not present" do
160
- expect(@json).not_to include("password")
161
- end
162
-
163
- include_examples "to_json equivalent to Chef::JSONCompat.to_json" do
164
- let(:jsonable) { @user }
165
- end
166
- end
167
-
168
- describe "when deserializing from JSON" do
169
- before(:each) do
170
- user = { "name" => "mr_spinks",
171
- "public_key" => "turtles",
172
- "private_key" => "pandas",
173
- "password" => "password",
174
- "admin" => true }
175
- @user = Chef::OscUser.from_json(Chef::JSONCompat.to_json(user))
176
- end
177
-
178
- it "should deserialize to a Chef::OscUser object" do
179
- expect(@user).to be_a_kind_of(Chef::OscUser)
180
- end
181
-
182
- it "preserves the name" do
183
- expect(@user.name).to eq("mr_spinks")
184
- end
185
-
186
- it "preserves the public key" do
187
- expect(@user.public_key).to eq("turtles")
188
- end
189
-
190
- it "preserves the admin status" do
191
- expect(@user.admin).to be_truthy
192
- end
193
-
194
- it "includes the private key if present" do
195
- expect(@user.private_key).to eq("pandas")
196
- end
197
-
198
- it "includes the password if present" do
199
- expect(@user.password).to eq("password")
200
- end
201
-
202
- end
203
-
204
- describe "API Interactions" do
205
- before (:each) do
206
- @user = Chef::OscUser.new
207
- @user.name "foobar"
208
- @http_client = double("Chef::REST mock")
209
- allow(Chef::REST).to receive(:new).and_return(@http_client)
210
- end
211
-
212
- describe "list" do
213
- before(:each) do
214
- Chef::Config[:chef_server_url] = "http://www.example.com"
215
- @osc_response = { "admin" => "http://www.example.com/users/admin"}
216
- @ohc_response = [ { "user" => { "username" => "admin" }} ]
217
- allow(Chef::OscUser).to receive(:load).with("admin").and_return(@user)
218
- @osc_inflated_response = { "admin" => @user }
219
- end
220
-
221
- it "lists all clients on an OSC server" do
222
- allow(@http_client).to receive(:get_rest).with("users").and_return(@osc_response)
223
- expect(Chef::OscUser.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_rest).with("users").and_return(@osc_response)
228
- expect(Chef::OscUser.list(true)).to eq(@osc_inflated_response)
229
- end
230
-
231
- it "lists all clients on an OHC/OPC server" do
232
- allow(@http_client).to receive(:get_rest).with("users").and_return(@ohc_response)
233
- # We expect that Chef::OscUser.list will give a consistent response
234
- # so OHC API responses should be transformed to OSC-style output.
235
- expect(Chef::OscUser.list).to eq(@osc_response)
236
- end
237
-
238
- it "inflate all clients on an OHC/OPC server" do
239
- allow(@http_client).to receive(:get_rest).with("users").and_return(@ohc_response)
240
- expect(Chef::OscUser.list(true)).to eq(@osc_inflated_response)
241
- end
242
- end
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_rest).with("users", {:name => "foobar", :admin => false, :password => "password"}).and_return({})
248
- @user.create
249
- end
250
- end
251
-
252
- describe "read" do
253
- it "loads a named user from the API" do
254
- expect(@http_client).to receive(:get_rest).with("users/foobar").and_return({"name" => "foobar", "admin" => true, "public_key" => "pubkey"})
255
- user = Chef::OscUser.load("foobar")
256
- expect(user.name).to eq("foobar")
257
- expect(user.admin).to eq(true)
258
- expect(user.public_key).to eq("pubkey")
259
- end
260
- end
261
-
262
- describe "update" do
263
- it "updates an existing user on via the API" do
264
- expect(@http_client).to receive(:put_rest).with("users/foobar", {:name => "foobar", :admin => false}).and_return({})
265
- @user.update
266
- end
267
- end
268
-
269
- describe "destroy" do
270
- it "deletes the specified user via the API" do
271
- expect(@http_client).to receive(:delete_rest).with("users/foobar")
272
- @user.destroy
273
- end
274
- end
275
- end
276
- end