puppet 2.7.9 → 2.7.11

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of puppet might be problematic. Click here for more details.

Files changed (187) hide show
  1. data/CHANGELOG +413 -0
  2. data/README_DEVELOPER.md +28 -0
  3. data/conf/redhat/puppet.spec +10 -1
  4. data/conf/solaris/pkginfo +1 -1
  5. data/conf/suse/puppet.spec +7 -4
  6. data/ext/envpuppet.bat +13 -0
  7. data/ext/rack/files/apache2.conf +4 -0
  8. data/install.rb +4 -8
  9. data/lib/puppet.rb +1 -1
  10. data/lib/puppet/agent.rb +7 -0
  11. data/lib/puppet/agent/disabler.rb +27 -0
  12. data/lib/puppet/agent/locker.rb +0 -10
  13. data/lib/puppet/application.rb +3 -0
  14. data/lib/puppet/application/agent.rb +13 -3
  15. data/lib/puppet/application/apply.rb +6 -6
  16. data/lib/puppet/application/cert.rb +5 -5
  17. data/lib/puppet/application/instrumentation_data.rb +4 -0
  18. data/lib/puppet/application/instrumentation_listener.rb +4 -0
  19. data/lib/puppet/application/instrumentation_probe.rb +4 -0
  20. data/lib/puppet/configurer.rb +3 -1
  21. data/lib/puppet/configurer/downloader.rb +4 -2
  22. data/lib/puppet/configurer/fact_handler.rb +0 -21
  23. data/lib/puppet/daemon.rb +3 -4
  24. data/lib/puppet/defaults.rb +2 -2
  25. data/lib/puppet/face/instrumentation_data.rb +28 -0
  26. data/lib/puppet/face/instrumentation_listener.rb +96 -0
  27. data/lib/puppet/face/instrumentation_probe.rb +77 -0
  28. data/lib/puppet/face/module/list.rb +64 -0
  29. data/lib/puppet/face/module/uninstall.rb +50 -0
  30. data/lib/puppet/face/node/clean.rb +1 -4
  31. data/lib/puppet/feature/base.rb +1 -0
  32. data/lib/puppet/file_serving/content.rb +1 -1
  33. data/lib/puppet/indirector/facts/facter.rb +20 -7
  34. data/lib/puppet/indirector/facts/inventory_active_record.rb +14 -11
  35. data/lib/puppet/indirector/indirection.rb +7 -0
  36. data/lib/puppet/indirector/instrumentation_data.rb +3 -0
  37. data/lib/puppet/indirector/instrumentation_data/local.rb +19 -0
  38. data/lib/puppet/indirector/instrumentation_data/rest.rb +5 -0
  39. data/lib/puppet/indirector/instrumentation_listener.rb +3 -0
  40. data/lib/puppet/indirector/instrumentation_listener/local.rb +23 -0
  41. data/lib/puppet/indirector/instrumentation_listener/rest.rb +5 -0
  42. data/lib/puppet/indirector/instrumentation_probe.rb +3 -0
  43. data/lib/puppet/indirector/instrumentation_probe/local.rb +24 -0
  44. data/lib/puppet/indirector/instrumentation_probe/rest.rb +5 -0
  45. data/lib/puppet/indirector/rest.rb +1 -1
  46. data/lib/puppet/module.rb +13 -17
  47. data/lib/puppet/module_tool/applications.rb +1 -0
  48. data/lib/puppet/module_tool/applications/uninstaller.rb +33 -0
  49. data/lib/puppet/module_tool/contents_description.rb +1 -1
  50. data/lib/puppet/network/server.rb +2 -3
  51. data/lib/puppet/node/environment.rb +16 -3
  52. data/lib/puppet/parser/ast/leaf.rb +1 -1
  53. data/lib/puppet/parser/functions/create_resources.rb +1 -1
  54. data/lib/puppet/parser/type_loader.rb +1 -1
  55. data/lib/puppet/property.rb +46 -14
  56. data/lib/puppet/provider.rb +13 -4
  57. data/lib/puppet/provider/augeas/augeas.rb +6 -4
  58. data/lib/puppet/provider/group/pw.rb +24 -10
  59. data/lib/puppet/provider/nameservice/directoryservice.rb +146 -37
  60. data/lib/puppet/provider/package/pip.rb +1 -1
  61. data/lib/puppet/provider/package/yum.rb +1 -2
  62. data/lib/puppet/provider/service/debian.rb +14 -0
  63. data/lib/puppet/provider/service/launchd.rb +1 -1
  64. data/lib/puppet/provider/service/smf.rb +2 -2
  65. data/lib/puppet/provider/user/pw.rb +56 -2
  66. data/lib/puppet/provider/user/user_role_add.rb +32 -22
  67. data/lib/puppet/provider/user/windows_adsi.rb +1 -0
  68. data/lib/puppet/rails/benchmark.rb +1 -1
  69. data/lib/puppet/reports/store.rb +8 -1
  70. data/lib/puppet/resource/catalog.rb +5 -1
  71. data/lib/puppet/simple_graph.rb +11 -14
  72. data/lib/puppet/transaction.rb +10 -4
  73. data/lib/puppet/transaction/report.rb +9 -3
  74. data/lib/puppet/type.rb +19 -7
  75. data/lib/puppet/type/exec.rb +1 -1
  76. data/lib/puppet/type/file.rb +4 -1
  77. data/lib/puppet/type/file/ensure.rb +5 -1
  78. data/lib/puppet/type/file/mode.rb +45 -10
  79. data/lib/puppet/type/file/source.rb +4 -0
  80. data/lib/puppet/type/host.rb +17 -3
  81. data/lib/puppet/type/k5login.rb +3 -2
  82. data/lib/puppet/type/schedule.rb +3 -2
  83. data/lib/puppet/util.rb +83 -27
  84. data/lib/puppet/util/anonymous_filelock.rb +36 -0
  85. data/lib/puppet/util/docs.rb +18 -2
  86. data/lib/puppet/util/instrumentation.rb +173 -0
  87. data/lib/puppet/util/instrumentation/data.rb +34 -0
  88. data/lib/puppet/util/instrumentation/indirection_probe.rb +29 -0
  89. data/lib/puppet/util/instrumentation/instrumentable.rb +143 -0
  90. data/lib/puppet/util/instrumentation/listener.rb +60 -0
  91. data/lib/puppet/util/instrumentation/listeners/log.rb +29 -0
  92. data/lib/puppet/util/instrumentation/listeners/performance.rb +30 -0
  93. data/lib/puppet/util/monkey_patches.rb +8 -0
  94. data/lib/puppet/util/pidlock.rb +21 -25
  95. data/lib/puppet/util/rdoc/parser.rb +2 -2
  96. data/lib/puppet/util/reference.rb +8 -23
  97. data/lib/puppet/util/retryaction.rb +48 -0
  98. data/lib/puppet/util/suidmanager.rb +70 -39
  99. data/lib/puppet/util/symbolic_file_mode.rb +140 -0
  100. data/spec/integration/configurer_spec.rb +5 -0
  101. data/spec/integration/indirector/direct_file_server_spec.rb +1 -1
  102. data/spec/integration/indirector/file_content/file_server_spec.rb +7 -7
  103. data/spec/integration/provider/package_spec.rb +7 -0
  104. data/spec/unit/agent/disabler_spec.rb +60 -0
  105. data/spec/unit/agent/locker_spec.rb +0 -12
  106. data/spec/unit/agent_spec.rb +8 -0
  107. data/spec/unit/application/agent_spec.rb +38 -1
  108. data/spec/unit/application/apply_spec.rb +34 -40
  109. data/spec/unit/application/cert_spec.rb +1 -1
  110. data/spec/unit/application_spec.rb +6 -0
  111. data/spec/unit/configurer/downloader_spec.rb +29 -10
  112. data/spec/unit/configurer/fact_handler_spec.rb +5 -29
  113. data/spec/unit/configurer_spec.rb +8 -8
  114. data/spec/unit/daemon_spec.rb +12 -26
  115. data/spec/unit/face/instrumentation_data.rb +7 -0
  116. data/spec/unit/face/instrumentation_listener.rb +38 -0
  117. data/spec/unit/face/instrumentation_probe.rb +21 -0
  118. data/spec/unit/face/node_spec.rb +111 -111
  119. data/spec/unit/file_serving/content_spec.rb +2 -2
  120. data/spec/unit/indirector/facts/facter_spec.rb +25 -3
  121. data/spec/unit/indirector/facts/inventory_active_record_spec.rb +14 -4
  122. data/spec/unit/indirector/instrumentation_data/local_spec.rb +52 -0
  123. data/spec/unit/indirector/instrumentation_data/rest_spec.rb +11 -0
  124. data/spec/unit/indirector/instrumentation_listener/local_spec.rb +65 -0
  125. data/spec/unit/indirector/instrumentation_listener/rest_spec.rb +11 -0
  126. data/spec/unit/indirector/instrumentation_probe/local_spec.rb +65 -0
  127. data/spec/unit/indirector/instrumentation_probe/rest_spec.rb +11 -0
  128. data/spec/unit/module_spec.rb +39 -125
  129. data/spec/unit/module_tool/uninstaller_spec.rb +44 -0
  130. data/spec/unit/network/server_spec.rb +2 -20
  131. data/spec/unit/node/environment_spec.rb +76 -58
  132. data/spec/unit/parser/ast/asthash_spec.rb +1 -2
  133. data/spec/unit/parser/ast/leaf_spec.rb +16 -0
  134. data/spec/unit/property/keyvalue_spec.rb +5 -2
  135. data/spec/unit/property_spec.rb +260 -159
  136. data/spec/unit/provider/augeas/augeas_spec.rb +2 -2
  137. data/spec/unit/provider/group/pw_spec.rb +81 -0
  138. data/spec/unit/provider/nameservice/directoryservice_spec.rb +102 -0
  139. data/spec/unit/provider/package/pip_spec.rb +7 -0
  140. data/spec/unit/provider/package/yum_spec.rb +45 -1
  141. data/spec/unit/provider/service/debian_spec.rb +15 -0
  142. data/spec/unit/provider/service/launchd_spec.rb +48 -43
  143. data/spec/unit/provider/service/smf_spec.rb +3 -3
  144. data/spec/unit/provider/user/pw_spec.rb +183 -0
  145. data/spec/unit/provider/user/user_role_add_spec.rb +46 -39
  146. data/spec/unit/provider/user/windows_adsi_spec.rb +1 -0
  147. data/spec/unit/provider_spec.rb +32 -0
  148. data/spec/unit/reports/store_spec.rb +19 -1
  149. data/spec/unit/simple_graph_spec.rb +34 -19
  150. data/spec/unit/ssl/certificate_factory_spec.rb +3 -3
  151. data/spec/unit/transaction/report_spec.rb +29 -1
  152. data/spec/unit/transaction_spec.rb +32 -46
  153. data/spec/unit/type/file/mode_spec.rb +1 -1
  154. data/spec/unit/type/file/source_spec.rb +28 -3
  155. data/spec/unit/type/file_spec.rb +17 -16
  156. data/spec/unit/type/host_spec.rb +527 -0
  157. data/spec/unit/type/k5login_spec.rb +115 -0
  158. data/spec/unit/type/schedule_spec.rb +6 -6
  159. data/spec/unit/type_spec.rb +51 -0
  160. data/spec/unit/util/anonymous_filelock_spec.rb +78 -0
  161. data/spec/unit/util/execution_stub_spec.rb +2 -1
  162. data/spec/unit/util/instrumentation/data_spec.rb +44 -0
  163. data/spec/unit/util/instrumentation/indirection_probe_spec.rb +19 -0
  164. data/spec/unit/util/instrumentation/instrumentable_spec.rb +186 -0
  165. data/spec/unit/util/instrumentation/listener_spec.rb +100 -0
  166. data/spec/unit/util/instrumentation/listeners/log_spec.rb +34 -0
  167. data/spec/unit/util/instrumentation/listeners/performance_spec.rb +36 -0
  168. data/spec/unit/util/instrumentation_spec.rb +181 -0
  169. data/spec/unit/util/pidlock_spec.rb +208 -0
  170. data/spec/unit/util/rdoc/parser_spec.rb +1 -1
  171. data/spec/unit/util/reference_spec.rb +16 -6
  172. data/spec/unit/util/retryaction_spec.rb +62 -0
  173. data/spec/unit/util/suidmanager_spec.rb +101 -83
  174. data/spec/unit/util/symbolic_file_mode_spec.rb +182 -0
  175. data/spec/unit/util_spec.rb +126 -0
  176. data/tasks/rake/apple.rake +176 -0
  177. data/tasks/rake/templates/prototype.plist.erb +38 -0
  178. metadata +61 -13
  179. data/lib/puppet/application/module.rb +0 -3
  180. data/lib/puppet/face/module.rb +0 -12
  181. data/spec/unit/face/module/build_spec.rb +0 -30
  182. data/spec/unit/face/module/changes_spec.rb +0 -30
  183. data/spec/unit/face/module/clean_spec.rb +0 -30
  184. data/spec/unit/face/module/generate_spec.rb +0 -30
  185. data/spec/unit/face/module/install_spec.rb +0 -75
  186. data/spec/unit/face/module/search_spec.rb +0 -40
  187. data/test/util/pidlock.rb +0 -126
