chef 11.8.4.ohai7.0-x86-mingw32 → 11.10.0.alpha.1-x86-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 (134) hide show
  1. checksums.yaml +7 -0
  2. data/distro/common/html/chef-client.8.html +3 -3
  3. data/distro/common/html/chef-expander.8.html +3 -3
  4. data/distro/common/html/chef-expanderctl.8.html +3 -3
  5. data/distro/common/html/chef-server-webui.8.html +3 -3
  6. data/distro/common/html/chef-server.8.html +3 -3
  7. data/distro/common/html/chef-shell.1.html +3 -3
  8. data/distro/common/html/chef-solo.8.html +3 -3
  9. data/distro/common/html/chef-solr.8.html +4 -4
  10. data/distro/common/html/knife-bootstrap.1.html +3 -3
  11. data/distro/common/html/knife-client.1.html +3 -3
  12. data/distro/common/html/knife-configure.1.html +3 -3
  13. data/distro/common/html/knife-cookbook-site.1.html +3 -3
  14. data/distro/common/html/knife-cookbook.1.html +3 -3
  15. data/distro/common/html/knife-data-bag.1.html +3 -3
  16. data/distro/common/html/knife-environment.1.html +3 -3
  17. data/distro/common/html/knife-exec.1.html +3 -3
  18. data/distro/common/html/knife-index.1.html +3 -3
  19. data/distro/common/html/knife-node.1.html +3 -3
  20. data/distro/common/html/knife-role.1.html +3 -3
  21. data/distro/common/html/knife-search.1.html +3 -3
  22. data/distro/common/html/knife-ssh.1.html +3 -3
  23. data/distro/common/html/knife-status.1.html +3 -3
  24. data/distro/common/html/knife-tag.1.html +3 -3
  25. data/distro/common/html/knife.1.html +3 -3
  26. data/distro/common/man/man8/chef-client.8 +3 -3
  27. data/distro/common/man/man8/chef-solo.8 +5 -2
  28. data/lib/chef.rb +2 -0
  29. data/lib/chef/application.rb +7 -2
  30. data/lib/chef/application/apply.rb +6 -0
  31. data/lib/chef/application/client.rb +3 -1
  32. data/lib/chef/application/knife.rb +2 -0
  33. data/lib/chef/application/solo.rb +1 -1
  34. data/lib/chef/client.rb +14 -11
  35. data/lib/chef/config.rb +4 -1
  36. data/lib/chef/cookbook_uploader.rb +14 -7
  37. data/lib/chef/encrypted_data_bag_item.rb +6 -303
  38. data/lib/chef/encrypted_data_bag_item/decryption_failure.rb +22 -0
  39. data/lib/chef/encrypted_data_bag_item/decryptor.rb +201 -0
  40. data/lib/chef/encrypted_data_bag_item/encryptor.rb +142 -0
  41. data/lib/chef/encrypted_data_bag_item/unacceptable_encrypted_data_bag_item_format.rb +22 -0
  42. data/lib/chef/encrypted_data_bag_item/unsupported_cipher.rb +22 -0
  43. data/lib/chef/encrypted_data_bag_item/unsupported_encrypted_data_bag_item_format.rb +22 -0
  44. data/lib/chef/exceptions.rb +1 -0
  45. data/lib/chef/formatters/doc.rb +19 -3
  46. data/lib/chef/http/basic_client.rb +1 -1
  47. data/lib/chef/http/http_request.rb +7 -0
  48. data/lib/chef/knife.rb +8 -1
  49. data/lib/chef/knife/bootstrap.rb +1 -1
  50. data/lib/chef/knife/cookbook_site_share.rb +2 -2
  51. data/lib/chef/knife/cookbook_upload.rb +7 -1
  52. data/lib/chef/knife/core/subcommand_loader.rb +2 -2
  53. data/lib/chef/knife/data_bag_create.rb +7 -0
  54. data/lib/chef/knife/environment_compare.rb +127 -0
  55. data/lib/chef/mixin/command.rb +11 -12
  56. data/lib/chef/mixin/deep_merge.rb +4 -4
  57. data/lib/chef/monkey_patches/net_http.rb +34 -0
  58. data/lib/chef/monkey_patches/uri.rb +70 -0
  59. data/lib/chef/platform/provider_mapping.rb +1 -0
  60. data/lib/chef/provider/cookbook_file.rb +8 -0
  61. data/lib/chef/provider/cron.rb +1 -1
  62. data/lib/chef/provider/directory.rb +7 -0
  63. data/lib/chef/provider/file.rb +17 -4
  64. data/lib/chef/provider/git.rb +23 -5
  65. data/lib/chef/provider/group.rb +30 -11
  66. data/lib/chef/provider/group/dscl.rb +26 -4
  67. data/lib/chef/provider/group/gpasswd.rb +14 -19
  68. data/lib/chef/provider/group/groupadd.rb +41 -1
  69. data/lib/chef/provider/group/groupmod.rb +46 -36
  70. data/lib/chef/provider/group/pw.rb +59 -16
  71. data/lib/chef/provider/group/suse.rb +16 -13
  72. data/lib/chef/provider/group/usermod.rb +38 -15
  73. data/lib/chef/provider/group/windows.rb +13 -6
  74. data/lib/chef/provider/ohai.rb +5 -6
  75. data/lib/chef/provider/remote_file.rb +8 -0
  76. data/lib/chef/provider/template.rb +8 -0
  77. data/lib/chef/provider/user.rb +5 -1
  78. data/lib/chef/provider/user/useradd.rb +7 -0
  79. data/lib/chef/provider/whyrun_safe_ruby_block.rb +30 -0
  80. data/lib/chef/providers.rb +1 -0
  81. data/lib/chef/resource/deploy.rb +18 -0
  82. data/lib/chef/resource/group.rb +11 -0
  83. data/lib/chef/resource/scm.rb +18 -0
  84. data/lib/chef/resource/whyrun_safe_ruby_block.rb +31 -0
  85. data/lib/chef/resources.rb +1 -0
  86. data/lib/chef/run_context.rb +11 -0
  87. data/lib/chef/shell/ext.rb +1 -1
  88. data/lib/chef/util/windows/net_group.rb +5 -1
  89. data/lib/chef/version.rb +1 -1
  90. data/spec/functional/resource/base.rb +3 -1
  91. data/spec/functional/resource/deploy_revision_spec.rb +1 -1
  92. data/spec/functional/resource/git_spec.rb +1 -1
  93. data/spec/functional/resource/group_spec.rb +257 -118
  94. data/spec/integration/client/client_spec.rb +82 -8
  95. data/spec/integration/client/ipv6_spec.rb +133 -0
  96. data/spec/integration/knife/cookbook_api_ipv6_spec.rb +111 -0
  97. data/spec/scripts/ssl-serve.rb +52 -0
  98. data/spec/spec_helper.rb +7 -6
  99. data/spec/support/platform_helpers.rb +21 -0
  100. data/spec/support/shared/functional/windows_script.rb +2 -1
  101. data/spec/support/shared/unit/provider/file.rb +181 -43
  102. data/spec/support/shared/unit/provider/useradd_based_user_provider.rb +18 -0
  103. data/spec/unit/application/client_spec.rb +1 -0
  104. data/spec/unit/client_spec.rb +14 -1
  105. data/spec/unit/config_spec.rb +20 -0
  106. data/spec/unit/encrypted_data_bag_item_spec.rb +32 -18
  107. data/spec/unit/knife/cookbook_upload_spec.rb +14 -0
  108. data/spec/unit/knife/core/subcommand_loader_spec.rb +2 -2
  109. data/spec/unit/knife/data_bag_create_spec.rb +7 -0
  110. data/spec/unit/knife/environment_compare_spec.rb +112 -0
  111. data/spec/unit/knife_spec.rb +6 -1
  112. data/spec/unit/monkey_patches/uri_spec.rb +34 -0
  113. data/spec/unit/provider/cookbook_file_spec.rb +2 -1
  114. data/spec/unit/provider/cron_spec.rb +6 -0
  115. data/spec/unit/provider/file_spec.rb +3 -1
  116. data/spec/unit/provider/git_spec.rb +28 -4
  117. data/spec/unit/provider/group/dscl_spec.rb +1 -0
  118. data/spec/unit/provider/group/gpasswd_spec.rb +16 -9
  119. data/spec/unit/provider/group/groupadd_spec.rb +3 -4
  120. data/spec/unit/provider/group/groupmod_spec.rb +0 -1
  121. data/spec/unit/provider/group/pw_spec.rb +11 -14
  122. data/spec/unit/provider/group/usermod_spec.rb +19 -4
  123. data/spec/unit/provider/group/windows_spec.rb +0 -8
  124. data/spec/unit/provider/group_spec.rb +26 -4
  125. data/spec/unit/provider/ohai_spec.rb +1 -0
  126. data/spec/unit/provider/remote_file_spec.rb +4 -3
  127. data/spec/unit/provider/template_spec.rb +5 -3
  128. data/spec/unit/provider/user_spec.rb +6 -0
  129. data/spec/unit/provider/whyrun_safe_ruby_block_spec.rb +47 -0
  130. data/spec/unit/resource/scm_spec.rb +10 -0
  131. data/spec/unit/rest/auth_credentials_spec.rb +4 -1
  132. data/spec/unit/rest_spec.rb +12 -3
  133. metadata +69 -121
  134. data/spec/functional/resource/ohai_spec.rb +0 -65
