Permalink
Browse files

Merge pull request #62 from vStone/feature/symbolic_filemodes

Feature/symbolic filemodes (cfr ticket #60)

Closes #60
  • Loading branch information...
2 parents 6a1ce04 + 7293e5d commit a40113365fa76a703dccd40b287e4f0168b170e0 Tim Sharpe committed Mar 26, 2012
Showing with 20 additions and 5 deletions.
  1. +1 −1 README.md
  2. +3 −3 lib/puppet-lint/plugins/check_resources.rb
  3. +16 −1 spec/puppet-lint/check_resources_spec.rb
View
@@ -60,7 +60,7 @@ At the moment, the following tests have been implemented:
* Symbolic links should be declared by using an ensure value of `link` and
explicitly specifying a value for the `target` attribute.
* File modes should be represented as a 4 digit string enclosed in single
- quotes.
+ quotes or use symbolic file modes.
### Conditionals
@@ -41,7 +41,7 @@ class PuppetLint::Plugins::CheckResources < PuppetLint::CheckPlugin
end
end
- check '4digit_file_mode' do
+ check 'file_mode' do
resource_indexes.each do |resource|
resource_tokens = tokens[resource[:start]..resource[:end]]
resource_type_token = tokens[tokens[0..resource[:start]].rindex { |r| r.first == :LBRACE } - 1]
@@ -50,8 +50,8 @@ class PuppetLint::Plugins::CheckResources < PuppetLint::CheckPlugin
attr_token = resource_tokens[resource_token_idx]
if attr_token.first == :NAME and attr_token.last[:value] == 'mode'
value_token = resource_tokens[resource_token_idx + 2]
- if value_token.last[:value] !~ /\d{4}/ and value_token.first != :VARIABLE
- notify :warning, :message => "mode should be represented as a 4 digit octal value", :linenumber => value_token.last[:line]
+ if value_token.last[:value] !~ /\d{4}/ and value_token.first != :VARIABLE and value_token.last[:value] !~ /^([ugoa]*[-=+][-=+rstwxXugo]*)(,[ugoa]*[-=+][-=+rstwxXugo]*)*$/
+ notify :warning, :message => "mode should be represented as a 4 digit octal value or symbolic file mode", :linenumber => value_token.last[:line]
end
end
end
@@ -11,7 +11,7 @@
let(:code) { "file { 'foo': mode => 777 }" }
its(:problems) {
- should have_problem :kind => :warning, :message => "mode should be represented as a 4 digit octal value", :linenumber => 1
+ should have_problem :kind => :warning, :message => "mode should be represented as a 4 digit octal value or symbolic file mode", :linenumber => 1
should_not have_problem :kind => :error
}
end
@@ -22,12 +22,27 @@
its(:problems) { should be_empty }
end
+ describe '4 digit unquoted file mode' do
+ let(:code) { "file { 'foo': mode => 0777 }" }
+
+ its(:problems) {
+ should have_problem :kind => :warning, :message => "unquoted file mode"
+ should_not have_problem :kind => :error
+ }
+ end
+
describe 'file mode as a variable' do
let(:code) { "file { 'foo': mode => $file_mode }" }
its(:problems) { should be_empty }
end
+ describe 'symbolic file mode' do
+ let(:code) { "file { 'foo': mode => 'u=rw,og=r' }" }
+
+ its(:problems) { should be_empty }
+ end
+
describe 'ensure as only attr in a single line resource' do
let(:code) { "file { 'foo': ensure => present }" }

0 comments on commit a401133

Please sign in to comment.