Skip to content

Commit

Permalink
Dbf 70 references api doesnt handle multiple (#404)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Rob Miller authored Sep 14, 2016
1 parent f5b3615 commit 719afdb
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -651,9 +651,8 @@ private RpslObjectWithReplacements replaceReferences(final RpslObject object, fi
}

final RpslObjectBuilder builder = new RpslObjectBuilder(object);
for (Map.Entry<RpslAttribute, RpslAttribute> entry : replacements.entrySet()) {
builder.replaceAttribute(entry.getKey(), entry.getValue());
}
builder.replaceAttributes(replacements);

return new RpslObjectWithReplacements(builder.get(), replacements);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" +
Expand Down Expand Up @@ -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: [email protected]\n" +
"auth: SSO [email protected]\n" +
"mnt-by: SSO-MNT\n" +
"source: TEST");
"descr: Maintainer\n" +
"admin-c: TP1-TEST\n" +
"upd-to: [email protected]\n" +
"auth: SSO [email protected]\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")
Expand Down Expand Up @@ -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: [email protected]\n" +
"auth: SSO [email protected]\n" +
"mnt-by: SSO-MNT\n" +
"source: TEST");
"descr: Maintainer\n" +
"admin-c: TP1-TEST\n" +
"upd-to: [email protected]\n" +
"auth: SSO [email protected]\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")
Expand Down Expand Up @@ -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: [email protected]\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: [email protected]\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"))
Expand Down Expand Up @@ -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(
Expand All @@ -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: [email protected]\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" +
Expand All @@ -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)
Expand All @@ -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()
Expand All @@ -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")
Expand All @@ -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: [email protected]\n" +
"mnt-by: OWNER-MNT\n" +
"source: TEST");
"org-type: other\n" +
"org-name: First Org\n" +
"address: RIPE NCC\n" +
"e-mail: [email protected]\n" +
"mnt-by: OWNER-MNT\n" +
"source: TEST");
try {
RestTest.target(getPort(), "whois/references/TEST/organisation/ORG-TO1-TEST?password=test")
.request()
Expand All @@ -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: [email protected]\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: [email protected]\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()
Expand Down Expand Up @@ -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: [email protected]\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: [email protected]\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(
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit 719afdb

Please sign in to comment.