@@ -0,0 +1,31 @@
1
+ #
2
+ # Author:: Phil Dibowitz (<phild@fb.com>)
3
+ # Copyright:: Copyright (c) 2013 Facebook
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
+ class Chef
20
+ class Resource
21
+ class WhyrunSafeRubyBlock < Chef::Resource::RubyBlock
22
+
23
+ def initialize(name, run_context=nil)
24
+ super
25
+ @resource_name = :whyrun_safe_ruby_block
26
+ @provider = Chef::Provider::WhyrunSafeRubyBlock
27
+ end
28
+
29
+ end
30
+ end
31
+ end
@@ -68,6 +68,7 @@ require 'chef/resource/smartos_package'
68
68
  require 'chef/resource/template'
69
69
  require 'chef/resource/timestamped_deploy'
70
70
  require 'chef/resource/user'
71
+ require 'chef/resource/whyrun_safe_ruby_block'
71
72
  require 'chef/resource/yum_package'
72
73
  require 'chef/resource/lwrp_base'
73
74
  require 'chef/resource/bff_package'
@@ -152,6 +152,17 @@ class Chef
152
152
  end
153
153
  end
154
154
 
155
+ def load_recipe_file(recipe_file)
156
+ if !File.exist?(recipe_file)
157
+ raise Chef::Exceptions::RecipeNotFound, "could not find recipe file #{recipe_file}"
158
+ end
159
+
160
+ Chef::Log.debug("Loading Recipe File #{recipe_file}")
161
+ recipe = Chef::Recipe.new('@recipe_files', recipe_file, self)
162
+ recipe.from_file(recipe_file)
163
+ recipe
164
+ end
165
+
155
166
  # Looks up an attribute file given the +cookbook_name+ and