@@ -135,7 +135,7 @@ describe RDoc::Parser, :'fails_on_ruby_1.9.2' => true do
135
135
 
136
136
  describe "when finding modules from filepath" do
137
137
  before :each do
138
- Puppet::Module.stubs(:modulepath).returns("/path/to/modules")
138
+ Puppet::Node::Environment.any_instance.stubs(:modulepath).returns("/path/to/modules")
139
139
  end
140
140
 
141
141
  it "should return the module name for modulized puppet manifests" do
@@ -8,20 +8,30 @@ describe Puppet::Util::Reference do
8
8
  Puppet::Util::Reference.newreference :testreference, :doc => "A peer of the type and configuration references, but with no useful information" do
9
9
  my_term = "A term"
10
10
  my_definition = <<-EOT
11
- The definition of this term.
12
- We should be able to handle multi-line definitions.
11
+ The definition of this term, marked by a colon and a space.
12
+ We should be able to handle multi-line definitions. Each subsequent
13
+ line should left-align with the first word character after the colon
14
+ used as the definition marker.
13
15
 
14
- We should be able to handle multi-paragraph definitions.
16
+ We should be able to handle multi-paragraph definitions.
17
+
18
+ Leading indentation should be stripped from the definition, which allows
19
+ us to indent the source string for cosmetic purposes.
15
20
  EOT
