Fixed more style changes and improved logic

This commit is contained in:
Joshua Arquilevich
2020-03-12 14:06:13 -07:00
parent 7b34f04be1
commit be72ec153d

View File

@ -340,14 +340,9 @@ public class ApexCRUDViolationRule extends AbstractApexRule {
} }
private boolean isWithSecurityEnforced(final AbstractApexNode<?> node) { private boolean isWithSecurityEnforced(final AbstractApexNode<?> node) {
// if (node instanceof ASTSoqlExpression) {
// String pattern = "(?i).*[^']\\s*WITH SECURITY_ENFORCED\\s*[^']*";
// String query = ((ASTSoqlExpression) node).getQuery();
// return query.matches(pattern);
// }
// return false;
if (node instanceof ASTSoqlExpression) { if (node instanceof ASTSoqlExpression) {
return WITH_SECURITY_ENFORCED.matcher(((ASTSoqlExpression) node).getQuery()).matches(); boolean temp = WITH_SECURITY_ENFORCED.matcher(((ASTSoqlExpression) node).getQuery()).matches();
return temp;//WITH_SECURITY_ENFORCED.matcher(((ASTSoqlExpression) node).getQuery()).matches();
} }
return false; return false;
} }
@ -517,14 +512,17 @@ public class ApexCRUDViolationRule extends AbstractApexRule {
} }
private void validateCRUDCheckPresent(final AbstractApexNode<?> node, final Object data, final String crudMethod, private void validateCRUDCheckPresent(final AbstractApexNode<?> node, final Object data, final String crudMethod,
final String typeCheck) { final String typeCheck) {
if (!typeToDMLOperationMapping.containsKey(typeCheck)) { boolean missingKey = !typeToDMLOperationMapping.containsKey(typeCheck);
if (!isProperESAPICheckForDML(typeCheck, crudMethod)) { boolean isImproperDMLCheck = !isProperESAPICheckForDML(typeCheck, crudMethod);
if (!isWithSecurityEnforced(node)) { boolean noSecurityEnforced = !isWithSecurityEnforced(node);
if (missingKey) {
//if condition returns true, add violation, otherwise return.
if (isImproperDMLCheck && noSecurityEnforced) {
addViolation(data, node); addViolation(data, node);
} }
}
} else { } else {
boolean properChecksHappened = false; boolean properChecksHappened = false;