156
167
  # +attr_file_name+. Used by DSL::IncludeAttribute
157
168
  def resolve_attribute(cookbook_name, attr_file_name)
@@ -212,7 +212,7 @@ E
212
212
  puts "This is the chef-shell.\n" +
213
213
  " Chef Version: #{::Chef::VERSION}\n" +
214
214
  " http://www.opscode.com/chef\n" +
215
- " http://wiki.opscode.com/display/chef/Home"
215
+ " http://docs.opscode.com/"
216
216
  :ucanhaz_automation
217
217
  end
218
218
  alias :shell :version
@@ -63,7 +63,7 @@ class Chef::Util::Windows::NetGroup < Chef::Util::Windows
63
63
  members = 0.chr * (nread * (PTR_SIZE * 3)) #nread * sizeof(LOCALGROUP_MEMBERS_INFO_1)
64
64
  memcpy(members, ptr, members.size)
65
65
 
66
- #3 pointer fields in LOCALGROUP_MEMBERS_INFO_1, offset 2*PTR_SIZE is lgrmi1_name
66
+ # 3 pointer fields in LOCALGROUP_MEMBERS_INFO_1, offset 2*PTR_SIZE is lgrmi1_name
67
67
  nread.times do |i|
68
68
  offset = (i * 3) + 2