16
21
  my_fragment = markdown_definitionlist(my_term, my_definition)
17
22
  end
18
23
  Puppet::Util::Reference.reference(:testreference).send(:to_markdown, true)
19
24
  my_fragment.should == <<-EOT
20
25
  A term
21
- : The definition of this term.
22
- We should be able to handle multi-line definitions.
26
+ : The definition of this term, marked by a colon and a space.
27
+ We should be able to handle multi-line definitions. Each subsequent
28
+ line should left-align with the first word character after the colon
29
+ used as the definition marker.
30
+
31
+ We should be able to handle multi-paragraph definitions.
23
32
 
24
- We should be able to handle multi-paragraph definitions.
33
+ Leading indentation should be stripped from the definition, which allows
34
+ us to indent the source string for cosmetic purposes.
25
35
 
26
36
  EOT
27
37
  end
@@ -0,0 +1,62 @@
1
+ #!/usr/bin/env rspec
2
+ require 'spec_helper'
3
+
4
+ require 'puppet/util/retryaction'
5
+
6
+ describe Puppet::Util::RetryAction do
7
+ let (:exceptions) {{ Puppet::Error => 'Puppet Error Exception' }}
8
+
9
+ it 'should retry on any exception if no acceptable exceptions given' do
10
+ Puppet::Util::RetryAction.expects(:sleep).with( (((2 ** 1) -1) * 0.1) )
11
+ Puppet::Util::RetryAction.expects(:sleep).with( (((2 ** 2) -1) * 0.1) )
12
+
13
+ expect do
14
+ Puppet::Util::RetryAction.retry_action( :retries => 2 ) do
15
+ raise ArgumentError, 'Fake Failure'
16
+ end
17
+ end.to raise_exception(Puppet::Util::RetryAction::RetryException::RetriesExceeded)
18
+ end
19
+
20
+ it 'should retry on acceptable exceptions' do
21
+ Puppet::Util::RetryAction.expects(:sleep).with( (((2 ** 1) -1) * 0.1) )
22
+ Puppet::Util::RetryAction.expects(:sleep).with( (((2 ** 2) -1) * 0.1) )
23
+
24
+ expect do
25
+ Puppet::Util::RetryAction.retry_action( :retries => 2, :retry_exceptions => exceptions) do
26
+ raise Puppet::Error, 'Fake Failure'
27
+ end
28
+ end.to raise_exception(Puppet::Util::RetryAction::RetryException::RetriesExceeded)
29
+ end
30
+
31
+ it 'should not retry on unacceptable exceptions' do
32
+ Puppet::Util::RetryAction.expects(:sleep).never
33
+
34
+ expect do
35
+ Puppet::Util::RetryAction.retry_action( :retries => 2, :retry_exceptions => exceptions) do
36
+ raise ArgumentError
37
+ end
38
+ end.to raise_exception(ArgumentError)
39
+ end
40
+
41
+ it 'should succeed if nothing is raised' do
42
+ Puppet::Util::RetryAction.expects(:sleep).never
43
+
44
+ Puppet::Util::RetryAction.retry_action( :retries => 2) do
45
+ true
46
+ end
47
+ end
48
+
49
+ it 'should succeed if an expected exception is raised retried and succeeds' do
50
+ should_retry = nil
51
+ Puppet::Util::RetryAction.expects(:sleep).once
52
+
53
+ Puppet::Util::RetryAction.retry_action( :retries => 2, :retry_exceptions => exceptions) do
54
+ if should_retry
55
+ true
56
+ else
57
+ should_retry = true
58
+ raise Puppet::Error, 'Fake error'
59
+ end
60
+ end
61
+ end
62
+ end
@@ -13,10 +13,18 @@ describe Puppet::Util::SUIDManager do
13
13
 
