diff --git a/orcid-api-web/src/main/java/org/orcid/api/memberV3/server/delegator/impl/MemberV3ApiServiceDelegatorImpl.java b/orcid-api-web/src/main/java/org/orcid/api/memberV3/server/delegator/impl/MemberV3ApiServiceDelegatorImpl.java index 1f28385b74..d73eb5bcb1 100644 --- a/orcid-api-web/src/main/java/org/orcid/api/memberV3/server/delegator/impl/MemberV3ApiServiceDelegatorImpl.java +++ b/orcid-api-web/src/main/java/org/orcid/api/memberV3/server/delegator/impl/MemberV3ApiServiceDelegatorImpl.java @@ -307,6 +307,7 @@ public Response viewRecord(String orcid) { Record record = recordManagerReadOnly.getRecord(orcid, filterVersionOfIdentifiers); orcidSecurityManager.checkAndFilter(orcid, record); if (record.getPerson() != null) { + emailDomainManager.processProfessionalEmailsForV3API(record.getPerson().getEmails()); sourceUtils.setSourceName(record.getPerson()); } if (record.getActivitiesSummary() != null) { diff --git a/orcid-api-web/src/test/java/org/orcid/api/memberV2/server/delegator/MemberV2ApiServiceDelegator_ReadPersonTest.java b/orcid-api-web/src/test/java/org/orcid/api/memberV2/server/delegator/MemberV2ApiServiceDelegator_ReadPersonTest.java index 1d26132069..4db7a22551 100644 --- a/orcid-api-web/src/test/java/org/orcid/api/memberV2/server/delegator/MemberV2ApiServiceDelegator_ReadPersonTest.java +++ b/orcid-api-web/src/test/java/org/orcid/api/memberV2/server/delegator/MemberV2ApiServiceDelegator_ReadPersonTest.java @@ -5,6 +5,7 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -84,7 +85,22 @@ public void testViewPersonReadPublic() { assertNotNull(element); assertEquals("/0000-0000-0000-0003/person", element.getPath()); Utils.assertIsPublicOrSource(element, "APP-5555555555555555"); - fail("TEST EMAILS"); + assertNotNull(element.getEmails()); + assertEquals(4, element.getEmails().getEmails().size()); + List emails = new ArrayList<>(); + emails.add("public_0000-0000-0000-0003@test.orcid.org"); + emails.add("public_0000-0000-0000-0003@orcid.org"); + emails.add("limited_0000-0000-0000-0003@test.orcid.org"); + emails.add("private_0000-0000-0000-0003@test.orcid.org"); + + for(Email e : element.getEmails().getEmails()) { + if(!emails.contains(e.getEmail())) { + fail(e.getEmail() + " is not in the email list"); + } + emails.remove(e.getEmail()); + } + + assertTrue(emails.isEmpty()); } @Test diff --git a/orcid-api-web/src/test/java/org/orcid/api/memberV2/server/delegator/MemberV2ApiServiceDelegator_ReadRecordTest.java b/orcid-api-web/src/test/java/org/orcid/api/memberV2/server/delegator/MemberV2ApiServiceDelegator_ReadRecordTest.java index 56620f893a..9ce94e6c7b 100644 --- a/orcid-api-web/src/test/java/org/orcid/api/memberV2/server/delegator/MemberV2ApiServiceDelegator_ReadRecordTest.java +++ b/orcid-api-web/src/test/java/org/orcid/api/memberV2/server/delegator/MemberV2ApiServiceDelegator_ReadRecordTest.java @@ -6,6 +6,7 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -102,7 +103,6 @@ public void testViewRecordWrongScope() { Utils.assertIsPublicOrSource(record.getActivitiesSummary(), SecurityContextTestUtils.DEFAULT_CLIENT_ID); assertEquals("/0000-0000-0000-0003/person", record.getPerson().getPath()); Utils.assertIsPublicOrSource(record.getPerson(), SecurityContextTestUtils.DEFAULT_CLIENT_ID); - } @Test @@ -116,7 +116,51 @@ public void testViewRecordReadPublic() { Utils.assertIsPublicOrSource(record.getActivitiesSummary(), "APP-5555555555555555"); assertEquals("/0000-0000-0000-0003/person", record.getPerson().getPath()); Utils.assertIsPublicOrSource(record.getPerson(), "APP-5555555555555555"); - fail("TEST EMAILS"); + assertNotNull(record.getPerson()); + assertNotNull(record.getPerson().getEmails()); + assertEquals(4, record.getPerson().getEmails().getEmails().size()); + List emails = new ArrayList<>(); + emails.add("public_0000-0000-0000-0003@test.orcid.org"); + emails.add("public_0000-0000-0000-0003@orcid.org"); + emails.add("limited_0000-0000-0000-0003@test.orcid.org"); + emails.add("private_0000-0000-0000-0003@test.orcid.org"); + + for(Email e : record.getPerson().getEmails().getEmails()) { + if(!emails.contains(e.getEmail())) { + fail(e.getEmail() + " is not in the email list"); + } + emails.remove(e.getEmail()); + } + + assertTrue(emails.isEmpty()); + } + + @Test + public void testViewRecordReadPublic_clientThatIsNotTheSourceOfEmails() { + SecurityContextTestUtils.setUpSecurityContextForClientOnly("APP-5555555555555556", ScopePathType.READ_PUBLIC); + Response r = serviceDelegator.viewRecord(ORCID); + Record record = (Record) r.getEntity(); + assertNotNull(record); + assertEquals("/0000-0000-0000-0003", record.getPath()); + assertEquals("/0000-0000-0000-0003/activities", record.getActivitiesSummary().getPath()); + Utils.assertIsPublicOrSource(record.getActivitiesSummary(), "APP-5555555555555556"); + assertEquals("/0000-0000-0000-0003/person", record.getPerson().getPath()); + Utils.assertIsPublicOrSource(record.getPerson(), "APP-5555555555555556"); + assertNotNull(record.getPerson()); + assertNotNull(record.getPerson().getEmails()); + assertEquals(2, record.getPerson().getEmails().getEmails().size()); + List emails = new ArrayList<>(); + emails.add("public_0000-0000-0000-0003@test.orcid.org"); + emails.add("public_0000-0000-0000-0003@orcid.org"); + + for(Email e : record.getPerson().getEmails().getEmails()) { + if(!emails.contains(e.getEmail())) { + fail(e.getEmail() + " is not in the email list"); + } + emails.remove(e.getEmail()); + } + + assertTrue(emails.isEmpty()); } @Test(expected = OrcidUnauthorizedException.class) @@ -229,28 +273,23 @@ public void testViewRecord() { for (Email email : person.getEmails().getEmails()) { Utils.verifyLastModified(email.getLastModifiedDate()); if (email.getEmail().equals("public_0000-0000-0000-0003@test.orcid.org")) { - assertEquals("APP-5555555555555555", email.getSource().retrieveSourcePath()); - assertNull(email.getSource().getSourceOrcid()); + assertEquals("0000-0000-0000-0000", email.getSource().retrieveSourcePath()); assertEquals(org.orcid.jaxb.model.common_v2.Visibility.PUBLIC.value(), email.getVisibility().value()); - assertEquals("Source Client 1", email.getSource().getSourceName().getContent()); + assertEquals("ORCID email validation", email.getSource().getSourceName().getContent()); } else if (email.getEmail().equals("limited_0000-0000-0000-0003@test.orcid.org")) { - assertEquals("APP-5555555555555555", email.getSource().retrieveSourcePath()); - assertNull(email.getSource().getSourceOrcid()); + assertEquals("0000-0000-0000-0000", email.getSource().retrieveSourcePath()); assertEquals(org.orcid.jaxb.model.common_v2.Visibility.LIMITED.value(), email.getVisibility().value()); - assertEquals("Source Client 1", email.getSource().getSourceName().getContent()); + assertEquals("ORCID email validation", email.getSource().getSourceName().getContent()); } else if (email.getEmail().equals("private_0000-0000-0000-0003@test.orcid.org")) { - assertEquals("APP-5555555555555555", email.getSource().retrieveSourcePath()); - assertNull(email.getSource().getSourceOrcid()); + assertEquals("0000-0000-0000-0000", email.getSource().retrieveSourcePath()); assertEquals(org.orcid.jaxb.model.common_v2.Visibility.PRIVATE.value(), email.getVisibility().value()); - assertEquals("Source Client 1", email.getSource().getSourceName().getContent()); + assertEquals("ORCID email validation", email.getSource().getSourceName().getContent()); } else if (email.getEmail().equals("self_limited_0000-0000-0000-0003@test.orcid.org")) { - assertEquals("0000-0000-0000-0003", email.getSource().retrieveSourcePath()); - assertNotNull(email.getSource().getSourceOrcid()); + assertEquals("0000-0000-0000-0000", email.getSource().retrieveSourcePath()); assertEquals(org.orcid.jaxb.model.common_v2.Visibility.LIMITED.value(), email.getVisibility().value()); - assertEquals("Credit Name", email.getSource().getSourceName().getContent()); + assertEquals("ORCID email validation", email.getSource().getSourceName().getContent()); } else if (email.getEmail().equals("public_0000-0000-0000-0003@orcid.org")) { assertEquals("0000-0000-0000-0000", email.getSource().retrieveSourcePath()); - assertNull(email.getSource().getSourceOrcid()); assertEquals(org.orcid.jaxb.model.common_v2.Visibility.PUBLIC.value(), email.getVisibility().value()); assertEquals("ORCID email validation", email.getSource().getSourceName().getContent()); } else { diff --git a/orcid-api-web/src/test/java/org/orcid/api/memberV3/server/delegator/MemberV3ApiServiceDelegator_EmailsTest.java b/orcid-api-web/src/test/java/org/orcid/api/memberV3/server/delegator/MemberV3ApiServiceDelegator_EmailsTest.java index 2319a2fdcb..b58dc4ddf2 100644 --- a/orcid-api-web/src/test/java/org/orcid/api/memberV3/server/delegator/MemberV3ApiServiceDelegator_EmailsTest.java +++ b/orcid-api-web/src/test/java/org/orcid/api/memberV3/server/delegator/MemberV3ApiServiceDelegator_EmailsTest.java @@ -8,6 +8,7 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -86,7 +87,41 @@ public void testViewEmailsReadPublic() { Emails element = (Emails) r.getEntity(); assertNotNull(element); assertEquals("/0000-0000-0000-0003/email", element.getPath()); - Utils.assertIsPublicOrSource(element, "APP-5555555555555555"); + assertEquals(4, element.getEmails().size()); + List emails = new ArrayList<>(); + emails.add("public_0000-0000-0000-0003@test.orcid.org"); + emails.add("public_0000-0000-0000-0003@orcid.org"); + emails.add("limited_0000-0000-0000-0003@test.orcid.org"); + emails.add("private_0000-0000-0000-0003@test.orcid.org"); + + for(Email e : element.getEmails()) { + if(!emails.contains(e.getEmail())) { + fail(e.getEmail() + " is not in the email list"); + } + emails.remove(e.getEmail()); + } + assertTrue(emails.isEmpty()); + } + + @Test + public void testViewEmailsReadPublic_ClientNotSourceOfAnyEmail() { + SecurityContextTestUtils.setUpSecurityContextForClientOnly("APP-5555555555555556", ScopePathType.READ_PUBLIC); + Response r = serviceDelegator.viewEmails(ORCID); + Emails element = (Emails) r.getEntity(); + assertNotNull(element); + assertEquals("/0000-0000-0000-0003/email", element.getPath()); + assertEquals(2, element.getEmails().size()); + List emails = new ArrayList<>(); + emails.add("public_0000-0000-0000-0003@test.orcid.org"); + emails.add("public_0000-0000-0000-0003@orcid.org"); + + for(Email e : element.getEmails()) { + if(!emails.contains(e.getEmail())) { + fail(e.getEmail() + " is not in the email list"); + } + emails.remove(e.getEmail()); + } + assertTrue(emails.isEmpty()); } @Test diff --git a/orcid-api-web/src/test/java/org/orcid/api/memberV3/server/delegator/MemberV3ApiServiceDelegator_ReadPersonTest.java b/orcid-api-web/src/test/java/org/orcid/api/memberV3/server/delegator/MemberV3ApiServiceDelegator_ReadPersonTest.java index 2e7d3dc83d..91cbb44db9 100644 --- a/orcid-api-web/src/test/java/org/orcid/api/memberV3/server/delegator/MemberV3ApiServiceDelegator_ReadPersonTest.java +++ b/orcid-api-web/src/test/java/org/orcid/api/memberV3/server/delegator/MemberV3ApiServiceDelegator_ReadPersonTest.java @@ -5,6 +5,7 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -90,7 +91,46 @@ public void testViewPersonReadPublic() { assertNotNull(element); assertEquals("/0000-0000-0000-0003/person", element.getPath()); Utils.assertIsPublicOrSource(element, "APP-5555555555555555"); - fail("Process emails"); + assertNotNull(element.getEmails()); + assertNotNull(element.getEmails().getEmails()); + assertEquals(4, element.getEmails().getEmails().size()); + List emails = new ArrayList<>(); + emails.add("public_0000-0000-0000-0003@test.orcid.org"); + emails.add("public_0000-0000-0000-0003@orcid.org"); + emails.add("limited_0000-0000-0000-0003@test.orcid.org"); + emails.add("private_0000-0000-0000-0003@test.orcid.org"); + + for(Email e : element.getEmails().getEmails()) { + if(!emails.contains(e.getEmail())) { + fail(e.getEmail() + " is not in the email list"); + } + emails.remove(e.getEmail()); + } + assertTrue(emails.isEmpty()); + } + + @Test + public void testViewPersonReadPublic_ClientNotSourceOfAnyEmail() { + SecurityContextTestUtils.setUpSecurityContextForClientOnly("APP-5555555555555556", ScopePathType.READ_PUBLIC); + Response r = serviceDelegator.viewPerson(ORCID); + Person element = (Person) r.getEntity(); + assertNotNull(element); + assertEquals("/0000-0000-0000-0003/person", element.getPath()); + Utils.assertIsPublicOrSource(element, "APP-5555555555555556"); + assertNotNull(element.getEmails()); + assertNotNull(element.getEmails().getEmails()); + assertEquals(2, element.getEmails().getEmails().size()); + List emails = new ArrayList<>(); + emails.add("public_0000-0000-0000-0003@test.orcid.org"); + emails.add("public_0000-0000-0000-0003@orcid.org"); + + for(Email e : element.getEmails().getEmails()) { + if(!emails.contains(e.getEmail())) { + fail(e.getEmail() + " is not in the email list"); + } + emails.remove(e.getEmail()); + } + assertTrue(emails.isEmpty()); } @Test diff --git a/orcid-api-web/src/test/java/org/orcid/api/memberV3/server/delegator/MemberV3ApiServiceDelegator_ReadRecordTest.java b/orcid-api-web/src/test/java/org/orcid/api/memberV3/server/delegator/MemberV3ApiServiceDelegator_ReadRecordTest.java index 8f24d02e81..e387c20e59 100644 --- a/orcid-api-web/src/test/java/org/orcid/api/memberV3/server/delegator/MemberV3ApiServiceDelegator_ReadRecordTest.java +++ b/orcid-api-web/src/test/java/org/orcid/api/memberV3/server/delegator/MemberV3ApiServiceDelegator_ReadRecordTest.java @@ -6,6 +6,7 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -103,32 +104,61 @@ public static void removeDBUnitData() throws Exception { } @Test - public void testViewRecordWrongScope() { - SecurityContextTestUtils.setUpSecurityContext(ORCID, ScopePathType.READ_PUBLIC); - Response response = serviceDelegator.viewRecord(ORCID); - // Verify everything inside is public - Record record = (Record) response.getEntity(); + public void testViewRecordReadPublic() { + SecurityContextTestUtils.setUpSecurityContextForClientOnly("APP-5555555555555555", ScopePathType.READ_PUBLIC); + Response r = serviceDelegator.viewRecord(ORCID); + Record record = (Record) r.getEntity(); assertNotNull(record); assertEquals("/0000-0000-0000-0003", record.getPath()); assertEquals("/0000-0000-0000-0003/activities", record.getActivitiesSummary().getPath()); - Utils.assertIsPublicOrSource(record.getActivitiesSummary(), SecurityContextTestUtils.DEFAULT_CLIENT_ID); + Utils.assertIsPublicOrSource(record.getActivitiesSummary(), "APP-5555555555555555"); assertEquals("/0000-0000-0000-0003/person", record.getPerson().getPath()); - Utils.assertIsPublicOrSource(record.getPerson(), SecurityContextTestUtils.DEFAULT_CLIENT_ID); - fail("Process emails"); + Utils.assertIsPublicOrSource(record.getPerson(), "APP-5555555555555555"); + assertNotNull(record.getPerson()); + assertNotNull(record.getPerson().getEmails()); + assertNotNull(record.getPerson().getEmails().getEmails()); + assertEquals(4, record.getPerson().getEmails().getEmails().size()); + List emails = new ArrayList<>(); + emails.add("public_0000-0000-0000-0003@test.orcid.org"); + emails.add("public_0000-0000-0000-0003@orcid.org"); + emails.add("limited_0000-0000-0000-0003@test.orcid.org"); + emails.add("private_0000-0000-0000-0003@test.orcid.org"); + + for(Email e : record.getPerson().getEmails().getEmails()) { + if(!emails.contains(e.getEmail())) { + fail(e.getEmail() + " is not in the email list"); + } + emails.remove(e.getEmail()); + } + assertTrue(emails.isEmpty()); } @Test - public void testViewRecordReadPublic() { - SecurityContextTestUtils.setUpSecurityContextForClientOnly("APP-5555555555555555", ScopePathType.READ_PUBLIC); + public void testViewRecordReadPublic_ClientNotSourceOfAnyEmail() { + SecurityContextTestUtils.setUpSecurityContextForClientOnly("APP-5555555555555556", ScopePathType.READ_PUBLIC); Response r = serviceDelegator.viewRecord(ORCID); Record record = (Record) r.getEntity(); assertNotNull(record); assertEquals("/0000-0000-0000-0003", record.getPath()); assertEquals("/0000-0000-0000-0003/activities", record.getActivitiesSummary().getPath()); - Utils.assertIsPublicOrSource(record.getActivitiesSummary(), "APP-5555555555555555"); + Utils.assertIsPublicOrSource(record.getActivitiesSummary(), "APP-5555555555555556"); assertEquals("/0000-0000-0000-0003/person", record.getPerson().getPath()); - Utils.assertIsPublicOrSource(record.getPerson(), "APP-5555555555555555"); - fail("Process emails"); + Utils.assertIsPublicOrSource(record.getPerson(), "APP-5555555555555556"); + assertNotNull(record.getPerson()); + assertNotNull(record.getPerson().getEmails()); + assertNotNull(record.getPerson().getEmails().getEmails()); + assertEquals(2, record.getPerson().getEmails().getEmails().size()); + List emails = new ArrayList<>(); + emails.add("public_0000-0000-0000-0003@test.orcid.org"); + emails.add("public_0000-0000-0000-0003@orcid.org"); + + for(Email e : record.getPerson().getEmails().getEmails()) { + if(!emails.contains(e.getEmail())) { + fail(e.getEmail() + " is not in the email list"); + } + emails.remove(e.getEmail()); + } + assertTrue(emails.isEmpty()); } @Test(expected = OrcidUnauthorizedException.class) @@ -241,28 +271,23 @@ public void testViewRecord() { for (Email email : person.getEmails().getEmails()) { Utils.verifyLastModified(email.getLastModifiedDate()); if (email.getEmail().equals("public_0000-0000-0000-0003@test.orcid.org")) { - assertEquals("APP-5555555555555555", email.getSource().retrieveSourcePath()); - assertNull(email.getSource().getSourceOrcid()); + assertEquals("0000-0000-0000-0000", email.getSource().retrieveSourcePath()); assertEquals(org.orcid.jaxb.model.common_v2.Visibility.PUBLIC.value(), email.getVisibility().value()); - assertEquals("Source Client 1", email.getSource().getSourceName().getContent()); + assertEquals("ORCID email validation", email.getSource().getSourceName().getContent()); } else if (email.getEmail().equals("limited_0000-0000-0000-0003@test.orcid.org")) { - assertEquals("APP-5555555555555555", email.getSource().retrieveSourcePath()); - assertNull(email.getSource().getSourceOrcid()); + assertEquals("0000-0000-0000-0000", email.getSource().retrieveSourcePath()); assertEquals(org.orcid.jaxb.model.common_v2.Visibility.LIMITED.value(), email.getVisibility().value()); - assertEquals("Source Client 1", email.getSource().getSourceName().getContent()); + assertEquals("ORCID email validation", email.getSource().getSourceName().getContent()); } else if (email.getEmail().equals("private_0000-0000-0000-0003@test.orcid.org")) { - assertEquals("APP-5555555555555555", email.getSource().retrieveSourcePath()); - assertNull(email.getSource().getSourceOrcid()); + assertEquals("0000-0000-0000-0000", email.getSource().retrieveSourcePath()); assertEquals(org.orcid.jaxb.model.common_v2.Visibility.PRIVATE.value(), email.getVisibility().value()); - assertEquals("Source Client 1", email.getSource().getSourceName().getContent()); + assertEquals("ORCID email validation", email.getSource().getSourceName().getContent()); } else if (email.getEmail().equals("self_limited_0000-0000-0000-0003@test.orcid.org")) { - assertEquals("0000-0000-0000-0003", email.getSource().retrieveSourcePath()); - assertNotNull(email.getSource().getSourceOrcid()); + assertEquals("0000-0000-0000-0000", email.getSource().retrieveSourcePath()); assertEquals(org.orcid.jaxb.model.common_v2.Visibility.LIMITED.value(), email.getVisibility().value()); - assertEquals("Credit Name", email.getSource().getSourceName().getContent()); + assertEquals("ORCID email validation", email.getSource().getSourceName().getContent()); } else if (email.getEmail().equals("public_0000-0000-0000-0003@orcid.org")) { assertEquals("0000-0000-0000-0000", email.getSource().retrieveSourcePath()); - assertNull(email.getSource().getSourceOrcid()); assertEquals(org.orcid.jaxb.model.common_v2.Visibility.PUBLIC.value(), email.getVisibility().value()); assertEquals("ORCID email validation", email.getSource().getSourceName().getContent()); } else {