69
69
  member = lpwstr_to_s(members, offset)
@@ -92,6 +92,10 @@ class Chef::Util::Windows::NetGroup < Chef::Util::Windows
92
92
  modify_members(members, NetLocalGroupAddMembers)
93
93
  end
94
94
 
95
+ def local_delete_members(members)
96
+ modify_members(members, NetLocalGroupDelMembers)
97
+ end
98
+
95
99
  def local_delete
96
100
  rc = NetLocalGroupDel.call(nil, @name)
97
101
  if rc != NERR_Success
@@ -17,7 +17,7 @@
17
17
 
18
18
  class Chef
19
19
  CHEF_ROOT = File.dirname(File.expand_path(File.dirname(__FILE__)))
20
- VERSION = '11.8.4.ohai7.0'
20
+ VERSION = '11.10.0.alpha.1'
21
21
  end
22
22
 
23
23
  # NOTE: the Chef::Version class is defined in version_class.rb
@@ -22,7 +22,9 @@ def ohai
22
22
  # provider is platform-dependent, we need platform ohai data:
23
23
  @OHAI_SYSTEM ||= begin
24
24
  ohai = Ohai::System.new
25
- ohai.all_plugins("platform")
25
+ ohai.require_plugin("os")
26
+ ohai.require_plugin("platform")
27
+ ohai.require_plugin("passwd")
26
28
  ohai
27
29
  end
28
30
  end
@@ -45,7 +45,7 @@ describe Chef::Resource::DeployRevision, :unix_only => true do
45
45
 
46
46
  before(:all) do
47
47
  @ohai = Ohai::System.new
48
- @ohai.all_plugins("os")
48
+ @ohai.require_plugin("os")
49
49
  end
50
50
 
51
51
  let(:node) do
@@ -92,7 +92,7 @@ E
92
92
 
93
93
  before(:all) do
94
94
  @ohai = Ohai::System.new
95
- @ohai.all_plugins("os")
95
+ @ohai.require_plugin("os")
96
96
  end
97
97
 
98
98
  context "working with pathes with special characters" do
@@ -20,33 +20,36 @@
20
20
  require 'spec_helper'
21
21
  require 'functional/resource/base'
22
22
 
23
- describe Chef::Resource::Group, :requires_root_or_running_windows do
24
-
25
- def group_should_exist(resource)
23
+ # Chef::Resource::Group are turned off on Mac OS X 10.6 due to caching
24
+ # issues around Etc.getgrnam() not picking up the group membership
25
+ # changes that are done on the system. Etc.endgrent is not functioning
26
+ # correctly on certain 10.6 boxes.
27
+ describe Chef::Resource::Group, :requires_root_or_running_windows, :not_supported_on_mac_osx_106 do
28
+ def group_should_exist(group)
26
29
  case ohai[:platform_family]
27
30
  when "debian", "fedora", "rhel", "suse", "gentoo", "slackware", "arch"
28
- expect { Etc::getgrnam(resource.name) }.to_not raise_error(ArgumentError, "can't find group for #{resource.name}")
29
- expect(resource.name).to eq(Etc::getgrnam(resource.name).name)
31
+ expect { Etc::getgrnam(group) }.to_not raise_error(ArgumentError, "can't find group for #{group}")
32
+ expect(group).to eq(Etc::getgrnam(group).name)
30
33
  when "windows"
31
- expect { Chef::Util::Windows::NetGroup.new(resource.group_name).local_get_members }.to_not raise_error(ArgumentError, "The group name could not be found.")
34
+ expect { Chef::Util::Windows::NetGroup.new(group).local_get_members }.to_not raise_error(ArgumentError, "The group name could not be found.")
32
35
  end
33
36
  end
34
37
 
35
- def user_exist_in_group?(resource, user)
38
+ def user_exist_in_group?(user)
36
39
  case ohai[:platform_family]
37
- when "debian", "fedora", "rhel", "suse", "gentoo", "slackware", "arch"
38
- Etc::getgrnam(resource.name).mem.include?(user)
39
40
  when "windows"
