Skip to content

Commit 377745a

Browse files
committed
Merge branch 'CHEF-1803'
2 parents 7dc80dc + d59b947 commit 377745a

4 files changed

Lines changed: 69 additions & 5 deletions

File tree

chef/lib/chef/resource/file.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,14 @@ def mode(arg=nil)
6767
set_or_return(
6868
:mode,
6969
arg,
70-
:regex => /^0?\d{3,4}$/
70+
:callbacks => {
71+
"not in valid numeric range" => lambda { |m|
72+
if m.kind_of?(String)
73+
m =~ /^0/ || m="0#{m}"
74+
end
75+
Integer(m)<=07777 && Integer(m)>=0
76+
}
77+
}
7178
)
7279
end
7380

chef/spec/unit/resource/file_spec.rb

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,47 @@
7777
lambda { @resource.group "root*goo" }.should raise_error(ArgumentError)
7878
end
7979

80-
it "should accept a valid unix file mode" do
80+
it "should accept a unix file mode in string form as an octal number" do
81+
lambda { @resource.mode "0" }.should_not raise_error(ArgumentError)
82+
lambda { @resource.mode "0000" }.should_not raise_error(ArgumentError)
83+
lambda { @resource.mode "0111" }.should_not raise_error(ArgumentError)
84+
lambda { @resource.mode "0444" }.should_not raise_error(ArgumentError)
85+
lambda { @resource.mode "07777" }.should_not raise_error(ArgumentError)
86+
87+
lambda { @resource.mode "0" }.should_not raise_error(ArgumentError)
88+
lambda { @resource.mode "111" }.should_not raise_error(ArgumentError)
89+
lambda { @resource.mode "444" }.should_not raise_error(ArgumentError)
90+
lambda { @resource.mode "7777" }.should_not raise_error(ArgumentError)
91+
92+
lambda { @resource.mode "-01" }.should raise_error(ArgumentError)
93+
lambda { @resource.mode "010000" }.should raise_error(ArgumentError)
94+
lambda { @resource.mode "-1" }.should raise_error(ArgumentError)
95+
lambda { @resource.mode "10000" }.should raise_error(ArgumentError)
96+
97+
lambda { @resource.mode "07778" }.should raise_error(ArgumentError)
98+
lambda { @resource.mode "7778" }.should raise_error(ArgumentError)
99+
lambda { @resource.mode "4095" }.should raise_error(ArgumentError)
100+
101+
lambda { @resource.mode "0foo1234" }.should raise_error(ArgumentError)
102+
lambda { @resource.mode "foo1234" }.should raise_error(ArgumentError)
103+
end
104+
105+
it "should accept a unix file mode in numeric form as a ruby-interpreted integer" do
106+
lambda { @resource.mode 0 }.should_not raise_error(ArgumentError)
107+
lambda { @resource.mode 0000 }.should_not raise_error(ArgumentError)
108+
lambda { @resource.mode 0111 }.should_not raise_error(ArgumentError)
81109
lambda { @resource.mode 0444 }.should_not raise_error(ArgumentError)
82-
@resource.mode.should eql(0444)
83-
lambda { @resource.mode 444 }.should_not raise_error(ArgumentError)
84-
lambda { @resource.mode 4 }.should raise_error(ArgumentError)
110+
lambda { @resource.mode 07777 }.should_not raise_error(ArgumentError)
111+
112+
lambda { @resource.mode 0 }.should_not raise_error(ArgumentError)
113+
lambda { @resource.mode 73 }.should_not raise_error(ArgumentError)
114+
lambda { @resource.mode 292 }.should_not raise_error(ArgumentError)
115+
lambda { @resource.mode 4095 }.should_not raise_error(ArgumentError)
116+
117+
lambda { @resource.mode -01 }.should raise_error(ArgumentError)
118+
lambda { @resource.mode 010000 }.should raise_error(ArgumentError)
119+
lambda { @resource.mode -1 }.should raise_error(ArgumentError)
120+
lambda { @resource.mode 4096 }.should raise_error(ArgumentError)
85121
end
86122

87123
it "should accept a user name or id for owner" do

features/data/cookbooks/manage_files/recipes/set_the_accessibility_of_a_created_file.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@
1717
# limitations under the License.
1818
#
1919

20+
file "#{node[:tmpdir]}/octal0111.txt" do
21+
owner 'nobody'
22+
mode 0111
23+
action :create
24+
end
25+
2026
file "#{node[:tmpdir]}/octal0644.txt" do
2127
owner 'nobody'
2228
mode 0644
@@ -29,6 +35,12 @@
2935
action :create
3036
end
3137

38+
file "#{node[:tmpdir]}/decimal73.txt" do
39+
owner 'nobody'
40+
mode 73
41+
action :create
42+
end
43+
3244
file "#{node[:tmpdir]}/decimal644.txt" do
3345
owner 'nobody'
3446
mode 644
@@ -41,6 +53,12 @@
4153
action :create
4254
end
4355

56+
file "#{node[:tmpdir]}/string111.txt" do
57+
owner 'nobody'
58+
mode "111"
59+
action :create
60+
end
61+
4462
file "#{node[:tmpdir]}/string644.txt" do
4563
owner 'nobody'
4664
mode "644"

features/provider/file/manage_files.feature

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,13 @@ Feature: Manage Files
4646
And it includes the recipe 'manage_files::set_the_accessibility_of_a_created_file'
4747
When I run the chef-client
4848
Then the run should exit '0'
49+
And the file named 'octal0111.txt' should have octal mode '0111'
4950
And the file named 'octal0644.txt' should have octal mode '0644'
5051
And the file named 'octal2644.txt' should have octal mode '2644'
52+
And the file named 'decimal73.txt' should have decimal mode '73'
5153
And the file named 'decimal644.txt' should have decimal mode '644'
5254
And the file named 'decimal2644.txt' should have decimal mode '2644'
55+
And the file named 'string111.txt' should have octal mode '111'
5356
And the file named 'string644.txt' should have octal mode '644'
5457
And the file named 'string0644.txt' should have octal mode '0644'
5558
And the file named 'string2644.txt' should have octal mode '2644'

0 commit comments

Comments
 (0)