'''Check that parameters without key as title breaks validation.'''
withpytest.raises(RuleValidationError,match=fr'^Rule {rule.id} should have a parameter name declared with `.name` before the bock, for each parameter'):
'''Check that forgetting the language for sources breaks validation'''
rule=invalid_rule('S100','cfamily')
withpytest.raises(RuleValidationError,match=re.escape(f'Rule {rule.id} has non highlighted code example in section "Noncompliant Code Example".\nUse [source,cpp] or [source,text] before the opening \'----\'.')):
'''Check that forgetting the language for sources breaks validation in case of multiple blocks too'''
rule=invalid_rule('S100','java')
withpytest.raises(RuleValidationError,match=re.escape(f'Rule {rule.id} has non highlighted code example in section "Noncompliant Code Example".\nUse [source,java] or [source,text] before the opening \'----\'.')):
'''Check that forgetting the language for sources breaks validation'''
rule=invalid_rule('S100','csharp')
withpytest.raises(RuleValidationError,match=re.escape(f'Rule {rule.id} has unknown language "unknown" in code example in section "Noncompliant Code Example".\nAre you looking for "csharp"?')):
'''Check that having "How to fix it" subsections using framework names that are not inside the "allowed_framework_names.adoc" file breaks validation'''
rule=invalid_rule('S101','csharp')
withpytest.raises(RuleValidationError,match=f'Rule csharp:S101 has a "How to fix it" section for an unsupported framework: "Foo Bar Framework"'):
withpytest.raises(RuleValidationError,match=f'Rule javascript:S101 has more than 6 "How to fix it" sections. Please ensure this limit can be increased with PM/UX teams'):
'''Check that mixing "How to fix it" and "How to fix it in FRAMEWORK" sections breaks validation'''
rule=invalid_rule('S200','abap')
withpytest.raises(RuleValidationError,match=f'Rule abap:S200 is mixing "How to fix it" with "How to fix it in FRAMEWORK NAME" sections. Either use a single "How to fix it" or one or more "How to fix it in FRAMEWORK"'):
'''Check that "How to fix it" sections with a weird format breaks validation'''
rule=invalid_rule('S200','typescript')
withpytest.raises(RuleValidationError,match=f'Rule typescript:S200 has a "How to fix it" section with an unsupported format: "How to fix it wrong format". Either use "How to fix it" or "How to fix it in FRAMEWORK NAME"'):
'''Check that the security standards links match what is define in th rule metadata'''
rule=rule_language('S200','docker')
withpytest.raises(RuleValidationError,match=re.escape('Rule docker:S200 has a mismatch for the OWASP security standards. Add links to the Resources/See section ([\'A10\']) or fix the rule metadata')):
'''Check that the security standards links match what is define in th rule metadata'''
rule=rule_language('S200','terraform')
withpytest.raises(RuleValidationError,match=re.escape('Rule terraform:S200 has a mismatch for the OWASP security standards. Remove links from the Resources/See section ([\'A10\']) or fix the rule metadata')):