40
- Chef::Util::Windows::NetGroup.new(resource.group_name).local_get_members.include?(user)
41
+ Chef::Util::Windows::NetGroup.new(group_name).local_get_members.include?(user)
42
+ else
43
+ Etc::getgrnam(group_name).mem.include?(user)
41
44
  end
42
45
  end
43
46
 
44
- def group_should_not_exist(resource)
47
+ def group_should_not_exist(group)
45
48
  case ohai[:platform_family]
46
49
  when "debian", "fedora", "rhel", "suse", "gentoo", "slackware", "arch"
47
- expect { Etc::getgrnam(resource.name) }.to raise_error(ArgumentError, "can't find group for #{resource.name}")
50
+ expect { Etc::getgrnam(group) }.to raise_error(ArgumentError, "can't find group for #{group}")
48
51
  when "windows"
49
- expect { Chef::Util::Windows::NetGroup.new(resource.group_name).local_get_members }.to raise_error(ArgumentError, "The group name could not be found.")
52
+ expect { Chef::Util::Windows::NetGroup.new(group).local_get_members }.to raise_error(ArgumentError, "The group name could not be found.")
50
53
  end
51
54
  end
52
55
 
@@ -54,151 +57,287 @@ describe Chef::Resource::Group, :requires_root_or_running_windows do
54
57
  return resource.gid == Etc::getgrnam(resource.name).gid if unix?
55
58
  end
56
59
 
57
- def get_user_resource(username)
60
+ def user(username)
58
61
  usr = Chef::Resource::User.new("#{username}", run_context)
59
- usr.password("Jetsream123!")
62
+ if ohai[:platform_family] == "windows"
63
+ usr.password("ComplexPass11!")
64
+ end
60
65
  usr
61
66
  end
62
67
 
63
68
  def create_user(username)
64
- get_user_resource(username).run_action(:create)
69
+ user(username).run_action(:create)
70
+ # TODO: User shouldn't exist
65
71
  end
66
72
 
67
73
  def remove_user(username)
68
- get_user_resource(username).run_action(:remove)
74
+ user(username).run_action(:remove)
75
+ # TODO: User shouldn't exist
69
76
  end
70
77
 
71
- before do
72
- @grp_resource = Chef::Resource::Group.new("test-group-#{SecureRandom.random_number(9999)}", run_context)
73
- end
78
+ shared_examples_for "correct group management" do
79
+ def add_members_to_group(members)
80
+ temp_resource = group_resource.dup
81
+ temp_resource.members(members)
82
+ temp_resource.excluded_members([ ])
83
+ temp_resource.append(true)
84
+ temp_resource.run_action(:modify)
85
+ members.each do |member|
86
+ user_exist_in_group?(member).should == true
87
+ end
88
+ end
74
89
 
75
- context "group create action" do
76
- after(:each) do
77
- @grp_resource.run_action(:remove)
90
+ def create_group
91
+ temp_resource = group_resource.dup
92
+ temp_resource.members([ ])
93
+ temp_resource.excluded_members([ ])
94
+ temp_resource.run_action(:create)
95
+ group_should_exist(group_name)
96
+ included_members.each do |member|
97
+ user_exist_in_group?(member).should == false
98
+ end
78
99
  end
79
100
 
80
- it "create a group" do
81
- @grp_resource.run_action(:create)
82
- group_should_exist(@grp_resource)
101
+ before(:each) do
102
+ create_group
83
103
  end
84
104
 
85
- context "group name with 256 characters", :windows_only do
86
- before(:each) do
87
- grp_name = "theoldmanwalkingdownthestreetalwayshadagoodsmileonhisfacetheoldmanwalkingdownthestreetalwayshadagoodsmileonhisfacetheoldmanwalkingdownthestreetalwayshadagoodsmileonhisfacetheoldmanwalkingdownthestreetalwayshadagoodsmileonhisfacetheoldmanwalkingdownthestree"
88
- @new_grp = Chef::Resource::Group.new(grp_name, run_context)
105
+ after(:each) do
106
+ group_resource.run_action(:remove)
107
+ group_should_not_exist(group_name)
108
+ end
109
+
110
+ describe "when append is not set" do
111
+ let(:included_members) { ["spec-Eric"] }
112
+
113
+ before do
114
+ create_user("spec-Eric")
115
+ create_user("spec-Gordon")
116
+ add_members_to_group(["spec-Gordon"])
89
117
  end