14
14
  before :each do
15
15
  Puppet::Util::SUIDManager.stubs(:convert_xid).returns(42)
16
- Puppet::Util::SUIDManager.stubs(:initgroups)
16
+ pwent = stub('pwent', :name => 'fred', :uid => 42, :gid => 42)
17
+ Etc.stubs(:getpwuid).with(42).returns(pwent)
17
18
 
18
19
  [:euid, :egid, :uid, :gid, :groups].each do |id|
19
- Process.stubs("#{id}=").with {|value| xids[id] = value}
20
+ Process.stubs("#{id}=").with {|value| xids[id] = value }
21
+ end
22
+ end
23
+
24
+ describe "#initgroups" do
25
+ it "should use the primary group of the user as the 'basegid'" do
26
+ Process.expects(:initgroups).with('fred', 42)
27
+ described_class.initgroups(42)
20
28
  end
21
29
  end
22
30
 
@@ -31,40 +39,88 @@ describe Puppet::Util::SUIDManager do
31
39
  end
32
40
 
33
41
  describe "#asuser" do
34
- it "should set euid/egid when root" do
35
- Process.stubs(:uid).returns(0)
42
+ it "should not get or set euid/egid when not root" do
36
43
  Puppet.features.stubs(:microsoft_windows?).returns(false)
