From bc5b01b452f28373182d5f5bf53aeeedfef57c96 Mon Sep 17 00:00:00 2001 From: maggarwal13 <50230916+maggarwal13@users.noreply.github.com> Date: Tue, 30 Apr 2024 13:39:22 +0200 Subject: [PATCH] Nwi4 bug during modify- hierarchy check (#1451) * fix nwi4 bug for modify ALLOCATED-ASSIGNED PA with a child ASSIGNED PA * fix build * add tests * refactor * add tests * refactor * remove unused imports * javadocs * use subclass for modify * refactor --------- Co-authored-by: Ed Shryane --- .../integration/InetnumIntegrationSpec.groovy | 41 +++ .../update/InetnumStatusBetweenSpec.groovy | 88 ++++++ .../spec/update/InetnumStatusChildSpec.groovy | 270 ++++++++++++++++++ ...mModifyStrictStatusMandatoryValidator.java | 58 ++++ .../InetnumModifyStrictStatusValidator.java | 70 +++++ ...InetnumStrictStatusMandatoryValidator.java | 8 +- .../inetnum/InetnumStrictStatusValidator.java | 19 +- 7 files changed, 530 insertions(+), 24 deletions(-) create mode 100644 whois-update/src/main/java/net/ripe/db/whois/update/handler/validator/inetnum/InetnumModifyStrictStatusMandatoryValidator.java create mode 100644 whois-update/src/main/java/net/ripe/db/whois/update/handler/validator/inetnum/InetnumModifyStrictStatusValidator.java diff --git a/whois-endtoend/src/test/groovy/net/ripe/db/whois/spec/integration/InetnumIntegrationSpec.groovy b/whois-endtoend/src/test/groovy/net/ripe/db/whois/spec/integration/InetnumIntegrationSpec.groovy index 11c4f771a7..a925aecb98 100644 --- a/whois-endtoend/src/test/groovy/net/ripe/db/whois/spec/integration/InetnumIntegrationSpec.groovy +++ b/whois-endtoend/src/test/groovy/net/ripe/db/whois/spec/integration/InetnumIntegrationSpec.groovy @@ -617,6 +617,47 @@ class InetnumIntegrationSpec extends BaseWhoisSourceSpec { object/ } + + def "modify status ALLOCATED ASSIGNED PA status to ASSIGNED PA fails"() { + given: + def insertResponse = syncUpdate(new SyncUpdate(data: """\ + inetnum: 192.0.0.0/24 + netname: RIPE-NCC + descr: description + country: DK + admin-c: TEST-PN + tech-c: TEST-PN + status: ALLOCATED-ASSIGNED PA + mnt-by: RIPE-NCC-HM-MNT + mnt-by: TEST-MNT + org: ORG-TOL5-TEST + source: TEST + password: hm + password: update + """.stripIndent(true))) + when: + insertResponse =~ /SUCCESS/ + then: + def response = syncUpdate new SyncUpdate(data: """\ + inetnum: 192.0.0.0/24 + netname: RIPE-NCC + descr: description + country: DK + admin-c: TEST-PN + tech-c: TEST-PN + status: ASSIGNED PA + mnt-by: RIPE-NCC-HM-MNT + mnt-by: TEST-MNT + org: ORG-TOL5-TEST + source: TEST + password: update + """.stripIndent(true)) + then: + response =~ /Modify FAILED: \[inetnum\] 192.0.0.0 - 192.0.0.255/ + response =~ /\*\*\*Error: status value cannot be changed, you must delete and re-create the + object/ + } + def "handle failure of out-of-range CIDR notation"() { when: def response = syncUpdate(new SyncUpdate(data: """\ diff --git a/whois-endtoend/src/test/groovy/net/ripe/db/whois/spec/update/InetnumStatusBetweenSpec.groovy b/whois-endtoend/src/test/groovy/net/ripe/db/whois/spec/update/InetnumStatusBetweenSpec.groovy index 14dccbb455..297abf4616 100644 --- a/whois-endtoend/src/test/groovy/net/ripe/db/whois/spec/update/InetnumStatusBetweenSpec.groovy +++ b/whois-endtoend/src/test/groovy/net/ripe/db/whois/spec/update/InetnumStatusBetweenSpec.groovy @@ -299,6 +299,50 @@ class InetnumStatusBetweenSpec extends BaseQueryUpdateSpec { queryObjectNotFound("-rGBT inetnum 192.100.0.0 - 192.200.255.255", "inetnum", "192.100.0.0 - 192.200.255.255") } + def "create between ALLOCATED UNSPECIFIED and ALLOCATED UNSPECIFIED, with status ALLOCATED-ASSIGNED PA"() { + given: + syncUpdate(getTransient("ALLOC-UNS") + "password: owner3\npassword: hm") + queryObject("-r -T inetnum 192.0.0.0 - 192.255.255.255", "inetnum", "192.0.0.0 - 192.255.255.255") + syncUpdate(getTransient("ALLOC-UNS2") + "password: owner3\npassword: hm") + queryObject("-r -T inetnum 192.168.0.0 - 192.169.255.255", "inetnum", "192.168.0.0 - 192.169.255.255") + + expect: + queryObjectNotFound("-r -T inetnum 192.100.0.0 - 192.200.255.255", "inetnum", "192.100.0.0 - 192.200.255.255") + + when: + def ack = syncUpdateWithResponse("""\ + inetnum: 192.100.0.0 - 192.200.255.255 + netname: TEST-NET-NAME + descr: TEST network + country: NL + org: ORG-LIR1-TEST + admin-c: TP1-TEST + tech-c: TP1-TEST + status: ALLOCATED-ASSIGNED PA + mnt-by: RIPE-NCC-HM-MNT + mnt-lower: LIR-MNT + source: TEST + + password: hm + password: owner3 + password: lir + """.stripIndent(true) + ) + + then: + + ack.summary.nrFound == 1 + ack.summary.assertSuccess(0, 0, 0, 0, 0) + ack.summary.assertErrors(1, 1, 0, 0) + + ack.countErrorWarnInfo(1, 0, 0) + ack.errors.any { it.operation == "Create" && it.key == "[inetnum] 192.100.0.0 - 192.200.255.255" } + ack.errorMessagesFor("Create", "[inetnum] 192.100.0.0 - 192.200.255.255") == + ["Status ALLOCATED-ASSIGNED PA not allowed when more specific object '192.168.0.0 - 192.169.255.255' has status ALLOCATED UNSPECIFIED"] + + queryObjectNotFound("-rGBT inetnum 192.100.0.0 - 192.200.255.255", "inetnum", "192.100.0.0 - 192.200.255.255") + } + def "create between ALLOCATED UNSPECIFIED and ALLOCATED UNSPECIFIED, with status LIR-PARTITIONED PA"() { given: syncUpdate(getTransient("ALLOC-UNS") + "password: owner3\npassword: hm") @@ -649,6 +693,50 @@ class InetnumStatusBetweenSpec extends BaseQueryUpdateSpec { queryObjectNotFound("-rGBT inetnum 192.100.0.0 - 192.200.255.255", "inetnum", "192.100.0.0 - 192.200.255.255") } + def "create between ALLOCATED UNSPECIFIED and ALLOCATED PA, with status ALLOCATED-ASSIGNED PA"() { + given: + syncUpdate(getTransient("ALLOC-UNS") + "password: owner3\npassword: hm") + queryObject("-r -T inetnum 192.0.0.0 - 192.255.255.255", "inetnum", "192.0.0.0 - 192.255.255.255") + syncUpdate(getTransient("ALLOC-PA") + "password: owner3\npassword: hm") + queryObject("-r -T inetnum 192.168.0.0 - 192.169.255.255", "inetnum", "192.168.0.0 - 192.169.255.255") + + expect: + queryObjectNotFound("-r -T inetnum 192.100.0.0 - 192.200.255.255", "inetnum", "192.100.0.0 - 192.200.255.255") + + when: + def ack = syncUpdateWithResponse("""\ + inetnum: 192.100.0.0 - 192.200.255.255 + netname: TEST-NET-NAME + descr: TEST network + country: NL + org: ORG-LIR1-TEST + admin-c: TP1-TEST + tech-c: TP1-TEST + status: ALLOCATED-ASSIGNED PA + mnt-by: RIPE-NCC-HM-MNT + mnt-lower: LIR-MNT + source: TEST + + password: hm + password: owner3 + password: lir + """.stripIndent(true) + ) + + then: + + ack.summary.nrFound == 1 + ack.summary.assertSuccess(0, 0, 0, 0, 0) + ack.summary.assertErrors(1, 1, 0, 0) + + ack.countErrorWarnInfo(1, 0, 0) + ack.errors.any { it.operation == "Create" && it.key == "[inetnum] 192.100.0.0 - 192.200.255.255" } + ack.errorMessagesFor("Create", "[inetnum] 192.100.0.0 - 192.200.255.255") == + ["Status ALLOCATED-ASSIGNED PA not allowed when more specific object '192.168.0.0 - 192.169.255.255' has status ALLOCATED PA"] + + queryObjectNotFound("-rGBT inetnum 192.100.0.0 - 192.200.255.255", "inetnum", "192.100.0.0 - 192.200.255.255") + } + def "create between ALLOCATED UNSPECIFIED and ALLOCATED PA, with status LIR-PARTITIONED PA"() { given: syncUpdate(getTransient("ALLOC-UNS") + "password: owner3\npassword: hm") diff --git a/whois-endtoend/src/test/groovy/net/ripe/db/whois/spec/update/InetnumStatusChildSpec.groovy b/whois-endtoend/src/test/groovy/net/ripe/db/whois/spec/update/InetnumStatusChildSpec.groovy index cafa30896a..338f18401f 100644 --- a/whois-endtoend/src/test/groovy/net/ripe/db/whois/spec/update/InetnumStatusChildSpec.groovy +++ b/whois-endtoend/src/test/groovy/net/ripe/db/whois/spec/update/InetnumStatusChildSpec.groovy @@ -4087,4 +4087,274 @@ class InetnumStatusChildSpec extends BaseQueryUpdateSpec { ack.warningSuccessMessagesFor("Modify", "[inetnum] 192.168.200.0 - 192.168.200.127") == ["inetnum parent has incorrect status: ASSIGNED PA"] } + + def "modify parent ALLOCATED PA to ALLOCATED-ASSIGNED PA, child status ASSIGNED PA"() { + given: + syncUpdate(getTransient("ALLOC-PA") + "password: owner3\npassword: hm") + queryObject("-r -T inetnum 192.168.0.0 - 192.169.255.255", "inetnum", "192.168.0.0 - 192.169.255.255") + dbfixture("""\ + inetnum: 192.168.200.0 - 192.168.200.127 + netname: RIPE-NET1 + descr: /27 assigned + country: NL + admin-c: TP1-TEST + tech-c: TP1-TEST + status: ASSIGNED PA + mnt-by: END-USER-MNT + source: TEST + """.stripIndent(true)) + expect: + queryObject("-r -T inetnum 192.168.200.0 - 192.168.200.127", "inetnum", "192.168.200.0 - 192.168.200.127") + + when: + def ack = syncUpdateWithResponse("""\ + inetnum: 192.168.0.0 - 192.169.255.255 + netname: TEST-NET-NAME + descr: TEST network + country: NL + org: ORG-LIR1-TEST + admin-c: TP1-TEST + tech-c: TP1-TEST + status: ALLOCATED-ASSIGNED PA + mnt-by: RIPE-NCC-HM-MNT + mnt-lower: LIR-MNT + mnt-lower: LIR2-MNT + source: TEST + + password: owner3 + password: hm + """.stripIndent(true) + ) + + then: + + ack.summary.nrFound == 1 + ack.summary.assertErrors(1, 0, 1, 0) + + ack.countErrorWarnInfo(1, 0, 0) + ack.errors.any { it.operation == "Modify" && it.key == "[inetnum] 192.168.0.0 - 192.169.255.255" } + ack.errorMessagesFor("Modify", "[inetnum] 192.168.0.0 - 192.169.255.255") == + ["Status ALLOCATED-ASSIGNED PA not allowed when more specific object '192.168.200.0 - 192.168.200.127' has status ASSIGNED PA"] + } + + def "modify parent ALLOCATED PA to ALLOCATED-ASSIGNED PA, child status ASSIGNED PA, using override"() { + given: + syncUpdate(getTransient("ALLOC-PA") + "password: owner3\npassword: hm") + queryObject("-r -T inetnum 192.168.0.0 - 192.169.255.255", "inetnum", "192.168.0.0 - 192.169.255.255") + dbfixture("""\ + inetnum: 192.168.200.0 - 192.168.200.127 + netname: RIPE-NET1 + descr: /27 assigned + country: NL + admin-c: TP1-TEST + tech-c: TP1-TEST + status: ASSIGNED PA + mnt-by: END-USER-MNT + source: TEST + """.stripIndent(true)) + expect: + queryObject("-r -T inetnum 192.168.200.0 - 192.168.200.127", "inetnum", "192.168.200.0 - 192.168.200.127") + + when: + def ack = syncUpdateWithResponse("""\ + inetnum: 192.168.0.0 - 192.169.255.255 + netname: TEST-NET-NAME + descr: TEST network + country: NL + org: ORG-LIR1-TEST + admin-c: TP1-TEST + tech-c: TP1-TEST + status: ALLOCATED-ASSIGNED PA + mnt-by: RIPE-NCC-HM-MNT + mnt-lower: LIR-MNT + mnt-lower: LIR2-MNT + source: TEST + override: denis,override1 + """.stripIndent(true) + ) + + then: + + ack.summary.nrFound == 1 + ack.summary.assertErrors(1, 0, 1, 0) + + ack.countErrorWarnInfo(1, 0, 1) + ack.errors.any { it.operation == "Modify" && it.key == "[inetnum] 192.168.0.0 - 192.169.255.255" } + ack.errorMessagesFor("Modify", "[inetnum] 192.168.0.0 - 192.169.255.255") == + ["Status ALLOCATED-ASSIGNED PA not allowed when more specific object '192.168.200.0 - 192.168.200.127' has status ASSIGNED PA"] + } + + def "modify ALLOCATED PA to ALLOCATED-ASSIGNED PA, parent status ASSIGNED PA"() { + given: + syncUpdate(getTransient("ALLOC-UNS") + "password: owner3\npassword: hm") + queryObject("-r -T inetnum 192.0.0.0 - 192.255.255.255", "inetnum", "192.0.0.0 - 192.255.255.255") + dbfixture("""\ + inetnum: 192.168.0.0 - 192.169.255.255 + netname: TEST-NET-NAME + descr: TEST network + country: NL + org: ORG-HR1-TEST + admin-c: TP1-TEST + tech-c: TP1-TEST + status: ALLOCATED PA + mnt-by: RIPE-NCC-HM-MNT + mnt-lower: LIR-MNT + source: TEST + """.stripIndent(true)) + expect: + queryObject("-r -T inetnum 192.168.0.0 - 192.169.255.255", "inetnum", "192.168.0.0 - 192.169.255.255") + + when: + def response = syncUpdateWithResponse("""\ + inetnum: 192.168.0.0 - 192.169.255.255 + netname: TEST-NET-NAME + descr: TEST network + country: NL + org: ORG-HR1-TEST + admin-c: TP1-TEST + tech-c: TP1-TEST + status: ALLOCATED-ASSIGNED PA + mnt-by: RIPE-NCC-HM-MNT + mnt-lower: LIR-MNT + source: TEST + + password: hm + """.stripIndent(true) + ) + + then: + + response =~ /SUCCESS/ + response =~ /Modify SUCCEEDED: \[inetnum\] 192.168.0.0 - 192.169.255.255/ + } + + def "modify ALLOCATED PA to ALLOCATED-ASSIGNED PA, parent status ASSIGNED PA, using override"() { + given: + syncUpdate(getTransient("ALLOC-UNS") + "password: owner3\npassword: hm") + queryObject("-r -T inetnum 192.0.0.0 - 192.255.255.255", "inetnum", "192.0.0.0 - 192.255.255.255") + dbfixture("""\ + inetnum: 192.168.0.0 - 192.169.255.255 + netname: TEST-NET-NAME + descr: TEST network + country: NL + org: ORG-HR1-TEST + admin-c: TP1-TEST + tech-c: TP1-TEST + status: ALLOCATED PA + mnt-by: RIPE-NCC-HM-MNT + mnt-lower: LIR-MNT + source: TEST + """.stripIndent(true)) + expect: + queryObject("-r -T inetnum 192.168.0.0 - 192.169.255.255", "inetnum", "192.168.0.0 - 192.169.255.255") + + when: + def response = syncUpdateWithResponse("""\ + inetnum: 192.168.0.0 - 192.169.255.255 + netname: TEST-NET-NAME + descr: TEST network + country: NL + org: ORG-HR1-TEST + admin-c: TP1-TEST + tech-c: TP1-TEST + status: ALLOCATED-ASSIGNED PA + mnt-by: RIPE-NCC-HM-MNT + mnt-lower: LIR-MNT + source: TEST + override: denis,override1 + """.stripIndent(true) + ) + + then: + + response =~ /SUCCESS/ + response =~ /Modify SUCCEEDED: \[inetnum\] 192.168.0.0 - 192.169.255.255/ + } + + def "modify ALLOCATED-ASSIGNED PA to ALLOCATED PA, parent status ASSIGNED PA, using override"() { + given: + syncUpdate(getTransient("ALLOC-UNS") + "password: owner3\npassword: hm") + queryObject("-r -T inetnum 192.0.0.0 - 192.255.255.255", "inetnum", "192.0.0.0 - 192.255.255.255") + dbfixture("""\ + inetnum: 192.168.0.0 - 192.169.255.255 + netname: TEST-NET-NAME + descr: TEST network + country: NL + org: ORG-HR1-TEST + admin-c: TP1-TEST + tech-c: TP1-TEST + status: ALLOCATED-ASSIGNED PA + mnt-by: RIPE-NCC-HM-MNT + mnt-lower: LIR-MNT + source: TEST + """.stripIndent(true)) + expect: + queryObject("-r -T inetnum 192.168.0.0 - 192.169.255.255", "inetnum", "192.168.0.0 - 192.169.255.255") + + when: + def response = syncUpdateWithResponse("""\ + inetnum: 192.168.0.0 - 192.169.255.255 + netname: TEST-NET-NAME + descr: TEST network + country: NL + org: ORG-HR1-TEST + admin-c: TP1-TEST + tech-c: TP1-TEST + status: ALLOCATED PA + mnt-by: RIPE-NCC-HM-MNT + mnt-lower: LIR-MNT + source: TEST + override: denis,override1 + """.stripIndent(true) + ) + + then: + + response =~ /SUCCESS/ + response =~ /Modify SUCCEEDED: \[inetnum\] 192.168.0.0 - 192.169.255.255/ + } + + def "modify ALLOCATED-ASSIGNED PA to ALLOCATED PA, parent status ASSIGNED PA"() { + given: + syncUpdate(getTransient("ALLOC-UNS") + "password: owner3\npassword: hm") + queryObject("-r -T inetnum 192.0.0.0 - 192.255.255.255", "inetnum", "192.0.0.0 - 192.255.255.255") + dbfixture("""\ + inetnum: 192.168.0.0 - 192.169.255.255 + netname: TEST-NET-NAME + descr: TEST network + country: NL + org: ORG-HR1-TEST + admin-c: TP1-TEST + tech-c: TP1-TEST + status: ALLOCATED-ASSIGNED PA + mnt-by: RIPE-NCC-HM-MNT + mnt-lower: LIR-MNT + source: TEST + """.stripIndent(true)) + expect: + queryObject("-r -T inetnum 192.168.0.0 - 192.169.255.255", "inetnum", "192.168.0.0 - 192.169.255.255") + + when: + def response = syncUpdateWithResponse("""\ + inetnum: 192.168.0.0 - 192.169.255.255 + netname: TEST-NET-NAME + descr: TEST network + country: NL + org: ORG-HR1-TEST + admin-c: TP1-TEST + tech-c: TP1-TEST + status: ALLOCATED PA + mnt-by: RIPE-NCC-HM-MNT + mnt-lower: LIR-MNT + source: TEST + + password: hm + """.stripIndent(true) + ) + + then: + + response =~ /SUCCESS/ + response =~ /Modify SUCCEEDED: \[inetnum\] 192.168.0.0 - 192.169.255.255/ + } } diff --git a/whois-update/src/main/java/net/ripe/db/whois/update/handler/validator/inetnum/InetnumModifyStrictStatusMandatoryValidator.java b/whois-update/src/main/java/net/ripe/db/whois/update/handler/validator/inetnum/InetnumModifyStrictStatusMandatoryValidator.java new file mode 100644 index 0000000000..9b02079da0 --- /dev/null +++ b/whois-update/src/main/java/net/ripe/db/whois/update/handler/validator/inetnum/InetnumModifyStrictStatusMandatoryValidator.java @@ -0,0 +1,58 @@ +package net.ripe.db.whois.update.handler.validator.inetnum; + +import com.google.common.collect.ImmutableList; +import net.ripe.db.whois.common.Message; +import net.ripe.db.whois.common.dao.RpslObjectDao; +import net.ripe.db.whois.common.dao.StatusDao; +import net.ripe.db.whois.common.domain.Maintainers; +import net.ripe.db.whois.common.iptree.Ipv4Tree; +import net.ripe.db.whois.common.rpsl.ObjectType; +import net.ripe.db.whois.update.domain.Action; +import net.ripe.db.whois.update.domain.PreparedUpdate; +import net.ripe.db.whois.update.domain.UpdateContext; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.Collections; +import java.util.List; +import static net.ripe.db.whois.update.domain.Action.MODIFY; +import static net.ripe.db.whois.update.handler.validator.inetnum.InetnumModifyStrictStatusValidator.canSkipValidation; + +/** + * Apply stricter status validation when modifying an inetnum object. + */ +@Component +public class InetnumModifyStrictStatusMandatoryValidator extends InetnumStrictStatusMandatoryValidator { + + private static final ImmutableList ACTIONS = ImmutableList.of(MODIFY); + private static final ImmutableList TYPES = ImmutableList.of(ObjectType.INETNUM); + + + @Autowired + public InetnumModifyStrictStatusMandatoryValidator( + final RpslObjectDao objectDao, + final StatusDao statusDao, + final Ipv4Tree ipv4Tree, + final Maintainers maintainers) { + super(objectDao, statusDao, ipv4Tree, maintainers); + } + + @Override + public List performValidation(final PreparedUpdate update, final UpdateContext updateContext) { + if(canSkipValidation(update)) { + return Collections.EMPTY_LIST; + } + + return validateStatusAgainstResourcesInTree(update, updateContext); + } + + @Override + public ImmutableList getActions() { + return ACTIONS; + } + + @Override + public ImmutableList getTypes() { + return TYPES; + } +} diff --git a/whois-update/src/main/java/net/ripe/db/whois/update/handler/validator/inetnum/InetnumModifyStrictStatusValidator.java b/whois-update/src/main/java/net/ripe/db/whois/update/handler/validator/inetnum/InetnumModifyStrictStatusValidator.java new file mode 100644 index 0000000000..0881ad47bf --- /dev/null +++ b/whois-update/src/main/java/net/ripe/db/whois/update/handler/validator/inetnum/InetnumModifyStrictStatusValidator.java @@ -0,0 +1,70 @@ +package net.ripe.db.whois.update.handler.validator.inetnum; + +import com.google.common.collect.ImmutableList; +import net.ripe.db.whois.common.Message; +import net.ripe.db.whois.common.dao.RpslObjectDao; +import net.ripe.db.whois.common.dao.StatusDao; +import net.ripe.db.whois.common.domain.Maintainers; +import net.ripe.db.whois.common.iptree.Ipv4Tree; +import net.ripe.db.whois.common.rpsl.AttributeType; +import net.ripe.db.whois.common.rpsl.ObjectType; +import net.ripe.db.whois.common.rpsl.attrs.InetnumStatus; +import net.ripe.db.whois.update.domain.Action; +import net.ripe.db.whois.update.domain.PreparedUpdate; +import net.ripe.db.whois.update.domain.UpdateContext; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.Collections; +import java.util.List; +import static net.ripe.db.whois.update.domain.Action.MODIFY; + +/** + * Apply stricter status validation when modifying an inetnum object. + */ +@Component +public class InetnumModifyStrictStatusValidator extends InetnumStrictStatusValidator { + + private static final ImmutableList ACTIONS = ImmutableList.of(MODIFY); + private static final ImmutableList TYPES = ImmutableList.of(ObjectType.INETNUM); + + @Autowired + public InetnumModifyStrictStatusValidator( + final RpslObjectDao objectDao, + final StatusDao statusDao, + final Ipv4Tree ipv4Tree, + final Maintainers maintainers) { + super(objectDao, statusDao, ipv4Tree, maintainers); + + } + + @Override + public List performValidation(final PreparedUpdate update, final UpdateContext updateContext) { + if(canSkipValidation(update)) { + return Collections.EMPTY_LIST; + } + + return validateStatusAgainstResourcesInTree(update, updateContext); + } + + protected static boolean canSkipValidation(final PreparedUpdate update) { + final InetnumStatus originalStatus = InetnumStatus.getStatusFor(update.getReferenceObject().getValueForAttribute(AttributeType.STATUS)); + final InetnumStatus updateStatus = InetnumStatus.getStatusFor(update.getUpdatedObject().getValueForAttribute(AttributeType.STATUS)); + + return (originalStatus == updateStatus) || !InetnumStatusValidator.canChangeStatus(originalStatus, updateStatus); + } + + @Override + public boolean isSkipForOverride() { + return true; + } + @Override + public ImmutableList getActions() { + return ACTIONS; + } + + @Override + public ImmutableList getTypes() { + return TYPES; + } +} diff --git a/whois-update/src/main/java/net/ripe/db/whois/update/handler/validator/inetnum/InetnumStrictStatusMandatoryValidator.java b/whois-update/src/main/java/net/ripe/db/whois/update/handler/validator/inetnum/InetnumStrictStatusMandatoryValidator.java index 2ade38831c..9b3995e647 100644 --- a/whois-update/src/main/java/net/ripe/db/whois/update/handler/validator/inetnum/InetnumStrictStatusMandatoryValidator.java +++ b/whois-update/src/main/java/net/ripe/db/whois/update/handler/validator/inetnum/InetnumStrictStatusMandatoryValidator.java @@ -16,8 +16,6 @@ import net.ripe.db.whois.common.rpsl.RpslAttribute; import net.ripe.db.whois.common.rpsl.RpslObject; import net.ripe.db.whois.common.rpsl.attrs.InetnumStatus; -import net.ripe.db.whois.update.authentication.Principal; -import net.ripe.db.whois.update.authentication.Subject; import net.ripe.db.whois.update.domain.Action; import net.ripe.db.whois.update.domain.PreparedUpdate; import net.ripe.db.whois.update.domain.UpdateContext; @@ -72,7 +70,7 @@ private List validateCreate(final PreparedUpdate update, final UpdateCo } @SuppressWarnings("unchecked") - private List validateStatusAgainstResourcesInTree(final PreparedUpdate update, final UpdateContext updateContext) { + protected List validateStatusAgainstResourcesInTree(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final Ipv4Resource ipInterval = Ipv4Resource.parse(updatedObject.getKey()); final List validationMessages = Lists.newArrayList(); @@ -123,10 +121,6 @@ private List validateStatusAgainstResourcesInTree(final PreparedUpdate return validationMessages; } - private boolean authByRs(final Subject subject) { - return subject.hasPrincipal(Principal.RS_MAINTAINER); - } - private boolean checkAuthorizationForStatusInHierarchy(final PreparedUpdate update, final Ipv4Resource ipInterval) { final RpslObject parentInHierarchyMaintainedByRs = findParentWithRsMaintainer(ipInterval); diff --git a/whois-update/src/main/java/net/ripe/db/whois/update/handler/validator/inetnum/InetnumStrictStatusValidator.java b/whois-update/src/main/java/net/ripe/db/whois/update/handler/validator/inetnum/InetnumStrictStatusValidator.java index 2efc42650c..fa2e3f893a 100644 --- a/whois-update/src/main/java/net/ripe/db/whois/update/handler/validator/inetnum/InetnumStrictStatusValidator.java +++ b/whois-update/src/main/java/net/ripe/db/whois/update/handler/validator/inetnum/InetnumStrictStatusValidator.java @@ -39,7 +39,7 @@ @Component public class InetnumStrictStatusValidator implements BusinessRuleValidator { - private static final ImmutableList ACTIONS = ImmutableList.of(CREATE, MODIFY); + private static final ImmutableList ACTIONS = ImmutableList.of(CREATE); private static final ImmutableList TYPES = ImmutableList.of(ObjectType.INETNUM); private final RpslObjectDao objectDao; @@ -61,10 +61,6 @@ public InetnumStrictStatusValidator( @Override public List performValidation(final PreparedUpdate update, final UpdateContext updateContext) { - if(canSkipValidation(update)) { - return Collections.EMPTY_LIST; - } - return validateCreate(update, updateContext); } @@ -73,7 +69,7 @@ private List validateCreate(final PreparedUpdate update, final UpdateCo } @SuppressWarnings("unchecked") - private List validateStatusAgainstResourcesInTree(final PreparedUpdate update, final UpdateContext updateContext) { + protected List validateStatusAgainstResourcesInTree(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final Ipv4Resource ipInterval = Ipv4Resource.parse(updatedObject.getKey()); final List validationMessages = Lists.newArrayList(); @@ -116,17 +112,6 @@ private void validateLegacyStatus(final InetnumStatus currentStatus, final Inetn } } - private boolean canSkipValidation(final PreparedUpdate update) { - if(update.getAction() == CREATE) { - return false; - } - - final InetnumStatus originalStatus = InetnumStatus.getStatusFor(update.getReferenceObject().getValueForAttribute(AttributeType.STATUS)); - final InetnumStatus updateStatus = InetnumStatus.getStatusFor(update.getUpdatedObject().getValueForAttribute(AttributeType.STATUS)); - - return (originalStatus == updateStatus) || !InetnumStatusValidator.canChangeStatus(originalStatus, updateStatus); - } - @Override public boolean isSkipForOverride() { return true;