118
+
90
119
  after do
91
- @new_grp.run_action(:remove)
120
+ remove_user("spec-Eric")
121
+ remove_user("spec-Gordon")
92
122
  end
93
- it " create a group" do
94
- @new_grp.run_action(:create)
95
- group_should_exist(@new_grp)
123
+
124
+ it "should remove the existing users and add the new users to the group" do
125
+ group_resource.run_action(tested_action)
126
+
127
+ user_exist_in_group?("spec-Eric").should == true
128
+ user_exist_in_group?("spec-Gordon").should == false
96
129
  end
97
130
  end
98
- context "group name with more than 256 characters", :windows_only do
131
+
132
+ describe "when append is set" do
99
133
  before(:each) do
100
- grp_name = "theoldmanwalkingdownthestreetalwayshadagoodsmileonhisfacetheoldmanwalkingdownthestreetalwayshadagoodsmileonhisfacetheoldmanwalkingdownthestreetalwayshadagoodsmileonhisfacetheoldmanwalkingdownthestreetalwayshadagoodsmileonhisfacetheoldmanwalkingdownthestreeQQQQQQQQQQQQQQQQQ"
101
- @new_grp = Chef::Resource::Group.new(grp_name, run_context)
134
+ group_resource.append(true)
102
135
  end
103
- it " not create a group" do
104
- expect { @new_grp.run_action(:create) }.to raise_error
105
- group_should_not_exist(@new_grp)
136
+
137
+ describe "when the users exist" do
138
+ before do
139
+ (included_members + excluded_members).each do |member|
140
+ create_user(member)
141
+ end
142
+ end
143
+
144
+ after do
145
+ (included_members + excluded_members).each do |member|
146
+ remove_user(member)
147
+ end
148
+ end
149
+
150
+ it "should add included members to the group" do
151
+ group_resource.run_action(tested_action)
152
+
153
+ included_members.each do |member|
154
+ user_exist_in_group?(member).should == true
155
+ end
156
+ excluded_members.each do |member|
157
+ user_exist_in_group?(member).should == false
158
+ end
159
+ end
160
+
161
+ describe "when group contains some users" do
162
+ before(:each) do
163
+ add_members_to_group([ "spec-Gordon", "spec-Anthony" ])
164
+ end
165
+
166
+ it "should add the included users and remove excluded users" do
167
+ group_resource.run_action(tested_action)
168
+
169
+ included_members.each do |member|
170
+ user_exist_in_group?(member).should == true
171
+ end
172
+ excluded_members.each do |member|
173
+ user_exist_in_group?(member).should == false
174
+ end
175
+ end
176
+ end
177
+ end
178
+
179
+ describe "when the users doesn't exist" do
180
+ describe "when append is not set" do
181
+ it "should raise an error" do
182
+ lambda { @grp_resource.run_action(tested_action) }.should raise_error
183
+ end
184
+ end
185
+
186
+ describe "when append is set" do
187
+ it "should raise an error" do
188
+ lambda { @grp_resource.run_action(tested_action) }.should raise_error
189
+ end
190
+ end
106
191
  end
107
192
  end
108
193
  end
109
194
 