44
+ Process.stubs(:uid).returns(1)
37
45
 
38
46
  Process.stubs(:egid).returns(51)
39
47
  Process.stubs(:euid).returns(50)
40
48
 
41
- Puppet::Util::SUIDManager.stubs(:convert_xid).with(:gid, 51).returns(51)
42
- Puppet::Util::SUIDManager.stubs(:convert_xid).with(:uid, 50).returns(50)
49
+ Puppet::Util::SUIDManager.asuser(user[:uid], user[:gid]) {}
43
50
 
44
- yielded = false
45
- Puppet::Util::SUIDManager.asuser(user[:uid], user[:gid]) do
46
- xids[:egid].should == user[:gid]
47
- xids[:euid].should == user[:uid]
48
- yielded = true
51
+ xids.should be_empty
52
+ end
53
+
54
+ context "when root and not windows" do
55
+ before :each do
56
+ Process.stubs(:uid).returns(0)
57
+ Puppet.features.stubs(:microsoft_windows?).returns(false)
49
58
  end
50
59
 
51
- xids[:egid].should == 51
52
- xids[:euid].should == 50
60
+ it "should set euid/egid when root" do
61
+ Process.stubs(:uid).returns(0)
53
62
 
54
- # It's possible asuser could simply not yield, so the assertions in the
55
- # block wouldn't fail. So verify those actually got checked.
56
- yielded.should be_true
57
- end
63
+ Process.stubs(:egid).returns(51)
64
+ Process.stubs(:euid).returns(50)
58
65
 
59
- it "should not get or set euid/egid when not root" do
60
- Process.stubs(:uid).returns(1)
66
+ Puppet::Util::SUIDManager.stubs(:convert_xid).with(:gid, 51).returns(51)
67
+ Puppet::Util::SUIDManager.stubs(:convert_xid).with(:uid, 50).returns(50)
68
+ Puppet::Util::SUIDManager.stubs(:initgroups).returns([])
61
69
 
62
- Process.stubs(:egid).returns(51)
63
- Process.stubs(:euid).returns(50)
70
+ yielded = false
71
+ Puppet::Util::SUIDManager.asuser(user[:uid], user[:gid]) do
72
+ xids[:egid].should == user[:gid]
73
+ xids[:euid].should == user[:uid]
74
+ yielded = true
75
+ end
64
76
 
65
- Puppet::Util::SUIDManager.asuser(user[:uid], user[:gid]) {}
77
+ xids[:egid].should == 51
78
+ xids[:euid].should == 50
66
79
 
67
- xids.should be_empty
80
+ # It's possible asuser could simply not yield, so the assertions in the
81
+ # block wouldn't fail. So verify those actually got checked.
82
+ yielded.should be_true
83
+ end
84
+
85
+ it "should just yield if user and group are nil" do
86
+ yielded = false
87
+ Puppet::Util::SUIDManager.asuser(nil, nil) { yielded = true }
88
+ yielded.should be_true
89
+ xids.should == {}
90
+ end
91
+
92
+ it "should just change group if only group is given" do
93
+ yielded = false
94
+ Puppet::Util::SUIDManager.asuser(nil, 42) { yielded = true }
95
+ yielded.should be_true
96
+ xids.should == { :egid => 42 }
97
+ end
98
+
99
+ it "should change gid to the primary group of uid by default" do
100
+ Process.stubs(:initgroups)
101
+
102
+ yielded = false
103
+ Puppet::Util::SUIDManager.asuser(42) { yielded = true }
104
+ yielded.should be_true
105
+ xids.should == { :euid => 42, :egid => 42 }
106
+ end
107
+
108
+ it "should change both uid and gid if given" do
109
+ # I don't like the sequence, but it is the only way to assert on the
110
+ # internal behaviour in a reliable fashion, given we need multiple
111
+ # sequenced calls to the same methods. --daniel 2012-02-05
112
+ horror = sequence('of user and group changes')
113
+ Puppet::Util::SUIDManager.expects(:change_group).with(43, false).in_sequence(horror)
114
+ Puppet::Util::SUIDManager.expects(:change_user).with(42, false).in_sequence(horror)
115
+ Puppet::Util::SUIDManager.expects(:change_group).
116
+ with(Puppet::Util::SUIDManager.egid, false).in_sequence(horror)
117
+ Puppet::Util::SUIDManager.expects(:change_user).
118
+ with(Puppet::Util::SUIDManager.euid, false).in_sequence(horror)
119
+
120
+ yielded = false
121
+ Puppet::Util::SUIDManager.asuser(42, 43) { yielded = true }
122
+ yielded.should be_true
123
+ end
68
124
  end
