diff --git a/saltlint/rules/FileModeQuotationRule.py b/saltlint/rules/FileModeQuotationRule.py index 07a21eb..38bbae7 100644 --- a/saltlint/rules/FileModeQuotationRule.py +++ b/saltlint/rules/FileModeQuotationRule.py @@ -17,7 +17,25 @@ class FileModeQuotationRule(Rule): tags = ['formatting'] version_added = 'v0.0.3' - regex = re.compile(r"^\s+- ((dir_)|(file_))?mode: [0-9]{3,4}") + regex = re.compile( + r"""^\s+ + -\ # whitespace escaped due to re.VERBOSE + (?:dir_|file_)?mode # file_mode, dir_mode or mode + :\ # whitespace escaped duo to re.VERBOSE + (?: + (\d{3,4}) # mode without quotation + | + (['"]\d{3,4} # mode prefixed with quotation + (?: + $ # end of line + | # or + [^\d'"] # ending quotation missing + ) + ) + ) + """, + re.VERBOSE + ) def match(self, file, line): return self.regex.search(line) diff --git a/tests/unit/TestFileModeQuotationRule.py b/tests/unit/TestFileModeQuotationRule.py index b2d2088..698fa5e 100644 --- a/tests/unit/TestFileModeQuotationRule.py +++ b/tests/unit/TestFileModeQuotationRule.py @@ -30,6 +30,18 @@ - dir_mode: 0775 ''' +MODE_MISSING_QUOTATION_LINE = ''' +testfile: + file.managed: + - name: /tmp/badfile + - user: root + - group: root + - mode: "0700 + - file_mode: '0660 + - dir_mode: 0775" +''' + + class TestModeQuotationRule(unittest.TestCase): collection = RulesCollection() @@ -44,3 +56,7 @@ def test_statement_positive(self): def test_statement_negative(self): results = self.runner.run_state(BAD_MODE_QUOTATION_LINE) self.assertEqual(3, len(results)) + + def test_missing_quotes(self): + results = self.runner.run_state(MODE_MISSING_QUOTATION_LINE) + self.assertEqual(3, len(results))