@Test public void testIsValidSecurityZoneForDeleteWithWrongIdReturnFalse() throws Exception{ RangerSecurityZone suppliedSecurityZone = getRangerSecurityZone(); Mockito.when(_store.getSecurityZone(suppliedSecurityZone.getId())).thenReturn(null); List<ValidationFailureDetails> failures = new ArrayList<ValidationFailureDetails>(); boolean isValid = rangerSecurityZoneValidator.isValid(suppliedSecurityZone.getId(), RangerValidator.Action.DELETE, failures); Assert.assertFalse(isValid); }
@Override boolean isValid(String name, Action action, List<ValidationFailureDetails> failures) { if (LOG.isDebugEnabled()) { LOG.debug(String.format("==> RangerPolicyValidator.isValid(%s, %s, %s)", name, action, failures)); } boolean ret = true; if (action != Action.DELETE) { ValidationErrorCode error = ValidationErrorCode.SECURITY_ZONE_VALIDATION_ERR_UNSUPPORTED_ACTION; failures.add(new ValidationFailureDetailsBuilder().isAnInternalError().becauseOf(error.getMessage()).errorCode(error.getErrorCode()).build()); ret = false; } else { if (StringUtils.isEmpty(name)) { ValidationErrorCode error = ValidationErrorCode.SECURITY_ZONE_VALIDATION_ERR_MISSING_FIELD; failures.add(new ValidationFailureDetailsBuilder().becauseOf("security zone name was null/missing").field("name").isMissing().errorCode(error.getErrorCode()).becauseOf(error.getMessage("name")).build()); ret = false; } else { if (getSecurityZone(name) == null) { ValidationErrorCode error = ValidationErrorCode.SECURITY_ZONE_VALIDATION_ERR_INVALID_ZONE_ID; failures.add(new ValidationFailureDetailsBuilder().becauseOf("security zone does not exist").field("name").errorCode(error.getErrorCode()).becauseOf(error.getMessage(name)).build()); ret = false; } } } if (LOG.isDebugEnabled()) { LOG.debug(String.format("<== RangerPolicyValidator.isValid(%s, %s, %s) : %s", name, action, failures, ret)); } return ret; }
RangerSecurityZoneValidator extends RangerValidator { @Override boolean isValid(String name, Action action, List<ValidationFailureDetails> failures) { if (LOG.isDebugEnabled()) { LOG.debug(String.format("==> RangerPolicyValidator.isValid(%s, %s, %s)", name, action, failures)); } boolean ret = true; if (action != Action.DELETE) { ValidationErrorCode error = ValidationErrorCode.SECURITY_ZONE_VALIDATION_ERR_UNSUPPORTED_ACTION; failures.add(new ValidationFailureDetailsBuilder().isAnInternalError().becauseOf(error.getMessage()).errorCode(error.getErrorCode()).build()); ret = false; } else { if (StringUtils.isEmpty(name)) { ValidationErrorCode error = ValidationErrorCode.SECURITY_ZONE_VALIDATION_ERR_MISSING_FIELD; failures.add(new ValidationFailureDetailsBuilder().becauseOf("security zone name was null/missing").field("name").isMissing().errorCode(error.getErrorCode()).becauseOf(error.getMessage("name")).build()); ret = false; } else { if (getSecurityZone(name) == null) { ValidationErrorCode error = ValidationErrorCode.SECURITY_ZONE_VALIDATION_ERR_INVALID_ZONE_ID; failures.add(new ValidationFailureDetailsBuilder().becauseOf("security zone does not exist").field("name").errorCode(error.getErrorCode()).becauseOf(error.getMessage(name)).build()); ret = false; } } } if (LOG.isDebugEnabled()) { LOG.debug(String.format("<== RangerPolicyValidator.isValid(%s, %s, %s) : %s", name, action, failures, ret)); } return ret; } }
RangerSecurityZoneValidator extends RangerValidator { @Override boolean isValid(String name, Action action, List<ValidationFailureDetails> failures) { if (LOG.isDebugEnabled()) { LOG.debug(String.format("==> RangerPolicyValidator.isValid(%s, %s, %s)", name, action, failures)); } boolean ret = true; if (action != Action.DELETE) { ValidationErrorCode error = ValidationErrorCode.SECURITY_ZONE_VALIDATION_ERR_UNSUPPORTED_ACTION; failures.add(new ValidationFailureDetailsBuilder().isAnInternalError().becauseOf(error.getMessage()).errorCode(error.getErrorCode()).build()); ret = false; } else { if (StringUtils.isEmpty(name)) { ValidationErrorCode error = ValidationErrorCode.SECURITY_ZONE_VALIDATION_ERR_MISSING_FIELD; failures.add(new ValidationFailureDetailsBuilder().becauseOf("security zone name was null/missing").field("name").isMissing().errorCode(error.getErrorCode()).becauseOf(error.getMessage("name")).build()); ret = false; } else { if (getSecurityZone(name) == null) { ValidationErrorCode error = ValidationErrorCode.SECURITY_ZONE_VALIDATION_ERR_INVALID_ZONE_ID; failures.add(new ValidationFailureDetailsBuilder().becauseOf("security zone does not exist").field("name").errorCode(error.getErrorCode()).becauseOf(error.getMessage(name)).build()); ret = false; } } } if (LOG.isDebugEnabled()) { LOG.debug(String.format("<== RangerPolicyValidator.isValid(%s, %s, %s) : %s", name, action, failures, ret)); } return ret; } RangerSecurityZoneValidator(ServiceStore store, SecurityZoneStore securityZoneStore); }
RangerSecurityZoneValidator extends RangerValidator { @Override boolean isValid(String name, Action action, List<ValidationFailureDetails> failures) { if (LOG.isDebugEnabled()) { LOG.debug(String.format("==> RangerPolicyValidator.isValid(%s, %s, %s)", name, action, failures)); } boolean ret = true; if (action != Action.DELETE) { ValidationErrorCode error = ValidationErrorCode.SECURITY_ZONE_VALIDATION_ERR_UNSUPPORTED_ACTION; failures.add(new ValidationFailureDetailsBuilder().isAnInternalError().becauseOf(error.getMessage()).errorCode(error.getErrorCode()).build()); ret = false; } else { if (StringUtils.isEmpty(name)) { ValidationErrorCode error = ValidationErrorCode.SECURITY_ZONE_VALIDATION_ERR_MISSING_FIELD; failures.add(new ValidationFailureDetailsBuilder().becauseOf("security zone name was null/missing").field("name").isMissing().errorCode(error.getErrorCode()).becauseOf(error.getMessage("name")).build()); ret = false; } else { if (getSecurityZone(name) == null) { ValidationErrorCode error = ValidationErrorCode.SECURITY_ZONE_VALIDATION_ERR_INVALID_ZONE_ID; failures.add(new ValidationFailureDetailsBuilder().becauseOf("security zone does not exist").field("name").errorCode(error.getErrorCode()).becauseOf(error.getMessage(name)).build()); ret = false; } } } if (LOG.isDebugEnabled()) { LOG.debug(String.format("<== RangerPolicyValidator.isValid(%s, %s, %s) : %s", name, action, failures, ret)); } return ret; } RangerSecurityZoneValidator(ServiceStore store, SecurityZoneStore securityZoneStore); void validate(RangerSecurityZone securityZone, Action action); }
RangerSecurityZoneValidator extends RangerValidator { @Override boolean isValid(String name, Action action, List<ValidationFailureDetails> failures) { if (LOG.isDebugEnabled()) { LOG.debug(String.format("==> RangerPolicyValidator.isValid(%s, %s, %s)", name, action, failures)); } boolean ret = true; if (action != Action.DELETE) { ValidationErrorCode error = ValidationErrorCode.SECURITY_ZONE_VALIDATION_ERR_UNSUPPORTED_ACTION; failures.add(new ValidationFailureDetailsBuilder().isAnInternalError().becauseOf(error.getMessage()).errorCode(error.getErrorCode()).build()); ret = false; } else { if (StringUtils.isEmpty(name)) { ValidationErrorCode error = ValidationErrorCode.SECURITY_ZONE_VALIDATION_ERR_MISSING_FIELD; failures.add(new ValidationFailureDetailsBuilder().becauseOf("security zone name was null/missing").field("name").isMissing().errorCode(error.getErrorCode()).becauseOf(error.getMessage("name")).build()); ret = false; } else { if (getSecurityZone(name) == null) { ValidationErrorCode error = ValidationErrorCode.SECURITY_ZONE_VALIDATION_ERR_INVALID_ZONE_ID; failures.add(new ValidationFailureDetailsBuilder().becauseOf("security zone does not exist").field("name").errorCode(error.getErrorCode()).becauseOf(error.getMessage(name)).build()); ret = false; } } } if (LOG.isDebugEnabled()) { LOG.debug(String.format("<== RangerPolicyValidator.isValid(%s, %s, %s) : %s", name, action, failures, ret)); } return ret; } RangerSecurityZoneValidator(ServiceStore store, SecurityZoneStore securityZoneStore); void validate(RangerSecurityZone securityZone, Action action);  }