69
125
 
70
126
  it "should not get or set euid/egid on Windows" do
@@ -78,7 +134,7 @@ describe Puppet::Util::SUIDManager do
78
134
 
79
135
  describe "#change_group" do
80
136
  describe "when changing permanently" do
81
- it "should try to change_privilege if it is supported" do
137
+ it "should change_privilege" do
82
138
  Process::GID.expects(:change_privilege).with do |gid|
83
139
  Process.gid = gid
84
140
  Process.egid = gid
@@ -89,15 +145,6 @@ describe Puppet::Util::SUIDManager do
89
145
  xids[:egid].should == 42
90
146
  xids[:gid].should == 42
91
147
  end
92
-
93
- it "should change both egid and gid if change_privilege isn't supported" do
94
- Process::GID.stubs(:change_privilege).raises(NotImplementedError)
95
-
96
- Puppet::Util::SUIDManager.change_group(42, true)
97
-
98
- xids[:egid].should == 42
99
- xids[:gid].should == 42
100
- end
101
148
  end
102
149
 
103
150
  describe "when changing temporarily" do
@@ -112,21 +159,12 @@ describe Puppet::Util::SUIDManager do
112
159
 
113
160
  describe "#change_user" do
114
161
  describe "when changing permanently" do
115
- it "should try to change_privilege if it is supported" do
162
+ it "should change_privilege" do
116
163
  Process::UID.expects(:change_privilege).with do |uid|
117
164
  Process.uid = uid
118
165
  Process.euid = uid
119
166
  end
120
167
 
121
- Puppet::Util::SUIDManager.change_user(42, true)
122
-
123
- xids[:euid].should == 42
124
- xids[:uid].should == 42
125
- end
126
-
127
- it "should change euid and uid and groups if change_privilege isn't supported" do
128
- Process::UID.stubs(:change_privilege).raises(NotImplementedError)
129
-
130
168
  Puppet::Util::SUIDManager.expects(:initgroups).with(42)
131
169
 
132
170
  Puppet::Util::SUIDManager.change_user(42, true)
@@ -138,6 +176,7 @@ describe Puppet::Util::SUIDManager do
138
176
 
139
177
  describe "when changing temporarily" do
140
178
  it "should change only euid and groups" do
179
+ Puppet::Util::SUIDManager.stubs(:initgroups).returns([])
141
180
  Puppet::Util::SUIDManager.change_user(42, false)
142
181
 
143
182
  xids[:euid].should == 42
@@ -174,46 +213,6 @@ describe Puppet::Util::SUIDManager do
174
213
  Kernel.system '' if $CHILD_STATUS.nil?
175
214
  end
176
215
 
177
- describe "with #system" do
178
- it "should set euid/egid when root" do
179
- Process.stubs(:uid).returns(0)
180
- Puppet.features.stubs(:microsoft_windows?).returns(false)
181
-
182
- Process.stubs(:egid).returns(51)
183
- Process.stubs(:euid).returns(50)
184
-
185
- Puppet::Util::SUIDManager.stubs(:convert_xid).with(:gid, 51).returns(51)
186
- Puppet::Util::SUIDManager.stubs(:convert_xid).with(:uid, 50).returns(50)
187
-
188
- Puppet::Util::SUIDManager.expects(:change_group).with(user[:uid])
189
- Puppet::Util::SUIDManager.expects(:change_user).with(user[:uid])
190
-
191
- Puppet::Util::SUIDManager.expects(:change_group).with(51)
192
- Puppet::Util::SUIDManager.expects(:change_user).with(50)
193
-
194
- Kernel.expects(:system).with('blah')
195
- Puppet::Util::SUIDManager.system('blah', user[:uid], user[:gid])
196
- end
197
-
198
- it "should not get or set euid/egid when not root" do
199
- Process.stubs(:uid).returns(1)
200
- Kernel.expects(:system).with('blah')
201
-
202
- Puppet::Util::SUIDManager.system('blah', user[:uid], user[:gid])
203
-
204
- xids.should be_empty
205
- end
206
-
207
- it "should not get or set euid/egid on Windows" do
208
- Puppet.features.stubs(:microsoft_windows?).returns true
209
- Kernel.expects(:system).with('blah')
210
-
211
- Puppet::Util::SUIDManager.system('blah', user[:uid], user[:gid])
212
-
213
- xids.should be_empty
214
- end
215
- end
216
-
217
216
  describe "with #run_and_capture" do
