From 719afdb6650e3fd7b2c0896712aa808837b81a25 Mon Sep 17 00:00:00 2001 From: Rob Miller Date: Wed, 14 Sep 2016 13:20:21 +0200 Subject: [PATCH] Dbf 70 references api doesnt handle multiple (#404) * Basic fix for missing auth attribute in old mntner objects causing deletion problem * now uses a property map instead of single named properties * fixed property * property missing from test properties file * fixed possible null pointer exception * missed a final * do not need to substitute '-' by using literals as keys in properties * will cater for identical values when dummifying * corrected formatting * typo * ignored test now passes, removing ignore --- .../db/whois/api/rest/ReferencesService.java | 5 +- .../ReferencesServiceTestIntegration.java | 158 +++++++++++------- 2 files changed, 99 insertions(+), 64 deletions(-) diff --git a/whois-api/src/main/java/net/ripe/db/whois/api/rest/ReferencesService.java b/whois-api/src/main/java/net/ripe/db/whois/api/rest/ReferencesService.java index e33fa77eb5..f0b5274494 100644 --- a/whois-api/src/main/java/net/ripe/db/whois/api/rest/ReferencesService.java +++ b/whois-api/src/main/java/net/ripe/db/whois/api/rest/ReferencesService.java @@ -651,9 +651,8 @@ private RpslObjectWithReplacements replaceReferences(final RpslObject object, fi } final RpslObjectBuilder builder = new RpslObjectBuilder(object); - for (Map.Entry entry : replacements.entrySet()) { - builder.replaceAttribute(entry.getKey(), entry.getValue()); - } + builder.replaceAttributes(replacements); + return new RpslObjectWithReplacements(builder.get(), replacements); } diff --git a/whois-api/src/test/java/net/ripe/db/whois/api/rest/ReferencesServiceTestIntegration.java b/whois-api/src/test/java/net/ripe/db/whois/api/rest/ReferencesServiceTestIntegration.java index 12c880f464..339f64d82a 100644 --- a/whois-api/src/test/java/net/ripe/db/whois/api/rest/ReferencesServiceTestIntegration.java +++ b/whois-api/src/test/java/net/ripe/db/whois/api/rest/ReferencesServiceTestIntegration.java @@ -307,11 +307,11 @@ public void update_create_multiple_objects_successfully() { public void update_create_multiple_objects_and_delete_successfully() { final RpslObject firstPerson = RpslObject.parse( "person: Test Person\n" + - "address: Singel 258\n" + - "phone: +31 6 12345678\n" + - "nic-hdl: TP2-TEST\n" + - "mnt-by: OWNER-MNT\n" + - "source: TEST"); + "address: Singel 258\n" + + "phone: +31 6 12345678\n" + + "nic-hdl: TP2-TEST\n" + + "mnt-by: OWNER-MNT\n" + + "source: TEST"); final RpslObject secondPerson = RpslObject.parse( "person: Test Person\n" + "address: Singel 258\n" + @@ -353,12 +353,12 @@ public void update_create_multiple_objects_and_delete_successfully() { public void update_modify_with_sso_auth_succeeds() { final RpslObject ssomnt = RpslObject.parse( "mntner: SSO-MNT\n" + - "descr: Maintainer\n" + - "admin-c: TP1-TEST\n" + - "upd-to: person@net.net\n" + - "auth: SSO person@net.net\n" + - "mnt-by: SSO-MNT\n" + - "source: TEST"); + "descr: Maintainer\n" + + "admin-c: TP1-TEST\n" + + "upd-to: person@net.net\n" + + "auth: SSO person@net.net\n" + + "mnt-by: SSO-MNT\n" + + "source: TEST"); //databaseHelper.addObject does not translate account to UUID, so we do it via classic REST @POST RestTest.target(getPort(), "whois/test/mntner") @@ -388,12 +388,12 @@ public void update_modify_with_sso_auth_succeeds() { public void update_delete_with_sso_auth_succeeds() { final RpslObject ssomnt = RpslObject.parse( "mntner: SSO-MNT\n" + - "descr: Maintainer\n" + - "admin-c: TP1-TEST\n" + - "upd-to: person@net.net\n" + - "auth: SSO person@net.net\n" + - "mnt-by: SSO-MNT\n" + - "source: TEST"); + "descr: Maintainer\n" + + "admin-c: TP1-TEST\n" + + "upd-to: person@net.net\n" + + "auth: SSO person@net.net\n" + + "mnt-by: SSO-MNT\n" + + "source: TEST"); //databaseHelper.addObject does not translate account to UUID, so we do it via classic REST @POST RestTest.target(getPort(), "whois/test/mntner") @@ -535,13 +535,13 @@ public void update_modify_multiple_objects_success() { "source: TEST"); final RpslObject updatedRole = RpslObject.parse( "role: Test Role\n" + - "address: Singel 258\n" + - "e-mail: noreply@ripe.net\n" + - "remarks: updated role\n" + - "phone: +31 6 12345678\n" + - "nic-hdl: TR1-TEST\n" + - "mnt-by: OWNER-MNT\n" + - "source: TEST"); + "address: Singel 258\n" + + "e-mail: noreply@ripe.net\n" + + "remarks: updated role\n" + + "phone: +31 6 12345678\n" + + "nic-hdl: TR1-TEST\n" + + "mnt-by: OWNER-MNT\n" + + "source: TEST"); final WhoisResources response = RestTest.target(getPort(), "whois/references/test") .queryParam("override", SyncUpdateUtils.encode("personadmin,secret,reason")) @@ -789,7 +789,6 @@ public void delete_pair_using_sso_returns_original_state_of_objects_in_response( new Attribute("mnt-by", "SSO-MNT", null, "mntner", Link.create("http://rest-test.db.ripe.net/test/mntner/SSO-MNT")))); } - @Ignore("[ES] TODO multiple references to person not handled properly") @Test public void delete_mntner_person_pair_multiple_references() { databaseHelper.addObject( @@ -800,11 +799,13 @@ public void delete_mntner_person_pair_multiple_references() { databaseHelper.addObject( "mntner: DUMMY-MNT\n" + "descr: Startup maintainer\n" + + "auth: MD5-PW $1$d9fKeTr2$Si7YudNf4rUGmR71n/cqk/ #test\n" + + "upd-to: noreply@ripe.net\n" + "admin-c: AP1-TEST\n" + "mnt-by: DUMMY-MNT\n" + "admin-c: AP1-TEST\n" + "tech-c: AP1-TEST\n" + - "source: RIPE"); + "source: TEST"); databaseHelper.updateObject( "person: Another Person\n" + "nic-hdl: AP1-TEST\n" + @@ -831,11 +832,11 @@ public void delete_object_multiple_references_succeeds() { databaseHelper.addObject( "role: Test Role\n" + - "address: Singel 258\n" + - "phone: +31 6 12345678\n" + - "nic-hdl: TR2-TEST\n" + - "mnt-by: OWNER-MNT\n" + - "source: TEST"); + "address: Singel 258\n" + + "phone: +31 6 12345678\n" + + "nic-hdl: TR2-TEST\n" + + "mnt-by: OWNER-MNT\n" + + "source: TEST"); final WhoisResources whoisResources = RestTest.target(getPort(), "whois/references/TEST/mntner/OWNER-MNT?password=test") .request(MediaType.APPLICATION_JSON_TYPE) @@ -853,11 +854,11 @@ public void delete_object_multiple_references_succeeds() { public void delete_object_with_outgoing_references_only() { databaseHelper.addObject( "role: Test Role\n" + - "address: Singel 258\n" + - "phone: +31 6 12345678\n" + - "nic-hdl: TR2-TEST\n" + - "mnt-by: OWNER-MNT\n" + - "source: TEST"); + "address: Singel 258\n" + + "phone: +31 6 12345678\n" + + "nic-hdl: TR2-TEST\n" + + "mnt-by: OWNER-MNT\n" + + "source: TEST"); final WhoisResources whoisResources = RestTest.target(getPort(), "whois/references/TEST/role/TR2-TEST?password=test") .request() @@ -873,11 +874,11 @@ public void delete_object_with_outgoing_references_only() { public void delete_object_with_outgoing_references_only_fails() { databaseHelper.addObject( "role: Test Role\n" + - "address: Singel 258\n" + - "phone: +31 6 12345678\n" + - "nic-hdl: TR2-TEST\n" + - "mnt-by: OWNER-MNT\n" + - "source: TEST"); + "address: Singel 258\n" + + "phone: +31 6 12345678\n" + + "nic-hdl: TR2-TEST\n" + + "mnt-by: OWNER-MNT\n" + + "source: TEST"); try { RestTest.target(getPort(), "whois/references/TEST/role/TR2-TEST") @@ -902,12 +903,12 @@ public void delete_object_with_outgoing_references_only_fails() { public void delete_non_mntner_or_role() { databaseHelper.addObject( "organisation: ORG-TO1-TEST\n" + - "org-type: other\n" + - "org-name: First Org\n" + - "address: RIPE NCC\n" + - "e-mail: dbtest@ripe.net\n" + - "mnt-by: OWNER-MNT\n" + - "source: TEST"); + "org-type: other\n" + + "org-name: First Org\n" + + "address: RIPE NCC\n" + + "e-mail: dbtest@ripe.net\n" + + "mnt-by: OWNER-MNT\n" + + "source: TEST"); try { RestTest.target(getPort(), "whois/references/TEST/organisation/ORG-TO1-TEST?password=test") .request() @@ -926,12 +927,12 @@ public void delete_non_mntner_or_role() { public void delete_mntner_fails_person_referenced_from_another_mntner() { databaseHelper.addObject( "mntner: ANOTHER-MNT\n" + - "descr: Another Maintainer\n" + - "admin-c: TP1-TEST\n" + - "upd-to: noreply@ripe.net\n" + - "auth: MD5-PW $1$d9fKeTr2$Si7YudNf4rUGmR71n/cqk/ #test\n" + - "mnt-by: ANOTHER-MNT\n" + - "source: TEST"); + "descr: Another Maintainer\n" + + "admin-c: TP1-TEST\n" + + "upd-to: noreply@ripe.net\n" + + "auth: MD5-PW $1$d9fKeTr2$Si7YudNf4rUGmR71n/cqk/ #test\n" + + "mnt-by: ANOTHER-MNT\n" + + "source: TEST"); final Response response = RestTest.target(getPort(), "whois/references/TEST/mntner/OWNER-MNT") .request() @@ -1018,6 +1019,41 @@ public void delete_person_mnter_pair_with_override() { assertThat(objectExists(ObjectType.PERSON, "TP2-TEST"), is(false)); } + @Test + public void delete_person_mnter_pair_with_override_duplicate_adminc() { + databaseHelper.addObject( + "mntner: ANOTHER-MNT\n" + + "auth: MD5-PW $1$d9fKeTr2$Si7YudNf4rUGmR71n/cqk/ #test\n" + + "upd-to: noreply@ripe.net\n" + + "mnt-by: ANOTHER-MNT\n" + + "source: TEST"); + databaseHelper.addObject( + "person: Test Person2\n" + + "nic-hdl: TP2-TEST\n" + + "mnt-by: ANOTHER-MNT\n" + + "source: TEST"); + databaseHelper.updateObject( + "mntner: ANOTHER-MNT\n" + + "auth: MD5-PW $1$d9fKeTr2$Si7YudNf4rUGmR71n/cqk/ #test\n" + + "upd-to: noreply@ripe.net\n" + + "admin-c: TP2-TEST\n" + + "admin-c: TP2-TEST\n" + + "mnt-by: ANOTHER-MNT\n" + + "source: TEST"); + + assertThat(objectExists(ObjectType.MNTNER, "ANOTHER-MNT"), is(true)); + assertThat(objectExists(ObjectType.PERSON, "TP2-TEST"), is(true)); + + RestTest.target(getPort(), "whois/references/TEST/mntner/ANOTHER-MNT") + .queryParam("override", "personadmin,secret,reason") + .request() + .delete(); + + assertThat(objectExists(ObjectType.MNTNER, "ANOTHER-MNT"), is(false)); + assertThat(objectExists(ObjectType.PERSON, "TP2-TEST"), is(false)); + } + + @Test public void delete_person_mnter_pair_with_override_bad_password() { databaseHelper.addObject( @@ -1124,18 +1160,18 @@ public void delete_role_mnter_pair_with_override_missing_mandatory_attribute_not // upd-to: not in map. no maintainers in db missing this mandatory attr, always been mandatory so should never be missing? databaseHelper.addObject( "mntner: ANOTHER-MNT\n" + - "mnt-by: ANOTHER-MNT\n" + - "source: TEST"); + "mnt-by: ANOTHER-MNT\n" + + "source: TEST"); databaseHelper.addObject( "role: Test Role2\n" + - "nic-hdl: TR2-TEST\n" + - "mnt-by: ANOTHER-MNT\n" + - "source: TEST"); + "nic-hdl: TR2-TEST\n" + + "mnt-by: ANOTHER-MNT\n" + + "source: TEST"); databaseHelper.updateObject( "mntner: ANOTHER-MNT\n" + - "admin-c: TR2-TEST\n" + - "mnt-by: ANOTHER-MNT\n" + - "source: TEST"); + "admin-c: TR2-TEST\n" + + "mnt-by: ANOTHER-MNT\n" + + "source: TEST"); assertThat(objectExists(ObjectType.MNTNER, "ANOTHER-MNT"), is(true)); assertThat(objectExists(ObjectType.ROLE, "TR2-TEST"), is(true));