110
- context "group remove action" do
111
- before(:each) do
112
- @grp_resource.run_action(:create)
195
+ let(:group_name) { "cheftest-#{SecureRandom.random_number(9999)}" }
196
+ let(:included_members) { nil }
197
+ let(:excluded_members) { nil }
198
+ let(:group_resource) {
199
+ group = Chef::Resource::Group.new(group_name, run_context)
200
+ group.members(included_members)
201
+ group.excluded_members(excluded_members)
202
+ group
203
+ }
204
+
205
+ it "append should be false by default" do
206
+ group_resource.append.should == false
207
+ end
208
+
209
+ describe "group create action" do
210
+ after(:each) do
211
+ group_resource.run_action(:remove)
212
+ group_should_not_exist(group_name)
213
+ end
214
+
215
+ it "should create a group" do
216
+ group_resource.run_action(:create)
217
+ group_should_exist(group_name)
218
+ end
219
+
220
+ describe "when group name is length 256", :windows_only do
221
+ let!(:group_name) { "theoldmanwalkingdownthestreetalwayshadagood\
222
+ smileonhisfacetheoldmanwalkingdownthestreetalwayshadagoodsmileonhisface\
223
+ theoldmanwalkingdownthestreetalwayshadagoodsmileonhisfacetheoldmanwalking\
224
+ downthestreetalwayshadagoodsmileonhisfacetheoldmanwalkingdownthestree" }
225
+
226
+ it "should create a group" do
227
+ group_resource.run_action(:create)
228
+ group_should_exist(group_name)
229
+ end
113
230
  end
114
231
 
115
- it "remove a group" do
116
- @grp_resource.run_action(:remove)
117
- group_should_not_exist(@grp_resource)
232
+ describe "when group name length is more than 256", :windows_only do
233
+ let!(:group_name) { "theoldmanwalkingdownthestreetalwayshadagood\
234
+ smileonhisfacetheoldmanwalkingdownthestreetalwayshadagoodsmileonhisface\
235
+ theoldmanwalkingdownthestreetalwayshadagoodsmileonhisfacetheoldmanwalking\
236
+ downthestreetalwayshadagoodsmileonhisfacetheoldmanwalkingdownthestreeQQQQQQ" }
237
+
238
+ it "should not create a group" do
239
+ lambda { group_resource.run_action(:create) }.should raise_error
240
+ group_should_not_exist(group_name)
241
+ end
242
+ end
243
+
244
+ # not_supported_on_solaris because of the use of excluded_members
245
+ describe "should raise an error when same member is included in the members and excluded_members", :not_supported_on_solaris do
246
+ it "should raise an error" do
247
+ invalid_resource = group_resource.dup
248
+ invalid_resource.members(["Jack"])
249
+ invalid_resource.excluded_members(["Jack"])
250
+ lambda { invalid_resource.run_action(:create)}.should raise_error(Chef::Exceptions::ConflictingMembersInGroup)
251
+ end
118
252
  end
119
253
  end
120
254
 
121
- context "group modify action", :unsupported_group_provider_platform do
122
- before(:each) do
123
- @grp_resource.run_action(:create)
255
+ describe "group remove action" do
256
+ describe "when there is a group" do
257
+ before do
258
+ group_resource.run_action(:create)
259
+ group_should_exist(group_name)
260
+ end
261
+
262
+ it "should remove a group" do
263
+ group_resource.run_action(:remove)
264
+ group_should_not_exist(group_name)
265
+ end
124
266
  end
125
267
 
126
- after(:each) do
127
- @grp_resource.run_action(:remove)
128
- end
129
-
130
- it "add user to group" do
131
- user1 = "user1-#{SecureRandom.random_number(9999)}"
132
- user2 = "user2-#{SecureRandom.random_number(9999)}"
133
-
134
- create_user(user1)
135
- @grp_resource.members(user1)
136
- expect(user_exist_in_group?(@grp_resource, user1)).to be_false
137
- @grp_resource.run_action(:modify)
138
- group_should_exist(@grp_resource)
139
- expect(user_exist_in_group?(@grp_resource, user1)).to be_true
140
-
141
- create_user(user2)
142
- expect(user_exist_in_group?(@grp_resource, user2)).to be_false
143
- @grp_resource.members(user2)
144
- @grp_resource.run_action(:modify)
145
- group_should_exist(@grp_resource)
146
-
147
- #default append is false, so modify action remove old member user1 from group and add new member user2
148
- expect(user_exist_in_group?(@grp_resource, user1)).to be_false
149
- expect(user_exist_in_group?(@grp_resource, user2)).to be_true
150
- remove_user(user1)
151
- remove_user(user2)
152
- end
153
-
154
-
155
- it "append user to a group" do
156
- user1 = "user1-#{SecureRandom.random_number(9999)}"
157
- user2 = "user2-#{SecureRandom.random_number(9999)}"
158
- create_user(user1)
159
- @grp_resource.members(user1)
160
- expect(user_exist_in_group?(@grp_resource, user1)).to be_false
161
- #default append attribute is false
162
- @grp_resource.run_action(:modify)
163
- group_should_exist(@grp_resource)
164
- expect(user_exist_in_group?(@grp_resource, user1)).to be_true
165
- #set append attribute to true
166
- @grp_resource.append(true)
167
- create_user(user2)
168
- expect(user_exist_in_group?(@grp_resource, user2)).to be_false
169
- @grp_resource.members(user2)
170
- @grp_resource.run_action(:modify)
171
- group_should_exist(@grp_resource)
172
- expect(user_exist_in_group?(@grp_resource, user1)).to be_true
173
- expect(user_exist_in_group?(@grp_resource, user2)).to be_true
174
- remove_user(user1)
175
- remove_user(user2)
176
- end
177
-
178
- it "raise error on add non-existent user to group" do
179
- user1 = "user1-#{SecureRandom.random_number(9999)}"
180
- @grp_resource.members(user1)
181
- @grp_resource.append(true)
182
- expect(user_exist_in_group?(@grp_resource, user1)).to be_false
183
- expect { @grp_resource.run_action(:modify) }.to raise_error
268
+ describe "when there is no group" do
269
+ it "should be no-op" do
270
+ group_resource.run_action(:remove)
271
+ group_should_not_exist(group_name)
272
+ end
184
273
  end
185
274
  end
186
275
 
187
- context "group manage action", :unix_only, :unsupported_group_provider_platform do
188
- before(:each) do
189
- @grp_resource.run_action(:create)
276
+ describe "group modify action", :not_supported_on_solaris do
277
+ let(:included_members) { ["spec-Gordon", "spec-Eric"] }
278
+ let(:excluded_members) { ["spec-Anthony"] }
279
+ let(:tested_action) { :modify }
280
+
281
+ describe "when there is no group" do
282
+ it "should raise an error" do
283
+ lambda { group_resource.run_action(:modify) }.should raise_error
284
+ end
190
285
  end
191
286
 
192
- after(:each) do
193
- @grp_resource.run_action(:remove)
287
+ describe "when there is a group" do
288
+ it_behaves_like "correct group management"
289
+ end
290
+ end
291
+
292
+ describe "group manage action", :not_supported_on_solaris do
293
+ let(:included_members) { ["spec-Gordon", "spec-Eric"] }
294
+ let(:excluded_members) { ["spec-Anthony"] }
295
+ let(:tested_action) { :manage }
296
+
297
+ describe "when there is no group" do
298
+ it "should raise an error" do
299
+ lambda { group_resource.run_action(:manage) }.should_not raise_error
300
+ group_should_not_exist(group_name)
301
+ end
194
302
  end
195
303
 
196
- it "change gid of the group" do
197
- grp_id = 1234567890
198
- @grp_resource.gid(grp_id)
199
- @grp_resource.run_action(:manage)
200
- group_should_exist(@grp_resource)
201
- expect(compare_gid(@grp_resource, grp_id)).to be_true
304
+ describe "when there is a group" do
305
+ it_behaves_like "correct group management"
306
+ end
307
+ end
308
+
309
+ describe "group resource with Usermod provider", :solaris_only do
310
+ describe "when excluded_members is set" do
311
+ let(:excluded_members) { ["spec-Anthony"] }
312
+
313
+ it ":manage should raise an error" do
314
+ lambda {group_resource.run_action(:manage) }.should raise_error
315
+ end
316
+
317
+ it ":modify should raise an error" do
318
+ lambda {group_resource.run_action(:modify) }.should raise_error
319
+ end
320
+
321
+ it ":create should raise an error" do
322
+ lambda {group_resource.run_action(:create) }.should raise_error
323
+ end
324
+ end
325
+
326
+ describe "when append is not set" do
327
+ let(:included_members) { ["spec-Gordon", "spec-Eric"] }
328
+
329
+ before(:each) do
330
+ group_resource.append(false)
331
+ end
332
+
333
+ it ":manage should raise an error" do
334
+ lambda {group_resource.run_action(:manage) }.should raise_error
335
+ end
336
+
337
+ it ":modify should raise an error" do
338
+ lambda {group_resource.run_action(:modify) }.should raise_error
339
+ end
202
340
  end
203
341
  end
204
342
  end
343
+