218
217
  it "should capture the output and return process status" do
219
218
  Puppet::Util.
@@ -308,3 +307,22 @@ describe Puppet::Util::SUIDManager do
308
307
  end
309
308
  end
310
309
  end
310
+
311
+ describe 'Puppet::Util::SUIDManager#groups=' do
312
+ subject do
313
+ Puppet::Util::SUIDManager
314
+ end
315
+
316
+
317
+ it "(#3419) should rescue Errno::EINVAL on OS X" do
318
+ Process.expects(:groups=).raises(Errno::EINVAL, 'blew up')
319
+ subject.expects(:osx_maj_ver).returns('10.7').twice
320
+ subject.groups = ['list', 'of', 'groups']
321
+ end
322
+
323
+ it "(#3419) should fail if an Errno::EINVAL is raised NOT on OS X" do
324
+ Process.expects(:groups=).raises(Errno::EINVAL, 'blew up')
325
+ subject.expects(:osx_maj_ver).returns(false)
326
+ expect { subject.groups = ['list', 'of', 'groups'] }.should raise_error(Errno::EINVAL)
327
+ end
328
+ end
@@ -0,0 +1,182 @@
1
+ #!/usr/bin/env rspec
2
+ require 'spec_helper'
3
+
4
+ require 'puppet/util/symbolic_file_mode'
5
+
6
+ describe Puppet::Util::SymbolicFileMode do
7
+ include Puppet::Util::SymbolicFileMode
8
+
9
+ describe "#valid_symbolic_mode?" do
10
+ %w{
11
+ 0 0000 1 1 7 11 77 111 777 11
12
+ 0 00000 01 01 07 011 077 0111 0777 011
13
+ = - + u= g= o= a= u+ g+ o+ a+ u- g- o- a- ugo= ugoa= ugugug=
14
+ a=,u=,g= a=,g+
15
+ =rwx +rwx -rwx
16
+ 644 go-w =rw,+X +X 755 u=rwx,go=rx u=rwx,go=u-w go= g=u-w
17
+ 755 0755
18
+ }.each do |input|
19
+ it "should treat #{input.inspect} as valid" do
20
+ valid_symbolic_mode?(input).should be_true
21
+ end
22
+ end
23
+
24
+ [0000, 0111, 0640, 0755, 0777].each do |input|
25
+ it "should treat the int #{input.to_s(8)} as value" do
26
+ valid_symbolic_mode?(input).should be_true
27
+ end
28
+ end
29
+
30
+ %w{
31
+ -1 -8 8 9 18 19 91 81 000000 11111 77777
32
+ 0-1 0-8 08 09 018 019 091 081 0000000 011111 077777
33
+ u g o a ug uo ua ag
34
+ }.each do |input|
35
+ it "should treat #{input.inspect} as invalid" do
36
+ valid_symbolic_mode?(input).should be_false
37
+ end
38
+ end
39
+ end
40
+
41
+ describe "#normalize_symbolic_mode" do
42
+ it "should turn an int into a string" do
43
+ normalize_symbolic_mode(12).should be_an_instance_of String
44
+ end
45
+
46
+ it "should not add a leading zero to an int" do
47
+ normalize_symbolic_mode(12).should_not =~ /^0/
48
+ end
49
+
50
+ it "should not add a leading zero to a string with a number" do
51
+ normalize_symbolic_mode("12").should_not =~ /^0/
52
+ end
53
+
54
+ it "should string a leading zero from a number" do
55
+ normalize_symbolic_mode("012").should == '12'
56
+ end
57
+
58
+ it "should pass through any other string" do
59
+ normalize_symbolic_mode("u=rwx").should == 'u=rwx'
60
+ end
61
+ end
62
+
63
+ describe "#symbolic_mode_to_int" do
64
+ {
65
+ "0654" => 00654,
66
+ "u+r" => 00400,
67
+ "g+r" => 00040,
68
+ "a+r" => 00444,
69
+ "a+x" => 00111,
70
+ "o+t" => 01000,
71
+ "o+t" => 01000,
72
+ ["o-t", 07777] => 06777,
73
+ ["a-x", 07777] => 07666,
74
+ ["a-rwx", 07777] => 07000,
75
+ ["ug-rwx", 07777] => 07007,
76
+ "a+x,ug-rwx" => 00001,
77
+ # My experimentation on debian suggests that +g ignores the sgid flag
78
+ ["a+g", 02060] => 02666,
79
+ # My experimentation on debian suggests that -g ignores the sgid flag
80
+ ["a-g", 02666] => 02000,
81
+ "g+x,a+g" => 00111,
82
+ # +X without exec set in the original should not set anything
83
+ "u+x,g+X" => 00100,
84
+ "g+X" => 00000,
85
+ # +X only refers to the original, *unmodified* file mode!
86
+ ["u+x,a+X", 0600] => 00700,
87
+ # Examples from the MacOS chmod(1) manpage
88
+ "0644" => 00644,
89
+ ["go-w", 07777] => 07755,
90
+ ["=rw,+X", 07777] => 07777,
91
+ ["=rw,+X", 07766] => 07777,
92
+ ["=rw,+X", 07676] => 07777,
93
+ ["=rw,+X", 07667] => 07777,
94
+ ["=rw,+X", 07666] => 07666,
95
+ "0755" => 00755,
96
+ "u=rwx,go=rx" => 00755,
97
+ "u=rwx,go=u-w" => 00755,
98
+ ["go=", 07777] => 07700,
99
+ ["g=u-w", 07777] => 07757,
100
+ ["g=u-w", 00700] => 00750,
101
+ ["g=u-w", 00600] => 00640,
102
+ ["g=u-w", 00500] => 00550,
103
+ ["g=u-w", 00400] => 00440,
104
+ ["g=u-w", 00300] => 00310,
105
+ ["g=u-w", 00200] => 00200,
106
+ ["g=u-w", 00100] => 00110,
107
+ ["g=u-w", 00000] => 00000,
108
+ # Cruel, but legal, use of the action set.
109
+ ["g=u+r-w", 0300] => 00350,
110
+ # Empty assignments.
111
+ ["u=", 00000] => 00000,
112
+ ["u=", 00600] => 00000,
113
+ ["ug=", 00000] => 00000,
114
+ ["ug=", 00600] => 00000,
115
+ ["ug=", 00660] => 00000,
116
+ ["ug=", 00666] => 00006,
117
+ ["=", 00000] => 00000,
118
+ ["=", 00666] => 00000,
119
+ ["+", 00000] => 00000,
120
+ ["+", 00124] => 00124,
121
+ ["-", 00000] => 00000,
122
+ ["-", 00124] => 00124,
123
+ }.each do |input, result|
124
+ from = input.is_a?(Array) ? "#{input[0]}, 0#{input[1].to_s(8)}" : input
125
+ it "should map #{from.inspect} to #{result.inspect}" do
126
+ symbolic_mode_to_int(*input).should == result
127
+ end
128
+ end
129
+
130
+ # Now, test some failure modes.
131
+ it "should fail if no mode is given" do
132
+ expect { symbolic_mode_to_int('') }.
133
+ to raise_error Puppet::Error, /empty mode string/
134
+ end
135
+
136
+ %w{u g o ug uo go ugo a uu u/x u!x u=r,,g=r}.each do |input|
137
+ it "should fail if no (valid) action is given: #{input.inspect}" do
138
+ expect { symbolic_mode_to_int(input) }.
139
+ to raise_error Puppet::Error, /Missing action/
140
+ end
141
+ end
142
+
143
+ %w{u+q u-rwF u+rw,g+rw,o+RW}.each do |input|
144
+ it "should fail with unknown op #{input.inspect}" do
145
+ expect { symbolic_mode_to_int(input) }.
146
+ to raise_error Puppet::Error, /Unknown operation/
147
+ end
148
+ end
149
+
150
+ it "should refuse to subtract the conditional execute op" do
151
+ expect { symbolic_mode_to_int("o-rwX") }.
152
+ to raise_error Puppet::Error, /only works with/
153
+ end
154
+
155
+ it "should refuse to set to the conditional execute op" do
156
+ expect { symbolic_mode_to_int("o=rwX") }.
157
+ to raise_error Puppet::Error, /only works with/
158
+ end
159
+
160
+ %w{8 08 9 09 118 119}.each do |input|
161
+ it "should fail for decimal modes: #{input.inspect}" do
162
+ expect { symbolic_mode_to_int(input) }.
163
+ to raise_error Puppet::Error, /octal/
164
+ end
165
+ end
166
+
167
+ it "should set the execute bit on a directory, without exec in original" do
168
+ symbolic_mode_to_int("u+X", 0444, true).to_s(8).should == "544"
169
+ symbolic_mode_to_int("g+X", 0444, true).to_s(8).should == "454"
170
+ symbolic_mode_to_int("o+X", 0444, true).to_s(8).should == "445"
171
+ symbolic_mode_to_int("+X", 0444, true).to_s(8).should == "555"
172
+ end
173
+
174
+ it "should set the execute bit on a file with exec in the original" do
175
+ symbolic_mode_to_int("+X", 0544).to_s(8).should == "555"
176
+ end
177
+
178
+ it "should not set the execute bit on a file without exec on the original even if set by earlier DSL" do
179
+ symbolic_mode_to_int("u+x,go+X", 0444).to_s(8).should == "544"
180
+ end
181
+ end
182
+ end