target
stringlengths 20
113k
| src_fm
stringlengths 11
86.3k
| src_fm_fc
stringlengths 21
86.4k
| src_fm_fc_co
stringlengths 30
86.4k
| src_fm_fc_ms
stringlengths 42
86.8k
| src_fm_fc_ms_ff
stringlengths 43
86.8k
|
---|---|---|---|---|---|
@Test public void transform_route6_no_change() { final RpslObject rpslObject = RpslObject.parse("" + "route6: 2001:1578:200::/40\n" + "origin: AS12321"); final RpslObject result = attributeSanitizer.sanitize(rpslObject, objectMessages); assertThat(result.getValueForAttribute(AttributeType.ROUTE6).toString(), is("2001:1578:200::/40")); verifyZeroInteractions(objectMessages); } | public RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages) { final Map<RpslAttribute, RpslAttribute> replacements = Maps.newHashMap(); for (final RpslAttribute attribute : object.getAttributes()) { final AttributeType type = attribute.getType(); String newValue = null; final Sanitizer sanitizer = SANITIZER_MAP.get(type); if (sanitizer == null) { continue; } try { newValue = sanitizer.sanitize(attribute); } catch (IllegalArgumentException ignored) { LOGGER.debug("{}: {}", ignored.getClass().getName(), ignored.getMessage()); } if (newValue == null) { continue; } final List<Message> attributeMessages = Lists.newArrayList(); if (!sanitizer.silent() && !attribute.getCleanValue().toString().equals(newValue)) { attributeMessages.add(ValidationMessages.attributeValueConverted(attribute.getCleanValue(), newValue)); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('\n') != -1) { attributeMessages.add(ValidationMessages.continuationLinesRemoved()); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('#') != -1) { attributeMessages.add(ValidationMessages.remarksReformatted()); } final String replacement = newValue + getCommentReplacement(attribute); final RpslAttribute transformed = new RpslAttribute(attribute.getKey(), replacement); replacements.put(attribute, transformed); for (final Message attributeMessage : attributeMessages) { objectMessages.addMessage(transformed, attributeMessage); } } return new RpslObjectBuilder(object).replaceAttributes(replacements).get(); } | AttributeSanitizer { public RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages) { final Map<RpslAttribute, RpslAttribute> replacements = Maps.newHashMap(); for (final RpslAttribute attribute : object.getAttributes()) { final AttributeType type = attribute.getType(); String newValue = null; final Sanitizer sanitizer = SANITIZER_MAP.get(type); if (sanitizer == null) { continue; } try { newValue = sanitizer.sanitize(attribute); } catch (IllegalArgumentException ignored) { LOGGER.debug("{}: {}", ignored.getClass().getName(), ignored.getMessage()); } if (newValue == null) { continue; } final List<Message> attributeMessages = Lists.newArrayList(); if (!sanitizer.silent() && !attribute.getCleanValue().toString().equals(newValue)) { attributeMessages.add(ValidationMessages.attributeValueConverted(attribute.getCleanValue(), newValue)); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('\n') != -1) { attributeMessages.add(ValidationMessages.continuationLinesRemoved()); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('#') != -1) { attributeMessages.add(ValidationMessages.remarksReformatted()); } final String replacement = newValue + getCommentReplacement(attribute); final RpslAttribute transformed = new RpslAttribute(attribute.getKey(), replacement); replacements.put(attribute, transformed); for (final Message attributeMessage : attributeMessages) { objectMessages.addMessage(transformed, attributeMessage); } } return new RpslObjectBuilder(object).replaceAttributes(replacements).get(); } } | AttributeSanitizer { public RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages) { final Map<RpslAttribute, RpslAttribute> replacements = Maps.newHashMap(); for (final RpslAttribute attribute : object.getAttributes()) { final AttributeType type = attribute.getType(); String newValue = null; final Sanitizer sanitizer = SANITIZER_MAP.get(type); if (sanitizer == null) { continue; } try { newValue = sanitizer.sanitize(attribute); } catch (IllegalArgumentException ignored) { LOGGER.debug("{}: {}", ignored.getClass().getName(), ignored.getMessage()); } if (newValue == null) { continue; } final List<Message> attributeMessages = Lists.newArrayList(); if (!sanitizer.silent() && !attribute.getCleanValue().toString().equals(newValue)) { attributeMessages.add(ValidationMessages.attributeValueConverted(attribute.getCleanValue(), newValue)); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('\n') != -1) { attributeMessages.add(ValidationMessages.continuationLinesRemoved()); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('#') != -1) { attributeMessages.add(ValidationMessages.remarksReformatted()); } final String replacement = newValue + getCommentReplacement(attribute); final RpslAttribute transformed = new RpslAttribute(attribute.getKey(), replacement); replacements.put(attribute, transformed); for (final Message attributeMessage : attributeMessages) { objectMessages.addMessage(transformed, attributeMessage); } } return new RpslObjectBuilder(object).replaceAttributes(replacements).get(); } @Autowired AttributeSanitizer(DateTimeProvider dateTimeProvider); } | AttributeSanitizer { public RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages) { final Map<RpslAttribute, RpslAttribute> replacements = Maps.newHashMap(); for (final RpslAttribute attribute : object.getAttributes()) { final AttributeType type = attribute.getType(); String newValue = null; final Sanitizer sanitizer = SANITIZER_MAP.get(type); if (sanitizer == null) { continue; } try { newValue = sanitizer.sanitize(attribute); } catch (IllegalArgumentException ignored) { LOGGER.debug("{}: {}", ignored.getClass().getName(), ignored.getMessage()); } if (newValue == null) { continue; } final List<Message> attributeMessages = Lists.newArrayList(); if (!sanitizer.silent() && !attribute.getCleanValue().toString().equals(newValue)) { attributeMessages.add(ValidationMessages.attributeValueConverted(attribute.getCleanValue(), newValue)); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('\n') != -1) { attributeMessages.add(ValidationMessages.continuationLinesRemoved()); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('#') != -1) { attributeMessages.add(ValidationMessages.remarksReformatted()); } final String replacement = newValue + getCommentReplacement(attribute); final RpslAttribute transformed = new RpslAttribute(attribute.getKey(), replacement); replacements.put(attribute, transformed); for (final Message attributeMessage : attributeMessages) { objectMessages.addMessage(transformed, attributeMessage); } } return new RpslObjectBuilder(object).replaceAttributes(replacements).get(); } @Autowired AttributeSanitizer(DateTimeProvider dateTimeProvider); CIString sanitizeKey(final RpslObject originalObject); RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages); } | AttributeSanitizer { public RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages) { final Map<RpslAttribute, RpslAttribute> replacements = Maps.newHashMap(); for (final RpslAttribute attribute : object.getAttributes()) { final AttributeType type = attribute.getType(); String newValue = null; final Sanitizer sanitizer = SANITIZER_MAP.get(type); if (sanitizer == null) { continue; } try { newValue = sanitizer.sanitize(attribute); } catch (IllegalArgumentException ignored) { LOGGER.debug("{}: {}", ignored.getClass().getName(), ignored.getMessage()); } if (newValue == null) { continue; } final List<Message> attributeMessages = Lists.newArrayList(); if (!sanitizer.silent() && !attribute.getCleanValue().toString().equals(newValue)) { attributeMessages.add(ValidationMessages.attributeValueConverted(attribute.getCleanValue(), newValue)); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('\n') != -1) { attributeMessages.add(ValidationMessages.continuationLinesRemoved()); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('#') != -1) { attributeMessages.add(ValidationMessages.remarksReformatted()); } final String replacement = newValue + getCommentReplacement(attribute); final RpslAttribute transformed = new RpslAttribute(attribute.getKey(), replacement); replacements.put(attribute, transformed); for (final Message attributeMessage : attributeMessages) { objectMessages.addMessage(transformed, attributeMessage); } } return new RpslObjectBuilder(object).replaceAttributes(replacements).get(); } @Autowired AttributeSanitizer(DateTimeProvider dateTimeProvider); CIString sanitizeKey(final RpslObject originalObject); RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages); } |
@Test public void modify_org_reference_missing() { when(update.getAction()).thenReturn(Action.MODIFY); when(update.getType()).thenReturn(ObjectType.INETNUM); when(update.getUpdatedObject()).thenReturn(RpslObject.parse("inetnum: 192.0/24\nstatus: ALLOCATED PA")); subject.validate(update, updateContext); verify(updateContext).addMessage(update, UpdateMessages.orgAttributeMissing()); } | @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final InetStatus inetStatus = getStatus(update); final List<RpslAttribute> updatedOrgAttributes = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (inetStatus.needsOrgReference() && updatedOrgAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.orgAttributeMissing()); return; } if (updatedOrgAttributes.isEmpty()) { return; } final RpslAttribute org = updatedOrgAttributes.get(0); final RpslObject referencedOrganisation = findOrgReference(org); if (referencedOrganisation == null) { updateContext.addMessage(update, UpdateMessages.referenceNotFound(org.getCleanValue())); return; } final CIString cleanOrgTypeValue = referencedOrganisation.findAttribute(AttributeType.ORG_TYPE).getCleanValue(); final OrgType orgType = OrgType.getFor(cleanOrgTypeValue); if (orgType == null || !inetStatus.isValidOrgType(orgType)) { updateContext.addMessage(update, UpdateMessages.wrongOrgType(inetStatus.getAllowedOrgTypes())); } } | ReferenceCheck implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final InetStatus inetStatus = getStatus(update); final List<RpslAttribute> updatedOrgAttributes = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (inetStatus.needsOrgReference() && updatedOrgAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.orgAttributeMissing()); return; } if (updatedOrgAttributes.isEmpty()) { return; } final RpslAttribute org = updatedOrgAttributes.get(0); final RpslObject referencedOrganisation = findOrgReference(org); if (referencedOrganisation == null) { updateContext.addMessage(update, UpdateMessages.referenceNotFound(org.getCleanValue())); return; } final CIString cleanOrgTypeValue = referencedOrganisation.findAttribute(AttributeType.ORG_TYPE).getCleanValue(); final OrgType orgType = OrgType.getFor(cleanOrgTypeValue); if (orgType == null || !inetStatus.isValidOrgType(orgType)) { updateContext.addMessage(update, UpdateMessages.wrongOrgType(inetStatus.getAllowedOrgTypes())); } } } | ReferenceCheck implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final InetStatus inetStatus = getStatus(update); final List<RpslAttribute> updatedOrgAttributes = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (inetStatus.needsOrgReference() && updatedOrgAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.orgAttributeMissing()); return; } if (updatedOrgAttributes.isEmpty()) { return; } final RpslAttribute org = updatedOrgAttributes.get(0); final RpslObject referencedOrganisation = findOrgReference(org); if (referencedOrganisation == null) { updateContext.addMessage(update, UpdateMessages.referenceNotFound(org.getCleanValue())); return; } final CIString cleanOrgTypeValue = referencedOrganisation.findAttribute(AttributeType.ORG_TYPE).getCleanValue(); final OrgType orgType = OrgType.getFor(cleanOrgTypeValue); if (orgType == null || !inetStatus.isValidOrgType(orgType)) { updateContext.addMessage(update, UpdateMessages.wrongOrgType(inetStatus.getAllowedOrgTypes())); } } @Autowired ReferenceCheck(final RpslObjectUpdateDao rpslObjectUpdateDao, final RpslObjectDao rpslObjectDao); } | ReferenceCheck implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final InetStatus inetStatus = getStatus(update); final List<RpslAttribute> updatedOrgAttributes = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (inetStatus.needsOrgReference() && updatedOrgAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.orgAttributeMissing()); return; } if (updatedOrgAttributes.isEmpty()) { return; } final RpslAttribute org = updatedOrgAttributes.get(0); final RpslObject referencedOrganisation = findOrgReference(org); if (referencedOrganisation == null) { updateContext.addMessage(update, UpdateMessages.referenceNotFound(org.getCleanValue())); return; } final CIString cleanOrgTypeValue = referencedOrganisation.findAttribute(AttributeType.ORG_TYPE).getCleanValue(); final OrgType orgType = OrgType.getFor(cleanOrgTypeValue); if (orgType == null || !inetStatus.isValidOrgType(orgType)) { updateContext.addMessage(update, UpdateMessages.wrongOrgType(inetStatus.getAllowedOrgTypes())); } } @Autowired ReferenceCheck(final RpslObjectUpdateDao rpslObjectUpdateDao, final RpslObjectDao rpslObjectDao); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | ReferenceCheck implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final InetStatus inetStatus = getStatus(update); final List<RpslAttribute> updatedOrgAttributes = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (inetStatus.needsOrgReference() && updatedOrgAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.orgAttributeMissing()); return; } if (updatedOrgAttributes.isEmpty()) { return; } final RpslAttribute org = updatedOrgAttributes.get(0); final RpslObject referencedOrganisation = findOrgReference(org); if (referencedOrganisation == null) { updateContext.addMessage(update, UpdateMessages.referenceNotFound(org.getCleanValue())); return; } final CIString cleanOrgTypeValue = referencedOrganisation.findAttribute(AttributeType.ORG_TYPE).getCleanValue(); final OrgType orgType = OrgType.getFor(cleanOrgTypeValue); if (orgType == null || !inetStatus.isValidOrgType(orgType)) { updateContext.addMessage(update, UpdateMessages.wrongOrgType(inetStatus.getAllowedOrgTypes())); } } @Autowired ReferenceCheck(final RpslObjectUpdateDao rpslObjectUpdateDao, final RpslObjectDao rpslObjectDao); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void modify_org_reference_missing_override() { when(updateSubject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)).thenReturn(true); when(update.getAction()).thenReturn(Action.MODIFY); when(update.getType()).thenReturn(ObjectType.INETNUM); when(update.getUpdatedObject()).thenReturn(RpslObject.parse("inetnum: 192.0/24\nstatus: ALLOCATED PA")); subject.validate(update, updateContext); verify(updateContext).getSubject(any(UpdateContainer.class)); verifyNoMoreInteractions(updateContext); } | @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final InetStatus inetStatus = getStatus(update); final List<RpslAttribute> updatedOrgAttributes = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (inetStatus.needsOrgReference() && updatedOrgAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.orgAttributeMissing()); return; } if (updatedOrgAttributes.isEmpty()) { return; } final RpslAttribute org = updatedOrgAttributes.get(0); final RpslObject referencedOrganisation = findOrgReference(org); if (referencedOrganisation == null) { updateContext.addMessage(update, UpdateMessages.referenceNotFound(org.getCleanValue())); return; } final CIString cleanOrgTypeValue = referencedOrganisation.findAttribute(AttributeType.ORG_TYPE).getCleanValue(); final OrgType orgType = OrgType.getFor(cleanOrgTypeValue); if (orgType == null || !inetStatus.isValidOrgType(orgType)) { updateContext.addMessage(update, UpdateMessages.wrongOrgType(inetStatus.getAllowedOrgTypes())); } } | ReferenceCheck implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final InetStatus inetStatus = getStatus(update); final List<RpslAttribute> updatedOrgAttributes = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (inetStatus.needsOrgReference() && updatedOrgAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.orgAttributeMissing()); return; } if (updatedOrgAttributes.isEmpty()) { return; } final RpslAttribute org = updatedOrgAttributes.get(0); final RpslObject referencedOrganisation = findOrgReference(org); if (referencedOrganisation == null) { updateContext.addMessage(update, UpdateMessages.referenceNotFound(org.getCleanValue())); return; } final CIString cleanOrgTypeValue = referencedOrganisation.findAttribute(AttributeType.ORG_TYPE).getCleanValue(); final OrgType orgType = OrgType.getFor(cleanOrgTypeValue); if (orgType == null || !inetStatus.isValidOrgType(orgType)) { updateContext.addMessage(update, UpdateMessages.wrongOrgType(inetStatus.getAllowedOrgTypes())); } } } | ReferenceCheck implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final InetStatus inetStatus = getStatus(update); final List<RpslAttribute> updatedOrgAttributes = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (inetStatus.needsOrgReference() && updatedOrgAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.orgAttributeMissing()); return; } if (updatedOrgAttributes.isEmpty()) { return; } final RpslAttribute org = updatedOrgAttributes.get(0); final RpslObject referencedOrganisation = findOrgReference(org); if (referencedOrganisation == null) { updateContext.addMessage(update, UpdateMessages.referenceNotFound(org.getCleanValue())); return; } final CIString cleanOrgTypeValue = referencedOrganisation.findAttribute(AttributeType.ORG_TYPE).getCleanValue(); final OrgType orgType = OrgType.getFor(cleanOrgTypeValue); if (orgType == null || !inetStatus.isValidOrgType(orgType)) { updateContext.addMessage(update, UpdateMessages.wrongOrgType(inetStatus.getAllowedOrgTypes())); } } @Autowired ReferenceCheck(final RpslObjectUpdateDao rpslObjectUpdateDao, final RpslObjectDao rpslObjectDao); } | ReferenceCheck implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final InetStatus inetStatus = getStatus(update); final List<RpslAttribute> updatedOrgAttributes = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (inetStatus.needsOrgReference() && updatedOrgAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.orgAttributeMissing()); return; } if (updatedOrgAttributes.isEmpty()) { return; } final RpslAttribute org = updatedOrgAttributes.get(0); final RpslObject referencedOrganisation = findOrgReference(org); if (referencedOrganisation == null) { updateContext.addMessage(update, UpdateMessages.referenceNotFound(org.getCleanValue())); return; } final CIString cleanOrgTypeValue = referencedOrganisation.findAttribute(AttributeType.ORG_TYPE).getCleanValue(); final OrgType orgType = OrgType.getFor(cleanOrgTypeValue); if (orgType == null || !inetStatus.isValidOrgType(orgType)) { updateContext.addMessage(update, UpdateMessages.wrongOrgType(inetStatus.getAllowedOrgTypes())); } } @Autowired ReferenceCheck(final RpslObjectUpdateDao rpslObjectUpdateDao, final RpslObjectDao rpslObjectDao); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | ReferenceCheck implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final InetStatus inetStatus = getStatus(update); final List<RpslAttribute> updatedOrgAttributes = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (inetStatus.needsOrgReference() && updatedOrgAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.orgAttributeMissing()); return; } if (updatedOrgAttributes.isEmpty()) { return; } final RpslAttribute org = updatedOrgAttributes.get(0); final RpslObject referencedOrganisation = findOrgReference(org); if (referencedOrganisation == null) { updateContext.addMessage(update, UpdateMessages.referenceNotFound(org.getCleanValue())); return; } final CIString cleanOrgTypeValue = referencedOrganisation.findAttribute(AttributeType.ORG_TYPE).getCleanValue(); final OrgType orgType = OrgType.getFor(cleanOrgTypeValue); if (orgType == null || !inetStatus.isValidOrgType(orgType)) { updateContext.addMessage(update, UpdateMessages.wrongOrgType(inetStatus.getAllowedOrgTypes())); } } @Autowired ReferenceCheck(final RpslObjectUpdateDao rpslObjectUpdateDao, final RpslObjectDao rpslObjectDao); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void modify_org_reference_not_found_in_db() { when(update.getAction()).thenReturn(Action.MODIFY); when(update.getUpdatedObject()).thenReturn(RpslObject.parse("inetnum: 192.0/24\nstatus: ALLOCATED PA\norg: ORG1")); when(rpslObjectUpdateDao.getAttributeReference(AttributeType.ORG, ciString("ORG1"))).thenReturn(null); subject.validate(update, updateContext); verify(updateContext).addMessage(update, UpdateMessages.referenceNotFound("ORG1")); } | @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final InetStatus inetStatus = getStatus(update); final List<RpslAttribute> updatedOrgAttributes = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (inetStatus.needsOrgReference() && updatedOrgAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.orgAttributeMissing()); return; } if (updatedOrgAttributes.isEmpty()) { return; } final RpslAttribute org = updatedOrgAttributes.get(0); final RpslObject referencedOrganisation = findOrgReference(org); if (referencedOrganisation == null) { updateContext.addMessage(update, UpdateMessages.referenceNotFound(org.getCleanValue())); return; } final CIString cleanOrgTypeValue = referencedOrganisation.findAttribute(AttributeType.ORG_TYPE).getCleanValue(); final OrgType orgType = OrgType.getFor(cleanOrgTypeValue); if (orgType == null || !inetStatus.isValidOrgType(orgType)) { updateContext.addMessage(update, UpdateMessages.wrongOrgType(inetStatus.getAllowedOrgTypes())); } } | ReferenceCheck implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final InetStatus inetStatus = getStatus(update); final List<RpslAttribute> updatedOrgAttributes = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (inetStatus.needsOrgReference() && updatedOrgAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.orgAttributeMissing()); return; } if (updatedOrgAttributes.isEmpty()) { return; } final RpslAttribute org = updatedOrgAttributes.get(0); final RpslObject referencedOrganisation = findOrgReference(org); if (referencedOrganisation == null) { updateContext.addMessage(update, UpdateMessages.referenceNotFound(org.getCleanValue())); return; } final CIString cleanOrgTypeValue = referencedOrganisation.findAttribute(AttributeType.ORG_TYPE).getCleanValue(); final OrgType orgType = OrgType.getFor(cleanOrgTypeValue); if (orgType == null || !inetStatus.isValidOrgType(orgType)) { updateContext.addMessage(update, UpdateMessages.wrongOrgType(inetStatus.getAllowedOrgTypes())); } } } | ReferenceCheck implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final InetStatus inetStatus = getStatus(update); final List<RpslAttribute> updatedOrgAttributes = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (inetStatus.needsOrgReference() && updatedOrgAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.orgAttributeMissing()); return; } if (updatedOrgAttributes.isEmpty()) { return; } final RpslAttribute org = updatedOrgAttributes.get(0); final RpslObject referencedOrganisation = findOrgReference(org); if (referencedOrganisation == null) { updateContext.addMessage(update, UpdateMessages.referenceNotFound(org.getCleanValue())); return; } final CIString cleanOrgTypeValue = referencedOrganisation.findAttribute(AttributeType.ORG_TYPE).getCleanValue(); final OrgType orgType = OrgType.getFor(cleanOrgTypeValue); if (orgType == null || !inetStatus.isValidOrgType(orgType)) { updateContext.addMessage(update, UpdateMessages.wrongOrgType(inetStatus.getAllowedOrgTypes())); } } @Autowired ReferenceCheck(final RpslObjectUpdateDao rpslObjectUpdateDao, final RpslObjectDao rpslObjectDao); } | ReferenceCheck implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final InetStatus inetStatus = getStatus(update); final List<RpslAttribute> updatedOrgAttributes = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (inetStatus.needsOrgReference() && updatedOrgAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.orgAttributeMissing()); return; } if (updatedOrgAttributes.isEmpty()) { return; } final RpslAttribute org = updatedOrgAttributes.get(0); final RpslObject referencedOrganisation = findOrgReference(org); if (referencedOrganisation == null) { updateContext.addMessage(update, UpdateMessages.referenceNotFound(org.getCleanValue())); return; } final CIString cleanOrgTypeValue = referencedOrganisation.findAttribute(AttributeType.ORG_TYPE).getCleanValue(); final OrgType orgType = OrgType.getFor(cleanOrgTypeValue); if (orgType == null || !inetStatus.isValidOrgType(orgType)) { updateContext.addMessage(update, UpdateMessages.wrongOrgType(inetStatus.getAllowedOrgTypes())); } } @Autowired ReferenceCheck(final RpslObjectUpdateDao rpslObjectUpdateDao, final RpslObjectDao rpslObjectDao); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | ReferenceCheck implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final InetStatus inetStatus = getStatus(update); final List<RpslAttribute> updatedOrgAttributes = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (inetStatus.needsOrgReference() && updatedOrgAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.orgAttributeMissing()); return; } if (updatedOrgAttributes.isEmpty()) { return; } final RpslAttribute org = updatedOrgAttributes.get(0); final RpslObject referencedOrganisation = findOrgReference(org); if (referencedOrganisation == null) { updateContext.addMessage(update, UpdateMessages.referenceNotFound(org.getCleanValue())); return; } final CIString cleanOrgTypeValue = referencedOrganisation.findAttribute(AttributeType.ORG_TYPE).getCleanValue(); final OrgType orgType = OrgType.getFor(cleanOrgTypeValue); if (orgType == null || !inetStatus.isValidOrgType(orgType)) { updateContext.addMessage(update, UpdateMessages.wrongOrgType(inetStatus.getAllowedOrgTypes())); } } @Autowired ReferenceCheck(final RpslObjectUpdateDao rpslObjectUpdateDao, final RpslObjectDao rpslObjectDao); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void modify_org_reference_not_found_in_db_override() { when(updateSubject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)).thenReturn(true); when(update.getAction()).thenReturn(Action.MODIFY); when(update.getUpdatedObject()).thenReturn(RpslObject.parse("inetnum: 192.0/24\nstatus: ALLOCATED PA\norg: ORG1")); when(rpslObjectUpdateDao.getAttributeReference(AttributeType.ORG, ciString("ORG1"))).thenReturn(null); subject.validate(update, updateContext); verify(updateContext).getSubject(any(UpdateContainer.class)); verifyNoMoreInteractions(updateContext); } | @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final InetStatus inetStatus = getStatus(update); final List<RpslAttribute> updatedOrgAttributes = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (inetStatus.needsOrgReference() && updatedOrgAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.orgAttributeMissing()); return; } if (updatedOrgAttributes.isEmpty()) { return; } final RpslAttribute org = updatedOrgAttributes.get(0); final RpslObject referencedOrganisation = findOrgReference(org); if (referencedOrganisation == null) { updateContext.addMessage(update, UpdateMessages.referenceNotFound(org.getCleanValue())); return; } final CIString cleanOrgTypeValue = referencedOrganisation.findAttribute(AttributeType.ORG_TYPE).getCleanValue(); final OrgType orgType = OrgType.getFor(cleanOrgTypeValue); if (orgType == null || !inetStatus.isValidOrgType(orgType)) { updateContext.addMessage(update, UpdateMessages.wrongOrgType(inetStatus.getAllowedOrgTypes())); } } | ReferenceCheck implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final InetStatus inetStatus = getStatus(update); final List<RpslAttribute> updatedOrgAttributes = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (inetStatus.needsOrgReference() && updatedOrgAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.orgAttributeMissing()); return; } if (updatedOrgAttributes.isEmpty()) { return; } final RpslAttribute org = updatedOrgAttributes.get(0); final RpslObject referencedOrganisation = findOrgReference(org); if (referencedOrganisation == null) { updateContext.addMessage(update, UpdateMessages.referenceNotFound(org.getCleanValue())); return; } final CIString cleanOrgTypeValue = referencedOrganisation.findAttribute(AttributeType.ORG_TYPE).getCleanValue(); final OrgType orgType = OrgType.getFor(cleanOrgTypeValue); if (orgType == null || !inetStatus.isValidOrgType(orgType)) { updateContext.addMessage(update, UpdateMessages.wrongOrgType(inetStatus.getAllowedOrgTypes())); } } } | ReferenceCheck implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final InetStatus inetStatus = getStatus(update); final List<RpslAttribute> updatedOrgAttributes = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (inetStatus.needsOrgReference() && updatedOrgAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.orgAttributeMissing()); return; } if (updatedOrgAttributes.isEmpty()) { return; } final RpslAttribute org = updatedOrgAttributes.get(0); final RpslObject referencedOrganisation = findOrgReference(org); if (referencedOrganisation == null) { updateContext.addMessage(update, UpdateMessages.referenceNotFound(org.getCleanValue())); return; } final CIString cleanOrgTypeValue = referencedOrganisation.findAttribute(AttributeType.ORG_TYPE).getCleanValue(); final OrgType orgType = OrgType.getFor(cleanOrgTypeValue); if (orgType == null || !inetStatus.isValidOrgType(orgType)) { updateContext.addMessage(update, UpdateMessages.wrongOrgType(inetStatus.getAllowedOrgTypes())); } } @Autowired ReferenceCheck(final RpslObjectUpdateDao rpslObjectUpdateDao, final RpslObjectDao rpslObjectDao); } | ReferenceCheck implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final InetStatus inetStatus = getStatus(update); final List<RpslAttribute> updatedOrgAttributes = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (inetStatus.needsOrgReference() && updatedOrgAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.orgAttributeMissing()); return; } if (updatedOrgAttributes.isEmpty()) { return; } final RpslAttribute org = updatedOrgAttributes.get(0); final RpslObject referencedOrganisation = findOrgReference(org); if (referencedOrganisation == null) { updateContext.addMessage(update, UpdateMessages.referenceNotFound(org.getCleanValue())); return; } final CIString cleanOrgTypeValue = referencedOrganisation.findAttribute(AttributeType.ORG_TYPE).getCleanValue(); final OrgType orgType = OrgType.getFor(cleanOrgTypeValue); if (orgType == null || !inetStatus.isValidOrgType(orgType)) { updateContext.addMessage(update, UpdateMessages.wrongOrgType(inetStatus.getAllowedOrgTypes())); } } @Autowired ReferenceCheck(final RpslObjectUpdateDao rpslObjectUpdateDao, final RpslObjectDao rpslObjectDao); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | ReferenceCheck implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final InetStatus inetStatus = getStatus(update); final List<RpslAttribute> updatedOrgAttributes = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (inetStatus.needsOrgReference() && updatedOrgAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.orgAttributeMissing()); return; } if (updatedOrgAttributes.isEmpty()) { return; } final RpslAttribute org = updatedOrgAttributes.get(0); final RpslObject referencedOrganisation = findOrgReference(org); if (referencedOrganisation == null) { updateContext.addMessage(update, UpdateMessages.referenceNotFound(org.getCleanValue())); return; } final CIString cleanOrgTypeValue = referencedOrganisation.findAttribute(AttributeType.ORG_TYPE).getCleanValue(); final OrgType orgType = OrgType.getFor(cleanOrgTypeValue); if (orgType == null || !inetStatus.isValidOrgType(orgType)) { updateContext.addMessage(update, UpdateMessages.wrongOrgType(inetStatus.getAllowedOrgTypes())); } } @Autowired ReferenceCheck(final RpslObjectUpdateDao rpslObjectUpdateDao, final RpslObjectDao rpslObjectDao); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void modify_wrong_orgtype_on_found_org() { when(update.getAction()).thenReturn(Action.MODIFY); when(update.getUpdatedObject()).thenReturn(RpslObject.parse("inetnum: 192.0/24\nstatus: ALLOCATED PA\norg: ORG1")); when(rpslObjectUpdateDao.getAttributeReference(AttributeType.ORG, ciString("ORG1"))).thenReturn(rpslObjectInfo); when(rpslObjectInfo.getKey()).thenReturn("ORG1"); when(rpslObjectDao.getByKey(ObjectType.ORGANISATION, "ORG1")).thenReturn(RpslObject.parse("organisation: ORG1\norg-type: OTHER")); subject.validate(update, updateContext); verify(updateContext).addMessage(update, UpdateMessages.wrongOrgType(InetnumStatus.ALLOCATED_PA.getAllowedOrgTypes())); } | @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final InetStatus inetStatus = getStatus(update); final List<RpslAttribute> updatedOrgAttributes = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (inetStatus.needsOrgReference() && updatedOrgAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.orgAttributeMissing()); return; } if (updatedOrgAttributes.isEmpty()) { return; } final RpslAttribute org = updatedOrgAttributes.get(0); final RpslObject referencedOrganisation = findOrgReference(org); if (referencedOrganisation == null) { updateContext.addMessage(update, UpdateMessages.referenceNotFound(org.getCleanValue())); return; } final CIString cleanOrgTypeValue = referencedOrganisation.findAttribute(AttributeType.ORG_TYPE).getCleanValue(); final OrgType orgType = OrgType.getFor(cleanOrgTypeValue); if (orgType == null || !inetStatus.isValidOrgType(orgType)) { updateContext.addMessage(update, UpdateMessages.wrongOrgType(inetStatus.getAllowedOrgTypes())); } } | ReferenceCheck implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final InetStatus inetStatus = getStatus(update); final List<RpslAttribute> updatedOrgAttributes = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (inetStatus.needsOrgReference() && updatedOrgAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.orgAttributeMissing()); return; } if (updatedOrgAttributes.isEmpty()) { return; } final RpslAttribute org = updatedOrgAttributes.get(0); final RpslObject referencedOrganisation = findOrgReference(org); if (referencedOrganisation == null) { updateContext.addMessage(update, UpdateMessages.referenceNotFound(org.getCleanValue())); return; } final CIString cleanOrgTypeValue = referencedOrganisation.findAttribute(AttributeType.ORG_TYPE).getCleanValue(); final OrgType orgType = OrgType.getFor(cleanOrgTypeValue); if (orgType == null || !inetStatus.isValidOrgType(orgType)) { updateContext.addMessage(update, UpdateMessages.wrongOrgType(inetStatus.getAllowedOrgTypes())); } } } | ReferenceCheck implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final InetStatus inetStatus = getStatus(update); final List<RpslAttribute> updatedOrgAttributes = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (inetStatus.needsOrgReference() && updatedOrgAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.orgAttributeMissing()); return; } if (updatedOrgAttributes.isEmpty()) { return; } final RpslAttribute org = updatedOrgAttributes.get(0); final RpslObject referencedOrganisation = findOrgReference(org); if (referencedOrganisation == null) { updateContext.addMessage(update, UpdateMessages.referenceNotFound(org.getCleanValue())); return; } final CIString cleanOrgTypeValue = referencedOrganisation.findAttribute(AttributeType.ORG_TYPE).getCleanValue(); final OrgType orgType = OrgType.getFor(cleanOrgTypeValue); if (orgType == null || !inetStatus.isValidOrgType(orgType)) { updateContext.addMessage(update, UpdateMessages.wrongOrgType(inetStatus.getAllowedOrgTypes())); } } @Autowired ReferenceCheck(final RpslObjectUpdateDao rpslObjectUpdateDao, final RpslObjectDao rpslObjectDao); } | ReferenceCheck implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final InetStatus inetStatus = getStatus(update); final List<RpslAttribute> updatedOrgAttributes = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (inetStatus.needsOrgReference() && updatedOrgAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.orgAttributeMissing()); return; } if (updatedOrgAttributes.isEmpty()) { return; } final RpslAttribute org = updatedOrgAttributes.get(0); final RpslObject referencedOrganisation = findOrgReference(org); if (referencedOrganisation == null) { updateContext.addMessage(update, UpdateMessages.referenceNotFound(org.getCleanValue())); return; } final CIString cleanOrgTypeValue = referencedOrganisation.findAttribute(AttributeType.ORG_TYPE).getCleanValue(); final OrgType orgType = OrgType.getFor(cleanOrgTypeValue); if (orgType == null || !inetStatus.isValidOrgType(orgType)) { updateContext.addMessage(update, UpdateMessages.wrongOrgType(inetStatus.getAllowedOrgTypes())); } } @Autowired ReferenceCheck(final RpslObjectUpdateDao rpslObjectUpdateDao, final RpslObjectDao rpslObjectDao); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | ReferenceCheck implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final InetStatus inetStatus = getStatus(update); final List<RpslAttribute> updatedOrgAttributes = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (inetStatus.needsOrgReference() && updatedOrgAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.orgAttributeMissing()); return; } if (updatedOrgAttributes.isEmpty()) { return; } final RpslAttribute org = updatedOrgAttributes.get(0); final RpslObject referencedOrganisation = findOrgReference(org); if (referencedOrganisation == null) { updateContext.addMessage(update, UpdateMessages.referenceNotFound(org.getCleanValue())); return; } final CIString cleanOrgTypeValue = referencedOrganisation.findAttribute(AttributeType.ORG_TYPE).getCleanValue(); final OrgType orgType = OrgType.getFor(cleanOrgTypeValue); if (orgType == null || !inetStatus.isValidOrgType(orgType)) { updateContext.addMessage(update, UpdateMessages.wrongOrgType(inetStatus.getAllowedOrgTypes())); } } @Autowired ReferenceCheck(final RpslObjectUpdateDao rpslObjectUpdateDao, final RpslObjectDao rpslObjectDao); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void modify_wrong_orgtype_on_found_org_override() { when(updateSubject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)).thenReturn(true); when(update.getAction()).thenReturn(Action.MODIFY); when(update.getUpdatedObject()).thenReturn(RpslObject.parse("inetnum: 192.0/24\nstatus: ALLOCATED PA\norg: ORG1")); when(rpslObjectUpdateDao.getAttributeReference(AttributeType.ORG, ciString("ORG1"))).thenReturn(rpslObjectInfo); when(rpslObjectInfo.getKey()).thenReturn("ORG1"); when(rpslObjectDao.getByKey(ObjectType.ORGANISATION, "ORG1")).thenReturn(RpslObject.parse("organisation: ORG1\norg-type: OTHER")); subject.validate(update, updateContext); verify(updateContext).getSubject(any(UpdateContainer.class)); verifyNoMoreInteractions(updateContext); } | @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final InetStatus inetStatus = getStatus(update); final List<RpslAttribute> updatedOrgAttributes = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (inetStatus.needsOrgReference() && updatedOrgAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.orgAttributeMissing()); return; } if (updatedOrgAttributes.isEmpty()) { return; } final RpslAttribute org = updatedOrgAttributes.get(0); final RpslObject referencedOrganisation = findOrgReference(org); if (referencedOrganisation == null) { updateContext.addMessage(update, UpdateMessages.referenceNotFound(org.getCleanValue())); return; } final CIString cleanOrgTypeValue = referencedOrganisation.findAttribute(AttributeType.ORG_TYPE).getCleanValue(); final OrgType orgType = OrgType.getFor(cleanOrgTypeValue); if (orgType == null || !inetStatus.isValidOrgType(orgType)) { updateContext.addMessage(update, UpdateMessages.wrongOrgType(inetStatus.getAllowedOrgTypes())); } } | ReferenceCheck implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final InetStatus inetStatus = getStatus(update); final List<RpslAttribute> updatedOrgAttributes = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (inetStatus.needsOrgReference() && updatedOrgAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.orgAttributeMissing()); return; } if (updatedOrgAttributes.isEmpty()) { return; } final RpslAttribute org = updatedOrgAttributes.get(0); final RpslObject referencedOrganisation = findOrgReference(org); if (referencedOrganisation == null) { updateContext.addMessage(update, UpdateMessages.referenceNotFound(org.getCleanValue())); return; } final CIString cleanOrgTypeValue = referencedOrganisation.findAttribute(AttributeType.ORG_TYPE).getCleanValue(); final OrgType orgType = OrgType.getFor(cleanOrgTypeValue); if (orgType == null || !inetStatus.isValidOrgType(orgType)) { updateContext.addMessage(update, UpdateMessages.wrongOrgType(inetStatus.getAllowedOrgTypes())); } } } | ReferenceCheck implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final InetStatus inetStatus = getStatus(update); final List<RpslAttribute> updatedOrgAttributes = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (inetStatus.needsOrgReference() && updatedOrgAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.orgAttributeMissing()); return; } if (updatedOrgAttributes.isEmpty()) { return; } final RpslAttribute org = updatedOrgAttributes.get(0); final RpslObject referencedOrganisation = findOrgReference(org); if (referencedOrganisation == null) { updateContext.addMessage(update, UpdateMessages.referenceNotFound(org.getCleanValue())); return; } final CIString cleanOrgTypeValue = referencedOrganisation.findAttribute(AttributeType.ORG_TYPE).getCleanValue(); final OrgType orgType = OrgType.getFor(cleanOrgTypeValue); if (orgType == null || !inetStatus.isValidOrgType(orgType)) { updateContext.addMessage(update, UpdateMessages.wrongOrgType(inetStatus.getAllowedOrgTypes())); } } @Autowired ReferenceCheck(final RpslObjectUpdateDao rpslObjectUpdateDao, final RpslObjectDao rpslObjectDao); } | ReferenceCheck implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final InetStatus inetStatus = getStatus(update); final List<RpslAttribute> updatedOrgAttributes = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (inetStatus.needsOrgReference() && updatedOrgAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.orgAttributeMissing()); return; } if (updatedOrgAttributes.isEmpty()) { return; } final RpslAttribute org = updatedOrgAttributes.get(0); final RpslObject referencedOrganisation = findOrgReference(org); if (referencedOrganisation == null) { updateContext.addMessage(update, UpdateMessages.referenceNotFound(org.getCleanValue())); return; } final CIString cleanOrgTypeValue = referencedOrganisation.findAttribute(AttributeType.ORG_TYPE).getCleanValue(); final OrgType orgType = OrgType.getFor(cleanOrgTypeValue); if (orgType == null || !inetStatus.isValidOrgType(orgType)) { updateContext.addMessage(update, UpdateMessages.wrongOrgType(inetStatus.getAllowedOrgTypes())); } } @Autowired ReferenceCheck(final RpslObjectUpdateDao rpslObjectUpdateDao, final RpslObjectDao rpslObjectDao); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | ReferenceCheck implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final InetStatus inetStatus = getStatus(update); final List<RpslAttribute> updatedOrgAttributes = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (inetStatus.needsOrgReference() && updatedOrgAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.orgAttributeMissing()); return; } if (updatedOrgAttributes.isEmpty()) { return; } final RpslAttribute org = updatedOrgAttributes.get(0); final RpslObject referencedOrganisation = findOrgReference(org); if (referencedOrganisation == null) { updateContext.addMessage(update, UpdateMessages.referenceNotFound(org.getCleanValue())); return; } final CIString cleanOrgTypeValue = referencedOrganisation.findAttribute(AttributeType.ORG_TYPE).getCleanValue(); final OrgType orgType = OrgType.getFor(cleanOrgTypeValue); if (orgType == null || !inetStatus.isValidOrgType(orgType)) { updateContext.addMessage(update, UpdateMessages.wrongOrgType(inetStatus.getAllowedOrgTypes())); } } @Autowired ReferenceCheck(final RpslObjectUpdateDao rpslObjectUpdateDao, final RpslObjectDao rpslObjectDao); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void modify_right_orgtype_on_found_org() { when(update.getAction()).thenReturn(Action.MODIFY); when(update.getUpdatedObject()).thenReturn(RpslObject.parse("inetnum: 192.0/24\nstatus: ALLOCATED PA\norg: ORG1")); when(rpslObjectUpdateDao.getAttributeReference(AttributeType.ORG, ciString("ORG1"))).thenReturn(rpslObjectInfo); when(rpslObjectInfo.getKey()).thenReturn("ORG1"); when(rpslObjectDao.getByKey(ObjectType.ORGANISATION, "ORG1")).thenReturn(RpslObject.parse("organisation: ORG1\norg-type: LIR")); subject.validate(update, updateContext); verify(updateContext).getSubject(any(UpdateContainer.class)); verifyNoMoreInteractions(updateContext); } | @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final InetStatus inetStatus = getStatus(update); final List<RpslAttribute> updatedOrgAttributes = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (inetStatus.needsOrgReference() && updatedOrgAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.orgAttributeMissing()); return; } if (updatedOrgAttributes.isEmpty()) { return; } final RpslAttribute org = updatedOrgAttributes.get(0); final RpslObject referencedOrganisation = findOrgReference(org); if (referencedOrganisation == null) { updateContext.addMessage(update, UpdateMessages.referenceNotFound(org.getCleanValue())); return; } final CIString cleanOrgTypeValue = referencedOrganisation.findAttribute(AttributeType.ORG_TYPE).getCleanValue(); final OrgType orgType = OrgType.getFor(cleanOrgTypeValue); if (orgType == null || !inetStatus.isValidOrgType(orgType)) { updateContext.addMessage(update, UpdateMessages.wrongOrgType(inetStatus.getAllowedOrgTypes())); } } | ReferenceCheck implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final InetStatus inetStatus = getStatus(update); final List<RpslAttribute> updatedOrgAttributes = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (inetStatus.needsOrgReference() && updatedOrgAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.orgAttributeMissing()); return; } if (updatedOrgAttributes.isEmpty()) { return; } final RpslAttribute org = updatedOrgAttributes.get(0); final RpslObject referencedOrganisation = findOrgReference(org); if (referencedOrganisation == null) { updateContext.addMessage(update, UpdateMessages.referenceNotFound(org.getCleanValue())); return; } final CIString cleanOrgTypeValue = referencedOrganisation.findAttribute(AttributeType.ORG_TYPE).getCleanValue(); final OrgType orgType = OrgType.getFor(cleanOrgTypeValue); if (orgType == null || !inetStatus.isValidOrgType(orgType)) { updateContext.addMessage(update, UpdateMessages.wrongOrgType(inetStatus.getAllowedOrgTypes())); } } } | ReferenceCheck implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final InetStatus inetStatus = getStatus(update); final List<RpslAttribute> updatedOrgAttributes = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (inetStatus.needsOrgReference() && updatedOrgAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.orgAttributeMissing()); return; } if (updatedOrgAttributes.isEmpty()) { return; } final RpslAttribute org = updatedOrgAttributes.get(0); final RpslObject referencedOrganisation = findOrgReference(org); if (referencedOrganisation == null) { updateContext.addMessage(update, UpdateMessages.referenceNotFound(org.getCleanValue())); return; } final CIString cleanOrgTypeValue = referencedOrganisation.findAttribute(AttributeType.ORG_TYPE).getCleanValue(); final OrgType orgType = OrgType.getFor(cleanOrgTypeValue); if (orgType == null || !inetStatus.isValidOrgType(orgType)) { updateContext.addMessage(update, UpdateMessages.wrongOrgType(inetStatus.getAllowedOrgTypes())); } } @Autowired ReferenceCheck(final RpslObjectUpdateDao rpslObjectUpdateDao, final RpslObjectDao rpslObjectDao); } | ReferenceCheck implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final InetStatus inetStatus = getStatus(update); final List<RpslAttribute> updatedOrgAttributes = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (inetStatus.needsOrgReference() && updatedOrgAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.orgAttributeMissing()); return; } if (updatedOrgAttributes.isEmpty()) { return; } final RpslAttribute org = updatedOrgAttributes.get(0); final RpslObject referencedOrganisation = findOrgReference(org); if (referencedOrganisation == null) { updateContext.addMessage(update, UpdateMessages.referenceNotFound(org.getCleanValue())); return; } final CIString cleanOrgTypeValue = referencedOrganisation.findAttribute(AttributeType.ORG_TYPE).getCleanValue(); final OrgType orgType = OrgType.getFor(cleanOrgTypeValue); if (orgType == null || !inetStatus.isValidOrgType(orgType)) { updateContext.addMessage(update, UpdateMessages.wrongOrgType(inetStatus.getAllowedOrgTypes())); } } @Autowired ReferenceCheck(final RpslObjectUpdateDao rpslObjectUpdateDao, final RpslObjectDao rpslObjectDao); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | ReferenceCheck implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final InetStatus inetStatus = getStatus(update); final List<RpslAttribute> updatedOrgAttributes = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (inetStatus.needsOrgReference() && updatedOrgAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.orgAttributeMissing()); return; } if (updatedOrgAttributes.isEmpty()) { return; } final RpslAttribute org = updatedOrgAttributes.get(0); final RpslObject referencedOrganisation = findOrgReference(org); if (referencedOrganisation == null) { updateContext.addMessage(update, UpdateMessages.referenceNotFound(org.getCleanValue())); return; } final CIString cleanOrgTypeValue = referencedOrganisation.findAttribute(AttributeType.ORG_TYPE).getCleanValue(); final OrgType orgType = OrgType.getFor(cleanOrgTypeValue); if (orgType == null || !inetStatus.isValidOrgType(orgType)) { updateContext.addMessage(update, UpdateMessages.wrongOrgType(inetStatus.getAllowedOrgTypes())); } } @Autowired ReferenceCheck(final RpslObjectUpdateDao rpslObjectUpdateDao, final RpslObjectDao rpslObjectDao); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void create_org_reference_missing() { when(update.getAction()).thenReturn(Action.CREATE); when(update.getUpdatedObject()).thenReturn(RpslObject.parse("inetnum: 192.0/24\nstatus: ALLOCATED PA")); subject.validate(update, updateContext); verify(updateContext).addMessage(update, UpdateMessages.orgAttributeMissing()); } | @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final InetStatus inetStatus = getStatus(update); final List<RpslAttribute> updatedOrgAttributes = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (inetStatus.needsOrgReference() && updatedOrgAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.orgAttributeMissing()); return; } if (updatedOrgAttributes.isEmpty()) { return; } final RpslAttribute org = updatedOrgAttributes.get(0); final RpslObject referencedOrganisation = findOrgReference(org); if (referencedOrganisation == null) { updateContext.addMessage(update, UpdateMessages.referenceNotFound(org.getCleanValue())); return; } final CIString cleanOrgTypeValue = referencedOrganisation.findAttribute(AttributeType.ORG_TYPE).getCleanValue(); final OrgType orgType = OrgType.getFor(cleanOrgTypeValue); if (orgType == null || !inetStatus.isValidOrgType(orgType)) { updateContext.addMessage(update, UpdateMessages.wrongOrgType(inetStatus.getAllowedOrgTypes())); } } | ReferenceCheck implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final InetStatus inetStatus = getStatus(update); final List<RpslAttribute> updatedOrgAttributes = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (inetStatus.needsOrgReference() && updatedOrgAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.orgAttributeMissing()); return; } if (updatedOrgAttributes.isEmpty()) { return; } final RpslAttribute org = updatedOrgAttributes.get(0); final RpslObject referencedOrganisation = findOrgReference(org); if (referencedOrganisation == null) { updateContext.addMessage(update, UpdateMessages.referenceNotFound(org.getCleanValue())); return; } final CIString cleanOrgTypeValue = referencedOrganisation.findAttribute(AttributeType.ORG_TYPE).getCleanValue(); final OrgType orgType = OrgType.getFor(cleanOrgTypeValue); if (orgType == null || !inetStatus.isValidOrgType(orgType)) { updateContext.addMessage(update, UpdateMessages.wrongOrgType(inetStatus.getAllowedOrgTypes())); } } } | ReferenceCheck implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final InetStatus inetStatus = getStatus(update); final List<RpslAttribute> updatedOrgAttributes = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (inetStatus.needsOrgReference() && updatedOrgAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.orgAttributeMissing()); return; } if (updatedOrgAttributes.isEmpty()) { return; } final RpslAttribute org = updatedOrgAttributes.get(0); final RpslObject referencedOrganisation = findOrgReference(org); if (referencedOrganisation == null) { updateContext.addMessage(update, UpdateMessages.referenceNotFound(org.getCleanValue())); return; } final CIString cleanOrgTypeValue = referencedOrganisation.findAttribute(AttributeType.ORG_TYPE).getCleanValue(); final OrgType orgType = OrgType.getFor(cleanOrgTypeValue); if (orgType == null || !inetStatus.isValidOrgType(orgType)) { updateContext.addMessage(update, UpdateMessages.wrongOrgType(inetStatus.getAllowedOrgTypes())); } } @Autowired ReferenceCheck(final RpslObjectUpdateDao rpslObjectUpdateDao, final RpslObjectDao rpslObjectDao); } | ReferenceCheck implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final InetStatus inetStatus = getStatus(update); final List<RpslAttribute> updatedOrgAttributes = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (inetStatus.needsOrgReference() && updatedOrgAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.orgAttributeMissing()); return; } if (updatedOrgAttributes.isEmpty()) { return; } final RpslAttribute org = updatedOrgAttributes.get(0); final RpslObject referencedOrganisation = findOrgReference(org); if (referencedOrganisation == null) { updateContext.addMessage(update, UpdateMessages.referenceNotFound(org.getCleanValue())); return; } final CIString cleanOrgTypeValue = referencedOrganisation.findAttribute(AttributeType.ORG_TYPE).getCleanValue(); final OrgType orgType = OrgType.getFor(cleanOrgTypeValue); if (orgType == null || !inetStatus.isValidOrgType(orgType)) { updateContext.addMessage(update, UpdateMessages.wrongOrgType(inetStatus.getAllowedOrgTypes())); } } @Autowired ReferenceCheck(final RpslObjectUpdateDao rpslObjectUpdateDao, final RpslObjectDao rpslObjectDao); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | ReferenceCheck implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final InetStatus inetStatus = getStatus(update); final List<RpslAttribute> updatedOrgAttributes = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (inetStatus.needsOrgReference() && updatedOrgAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.orgAttributeMissing()); return; } if (updatedOrgAttributes.isEmpty()) { return; } final RpslAttribute org = updatedOrgAttributes.get(0); final RpslObject referencedOrganisation = findOrgReference(org); if (referencedOrganisation == null) { updateContext.addMessage(update, UpdateMessages.referenceNotFound(org.getCleanValue())); return; } final CIString cleanOrgTypeValue = referencedOrganisation.findAttribute(AttributeType.ORG_TYPE).getCleanValue(); final OrgType orgType = OrgType.getFor(cleanOrgTypeValue); if (orgType == null || !inetStatus.isValidOrgType(orgType)) { updateContext.addMessage(update, UpdateMessages.wrongOrgType(inetStatus.getAllowedOrgTypes())); } } @Autowired ReferenceCheck(final RpslObjectUpdateDao rpslObjectUpdateDao, final RpslObjectDao rpslObjectDao); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void create_org_reference_missing_override() { when(updateSubject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)).thenReturn(true); when(update.getAction()).thenReturn(Action.CREATE); when(update.getUpdatedObject()).thenReturn(RpslObject.parse("inetnum: 192.0/24\nstatus: ALLOCATED PA")); subject.validate(update, updateContext); verify(updateContext).getSubject(any(UpdateContainer.class)); verifyNoMoreInteractions(updateContext); } | @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final InetStatus inetStatus = getStatus(update); final List<RpslAttribute> updatedOrgAttributes = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (inetStatus.needsOrgReference() && updatedOrgAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.orgAttributeMissing()); return; } if (updatedOrgAttributes.isEmpty()) { return; } final RpslAttribute org = updatedOrgAttributes.get(0); final RpslObject referencedOrganisation = findOrgReference(org); if (referencedOrganisation == null) { updateContext.addMessage(update, UpdateMessages.referenceNotFound(org.getCleanValue())); return; } final CIString cleanOrgTypeValue = referencedOrganisation.findAttribute(AttributeType.ORG_TYPE).getCleanValue(); final OrgType orgType = OrgType.getFor(cleanOrgTypeValue); if (orgType == null || !inetStatus.isValidOrgType(orgType)) { updateContext.addMessage(update, UpdateMessages.wrongOrgType(inetStatus.getAllowedOrgTypes())); } } | ReferenceCheck implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final InetStatus inetStatus = getStatus(update); final List<RpslAttribute> updatedOrgAttributes = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (inetStatus.needsOrgReference() && updatedOrgAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.orgAttributeMissing()); return; } if (updatedOrgAttributes.isEmpty()) { return; } final RpslAttribute org = updatedOrgAttributes.get(0); final RpslObject referencedOrganisation = findOrgReference(org); if (referencedOrganisation == null) { updateContext.addMessage(update, UpdateMessages.referenceNotFound(org.getCleanValue())); return; } final CIString cleanOrgTypeValue = referencedOrganisation.findAttribute(AttributeType.ORG_TYPE).getCleanValue(); final OrgType orgType = OrgType.getFor(cleanOrgTypeValue); if (orgType == null || !inetStatus.isValidOrgType(orgType)) { updateContext.addMessage(update, UpdateMessages.wrongOrgType(inetStatus.getAllowedOrgTypes())); } } } | ReferenceCheck implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final InetStatus inetStatus = getStatus(update); final List<RpslAttribute> updatedOrgAttributes = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (inetStatus.needsOrgReference() && updatedOrgAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.orgAttributeMissing()); return; } if (updatedOrgAttributes.isEmpty()) { return; } final RpslAttribute org = updatedOrgAttributes.get(0); final RpslObject referencedOrganisation = findOrgReference(org); if (referencedOrganisation == null) { updateContext.addMessage(update, UpdateMessages.referenceNotFound(org.getCleanValue())); return; } final CIString cleanOrgTypeValue = referencedOrganisation.findAttribute(AttributeType.ORG_TYPE).getCleanValue(); final OrgType orgType = OrgType.getFor(cleanOrgTypeValue); if (orgType == null || !inetStatus.isValidOrgType(orgType)) { updateContext.addMessage(update, UpdateMessages.wrongOrgType(inetStatus.getAllowedOrgTypes())); } } @Autowired ReferenceCheck(final RpslObjectUpdateDao rpslObjectUpdateDao, final RpslObjectDao rpslObjectDao); } | ReferenceCheck implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final InetStatus inetStatus = getStatus(update); final List<RpslAttribute> updatedOrgAttributes = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (inetStatus.needsOrgReference() && updatedOrgAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.orgAttributeMissing()); return; } if (updatedOrgAttributes.isEmpty()) { return; } final RpslAttribute org = updatedOrgAttributes.get(0); final RpslObject referencedOrganisation = findOrgReference(org); if (referencedOrganisation == null) { updateContext.addMessage(update, UpdateMessages.referenceNotFound(org.getCleanValue())); return; } final CIString cleanOrgTypeValue = referencedOrganisation.findAttribute(AttributeType.ORG_TYPE).getCleanValue(); final OrgType orgType = OrgType.getFor(cleanOrgTypeValue); if (orgType == null || !inetStatus.isValidOrgType(orgType)) { updateContext.addMessage(update, UpdateMessages.wrongOrgType(inetStatus.getAllowedOrgTypes())); } } @Autowired ReferenceCheck(final RpslObjectUpdateDao rpslObjectUpdateDao, final RpslObjectDao rpslObjectDao); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | ReferenceCheck implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final InetStatus inetStatus = getStatus(update); final List<RpslAttribute> updatedOrgAttributes = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (inetStatus.needsOrgReference() && updatedOrgAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.orgAttributeMissing()); return; } if (updatedOrgAttributes.isEmpty()) { return; } final RpslAttribute org = updatedOrgAttributes.get(0); final RpslObject referencedOrganisation = findOrgReference(org); if (referencedOrganisation == null) { updateContext.addMessage(update, UpdateMessages.referenceNotFound(org.getCleanValue())); return; } final CIString cleanOrgTypeValue = referencedOrganisation.findAttribute(AttributeType.ORG_TYPE).getCleanValue(); final OrgType orgType = OrgType.getFor(cleanOrgTypeValue); if (orgType == null || !inetStatus.isValidOrgType(orgType)) { updateContext.addMessage(update, UpdateMessages.wrongOrgType(inetStatus.getAllowedOrgTypes())); } } @Autowired ReferenceCheck(final RpslObjectUpdateDao rpslObjectUpdateDao, final RpslObjectDao rpslObjectDao); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void create_org_reference_not_found_in_db() { when(update.getAction()).thenReturn(Action.CREATE); when(update.getUpdatedObject()).thenReturn(RpslObject.parse("inetnum: 192.0/24\nstatus: ALLOCATED PA\norg: ORG1")); when(rpslObjectUpdateDao.getAttributeReference(AttributeType.ORG, ciString("ORG1"))).thenReturn(null); subject.validate(update, updateContext); verify(updateContext).addMessage(update, UpdateMessages.referenceNotFound("ORG1")); } | @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final InetStatus inetStatus = getStatus(update); final List<RpslAttribute> updatedOrgAttributes = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (inetStatus.needsOrgReference() && updatedOrgAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.orgAttributeMissing()); return; } if (updatedOrgAttributes.isEmpty()) { return; } final RpslAttribute org = updatedOrgAttributes.get(0); final RpslObject referencedOrganisation = findOrgReference(org); if (referencedOrganisation == null) { updateContext.addMessage(update, UpdateMessages.referenceNotFound(org.getCleanValue())); return; } final CIString cleanOrgTypeValue = referencedOrganisation.findAttribute(AttributeType.ORG_TYPE).getCleanValue(); final OrgType orgType = OrgType.getFor(cleanOrgTypeValue); if (orgType == null || !inetStatus.isValidOrgType(orgType)) { updateContext.addMessage(update, UpdateMessages.wrongOrgType(inetStatus.getAllowedOrgTypes())); } } | ReferenceCheck implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final InetStatus inetStatus = getStatus(update); final List<RpslAttribute> updatedOrgAttributes = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (inetStatus.needsOrgReference() && updatedOrgAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.orgAttributeMissing()); return; } if (updatedOrgAttributes.isEmpty()) { return; } final RpslAttribute org = updatedOrgAttributes.get(0); final RpslObject referencedOrganisation = findOrgReference(org); if (referencedOrganisation == null) { updateContext.addMessage(update, UpdateMessages.referenceNotFound(org.getCleanValue())); return; } final CIString cleanOrgTypeValue = referencedOrganisation.findAttribute(AttributeType.ORG_TYPE).getCleanValue(); final OrgType orgType = OrgType.getFor(cleanOrgTypeValue); if (orgType == null || !inetStatus.isValidOrgType(orgType)) { updateContext.addMessage(update, UpdateMessages.wrongOrgType(inetStatus.getAllowedOrgTypes())); } } } | ReferenceCheck implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final InetStatus inetStatus = getStatus(update); final List<RpslAttribute> updatedOrgAttributes = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (inetStatus.needsOrgReference() && updatedOrgAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.orgAttributeMissing()); return; } if (updatedOrgAttributes.isEmpty()) { return; } final RpslAttribute org = updatedOrgAttributes.get(0); final RpslObject referencedOrganisation = findOrgReference(org); if (referencedOrganisation == null) { updateContext.addMessage(update, UpdateMessages.referenceNotFound(org.getCleanValue())); return; } final CIString cleanOrgTypeValue = referencedOrganisation.findAttribute(AttributeType.ORG_TYPE).getCleanValue(); final OrgType orgType = OrgType.getFor(cleanOrgTypeValue); if (orgType == null || !inetStatus.isValidOrgType(orgType)) { updateContext.addMessage(update, UpdateMessages.wrongOrgType(inetStatus.getAllowedOrgTypes())); } } @Autowired ReferenceCheck(final RpslObjectUpdateDao rpslObjectUpdateDao, final RpslObjectDao rpslObjectDao); } | ReferenceCheck implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final InetStatus inetStatus = getStatus(update); final List<RpslAttribute> updatedOrgAttributes = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (inetStatus.needsOrgReference() && updatedOrgAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.orgAttributeMissing()); return; } if (updatedOrgAttributes.isEmpty()) { return; } final RpslAttribute org = updatedOrgAttributes.get(0); final RpslObject referencedOrganisation = findOrgReference(org); if (referencedOrganisation == null) { updateContext.addMessage(update, UpdateMessages.referenceNotFound(org.getCleanValue())); return; } final CIString cleanOrgTypeValue = referencedOrganisation.findAttribute(AttributeType.ORG_TYPE).getCleanValue(); final OrgType orgType = OrgType.getFor(cleanOrgTypeValue); if (orgType == null || !inetStatus.isValidOrgType(orgType)) { updateContext.addMessage(update, UpdateMessages.wrongOrgType(inetStatus.getAllowedOrgTypes())); } } @Autowired ReferenceCheck(final RpslObjectUpdateDao rpslObjectUpdateDao, final RpslObjectDao rpslObjectDao); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | ReferenceCheck implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final InetStatus inetStatus = getStatus(update); final List<RpslAttribute> updatedOrgAttributes = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (inetStatus.needsOrgReference() && updatedOrgAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.orgAttributeMissing()); return; } if (updatedOrgAttributes.isEmpty()) { return; } final RpslAttribute org = updatedOrgAttributes.get(0); final RpslObject referencedOrganisation = findOrgReference(org); if (referencedOrganisation == null) { updateContext.addMessage(update, UpdateMessages.referenceNotFound(org.getCleanValue())); return; } final CIString cleanOrgTypeValue = referencedOrganisation.findAttribute(AttributeType.ORG_TYPE).getCleanValue(); final OrgType orgType = OrgType.getFor(cleanOrgTypeValue); if (orgType == null || !inetStatus.isValidOrgType(orgType)) { updateContext.addMessage(update, UpdateMessages.wrongOrgType(inetStatus.getAllowedOrgTypes())); } } @Autowired ReferenceCheck(final RpslObjectUpdateDao rpslObjectUpdateDao, final RpslObjectDao rpslObjectDao); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void transform_route6_leading_zeroes() { final RpslObject rpslObject = RpslObject.parse("" + "route6: 2001:1578:0200::/40\n" + "origin: AS12321"); final RpslObject result = attributeSanitizer.sanitize(rpslObject, objectMessages); assertThat(result.getValueForAttribute(AttributeType.ROUTE6).toString(), is("2001:1578:200::/40")); verify(objectMessages).addMessage(result.findAttribute(AttributeType.ROUTE6), ValidationMessages.attributeValueConverted("2001:1578:0200::/40", "2001:1578:200::/40")); verifyNoMoreInteractions(objectMessages); } | public RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages) { final Map<RpslAttribute, RpslAttribute> replacements = Maps.newHashMap(); for (final RpslAttribute attribute : object.getAttributes()) { final AttributeType type = attribute.getType(); String newValue = null; final Sanitizer sanitizer = SANITIZER_MAP.get(type); if (sanitizer == null) { continue; } try { newValue = sanitizer.sanitize(attribute); } catch (IllegalArgumentException ignored) { LOGGER.debug("{}: {}", ignored.getClass().getName(), ignored.getMessage()); } if (newValue == null) { continue; } final List<Message> attributeMessages = Lists.newArrayList(); if (!sanitizer.silent() && !attribute.getCleanValue().toString().equals(newValue)) { attributeMessages.add(ValidationMessages.attributeValueConverted(attribute.getCleanValue(), newValue)); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('\n') != -1) { attributeMessages.add(ValidationMessages.continuationLinesRemoved()); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('#') != -1) { attributeMessages.add(ValidationMessages.remarksReformatted()); } final String replacement = newValue + getCommentReplacement(attribute); final RpslAttribute transformed = new RpslAttribute(attribute.getKey(), replacement); replacements.put(attribute, transformed); for (final Message attributeMessage : attributeMessages) { objectMessages.addMessage(transformed, attributeMessage); } } return new RpslObjectBuilder(object).replaceAttributes(replacements).get(); } | AttributeSanitizer { public RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages) { final Map<RpslAttribute, RpslAttribute> replacements = Maps.newHashMap(); for (final RpslAttribute attribute : object.getAttributes()) { final AttributeType type = attribute.getType(); String newValue = null; final Sanitizer sanitizer = SANITIZER_MAP.get(type); if (sanitizer == null) { continue; } try { newValue = sanitizer.sanitize(attribute); } catch (IllegalArgumentException ignored) { LOGGER.debug("{}: {}", ignored.getClass().getName(), ignored.getMessage()); } if (newValue == null) { continue; } final List<Message> attributeMessages = Lists.newArrayList(); if (!sanitizer.silent() && !attribute.getCleanValue().toString().equals(newValue)) { attributeMessages.add(ValidationMessages.attributeValueConverted(attribute.getCleanValue(), newValue)); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('\n') != -1) { attributeMessages.add(ValidationMessages.continuationLinesRemoved()); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('#') != -1) { attributeMessages.add(ValidationMessages.remarksReformatted()); } final String replacement = newValue + getCommentReplacement(attribute); final RpslAttribute transformed = new RpslAttribute(attribute.getKey(), replacement); replacements.put(attribute, transformed); for (final Message attributeMessage : attributeMessages) { objectMessages.addMessage(transformed, attributeMessage); } } return new RpslObjectBuilder(object).replaceAttributes(replacements).get(); } } | AttributeSanitizer { public RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages) { final Map<RpslAttribute, RpslAttribute> replacements = Maps.newHashMap(); for (final RpslAttribute attribute : object.getAttributes()) { final AttributeType type = attribute.getType(); String newValue = null; final Sanitizer sanitizer = SANITIZER_MAP.get(type); if (sanitizer == null) { continue; } try { newValue = sanitizer.sanitize(attribute); } catch (IllegalArgumentException ignored) { LOGGER.debug("{}: {}", ignored.getClass().getName(), ignored.getMessage()); } if (newValue == null) { continue; } final List<Message> attributeMessages = Lists.newArrayList(); if (!sanitizer.silent() && !attribute.getCleanValue().toString().equals(newValue)) { attributeMessages.add(ValidationMessages.attributeValueConverted(attribute.getCleanValue(), newValue)); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('\n') != -1) { attributeMessages.add(ValidationMessages.continuationLinesRemoved()); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('#') != -1) { attributeMessages.add(ValidationMessages.remarksReformatted()); } final String replacement = newValue + getCommentReplacement(attribute); final RpslAttribute transformed = new RpslAttribute(attribute.getKey(), replacement); replacements.put(attribute, transformed); for (final Message attributeMessage : attributeMessages) { objectMessages.addMessage(transformed, attributeMessage); } } return new RpslObjectBuilder(object).replaceAttributes(replacements).get(); } @Autowired AttributeSanitizer(DateTimeProvider dateTimeProvider); } | AttributeSanitizer { public RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages) { final Map<RpslAttribute, RpslAttribute> replacements = Maps.newHashMap(); for (final RpslAttribute attribute : object.getAttributes()) { final AttributeType type = attribute.getType(); String newValue = null; final Sanitizer sanitizer = SANITIZER_MAP.get(type); if (sanitizer == null) { continue; } try { newValue = sanitizer.sanitize(attribute); } catch (IllegalArgumentException ignored) { LOGGER.debug("{}: {}", ignored.getClass().getName(), ignored.getMessage()); } if (newValue == null) { continue; } final List<Message> attributeMessages = Lists.newArrayList(); if (!sanitizer.silent() && !attribute.getCleanValue().toString().equals(newValue)) { attributeMessages.add(ValidationMessages.attributeValueConverted(attribute.getCleanValue(), newValue)); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('\n') != -1) { attributeMessages.add(ValidationMessages.continuationLinesRemoved()); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('#') != -1) { attributeMessages.add(ValidationMessages.remarksReformatted()); } final String replacement = newValue + getCommentReplacement(attribute); final RpslAttribute transformed = new RpslAttribute(attribute.getKey(), replacement); replacements.put(attribute, transformed); for (final Message attributeMessage : attributeMessages) { objectMessages.addMessage(transformed, attributeMessage); } } return new RpslObjectBuilder(object).replaceAttributes(replacements).get(); } @Autowired AttributeSanitizer(DateTimeProvider dateTimeProvider); CIString sanitizeKey(final RpslObject originalObject); RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages); } | AttributeSanitizer { public RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages) { final Map<RpslAttribute, RpslAttribute> replacements = Maps.newHashMap(); for (final RpslAttribute attribute : object.getAttributes()) { final AttributeType type = attribute.getType(); String newValue = null; final Sanitizer sanitizer = SANITIZER_MAP.get(type); if (sanitizer == null) { continue; } try { newValue = sanitizer.sanitize(attribute); } catch (IllegalArgumentException ignored) { LOGGER.debug("{}: {}", ignored.getClass().getName(), ignored.getMessage()); } if (newValue == null) { continue; } final List<Message> attributeMessages = Lists.newArrayList(); if (!sanitizer.silent() && !attribute.getCleanValue().toString().equals(newValue)) { attributeMessages.add(ValidationMessages.attributeValueConverted(attribute.getCleanValue(), newValue)); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('\n') != -1) { attributeMessages.add(ValidationMessages.continuationLinesRemoved()); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('#') != -1) { attributeMessages.add(ValidationMessages.remarksReformatted()); } final String replacement = newValue + getCommentReplacement(attribute); final RpslAttribute transformed = new RpslAttribute(attribute.getKey(), replacement); replacements.put(attribute, transformed); for (final Message attributeMessage : attributeMessages) { objectMessages.addMessage(transformed, attributeMessage); } } return new RpslObjectBuilder(object).replaceAttributes(replacements).get(); } @Autowired AttributeSanitizer(DateTimeProvider dateTimeProvider); CIString sanitizeKey(final RpslObject originalObject); RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages); } |
@Test public void create_org_reference_not_found_in_db_override() { when(updateSubject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)).thenReturn(true); when(update.getAction()).thenReturn(Action.CREATE); when(update.getUpdatedObject()).thenReturn(RpslObject.parse("inetnum: 192.0/24\nstatus: ALLOCATED PA\norg: ORG1")); when(rpslObjectUpdateDao.getAttributeReference(AttributeType.ORG, ciString("ORG1"))).thenReturn(null); subject.validate(update, updateContext); verify(updateContext).getSubject(any(UpdateContainer.class)); verifyNoMoreInteractions(updateContext); } | @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final InetStatus inetStatus = getStatus(update); final List<RpslAttribute> updatedOrgAttributes = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (inetStatus.needsOrgReference() && updatedOrgAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.orgAttributeMissing()); return; } if (updatedOrgAttributes.isEmpty()) { return; } final RpslAttribute org = updatedOrgAttributes.get(0); final RpslObject referencedOrganisation = findOrgReference(org); if (referencedOrganisation == null) { updateContext.addMessage(update, UpdateMessages.referenceNotFound(org.getCleanValue())); return; } final CIString cleanOrgTypeValue = referencedOrganisation.findAttribute(AttributeType.ORG_TYPE).getCleanValue(); final OrgType orgType = OrgType.getFor(cleanOrgTypeValue); if (orgType == null || !inetStatus.isValidOrgType(orgType)) { updateContext.addMessage(update, UpdateMessages.wrongOrgType(inetStatus.getAllowedOrgTypes())); } } | ReferenceCheck implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final InetStatus inetStatus = getStatus(update); final List<RpslAttribute> updatedOrgAttributes = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (inetStatus.needsOrgReference() && updatedOrgAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.orgAttributeMissing()); return; } if (updatedOrgAttributes.isEmpty()) { return; } final RpslAttribute org = updatedOrgAttributes.get(0); final RpslObject referencedOrganisation = findOrgReference(org); if (referencedOrganisation == null) { updateContext.addMessage(update, UpdateMessages.referenceNotFound(org.getCleanValue())); return; } final CIString cleanOrgTypeValue = referencedOrganisation.findAttribute(AttributeType.ORG_TYPE).getCleanValue(); final OrgType orgType = OrgType.getFor(cleanOrgTypeValue); if (orgType == null || !inetStatus.isValidOrgType(orgType)) { updateContext.addMessage(update, UpdateMessages.wrongOrgType(inetStatus.getAllowedOrgTypes())); } } } | ReferenceCheck implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final InetStatus inetStatus = getStatus(update); final List<RpslAttribute> updatedOrgAttributes = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (inetStatus.needsOrgReference() && updatedOrgAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.orgAttributeMissing()); return; } if (updatedOrgAttributes.isEmpty()) { return; } final RpslAttribute org = updatedOrgAttributes.get(0); final RpslObject referencedOrganisation = findOrgReference(org); if (referencedOrganisation == null) { updateContext.addMessage(update, UpdateMessages.referenceNotFound(org.getCleanValue())); return; } final CIString cleanOrgTypeValue = referencedOrganisation.findAttribute(AttributeType.ORG_TYPE).getCleanValue(); final OrgType orgType = OrgType.getFor(cleanOrgTypeValue); if (orgType == null || !inetStatus.isValidOrgType(orgType)) { updateContext.addMessage(update, UpdateMessages.wrongOrgType(inetStatus.getAllowedOrgTypes())); } } @Autowired ReferenceCheck(final RpslObjectUpdateDao rpslObjectUpdateDao, final RpslObjectDao rpslObjectDao); } | ReferenceCheck implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final InetStatus inetStatus = getStatus(update); final List<RpslAttribute> updatedOrgAttributes = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (inetStatus.needsOrgReference() && updatedOrgAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.orgAttributeMissing()); return; } if (updatedOrgAttributes.isEmpty()) { return; } final RpslAttribute org = updatedOrgAttributes.get(0); final RpslObject referencedOrganisation = findOrgReference(org); if (referencedOrganisation == null) { updateContext.addMessage(update, UpdateMessages.referenceNotFound(org.getCleanValue())); return; } final CIString cleanOrgTypeValue = referencedOrganisation.findAttribute(AttributeType.ORG_TYPE).getCleanValue(); final OrgType orgType = OrgType.getFor(cleanOrgTypeValue); if (orgType == null || !inetStatus.isValidOrgType(orgType)) { updateContext.addMessage(update, UpdateMessages.wrongOrgType(inetStatus.getAllowedOrgTypes())); } } @Autowired ReferenceCheck(final RpslObjectUpdateDao rpslObjectUpdateDao, final RpslObjectDao rpslObjectDao); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | ReferenceCheck implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final InetStatus inetStatus = getStatus(update); final List<RpslAttribute> updatedOrgAttributes = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (inetStatus.needsOrgReference() && updatedOrgAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.orgAttributeMissing()); return; } if (updatedOrgAttributes.isEmpty()) { return; } final RpslAttribute org = updatedOrgAttributes.get(0); final RpslObject referencedOrganisation = findOrgReference(org); if (referencedOrganisation == null) { updateContext.addMessage(update, UpdateMessages.referenceNotFound(org.getCleanValue())); return; } final CIString cleanOrgTypeValue = referencedOrganisation.findAttribute(AttributeType.ORG_TYPE).getCleanValue(); final OrgType orgType = OrgType.getFor(cleanOrgTypeValue); if (orgType == null || !inetStatus.isValidOrgType(orgType)) { updateContext.addMessage(update, UpdateMessages.wrongOrgType(inetStatus.getAllowedOrgTypes())); } } @Autowired ReferenceCheck(final RpslObjectUpdateDao rpslObjectUpdateDao, final RpslObjectDao rpslObjectDao); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void create_wrong_orgtype_on_found_org() { when(update.getAction()).thenReturn(Action.CREATE); when(update.getUpdatedObject()).thenReturn(RpslObject.parse("inetnum: 192.0/24\nstatus: ALLOCATED PA\norg: ORG1")); when(rpslObjectUpdateDao.getAttributeReference(AttributeType.ORG, ciString("ORG1"))).thenReturn(rpslObjectInfo); when(rpslObjectInfo.getKey()).thenReturn("ORG1"); when(rpslObjectDao.getByKey(ObjectType.ORGANISATION, "ORG1")).thenReturn(RpslObject.parse("organisation: ORG1\norg-type: OTHER")); subject.validate(update, updateContext); verify(updateContext).addMessage(update, UpdateMessages.wrongOrgType(InetnumStatus.ALLOCATED_PA.getAllowedOrgTypes())); } | @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final InetStatus inetStatus = getStatus(update); final List<RpslAttribute> updatedOrgAttributes = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (inetStatus.needsOrgReference() && updatedOrgAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.orgAttributeMissing()); return; } if (updatedOrgAttributes.isEmpty()) { return; } final RpslAttribute org = updatedOrgAttributes.get(0); final RpslObject referencedOrganisation = findOrgReference(org); if (referencedOrganisation == null) { updateContext.addMessage(update, UpdateMessages.referenceNotFound(org.getCleanValue())); return; } final CIString cleanOrgTypeValue = referencedOrganisation.findAttribute(AttributeType.ORG_TYPE).getCleanValue(); final OrgType orgType = OrgType.getFor(cleanOrgTypeValue); if (orgType == null || !inetStatus.isValidOrgType(orgType)) { updateContext.addMessage(update, UpdateMessages.wrongOrgType(inetStatus.getAllowedOrgTypes())); } } | ReferenceCheck implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final InetStatus inetStatus = getStatus(update); final List<RpslAttribute> updatedOrgAttributes = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (inetStatus.needsOrgReference() && updatedOrgAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.orgAttributeMissing()); return; } if (updatedOrgAttributes.isEmpty()) { return; } final RpslAttribute org = updatedOrgAttributes.get(0); final RpslObject referencedOrganisation = findOrgReference(org); if (referencedOrganisation == null) { updateContext.addMessage(update, UpdateMessages.referenceNotFound(org.getCleanValue())); return; } final CIString cleanOrgTypeValue = referencedOrganisation.findAttribute(AttributeType.ORG_TYPE).getCleanValue(); final OrgType orgType = OrgType.getFor(cleanOrgTypeValue); if (orgType == null || !inetStatus.isValidOrgType(orgType)) { updateContext.addMessage(update, UpdateMessages.wrongOrgType(inetStatus.getAllowedOrgTypes())); } } } | ReferenceCheck implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final InetStatus inetStatus = getStatus(update); final List<RpslAttribute> updatedOrgAttributes = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (inetStatus.needsOrgReference() && updatedOrgAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.orgAttributeMissing()); return; } if (updatedOrgAttributes.isEmpty()) { return; } final RpslAttribute org = updatedOrgAttributes.get(0); final RpslObject referencedOrganisation = findOrgReference(org); if (referencedOrganisation == null) { updateContext.addMessage(update, UpdateMessages.referenceNotFound(org.getCleanValue())); return; } final CIString cleanOrgTypeValue = referencedOrganisation.findAttribute(AttributeType.ORG_TYPE).getCleanValue(); final OrgType orgType = OrgType.getFor(cleanOrgTypeValue); if (orgType == null || !inetStatus.isValidOrgType(orgType)) { updateContext.addMessage(update, UpdateMessages.wrongOrgType(inetStatus.getAllowedOrgTypes())); } } @Autowired ReferenceCheck(final RpslObjectUpdateDao rpslObjectUpdateDao, final RpslObjectDao rpslObjectDao); } | ReferenceCheck implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final InetStatus inetStatus = getStatus(update); final List<RpslAttribute> updatedOrgAttributes = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (inetStatus.needsOrgReference() && updatedOrgAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.orgAttributeMissing()); return; } if (updatedOrgAttributes.isEmpty()) { return; } final RpslAttribute org = updatedOrgAttributes.get(0); final RpslObject referencedOrganisation = findOrgReference(org); if (referencedOrganisation == null) { updateContext.addMessage(update, UpdateMessages.referenceNotFound(org.getCleanValue())); return; } final CIString cleanOrgTypeValue = referencedOrganisation.findAttribute(AttributeType.ORG_TYPE).getCleanValue(); final OrgType orgType = OrgType.getFor(cleanOrgTypeValue); if (orgType == null || !inetStatus.isValidOrgType(orgType)) { updateContext.addMessage(update, UpdateMessages.wrongOrgType(inetStatus.getAllowedOrgTypes())); } } @Autowired ReferenceCheck(final RpslObjectUpdateDao rpslObjectUpdateDao, final RpslObjectDao rpslObjectDao); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | ReferenceCheck implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final InetStatus inetStatus = getStatus(update); final List<RpslAttribute> updatedOrgAttributes = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (inetStatus.needsOrgReference() && updatedOrgAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.orgAttributeMissing()); return; } if (updatedOrgAttributes.isEmpty()) { return; } final RpslAttribute org = updatedOrgAttributes.get(0); final RpslObject referencedOrganisation = findOrgReference(org); if (referencedOrganisation == null) { updateContext.addMessage(update, UpdateMessages.referenceNotFound(org.getCleanValue())); return; } final CIString cleanOrgTypeValue = referencedOrganisation.findAttribute(AttributeType.ORG_TYPE).getCleanValue(); final OrgType orgType = OrgType.getFor(cleanOrgTypeValue); if (orgType == null || !inetStatus.isValidOrgType(orgType)) { updateContext.addMessage(update, UpdateMessages.wrongOrgType(inetStatus.getAllowedOrgTypes())); } } @Autowired ReferenceCheck(final RpslObjectUpdateDao rpslObjectUpdateDao, final RpslObjectDao rpslObjectDao); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void create_wrong_orgtype_on_found_org_direct_assignment() { when(update.getAction()).thenReturn(Action.CREATE); when(update.getUpdatedObject()).thenReturn(RpslObject.parse("inetnum: 192.0/24\nstatus: ALLOCATED PA\norg: ORG1")); when(rpslObjectUpdateDao.getAttributeReference(AttributeType.ORG, ciString("ORG1"))).thenReturn(rpslObjectInfo); when(rpslObjectInfo.getKey()).thenReturn("ORG1"); when(rpslObjectDao.getByKey(ObjectType.ORGANISATION, "ORG1")).thenReturn(RpslObject.parse("organisation: ORG1\norg-type: DIRECT_ASSIGNMENT")); subject.validate(update, updateContext); verify(updateContext).addMessage(update, UpdateMessages.wrongOrgType(InetnumStatus.ALLOCATED_PA.getAllowedOrgTypes())); } | @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final InetStatus inetStatus = getStatus(update); final List<RpslAttribute> updatedOrgAttributes = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (inetStatus.needsOrgReference() && updatedOrgAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.orgAttributeMissing()); return; } if (updatedOrgAttributes.isEmpty()) { return; } final RpslAttribute org = updatedOrgAttributes.get(0); final RpslObject referencedOrganisation = findOrgReference(org); if (referencedOrganisation == null) { updateContext.addMessage(update, UpdateMessages.referenceNotFound(org.getCleanValue())); return; } final CIString cleanOrgTypeValue = referencedOrganisation.findAttribute(AttributeType.ORG_TYPE).getCleanValue(); final OrgType orgType = OrgType.getFor(cleanOrgTypeValue); if (orgType == null || !inetStatus.isValidOrgType(orgType)) { updateContext.addMessage(update, UpdateMessages.wrongOrgType(inetStatus.getAllowedOrgTypes())); } } | ReferenceCheck implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final InetStatus inetStatus = getStatus(update); final List<RpslAttribute> updatedOrgAttributes = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (inetStatus.needsOrgReference() && updatedOrgAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.orgAttributeMissing()); return; } if (updatedOrgAttributes.isEmpty()) { return; } final RpslAttribute org = updatedOrgAttributes.get(0); final RpslObject referencedOrganisation = findOrgReference(org); if (referencedOrganisation == null) { updateContext.addMessage(update, UpdateMessages.referenceNotFound(org.getCleanValue())); return; } final CIString cleanOrgTypeValue = referencedOrganisation.findAttribute(AttributeType.ORG_TYPE).getCleanValue(); final OrgType orgType = OrgType.getFor(cleanOrgTypeValue); if (orgType == null || !inetStatus.isValidOrgType(orgType)) { updateContext.addMessage(update, UpdateMessages.wrongOrgType(inetStatus.getAllowedOrgTypes())); } } } | ReferenceCheck implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final InetStatus inetStatus = getStatus(update); final List<RpslAttribute> updatedOrgAttributes = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (inetStatus.needsOrgReference() && updatedOrgAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.orgAttributeMissing()); return; } if (updatedOrgAttributes.isEmpty()) { return; } final RpslAttribute org = updatedOrgAttributes.get(0); final RpslObject referencedOrganisation = findOrgReference(org); if (referencedOrganisation == null) { updateContext.addMessage(update, UpdateMessages.referenceNotFound(org.getCleanValue())); return; } final CIString cleanOrgTypeValue = referencedOrganisation.findAttribute(AttributeType.ORG_TYPE).getCleanValue(); final OrgType orgType = OrgType.getFor(cleanOrgTypeValue); if (orgType == null || !inetStatus.isValidOrgType(orgType)) { updateContext.addMessage(update, UpdateMessages.wrongOrgType(inetStatus.getAllowedOrgTypes())); } } @Autowired ReferenceCheck(final RpslObjectUpdateDao rpslObjectUpdateDao, final RpslObjectDao rpslObjectDao); } | ReferenceCheck implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final InetStatus inetStatus = getStatus(update); final List<RpslAttribute> updatedOrgAttributes = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (inetStatus.needsOrgReference() && updatedOrgAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.orgAttributeMissing()); return; } if (updatedOrgAttributes.isEmpty()) { return; } final RpslAttribute org = updatedOrgAttributes.get(0); final RpslObject referencedOrganisation = findOrgReference(org); if (referencedOrganisation == null) { updateContext.addMessage(update, UpdateMessages.referenceNotFound(org.getCleanValue())); return; } final CIString cleanOrgTypeValue = referencedOrganisation.findAttribute(AttributeType.ORG_TYPE).getCleanValue(); final OrgType orgType = OrgType.getFor(cleanOrgTypeValue); if (orgType == null || !inetStatus.isValidOrgType(orgType)) { updateContext.addMessage(update, UpdateMessages.wrongOrgType(inetStatus.getAllowedOrgTypes())); } } @Autowired ReferenceCheck(final RpslObjectUpdateDao rpslObjectUpdateDao, final RpslObjectDao rpslObjectDao); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | ReferenceCheck implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final InetStatus inetStatus = getStatus(update); final List<RpslAttribute> updatedOrgAttributes = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (inetStatus.needsOrgReference() && updatedOrgAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.orgAttributeMissing()); return; } if (updatedOrgAttributes.isEmpty()) { return; } final RpslAttribute org = updatedOrgAttributes.get(0); final RpslObject referencedOrganisation = findOrgReference(org); if (referencedOrganisation == null) { updateContext.addMessage(update, UpdateMessages.referenceNotFound(org.getCleanValue())); return; } final CIString cleanOrgTypeValue = referencedOrganisation.findAttribute(AttributeType.ORG_TYPE).getCleanValue(); final OrgType orgType = OrgType.getFor(cleanOrgTypeValue); if (orgType == null || !inetStatus.isValidOrgType(orgType)) { updateContext.addMessage(update, UpdateMessages.wrongOrgType(inetStatus.getAllowedOrgTypes())); } } @Autowired ReferenceCheck(final RpslObjectUpdateDao rpslObjectUpdateDao, final RpslObjectDao rpslObjectDao); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void create_wrong_orgtype_on_found_org_override() { when(updateSubject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)).thenReturn(true); when(update.getAction()).thenReturn(Action.CREATE); when(update.getUpdatedObject()).thenReturn(RpslObject.parse("inetnum: 192.0/24\nstatus: ALLOCATED PA\norg: ORG1")); when(rpslObjectUpdateDao.getAttributeReference(AttributeType.ORG, ciString("ORG1"))).thenReturn(rpslObjectInfo); when(rpslObjectInfo.getKey()).thenReturn("ORG1"); when(rpslObjectDao.getByKey(ObjectType.ORGANISATION, "ORG1")).thenReturn(RpslObject.parse("organisation: ORG1\norg-type: OTHER")); subject.validate(update, updateContext); verify(updateContext).getSubject(any(UpdateContainer.class)); verifyNoMoreInteractions(updateContext); } | @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final InetStatus inetStatus = getStatus(update); final List<RpslAttribute> updatedOrgAttributes = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (inetStatus.needsOrgReference() && updatedOrgAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.orgAttributeMissing()); return; } if (updatedOrgAttributes.isEmpty()) { return; } final RpslAttribute org = updatedOrgAttributes.get(0); final RpslObject referencedOrganisation = findOrgReference(org); if (referencedOrganisation == null) { updateContext.addMessage(update, UpdateMessages.referenceNotFound(org.getCleanValue())); return; } final CIString cleanOrgTypeValue = referencedOrganisation.findAttribute(AttributeType.ORG_TYPE).getCleanValue(); final OrgType orgType = OrgType.getFor(cleanOrgTypeValue); if (orgType == null || !inetStatus.isValidOrgType(orgType)) { updateContext.addMessage(update, UpdateMessages.wrongOrgType(inetStatus.getAllowedOrgTypes())); } } | ReferenceCheck implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final InetStatus inetStatus = getStatus(update); final List<RpslAttribute> updatedOrgAttributes = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (inetStatus.needsOrgReference() && updatedOrgAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.orgAttributeMissing()); return; } if (updatedOrgAttributes.isEmpty()) { return; } final RpslAttribute org = updatedOrgAttributes.get(0); final RpslObject referencedOrganisation = findOrgReference(org); if (referencedOrganisation == null) { updateContext.addMessage(update, UpdateMessages.referenceNotFound(org.getCleanValue())); return; } final CIString cleanOrgTypeValue = referencedOrganisation.findAttribute(AttributeType.ORG_TYPE).getCleanValue(); final OrgType orgType = OrgType.getFor(cleanOrgTypeValue); if (orgType == null || !inetStatus.isValidOrgType(orgType)) { updateContext.addMessage(update, UpdateMessages.wrongOrgType(inetStatus.getAllowedOrgTypes())); } } } | ReferenceCheck implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final InetStatus inetStatus = getStatus(update); final List<RpslAttribute> updatedOrgAttributes = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (inetStatus.needsOrgReference() && updatedOrgAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.orgAttributeMissing()); return; } if (updatedOrgAttributes.isEmpty()) { return; } final RpslAttribute org = updatedOrgAttributes.get(0); final RpslObject referencedOrganisation = findOrgReference(org); if (referencedOrganisation == null) { updateContext.addMessage(update, UpdateMessages.referenceNotFound(org.getCleanValue())); return; } final CIString cleanOrgTypeValue = referencedOrganisation.findAttribute(AttributeType.ORG_TYPE).getCleanValue(); final OrgType orgType = OrgType.getFor(cleanOrgTypeValue); if (orgType == null || !inetStatus.isValidOrgType(orgType)) { updateContext.addMessage(update, UpdateMessages.wrongOrgType(inetStatus.getAllowedOrgTypes())); } } @Autowired ReferenceCheck(final RpslObjectUpdateDao rpslObjectUpdateDao, final RpslObjectDao rpslObjectDao); } | ReferenceCheck implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final InetStatus inetStatus = getStatus(update); final List<RpslAttribute> updatedOrgAttributes = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (inetStatus.needsOrgReference() && updatedOrgAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.orgAttributeMissing()); return; } if (updatedOrgAttributes.isEmpty()) { return; } final RpslAttribute org = updatedOrgAttributes.get(0); final RpslObject referencedOrganisation = findOrgReference(org); if (referencedOrganisation == null) { updateContext.addMessage(update, UpdateMessages.referenceNotFound(org.getCleanValue())); return; } final CIString cleanOrgTypeValue = referencedOrganisation.findAttribute(AttributeType.ORG_TYPE).getCleanValue(); final OrgType orgType = OrgType.getFor(cleanOrgTypeValue); if (orgType == null || !inetStatus.isValidOrgType(orgType)) { updateContext.addMessage(update, UpdateMessages.wrongOrgType(inetStatus.getAllowedOrgTypes())); } } @Autowired ReferenceCheck(final RpslObjectUpdateDao rpslObjectUpdateDao, final RpslObjectDao rpslObjectDao); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | ReferenceCheck implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final InetStatus inetStatus = getStatus(update); final List<RpslAttribute> updatedOrgAttributes = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (inetStatus.needsOrgReference() && updatedOrgAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.orgAttributeMissing()); return; } if (updatedOrgAttributes.isEmpty()) { return; } final RpslAttribute org = updatedOrgAttributes.get(0); final RpslObject referencedOrganisation = findOrgReference(org); if (referencedOrganisation == null) { updateContext.addMessage(update, UpdateMessages.referenceNotFound(org.getCleanValue())); return; } final CIString cleanOrgTypeValue = referencedOrganisation.findAttribute(AttributeType.ORG_TYPE).getCleanValue(); final OrgType orgType = OrgType.getFor(cleanOrgTypeValue); if (orgType == null || !inetStatus.isValidOrgType(orgType)) { updateContext.addMessage(update, UpdateMessages.wrongOrgType(inetStatus.getAllowedOrgTypes())); } } @Autowired ReferenceCheck(final RpslObjectUpdateDao rpslObjectUpdateDao, final RpslObjectDao rpslObjectDao); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void create_right_orgtype_on_found_org() { when(update.getAction()).thenReturn(Action.CREATE); when(update.getUpdatedObject()).thenReturn(RpslObject.parse("inetnum: 192.0/24\nstatus: ALLOCATED PA\norg: ORG1")); when(rpslObjectUpdateDao.getAttributeReference(AttributeType.ORG, ciString("ORG1"))).thenReturn(rpslObjectInfo); when(rpslObjectInfo.getKey()).thenReturn("ORG1"); when(rpslObjectDao.getByKey(ObjectType.ORGANISATION, "ORG1")).thenReturn(RpslObject.parse("organisation: ORG1\norg-type: LIR")); subject.validate(update, updateContext); verify(updateContext).getSubject(any(UpdateContainer.class)); verifyNoMoreInteractions(updateContext); } | @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final InetStatus inetStatus = getStatus(update); final List<RpslAttribute> updatedOrgAttributes = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (inetStatus.needsOrgReference() && updatedOrgAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.orgAttributeMissing()); return; } if (updatedOrgAttributes.isEmpty()) { return; } final RpslAttribute org = updatedOrgAttributes.get(0); final RpslObject referencedOrganisation = findOrgReference(org); if (referencedOrganisation == null) { updateContext.addMessage(update, UpdateMessages.referenceNotFound(org.getCleanValue())); return; } final CIString cleanOrgTypeValue = referencedOrganisation.findAttribute(AttributeType.ORG_TYPE).getCleanValue(); final OrgType orgType = OrgType.getFor(cleanOrgTypeValue); if (orgType == null || !inetStatus.isValidOrgType(orgType)) { updateContext.addMessage(update, UpdateMessages.wrongOrgType(inetStatus.getAllowedOrgTypes())); } } | ReferenceCheck implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final InetStatus inetStatus = getStatus(update); final List<RpslAttribute> updatedOrgAttributes = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (inetStatus.needsOrgReference() && updatedOrgAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.orgAttributeMissing()); return; } if (updatedOrgAttributes.isEmpty()) { return; } final RpslAttribute org = updatedOrgAttributes.get(0); final RpslObject referencedOrganisation = findOrgReference(org); if (referencedOrganisation == null) { updateContext.addMessage(update, UpdateMessages.referenceNotFound(org.getCleanValue())); return; } final CIString cleanOrgTypeValue = referencedOrganisation.findAttribute(AttributeType.ORG_TYPE).getCleanValue(); final OrgType orgType = OrgType.getFor(cleanOrgTypeValue); if (orgType == null || !inetStatus.isValidOrgType(orgType)) { updateContext.addMessage(update, UpdateMessages.wrongOrgType(inetStatus.getAllowedOrgTypes())); } } } | ReferenceCheck implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final InetStatus inetStatus = getStatus(update); final List<RpslAttribute> updatedOrgAttributes = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (inetStatus.needsOrgReference() && updatedOrgAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.orgAttributeMissing()); return; } if (updatedOrgAttributes.isEmpty()) { return; } final RpslAttribute org = updatedOrgAttributes.get(0); final RpslObject referencedOrganisation = findOrgReference(org); if (referencedOrganisation == null) { updateContext.addMessage(update, UpdateMessages.referenceNotFound(org.getCleanValue())); return; } final CIString cleanOrgTypeValue = referencedOrganisation.findAttribute(AttributeType.ORG_TYPE).getCleanValue(); final OrgType orgType = OrgType.getFor(cleanOrgTypeValue); if (orgType == null || !inetStatus.isValidOrgType(orgType)) { updateContext.addMessage(update, UpdateMessages.wrongOrgType(inetStatus.getAllowedOrgTypes())); } } @Autowired ReferenceCheck(final RpslObjectUpdateDao rpslObjectUpdateDao, final RpslObjectDao rpslObjectDao); } | ReferenceCheck implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final InetStatus inetStatus = getStatus(update); final List<RpslAttribute> updatedOrgAttributes = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (inetStatus.needsOrgReference() && updatedOrgAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.orgAttributeMissing()); return; } if (updatedOrgAttributes.isEmpty()) { return; } final RpslAttribute org = updatedOrgAttributes.get(0); final RpslObject referencedOrganisation = findOrgReference(org); if (referencedOrganisation == null) { updateContext.addMessage(update, UpdateMessages.referenceNotFound(org.getCleanValue())); return; } final CIString cleanOrgTypeValue = referencedOrganisation.findAttribute(AttributeType.ORG_TYPE).getCleanValue(); final OrgType orgType = OrgType.getFor(cleanOrgTypeValue); if (orgType == null || !inetStatus.isValidOrgType(orgType)) { updateContext.addMessage(update, UpdateMessages.wrongOrgType(inetStatus.getAllowedOrgTypes())); } } @Autowired ReferenceCheck(final RpslObjectUpdateDao rpslObjectUpdateDao, final RpslObjectDao rpslObjectDao); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | ReferenceCheck implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final InetStatus inetStatus = getStatus(update); final List<RpslAttribute> updatedOrgAttributes = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (inetStatus.needsOrgReference() && updatedOrgAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.orgAttributeMissing()); return; } if (updatedOrgAttributes.isEmpty()) { return; } final RpslAttribute org = updatedOrgAttributes.get(0); final RpslObject referencedOrganisation = findOrgReference(org); if (referencedOrganisation == null) { updateContext.addMessage(update, UpdateMessages.referenceNotFound(org.getCleanValue())); return; } final CIString cleanOrgTypeValue = referencedOrganisation.findAttribute(AttributeType.ORG_TYPE).getCleanValue(); final OrgType orgType = OrgType.getFor(cleanOrgTypeValue); if (orgType == null || !inetStatus.isValidOrgType(orgType)) { updateContext.addMessage(update, UpdateMessages.wrongOrgType(inetStatus.getAllowedOrgTypes())); } } @Autowired ReferenceCheck(final RpslObjectUpdateDao rpslObjectUpdateDao, final RpslObjectDao rpslObjectDao); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void getActions() { assertThat(subject.getActions(), contains(Action.CREATE)); } | @Override public ImmutableList<Action> getActions() { return ACTIONS; } | IntersectionValidator implements BusinessRuleValidator { @Override public ImmutableList<Action> getActions() { return ACTIONS; } } | IntersectionValidator implements BusinessRuleValidator { @Override public ImmutableList<Action> getActions() { return ACTIONS; } @Autowired IntersectionValidator(final Ipv4Tree ipv4Tree, final Ipv6Tree ipv6Tree); } | IntersectionValidator implements BusinessRuleValidator { @Override public ImmutableList<Action> getActions() { return ACTIONS; } @Autowired IntersectionValidator(final Ipv4Tree ipv4Tree, final Ipv6Tree ipv6Tree); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | IntersectionValidator implements BusinessRuleValidator { @Override public ImmutableList<Action> getActions() { return ACTIONS; } @Autowired IntersectionValidator(final Ipv4Tree ipv4Tree, final Ipv6Tree ipv6Tree); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void getTypes() { assertThat(subject.getTypes(), containsInAnyOrder(ObjectType.INETNUM, ObjectType.INET6NUM)); } | @Override public ImmutableList<ObjectType> getTypes() { return TYPES; } | IntersectionValidator implements BusinessRuleValidator { @Override public ImmutableList<ObjectType> getTypes() { return TYPES; } } | IntersectionValidator implements BusinessRuleValidator { @Override public ImmutableList<ObjectType> getTypes() { return TYPES; } @Autowired IntersectionValidator(final Ipv4Tree ipv4Tree, final Ipv6Tree ipv6Tree); } | IntersectionValidator implements BusinessRuleValidator { @Override public ImmutableList<ObjectType> getTypes() { return TYPES; } @Autowired IntersectionValidator(final Ipv4Tree ipv4Tree, final Ipv6Tree ipv6Tree); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | IntersectionValidator implements BusinessRuleValidator { @Override public ImmutableList<ObjectType> getTypes() { return TYPES; } @Autowired IntersectionValidator(final Ipv4Tree ipv4Tree, final Ipv6Tree ipv6Tree); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void validate_no_children_ipv4() { final RpslObject object = RpslObject.parse("inetnum: 193.0.0.0"); when(ipv4Tree.findFirstMoreSpecific(parentIpv4Key)).thenReturn(Lists.<Ipv4Entry>newArrayList()); when(update.getReferenceObject()).thenReturn(object); subject.validate(update, updateContext); verifyZeroInteractions(updateContext); } | @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final IpInterval ipInterval = IpInterval.parse(update.getReferenceObject().getKey()); if (ipInterval instanceof Ipv4Resource) { validateIntersections(update, updateContext, ipInterval, ipv4Tree); } else { validateIntersections(update, updateContext, ipInterval, ipv6Tree); } } | IntersectionValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final IpInterval ipInterval = IpInterval.parse(update.getReferenceObject().getKey()); if (ipInterval instanceof Ipv4Resource) { validateIntersections(update, updateContext, ipInterval, ipv4Tree); } else { validateIntersections(update, updateContext, ipInterval, ipv6Tree); } } } | IntersectionValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final IpInterval ipInterval = IpInterval.parse(update.getReferenceObject().getKey()); if (ipInterval instanceof Ipv4Resource) { validateIntersections(update, updateContext, ipInterval, ipv4Tree); } else { validateIntersections(update, updateContext, ipInterval, ipv6Tree); } } @Autowired IntersectionValidator(final Ipv4Tree ipv4Tree, final Ipv6Tree ipv6Tree); } | IntersectionValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final IpInterval ipInterval = IpInterval.parse(update.getReferenceObject().getKey()); if (ipInterval instanceof Ipv4Resource) { validateIntersections(update, updateContext, ipInterval, ipv4Tree); } else { validateIntersections(update, updateContext, ipInterval, ipv6Tree); } } @Autowired IntersectionValidator(final Ipv4Tree ipv4Tree, final Ipv6Tree ipv6Tree); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | IntersectionValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final IpInterval ipInterval = IpInterval.parse(update.getReferenceObject().getKey()); if (ipInterval instanceof Ipv4Resource) { validateIntersections(update, updateContext, ipInterval, ipv4Tree); } else { validateIntersections(update, updateContext, ipInterval, ipv6Tree); } } @Autowired IntersectionValidator(final Ipv4Tree ipv4Tree, final Ipv6Tree ipv6Tree); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void validate_no_children_ipv6() { final RpslObject object = RpslObject.parse("inet6num: 2001:0658:021A::/48"); when(ipv6Tree.findFirstMoreSpecific(parentIpv6Key)).thenReturn(Lists.<Ipv6Entry>newArrayList()); when(update.getReferenceObject()).thenReturn(object); subject.validate(update, updateContext); verifyZeroInteractions(updateContext); } | @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final IpInterval ipInterval = IpInterval.parse(update.getReferenceObject().getKey()); if (ipInterval instanceof Ipv4Resource) { validateIntersections(update, updateContext, ipInterval, ipv4Tree); } else { validateIntersections(update, updateContext, ipInterval, ipv6Tree); } } | IntersectionValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final IpInterval ipInterval = IpInterval.parse(update.getReferenceObject().getKey()); if (ipInterval instanceof Ipv4Resource) { validateIntersections(update, updateContext, ipInterval, ipv4Tree); } else { validateIntersections(update, updateContext, ipInterval, ipv6Tree); } } } | IntersectionValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final IpInterval ipInterval = IpInterval.parse(update.getReferenceObject().getKey()); if (ipInterval instanceof Ipv4Resource) { validateIntersections(update, updateContext, ipInterval, ipv4Tree); } else { validateIntersections(update, updateContext, ipInterval, ipv6Tree); } } @Autowired IntersectionValidator(final Ipv4Tree ipv4Tree, final Ipv6Tree ipv6Tree); } | IntersectionValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final IpInterval ipInterval = IpInterval.parse(update.getReferenceObject().getKey()); if (ipInterval instanceof Ipv4Resource) { validateIntersections(update, updateContext, ipInterval, ipv4Tree); } else { validateIntersections(update, updateContext, ipInterval, ipv6Tree); } } @Autowired IntersectionValidator(final Ipv4Tree ipv4Tree, final Ipv6Tree ipv6Tree); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | IntersectionValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final IpInterval ipInterval = IpInterval.parse(update.getReferenceObject().getKey()); if (ipInterval instanceof Ipv4Resource) { validateIntersections(update, updateContext, ipInterval, ipv4Tree); } else { validateIntersections(update, updateContext, ipInterval, ipv6Tree); } } @Autowired IntersectionValidator(final Ipv4Tree ipv4Tree, final Ipv6Tree ipv6Tree); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void validate_no_intersections_ipv4() { final RpslObject object = RpslObject.parse("inetnum: 193.0.0.0 - 193.0.0.10"); when(ipv4Tree.findFirstMoreSpecific(parentIpv4Key)).thenReturn(Lists.newArrayList( new Ipv4Entry(Ipv4Resource.parse("192/8"), 1), new Ipv4Entry(Ipv4Resource.parse("193.0.0.1"), 2), new Ipv4Entry(Ipv4Resource.parse("193.0.1/24"), 3), new Ipv4Entry(Ipv4Resource.parse("193.0.0.1 - 193.0.0.2"), 4) )); when(update.getReferenceObject()).thenReturn(object); subject.validate(update, updateContext); verifyZeroInteractions(updateContext); } | @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final IpInterval ipInterval = IpInterval.parse(update.getReferenceObject().getKey()); if (ipInterval instanceof Ipv4Resource) { validateIntersections(update, updateContext, ipInterval, ipv4Tree); } else { validateIntersections(update, updateContext, ipInterval, ipv6Tree); } } | IntersectionValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final IpInterval ipInterval = IpInterval.parse(update.getReferenceObject().getKey()); if (ipInterval instanceof Ipv4Resource) { validateIntersections(update, updateContext, ipInterval, ipv4Tree); } else { validateIntersections(update, updateContext, ipInterval, ipv6Tree); } } } | IntersectionValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final IpInterval ipInterval = IpInterval.parse(update.getReferenceObject().getKey()); if (ipInterval instanceof Ipv4Resource) { validateIntersections(update, updateContext, ipInterval, ipv4Tree); } else { validateIntersections(update, updateContext, ipInterval, ipv6Tree); } } @Autowired IntersectionValidator(final Ipv4Tree ipv4Tree, final Ipv6Tree ipv6Tree); } | IntersectionValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final IpInterval ipInterval = IpInterval.parse(update.getReferenceObject().getKey()); if (ipInterval instanceof Ipv4Resource) { validateIntersections(update, updateContext, ipInterval, ipv4Tree); } else { validateIntersections(update, updateContext, ipInterval, ipv6Tree); } } @Autowired IntersectionValidator(final Ipv4Tree ipv4Tree, final Ipv6Tree ipv6Tree); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | IntersectionValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final IpInterval ipInterval = IpInterval.parse(update.getReferenceObject().getKey()); if (ipInterval instanceof Ipv4Resource) { validateIntersections(update, updateContext, ipInterval, ipv4Tree); } else { validateIntersections(update, updateContext, ipInterval, ipv6Tree); } } @Autowired IntersectionValidator(final Ipv4Tree ipv4Tree, final Ipv6Tree ipv6Tree); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void transform_route6_trailing_zero() { final RpslObject rpslObject = RpslObject.parse("" + "route6: 2001:1578:200::0/40\n" + "origin: AS12321"); final RpslObject result = attributeSanitizer.sanitize(rpslObject, objectMessages); assertThat(result.getValueForAttribute(AttributeType.ROUTE6).toString(), is("2001:1578:200::/40")); verify(objectMessages).addMessage(result.findAttribute(AttributeType.ROUTE6), ValidationMessages.attributeValueConverted("2001:1578:200::0/40", "2001:1578:200::/40")); verifyNoMoreInteractions(objectMessages); } | public RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages) { final Map<RpslAttribute, RpslAttribute> replacements = Maps.newHashMap(); for (final RpslAttribute attribute : object.getAttributes()) { final AttributeType type = attribute.getType(); String newValue = null; final Sanitizer sanitizer = SANITIZER_MAP.get(type); if (sanitizer == null) { continue; } try { newValue = sanitizer.sanitize(attribute); } catch (IllegalArgumentException ignored) { LOGGER.debug("{}: {}", ignored.getClass().getName(), ignored.getMessage()); } if (newValue == null) { continue; } final List<Message> attributeMessages = Lists.newArrayList(); if (!sanitizer.silent() && !attribute.getCleanValue().toString().equals(newValue)) { attributeMessages.add(ValidationMessages.attributeValueConverted(attribute.getCleanValue(), newValue)); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('\n') != -1) { attributeMessages.add(ValidationMessages.continuationLinesRemoved()); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('#') != -1) { attributeMessages.add(ValidationMessages.remarksReformatted()); } final String replacement = newValue + getCommentReplacement(attribute); final RpslAttribute transformed = new RpslAttribute(attribute.getKey(), replacement); replacements.put(attribute, transformed); for (final Message attributeMessage : attributeMessages) { objectMessages.addMessage(transformed, attributeMessage); } } return new RpslObjectBuilder(object).replaceAttributes(replacements).get(); } | AttributeSanitizer { public RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages) { final Map<RpslAttribute, RpslAttribute> replacements = Maps.newHashMap(); for (final RpslAttribute attribute : object.getAttributes()) { final AttributeType type = attribute.getType(); String newValue = null; final Sanitizer sanitizer = SANITIZER_MAP.get(type); if (sanitizer == null) { continue; } try { newValue = sanitizer.sanitize(attribute); } catch (IllegalArgumentException ignored) { LOGGER.debug("{}: {}", ignored.getClass().getName(), ignored.getMessage()); } if (newValue == null) { continue; } final List<Message> attributeMessages = Lists.newArrayList(); if (!sanitizer.silent() && !attribute.getCleanValue().toString().equals(newValue)) { attributeMessages.add(ValidationMessages.attributeValueConverted(attribute.getCleanValue(), newValue)); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('\n') != -1) { attributeMessages.add(ValidationMessages.continuationLinesRemoved()); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('#') != -1) { attributeMessages.add(ValidationMessages.remarksReformatted()); } final String replacement = newValue + getCommentReplacement(attribute); final RpslAttribute transformed = new RpslAttribute(attribute.getKey(), replacement); replacements.put(attribute, transformed); for (final Message attributeMessage : attributeMessages) { objectMessages.addMessage(transformed, attributeMessage); } } return new RpslObjectBuilder(object).replaceAttributes(replacements).get(); } } | AttributeSanitizer { public RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages) { final Map<RpslAttribute, RpslAttribute> replacements = Maps.newHashMap(); for (final RpslAttribute attribute : object.getAttributes()) { final AttributeType type = attribute.getType(); String newValue = null; final Sanitizer sanitizer = SANITIZER_MAP.get(type); if (sanitizer == null) { continue; } try { newValue = sanitizer.sanitize(attribute); } catch (IllegalArgumentException ignored) { LOGGER.debug("{}: {}", ignored.getClass().getName(), ignored.getMessage()); } if (newValue == null) { continue; } final List<Message> attributeMessages = Lists.newArrayList(); if (!sanitizer.silent() && !attribute.getCleanValue().toString().equals(newValue)) { attributeMessages.add(ValidationMessages.attributeValueConverted(attribute.getCleanValue(), newValue)); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('\n') != -1) { attributeMessages.add(ValidationMessages.continuationLinesRemoved()); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('#') != -1) { attributeMessages.add(ValidationMessages.remarksReformatted()); } final String replacement = newValue + getCommentReplacement(attribute); final RpslAttribute transformed = new RpslAttribute(attribute.getKey(), replacement); replacements.put(attribute, transformed); for (final Message attributeMessage : attributeMessages) { objectMessages.addMessage(transformed, attributeMessage); } } return new RpslObjectBuilder(object).replaceAttributes(replacements).get(); } @Autowired AttributeSanitizer(DateTimeProvider dateTimeProvider); } | AttributeSanitizer { public RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages) { final Map<RpslAttribute, RpslAttribute> replacements = Maps.newHashMap(); for (final RpslAttribute attribute : object.getAttributes()) { final AttributeType type = attribute.getType(); String newValue = null; final Sanitizer sanitizer = SANITIZER_MAP.get(type); if (sanitizer == null) { continue; } try { newValue = sanitizer.sanitize(attribute); } catch (IllegalArgumentException ignored) { LOGGER.debug("{}: {}", ignored.getClass().getName(), ignored.getMessage()); } if (newValue == null) { continue; } final List<Message> attributeMessages = Lists.newArrayList(); if (!sanitizer.silent() && !attribute.getCleanValue().toString().equals(newValue)) { attributeMessages.add(ValidationMessages.attributeValueConverted(attribute.getCleanValue(), newValue)); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('\n') != -1) { attributeMessages.add(ValidationMessages.continuationLinesRemoved()); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('#') != -1) { attributeMessages.add(ValidationMessages.remarksReformatted()); } final String replacement = newValue + getCommentReplacement(attribute); final RpslAttribute transformed = new RpslAttribute(attribute.getKey(), replacement); replacements.put(attribute, transformed); for (final Message attributeMessage : attributeMessages) { objectMessages.addMessage(transformed, attributeMessage); } } return new RpslObjectBuilder(object).replaceAttributes(replacements).get(); } @Autowired AttributeSanitizer(DateTimeProvider dateTimeProvider); CIString sanitizeKey(final RpslObject originalObject); RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages); } | AttributeSanitizer { public RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages) { final Map<RpslAttribute, RpslAttribute> replacements = Maps.newHashMap(); for (final RpslAttribute attribute : object.getAttributes()) { final AttributeType type = attribute.getType(); String newValue = null; final Sanitizer sanitizer = SANITIZER_MAP.get(type); if (sanitizer == null) { continue; } try { newValue = sanitizer.sanitize(attribute); } catch (IllegalArgumentException ignored) { LOGGER.debug("{}: {}", ignored.getClass().getName(), ignored.getMessage()); } if (newValue == null) { continue; } final List<Message> attributeMessages = Lists.newArrayList(); if (!sanitizer.silent() && !attribute.getCleanValue().toString().equals(newValue)) { attributeMessages.add(ValidationMessages.attributeValueConverted(attribute.getCleanValue(), newValue)); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('\n') != -1) { attributeMessages.add(ValidationMessages.continuationLinesRemoved()); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('#') != -1) { attributeMessages.add(ValidationMessages.remarksReformatted()); } final String replacement = newValue + getCommentReplacement(attribute); final RpslAttribute transformed = new RpslAttribute(attribute.getKey(), replacement); replacements.put(attribute, transformed); for (final Message attributeMessage : attributeMessages) { objectMessages.addMessage(transformed, attributeMessage); } } return new RpslObjectBuilder(object).replaceAttributes(replacements).get(); } @Autowired AttributeSanitizer(DateTimeProvider dateTimeProvider); CIString sanitizeKey(final RpslObject originalObject); RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages); } |
@Test public void validate_intersections_ipv4() { final RpslObject object = RpslObject.parse("inetnum: 193.0.0.0 - 193.0.0.10"); when(ipv4Tree.findFirstMoreSpecific(parentIpv4Key)).thenReturn(Lists.newArrayList( new Ipv4Entry(Ipv4Resource.parse("193.0.0.10 - 193.0.0.12"), 1), new Ipv4Entry(Ipv4Resource.parse("193.0.1/24"), 2) )); when(update.getReferenceObject()).thenReturn(object); subject.validate(update, updateContext); verify(updateContext).addMessage(update, UpdateMessages.intersectingRange(Ipv4Resource.parse("193.0.0.10 - 193.0.0.12"))); verifyNoMoreInteractions(updateContext); } | @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final IpInterval ipInterval = IpInterval.parse(update.getReferenceObject().getKey()); if (ipInterval instanceof Ipv4Resource) { validateIntersections(update, updateContext, ipInterval, ipv4Tree); } else { validateIntersections(update, updateContext, ipInterval, ipv6Tree); } } | IntersectionValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final IpInterval ipInterval = IpInterval.parse(update.getReferenceObject().getKey()); if (ipInterval instanceof Ipv4Resource) { validateIntersections(update, updateContext, ipInterval, ipv4Tree); } else { validateIntersections(update, updateContext, ipInterval, ipv6Tree); } } } | IntersectionValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final IpInterval ipInterval = IpInterval.parse(update.getReferenceObject().getKey()); if (ipInterval instanceof Ipv4Resource) { validateIntersections(update, updateContext, ipInterval, ipv4Tree); } else { validateIntersections(update, updateContext, ipInterval, ipv6Tree); } } @Autowired IntersectionValidator(final Ipv4Tree ipv4Tree, final Ipv6Tree ipv6Tree); } | IntersectionValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final IpInterval ipInterval = IpInterval.parse(update.getReferenceObject().getKey()); if (ipInterval instanceof Ipv4Resource) { validateIntersections(update, updateContext, ipInterval, ipv4Tree); } else { validateIntersections(update, updateContext, ipInterval, ipv6Tree); } } @Autowired IntersectionValidator(final Ipv4Tree ipv4Tree, final Ipv6Tree ipv6Tree); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | IntersectionValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final IpInterval ipInterval = IpInterval.parse(update.getReferenceObject().getKey()); if (ipInterval instanceof Ipv4Resource) { validateIntersections(update, updateContext, ipInterval, ipv4Tree); } else { validateIntersections(update, updateContext, ipInterval, ipv6Tree); } } @Autowired IntersectionValidator(final Ipv4Tree ipv4Tree, final Ipv6Tree ipv6Tree); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void validate_invalid_parent_interval() throws Exception { when(ipv6Tree.findFirstLessSpecific(any(Ipv6Resource.class))).thenReturn(Collections.<Ipv6Entry>emptyList()); when(update.getReferenceObject()).thenReturn(RpslObject.parse("inet6num: fe80::/32")); subject.validate(update, updateContext); verify(updateContext).addMessage(update, UpdateMessages.invalidParentEntryForInterval(Ipv6Resource.parse("fe80::/32"))); verifyNoMoreInteractions(updateContext); } | @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final IpInterval ipInterval = IpInterval.parse(update.getReferenceObject().getKey()); if (ipInterval instanceof Ipv4Resource) { validateIntersections(update, updateContext, ipInterval, ipv4Tree); } else { validateIntersections(update, updateContext, ipInterval, ipv6Tree); } } | IntersectionValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final IpInterval ipInterval = IpInterval.parse(update.getReferenceObject().getKey()); if (ipInterval instanceof Ipv4Resource) { validateIntersections(update, updateContext, ipInterval, ipv4Tree); } else { validateIntersections(update, updateContext, ipInterval, ipv6Tree); } } } | IntersectionValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final IpInterval ipInterval = IpInterval.parse(update.getReferenceObject().getKey()); if (ipInterval instanceof Ipv4Resource) { validateIntersections(update, updateContext, ipInterval, ipv4Tree); } else { validateIntersections(update, updateContext, ipInterval, ipv6Tree); } } @Autowired IntersectionValidator(final Ipv4Tree ipv4Tree, final Ipv6Tree ipv6Tree); } | IntersectionValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final IpInterval ipInterval = IpInterval.parse(update.getReferenceObject().getKey()); if (ipInterval instanceof Ipv4Resource) { validateIntersections(update, updateContext, ipInterval, ipv4Tree); } else { validateIntersections(update, updateContext, ipInterval, ipv6Tree); } } @Autowired IntersectionValidator(final Ipv4Tree ipv4Tree, final Ipv6Tree ipv6Tree); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | IntersectionValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final IpInterval ipInterval = IpInterval.parse(update.getReferenceObject().getKey()); if (ipInterval instanceof Ipv4Resource) { validateIntersections(update, updateContext, ipInterval, ipv4Tree); } else { validateIntersections(update, updateContext, ipInterval, ipv6Tree); } } @Autowired IntersectionValidator(final Ipv4Tree ipv4Tree, final Ipv6Tree ipv6Tree); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void modify_has_no_endusermntner() { when(update.getUpdatedObject()).thenReturn(RpslObject.parse("inetnum: 192.0/24\nstatus: ASSIGNED ANYCAST\nmnt-by: TEST-MNT")); when(updateContext.getSubject(update)).thenReturn(principalSubject); when(principalSubject.hasPrincipal(Principal.ENDUSER_MAINTAINER)).thenReturn(true); subject.validate(update, updateContext); verify(updateContext).addMessage(update, UpdateMessages.adminMaintainerRemoved()); verify(maintainers).isEnduserMaintainer(ciSet("TEST-MNT")); verifyNoMoreInteractions(maintainers); } | @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (subject.hasPrincipal(Principal.ENDUSER_MAINTAINER)) { final boolean hasEnduserMaintainers = maintainers.isEnduserMaintainer( update.getUpdatedObject().getValuesForAttribute(AttributeType.MNT_BY)); if (!hasEnduserMaintainers) { updateContext.addMessage(update, UpdateMessages.adminMaintainerRemoved()); } } } | EndUserMaintainerChecks implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (subject.hasPrincipal(Principal.ENDUSER_MAINTAINER)) { final boolean hasEnduserMaintainers = maintainers.isEnduserMaintainer( update.getUpdatedObject().getValuesForAttribute(AttributeType.MNT_BY)); if (!hasEnduserMaintainers) { updateContext.addMessage(update, UpdateMessages.adminMaintainerRemoved()); } } } } | EndUserMaintainerChecks implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (subject.hasPrincipal(Principal.ENDUSER_MAINTAINER)) { final boolean hasEnduserMaintainers = maintainers.isEnduserMaintainer( update.getUpdatedObject().getValuesForAttribute(AttributeType.MNT_BY)); if (!hasEnduserMaintainers) { updateContext.addMessage(update, UpdateMessages.adminMaintainerRemoved()); } } } @Autowired EndUserMaintainerChecks(final Maintainers maintainers); } | EndUserMaintainerChecks implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (subject.hasPrincipal(Principal.ENDUSER_MAINTAINER)) { final boolean hasEnduserMaintainers = maintainers.isEnduserMaintainer( update.getUpdatedObject().getValuesForAttribute(AttributeType.MNT_BY)); if (!hasEnduserMaintainers) { updateContext.addMessage(update, UpdateMessages.adminMaintainerRemoved()); } } } @Autowired EndUserMaintainerChecks(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | EndUserMaintainerChecks implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (subject.hasPrincipal(Principal.ENDUSER_MAINTAINER)) { final boolean hasEnduserMaintainers = maintainers.isEnduserMaintainer( update.getUpdatedObject().getValuesForAttribute(AttributeType.MNT_BY)); if (!hasEnduserMaintainers) { updateContext.addMessage(update, UpdateMessages.adminMaintainerRemoved()); } } } @Autowired EndUserMaintainerChecks(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void modify_has_no_endusermntner_override() { when(update.getUpdatedObject()).thenReturn(RpslObject.parse("inetnum: 192.0/24\nstatus: ASSIGNED ANYCAST\nmnt-by: TEST-MNT")); when(updateContext.getSubject(update)).thenReturn(principalSubject); when(principalSubject.hasPrincipal(any(Principal.class))).thenReturn(true); subject.validate(update, updateContext); verify(updateContext, never()).addMessage(eq(update), any(Message.class)); verifyZeroInteractions(maintainers); } | @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (subject.hasPrincipal(Principal.ENDUSER_MAINTAINER)) { final boolean hasEnduserMaintainers = maintainers.isEnduserMaintainer( update.getUpdatedObject().getValuesForAttribute(AttributeType.MNT_BY)); if (!hasEnduserMaintainers) { updateContext.addMessage(update, UpdateMessages.adminMaintainerRemoved()); } } } | EndUserMaintainerChecks implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (subject.hasPrincipal(Principal.ENDUSER_MAINTAINER)) { final boolean hasEnduserMaintainers = maintainers.isEnduserMaintainer( update.getUpdatedObject().getValuesForAttribute(AttributeType.MNT_BY)); if (!hasEnduserMaintainers) { updateContext.addMessage(update, UpdateMessages.adminMaintainerRemoved()); } } } } | EndUserMaintainerChecks implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (subject.hasPrincipal(Principal.ENDUSER_MAINTAINER)) { final boolean hasEnduserMaintainers = maintainers.isEnduserMaintainer( update.getUpdatedObject().getValuesForAttribute(AttributeType.MNT_BY)); if (!hasEnduserMaintainers) { updateContext.addMessage(update, UpdateMessages.adminMaintainerRemoved()); } } } @Autowired EndUserMaintainerChecks(final Maintainers maintainers); } | EndUserMaintainerChecks implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (subject.hasPrincipal(Principal.ENDUSER_MAINTAINER)) { final boolean hasEnduserMaintainers = maintainers.isEnduserMaintainer( update.getUpdatedObject().getValuesForAttribute(AttributeType.MNT_BY)); if (!hasEnduserMaintainers) { updateContext.addMessage(update, UpdateMessages.adminMaintainerRemoved()); } } } @Autowired EndUserMaintainerChecks(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | EndUserMaintainerChecks implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (subject.hasPrincipal(Principal.ENDUSER_MAINTAINER)) { final boolean hasEnduserMaintainers = maintainers.isEnduserMaintainer( update.getUpdatedObject().getValuesForAttribute(AttributeType.MNT_BY)); if (!hasEnduserMaintainers) { updateContext.addMessage(update, UpdateMessages.adminMaintainerRemoved()); } } } @Autowired EndUserMaintainerChecks(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void modify_succeeds() { when(principalSubject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)).thenReturn(true); when(update.getUpdatedObject()).thenReturn(RpslObject.parse("inetnum: 192.0/24\nstatus: ASSIGNED ANYCAST\nmnt-by: END-MNT")); when(updateContext.getSubject(update)).thenReturn(principalSubject); subject.validate(update, updateContext); verify(updateContext, never()).addMessage(eq(update), any(Message.class)); verifyZeroInteractions(maintainers); } | @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (subject.hasPrincipal(Principal.ENDUSER_MAINTAINER)) { final boolean hasEnduserMaintainers = maintainers.isEnduserMaintainer( update.getUpdatedObject().getValuesForAttribute(AttributeType.MNT_BY)); if (!hasEnduserMaintainers) { updateContext.addMessage(update, UpdateMessages.adminMaintainerRemoved()); } } } | EndUserMaintainerChecks implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (subject.hasPrincipal(Principal.ENDUSER_MAINTAINER)) { final boolean hasEnduserMaintainers = maintainers.isEnduserMaintainer( update.getUpdatedObject().getValuesForAttribute(AttributeType.MNT_BY)); if (!hasEnduserMaintainers) { updateContext.addMessage(update, UpdateMessages.adminMaintainerRemoved()); } } } } | EndUserMaintainerChecks implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (subject.hasPrincipal(Principal.ENDUSER_MAINTAINER)) { final boolean hasEnduserMaintainers = maintainers.isEnduserMaintainer( update.getUpdatedObject().getValuesForAttribute(AttributeType.MNT_BY)); if (!hasEnduserMaintainers) { updateContext.addMessage(update, UpdateMessages.adminMaintainerRemoved()); } } } @Autowired EndUserMaintainerChecks(final Maintainers maintainers); } | EndUserMaintainerChecks implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (subject.hasPrincipal(Principal.ENDUSER_MAINTAINER)) { final boolean hasEnduserMaintainers = maintainers.isEnduserMaintainer( update.getUpdatedObject().getValuesForAttribute(AttributeType.MNT_BY)); if (!hasEnduserMaintainers) { updateContext.addMessage(update, UpdateMessages.adminMaintainerRemoved()); } } } @Autowired EndUserMaintainerChecks(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | EndUserMaintainerChecks implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (subject.hasPrincipal(Principal.ENDUSER_MAINTAINER)) { final boolean hasEnduserMaintainers = maintainers.isEnduserMaintainer( update.getUpdatedObject().getValuesForAttribute(AttributeType.MNT_BY)); if (!hasEnduserMaintainers) { updateContext.addMessage(update, UpdateMessages.adminMaintainerRemoved()); } } } @Autowired EndUserMaintainerChecks(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void getActions() { assertThat(subject.getActions(), contains(Action.MODIFY)); } | @Override public ImmutableList<Action> getActions() { return ACTIONS; } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public ImmutableList<Action> getActions() { return ACTIONS; } } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public ImmutableList<Action> getActions() { return ACTIONS; } @Autowired OrgAttributeNotChangedValidator(final Maintainers maintainers); } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public ImmutableList<Action> getActions() { return ACTIONS; } @Autowired OrgAttributeNotChangedValidator(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public ImmutableList<Action> getActions() { return ACTIONS; } @Autowired OrgAttributeNotChangedValidator(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void getTypes() { assertThat(subject.getTypes(), containsInAnyOrder(ObjectType.INETNUM, ObjectType.INET6NUM, ObjectType.AUT_NUM)); } | @Override public ImmutableList<ObjectType> getTypes() { return TYPES; } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public ImmutableList<ObjectType> getTypes() { return TYPES; } } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public ImmutableList<ObjectType> getTypes() { return TYPES; } @Autowired OrgAttributeNotChangedValidator(final Maintainers maintainers); } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public ImmutableList<ObjectType> getTypes() { return TYPES; } @Autowired OrgAttributeNotChangedValidator(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public ImmutableList<ObjectType> getTypes() { return TYPES; } @Autowired OrgAttributeNotChangedValidator(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void validate_org_attribute_not_changed_for_aut_num() { final RpslObject rpslObject = RpslObject.parse("" + "aut-num: AS123\n" + "org: ORG-RT-TEST\n" + "mnt-by: TEST-MNT"); when(update.getReferenceObject()).thenReturn(rpslObject); when(update.getUpdatedObject()).thenReturn(rpslObject); subject.validate(update, updateContext); verify(updateContext, never()).addMessage(Matchers.<Update>anyObject(), Matchers.<Message>anyObject()); verify(updateContext, never()).addMessage(Matchers.<Update>anyObject(), Matchers.<RpslAttribute>anyObject(), Matchers.<Message>anyObject()); verifyZeroInteractions(maintainers); } | @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } @Autowired OrgAttributeNotChangedValidator(final Maintainers maintainers); } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } @Autowired OrgAttributeNotChangedValidator(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } @Autowired OrgAttributeNotChangedValidator(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void validate_org_attribute_not_changed_for_inetnum() { final RpslObject rpslObject = RpslObject.parse("" + "inetnum: 192.168.0.0 - 192.169.255.255\n" + "netname: TEST-NET-NAME\n" + "descr: TEST network\n" + "country: NL\n" + "org: ORG-LIR1-TEST\n" + "admin-c: TP1-TEST\n" + "tech-c: TP1-TEST\n" + "status: ALLOCATED PA\n" + "mnt-by: RIPE-NCC-HM-MNT\n" + "mnt-lower: LIR-MNT\n" + "source: TEST"); when(update.getReferenceObject()).thenReturn(rpslObject); when(update.getUpdatedObject()).thenReturn(rpslObject); subject.validate(update, updateContext); verify(updateContext, never()).addMessage(Matchers.<Update>anyObject(), Matchers.<Message>anyObject()); verify(updateContext, never()).addMessage(Matchers.<Update>anyObject(), Matchers.<RpslAttribute>anyObject(), Matchers.<Message>anyObject()); verifyZeroInteractions(maintainers); } | @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } @Autowired OrgAttributeNotChangedValidator(final Maintainers maintainers); } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } @Autowired OrgAttributeNotChangedValidator(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } @Autowired OrgAttributeNotChangedValidator(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void validate_org_attribute_not_changed_for_inet6num() { final RpslObject rpslObject = RpslObject.parse("" + "inet6num: 2001:600:1:1:1:1:1:1/64\n" + "netname: TEST-NET-NAME\n" + "descr: TEST network\n" + "country: NL\n" + "org: ORG-LIR1-TEST\n" + "admin-c: TP1-TEST\n" + "tech-c: TP1-TEST\n" + "status: ALLOCATED PA\n" + "mnt-by: RIPE-NCC-HM-MNT\n" + "mnt-lower: LIR-MNT\n" + "source: TEST"); when(update.getReferenceObject()).thenReturn(rpslObject); when(update.getUpdatedObject()).thenReturn(rpslObject); subject.validate(update, updateContext); verify(updateContext, never()).addMessage(Matchers.<Update>anyObject(), Matchers.<Message>anyObject()); verify(updateContext, never()).addMessage(Matchers.<Update>anyObject(), Matchers.<RpslAttribute>anyObject(), Matchers.<Message>anyObject()); verifyZeroInteractions(maintainers); } | @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } @Autowired OrgAttributeNotChangedValidator(final Maintainers maintainers); } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } @Autowired OrgAttributeNotChangedValidator(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } @Autowired OrgAttributeNotChangedValidator(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void transform_route6_uppercase() { final RpslObject rpslObject = RpslObject.parse("" + "route6: 2001:6F8::/32\n" + "origin: AS12321"); final RpslObject result = attributeSanitizer.sanitize(rpslObject, objectMessages); assertThat(result.getValueForAttribute(AttributeType.ROUTE6).toString(), is("2001:6f8::/32")); verify(objectMessages).addMessage(result.findAttribute(AttributeType.ROUTE6), ValidationMessages.attributeValueConverted("2001:6F8::/32", "2001:6f8::/32")); verifyNoMoreInteractions(objectMessages); } | public RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages) { final Map<RpslAttribute, RpslAttribute> replacements = Maps.newHashMap(); for (final RpslAttribute attribute : object.getAttributes()) { final AttributeType type = attribute.getType(); String newValue = null; final Sanitizer sanitizer = SANITIZER_MAP.get(type); if (sanitizer == null) { continue; } try { newValue = sanitizer.sanitize(attribute); } catch (IllegalArgumentException ignored) { LOGGER.debug("{}: {}", ignored.getClass().getName(), ignored.getMessage()); } if (newValue == null) { continue; } final List<Message> attributeMessages = Lists.newArrayList(); if (!sanitizer.silent() && !attribute.getCleanValue().toString().equals(newValue)) { attributeMessages.add(ValidationMessages.attributeValueConverted(attribute.getCleanValue(), newValue)); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('\n') != -1) { attributeMessages.add(ValidationMessages.continuationLinesRemoved()); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('#') != -1) { attributeMessages.add(ValidationMessages.remarksReformatted()); } final String replacement = newValue + getCommentReplacement(attribute); final RpslAttribute transformed = new RpslAttribute(attribute.getKey(), replacement); replacements.put(attribute, transformed); for (final Message attributeMessage : attributeMessages) { objectMessages.addMessage(transformed, attributeMessage); } } return new RpslObjectBuilder(object).replaceAttributes(replacements).get(); } | AttributeSanitizer { public RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages) { final Map<RpslAttribute, RpslAttribute> replacements = Maps.newHashMap(); for (final RpslAttribute attribute : object.getAttributes()) { final AttributeType type = attribute.getType(); String newValue = null; final Sanitizer sanitizer = SANITIZER_MAP.get(type); if (sanitizer == null) { continue; } try { newValue = sanitizer.sanitize(attribute); } catch (IllegalArgumentException ignored) { LOGGER.debug("{}: {}", ignored.getClass().getName(), ignored.getMessage()); } if (newValue == null) { continue; } final List<Message> attributeMessages = Lists.newArrayList(); if (!sanitizer.silent() && !attribute.getCleanValue().toString().equals(newValue)) { attributeMessages.add(ValidationMessages.attributeValueConverted(attribute.getCleanValue(), newValue)); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('\n') != -1) { attributeMessages.add(ValidationMessages.continuationLinesRemoved()); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('#') != -1) { attributeMessages.add(ValidationMessages.remarksReformatted()); } final String replacement = newValue + getCommentReplacement(attribute); final RpslAttribute transformed = new RpslAttribute(attribute.getKey(), replacement); replacements.put(attribute, transformed); for (final Message attributeMessage : attributeMessages) { objectMessages.addMessage(transformed, attributeMessage); } } return new RpslObjectBuilder(object).replaceAttributes(replacements).get(); } } | AttributeSanitizer { public RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages) { final Map<RpslAttribute, RpslAttribute> replacements = Maps.newHashMap(); for (final RpslAttribute attribute : object.getAttributes()) { final AttributeType type = attribute.getType(); String newValue = null; final Sanitizer sanitizer = SANITIZER_MAP.get(type); if (sanitizer == null) { continue; } try { newValue = sanitizer.sanitize(attribute); } catch (IllegalArgumentException ignored) { LOGGER.debug("{}: {}", ignored.getClass().getName(), ignored.getMessage()); } if (newValue == null) { continue; } final List<Message> attributeMessages = Lists.newArrayList(); if (!sanitizer.silent() && !attribute.getCleanValue().toString().equals(newValue)) { attributeMessages.add(ValidationMessages.attributeValueConverted(attribute.getCleanValue(), newValue)); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('\n') != -1) { attributeMessages.add(ValidationMessages.continuationLinesRemoved()); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('#') != -1) { attributeMessages.add(ValidationMessages.remarksReformatted()); } final String replacement = newValue + getCommentReplacement(attribute); final RpslAttribute transformed = new RpslAttribute(attribute.getKey(), replacement); replacements.put(attribute, transformed); for (final Message attributeMessage : attributeMessages) { objectMessages.addMessage(transformed, attributeMessage); } } return new RpslObjectBuilder(object).replaceAttributes(replacements).get(); } @Autowired AttributeSanitizer(DateTimeProvider dateTimeProvider); } | AttributeSanitizer { public RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages) { final Map<RpslAttribute, RpslAttribute> replacements = Maps.newHashMap(); for (final RpslAttribute attribute : object.getAttributes()) { final AttributeType type = attribute.getType(); String newValue = null; final Sanitizer sanitizer = SANITIZER_MAP.get(type); if (sanitizer == null) { continue; } try { newValue = sanitizer.sanitize(attribute); } catch (IllegalArgumentException ignored) { LOGGER.debug("{}: {}", ignored.getClass().getName(), ignored.getMessage()); } if (newValue == null) { continue; } final List<Message> attributeMessages = Lists.newArrayList(); if (!sanitizer.silent() && !attribute.getCleanValue().toString().equals(newValue)) { attributeMessages.add(ValidationMessages.attributeValueConverted(attribute.getCleanValue(), newValue)); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('\n') != -1) { attributeMessages.add(ValidationMessages.continuationLinesRemoved()); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('#') != -1) { attributeMessages.add(ValidationMessages.remarksReformatted()); } final String replacement = newValue + getCommentReplacement(attribute); final RpslAttribute transformed = new RpslAttribute(attribute.getKey(), replacement); replacements.put(attribute, transformed); for (final Message attributeMessage : attributeMessages) { objectMessages.addMessage(transformed, attributeMessage); } } return new RpslObjectBuilder(object).replaceAttributes(replacements).get(); } @Autowired AttributeSanitizer(DateTimeProvider dateTimeProvider); CIString sanitizeKey(final RpslObject originalObject); RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages); } | AttributeSanitizer { public RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages) { final Map<RpslAttribute, RpslAttribute> replacements = Maps.newHashMap(); for (final RpslAttribute attribute : object.getAttributes()) { final AttributeType type = attribute.getType(); String newValue = null; final Sanitizer sanitizer = SANITIZER_MAP.get(type); if (sanitizer == null) { continue; } try { newValue = sanitizer.sanitize(attribute); } catch (IllegalArgumentException ignored) { LOGGER.debug("{}: {}", ignored.getClass().getName(), ignored.getMessage()); } if (newValue == null) { continue; } final List<Message> attributeMessages = Lists.newArrayList(); if (!sanitizer.silent() && !attribute.getCleanValue().toString().equals(newValue)) { attributeMessages.add(ValidationMessages.attributeValueConverted(attribute.getCleanValue(), newValue)); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('\n') != -1) { attributeMessages.add(ValidationMessages.continuationLinesRemoved()); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('#') != -1) { attributeMessages.add(ValidationMessages.remarksReformatted()); } final String replacement = newValue + getCommentReplacement(attribute); final RpslAttribute transformed = new RpslAttribute(attribute.getKey(), replacement); replacements.put(attribute, transformed); for (final Message attributeMessage : attributeMessages) { objectMessages.addMessage(transformed, attributeMessage); } } return new RpslObjectBuilder(object).replaceAttributes(replacements).get(); } @Autowired AttributeSanitizer(DateTimeProvider dateTimeProvider); CIString sanitizeKey(final RpslObject originalObject); RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages); } |
@Test public void isLastSerialFile_created() throws IOException { subject.createExportFileWriters(folder.getRoot(), LAST_SERIAL); final File currentSerialFile = new File(folder.getRoot(), "dbase/RIPE.CURRENTSERIAL"); assertThat(currentSerialFile.exists(), Matchers.is(true)); final String savedSerial = new String(FileCopyUtils.copyToByteArray(currentSerialFile), StandardCharsets.ISO_8859_1); assertThat(savedSerial, Matchers.is(String.valueOf(LAST_SERIAL))); final File newSerialFile = new File(folder.getRoot(), "dbase_new/RIPE.CURRENTSERIAL"); assertThat(newSerialFile.exists(), Matchers.is(true)); final String newSavedSerial = new String(FileCopyUtils.copyToByteArray(currentSerialFile), StandardCharsets.ISO_8859_1); assertThat(newSavedSerial, Matchers.is(String.valueOf(LAST_SERIAL))); } | public List<ExportFileWriter> createExportFileWriters(final File baseDir, final int lastSerial) { final File fullDir = new File(baseDir, legacyExternalExportDir); final File fullDirNew = new File(baseDir, externalExportDir); final File splitDir = new File(baseDir, legacyExternalExportDir + File.separator + SPLITFILE_FOLDERNAME); final File splitDirNew = new File(baseDir, externalExportDir + File.separator + SPLITFILE_FOLDERNAME); final File internalDir = new File(baseDir, internalExportDir + File.separator + SPLITFILE_FOLDERNAME); initDirs(fullDirNew, fullDir, splitDirNew, splitDir, internalDir); try { FileCopyUtils.copy(String.valueOf(lastSerial).getBytes(StandardCharsets.ISO_8859_1), new File(fullDirNew, CURRENTSERIAL_FILENAME)); FileCopyUtils.copy(String.valueOf(lastSerial).getBytes(StandardCharsets.ISO_8859_1), new File(fullDir, CURRENTSERIAL_FILENAME)); FileCopyUtils.copy(String.valueOf(lastSerial).getBytes(StandardCharsets.ISO_8859_1), new File(fullDirNew, CURRENTSERIAL_NONAUTH_FILENAME)); FileCopyUtils.copy(String.valueOf(lastSerial).getBytes(StandardCharsets.ISO_8859_1), new File(fullDir, CURRENTSERIAL_NONAUTH_FILENAME)); } catch (IOException e) { throw new RuntimeException("Writing current serial", e); } final FilenameStrategy singleFile = new FilenameStrategy.SingleFile(); final FilenameStrategy splitFile = new FilenameStrategy.SplitFile(); final FilenameStrategy nonAuthSingleFile = new FilenameStrategy.NonAuthSingleFile(); final FilenameStrategy nonAuthSplitFile = new FilenameStrategy.NonAuthSplitFile(); final ExportFilter sourceFilter = new ExportFilter.SourceExportFilter(source, ImmutableSet.copyOf(ObjectType.values())); final ExportFilter nonAuthSourceFilter = new ExportFilter.SourceExportFilter(nonAuthSource, Sets.immutableEnumSet(AUT_NUM, ROUTE, ROUTE6), false); return Lists.newArrayList( new ExportFileWriter(fullDir, singleFile, new DecorationStrategy.DummifyLegacy(dummifierNrtm), sourceFilter), new ExportFileWriter(splitDir, splitFile, new DecorationStrategy.DummifyLegacy(dummifierNrtm), sourceFilter), new ExportFileWriter(fullDirNew, singleFile, new DecorationStrategy.DummifyCurrent(dummifierCurrent), sourceFilter), new ExportFileWriter(splitDirNew, splitFile, new DecorationStrategy.DummifyCurrent(dummifierCurrent), sourceFilter), new ExportFileWriter(internalDir, splitFile, new DecorationStrategy.None(), sourceFilter), new ExportFileWriter(fullDir, nonAuthSingleFile, new DecorationStrategy.DummifyLegacy(dummifierNrtm), nonAuthSourceFilter), new ExportFileWriter(splitDir, nonAuthSplitFile, new DecorationStrategy.DummifyLegacy(dummifierNrtm), nonAuthSourceFilter), new ExportFileWriter(fullDirNew, nonAuthSingleFile, new DecorationStrategy.DummifyCurrent(dummifierCurrent), nonAuthSourceFilter), new ExportFileWriter(splitDirNew, nonAuthSplitFile, new DecorationStrategy.DummifyCurrent(dummifierCurrent), nonAuthSourceFilter), new ExportFileWriter(internalDir, nonAuthSplitFile, new DecorationStrategy.None(), nonAuthSourceFilter) ); } | ExportFileWriterFactory { public List<ExportFileWriter> createExportFileWriters(final File baseDir, final int lastSerial) { final File fullDir = new File(baseDir, legacyExternalExportDir); final File fullDirNew = new File(baseDir, externalExportDir); final File splitDir = new File(baseDir, legacyExternalExportDir + File.separator + SPLITFILE_FOLDERNAME); final File splitDirNew = new File(baseDir, externalExportDir + File.separator + SPLITFILE_FOLDERNAME); final File internalDir = new File(baseDir, internalExportDir + File.separator + SPLITFILE_FOLDERNAME); initDirs(fullDirNew, fullDir, splitDirNew, splitDir, internalDir); try { FileCopyUtils.copy(String.valueOf(lastSerial).getBytes(StandardCharsets.ISO_8859_1), new File(fullDirNew, CURRENTSERIAL_FILENAME)); FileCopyUtils.copy(String.valueOf(lastSerial).getBytes(StandardCharsets.ISO_8859_1), new File(fullDir, CURRENTSERIAL_FILENAME)); FileCopyUtils.copy(String.valueOf(lastSerial).getBytes(StandardCharsets.ISO_8859_1), new File(fullDirNew, CURRENTSERIAL_NONAUTH_FILENAME)); FileCopyUtils.copy(String.valueOf(lastSerial).getBytes(StandardCharsets.ISO_8859_1), new File(fullDir, CURRENTSERIAL_NONAUTH_FILENAME)); } catch (IOException e) { throw new RuntimeException("Writing current serial", e); } final FilenameStrategy singleFile = new FilenameStrategy.SingleFile(); final FilenameStrategy splitFile = new FilenameStrategy.SplitFile(); final FilenameStrategy nonAuthSingleFile = new FilenameStrategy.NonAuthSingleFile(); final FilenameStrategy nonAuthSplitFile = new FilenameStrategy.NonAuthSplitFile(); final ExportFilter sourceFilter = new ExportFilter.SourceExportFilter(source, ImmutableSet.copyOf(ObjectType.values())); final ExportFilter nonAuthSourceFilter = new ExportFilter.SourceExportFilter(nonAuthSource, Sets.immutableEnumSet(AUT_NUM, ROUTE, ROUTE6), false); return Lists.newArrayList( new ExportFileWriter(fullDir, singleFile, new DecorationStrategy.DummifyLegacy(dummifierNrtm), sourceFilter), new ExportFileWriter(splitDir, splitFile, new DecorationStrategy.DummifyLegacy(dummifierNrtm), sourceFilter), new ExportFileWriter(fullDirNew, singleFile, new DecorationStrategy.DummifyCurrent(dummifierCurrent), sourceFilter), new ExportFileWriter(splitDirNew, splitFile, new DecorationStrategy.DummifyCurrent(dummifierCurrent), sourceFilter), new ExportFileWriter(internalDir, splitFile, new DecorationStrategy.None(), sourceFilter), new ExportFileWriter(fullDir, nonAuthSingleFile, new DecorationStrategy.DummifyLegacy(dummifierNrtm), nonAuthSourceFilter), new ExportFileWriter(splitDir, nonAuthSplitFile, new DecorationStrategy.DummifyLegacy(dummifierNrtm), nonAuthSourceFilter), new ExportFileWriter(fullDirNew, nonAuthSingleFile, new DecorationStrategy.DummifyCurrent(dummifierCurrent), nonAuthSourceFilter), new ExportFileWriter(splitDirNew, nonAuthSplitFile, new DecorationStrategy.DummifyCurrent(dummifierCurrent), nonAuthSourceFilter), new ExportFileWriter(internalDir, nonAuthSplitFile, new DecorationStrategy.None(), nonAuthSourceFilter) ); } } | ExportFileWriterFactory { public List<ExportFileWriter> createExportFileWriters(final File baseDir, final int lastSerial) { final File fullDir = new File(baseDir, legacyExternalExportDir); final File fullDirNew = new File(baseDir, externalExportDir); final File splitDir = new File(baseDir, legacyExternalExportDir + File.separator + SPLITFILE_FOLDERNAME); final File splitDirNew = new File(baseDir, externalExportDir + File.separator + SPLITFILE_FOLDERNAME); final File internalDir = new File(baseDir, internalExportDir + File.separator + SPLITFILE_FOLDERNAME); initDirs(fullDirNew, fullDir, splitDirNew, splitDir, internalDir); try { FileCopyUtils.copy(String.valueOf(lastSerial).getBytes(StandardCharsets.ISO_8859_1), new File(fullDirNew, CURRENTSERIAL_FILENAME)); FileCopyUtils.copy(String.valueOf(lastSerial).getBytes(StandardCharsets.ISO_8859_1), new File(fullDir, CURRENTSERIAL_FILENAME)); FileCopyUtils.copy(String.valueOf(lastSerial).getBytes(StandardCharsets.ISO_8859_1), new File(fullDirNew, CURRENTSERIAL_NONAUTH_FILENAME)); FileCopyUtils.copy(String.valueOf(lastSerial).getBytes(StandardCharsets.ISO_8859_1), new File(fullDir, CURRENTSERIAL_NONAUTH_FILENAME)); } catch (IOException e) { throw new RuntimeException("Writing current serial", e); } final FilenameStrategy singleFile = new FilenameStrategy.SingleFile(); final FilenameStrategy splitFile = new FilenameStrategy.SplitFile(); final FilenameStrategy nonAuthSingleFile = new FilenameStrategy.NonAuthSingleFile(); final FilenameStrategy nonAuthSplitFile = new FilenameStrategy.NonAuthSplitFile(); final ExportFilter sourceFilter = new ExportFilter.SourceExportFilter(source, ImmutableSet.copyOf(ObjectType.values())); final ExportFilter nonAuthSourceFilter = new ExportFilter.SourceExportFilter(nonAuthSource, Sets.immutableEnumSet(AUT_NUM, ROUTE, ROUTE6), false); return Lists.newArrayList( new ExportFileWriter(fullDir, singleFile, new DecorationStrategy.DummifyLegacy(dummifierNrtm), sourceFilter), new ExportFileWriter(splitDir, splitFile, new DecorationStrategy.DummifyLegacy(dummifierNrtm), sourceFilter), new ExportFileWriter(fullDirNew, singleFile, new DecorationStrategy.DummifyCurrent(dummifierCurrent), sourceFilter), new ExportFileWriter(splitDirNew, splitFile, new DecorationStrategy.DummifyCurrent(dummifierCurrent), sourceFilter), new ExportFileWriter(internalDir, splitFile, new DecorationStrategy.None(), sourceFilter), new ExportFileWriter(fullDir, nonAuthSingleFile, new DecorationStrategy.DummifyLegacy(dummifierNrtm), nonAuthSourceFilter), new ExportFileWriter(splitDir, nonAuthSplitFile, new DecorationStrategy.DummifyLegacy(dummifierNrtm), nonAuthSourceFilter), new ExportFileWriter(fullDirNew, nonAuthSingleFile, new DecorationStrategy.DummifyCurrent(dummifierCurrent), nonAuthSourceFilter), new ExportFileWriter(splitDirNew, nonAuthSplitFile, new DecorationStrategy.DummifyCurrent(dummifierCurrent), nonAuthSourceFilter), new ExportFileWriter(internalDir, nonAuthSplitFile, new DecorationStrategy.None(), nonAuthSourceFilter) ); } @Autowired ExportFileWriterFactory(final DummifierNrtm dummifierNrtm, final DummifierCurrent dummifierCurrent,
@Value("${dir.rpsl.export.internal}") final String internalExportDir,
@Value("${dir.rpsl.export.external}") final String externalExportDir,
@Value("${dir.rpsl.export.external.legacy}") final String legacyExternalExportDir,
@Value("${whois.source}") final String source,
@Value("${whois.nonauth.source}") final String nonAuthSource); } | ExportFileWriterFactory { public List<ExportFileWriter> createExportFileWriters(final File baseDir, final int lastSerial) { final File fullDir = new File(baseDir, legacyExternalExportDir); final File fullDirNew = new File(baseDir, externalExportDir); final File splitDir = new File(baseDir, legacyExternalExportDir + File.separator + SPLITFILE_FOLDERNAME); final File splitDirNew = new File(baseDir, externalExportDir + File.separator + SPLITFILE_FOLDERNAME); final File internalDir = new File(baseDir, internalExportDir + File.separator + SPLITFILE_FOLDERNAME); initDirs(fullDirNew, fullDir, splitDirNew, splitDir, internalDir); try { FileCopyUtils.copy(String.valueOf(lastSerial).getBytes(StandardCharsets.ISO_8859_1), new File(fullDirNew, CURRENTSERIAL_FILENAME)); FileCopyUtils.copy(String.valueOf(lastSerial).getBytes(StandardCharsets.ISO_8859_1), new File(fullDir, CURRENTSERIAL_FILENAME)); FileCopyUtils.copy(String.valueOf(lastSerial).getBytes(StandardCharsets.ISO_8859_1), new File(fullDirNew, CURRENTSERIAL_NONAUTH_FILENAME)); FileCopyUtils.copy(String.valueOf(lastSerial).getBytes(StandardCharsets.ISO_8859_1), new File(fullDir, CURRENTSERIAL_NONAUTH_FILENAME)); } catch (IOException e) { throw new RuntimeException("Writing current serial", e); } final FilenameStrategy singleFile = new FilenameStrategy.SingleFile(); final FilenameStrategy splitFile = new FilenameStrategy.SplitFile(); final FilenameStrategy nonAuthSingleFile = new FilenameStrategy.NonAuthSingleFile(); final FilenameStrategy nonAuthSplitFile = new FilenameStrategy.NonAuthSplitFile(); final ExportFilter sourceFilter = new ExportFilter.SourceExportFilter(source, ImmutableSet.copyOf(ObjectType.values())); final ExportFilter nonAuthSourceFilter = new ExportFilter.SourceExportFilter(nonAuthSource, Sets.immutableEnumSet(AUT_NUM, ROUTE, ROUTE6), false); return Lists.newArrayList( new ExportFileWriter(fullDir, singleFile, new DecorationStrategy.DummifyLegacy(dummifierNrtm), sourceFilter), new ExportFileWriter(splitDir, splitFile, new DecorationStrategy.DummifyLegacy(dummifierNrtm), sourceFilter), new ExportFileWriter(fullDirNew, singleFile, new DecorationStrategy.DummifyCurrent(dummifierCurrent), sourceFilter), new ExportFileWriter(splitDirNew, splitFile, new DecorationStrategy.DummifyCurrent(dummifierCurrent), sourceFilter), new ExportFileWriter(internalDir, splitFile, new DecorationStrategy.None(), sourceFilter), new ExportFileWriter(fullDir, nonAuthSingleFile, new DecorationStrategy.DummifyLegacy(dummifierNrtm), nonAuthSourceFilter), new ExportFileWriter(splitDir, nonAuthSplitFile, new DecorationStrategy.DummifyLegacy(dummifierNrtm), nonAuthSourceFilter), new ExportFileWriter(fullDirNew, nonAuthSingleFile, new DecorationStrategy.DummifyCurrent(dummifierCurrent), nonAuthSourceFilter), new ExportFileWriter(splitDirNew, nonAuthSplitFile, new DecorationStrategy.DummifyCurrent(dummifierCurrent), nonAuthSourceFilter), new ExportFileWriter(internalDir, nonAuthSplitFile, new DecorationStrategy.None(), nonAuthSourceFilter) ); } @Autowired ExportFileWriterFactory(final DummifierNrtm dummifierNrtm, final DummifierCurrent dummifierCurrent,
@Value("${dir.rpsl.export.internal}") final String internalExportDir,
@Value("${dir.rpsl.export.external}") final String externalExportDir,
@Value("${dir.rpsl.export.external.legacy}") final String legacyExternalExportDir,
@Value("${whois.source}") final String source,
@Value("${whois.nonauth.source}") final String nonAuthSource); List<ExportFileWriter> createExportFileWriters(final File baseDir, final int lastSerial); boolean isExportDir(final File dir); } | ExportFileWriterFactory { public List<ExportFileWriter> createExportFileWriters(final File baseDir, final int lastSerial) { final File fullDir = new File(baseDir, legacyExternalExportDir); final File fullDirNew = new File(baseDir, externalExportDir); final File splitDir = new File(baseDir, legacyExternalExportDir + File.separator + SPLITFILE_FOLDERNAME); final File splitDirNew = new File(baseDir, externalExportDir + File.separator + SPLITFILE_FOLDERNAME); final File internalDir = new File(baseDir, internalExportDir + File.separator + SPLITFILE_FOLDERNAME); initDirs(fullDirNew, fullDir, splitDirNew, splitDir, internalDir); try { FileCopyUtils.copy(String.valueOf(lastSerial).getBytes(StandardCharsets.ISO_8859_1), new File(fullDirNew, CURRENTSERIAL_FILENAME)); FileCopyUtils.copy(String.valueOf(lastSerial).getBytes(StandardCharsets.ISO_8859_1), new File(fullDir, CURRENTSERIAL_FILENAME)); FileCopyUtils.copy(String.valueOf(lastSerial).getBytes(StandardCharsets.ISO_8859_1), new File(fullDirNew, CURRENTSERIAL_NONAUTH_FILENAME)); FileCopyUtils.copy(String.valueOf(lastSerial).getBytes(StandardCharsets.ISO_8859_1), new File(fullDir, CURRENTSERIAL_NONAUTH_FILENAME)); } catch (IOException e) { throw new RuntimeException("Writing current serial", e); } final FilenameStrategy singleFile = new FilenameStrategy.SingleFile(); final FilenameStrategy splitFile = new FilenameStrategy.SplitFile(); final FilenameStrategy nonAuthSingleFile = new FilenameStrategy.NonAuthSingleFile(); final FilenameStrategy nonAuthSplitFile = new FilenameStrategy.NonAuthSplitFile(); final ExportFilter sourceFilter = new ExportFilter.SourceExportFilter(source, ImmutableSet.copyOf(ObjectType.values())); final ExportFilter nonAuthSourceFilter = new ExportFilter.SourceExportFilter(nonAuthSource, Sets.immutableEnumSet(AUT_NUM, ROUTE, ROUTE6), false); return Lists.newArrayList( new ExportFileWriter(fullDir, singleFile, new DecorationStrategy.DummifyLegacy(dummifierNrtm), sourceFilter), new ExportFileWriter(splitDir, splitFile, new DecorationStrategy.DummifyLegacy(dummifierNrtm), sourceFilter), new ExportFileWriter(fullDirNew, singleFile, new DecorationStrategy.DummifyCurrent(dummifierCurrent), sourceFilter), new ExportFileWriter(splitDirNew, splitFile, new DecorationStrategy.DummifyCurrent(dummifierCurrent), sourceFilter), new ExportFileWriter(internalDir, splitFile, new DecorationStrategy.None(), sourceFilter), new ExportFileWriter(fullDir, nonAuthSingleFile, new DecorationStrategy.DummifyLegacy(dummifierNrtm), nonAuthSourceFilter), new ExportFileWriter(splitDir, nonAuthSplitFile, new DecorationStrategy.DummifyLegacy(dummifierNrtm), nonAuthSourceFilter), new ExportFileWriter(fullDirNew, nonAuthSingleFile, new DecorationStrategy.DummifyCurrent(dummifierCurrent), nonAuthSourceFilter), new ExportFileWriter(splitDirNew, nonAuthSplitFile, new DecorationStrategy.DummifyCurrent(dummifierCurrent), nonAuthSourceFilter), new ExportFileWriter(internalDir, nonAuthSplitFile, new DecorationStrategy.None(), nonAuthSourceFilter) ); } @Autowired ExportFileWriterFactory(final DummifierNrtm dummifierNrtm, final DummifierCurrent dummifierCurrent,
@Value("${dir.rpsl.export.internal}") final String internalExportDir,
@Value("${dir.rpsl.export.external}") final String externalExportDir,
@Value("${dir.rpsl.export.external.legacy}") final String legacyExternalExportDir,
@Value("${whois.source}") final String source,
@Value("${whois.nonauth.source}") final String nonAuthSource); List<ExportFileWriter> createExportFileWriters(final File baseDir, final int lastSerial); boolean isExportDir(final File dir); } |
@Test public void validate_has_no_org_attribute_for_aut_num() { final RpslObject rpslObject = RpslObject.parse("" + "aut-num: AS123\n" + "mnt-by: TEST-MNT"); when(update.getReferenceObject()).thenReturn(rpslObject); when(update.getUpdatedObject()).thenReturn(rpslObject); subject.validate(update, updateContext); verify(updateContext, never()).addMessage(Matchers.<Update>anyObject(), Matchers.<Message>anyObject()); verify(updateContext, never()).addMessage(Matchers.<Update>anyObject(), Matchers.<RpslAttribute>anyObject(), Matchers.<Message>anyObject()); verifyZeroInteractions(maintainers); } | @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } @Autowired OrgAttributeNotChangedValidator(final Maintainers maintainers); } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } @Autowired OrgAttributeNotChangedValidator(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } @Autowired OrgAttributeNotChangedValidator(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void validate_has_no_org_attribute_for_inetnum() { final RpslObject rpslObject = RpslObject.parse("" + "inetnum: 192.168.0.0 - 192.169.255.255\n" + "netname: TEST-NET-NAME\n" + "descr: TEST network\n" + "country: NL\n" + "admin-c: TP1-TEST\n" + "tech-c: TP1-TEST\n" + "status: ALLOCATED PA\n" + "mnt-by: RIPE-NCC-HM-MNT\n" + "mnt-lower: LIR-MNT\n" + "source: TEST"); when(update.getReferenceObject()).thenReturn(rpslObject); when(update.getUpdatedObject()).thenReturn(rpslObject); subject.validate(update, updateContext); verify(updateContext, never()).addMessage(Matchers.<Update>anyObject(), Matchers.<Message>anyObject()); verify(updateContext, never()).addMessage(Matchers.<Update>anyObject(), Matchers.<RpslAttribute>anyObject(), Matchers.<Message>anyObject()); verifyZeroInteractions(maintainers); } | @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } @Autowired OrgAttributeNotChangedValidator(final Maintainers maintainers); } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } @Autowired OrgAttributeNotChangedValidator(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } @Autowired OrgAttributeNotChangedValidator(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void validate_has_no_org_attribute_for_inet6num() { final RpslObject rpslObject = RpslObject.parse("" + "inet6num: 2001:600:1:1:1:1:1:1/64\n" + "netname: TEST-NET-NAME\n" + "descr: TEST network\n" + "country: NL\n" + "admin-c: TP1-TEST\n" + "tech-c: TP1-TEST\n" + "status: ALLOCATED PA\n" + "mnt-by: RIPE-NCC-HM-MNT\n" + "mnt-lower: LIR-MNT\n" + "source: TEST"); when(update.getReferenceObject()).thenReturn(rpslObject); when(update.getUpdatedObject()).thenReturn(rpslObject); subject.validate(update, updateContext); verify(updateContext, never()).addMessage(Matchers.<Update>anyObject(), Matchers.<Message>anyObject()); verify(updateContext, never()).addMessage(Matchers.<Update>anyObject(), Matchers.<RpslAttribute>anyObject(), Matchers.<Message>anyObject()); verifyZeroInteractions(maintainers); } | @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } @Autowired OrgAttributeNotChangedValidator(final Maintainers maintainers); } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } @Autowired OrgAttributeNotChangedValidator(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } @Autowired OrgAttributeNotChangedValidator(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void validate_resource_not_maintained_by_ripe_for_aut_num() { final RpslObject original = RpslObject.parse("" + "aut-num: AS123\n" + "org: ORG-RT-TEST\n" + "mnt-by: TEST-MNT"); when(update.getReferenceObject()).thenReturn(original); final RpslObject updated = RpslObject.parse("" + "aut-num: AS123\n" + "org: ORG-PQ-TEST\n" + "mnt-by: OTHER-MNT"); when(update.getUpdatedObject()).thenReturn(updated); when(update.isOverride()).thenReturn(Boolean.FALSE); when(updateContext.getSubject(update)).thenReturn(subjectObject); when(subjectObject.hasPrincipal(Principal.RS_MAINTAINER)).thenReturn(Boolean.FALSE); subject.validate(update, updateContext); verify(updateContext, never()).addMessage(Matchers.<Update>anyObject(), Matchers.<Message>anyObject()); verify(updateContext, never()).addMessage(Matchers.<Update>anyObject(), Matchers.<RpslAttribute>anyObject(), Matchers.<Message>anyObject()); verify(maintainers).isRsMaintainer(ciSet("TEST-MNT")); verifyNoMoreInteractions(maintainers); } | @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } @Autowired OrgAttributeNotChangedValidator(final Maintainers maintainers); } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } @Autowired OrgAttributeNotChangedValidator(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } @Autowired OrgAttributeNotChangedValidator(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void validate_resource_not_maintained_by_ripe_for_inetnum() { final RpslObject original = RpslObject.parse("" + "inetnum: 192.168.0.0 - 192.169.255.255\n" + "netname: TEST-NET-NAME\n" + "descr: TEST network\n" + "country: NL\n" + "org: ORG-LIR1-TEST\n" + "admin-c: TP1-TEST\n" + "tech-c: TP1-TEST\n" + "status: ALLOCATED PA\n" + "mnt-by: TEST-MNT\n" + "mnt-lower: LIR-MNT\n" + "source: TEST"); when(update.getReferenceObject()).thenReturn(original); final RpslObject updated = RpslObject.parse("" + "inetnum: 192.168.0.0 - 192.169.255.255\n" + "netname: TEST-NET-NAME\n" + "descr: TEST network\n" + "country: NL\n" + "org: ORG-LIR2-TEST\n" + "admin-c: TP1-TEST\n" + "tech-c: TP1-TEST\n" + "status: ALLOCATED PA\n" + "mnt-by: OTHER-MNT\n" + "mnt-lower: LIR-MNT\n" + "source: TEST"); when(update.getUpdatedObject()).thenReturn(updated); when(update.isOverride()).thenReturn(Boolean.FALSE); when(updateContext.getSubject(update)).thenReturn(subjectObject); when(subjectObject.hasPrincipal(Principal.RS_MAINTAINER)).thenReturn(Boolean.FALSE); subject.validate(update, updateContext); verify(updateContext, never()).addMessage(Matchers.<Update>anyObject(), Matchers.<Message>anyObject()); verify(updateContext, never()).addMessage(Matchers.<Update>anyObject(), Matchers.<RpslAttribute>anyObject(), Matchers.<Message>anyObject()); verify(maintainers).isRsMaintainer(ciSet("TEST-MNT")); verifyNoMoreInteractions(maintainers); } | @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } @Autowired OrgAttributeNotChangedValidator(final Maintainers maintainers); } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } @Autowired OrgAttributeNotChangedValidator(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } @Autowired OrgAttributeNotChangedValidator(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void validate_resource_not_maintained_by_ripe_for_inet6num() { final RpslObject original = RpslObject.parse("" + "inet6num: 2001:600:1:1:1:1:1:1/64\n" + "netname: TEST-NET-NAME\n" + "descr: TEST network\n" + "country: NL\n" + "org: ORG-LIR1-TEST\n" + "admin-c: TP1-TEST\n" + "tech-c: TP1-TEST\n" + "status: ALLOCATED PA\n" + "mnt-by: OTHER-MNT\n" + "mnt-lower: LIR-MNT\n" + "source: TEST"); when(update.getReferenceObject()).thenReturn(original); final RpslObject updated = RpslObject.parse("" + "inet6num: 2001:600:1:1:1:1:1:1/64\n" + "netname: TEST-NET-NAME\n" + "descr: TEST network\n" + "country: NL\n" + "org: ORG-LIR2-TEST\n" + "admin-c: TP1-TEST\n" + "tech-c: TP1-TEST\n" + "status: ALLOCATED PA\n" + "mnt-by: OTHER-MNT\n" + "mnt-lower: LIR-MNT\n" + "source: TEST"); when(update.getUpdatedObject()).thenReturn(updated); when(update.isOverride()).thenReturn(Boolean.FALSE); when(updateContext.getSubject(update)).thenReturn(subjectObject); when(subjectObject.hasPrincipal(Principal.RS_MAINTAINER)).thenReturn(Boolean.FALSE); subject.validate(update, updateContext); verify(updateContext, never()).addMessage(Matchers.<Update>anyObject(), Matchers.<Message>anyObject()); verify(updateContext, never()).addMessage(Matchers.<Update>anyObject(), Matchers.<RpslAttribute>anyObject(), Matchers.<Message>anyObject()); verify(maintainers).isRsMaintainer(ciSet("OTHER-MNT")); verifyNoMoreInteractions(maintainers); } | @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } @Autowired OrgAttributeNotChangedValidator(final Maintainers maintainers); } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } @Autowired OrgAttributeNotChangedValidator(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } @Autowired OrgAttributeNotChangedValidator(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void validate_modify_resource_maintained_by_ripe_auth_by_other_mnt_for_aut_num() { final RpslObject original = RpslObject.parse("" + "aut-num: AS123\n" + "org: ORG-RT-TEST\n" + "mnt-by: RIPE-NCC-HM-MNT"); when(update.getReferenceObject()).thenReturn(original); final RpslObject updated = RpslObject.parse("" + "aut-num: AS123\n" + "org: ORG-PQ-TEST\n" + "mnt-by: RIPE-NCC-HM-MNT"); when(update.getUpdatedObject()).thenReturn(updated); when(update.isOverride()).thenReturn(Boolean.FALSE); when(updateContext.getSubject(update)).thenReturn(subjectObject); when(subjectObject.hasPrincipal(Principal.RS_MAINTAINER)).thenReturn(Boolean.FALSE); subject.validate(update, updateContext); verify(updateContext, never()).addMessage(Matchers.<Update>anyObject(), Matchers.<Message>anyObject()); verify(updateContext).addMessage(update, updated.findAttribute(AttributeType.ORG), UpdateMessages.cantChangeOrgAttribute()); verify(maintainers).isRsMaintainer(ciSet("RIPE-NCC-HM-MNT")); verifyNoMoreInteractions(maintainers); } | @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } @Autowired OrgAttributeNotChangedValidator(final Maintainers maintainers); } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } @Autowired OrgAttributeNotChangedValidator(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } @Autowired OrgAttributeNotChangedValidator(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void validate_modify_resource_maintained_by_ripe_auth_by_other_mnt_for_inetnum() { final RpslObject original = RpslObject.parse("" + "inetnum: 192.168.0.0 - 192.169.255.255\n" + "netname: TEST-NET-NAME\n" + "descr: TEST network\n" + "country: NL\n" + "org: ORG-LIR1-TEST\n" + "admin-c: TP1-TEST\n" + "tech-c: TP1-TEST\n" + "status: ALLOCATED PA\n" + "mnt-by: RIPE-NCC-HM-MNT\n" + "mnt-by: TEST-MNT\n" + "source: TEST"); when(update.getReferenceObject()).thenReturn(original); final RpslObject updated = RpslObject.parse("" + "inetnum: 192.168.0.0 - 192.169.255.255\n" + "netname: TEST-NET-NAME\n" + "descr: TEST network\n" + "country: NL\n" + "org: ORG-LIR2-TEST\n" + "admin-c: TP1-TEST\n" + "tech-c: TP1-TEST\n" + "status: ALLOCATED PA\n" + "mnt-by: RIPE-NCC-HM-MNT\n" + "mnt-by: TEST-MNT\n" + "source: TEST"); when(update.getUpdatedObject()).thenReturn(updated); when(update.isOverride()).thenReturn(Boolean.FALSE); when(updateContext.getSubject(update)).thenReturn(subjectObject); when(subjectObject.hasPrincipal(Principal.RS_MAINTAINER)).thenReturn(Boolean.FALSE); subject.validate(update, updateContext); verify(updateContext, never()).addMessage(Matchers.<Update>anyObject(), Matchers.<Message>anyObject()); verify(updateContext).addMessage(update, updated.findAttribute(AttributeType.ORG), UpdateMessages.cantChangeOrgAttribute()); verify(maintainers).isRsMaintainer(ciSet("RIPE-NCC-HM-MNT", "TEST-MNT")); verifyNoMoreInteractions(maintainers); } | @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } @Autowired OrgAttributeNotChangedValidator(final Maintainers maintainers); } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } @Autowired OrgAttributeNotChangedValidator(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } @Autowired OrgAttributeNotChangedValidator(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void validate_modify_resource_maintained_by_ripe_auth_by_other_mnt_for_inet6num() { final RpslObject original = RpslObject.parse("" + "inetnum: 2001:600:1:1:1:1:1:1/64\n" + "netname: TEST-NET-NAME\n" + "descr: TEST network\n" + "country: NL\n" + "org: ORG-LIR1-TEST\n" + "admin-c: TP1-TEST\n" + "tech-c: TP1-TEST\n" + "status: ALLOCATED PA\n" + "mnt-by: RIPE-NCC-HM-MNT\n" + "mnt-by: TEST-MNT\n" + "source: TEST"); when(update.getReferenceObject()).thenReturn(original); final RpslObject updated = RpslObject.parse("" + "inetnum: 2001:600:1:1:1:1:1:1/64\n" + "netname: TEST-NET-NAME\n" + "descr: TEST network\n" + "country: NL\n" + "org: ORG-LIR2-TEST\n" + "admin-c: TP1-TEST\n" + "tech-c: TP1-TEST\n" + "status: ALLOCATED PA\n" + "mnt-by: RIPE-NCC-HM-MNT\n" + "mnt-by: TEST-MNT\n" + "source: TEST"); when(update.getUpdatedObject()).thenReturn(updated); when(update.isOverride()).thenReturn(Boolean.FALSE); when(updateContext.getSubject(update)).thenReturn(subjectObject); when(subjectObject.hasPrincipal(Principal.RS_MAINTAINER)).thenReturn(Boolean.FALSE); subject.validate(update, updateContext); verify(updateContext, never()).addMessage(Matchers.<Update>anyObject(), Matchers.<Message>anyObject()); verify(updateContext).addMessage(update, updated.findAttribute(AttributeType.ORG), UpdateMessages.cantChangeOrgAttribute()); verify(maintainers).isRsMaintainer(ciSet("RIPE-NCC-HM-MNT", "TEST-MNT")); verifyNoMoreInteractions(maintainers); } | @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } @Autowired OrgAttributeNotChangedValidator(final Maintainers maintainers); } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } @Autowired OrgAttributeNotChangedValidator(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } @Autowired OrgAttributeNotChangedValidator(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void validate_delete_resource_maintained_by_ripe_auth_by_other_mnt_for_aut_num() { final RpslObject original = RpslObject.parse("" + "aut-num: AS123\n" + "org: ORG-RT-TEST\n" + "mnt-by: RIPE-NCC-HM-MNT"); when(update.getReferenceObject()).thenReturn(original); final RpslObject updated = RpslObject.parse("" + "aut-num: AS123\n" + "mnt-by: RIPE-NCC-HM-MNT"); when(update.getUpdatedObject()).thenReturn(updated); when(update.isOverride()).thenReturn(Boolean.FALSE); when(updateContext.getSubject(update)).thenReturn(subjectObject); when(subjectObject.hasPrincipal(Principal.RS_MAINTAINER)).thenReturn(Boolean.FALSE); subject.validate(update, updateContext); verify(updateContext).addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); verify(updateContext, never()).addMessage(Matchers.<Update>anyObject(), Matchers.<RpslAttribute>anyObject(), Matchers.<Message>anyObject()); verify(maintainers).isRsMaintainer(ciSet("RIPE-NCC-HM-MNT")); verifyNoMoreInteractions(maintainers); } | @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } @Autowired OrgAttributeNotChangedValidator(final Maintainers maintainers); } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } @Autowired OrgAttributeNotChangedValidator(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } @Autowired OrgAttributeNotChangedValidator(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void transform_alias_no_dot() { final RpslObject rpslObject = RpslObject.parse("" + "inet-rtr: test.ripe.net\n" + "alias: alias.ripe.net"); final RpslObject result = attributeSanitizer.sanitize(rpslObject, objectMessages); assertThat(result.getValueForAttribute(AttributeType.ALIAS).toString(), is("alias.ripe.net")); verifyNoMoreInteractions(objectMessages); } | public RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages) { final Map<RpslAttribute, RpslAttribute> replacements = Maps.newHashMap(); for (final RpslAttribute attribute : object.getAttributes()) { final AttributeType type = attribute.getType(); String newValue = null; final Sanitizer sanitizer = SANITIZER_MAP.get(type); if (sanitizer == null) { continue; } try { newValue = sanitizer.sanitize(attribute); } catch (IllegalArgumentException ignored) { LOGGER.debug("{}: {}", ignored.getClass().getName(), ignored.getMessage()); } if (newValue == null) { continue; } final List<Message> attributeMessages = Lists.newArrayList(); if (!sanitizer.silent() && !attribute.getCleanValue().toString().equals(newValue)) { attributeMessages.add(ValidationMessages.attributeValueConverted(attribute.getCleanValue(), newValue)); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('\n') != -1) { attributeMessages.add(ValidationMessages.continuationLinesRemoved()); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('#') != -1) { attributeMessages.add(ValidationMessages.remarksReformatted()); } final String replacement = newValue + getCommentReplacement(attribute); final RpslAttribute transformed = new RpslAttribute(attribute.getKey(), replacement); replacements.put(attribute, transformed); for (final Message attributeMessage : attributeMessages) { objectMessages.addMessage(transformed, attributeMessage); } } return new RpslObjectBuilder(object).replaceAttributes(replacements).get(); } | AttributeSanitizer { public RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages) { final Map<RpslAttribute, RpslAttribute> replacements = Maps.newHashMap(); for (final RpslAttribute attribute : object.getAttributes()) { final AttributeType type = attribute.getType(); String newValue = null; final Sanitizer sanitizer = SANITIZER_MAP.get(type); if (sanitizer == null) { continue; } try { newValue = sanitizer.sanitize(attribute); } catch (IllegalArgumentException ignored) { LOGGER.debug("{}: {}", ignored.getClass().getName(), ignored.getMessage()); } if (newValue == null) { continue; } final List<Message> attributeMessages = Lists.newArrayList(); if (!sanitizer.silent() && !attribute.getCleanValue().toString().equals(newValue)) { attributeMessages.add(ValidationMessages.attributeValueConverted(attribute.getCleanValue(), newValue)); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('\n') != -1) { attributeMessages.add(ValidationMessages.continuationLinesRemoved()); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('#') != -1) { attributeMessages.add(ValidationMessages.remarksReformatted()); } final String replacement = newValue + getCommentReplacement(attribute); final RpslAttribute transformed = new RpslAttribute(attribute.getKey(), replacement); replacements.put(attribute, transformed); for (final Message attributeMessage : attributeMessages) { objectMessages.addMessage(transformed, attributeMessage); } } return new RpslObjectBuilder(object).replaceAttributes(replacements).get(); } } | AttributeSanitizer { public RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages) { final Map<RpslAttribute, RpslAttribute> replacements = Maps.newHashMap(); for (final RpslAttribute attribute : object.getAttributes()) { final AttributeType type = attribute.getType(); String newValue = null; final Sanitizer sanitizer = SANITIZER_MAP.get(type); if (sanitizer == null) { continue; } try { newValue = sanitizer.sanitize(attribute); } catch (IllegalArgumentException ignored) { LOGGER.debug("{}: {}", ignored.getClass().getName(), ignored.getMessage()); } if (newValue == null) { continue; } final List<Message> attributeMessages = Lists.newArrayList(); if (!sanitizer.silent() && !attribute.getCleanValue().toString().equals(newValue)) { attributeMessages.add(ValidationMessages.attributeValueConverted(attribute.getCleanValue(), newValue)); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('\n') != -1) { attributeMessages.add(ValidationMessages.continuationLinesRemoved()); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('#') != -1) { attributeMessages.add(ValidationMessages.remarksReformatted()); } final String replacement = newValue + getCommentReplacement(attribute); final RpslAttribute transformed = new RpslAttribute(attribute.getKey(), replacement); replacements.put(attribute, transformed); for (final Message attributeMessage : attributeMessages) { objectMessages.addMessage(transformed, attributeMessage); } } return new RpslObjectBuilder(object).replaceAttributes(replacements).get(); } @Autowired AttributeSanitizer(DateTimeProvider dateTimeProvider); } | AttributeSanitizer { public RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages) { final Map<RpslAttribute, RpslAttribute> replacements = Maps.newHashMap(); for (final RpslAttribute attribute : object.getAttributes()) { final AttributeType type = attribute.getType(); String newValue = null; final Sanitizer sanitizer = SANITIZER_MAP.get(type); if (sanitizer == null) { continue; } try { newValue = sanitizer.sanitize(attribute); } catch (IllegalArgumentException ignored) { LOGGER.debug("{}: {}", ignored.getClass().getName(), ignored.getMessage()); } if (newValue == null) { continue; } final List<Message> attributeMessages = Lists.newArrayList(); if (!sanitizer.silent() && !attribute.getCleanValue().toString().equals(newValue)) { attributeMessages.add(ValidationMessages.attributeValueConverted(attribute.getCleanValue(), newValue)); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('\n') != -1) { attributeMessages.add(ValidationMessages.continuationLinesRemoved()); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('#') != -1) { attributeMessages.add(ValidationMessages.remarksReformatted()); } final String replacement = newValue + getCommentReplacement(attribute); final RpslAttribute transformed = new RpslAttribute(attribute.getKey(), replacement); replacements.put(attribute, transformed); for (final Message attributeMessage : attributeMessages) { objectMessages.addMessage(transformed, attributeMessage); } } return new RpslObjectBuilder(object).replaceAttributes(replacements).get(); } @Autowired AttributeSanitizer(DateTimeProvider dateTimeProvider); CIString sanitizeKey(final RpslObject originalObject); RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages); } | AttributeSanitizer { public RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages) { final Map<RpslAttribute, RpslAttribute> replacements = Maps.newHashMap(); for (final RpslAttribute attribute : object.getAttributes()) { final AttributeType type = attribute.getType(); String newValue = null; final Sanitizer sanitizer = SANITIZER_MAP.get(type); if (sanitizer == null) { continue; } try { newValue = sanitizer.sanitize(attribute); } catch (IllegalArgumentException ignored) { LOGGER.debug("{}: {}", ignored.getClass().getName(), ignored.getMessage()); } if (newValue == null) { continue; } final List<Message> attributeMessages = Lists.newArrayList(); if (!sanitizer.silent() && !attribute.getCleanValue().toString().equals(newValue)) { attributeMessages.add(ValidationMessages.attributeValueConverted(attribute.getCleanValue(), newValue)); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('\n') != -1) { attributeMessages.add(ValidationMessages.continuationLinesRemoved()); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('#') != -1) { attributeMessages.add(ValidationMessages.remarksReformatted()); } final String replacement = newValue + getCommentReplacement(attribute); final RpslAttribute transformed = new RpslAttribute(attribute.getKey(), replacement); replacements.put(attribute, transformed); for (final Message attributeMessage : attributeMessages) { objectMessages.addMessage(transformed, attributeMessage); } } return new RpslObjectBuilder(object).replaceAttributes(replacements).get(); } @Autowired AttributeSanitizer(DateTimeProvider dateTimeProvider); CIString sanitizeKey(final RpslObject originalObject); RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages); } |
@Test public void validate_delete_resource_maintained_by_ripe_auth_by_other_mnt_for_inetnum() { final RpslObject original = RpslObject.parse("" + "inetnum: 192.168.0.0 - 192.169.255.255\n" + "netname: TEST-NET-NAME\n" + "descr: TEST network\n" + "country: NL\n" + "org: ORG-LIR1-TEST\n" + "admin-c: TP1-TEST\n" + "tech-c: TP1-TEST\n" + "status: ALLOCATED PA\n" + "mnt-by: RIPE-NCC-HM-MNT\n" + "mnt-by: TEST-MNT\n" + "source: TEST"); when(update.getReferenceObject()).thenReturn(original); final RpslObject updated = RpslObject.parse("" + "inetnum: 192.168.0.0 - 192.169.255.255\n" + "netname: TEST-NET-NAME\n" + "descr: TEST network\n" + "country: NL\n" + "admin-c: TP1-TEST\n" + "tech-c: TP1-TEST\n" + "status: ALLOCATED PA\n" + "mnt-by: RIPE-NCC-HM-MNT\n" + "mnt-by: TEST-MNT\n" + "source: TEST"); when(update.getUpdatedObject()).thenReturn(updated); when(update.isOverride()).thenReturn(Boolean.FALSE); when(updateContext.getSubject(update)).thenReturn(subjectObject); when(subjectObject.hasPrincipal(Principal.RS_MAINTAINER)).thenReturn(Boolean.FALSE); subject.validate(update, updateContext); verify(updateContext).addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); verify(updateContext, never()).addMessage(Matchers.<Update>anyObject(), Matchers.<RpslAttribute>anyObject(), Matchers.<Message>anyObject()); verify(maintainers).isRsMaintainer(ciSet("RIPE-NCC-HM-MNT", "TEST-MNT")); verifyNoMoreInteractions(maintainers); } | @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } @Autowired OrgAttributeNotChangedValidator(final Maintainers maintainers); } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } @Autowired OrgAttributeNotChangedValidator(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } @Autowired OrgAttributeNotChangedValidator(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void validate_delete_resource_maintained_by_ripe_auth_by_other_mnt_for_inet6num() { final RpslObject original = RpslObject.parse("" + "inetnum: 2001:600:1:1:1:1:1:1/64\n" + "netname: TEST-NET-NAME\n" + "descr: TEST network\n" + "country: NL\n" + "org: ORG-LIR1-TEST\n" + "admin-c: TP1-TEST\n" + "tech-c: TP1-TEST\n" + "status: ALLOCATED PA\n" + "mnt-by: RIPE-NCC-HM-MNT\n" + "mnt-by: TEST-MNT\n" + "source: TEST"); when(update.getReferenceObject()).thenReturn(original); final RpslObject updated = RpslObject.parse("" + "inetnum: 2001:600:1:1:1:1:1:1/64\n" + "netname: TEST-NET-NAME\n" + "descr: TEST network\n" + "country: NL\n" + "admin-c: TP1-TEST\n" + "tech-c: TP1-TEST\n" + "status: ALLOCATED PA\n" + "mnt-by: RIPE-NCC-HM-MNT\n" + "mnt-by: TEST-MNT\n" + "source: TEST"); when(update.getUpdatedObject()).thenReturn(updated); when(update.isOverride()).thenReturn(Boolean.FALSE); when(updateContext.getSubject(update)).thenReturn(subjectObject); when(subjectObject.hasPrincipal(Principal.RS_MAINTAINER)).thenReturn(Boolean.FALSE); subject.validate(update, updateContext); verify(updateContext).addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); verify(updateContext, never()).addMessage(Matchers.<Update>anyObject(), Matchers.<RpslAttribute>anyObject(), Matchers.<Message>anyObject()); verify(maintainers).isRsMaintainer(ciSet("RIPE-NCC-HM-MNT", "TEST-MNT")); verifyNoMoreInteractions(maintainers); } | @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } @Autowired OrgAttributeNotChangedValidator(final Maintainers maintainers); } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } @Autowired OrgAttributeNotChangedValidator(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } @Autowired OrgAttributeNotChangedValidator(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void validate_resource_maintained_by_ripe_for_aut_num() { when(subjectObject.hasPrincipal(Principal.RS_MAINTAINER)).thenReturn(Boolean.TRUE); when(updateContext.getSubject(update)).thenReturn(subjectObject); final RpslObject original = RpslObject.parse("" + "aut-num: AS123\n" + "org: ORG-RT-TEST\n" + "mnt-by: RIPE-NCC-HM-MNT"); when(update.getReferenceObject()).thenReturn(original); final RpslObject updated = RpslObject.parse("" + "aut-num: AS123\n" + "org: ORG-WG-TEST\n" + "mnt-by: RIPE-NCC-HM-MNT"); when(update.getUpdatedObject()).thenReturn(updated); when(update.isOverride()).thenReturn(Boolean.FALSE); subject.validate(update, updateContext); verify(updateContext, never()).addMessage(Matchers.<Update>anyObject(), Matchers.<Message>anyObject()); verify(updateContext, never()).addMessage(Matchers.<Update>anyObject(), Matchers.<RpslAttribute>anyObject(), Matchers.<Message>anyObject()); verify(maintainers).isRsMaintainer(ciSet("RIPE-NCC-HM-MNT")); verifyNoMoreInteractions(maintainers); } | @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } @Autowired OrgAttributeNotChangedValidator(final Maintainers maintainers); } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } @Autowired OrgAttributeNotChangedValidator(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } @Autowired OrgAttributeNotChangedValidator(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void validate_resource_maintained_by_ripe_for_inetnum() { when(subjectObject.hasPrincipal(Principal.RS_MAINTAINER)).thenReturn(Boolean.TRUE); when(updateContext.getSubject(update)).thenReturn(subjectObject); final RpslObject original = RpslObject.parse("" + "inetnum: 192.168.0.0 - 192.169.255.255\n" + "netname: TEST-NET-NAME\n" + "descr: TEST network\n" + "country: NL\n" + "org: ORG-LIR1-TEST\n" + "admin-c: TP1-TEST\n" + "tech-c: TP1-TEST\n" + "status: ALLOCATED PA\n" + "mnt-by: RIPE-NCC-HM-MNT\n" + "mnt-by: TEST-MNT\n" + "source: TEST"); when(update.getReferenceObject()).thenReturn(original); final RpslObject updated = RpslObject.parse("" + "inetnum: 192.168.0.0 - 192.169.255.255\n" + "netname: TEST-NET-NAME\n" + "descr: TEST network\n" + "country: NL\n" + "org: ORG-LIR2-TEST\n" + "admin-c: TP1-TEST\n" + "tech-c: TP1-TEST\n" + "status: ALLOCATED PA\n" + "mnt-by: RIPE-NCC-HM-MNT\n" + "mnt-by: TEST-MNT\n" + "source: TEST"); when(update.getUpdatedObject()).thenReturn(updated); when(update.isOverride()).thenReturn(Boolean.FALSE); subject.validate(update, updateContext); verify(updateContext, never()).addMessage(Matchers.<Update>anyObject(), Matchers.<Message>anyObject()); verify(updateContext, never()).addMessage(Matchers.<Update>anyObject(), Matchers.<RpslAttribute>anyObject(), Matchers.<Message>anyObject()); verify(maintainers).isRsMaintainer(ciSet("RIPE-NCC-HM-MNT", "TEST-MNT")); verifyNoMoreInteractions(maintainers); } | @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } @Autowired OrgAttributeNotChangedValidator(final Maintainers maintainers); } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } @Autowired OrgAttributeNotChangedValidator(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } @Autowired OrgAttributeNotChangedValidator(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void validate_resource_maintained_by_ripe_for_inet6num() { when(subjectObject.hasPrincipal(Principal.RS_MAINTAINER)).thenReturn(Boolean.TRUE); when(updateContext.getSubject(update)).thenReturn(subjectObject); final RpslObject original = RpslObject.parse("" + "inetnum: 2001:600:1:1:1:1:1:1/64\n" + "netname: TEST-NET-NAME\n" + "descr: TEST network\n" + "country: NL\n" + "org: ORG-LIR1-TEST\n" + "admin-c: TP1-TEST\n" + "tech-c: TP1-TEST\n" + "status: ALLOCATED PA\n" + "mnt-by: RIPE-NCC-HM-MNT\n" + "mnt-by: TEST-MNT\n" + "source: TEST"); when(update.getReferenceObject()).thenReturn(original); final RpslObject updated = RpslObject.parse("" + "inetnum: 2001:600:1:1:1:1:1:1/64\n" + "netname: TEST-NET-NAME\n" + "descr: TEST network\n" + "country: NL\n" + "org: ORG-LIR2-TEST\n" + "admin-c: TP1-TEST\n" + "tech-c: TP1-TEST\n" + "status: ALLOCATED PA\n" + "mnt-by: RIPE-NCC-HM-MNT\n" + "mnt-by: TEST-MNT\n" + "source: TEST"); when(update.getUpdatedObject()).thenReturn(updated); when(update.isOverride()).thenReturn(Boolean.FALSE); subject.validate(update, updateContext); verify(updateContext, never()).addMessage(Matchers.<Update>anyObject(), Matchers.<Message>anyObject()); verify(updateContext, never()).addMessage(Matchers.<Update>anyObject(), Matchers.<RpslAttribute>anyObject(), Matchers.<Message>anyObject()); verify(maintainers).isRsMaintainer(ciSet("RIPE-NCC-HM-MNT", "TEST-MNT")); verifyNoMoreInteractions(maintainers); } | @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } @Autowired OrgAttributeNotChangedValidator(final Maintainers maintainers); } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } @Autowired OrgAttributeNotChangedValidator(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } @Autowired OrgAttributeNotChangedValidator(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void validate_resource_not_maintained_by_ripe_override_for_aut_num() { when(subjectObject.hasPrincipal(Principal.RS_MAINTAINER)).thenReturn(false); when(subjectObject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)).thenReturn(true); when(updateContext.getSubject(update)).thenReturn(subjectObject); final RpslObject original = RpslObject.parse("" + "aut-num: AS123\n" + "org: ORG-RT-TEST\n" + "mnt-by: RIPE-NCC-END-MNT"); when(update.getReferenceObject()).thenReturn(original); final RpslObject updated = RpslObject.parse("" + "aut-num: AS123\n" + "org: ORG-WG-TEST\n" + "mnt-by: RIPE-NCC-END-MNT"); when(update.getUpdatedObject()).thenReturn(updated); subject.validate(update, updateContext); verify(updateContext, never()).addMessage(Matchers.<Update>anyObject(), Matchers.<Message>anyObject()); verify(updateContext, never()).addMessage(Matchers.<Update>anyObject(), Matchers.<RpslAttribute>anyObject(), Matchers.<Message>anyObject()); verify(maintainers).isRsMaintainer(ciSet("RIPE-NCC-END-MNT")); verifyNoMoreInteractions(maintainers); } | @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } @Autowired OrgAttributeNotChangedValidator(final Maintainers maintainers); } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } @Autowired OrgAttributeNotChangedValidator(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } @Autowired OrgAttributeNotChangedValidator(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void validate_resource_not_maintained_by_ripe_override_for_inetnum() { when(subjectObject.hasPrincipal(Principal.RS_MAINTAINER)).thenReturn(false); when(subjectObject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)).thenReturn(true); when(updateContext.getSubject(update)).thenReturn(subjectObject); final RpslObject original = RpslObject.parse("" + "inetnum: 192.168.0.0 - 192.169.255.255\n" + "netname: TEST-NET-NAME\n" + "descr: TEST network\n" + "country: NL\n" + "org: ORG-LIR1-TEST\n" + "admin-c: TP1-TEST\n" + "tech-c: TP1-TEST\n" + "status: ALLOCATED PA\n" + "mnt-by: TEST-MNT\n" + "source: TEST"); when(update.getReferenceObject()).thenReturn(original); final RpslObject updated = RpslObject.parse("" + "inetnum: 192.168.0.0 - 192.169.255.255\n" + "netname: TEST-NET-NAME\n" + "descr: TEST network\n" + "country: NL\n" + "org: ORG-LIR2-TEST\n" + "admin-c: TP1-TEST\n" + "tech-c: TP1-TEST\n" + "status: ALLOCATED PA\n" + "mnt-by: TEST-MNT\n" + "source: TEST"); when(update.getUpdatedObject()).thenReturn(updated); subject.validate(update, updateContext); verify(updateContext, never()).addMessage(Matchers.<Update>anyObject(), Matchers.<Message>anyObject()); verify(updateContext, never()).addMessage(Matchers.<Update>anyObject(), Matchers.<RpslAttribute>anyObject(), Matchers.<Message>anyObject()); verify(maintainers).isRsMaintainer(ciSet("TEST-MNT")); verifyNoMoreInteractions(maintainers); } | @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } @Autowired OrgAttributeNotChangedValidator(final Maintainers maintainers); } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } @Autowired OrgAttributeNotChangedValidator(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } @Autowired OrgAttributeNotChangedValidator(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void validate_resource_not_maintained_by_ripe_override_for_inet6num() { when(subjectObject.hasPrincipal(Principal.RS_MAINTAINER)).thenReturn(false); when(subjectObject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)).thenReturn(true); when(updateContext.getSubject(update)).thenReturn(subjectObject); final RpslObject original = RpslObject.parse("" + "inetnum: 2001:600:1:1:1:1:1:1/64\n" + "netname: TEST-NET-NAME\n" + "descr: TEST network\n" + "country: NL\n" + "org: ORG-LIR1-TEST\n" + "admin-c: TP1-TEST\n" + "tech-c: TP1-TEST\n" + "status: ALLOCATED PA\n" + "mnt-by: TEST-MNT\n" + "source: TEST"); when(update.getReferenceObject()).thenReturn(original); final RpslObject updated = RpslObject.parse("" + "inetnum: 2001:600:1:1:1:1:1:1/64\n" + "netname: TEST-NET-NAME\n" + "descr: TEST network\n" + "country: NL\n" + "org: ORG-LIR2-TEST\n" + "admin-c: TP1-TEST\n" + "tech-c: TP1-TEST\n" + "status: ALLOCATED PA\n" + "mnt-by: TEST-MNT\n" + "source: TEST"); when(update.getUpdatedObject()).thenReturn(updated); subject.validate(update, updateContext); verify(updateContext, never()).addMessage(Matchers.<Update>anyObject(), Matchers.<Message>anyObject()); verify(updateContext, never()).addMessage(Matchers.<Update>anyObject(), Matchers.<RpslAttribute>anyObject(), Matchers.<Message>anyObject()); verify(maintainers).isRsMaintainer(ciSet("TEST-MNT")); verifyNoMoreInteractions(maintainers); } | @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } @Autowired OrgAttributeNotChangedValidator(final Maintainers maintainers); } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } @Autowired OrgAttributeNotChangedValidator(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | OrgAttributeNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final CIString originalOrg = originalObject.getValueOrNullForAttribute(AttributeType.ORG); final CIString updatedOrg = update.getUpdatedObject().getValueOrNullForAttribute(AttributeType.ORG); if (Objects.equals(originalOrg, updatedOrg)) { return; } boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); final Subject subject = updateContext.getSubject(update); if (rsMaintained && !(subject.hasPrincipal(Principal.RS_MAINTAINER) || subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER))) { final List<RpslAttribute> org = update.getUpdatedObject().findAttributes(AttributeType.ORG); if (org.isEmpty()) { updateContext.addMessage(update, UpdateMessages.cantRemoveOrgAttribute()); } else { updateContext.addMessage(update, org.get(0), UpdateMessages.cantChangeOrgAttribute()); } } } @Autowired OrgAttributeNotChangedValidator(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void invalid_child_status_fails_ipv4() { when(update.getType()).thenReturn(INETNUM); when(authenticationSubject.hasPrincipal(Principal.ALLOC_MAINTAINER)).thenReturn(true); final Ipv4Resource ipv4Resource = Ipv4Resource.parse("192.0/32"); final Ipv4Entry child = new Ipv4Entry(ipv4Resource, 1); when(ipv4Tree.findFirstMoreSpecific(any(Ipv4Resource.class))).thenReturn(Lists.<Ipv4Entry>newArrayList(child)); when(update.getUpdatedObject()).thenReturn(RpslObject.parse("inetnum: 192.0/24\nstatus: ALLOCATED PA")); when(objectDao.getById(1)).thenReturn(RpslObject.parse("inetnum: 192.0/32\nstatus: ASSIGNED PI")); subject.validate(update, updateContext); verify(updateContext).addMessage(update, UpdateMessages.incorrectChildStatus(ERROR, "ALLOCATED PA", "ASSIGNED PI", "192.0/32")); verify(maintainers).isRsMaintainer(ciSet()); verifyNoMoreInteractions(maintainers); } | @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { validateCreate(update, updateContext); } | StrictStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { validateCreate(update, updateContext); } } | StrictStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { validateCreate(update, updateContext); } @Autowired StrictStatusValidator(
final RpslObjectDao objectDao,
final Ipv4Tree ipv4Tree,
final Ipv6Tree ipv6Tree,
final Maintainers maintainers); } | StrictStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { validateCreate(update, updateContext); } @Autowired StrictStatusValidator(
final RpslObjectDao objectDao,
final Ipv4Tree ipv4Tree,
final Ipv6Tree ipv6Tree,
final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | StrictStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { validateCreate(update, updateContext); } @Autowired StrictStatusValidator(
final RpslObjectDao objectDao,
final Ipv4Tree ipv4Tree,
final Ipv6Tree ipv6Tree,
final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void not_authorized_by_rsmntner_ipv4() { when(ipv4Tree.findFirstLessSpecific(any(Ipv4Resource.class))).thenReturn(Lists.newArrayList(new Ipv4Entry(Ipv4Resource.parse("0/0"), 1))); when(objectDao.getById(1)).thenReturn(RpslObject.parse("inetnum: 0.0.0.0 - 255.255.255\nstatus: ALLOCATED UNSPECIFIED")); when(update.getType()).thenReturn(INETNUM); when(authenticationSubject.hasPrincipal(Principal.ALLOC_MAINTAINER)).thenReturn(false); when(update.getUpdatedObject()).thenReturn(RpslObject.parse("inetnum: 192.0/24\nstatus: ASSIGNED ANYCAST")); when(ipv4Tree.findFirstMoreSpecific(any(Ipv4Resource.class))).thenReturn(Lists.<Ipv4Entry>newArrayList()); subject.validate(update, updateContext); verify(updateContext).addMessage(update, UpdateMessages.statusRequiresAuthorization("ASSIGNED ANYCAST")); verify(maintainers, times(2)).isRsMaintainer(ciSet()); verifyNoMoreInteractions(maintainers); } | @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { validateCreate(update, updateContext); } | StrictStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { validateCreate(update, updateContext); } } | StrictStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { validateCreate(update, updateContext); } @Autowired StrictStatusValidator(
final RpslObjectDao objectDao,
final Ipv4Tree ipv4Tree,
final Ipv6Tree ipv6Tree,
final Maintainers maintainers); } | StrictStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { validateCreate(update, updateContext); } @Autowired StrictStatusValidator(
final RpslObjectDao objectDao,
final Ipv4Tree ipv4Tree,
final Ipv6Tree ipv6Tree,
final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | StrictStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { validateCreate(update, updateContext); } @Autowired StrictStatusValidator(
final RpslObjectDao objectDao,
final Ipv4Tree ipv4Tree,
final Ipv6Tree ipv6Tree,
final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void transform_alias_with_trailing_dot() { final RpslObject rpslObject = RpslObject.parse("" + "inet-rtr: test.ripe.net\n" + "alias: alias.ripe.net."); final RpslObject result = attributeSanitizer.sanitize(rpslObject, objectMessages); assertThat(result.getValueForAttribute(AttributeType.ALIAS).toString(), is("alias.ripe.net")); verify(objectMessages).addMessage(result.findAttribute(AttributeType.ALIAS), ValidationMessages.attributeValueConverted("alias.ripe.net.", "alias.ripe.net")); verifyNoMoreInteractions(objectMessages); } | public RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages) { final Map<RpslAttribute, RpslAttribute> replacements = Maps.newHashMap(); for (final RpslAttribute attribute : object.getAttributes()) { final AttributeType type = attribute.getType(); String newValue = null; final Sanitizer sanitizer = SANITIZER_MAP.get(type); if (sanitizer == null) { continue; } try { newValue = sanitizer.sanitize(attribute); } catch (IllegalArgumentException ignored) { LOGGER.debug("{}: {}", ignored.getClass().getName(), ignored.getMessage()); } if (newValue == null) { continue; } final List<Message> attributeMessages = Lists.newArrayList(); if (!sanitizer.silent() && !attribute.getCleanValue().toString().equals(newValue)) { attributeMessages.add(ValidationMessages.attributeValueConverted(attribute.getCleanValue(), newValue)); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('\n') != -1) { attributeMessages.add(ValidationMessages.continuationLinesRemoved()); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('#') != -1) { attributeMessages.add(ValidationMessages.remarksReformatted()); } final String replacement = newValue + getCommentReplacement(attribute); final RpslAttribute transformed = new RpslAttribute(attribute.getKey(), replacement); replacements.put(attribute, transformed); for (final Message attributeMessage : attributeMessages) { objectMessages.addMessage(transformed, attributeMessage); } } return new RpslObjectBuilder(object).replaceAttributes(replacements).get(); } | AttributeSanitizer { public RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages) { final Map<RpslAttribute, RpslAttribute> replacements = Maps.newHashMap(); for (final RpslAttribute attribute : object.getAttributes()) { final AttributeType type = attribute.getType(); String newValue = null; final Sanitizer sanitizer = SANITIZER_MAP.get(type); if (sanitizer == null) { continue; } try { newValue = sanitizer.sanitize(attribute); } catch (IllegalArgumentException ignored) { LOGGER.debug("{}: {}", ignored.getClass().getName(), ignored.getMessage()); } if (newValue == null) { continue; } final List<Message> attributeMessages = Lists.newArrayList(); if (!sanitizer.silent() && !attribute.getCleanValue().toString().equals(newValue)) { attributeMessages.add(ValidationMessages.attributeValueConverted(attribute.getCleanValue(), newValue)); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('\n') != -1) { attributeMessages.add(ValidationMessages.continuationLinesRemoved()); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('#') != -1) { attributeMessages.add(ValidationMessages.remarksReformatted()); } final String replacement = newValue + getCommentReplacement(attribute); final RpslAttribute transformed = new RpslAttribute(attribute.getKey(), replacement); replacements.put(attribute, transformed); for (final Message attributeMessage : attributeMessages) { objectMessages.addMessage(transformed, attributeMessage); } } return new RpslObjectBuilder(object).replaceAttributes(replacements).get(); } } | AttributeSanitizer { public RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages) { final Map<RpslAttribute, RpslAttribute> replacements = Maps.newHashMap(); for (final RpslAttribute attribute : object.getAttributes()) { final AttributeType type = attribute.getType(); String newValue = null; final Sanitizer sanitizer = SANITIZER_MAP.get(type); if (sanitizer == null) { continue; } try { newValue = sanitizer.sanitize(attribute); } catch (IllegalArgumentException ignored) { LOGGER.debug("{}: {}", ignored.getClass().getName(), ignored.getMessage()); } if (newValue == null) { continue; } final List<Message> attributeMessages = Lists.newArrayList(); if (!sanitizer.silent() && !attribute.getCleanValue().toString().equals(newValue)) { attributeMessages.add(ValidationMessages.attributeValueConverted(attribute.getCleanValue(), newValue)); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('\n') != -1) { attributeMessages.add(ValidationMessages.continuationLinesRemoved()); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('#') != -1) { attributeMessages.add(ValidationMessages.remarksReformatted()); } final String replacement = newValue + getCommentReplacement(attribute); final RpslAttribute transformed = new RpslAttribute(attribute.getKey(), replacement); replacements.put(attribute, transformed); for (final Message attributeMessage : attributeMessages) { objectMessages.addMessage(transformed, attributeMessage); } } return new RpslObjectBuilder(object).replaceAttributes(replacements).get(); } @Autowired AttributeSanitizer(DateTimeProvider dateTimeProvider); } | AttributeSanitizer { public RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages) { final Map<RpslAttribute, RpslAttribute> replacements = Maps.newHashMap(); for (final RpslAttribute attribute : object.getAttributes()) { final AttributeType type = attribute.getType(); String newValue = null; final Sanitizer sanitizer = SANITIZER_MAP.get(type); if (sanitizer == null) { continue; } try { newValue = sanitizer.sanitize(attribute); } catch (IllegalArgumentException ignored) { LOGGER.debug("{}: {}", ignored.getClass().getName(), ignored.getMessage()); } if (newValue == null) { continue; } final List<Message> attributeMessages = Lists.newArrayList(); if (!sanitizer.silent() && !attribute.getCleanValue().toString().equals(newValue)) { attributeMessages.add(ValidationMessages.attributeValueConverted(attribute.getCleanValue(), newValue)); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('\n') != -1) { attributeMessages.add(ValidationMessages.continuationLinesRemoved()); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('#') != -1) { attributeMessages.add(ValidationMessages.remarksReformatted()); } final String replacement = newValue + getCommentReplacement(attribute); final RpslAttribute transformed = new RpslAttribute(attribute.getKey(), replacement); replacements.put(attribute, transformed); for (final Message attributeMessage : attributeMessages) { objectMessages.addMessage(transformed, attributeMessage); } } return new RpslObjectBuilder(object).replaceAttributes(replacements).get(); } @Autowired AttributeSanitizer(DateTimeProvider dateTimeProvider); CIString sanitizeKey(final RpslObject originalObject); RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages); } | AttributeSanitizer { public RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages) { final Map<RpslAttribute, RpslAttribute> replacements = Maps.newHashMap(); for (final RpslAttribute attribute : object.getAttributes()) { final AttributeType type = attribute.getType(); String newValue = null; final Sanitizer sanitizer = SANITIZER_MAP.get(type); if (sanitizer == null) { continue; } try { newValue = sanitizer.sanitize(attribute); } catch (IllegalArgumentException ignored) { LOGGER.debug("{}: {}", ignored.getClass().getName(), ignored.getMessage()); } if (newValue == null) { continue; } final List<Message> attributeMessages = Lists.newArrayList(); if (!sanitizer.silent() && !attribute.getCleanValue().toString().equals(newValue)) { attributeMessages.add(ValidationMessages.attributeValueConverted(attribute.getCleanValue(), newValue)); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('\n') != -1) { attributeMessages.add(ValidationMessages.continuationLinesRemoved()); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('#') != -1) { attributeMessages.add(ValidationMessages.remarksReformatted()); } final String replacement = newValue + getCommentReplacement(attribute); final RpslAttribute transformed = new RpslAttribute(attribute.getKey(), replacement); replacements.put(attribute, transformed); for (final Message attributeMessage : attributeMessages) { objectMessages.addMessage(transformed, attributeMessage); } } return new RpslObjectBuilder(object).replaceAttributes(replacements).get(); } @Autowired AttributeSanitizer(DateTimeProvider dateTimeProvider); CIString sanitizeKey(final RpslObject originalObject); RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages); } |
@Test public void not_authorized_by_rsmntner_ipv4_override() { when(ipv4Tree.findFirstLessSpecific(any(Ipv4Resource.class))).thenReturn(Lists.newArrayList(new Ipv4Entry(Ipv4Resource.parse("0/0"), 1))); when(objectDao.getById(1)).thenReturn(RpslObject.parse("inetnum: 0.0.0.0 - 255.255.255\nstatus: ALLOCATED UNSPECIFIED")); when(update.getType()).thenReturn(INETNUM); when(authenticationSubject.hasPrincipal(Principal.ALLOC_MAINTAINER)).thenReturn(false); when(authenticationSubject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)).thenReturn(true); when(update.getUpdatedObject()).thenReturn(RpslObject.parse("inetnum: 192.0/24\nstatus: ASSIGNED ANYCAST")); when(ipv4Tree.findFirstMoreSpecific(any(Ipv4Resource.class))).thenReturn(Lists.<Ipv4Entry>newArrayList()); subject.validate(update, updateContext); verify(updateContext, never()).addMessage(eq(update), any(Message.class)); } | @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { validateCreate(update, updateContext); } | StrictStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { validateCreate(update, updateContext); } } | StrictStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { validateCreate(update, updateContext); } @Autowired StrictStatusValidator(
final RpslObjectDao objectDao,
final Ipv4Tree ipv4Tree,
final Ipv6Tree ipv6Tree,
final Maintainers maintainers); } | StrictStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { validateCreate(update, updateContext); } @Autowired StrictStatusValidator(
final RpslObjectDao objectDao,
final Ipv4Tree ipv4Tree,
final Ipv6Tree ipv6Tree,
final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | StrictStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { validateCreate(update, updateContext); } @Autowired StrictStatusValidator(
final RpslObjectDao objectDao,
final Ipv4Tree ipv4Tree,
final Ipv6Tree ipv6Tree,
final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void parent_has_assigned_pa_status_and_grandparent_is_allocated_pa_and_has_rs_maintainer() { when(update.getType()).thenReturn(INETNUM); when(update.getUpdatedObject()).thenReturn(RpslObject.parse("inetnum: 192.168.1.0/24\nstatus: ASSIGNED PA")); Ipv4Entry parentEntry = new Ipv4Entry(Ipv4Resource.parse("192.168/16"), 1); when(objectDao.getById(1)).thenReturn(RpslObject.parse("inetnum: 192.168/16\nstatus: ASSIGNED PA")); Ipv4Entry grandParentEntry = new Ipv4Entry(Ipv4Resource.parse("192/8"), 2); when(objectDao.getById(2)).thenReturn(RpslObject.parse("inetnum: 192/8\nstatus: ALLOCATED PA\nmnt-by: RIPE-NCC-HM-MNT")); when(ipv4Tree.findAllLessSpecific(any(Ipv4Resource.class))).thenReturn(Lists.<Ipv4Entry>newArrayList(parentEntry, grandParentEntry)); when(ipv4Tree.findFirstLessSpecific(any(Ipv4Resource.class))).thenReturn(Lists.<Ipv4Entry>newArrayList(parentEntry)); subject.validate(update, updateContext); verify(updateContext).addMessage(update, UpdateMessages.incorrectParentStatus(ERROR, INETNUM, "ASSIGNED PA")); verify(maintainers).isRsMaintainer(ciSet("RIPE-NCC-HM-MNT")); verify(maintainers, times(2)).isRsMaintainer(ciSet()); verifyNoMoreInteractions(maintainers); } | @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { validateCreate(update, updateContext); } | StrictStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { validateCreate(update, updateContext); } } | StrictStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { validateCreate(update, updateContext); } @Autowired StrictStatusValidator(
final RpslObjectDao objectDao,
final Ipv4Tree ipv4Tree,
final Ipv6Tree ipv6Tree,
final Maintainers maintainers); } | StrictStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { validateCreate(update, updateContext); } @Autowired StrictStatusValidator(
final RpslObjectDao objectDao,
final Ipv4Tree ipv4Tree,
final Ipv6Tree ipv6Tree,
final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | StrictStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { validateCreate(update, updateContext); } @Autowired StrictStatusValidator(
final RpslObjectDao objectDao,
final Ipv4Tree ipv4Tree,
final Ipv6Tree ipv6Tree,
final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void parent_has_assigned_pa_status_and_grandparent_is_allocated_pa_but_does_not_have_rs_maintainer() { when(update.getType()).thenReturn(INETNUM); when(update.getUpdatedObject()).thenReturn(RpslObject.parse("inetnum: 192.168.1.0/24\nstatus: ASSIGNED PA")); Ipv4Entry parentEntry = new Ipv4Entry(Ipv4Resource.parse("192.168/16"), 1); when(objectDao.getById(1)).thenReturn(RpslObject.parse("inetnum: 192.168/16\nstatus: ASSIGNED PA")); Ipv4Entry grandParentEntry = new Ipv4Entry(Ipv4Resource.parse("192/8"), 2); when(objectDao.getById(2)).thenReturn(RpslObject.parse("inetnum: 192/8\nstatus: ALLOCATED PA")); when(ipv4Tree.findAllLessSpecific(any(Ipv4Resource.class))).thenReturn(Lists.<Ipv4Entry>newArrayList(parentEntry, grandParentEntry)); when(ipv4Tree.findFirstLessSpecific(any(Ipv4Resource.class))).thenReturn(Lists.<Ipv4Entry>newArrayList(parentEntry)); subject.validate(update, updateContext); verify(updateContext, never()).addMessage(update, UpdateMessages.incorrectParentStatus(ERROR, INETNUM, "ASSIGNED PA")); verify(maintainers, times(3)).isRsMaintainer(ciSet()); verifyNoMoreInteractions(maintainers); } | @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { validateCreate(update, updateContext); } | StrictStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { validateCreate(update, updateContext); } } | StrictStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { validateCreate(update, updateContext); } @Autowired StrictStatusValidator(
final RpslObjectDao objectDao,
final Ipv4Tree ipv4Tree,
final Ipv6Tree ipv6Tree,
final Maintainers maintainers); } | StrictStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { validateCreate(update, updateContext); } @Autowired StrictStatusValidator(
final RpslObjectDao objectDao,
final Ipv4Tree ipv4Tree,
final Ipv6Tree ipv6Tree,
final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | StrictStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { validateCreate(update, updateContext); } @Autowired StrictStatusValidator(
final RpslObjectDao objectDao,
final Ipv4Tree ipv4Tree,
final Ipv6Tree ipv6Tree,
final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void incorrect_parent_status_ipv4() { when(update.getType()).thenReturn(INETNUM); when(authenticationSubject.hasPrincipal(Principal.ALLOC_MAINTAINER)).thenReturn(true); when(update.getUpdatedObject()).thenReturn(RpslObject.parse("inetnum: 192.0/24\nstatus: ASSIGNED PI")); when(ipv4Tree.findFirstMoreSpecific(any(Ipv4Resource.class))).thenReturn(Lists.<Ipv4Entry>newArrayList()); Ipv4Entry parentEntry = new Ipv4Entry(Ipv4Resource.parse("192.0/16"), 1); when(ipv4Tree.findFirstLessSpecific(any(Ipv4Resource.class))).thenReturn(Lists.<Ipv4Entry>newArrayList(parentEntry)); final RpslObject parent = RpslObject.parse("inetnum: 192.0/16\nstatus: SUB-ALLOCATED PA"); when(objectDao.getById(1)).thenReturn(parent); subject.validate(update, updateContext); verify(updateContext).addMessage(update, UpdateMessages.incorrectParentStatus(ERROR, INETNUM, "SUB-ALLOCATED PA")); verify(maintainers).isRsMaintainer(ciSet()); verifyNoMoreInteractions(maintainers); } | @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { validateCreate(update, updateContext); } | StrictStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { validateCreate(update, updateContext); } } | StrictStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { validateCreate(update, updateContext); } @Autowired StrictStatusValidator(
final RpslObjectDao objectDao,
final Ipv4Tree ipv4Tree,
final Ipv6Tree ipv6Tree,
final Maintainers maintainers); } | StrictStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { validateCreate(update, updateContext); } @Autowired StrictStatusValidator(
final RpslObjectDao objectDao,
final Ipv4Tree ipv4Tree,
final Ipv6Tree ipv6Tree,
final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | StrictStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { validateCreate(update, updateContext); } @Autowired StrictStatusValidator(
final RpslObjectDao objectDao,
final Ipv4Tree ipv4Tree,
final Ipv6Tree ipv6Tree,
final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void incorrect_parent_status_ipv4_override() { when(update.getType()).thenReturn(INETNUM); when(authenticationSubject.hasPrincipal(Principal.ALLOC_MAINTAINER)).thenReturn(true); when(authenticationSubject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)).thenReturn(true); when(update.getUpdatedObject()).thenReturn(RpslObject.parse("inetnum: 192.0/24\nstatus: ASSIGNED PI")); when(ipv4Tree.findFirstMoreSpecific(any(Ipv4Resource.class))).thenReturn(Lists.<Ipv4Entry>newArrayList()); Ipv4Entry parentEntry = new Ipv4Entry(Ipv4Resource.parse("192.0/16"), 1); when(ipv4Tree.findFirstLessSpecific(any(Ipv4Resource.class))).thenReturn(Lists.<Ipv4Entry>newArrayList(parentEntry)); final RpslObject parent = RpslObject.parse("inetnum: 192.0/16\nstatus: SUB-ALLOCATED PA"); when(objectDao.getById(1)).thenReturn(parent); subject.validate(update, updateContext); verify(updateContext).addMessage(update, UpdateMessages.incorrectParentStatus(ERROR, INETNUM, "SUB-ALLOCATED PA")); } | @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { validateCreate(update, updateContext); } | StrictStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { validateCreate(update, updateContext); } } | StrictStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { validateCreate(update, updateContext); } @Autowired StrictStatusValidator(
final RpslObjectDao objectDao,
final Ipv4Tree ipv4Tree,
final Ipv6Tree ipv6Tree,
final Maintainers maintainers); } | StrictStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { validateCreate(update, updateContext); } @Autowired StrictStatusValidator(
final RpslObjectDao objectDao,
final Ipv4Tree ipv4Tree,
final Ipv6Tree ipv6Tree,
final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | StrictStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { validateCreate(update, updateContext); } @Autowired StrictStatusValidator(
final RpslObjectDao objectDao,
final Ipv4Tree ipv4Tree,
final Ipv6Tree ipv6Tree,
final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void correct_parent_status_ipv4() { when(update.getType()).thenReturn(INETNUM); when(authenticationSubject.hasPrincipal(Principal.RS_MAINTAINER)).thenReturn(true); when(update.getUpdatedObject()).thenReturn(RpslObject.parse("inetnum: 192.0/24\nstatus: ASSIGNED PI\nmnt-by: RIPE-NCC-HM-MNT")); when(ipv4Tree.findFirstMoreSpecific(any(Ipv4Resource.class))).thenReturn(Lists.<Ipv4Entry>newArrayList()); Ipv4Entry parentEntry = new Ipv4Entry(Ipv4Resource.parse("192.0/16"), 1); when(ipv4Tree.findFirstLessSpecific(any(Ipv4Resource.class))).thenReturn(Lists.<Ipv4Entry>newArrayList(parentEntry)); final RpslObject parent = RpslObject.parse("inetnum: 192.0/16\nstatus: ALLOCATED UNSPECIFIED"); when(objectDao.getById(1)).thenReturn(parent); subject.validate(update, updateContext); verify(updateContext, never()).addMessage(eq(update), any(Message.class)); verify(maintainers).isRsMaintainer(ciSet("RIPE-NCC-HM-MNT")); verifyNoMoreInteractions(maintainers); } | @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { validateCreate(update, updateContext); } | StrictStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { validateCreate(update, updateContext); } } | StrictStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { validateCreate(update, updateContext); } @Autowired StrictStatusValidator(
final RpslObjectDao objectDao,
final Ipv4Tree ipv4Tree,
final Ipv6Tree ipv6Tree,
final Maintainers maintainers); } | StrictStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { validateCreate(update, updateContext); } @Autowired StrictStatusValidator(
final RpslObjectDao objectDao,
final Ipv4Tree ipv4Tree,
final Ipv6Tree ipv6Tree,
final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | StrictStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { validateCreate(update, updateContext); } @Autowired StrictStatusValidator(
final RpslObjectDao objectDao,
final Ipv4Tree ipv4Tree,
final Ipv6Tree ipv6Tree,
final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void not_authorized_by_rsmntner_ipv6() { when(ipv6Tree.findFirstLessSpecific(any(Ipv6Resource.class))).thenReturn(Lists.newArrayList(new Ipv6Entry(Ipv6Resource.parse("::0/0"), 1))); when(objectDao.getById(1)).thenReturn(RpslObject.parse("inet6num: ::0/0\nstatus: ALLOCATED-BY-RIR")); when(update.getType()).thenReturn(ObjectType.INET6NUM); when(authenticationSubject.hasPrincipal(Principal.ALLOC_MAINTAINER)).thenReturn(false); when(update.getUpdatedObject()).thenReturn(RpslObject.parse("inet6num: 2001::/48\nstatus: ASSIGNED ANYCAST")); when(ipv6Tree.findFirstMoreSpecific(any(Ipv6Resource.class))).thenReturn(Lists.<Ipv6Entry>newArrayList()); subject.validate(update, updateContext); verify(updateContext).addMessage(update, UpdateMessages.statusRequiresAuthorization("ASSIGNED ANYCAST")); verify(maintainers, times(2)).isRsMaintainer(ciSet()); verifyNoMoreInteractions(maintainers); } | @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { validateCreate(update, updateContext); } | StrictStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { validateCreate(update, updateContext); } } | StrictStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { validateCreate(update, updateContext); } @Autowired StrictStatusValidator(
final RpslObjectDao objectDao,
final Ipv4Tree ipv4Tree,
final Ipv6Tree ipv6Tree,
final Maintainers maintainers); } | StrictStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { validateCreate(update, updateContext); } @Autowired StrictStatusValidator(
final RpslObjectDao objectDao,
final Ipv4Tree ipv4Tree,
final Ipv6Tree ipv6Tree,
final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | StrictStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { validateCreate(update, updateContext); } @Autowired StrictStatusValidator(
final RpslObjectDao objectDao,
final Ipv4Tree ipv4Tree,
final Ipv6Tree ipv6Tree,
final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void incorrect_parent_status_ipv6() { when(update.getType()).thenReturn(ObjectType.INET6NUM); when(authenticationSubject.hasPrincipal(Principal.ALLOC_MAINTAINER)).thenReturn(true); when(update.getUpdatedObject()).thenReturn(RpslObject.parse("inet6num: 2001::/48\nstatus: ASSIGNED PI\nmnt-by: RIPE-NCC-HM-MNT\n")); when(ipv6Tree.findFirstMoreSpecific(any(Ipv6Resource.class))).thenReturn(Lists.<Ipv6Entry>newArrayList()); Ipv6Entry parentEntry = new Ipv6Entry(Ipv6Resource.parse("2001::/24"), 1); when(ipv6Tree.findFirstLessSpecific(any(Ipv6Resource.class))).thenReturn(Lists.<Ipv6Entry>newArrayList(parentEntry)); final RpslObject parent = RpslObject.parse("inet6num: 2001::/24\nstatus: ALLOCATED-BY-LIR"); when(objectDao.getById(1)).thenReturn(parent); subject.validate(update, updateContext); verify(updateContext).addMessage(update, UpdateMessages.incorrectParentStatus(ERROR, ObjectType.INET6NUM, "ALLOCATED-BY-LIR")); verify(maintainers, times(2)).isRsMaintainer(ciSet("RIPE-NCC-HM-MNT")); verifyNoMoreInteractions(maintainers); } | @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { validateCreate(update, updateContext); } | StrictStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { validateCreate(update, updateContext); } } | StrictStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { validateCreate(update, updateContext); } @Autowired StrictStatusValidator(
final RpslObjectDao objectDao,
final Ipv4Tree ipv4Tree,
final Ipv6Tree ipv6Tree,
final Maintainers maintainers); } | StrictStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { validateCreate(update, updateContext); } @Autowired StrictStatusValidator(
final RpslObjectDao objectDao,
final Ipv4Tree ipv4Tree,
final Ipv6Tree ipv6Tree,
final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | StrictStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { validateCreate(update, updateContext); } @Autowired StrictStatusValidator(
final RpslObjectDao objectDao,
final Ipv4Tree ipv4Tree,
final Ipv6Tree ipv6Tree,
final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void correct_parent_status_ipv6() { when(update.getType()).thenReturn(ObjectType.INET6NUM); when(authenticationSubject.hasPrincipal(Principal.RS_MAINTAINER)).thenReturn(true); when(update.getUpdatedObject()).thenReturn(RpslObject.parse("inet6num: 2001::/48\nstatus: ASSIGNED PI\nmnt-by: RIPE-NCC-HM-MNT\n")); when(ipv6Tree.findFirstMoreSpecific(any(Ipv6Resource.class))).thenReturn(Lists.<Ipv6Entry>newArrayList()); Ipv6Entry parentEntry = new Ipv6Entry(Ipv6Resource.parse("2001::/24"), 1); when(ipv6Tree.findFirstLessSpecific(any(Ipv6Resource.class))).thenReturn(Lists.<Ipv6Entry>newArrayList(parentEntry)); final RpslObject parent = RpslObject.parse("inet6num: 2001::/24\nstatus: ALLOCATED-BY-RIR"); when(objectDao.getById(1)).thenReturn(parent); subject.validate(update, updateContext); verify(updateContext, never()).addMessage(eq(update), any(Message.class)); verify(maintainers, times(2)).isRsMaintainer(ciSet("RIPE-NCC-HM-MNT")); verifyNoMoreInteractions(maintainers); } | @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { validateCreate(update, updateContext); } | StrictStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { validateCreate(update, updateContext); } } | StrictStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { validateCreate(update, updateContext); } @Autowired StrictStatusValidator(
final RpslObjectDao objectDao,
final Ipv4Tree ipv4Tree,
final Ipv6Tree ipv6Tree,
final Maintainers maintainers); } | StrictStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { validateCreate(update, updateContext); } @Autowired StrictStatusValidator(
final RpslObjectDao objectDao,
final Ipv4Tree ipv4Tree,
final Ipv6Tree ipv6Tree,
final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | StrictStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { validateCreate(update, updateContext); } @Autowired StrictStatusValidator(
final RpslObjectDao objectDao,
final Ipv4Tree ipv4Tree,
final Ipv6Tree ipv6Tree,
final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void create_inetnum_w_legacy_allowed_under_legacy_w_non_rs_maintainer() { when(ipv4Tree.findFirstLessSpecific(any(Ipv4Resource.class))).thenReturn(Lists.newArrayList(new Ipv4Entry(Ipv4Resource.parse("0/0"), 1))); when(objectDao.getById(1)).thenReturn(RpslObject.parse("" + "inetnum: 0.0.0.0 - 255.255.255.255\n" + "status: LEGACY")); when(update.getType()).thenReturn(INETNUM); when(update.getUpdatedObject()).thenReturn(RpslObject.parse("" + "inetnum: 192.0/24\n" + "status: LEGACY\n" + "mnt-by: TEST-MNT\n" + "password: update")); subject.validate(update, updateContext); verify(updateContext, never()).addMessage(update, UpdateMessages.inetnumStatusLegacy()); } | @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { validateCreate(update, updateContext); } | StrictStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { validateCreate(update, updateContext); } } | StrictStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { validateCreate(update, updateContext); } @Autowired StrictStatusValidator(
final RpslObjectDao objectDao,
final Ipv4Tree ipv4Tree,
final Ipv6Tree ipv6Tree,
final Maintainers maintainers); } | StrictStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { validateCreate(update, updateContext); } @Autowired StrictStatusValidator(
final RpslObjectDao objectDao,
final Ipv4Tree ipv4Tree,
final Ipv6Tree ipv6Tree,
final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | StrictStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { validateCreate(update, updateContext); } @Autowired StrictStatusValidator(
final RpslObjectDao objectDao,
final Ipv4Tree ipv4Tree,
final Ipv6Tree ipv6Tree,
final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void transform_inetrtr_no_dot() { final RpslObject rpslObject = RpslObject.parse("" + "inet-rtr: test.ripe.net\n" + "alias: alias.ripe.net"); final RpslObject result = attributeSanitizer.sanitize(rpslObject, objectMessages); assertThat(result.getValueForAttribute(AttributeType.INET_RTR).toString(), is("test.ripe.net")); verifyNoMoreInteractions(objectMessages); } | public RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages) { final Map<RpslAttribute, RpslAttribute> replacements = Maps.newHashMap(); for (final RpslAttribute attribute : object.getAttributes()) { final AttributeType type = attribute.getType(); String newValue = null; final Sanitizer sanitizer = SANITIZER_MAP.get(type); if (sanitizer == null) { continue; } try { newValue = sanitizer.sanitize(attribute); } catch (IllegalArgumentException ignored) { LOGGER.debug("{}: {}", ignored.getClass().getName(), ignored.getMessage()); } if (newValue == null) { continue; } final List<Message> attributeMessages = Lists.newArrayList(); if (!sanitizer.silent() && !attribute.getCleanValue().toString().equals(newValue)) { attributeMessages.add(ValidationMessages.attributeValueConverted(attribute.getCleanValue(), newValue)); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('\n') != -1) { attributeMessages.add(ValidationMessages.continuationLinesRemoved()); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('#') != -1) { attributeMessages.add(ValidationMessages.remarksReformatted()); } final String replacement = newValue + getCommentReplacement(attribute); final RpslAttribute transformed = new RpslAttribute(attribute.getKey(), replacement); replacements.put(attribute, transformed); for (final Message attributeMessage : attributeMessages) { objectMessages.addMessage(transformed, attributeMessage); } } return new RpslObjectBuilder(object).replaceAttributes(replacements).get(); } | AttributeSanitizer { public RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages) { final Map<RpslAttribute, RpslAttribute> replacements = Maps.newHashMap(); for (final RpslAttribute attribute : object.getAttributes()) { final AttributeType type = attribute.getType(); String newValue = null; final Sanitizer sanitizer = SANITIZER_MAP.get(type); if (sanitizer == null) { continue; } try { newValue = sanitizer.sanitize(attribute); } catch (IllegalArgumentException ignored) { LOGGER.debug("{}: {}", ignored.getClass().getName(), ignored.getMessage()); } if (newValue == null) { continue; } final List<Message> attributeMessages = Lists.newArrayList(); if (!sanitizer.silent() && !attribute.getCleanValue().toString().equals(newValue)) { attributeMessages.add(ValidationMessages.attributeValueConverted(attribute.getCleanValue(), newValue)); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('\n') != -1) { attributeMessages.add(ValidationMessages.continuationLinesRemoved()); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('#') != -1) { attributeMessages.add(ValidationMessages.remarksReformatted()); } final String replacement = newValue + getCommentReplacement(attribute); final RpslAttribute transformed = new RpslAttribute(attribute.getKey(), replacement); replacements.put(attribute, transformed); for (final Message attributeMessage : attributeMessages) { objectMessages.addMessage(transformed, attributeMessage); } } return new RpslObjectBuilder(object).replaceAttributes(replacements).get(); } } | AttributeSanitizer { public RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages) { final Map<RpslAttribute, RpslAttribute> replacements = Maps.newHashMap(); for (final RpslAttribute attribute : object.getAttributes()) { final AttributeType type = attribute.getType(); String newValue = null; final Sanitizer sanitizer = SANITIZER_MAP.get(type); if (sanitizer == null) { continue; } try { newValue = sanitizer.sanitize(attribute); } catch (IllegalArgumentException ignored) { LOGGER.debug("{}: {}", ignored.getClass().getName(), ignored.getMessage()); } if (newValue == null) { continue; } final List<Message> attributeMessages = Lists.newArrayList(); if (!sanitizer.silent() && !attribute.getCleanValue().toString().equals(newValue)) { attributeMessages.add(ValidationMessages.attributeValueConverted(attribute.getCleanValue(), newValue)); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('\n') != -1) { attributeMessages.add(ValidationMessages.continuationLinesRemoved()); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('#') != -1) { attributeMessages.add(ValidationMessages.remarksReformatted()); } final String replacement = newValue + getCommentReplacement(attribute); final RpslAttribute transformed = new RpslAttribute(attribute.getKey(), replacement); replacements.put(attribute, transformed); for (final Message attributeMessage : attributeMessages) { objectMessages.addMessage(transformed, attributeMessage); } } return new RpslObjectBuilder(object).replaceAttributes(replacements).get(); } @Autowired AttributeSanitizer(DateTimeProvider dateTimeProvider); } | AttributeSanitizer { public RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages) { final Map<RpslAttribute, RpslAttribute> replacements = Maps.newHashMap(); for (final RpslAttribute attribute : object.getAttributes()) { final AttributeType type = attribute.getType(); String newValue = null; final Sanitizer sanitizer = SANITIZER_MAP.get(type); if (sanitizer == null) { continue; } try { newValue = sanitizer.sanitize(attribute); } catch (IllegalArgumentException ignored) { LOGGER.debug("{}: {}", ignored.getClass().getName(), ignored.getMessage()); } if (newValue == null) { continue; } final List<Message> attributeMessages = Lists.newArrayList(); if (!sanitizer.silent() && !attribute.getCleanValue().toString().equals(newValue)) { attributeMessages.add(ValidationMessages.attributeValueConverted(attribute.getCleanValue(), newValue)); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('\n') != -1) { attributeMessages.add(ValidationMessages.continuationLinesRemoved()); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('#') != -1) { attributeMessages.add(ValidationMessages.remarksReformatted()); } final String replacement = newValue + getCommentReplacement(attribute); final RpslAttribute transformed = new RpslAttribute(attribute.getKey(), replacement); replacements.put(attribute, transformed); for (final Message attributeMessage : attributeMessages) { objectMessages.addMessage(transformed, attributeMessage); } } return new RpslObjectBuilder(object).replaceAttributes(replacements).get(); } @Autowired AttributeSanitizer(DateTimeProvider dateTimeProvider); CIString sanitizeKey(final RpslObject originalObject); RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages); } | AttributeSanitizer { public RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages) { final Map<RpslAttribute, RpslAttribute> replacements = Maps.newHashMap(); for (final RpslAttribute attribute : object.getAttributes()) { final AttributeType type = attribute.getType(); String newValue = null; final Sanitizer sanitizer = SANITIZER_MAP.get(type); if (sanitizer == null) { continue; } try { newValue = sanitizer.sanitize(attribute); } catch (IllegalArgumentException ignored) { LOGGER.debug("{}: {}", ignored.getClass().getName(), ignored.getMessage()); } if (newValue == null) { continue; } final List<Message> attributeMessages = Lists.newArrayList(); if (!sanitizer.silent() && !attribute.getCleanValue().toString().equals(newValue)) { attributeMessages.add(ValidationMessages.attributeValueConverted(attribute.getCleanValue(), newValue)); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('\n') != -1) { attributeMessages.add(ValidationMessages.continuationLinesRemoved()); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('#') != -1) { attributeMessages.add(ValidationMessages.remarksReformatted()); } final String replacement = newValue + getCommentReplacement(attribute); final RpslAttribute transformed = new RpslAttribute(attribute.getKey(), replacement); replacements.put(attribute, transformed); for (final Message attributeMessage : attributeMessages) { objectMessages.addMessage(transformed, attributeMessage); } } return new RpslObjectBuilder(object).replaceAttributes(replacements).get(); } @Autowired AttributeSanitizer(DateTimeProvider dateTimeProvider); CIString sanitizeKey(final RpslObject originalObject); RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages); } |
@Test public void create_inetnum_w_legacy_not_allowed_under_unspecified_w_non_rs_maintainer() { when(ipv4Tree.findFirstLessSpecific(any(Ipv4Resource.class))).thenReturn(Lists.newArrayList(new Ipv4Entry(Ipv4Resource.parse("0/0"), 1))); when(objectDao.getById(1)).thenReturn(RpslObject.parse("" + "inetnum: 0.0.0.0 - 255.255.255.255\n" + "status: ALLOCATED UNSPECIFIED")); when(update.getType()).thenReturn(INETNUM); when(update.getUpdatedObject()).thenReturn(RpslObject.parse("" + "inetnum: 192.0/24\n" + "status: LEGACY\n" + "mnt-by: TEST-MNT\n" + "password: update")); subject.validate(update, updateContext); verify(updateContext, times(1)).addMessage(update, UpdateMessages.inetnumStatusLegacy()); } | @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { validateCreate(update, updateContext); } | StrictStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { validateCreate(update, updateContext); } } | StrictStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { validateCreate(update, updateContext); } @Autowired StrictStatusValidator(
final RpslObjectDao objectDao,
final Ipv4Tree ipv4Tree,
final Ipv6Tree ipv6Tree,
final Maintainers maintainers); } | StrictStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { validateCreate(update, updateContext); } @Autowired StrictStatusValidator(
final RpslObjectDao objectDao,
final Ipv4Tree ipv4Tree,
final Ipv6Tree ipv6Tree,
final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | StrictStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { validateCreate(update, updateContext); } @Autowired StrictStatusValidator(
final RpslObjectDao objectDao,
final Ipv4Tree ipv4Tree,
final Ipv6Tree ipv6Tree,
final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void create_inetnum_w_legacy_allowed_under_unspecified_w_rs_maintainer() { when(authenticationSubject.hasPrincipal(Principal.RS_MAINTAINER)).thenReturn(true); when(ipv4Tree.findFirstLessSpecific(any(Ipv4Resource.class))).thenReturn(Lists.newArrayList(new Ipv4Entry(Ipv4Resource.parse("0/0"), 1))); when(objectDao.getById(1)).thenReturn(RpslObject.parse("" + "inetnum: 0.0.0.0 - 255.255.255.255\n" + "status: ALLOCATED UNSPECIFIED")); when(update.getType()).thenReturn(INETNUM); when(update.getUpdatedObject()).thenReturn(RpslObject.parse("" + "inetnum: 192.0/24\n" + "status: LEGACY\n" + "mnt-by: RIPE-NCC-HM-MNT\n" + "password: update")); subject.validate(update, updateContext); verify(updateContext, never()).addMessage(update, UpdateMessages.inetnumStatusLegacy()); } | @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { validateCreate(update, updateContext); } | StrictStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { validateCreate(update, updateContext); } } | StrictStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { validateCreate(update, updateContext); } @Autowired StrictStatusValidator(
final RpslObjectDao objectDao,
final Ipv4Tree ipv4Tree,
final Ipv6Tree ipv6Tree,
final Maintainers maintainers); } | StrictStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { validateCreate(update, updateContext); } @Autowired StrictStatusValidator(
final RpslObjectDao objectDao,
final Ipv4Tree ipv4Tree,
final Ipv6Tree ipv6Tree,
final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | StrictStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { validateCreate(update, updateContext); } @Autowired StrictStatusValidator(
final RpslObjectDao objectDao,
final Ipv4Tree ipv4Tree,
final Ipv6Tree ipv6Tree,
final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void create_inetnum_w_legacy_not_allowed_under_wrong_status_w_rs_maintainer() { when(authenticationSubject.hasPrincipal(Principal.RS_MAINTAINER)).thenReturn(true); when(ipv4Tree.findFirstLessSpecific(any(Ipv4Resource.class))).thenReturn(Lists.newArrayList(new Ipv4Entry(Ipv4Resource.parse("0/0"), 1))); when(objectDao.getById(1)).thenReturn(RpslObject.parse("" + "inetnum: 0.0.0.0 - 255.255.255.255\n" + "status: LIR-PARTITIONED PA")); when(update.getType()).thenReturn(INETNUM); when(update.getUpdatedObject()).thenReturn(RpslObject.parse("" + "inetnum: 192.0/24\n" + "status: LEGACY\n" + "mnt-by: RIPE-NCC-HM-MNT\n" + "password: update")); subject.validate(update, updateContext); verify(updateContext, never()).addMessage(update, UpdateMessages.inetnumStatusLegacy()); verify(updateContext, times(1)).addMessage(update, UpdateMessages.incorrectParentStatus(ERROR, INETNUM, "LIR-PARTITIONED PA")); } | @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { validateCreate(update, updateContext); } | StrictStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { validateCreate(update, updateContext); } } | StrictStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { validateCreate(update, updateContext); } @Autowired StrictStatusValidator(
final RpslObjectDao objectDao,
final Ipv4Tree ipv4Tree,
final Ipv6Tree ipv6Tree,
final Maintainers maintainers); } | StrictStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { validateCreate(update, updateContext); } @Autowired StrictStatusValidator(
final RpslObjectDao objectDao,
final Ipv4Tree ipv4Tree,
final Ipv6Tree ipv6Tree,
final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | StrictStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { validateCreate(update, updateContext); } @Autowired StrictStatusValidator(
final RpslObjectDao objectDao,
final Ipv4Tree ipv4Tree,
final Ipv6Tree ipv6Tree,
final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void validate_invalid_parent_interval() throws Exception { when(update.getAction()).thenReturn(Action.CREATE); when(update.getUpdatedObject()).thenReturn(RpslObject.parse("" + "inetnum: 192.0/24\n" + "status: ASSIGNED PA")); when(ipv4Tree.findFirstLessSpecific(any(Ipv4Resource.class))).thenReturn(Collections.<Ipv4Entry>emptyList()); subject.validate(update, updateContext); verify(updateContext).addMessage(update, UpdateMessages.invalidParentEntryForInterval(Ipv4Resource.parse("192.0/24"))); verifyNoMoreInteractions(updateContext); } | @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { validateCreate(update, updateContext); } | StrictStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { validateCreate(update, updateContext); } } | StrictStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { validateCreate(update, updateContext); } @Autowired StrictStatusValidator(
final RpslObjectDao objectDao,
final Ipv4Tree ipv4Tree,
final Ipv6Tree ipv6Tree,
final Maintainers maintainers); } | StrictStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { validateCreate(update, updateContext); } @Autowired StrictStatusValidator(
final RpslObjectDao objectDao,
final Ipv4Tree ipv4Tree,
final Ipv6Tree ipv6Tree,
final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | StrictStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { validateCreate(update, updateContext); } @Autowired StrictStatusValidator(
final RpslObjectDao objectDao,
final Ipv4Tree ipv4Tree,
final Ipv6Tree ipv6Tree,
final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void status_does_not_require_endMntnerAuthorisation_inetnum() { when(update.getType()).thenReturn(ObjectType.INETNUM); when(update.getReferenceObject()).thenReturn(RpslObject.parse("inetnum: 192.0/24\nstatus: ALLOCATED PA")); when(update.getUpdatedObject()).thenReturn(RpslObject.parse("inetnum: 192.0/24\nstatus: ALLOCATED PA")); subject.validate(update, updateContext); verify(updateContext).getSubject(any(UpdateContainer.class)); verifyNoMoreInteractions(updateContext); } | @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } | MntLowerAddedRemoved implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } } | MntLowerAddedRemoved implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } } | MntLowerAddedRemoved implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | MntLowerAddedRemoved implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void status_does_not_require_endMntnerAuthorisation_inet6num() { when(update.getType()).thenReturn(ObjectType.INET6NUM); when(update.getReferenceObject()).thenReturn(RpslObject.parse("inet6num: ffff::/24\nstatus: ALLOCATED-BY-LIR")); when(update.getUpdatedObject()).thenReturn(RpslObject.parse("inet6num: ffff::/24\nstatus: ALLOCATED-BY-LIR")); subject.validate(update, updateContext); verify(updateContext).getSubject(any(UpdateContainer.class)); verifyNoMoreInteractions(updateContext); } | @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } | MntLowerAddedRemoved implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } } | MntLowerAddedRemoved implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } } | MntLowerAddedRemoved implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | MntLowerAddedRemoved implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void modify_mntLower_added_inetnum() { when(authenticationSubject.hasPrincipal(Principal.ENDUSER_MAINTAINER)).thenReturn(true); when(update.getType()).thenReturn(ObjectType.INETNUM); when(update.getDifferences(AttributeType.MNT_LOWER)).thenReturn(ciSet("TEST-MNT")); when(update.getReferenceObject()).thenReturn(RpslObject.parse("inetnum: 192.0/24\nstatus: ASSIGNED ANYCAST")); when(update.getUpdatedObject()).thenReturn(RpslObject.parse("inetnum: 192.0/24\nstatus: ASSIGNED ANYCAST\nmnt-lower: TEST-MNT")); when(updateContext.getSubject(update)).thenReturn(authenticationSubject); subject.validate(update, updateContext); verify(updateContext).addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } | @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } | MntLowerAddedRemoved implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } } | MntLowerAddedRemoved implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } } | MntLowerAddedRemoved implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | MntLowerAddedRemoved implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void modify_mntLower_added_inetnum_override() { when(authenticationSubject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)).thenReturn(true); when(update.getType()).thenReturn(ObjectType.INETNUM); when(update.getReferenceObject()).thenReturn(RpslObject.parse("inetnum: 192.0/24\nstatus: ASSIGNED PI")); when(update.getUpdatedObject()).thenReturn(RpslObject.parse("inetnum: 192.0/24\nstatus: ASSIGNED PI\nmnt-lower: TEST-MNT")); when(updateContext.getSubject(update)).thenReturn(authenticationSubject); subject.validate(update, updateContext); verify(updateContext).getSubject(any(UpdateContainer.class)); verifyNoMoreInteractions(updateContext); } | @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } | MntLowerAddedRemoved implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } } | MntLowerAddedRemoved implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } } | MntLowerAddedRemoved implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | MntLowerAddedRemoved implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void modify_mntLower_added_inet6num() { when(authenticationSubject.hasPrincipal(Principal.ENDUSER_MAINTAINER)).thenReturn(true); when(update.getType()).thenReturn(ObjectType.INET6NUM); when(update.getReferenceObject()).thenReturn(RpslObject.parse("inet6num: ffff::/48\nstatus: ASSIGNED PI")); when(update.getUpdatedObject()).thenReturn(RpslObject.parse("inet6num: ffff::/48\nstatus: ASSIGNED PI\nmnt-lower: TEST-MNT")); when(update.getDifferences(AttributeType.MNT_LOWER)).thenReturn(ciSet("TEST-MNT")); when(updateContext.getSubject(update)).thenReturn(authenticationSubject); subject.validate(update, updateContext); verify(updateContext).addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } | @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } | MntLowerAddedRemoved implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } } | MntLowerAddedRemoved implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } } | MntLowerAddedRemoved implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | MntLowerAddedRemoved implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void modify_mntLower_added_inet6num_override() { when(authenticationSubject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)).thenReturn(true); when(update.getType()).thenReturn(ObjectType.INET6NUM); when(update.getReferenceObject()).thenReturn(RpslObject.parse("inet6num: ffff::/48\nstatus: ASSIGNED PI")); when(update.getUpdatedObject()).thenReturn(RpslObject.parse("inet6num: ffff::/48\nstatus: ASSIGNED PI\nmnt-lower: TEST-MNT")); when(updateContext.getSubject(update)).thenReturn(authenticationSubject); subject.validate(update, updateContext); verify(updateContext).getSubject(any(UpdateContainer.class)); verifyNoMoreInteractions(updateContext); } | @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } | MntLowerAddedRemoved implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } } | MntLowerAddedRemoved implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } } | MntLowerAddedRemoved implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | MntLowerAddedRemoved implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void transform_key_inetrtr_no_dot() { final RpslObject rpslObject = RpslObject.parse("" + "inet-rtr: test.ripe.net\n" + "alias: alias.ripe.net"); final CIString result = attributeSanitizer.sanitizeKey(rpslObject); assertThat(result.toString(), is("test.ripe.net")); verifyNoMoreInteractions(objectMessages); } | public CIString sanitizeKey(final RpslObject originalObject) { final List<RpslAttribute> keyRelatedAttributes = getKeyRelatedAttributes(originalObject); return new RpslObject(sanitizeKeyAttributes(keyRelatedAttributes)).getKey(); } | AttributeSanitizer { public CIString sanitizeKey(final RpslObject originalObject) { final List<RpslAttribute> keyRelatedAttributes = getKeyRelatedAttributes(originalObject); return new RpslObject(sanitizeKeyAttributes(keyRelatedAttributes)).getKey(); } } | AttributeSanitizer { public CIString sanitizeKey(final RpslObject originalObject) { final List<RpslAttribute> keyRelatedAttributes = getKeyRelatedAttributes(originalObject); return new RpslObject(sanitizeKeyAttributes(keyRelatedAttributes)).getKey(); } @Autowired AttributeSanitizer(DateTimeProvider dateTimeProvider); } | AttributeSanitizer { public CIString sanitizeKey(final RpslObject originalObject) { final List<RpslAttribute> keyRelatedAttributes = getKeyRelatedAttributes(originalObject); return new RpslObject(sanitizeKeyAttributes(keyRelatedAttributes)).getKey(); } @Autowired AttributeSanitizer(DateTimeProvider dateTimeProvider); CIString sanitizeKey(final RpslObject originalObject); RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages); } | AttributeSanitizer { public CIString sanitizeKey(final RpslObject originalObject) { final List<RpslAttribute> keyRelatedAttributes = getKeyRelatedAttributes(originalObject); return new RpslObject(sanitizeKeyAttributes(keyRelatedAttributes)).getKey(); } @Autowired AttributeSanitizer(DateTimeProvider dateTimeProvider); CIString sanitizeKey(final RpslObject originalObject); RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages); } |
@Test public void modify_mntLower_removed_inetnum() { when(authenticationSubject.hasPrincipal(Principal.ENDUSER_MAINTAINER)).thenReturn(true); when(update.getType()).thenReturn(ObjectType.INETNUM); when(update.getReferenceObject()).thenReturn(RpslObject.parse("inetnum: 192.0/24\nstatus: ASSIGNED ANYCAST\nmnt-lower: TEST-MNT")); when(update.getUpdatedObject()).thenReturn(RpslObject.parse("inetnum: 192.0/24\nstatus: ASSIGNED ANYCAST")); when(update.getDifferences(AttributeType.MNT_LOWER)).thenReturn(ciSet("TEST-MNT")); when(updateContext.getSubject(update)).thenReturn(authenticationSubject); subject.validate(update, updateContext); verify(updateContext).addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } | @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } | MntLowerAddedRemoved implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } } | MntLowerAddedRemoved implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } } | MntLowerAddedRemoved implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | MntLowerAddedRemoved implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void modify_mntLower_removed_inetnum_override() { when(authenticationSubject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)).thenReturn(true); when(update.getType()).thenReturn(ObjectType.INETNUM); when(update.getReferenceObject()).thenReturn(RpslObject.parse("inetnum: 192.0/24\nstatus: ASSIGNED ANYCAST\nmnt-lower: TEST-MNT")); when(update.getUpdatedObject()).thenReturn(RpslObject.parse("inetnum: 192.0/24\nstatus: ASSIGNED ANYCAST")); when(updateContext.getSubject(update)).thenReturn(authenticationSubject); subject.validate(update, updateContext); verify(updateContext).getSubject(any(UpdateContainer.class)); verifyNoMoreInteractions(updateContext); } | @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } | MntLowerAddedRemoved implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } } | MntLowerAddedRemoved implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } } | MntLowerAddedRemoved implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | MntLowerAddedRemoved implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void modify_mntLower_removed_inet6num() { when(authenticationSubject.hasPrincipal(Principal.ENDUSER_MAINTAINER)).thenReturn(true); when(update.getType()).thenReturn(ObjectType.INET6NUM); when(update.getReferenceObject()).thenReturn(RpslObject.parse("inet6num: ffff::/48\nstatus: ASSIGNED ANYCAST\nmnt-lower: TEST-MNT")); when(update.getUpdatedObject()).thenReturn(RpslObject.parse("inet6num: ffff::/48\nstatus: ASSIGNED ANYCAST")); when(update.getDifferences(AttributeType.MNT_LOWER)).thenReturn(ciSet("TEST-MNT")); when(updateContext.getSubject(update)).thenReturn(authenticationSubject); subject.validate(update, updateContext); verify(updateContext).addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } | @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } | MntLowerAddedRemoved implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } } | MntLowerAddedRemoved implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } } | MntLowerAddedRemoved implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | MntLowerAddedRemoved implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void modify_mntLower_removed_override() { when(authenticationSubject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)).thenReturn(true); when(update.getType()).thenReturn(ObjectType.INET6NUM); when(update.getReferenceObject()).thenReturn(RpslObject.parse("inet6num: ffff::/48\nstatus: ASSIGNED ANYCAST\nmnt-lower: TEST-MNT")); when(update.getUpdatedObject()).thenReturn(RpslObject.parse("inet6num: ffff::/48\nstatus: ASSIGNED ANYCAST")); when(updateContext.getSubject(update)).thenReturn(authenticationSubject); subject.validate(update, updateContext); verify(updateContext).getSubject(any(UpdateContainer.class)); verifyNoMoreInteractions(updateContext); } | @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } | MntLowerAddedRemoved implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } } | MntLowerAddedRemoved implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } } | MntLowerAddedRemoved implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | MntLowerAddedRemoved implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void modify_mntLowers_same_inetnum() { when(update.getType()).thenReturn(ObjectType.INETNUM); when(update.getReferenceObject()).thenReturn(RpslObject.parse("inetnum: 192.0/24\nstatus: ASSIGNED ANYCAST\nmnt-lower: TEST-MNT")); when(update.getUpdatedObject()).thenReturn(RpslObject.parse("inetnum: 192.0/24\nstatus: ASSIGNED ANYCAST\nmnt-lower: TEST-MNT")); when(updateContext.getSubject(update)).thenReturn(authenticationSubject); subject.validate(update, updateContext); verify(updateContext, never()).addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } | @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } | MntLowerAddedRemoved implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } } | MntLowerAddedRemoved implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } } | MntLowerAddedRemoved implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | MntLowerAddedRemoved implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void modify_mntLowers_same_inetnum_override() { when(authenticationSubject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)).thenReturn(true); when(update.getType()).thenReturn(ObjectType.INETNUM); when(update.getReferenceObject()).thenReturn(RpslObject.parse("inetnum: 192.0/24\nstatus: ASSIGNED ANYCAST\nmnt-lower: TEST-MNT")); when(update.getUpdatedObject()).thenReturn(RpslObject.parse("inetnum: 192.0/24\nstatus: ASSIGNED ANYCAST\nmnt-lower: TEST-MNT")); when(updateContext.getSubject(update)).thenReturn(authenticationSubject); subject.validate(update, updateContext); verify(updateContext).getSubject(any(UpdateContainer.class)); verifyNoMoreInteractions(updateContext); } | @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } | MntLowerAddedRemoved implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } } | MntLowerAddedRemoved implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } } | MntLowerAddedRemoved implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | MntLowerAddedRemoved implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void modify_mntLowers_same_inet6num() { when(update.getType()).thenReturn(ObjectType.INET6NUM); when(update.getReferenceObject()).thenReturn(RpslObject.parse("inet6num: ffff::/24\nstatus: ASSIGNED ANYCAST\nmnt-lower: TEST-MNT")); when(update.getUpdatedObject()).thenReturn(RpslObject.parse("inet6num: ffff::/24\nstatus: ASSIGNED ANYCAST\nmnt-lower: TEST-MNT")); when(updateContext.getSubject(update)).thenReturn(authenticationSubject); subject.validate(update, updateContext); verify(updateContext, never()).addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } | @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } | MntLowerAddedRemoved implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } } | MntLowerAddedRemoved implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } } | MntLowerAddedRemoved implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | MntLowerAddedRemoved implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void modify_mntLowers_same_inet6num_override() { when(authenticationSubject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)).thenReturn(true); when(update.getType()).thenReturn(ObjectType.INET6NUM); when(update.getReferenceObject()).thenReturn(RpslObject.parse("inet6num: ffff::/24\nstatus: ASSIGNED ANYCAST\nmnt-lower: TEST-MNT")); when(update.getUpdatedObject()).thenReturn(RpslObject.parse("inet6num: ffff::/24\nstatus: ASSIGNED ANYCAST\nmnt-lower: TEST-MNT")); when(updateContext.getSubject(update)).thenReturn(authenticationSubject); subject.validate(update, updateContext); verify(updateContext).getSubject(any(UpdateContainer.class)); verifyNoMoreInteractions(updateContext); } | @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } | MntLowerAddedRemoved implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } } | MntLowerAddedRemoved implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } } | MntLowerAddedRemoved implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | MntLowerAddedRemoved implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void modify_authorisation_succeeds_inetnum() { when(update.getType()).thenReturn(ObjectType.INETNUM); when(update.getReferenceObject()).thenReturn(RpslObject.parse("inetnum: 192.0/24\nstatus: ASSIGNED ANYCAST\nmnt-lower: TEST-MNT")); when(update.getUpdatedObject()).thenReturn(RpslObject.parse("inetnum: 192.0/24\nstatus: ASSIGNED ANYCAST\nmnt-lower: OTHER-MNT")); when(authenticationSubject.hasPrincipal(any(Principal.class))).thenReturn(true); when(updateContext.getSubject(update)).thenReturn(authenticationSubject); subject.validate(update, updateContext); verify(updateContext, never()).addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } | @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } | MntLowerAddedRemoved implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } } | MntLowerAddedRemoved implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } } | MntLowerAddedRemoved implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | MntLowerAddedRemoved implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void modify_authorisation_succeeds_inet6num() { when(update.getType()).thenReturn(ObjectType.INET6NUM); when(update.getReferenceObject()).thenReturn(RpslObject.parse("inet6num: ffff/32\nstatus: ASSIGNED ANYCAST\nmnt-lower: TEST-MNT")); when(update.getUpdatedObject()).thenReturn(RpslObject.parse("inet6num: ffff::/32\nstatus: ASSIGNED ANYCAST\nmnt-lower: OTHER-MNT")); when(updateContext.getSubject(update)).thenReturn(authenticationSubject); subject.validate(update, updateContext); verify(updateContext, never()).addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } | @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } | MntLowerAddedRemoved implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } } | MntLowerAddedRemoved implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } } | MntLowerAddedRemoved implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | MntLowerAddedRemoved implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void transform_inetrtr_with_trailing_dot() { final RpslObject rpslObject = RpslObject.parse("" + "inet-rtr: test.ripe.net.\n" + "alias: alias.ripe.net"); final RpslObject result = attributeSanitizer.sanitize(rpslObject, objectMessages); assertThat(result.getValueForAttribute(AttributeType.INET_RTR).toString(), is("test.ripe.net")); verify(objectMessages).addMessage(result.findAttribute(AttributeType.INET_RTR), ValidationMessages.attributeValueConverted("test.ripe.net.", "test.ripe.net")); verifyNoMoreInteractions(objectMessages); } | public RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages) { final Map<RpslAttribute, RpslAttribute> replacements = Maps.newHashMap(); for (final RpslAttribute attribute : object.getAttributes()) { final AttributeType type = attribute.getType(); String newValue = null; final Sanitizer sanitizer = SANITIZER_MAP.get(type); if (sanitizer == null) { continue; } try { newValue = sanitizer.sanitize(attribute); } catch (IllegalArgumentException ignored) { LOGGER.debug("{}: {}", ignored.getClass().getName(), ignored.getMessage()); } if (newValue == null) { continue; } final List<Message> attributeMessages = Lists.newArrayList(); if (!sanitizer.silent() && !attribute.getCleanValue().toString().equals(newValue)) { attributeMessages.add(ValidationMessages.attributeValueConverted(attribute.getCleanValue(), newValue)); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('\n') != -1) { attributeMessages.add(ValidationMessages.continuationLinesRemoved()); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('#') != -1) { attributeMessages.add(ValidationMessages.remarksReformatted()); } final String replacement = newValue + getCommentReplacement(attribute); final RpslAttribute transformed = new RpslAttribute(attribute.getKey(), replacement); replacements.put(attribute, transformed); for (final Message attributeMessage : attributeMessages) { objectMessages.addMessage(transformed, attributeMessage); } } return new RpslObjectBuilder(object).replaceAttributes(replacements).get(); } | AttributeSanitizer { public RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages) { final Map<RpslAttribute, RpslAttribute> replacements = Maps.newHashMap(); for (final RpslAttribute attribute : object.getAttributes()) { final AttributeType type = attribute.getType(); String newValue = null; final Sanitizer sanitizer = SANITIZER_MAP.get(type); if (sanitizer == null) { continue; } try { newValue = sanitizer.sanitize(attribute); } catch (IllegalArgumentException ignored) { LOGGER.debug("{}: {}", ignored.getClass().getName(), ignored.getMessage()); } if (newValue == null) { continue; } final List<Message> attributeMessages = Lists.newArrayList(); if (!sanitizer.silent() && !attribute.getCleanValue().toString().equals(newValue)) { attributeMessages.add(ValidationMessages.attributeValueConverted(attribute.getCleanValue(), newValue)); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('\n') != -1) { attributeMessages.add(ValidationMessages.continuationLinesRemoved()); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('#') != -1) { attributeMessages.add(ValidationMessages.remarksReformatted()); } final String replacement = newValue + getCommentReplacement(attribute); final RpslAttribute transformed = new RpslAttribute(attribute.getKey(), replacement); replacements.put(attribute, transformed); for (final Message attributeMessage : attributeMessages) { objectMessages.addMessage(transformed, attributeMessage); } } return new RpslObjectBuilder(object).replaceAttributes(replacements).get(); } } | AttributeSanitizer { public RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages) { final Map<RpslAttribute, RpslAttribute> replacements = Maps.newHashMap(); for (final RpslAttribute attribute : object.getAttributes()) { final AttributeType type = attribute.getType(); String newValue = null; final Sanitizer sanitizer = SANITIZER_MAP.get(type); if (sanitizer == null) { continue; } try { newValue = sanitizer.sanitize(attribute); } catch (IllegalArgumentException ignored) { LOGGER.debug("{}: {}", ignored.getClass().getName(), ignored.getMessage()); } if (newValue == null) { continue; } final List<Message> attributeMessages = Lists.newArrayList(); if (!sanitizer.silent() && !attribute.getCleanValue().toString().equals(newValue)) { attributeMessages.add(ValidationMessages.attributeValueConverted(attribute.getCleanValue(), newValue)); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('\n') != -1) { attributeMessages.add(ValidationMessages.continuationLinesRemoved()); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('#') != -1) { attributeMessages.add(ValidationMessages.remarksReformatted()); } final String replacement = newValue + getCommentReplacement(attribute); final RpslAttribute transformed = new RpslAttribute(attribute.getKey(), replacement); replacements.put(attribute, transformed); for (final Message attributeMessage : attributeMessages) { objectMessages.addMessage(transformed, attributeMessage); } } return new RpslObjectBuilder(object).replaceAttributes(replacements).get(); } @Autowired AttributeSanitizer(DateTimeProvider dateTimeProvider); } | AttributeSanitizer { public RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages) { final Map<RpslAttribute, RpslAttribute> replacements = Maps.newHashMap(); for (final RpslAttribute attribute : object.getAttributes()) { final AttributeType type = attribute.getType(); String newValue = null; final Sanitizer sanitizer = SANITIZER_MAP.get(type); if (sanitizer == null) { continue; } try { newValue = sanitizer.sanitize(attribute); } catch (IllegalArgumentException ignored) { LOGGER.debug("{}: {}", ignored.getClass().getName(), ignored.getMessage()); } if (newValue == null) { continue; } final List<Message> attributeMessages = Lists.newArrayList(); if (!sanitizer.silent() && !attribute.getCleanValue().toString().equals(newValue)) { attributeMessages.add(ValidationMessages.attributeValueConverted(attribute.getCleanValue(), newValue)); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('\n') != -1) { attributeMessages.add(ValidationMessages.continuationLinesRemoved()); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('#') != -1) { attributeMessages.add(ValidationMessages.remarksReformatted()); } final String replacement = newValue + getCommentReplacement(attribute); final RpslAttribute transformed = new RpslAttribute(attribute.getKey(), replacement); replacements.put(attribute, transformed); for (final Message attributeMessage : attributeMessages) { objectMessages.addMessage(transformed, attributeMessage); } } return new RpslObjectBuilder(object).replaceAttributes(replacements).get(); } @Autowired AttributeSanitizer(DateTimeProvider dateTimeProvider); CIString sanitizeKey(final RpslObject originalObject); RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages); } | AttributeSanitizer { public RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages) { final Map<RpslAttribute, RpslAttribute> replacements = Maps.newHashMap(); for (final RpslAttribute attribute : object.getAttributes()) { final AttributeType type = attribute.getType(); String newValue = null; final Sanitizer sanitizer = SANITIZER_MAP.get(type); if (sanitizer == null) { continue; } try { newValue = sanitizer.sanitize(attribute); } catch (IllegalArgumentException ignored) { LOGGER.debug("{}: {}", ignored.getClass().getName(), ignored.getMessage()); } if (newValue == null) { continue; } final List<Message> attributeMessages = Lists.newArrayList(); if (!sanitizer.silent() && !attribute.getCleanValue().toString().equals(newValue)) { attributeMessages.add(ValidationMessages.attributeValueConverted(attribute.getCleanValue(), newValue)); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('\n') != -1) { attributeMessages.add(ValidationMessages.continuationLinesRemoved()); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('#') != -1) { attributeMessages.add(ValidationMessages.remarksReformatted()); } final String replacement = newValue + getCommentReplacement(attribute); final RpslAttribute transformed = new RpslAttribute(attribute.getKey(), replacement); replacements.put(attribute, transformed); for (final Message attributeMessage : attributeMessages) { objectMessages.addMessage(transformed, attributeMessage); } } return new RpslObjectBuilder(object).replaceAttributes(replacements).get(); } @Autowired AttributeSanitizer(DateTimeProvider dateTimeProvider); CIString sanitizeKey(final RpslObject originalObject); RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages); } |
@Test public void modify_fails_assigned_anycast_inetnum() { when(authenticationSubject.hasPrincipal(Principal.ENDUSER_MAINTAINER)).thenReturn(true); when(update.getType()).thenReturn(ObjectType.INETNUM); when(update.getDifferences(AttributeType.MNT_LOWER)).thenReturn(ciSet("OTHER-MNT")); when(update.getReferenceObject()).thenReturn(RpslObject.parse("inetnum: 192.0/24\nstatus: ASSIGNED ANYCAST\nmnt-lower: TEST-MNT")); when(update.getUpdatedObject()).thenReturn(RpslObject.parse("inetnum: 192.0/24\nstatus: ASSIGNED ANYCAST\nmnt-lower: OTHER-MNT")); when(updateContext.getSubject(update)).thenReturn(authenticationSubject); subject.validate(update, updateContext); verify(updateContext, times(1)).addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } | @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } | MntLowerAddedRemoved implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } } | MntLowerAddedRemoved implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } } | MntLowerAddedRemoved implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | MntLowerAddedRemoved implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } if (ObjectType.INETNUM.equals(update.getType()) && !VALIDATED_INETNUM_STATUSES.contains(getStatus(update))) { return; } if (ObjectType.INET6NUM.equals(update.getType()) && !VALIDATED_INET6NUM_STATUSES.contains(getStatus(update))) { return; } final Set<CIString> differences = update.getDifferences(AttributeType.MNT_LOWER); if (!differences.isEmpty() && !subject.hasPrincipal(Principal.RS_MAINTAINER)) { updateContext.addMessage(update, UpdateMessages.authorisationRequiredForAttrChange(AttributeType.MNT_LOWER)); } } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void testGetActions() { assertThat(subject.getActions(), containsInAnyOrder(Action.CREATE, Action.MODIFY)); } | @Override public ImmutableList<Action> getActions() { return ACTIONS; } | AsblockByRsMaintainersOnlyValidator implements BusinessRuleValidator { @Override public ImmutableList<Action> getActions() { return ACTIONS; } } | AsblockByRsMaintainersOnlyValidator implements BusinessRuleValidator { @Override public ImmutableList<Action> getActions() { return ACTIONS; } } | AsblockByRsMaintainersOnlyValidator implements BusinessRuleValidator { @Override public ImmutableList<Action> getActions() { return ACTIONS; } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | AsblockByRsMaintainersOnlyValidator implements BusinessRuleValidator { @Override public ImmutableList<Action> getActions() { return ACTIONS; } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void testGetTypes() { assertThat(subject.getTypes(), containsInAnyOrder(ObjectType.AS_BLOCK)); } | @Override public ImmutableList<ObjectType> getTypes() { return TYPES; } | AsblockByRsMaintainersOnlyValidator implements BusinessRuleValidator { @Override public ImmutableList<ObjectType> getTypes() { return TYPES; } } | AsblockByRsMaintainersOnlyValidator implements BusinessRuleValidator { @Override public ImmutableList<ObjectType> getTypes() { return TYPES; } } | AsblockByRsMaintainersOnlyValidator implements BusinessRuleValidator { @Override public ImmutableList<ObjectType> getTypes() { return TYPES; } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | AsblockByRsMaintainersOnlyValidator implements BusinessRuleValidator { @Override public ImmutableList<ObjectType> getTypes() { return TYPES; } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void validate_override_succeeds() { when(update.isOverride()).thenReturn(true); when(updateContext.getSubject(update)).thenReturn(subjectObject); when(subjectObject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)).thenReturn(true); subject.validate(update, updateContext); verify(updateContext, never()).addMessage(update, UpdateMessages.asblockIsMaintainedByRipe()); } | @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final boolean authenticatedByOverride = updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER); final boolean authenticatedByDbmMaintainer = updateContext.getSubject(update).hasPrincipal(Principal.DBM_MAINTAINER); if (!(authenticatedByOverride || authenticatedByDbmMaintainer)) { updateContext.addMessage(update, UpdateMessages.asblockIsMaintainedByRipe()); } } | AsblockByRsMaintainersOnlyValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final boolean authenticatedByOverride = updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER); final boolean authenticatedByDbmMaintainer = updateContext.getSubject(update).hasPrincipal(Principal.DBM_MAINTAINER); if (!(authenticatedByOverride || authenticatedByDbmMaintainer)) { updateContext.addMessage(update, UpdateMessages.asblockIsMaintainedByRipe()); } } } | AsblockByRsMaintainersOnlyValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final boolean authenticatedByOverride = updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER); final boolean authenticatedByDbmMaintainer = updateContext.getSubject(update).hasPrincipal(Principal.DBM_MAINTAINER); if (!(authenticatedByOverride || authenticatedByDbmMaintainer)) { updateContext.addMessage(update, UpdateMessages.asblockIsMaintainedByRipe()); } } } | AsblockByRsMaintainersOnlyValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final boolean authenticatedByOverride = updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER); final boolean authenticatedByDbmMaintainer = updateContext.getSubject(update).hasPrincipal(Principal.DBM_MAINTAINER); if (!(authenticatedByOverride || authenticatedByDbmMaintainer)) { updateContext.addMessage(update, UpdateMessages.asblockIsMaintainedByRipe()); } } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | AsblockByRsMaintainersOnlyValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final boolean authenticatedByOverride = updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER); final boolean authenticatedByDbmMaintainer = updateContext.getSubject(update).hasPrincipal(Principal.DBM_MAINTAINER); if (!(authenticatedByOverride || authenticatedByDbmMaintainer)) { updateContext.addMessage(update, UpdateMessages.asblockIsMaintainedByRipe()); } } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void validate_authenticatedByDbmMaintainer_succeeds() { when(update.isOverride()).thenReturn(false); when(updateContext.getSubject(update)).thenReturn(subjectObject); when(subjectObject.hasPrincipal(Principal.DBM_MAINTAINER)).thenReturn(true); subject.validate(update, updateContext); verify(updateContext, never()).addMessage(update, UpdateMessages.asblockIsMaintainedByRipe()); } | @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final boolean authenticatedByOverride = updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER); final boolean authenticatedByDbmMaintainer = updateContext.getSubject(update).hasPrincipal(Principal.DBM_MAINTAINER); if (!(authenticatedByOverride || authenticatedByDbmMaintainer)) { updateContext.addMessage(update, UpdateMessages.asblockIsMaintainedByRipe()); } } | AsblockByRsMaintainersOnlyValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final boolean authenticatedByOverride = updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER); final boolean authenticatedByDbmMaintainer = updateContext.getSubject(update).hasPrincipal(Principal.DBM_MAINTAINER); if (!(authenticatedByOverride || authenticatedByDbmMaintainer)) { updateContext.addMessage(update, UpdateMessages.asblockIsMaintainedByRipe()); } } } | AsblockByRsMaintainersOnlyValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final boolean authenticatedByOverride = updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER); final boolean authenticatedByDbmMaintainer = updateContext.getSubject(update).hasPrincipal(Principal.DBM_MAINTAINER); if (!(authenticatedByOverride || authenticatedByDbmMaintainer)) { updateContext.addMessage(update, UpdateMessages.asblockIsMaintainedByRipe()); } } } | AsblockByRsMaintainersOnlyValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final boolean authenticatedByOverride = updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER); final boolean authenticatedByDbmMaintainer = updateContext.getSubject(update).hasPrincipal(Principal.DBM_MAINTAINER); if (!(authenticatedByOverride || authenticatedByDbmMaintainer)) { updateContext.addMessage(update, UpdateMessages.asblockIsMaintainedByRipe()); } } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | AsblockByRsMaintainersOnlyValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final boolean authenticatedByOverride = updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER); final boolean authenticatedByDbmMaintainer = updateContext.getSubject(update).hasPrincipal(Principal.DBM_MAINTAINER); if (!(authenticatedByOverride || authenticatedByDbmMaintainer)) { updateContext.addMessage(update, UpdateMessages.asblockIsMaintainedByRipe()); } } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void validate_not_authenticatedByDbmMaintainer_or_override_fails() { when(update.isOverride()).thenReturn(false); when(updateContext.getSubject(update)).thenReturn(subjectObject); when(subjectObject.hasPrincipal(Principal.DBM_MAINTAINER)).thenReturn(false); subject.validate(update, updateContext); verify(updateContext).addMessage(update, UpdateMessages.asblockIsMaintainedByRipe()); } | @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final boolean authenticatedByOverride = updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER); final boolean authenticatedByDbmMaintainer = updateContext.getSubject(update).hasPrincipal(Principal.DBM_MAINTAINER); if (!(authenticatedByOverride || authenticatedByDbmMaintainer)) { updateContext.addMessage(update, UpdateMessages.asblockIsMaintainedByRipe()); } } | AsblockByRsMaintainersOnlyValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final boolean authenticatedByOverride = updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER); final boolean authenticatedByDbmMaintainer = updateContext.getSubject(update).hasPrincipal(Principal.DBM_MAINTAINER); if (!(authenticatedByOverride || authenticatedByDbmMaintainer)) { updateContext.addMessage(update, UpdateMessages.asblockIsMaintainedByRipe()); } } } | AsblockByRsMaintainersOnlyValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final boolean authenticatedByOverride = updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER); final boolean authenticatedByDbmMaintainer = updateContext.getSubject(update).hasPrincipal(Principal.DBM_MAINTAINER); if (!(authenticatedByOverride || authenticatedByDbmMaintainer)) { updateContext.addMessage(update, UpdateMessages.asblockIsMaintainedByRipe()); } } } | AsblockByRsMaintainersOnlyValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final boolean authenticatedByOverride = updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER); final boolean authenticatedByDbmMaintainer = updateContext.getSubject(update).hasPrincipal(Principal.DBM_MAINTAINER); if (!(authenticatedByOverride || authenticatedByDbmMaintainer)) { updateContext.addMessage(update, UpdateMessages.asblockIsMaintainedByRipe()); } } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } | AsblockByRsMaintainersOnlyValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final boolean authenticatedByOverride = updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER); final boolean authenticatedByDbmMaintainer = updateContext.getSubject(update).hasPrincipal(Principal.DBM_MAINTAINER); if (!(authenticatedByOverride || authenticatedByDbmMaintainer)) { updateContext.addMessage(update, UpdateMessages.asblockIsMaintainedByRipe()); } } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); } |
@Test public void testGetActions() { assertThat(subject.getActions(), containsInAnyOrder(Action.CREATE)); } | @Override public ImmutableList<Action> getActions() { return ACTIONS; } | AsblockHierarchyValidator implements BusinessRuleValidator { @Override public ImmutableList<Action> getActions() { return ACTIONS; } } | AsblockHierarchyValidator implements BusinessRuleValidator { @Override public ImmutableList<Action> getActions() { return ACTIONS; } @Autowired AsblockHierarchyValidator(final RpslObjectDao rpslObjectDao); } | AsblockHierarchyValidator implements BusinessRuleValidator { @Override public ImmutableList<Action> getActions() { return ACTIONS; } @Autowired AsblockHierarchyValidator(final RpslObjectDao rpslObjectDao); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); } | AsblockHierarchyValidator implements BusinessRuleValidator { @Override public ImmutableList<Action> getActions() { return ACTIONS; } @Autowired AsblockHierarchyValidator(final RpslObjectDao rpslObjectDao); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); } |
@Test public void testGetTypes() { assertThat(subject.getTypes(), containsInAnyOrder(ObjectType.AS_BLOCK)); } | @Override public ImmutableList<ObjectType> getTypes() { return TYPES; } | AsblockHierarchyValidator implements BusinessRuleValidator { @Override public ImmutableList<ObjectType> getTypes() { return TYPES; } } | AsblockHierarchyValidator implements BusinessRuleValidator { @Override public ImmutableList<ObjectType> getTypes() { return TYPES; } @Autowired AsblockHierarchyValidator(final RpslObjectDao rpslObjectDao); } | AsblockHierarchyValidator implements BusinessRuleValidator { @Override public ImmutableList<ObjectType> getTypes() { return TYPES; } @Autowired AsblockHierarchyValidator(final RpslObjectDao rpslObjectDao); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); } | AsblockHierarchyValidator implements BusinessRuleValidator { @Override public ImmutableList<ObjectType> getTypes() { return TYPES; } @Autowired AsblockHierarchyValidator(final RpslObjectDao rpslObjectDao); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); } |
@Test public void validate_asBlock_Parent_exists() { when(update.getUpdatedObject()).thenReturn(RpslObject.parse("as-block: AS10 - AS20")); when(updateContext.getSubject(update)).thenReturn(subjectObject); when(rpslObjectDao.findAsBlockIntersections(10L, 20L)).thenReturn(Lists.newArrayList(RpslObject.parse("as-block: AS1 - AS30"))); subject.validate(update, updateContext); verify(updateContext, times(1)).addMessage(update, UpdateMessages.asblockParentAlreadyExists()); } | @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { AsBlockRange asBlockNew = AsBlockRange.parse(update.getUpdatedObject().getKey().toString()); final List<RpslObject> intersections = rpslObjectDao.findAsBlockIntersections(asBlockNew.getBegin(), asBlockNew.getEnd()); for (final RpslObject intersection : intersections) { final AsBlockRange asBlockExisting = AsBlockRange.parse(intersection.getKey().toString()); if (asBlockExisting.equals(asBlockNew)) { updateContext.addMessage(update, UpdateMessages.asblockAlreadyExists()); } else if (asBlockExisting.contains(asBlockNew)) { updateContext.addMessage(update, UpdateMessages.asblockParentAlreadyExists()); } else if (asBlockNew.contains(asBlockExisting)) { updateContext.addMessage(update, UpdateMessages.asblockChildAlreadyExists()); } else { updateContext.addMessage(update, UpdateMessages.intersectingAsblockAlreadyExists()); } } } | AsblockHierarchyValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { AsBlockRange asBlockNew = AsBlockRange.parse(update.getUpdatedObject().getKey().toString()); final List<RpslObject> intersections = rpslObjectDao.findAsBlockIntersections(asBlockNew.getBegin(), asBlockNew.getEnd()); for (final RpslObject intersection : intersections) { final AsBlockRange asBlockExisting = AsBlockRange.parse(intersection.getKey().toString()); if (asBlockExisting.equals(asBlockNew)) { updateContext.addMessage(update, UpdateMessages.asblockAlreadyExists()); } else if (asBlockExisting.contains(asBlockNew)) { updateContext.addMessage(update, UpdateMessages.asblockParentAlreadyExists()); } else if (asBlockNew.contains(asBlockExisting)) { updateContext.addMessage(update, UpdateMessages.asblockChildAlreadyExists()); } else { updateContext.addMessage(update, UpdateMessages.intersectingAsblockAlreadyExists()); } } } } | AsblockHierarchyValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { AsBlockRange asBlockNew = AsBlockRange.parse(update.getUpdatedObject().getKey().toString()); final List<RpslObject> intersections = rpslObjectDao.findAsBlockIntersections(asBlockNew.getBegin(), asBlockNew.getEnd()); for (final RpslObject intersection : intersections) { final AsBlockRange asBlockExisting = AsBlockRange.parse(intersection.getKey().toString()); if (asBlockExisting.equals(asBlockNew)) { updateContext.addMessage(update, UpdateMessages.asblockAlreadyExists()); } else if (asBlockExisting.contains(asBlockNew)) { updateContext.addMessage(update, UpdateMessages.asblockParentAlreadyExists()); } else if (asBlockNew.contains(asBlockExisting)) { updateContext.addMessage(update, UpdateMessages.asblockChildAlreadyExists()); } else { updateContext.addMessage(update, UpdateMessages.intersectingAsblockAlreadyExists()); } } } @Autowired AsblockHierarchyValidator(final RpslObjectDao rpslObjectDao); } | AsblockHierarchyValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { AsBlockRange asBlockNew = AsBlockRange.parse(update.getUpdatedObject().getKey().toString()); final List<RpslObject> intersections = rpslObjectDao.findAsBlockIntersections(asBlockNew.getBegin(), asBlockNew.getEnd()); for (final RpslObject intersection : intersections) { final AsBlockRange asBlockExisting = AsBlockRange.parse(intersection.getKey().toString()); if (asBlockExisting.equals(asBlockNew)) { updateContext.addMessage(update, UpdateMessages.asblockAlreadyExists()); } else if (asBlockExisting.contains(asBlockNew)) { updateContext.addMessage(update, UpdateMessages.asblockParentAlreadyExists()); } else if (asBlockNew.contains(asBlockExisting)) { updateContext.addMessage(update, UpdateMessages.asblockChildAlreadyExists()); } else { updateContext.addMessage(update, UpdateMessages.intersectingAsblockAlreadyExists()); } } } @Autowired AsblockHierarchyValidator(final RpslObjectDao rpslObjectDao); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); } | AsblockHierarchyValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { AsBlockRange asBlockNew = AsBlockRange.parse(update.getUpdatedObject().getKey().toString()); final List<RpslObject> intersections = rpslObjectDao.findAsBlockIntersections(asBlockNew.getBegin(), asBlockNew.getEnd()); for (final RpslObject intersection : intersections) { final AsBlockRange asBlockExisting = AsBlockRange.parse(intersection.getKey().toString()); if (asBlockExisting.equals(asBlockNew)) { updateContext.addMessage(update, UpdateMessages.asblockAlreadyExists()); } else if (asBlockExisting.contains(asBlockNew)) { updateContext.addMessage(update, UpdateMessages.asblockParentAlreadyExists()); } else if (asBlockNew.contains(asBlockExisting)) { updateContext.addMessage(update, UpdateMessages.asblockChildAlreadyExists()); } else { updateContext.addMessage(update, UpdateMessages.intersectingAsblockAlreadyExists()); } } } @Autowired AsblockHierarchyValidator(final RpslObjectDao rpslObjectDao); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); } |
@Test public void validate_asBlock_intersects() { when(update.getUpdatedObject()).thenReturn(RpslObject.parse("as-block: AS10 - AS20")); when(updateContext.getSubject(update)).thenReturn(subjectObject); when(rpslObjectDao.findAsBlockIntersections(10L, 20L)).thenReturn(Lists.newArrayList(RpslObject.parse("as-block: AS15 - AS30"))); subject.validate(update, updateContext); verify(updateContext, times(1)).addMessage(update, UpdateMessages.intersectingAsblockAlreadyExists()); } | @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { AsBlockRange asBlockNew = AsBlockRange.parse(update.getUpdatedObject().getKey().toString()); final List<RpslObject> intersections = rpslObjectDao.findAsBlockIntersections(asBlockNew.getBegin(), asBlockNew.getEnd()); for (final RpslObject intersection : intersections) { final AsBlockRange asBlockExisting = AsBlockRange.parse(intersection.getKey().toString()); if (asBlockExisting.equals(asBlockNew)) { updateContext.addMessage(update, UpdateMessages.asblockAlreadyExists()); } else if (asBlockExisting.contains(asBlockNew)) { updateContext.addMessage(update, UpdateMessages.asblockParentAlreadyExists()); } else if (asBlockNew.contains(asBlockExisting)) { updateContext.addMessage(update, UpdateMessages.asblockChildAlreadyExists()); } else { updateContext.addMessage(update, UpdateMessages.intersectingAsblockAlreadyExists()); } } } | AsblockHierarchyValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { AsBlockRange asBlockNew = AsBlockRange.parse(update.getUpdatedObject().getKey().toString()); final List<RpslObject> intersections = rpslObjectDao.findAsBlockIntersections(asBlockNew.getBegin(), asBlockNew.getEnd()); for (final RpslObject intersection : intersections) { final AsBlockRange asBlockExisting = AsBlockRange.parse(intersection.getKey().toString()); if (asBlockExisting.equals(asBlockNew)) { updateContext.addMessage(update, UpdateMessages.asblockAlreadyExists()); } else if (asBlockExisting.contains(asBlockNew)) { updateContext.addMessage(update, UpdateMessages.asblockParentAlreadyExists()); } else if (asBlockNew.contains(asBlockExisting)) { updateContext.addMessage(update, UpdateMessages.asblockChildAlreadyExists()); } else { updateContext.addMessage(update, UpdateMessages.intersectingAsblockAlreadyExists()); } } } } | AsblockHierarchyValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { AsBlockRange asBlockNew = AsBlockRange.parse(update.getUpdatedObject().getKey().toString()); final List<RpslObject> intersections = rpslObjectDao.findAsBlockIntersections(asBlockNew.getBegin(), asBlockNew.getEnd()); for (final RpslObject intersection : intersections) { final AsBlockRange asBlockExisting = AsBlockRange.parse(intersection.getKey().toString()); if (asBlockExisting.equals(asBlockNew)) { updateContext.addMessage(update, UpdateMessages.asblockAlreadyExists()); } else if (asBlockExisting.contains(asBlockNew)) { updateContext.addMessage(update, UpdateMessages.asblockParentAlreadyExists()); } else if (asBlockNew.contains(asBlockExisting)) { updateContext.addMessage(update, UpdateMessages.asblockChildAlreadyExists()); } else { updateContext.addMessage(update, UpdateMessages.intersectingAsblockAlreadyExists()); } } } @Autowired AsblockHierarchyValidator(final RpslObjectDao rpslObjectDao); } | AsblockHierarchyValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { AsBlockRange asBlockNew = AsBlockRange.parse(update.getUpdatedObject().getKey().toString()); final List<RpslObject> intersections = rpslObjectDao.findAsBlockIntersections(asBlockNew.getBegin(), asBlockNew.getEnd()); for (final RpslObject intersection : intersections) { final AsBlockRange asBlockExisting = AsBlockRange.parse(intersection.getKey().toString()); if (asBlockExisting.equals(asBlockNew)) { updateContext.addMessage(update, UpdateMessages.asblockAlreadyExists()); } else if (asBlockExisting.contains(asBlockNew)) { updateContext.addMessage(update, UpdateMessages.asblockParentAlreadyExists()); } else if (asBlockNew.contains(asBlockExisting)) { updateContext.addMessage(update, UpdateMessages.asblockChildAlreadyExists()); } else { updateContext.addMessage(update, UpdateMessages.intersectingAsblockAlreadyExists()); } } } @Autowired AsblockHierarchyValidator(final RpslObjectDao rpslObjectDao); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); } | AsblockHierarchyValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { AsBlockRange asBlockNew = AsBlockRange.parse(update.getUpdatedObject().getKey().toString()); final List<RpslObject> intersections = rpslObjectDao.findAsBlockIntersections(asBlockNew.getBegin(), asBlockNew.getEnd()); for (final RpslObject intersection : intersections) { final AsBlockRange asBlockExisting = AsBlockRange.parse(intersection.getKey().toString()); if (asBlockExisting.equals(asBlockNew)) { updateContext.addMessage(update, UpdateMessages.asblockAlreadyExists()); } else if (asBlockExisting.contains(asBlockNew)) { updateContext.addMessage(update, UpdateMessages.asblockParentAlreadyExists()); } else if (asBlockNew.contains(asBlockExisting)) { updateContext.addMessage(update, UpdateMessages.asblockChildAlreadyExists()); } else { updateContext.addMessage(update, UpdateMessages.intersectingAsblockAlreadyExists()); } } } @Autowired AsblockHierarchyValidator(final RpslObjectDao rpslObjectDao); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); } |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.