From 3aece97bcda8b18547729b249574ba0acc1ad805 Mon Sep 17 00:00:00 2001 From: milanmajchrak Date: Sat, 17 Oct 2026 16:56:42 +0200 Subject: [PATCH 1/2] CLARIN-DSpace v9/Deny reads of ownerless CLARIN user records and anonymous CLARIN searches Allowance and user-metadata records created by an anonymous download have no user registration. The authorize helpers let any signed-in user read them by ID, including the form data, IP address and download token. Now only an admin may read them. The CLARIN search methods (byEPerson, byBitstreamAndUser and, where it exists, byUserRegistrationAndBitstream) had no PreAuthorize, so an anonymous request ended with a NullPointerException and a 500. They now require an authenticated user and map AuthorizeException to 401 or 403. The link repositories map it the same way instead of returning a 500. Co-Authored-By: Claude Fable 5.1 --- ...censeResourceUserAllowanceServiceImpl.java | 16 +- .../clarin/ClarinUserMetadataServiceImpl.java | 16 +- .../ClarinUserRegistrationServiceImpl.java | 8 +- ...seResourceUserAllowanceRestRepository.java | 13 +- .../ClarinUserMetadataRestRepository.java | 12 +- .../ClarinUserRegistrationRestRepository.java | 12 +- ...ResourceUserAllowanceRestRepositoryIT.java | 180 ++++++++++++++++++ .../ClarinUserMetadataRestRepositoryIT.java | 107 +++++++++++ ...larinUserRegistrationRestRepositoryIT.java | 64 +++++++ 9 files changed, 389 insertions(+), 39 deletions(-) create mode 100644 dspace-server-webapp/src/test/java/org/dspace/app/rest/ClarinLicenseResourceUserAllowanceRestRepositoryIT.java diff --git a/dspace-api/src/main/java/org/dspace/content/clarin/ClarinLicenseResourceUserAllowanceServiceImpl.java b/dspace-api/src/main/java/org/dspace/content/clarin/ClarinLicenseResourceUserAllowanceServiceImpl.java index 4af119b0c8cc..2ecfbf5da979 100644 --- a/dspace-api/src/main/java/org/dspace/content/clarin/ClarinLicenseResourceUserAllowanceServiceImpl.java +++ b/dspace-api/src/main/java/org/dspace/content/clarin/ClarinLicenseResourceUserAllowanceServiceImpl.java @@ -152,18 +152,12 @@ private void authorizeClruaAction(Context context, List findAll(Context context, Pag } @SearchRestMethod(name = "byBitstreamAndUser") + @PreAuthorize("hasAuthority('AUTHENTICATED')") public Page findByValue( @Parameter(value = "bitstreamUUID", required = true) UUID bitstreamUUID, @Parameter(value = "userUUID", required = true) UUID userUUID, - Pageable pageable) throws SQLException, AuthorizeException { + Pageable pageable) throws SQLException { Context context = obtainContext(); - List clarinLicenseResourceUserAllowance = - clarinLicenseResourceUserAllowanceService.findByEPersonIdAndBitstreamId(context, userUUID, - bitstreamUUID); + List clarinLicenseResourceUserAllowance; + try { + clarinLicenseResourceUserAllowance = clarinLicenseResourceUserAllowanceService + .findByEPersonIdAndBitstreamId(context, userUUID, bitstreamUUID); + } catch (AuthorizeException e) { + throw new RESTAuthorizationException(e); + } if (CollectionUtils.isEmpty(clarinLicenseResourceUserAllowance)) { return null; diff --git a/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/ClarinUserMetadataRestRepository.java b/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/ClarinUserMetadataRestRepository.java index 4270bcda8843..ebdf303d332c 100644 --- a/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/ClarinUserMetadataRestRepository.java +++ b/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/ClarinUserMetadataRestRepository.java @@ -64,14 +64,20 @@ public Page findAll(Context context, Pageable pageable) } @SearchRestMethod(name = "byUserRegistrationAndBitstream") + @PreAuthorize("hasAuthority('AUTHENTICATED')") public Page findByUserRegistrationAndBitstream( @Parameter(value = "userRegUUID", required = true) Integer userRegId, @Parameter(value = "bitstreamUUID", required = true) UUID bitstreamUUID, - Pageable pageable) throws SQLException, AuthorizeException { + Pageable pageable) throws SQLException { Context context = obtainContext(); - List clarinUserMetadataList = - clarinUserMetadataService.findByUserRegistrationAndBitstream(context, userRegId, bitstreamUUID, true); + List clarinUserMetadataList; + try { + clarinUserMetadataList = clarinUserMetadataService + .findByUserRegistrationAndBitstream(context, userRegId, bitstreamUUID, true); + } catch (AuthorizeException e) { + throw new RESTAuthorizationException(e); + } return converter.toRestPage(clarinUserMetadataList, pageable, utils.obtainProjection()); } diff --git a/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/ClarinUserRegistrationRestRepository.java b/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/ClarinUserRegistrationRestRepository.java index 0d616855292d..28088e5d6efc 100644 --- a/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/ClarinUserRegistrationRestRepository.java +++ b/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/ClarinUserRegistrationRestRepository.java @@ -80,14 +80,18 @@ protected ClarinUserRegistrationRest createAndReturn(Context context) throws SQL } @SearchRestMethod(name = "byEPerson") + @PreAuthorize("hasAuthority('AUTHENTICATED')") public Page findByEPerson(@Parameter(value = "userUUID", required = true) UUID userUUID, - Pageable pageable) - throws SQLException, AuthorizeException { + Pageable pageable) throws SQLException { Context context = obtainContext(); - List clarinUserRegistrationList = - clarinUserRegistrationService.findByEPersonUUID(context, userUUID); + List clarinUserRegistrationList; + try { + clarinUserRegistrationList = clarinUserRegistrationService.findByEPersonUUID(context, userUUID); + } catch (AuthorizeException e) { + throw new RESTAuthorizationException(e); + } if (CollectionUtils.isEmpty(clarinUserRegistrationList)) { return null; } diff --git a/dspace-server-webapp/src/test/java/org/dspace/app/rest/ClarinLicenseResourceUserAllowanceRestRepositoryIT.java b/dspace-server-webapp/src/test/java/org/dspace/app/rest/ClarinLicenseResourceUserAllowanceRestRepositoryIT.java new file mode 100644 index 000000000000..eb16d8b701e8 --- /dev/null +++ b/dspace-server-webapp/src/test/java/org/dspace/app/rest/ClarinLicenseResourceUserAllowanceRestRepositoryIT.java @@ -0,0 +1,180 @@ +/** + * The contents of this file are subject to the license and copyright + * detailed in the LICENSE and NOTICE files at the root of the source + * tree and available online at + * + * http://www.dspace.org/license/ + */ +package org.dspace.app.rest; + +import static org.hamcrest.Matchers.is; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.io.IOUtils; +import org.dspace.app.rest.test.AbstractControllerIntegrationTest; +import org.dspace.builder.BitstreamBuilder; +import org.dspace.builder.ClarinLicenseBuilder; +import org.dspace.builder.ClarinLicenseResourceMappingBuilder; +import org.dspace.builder.ClarinLicenseResourceUserAllowanceBuilder; +import org.dspace.builder.ClarinUserRegistrationBuilder; +import org.dspace.builder.CollectionBuilder; +import org.dspace.builder.CommunityBuilder; +import org.dspace.builder.EPersonBuilder; +import org.dspace.builder.ItemBuilder; +import org.dspace.content.Bitstream; +import org.dspace.content.Collection; +import org.dspace.content.Community; +import org.dspace.content.Item; +import org.dspace.content.clarin.ClarinLicenseResourceMapping; +import org.dspace.content.clarin.ClarinLicenseResourceUserAllowance; +import org.dspace.content.clarin.ClarinUserRegistration; +import org.dspace.eperson.EPerson; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class ClarinLicenseResourceUserAllowanceRestRepositoryIT extends AbstractControllerIntegrationTest { + + private Bitstream bitstream; + private ClarinLicenseResourceMapping mapping; + private ClarinUserRegistration clarinUserRegistration; + private EPerson otherEPerson; + private final List allowanceIds = new ArrayList<>(); + + @Before + public void setup() throws Exception { + context.turnOffAuthorisationSystem(); + Community community = CommunityBuilder.createCommunity(context) + .withName("Community") + .build(); + Collection collection = CollectionBuilder.createCollection(context, community) + .withName("Collection") + .build(); + Item item = ItemBuilder.createItem(context, collection) + .withTitle("Item") + .build(); + bitstream = BitstreamBuilder + .createBitstream(context, item, IOUtils.toInputStream("content", StandardCharsets.UTF_8)) + .withName("file.txt") + .build(); + mapping = ClarinLicenseResourceMappingBuilder.createClarinLicenseResourceMapping(context).build(); + mapping.setLicense(ClarinLicenseBuilder.createClarinLicense(context).build()); + mapping.setBitstream(bitstream); + clarinUserRegistration = ClarinUserRegistrationBuilder.createClarinUserRegistration(context) + .withEPersonID(eperson.getID()) + .build(); + otherEPerson = EPersonBuilder.createEPerson(context) + .withEmail("otherEperson@mail.com") + .withPassword(password) + .build(); + context.restoreAuthSystemState(); + } + + @After + public void deleteAllowances() throws Exception { + for (Integer id : allowanceIds) { + ClarinLicenseResourceUserAllowanceBuilder.deleteClarinLicenseResourceUserAllowance(id); + } + } + + @Test + public void findOneTest() throws Exception { + ClarinLicenseResourceUserAllowance allowance = createAllowance(clarinUserRegistration); + String url = "/api/core/clarinlruallowances/" + allowance.getID(); + + getClient().perform(get(url)) + .andExpect(status().isUnauthorized()); + + String userToken = getAuthToken(eperson.getEmail(), password); + getClient(userToken).perform(get(url)) + .andExpect(status().isOk()); + + String otherUserToken = getAuthToken(otherEPerson.getEmail(), password); + getClient(otherUserToken).perform(get(url)) + .andExpect(status().isForbidden()); + + String adminToken = getAuthToken(admin.getEmail(), password); + getClient(adminToken).perform(get(url)) + .andExpect(status().isOk()); + } + + @Test + public void findOneWithoutUserRegistrationTest() throws Exception { + // Allowances without a user registration come from an anonymous download, only admin can read them + ClarinLicenseResourceUserAllowance allowance = createAllowance(null); + String url = "/api/core/clarinlruallowances/" + allowance.getID(); + + getClient().perform(get(url)) + .andExpect(status().isUnauthorized()); + + String userToken = getAuthToken(eperson.getEmail(), password); + getClient(userToken).perform(get(url)) + .andExpect(status().isForbidden()); + + String adminToken = getAuthToken(admin.getEmail(), password); + getClient(adminToken).perform(get(url)) + .andExpect(status().isOk()); + } + + @Test + public void linksTest() throws Exception { + ClarinLicenseResourceUserAllowance allowance = createAllowance(clarinUserRegistration); + + String userToken = getAuthToken(eperson.getEmail(), password); + String otherUserToken = getAuthToken(otherEPerson.getEmail(), password); + for (String link : List.of("userRegistration", "resourceMapping")) { + String url = "/api/core/clarinlruallowances/" + allowance.getID() + "/" + link; + + getClient().perform(get(url)) + .andExpect(status().isUnauthorized()); + + getClient(otherUserToken).perform(get(url)) + .andExpect(status().isForbidden()); + + getClient(userToken).perform(get(url)) + .andExpect(status().isOk()); + } + } + + @Test + public void findByBitstreamAndUserTest() throws Exception { + createAllowance(clarinUserRegistration); + String search = "/api/core/clarinlruallowances/search/byBitstreamAndUser?bitstreamUUID=" + + bitstream.getID() + "&userUUID=" + eperson.getID(); + + getClient().perform(get(search)) + .andExpect(status().isUnauthorized()); + + String userToken = getAuthToken(eperson.getEmail(), password); + getClient(userToken).perform(get(search)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.page.totalElements", is(1))); + + String otherUserToken = getAuthToken(otherEPerson.getEmail(), password); + getClient(otherUserToken).perform(get(search)) + .andExpect(status().isForbidden()); + + String adminToken = getAuthToken(admin.getEmail(), password); + getClient(adminToken).perform(get(search)) + .andExpect(status().isOk()); + } + + private ClarinLicenseResourceUserAllowance createAllowance(ClarinUserRegistration owner) throws Exception { + context.turnOffAuthorisationSystem(); + ClarinLicenseResourceUserAllowance allowance = ClarinLicenseResourceUserAllowanceBuilder + .createClarinLicenseResourceUserAllowance(context) + .withUser(owner) + .withMapping(mapping) + .withToken("downloadToken") + .build(); + context.restoreAuthSystemState(); + allowanceIds.add(allowance.getID()); + return allowance; + } +} diff --git a/dspace-server-webapp/src/test/java/org/dspace/app/rest/ClarinUserMetadataRestRepositoryIT.java b/dspace-server-webapp/src/test/java/org/dspace/app/rest/ClarinUserMetadataRestRepositoryIT.java index 357a099d2b9c..71f4fd3f1e65 100644 --- a/dspace-server-webapp/src/test/java/org/dspace/app/rest/ClarinUserMetadataRestRepositoryIT.java +++ b/dspace-server-webapp/src/test/java/org/dspace/app/rest/ClarinUserMetadataRestRepositoryIT.java @@ -7,24 +7,49 @@ */ package org.dspace.app.rest; +import static org.hamcrest.Matchers.is; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import java.nio.charset.StandardCharsets; + +import org.apache.commons.io.IOUtils; import org.dspace.app.rest.test.AbstractControllerIntegrationTest; +import org.dspace.builder.BitstreamBuilder; import org.dspace.builder.ClarinLicenseBuilder; +import org.dspace.builder.ClarinLicenseResourceMappingBuilder; +import org.dspace.builder.ClarinLicenseResourceUserAllowanceBuilder; import org.dspace.builder.ClarinUserMetadataBuilder; import org.dspace.builder.ClarinUserRegistrationBuilder; import org.dspace.builder.CollectionBuilder; import org.dspace.builder.CommunityBuilder; import org.dspace.builder.EPersonBuilder; +import org.dspace.builder.ItemBuilder; +import org.dspace.content.Bitstream; +import org.dspace.content.Collection; import org.dspace.content.Community; +import org.dspace.content.Item; +import org.dspace.content.clarin.ClarinLicenseResourceMapping; +import org.dspace.content.clarin.ClarinLicenseResourceUserAllowance; import org.dspace.content.clarin.ClarinUserMetadata; import org.dspace.content.clarin.ClarinUserRegistration; import org.dspace.eperson.EPerson; +import org.junit.After; import org.junit.Test; public class ClarinUserMetadataRestRepositoryIT extends AbstractControllerIntegrationTest { + private ClarinLicenseResourceUserAllowance allowance; + private ClarinLicenseResourceMapping mapping; + + @After + public void deleteAllowance() throws Exception { + if (allowance != null) { + ClarinLicenseResourceUserAllowanceBuilder.deleteClarinLicenseResourceUserAllowance(allowance.getID()); + } + } + @Test public void findAllTest() throws Exception { context.turnOffAuthorisationSystem(); @@ -121,4 +146,86 @@ public void findOneTest() throws Exception { otherClarinUserMetadata.getID())) .andExpect(status().isForbidden()); } + + @Test + public void findOneWithoutUserRegistrationTest() throws Exception { + context.turnOffAuthorisationSystem(); + ClarinUserMetadata clarinUserMetadata = ClarinUserMetadataBuilder.createClarinUserMetadata(context) + .build(); + context.restoreAuthSystemState(); + + // User metadata without a user registration come from an anonymous download, only admin can read them + getClient().perform(get("/api/core/clarinusermetadatas/" + clarinUserMetadata.getID())) + .andExpect(status().isUnauthorized()); + + String userToken = getAuthToken(eperson.getEmail(), password); + getClient(userToken).perform(get("/api/core/clarinusermetadatas/" + clarinUserMetadata.getID())) + .andExpect(status().isForbidden()); + + String adminToken = getAuthToken(admin.getEmail(), password); + getClient(adminToken).perform(get("/api/core/clarinusermetadatas/" + clarinUserMetadata.getID())) + .andExpect(status().isOk()); + } + + @Test + public void findByUserRegistrationAndBitstreamTest() throws Exception { + context.turnOffAuthorisationSystem(); + Bitstream bitstream = createBitstreamWithLicense(); + ClarinUserRegistration clarinUserRegistration = ClarinUserRegistrationBuilder + .createClarinUserRegistration(context) + .withEPersonID(eperson.getID()) + .build(); + allowance = ClarinLicenseResourceUserAllowanceBuilder.createClarinLicenseResourceUserAllowance(context) + .withUser(clarinUserRegistration) + .withMapping(mapping) + .build(); + ClarinUserMetadata clarinUserMetadata = ClarinUserMetadataBuilder.createClarinUserMetadata(context) + .withUserRegistration(clarinUserRegistration) + .build(); + clarinUserMetadata.setTransaction(allowance); + EPerson otherEPerson = EPersonBuilder.createEPerson(context) + .withEmail("otherEperson@mail.com") + .withPassword(password) + .build(); + context.restoreAuthSystemState(); + + String search = "/api/core/clarinusermetadatas/search/byUserRegistrationAndBitstream?userRegUUID=" + + clarinUserRegistration.getID() + "&bitstreamUUID=" + bitstream.getID(); + + getClient().perform(get(search)) + .andExpect(status().isUnauthorized()); + + String userToken = getAuthToken(eperson.getEmail(), password); + getClient(userToken).perform(get(search)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.page.totalElements", is(1))); + + String otherUserToken = getAuthToken(otherEPerson.getEmail(), password); + getClient(otherUserToken).perform(get(search)) + .andExpect(status().isForbidden()); + + String adminToken = getAuthToken(admin.getEmail(), password); + getClient(adminToken).perform(get(search)) + .andExpect(status().isOk()); + } + + private Bitstream createBitstreamWithLicense() throws Exception { + Community community = CommunityBuilder.createCommunity(context) + .withName("Community") + .build(); + Collection collection = CollectionBuilder.createCollection(context, community) + .withName("Collection") + .build(); + Item item = ItemBuilder.createItem(context, collection) + .withTitle("Item") + .build(); + Bitstream bitstream = BitstreamBuilder + .createBitstream(context, item, IOUtils.toInputStream("content", StandardCharsets.UTF_8)) + .withName("file.txt") + .build(); + mapping = ClarinLicenseResourceMappingBuilder.createClarinLicenseResourceMapping(context).build(); + mapping.setLicense(ClarinLicenseBuilder.createClarinLicense(context).build()); + mapping.setBitstream(bitstream); + return bitstream; + } } diff --git a/dspace-server-webapp/src/test/java/org/dspace/app/rest/ClarinUserRegistrationRestRepositoryIT.java b/dspace-server-webapp/src/test/java/org/dspace/app/rest/ClarinUserRegistrationRestRepositoryIT.java index ab4bbaeed0a1..016e89cf558f 100644 --- a/dspace-server-webapp/src/test/java/org/dspace/app/rest/ClarinUserRegistrationRestRepositoryIT.java +++ b/dspace-server-webapp/src/test/java/org/dspace/app/rest/ClarinUserRegistrationRestRepositoryIT.java @@ -7,9 +7,13 @@ */ package org.dspace.app.rest; +import static org.hamcrest.Matchers.is; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import java.util.List; + import org.dspace.app.rest.test.AbstractControllerIntegrationTest; import org.dspace.builder.ClarinLicenseBuilder; import org.dspace.builder.ClarinUserMetadataBuilder; @@ -114,4 +118,64 @@ public void findOneTest() throws Exception { otherClarinUserRegistration.getID())) .andExpect(status().isForbidden()); } + + @Test + public void findByEPersonTest() throws Exception { + context.turnOffAuthorisationSystem(); + ClarinUserRegistrationBuilder.createClarinUserRegistration(context) + .withEPersonID(eperson.getID()) + .build(); + EPerson otherEPerson = EPersonBuilder.createEPerson(context) + .withEmail("otherEperson@mail.com") + .withPassword(password) + .build(); + context.restoreAuthSystemState(); + + String search = "/api/core/clarinuserregistrations/search/byEPerson?userUUID=" + eperson.getID(); + + getClient().perform(get(search)) + .andExpect(status().isUnauthorized()); + + String userToken = getAuthToken(eperson.getEmail(), password); + getClient(userToken).perform(get(search)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.page.totalElements", is(1))); + + String otherUserToken = getAuthToken(otherEPerson.getEmail(), password); + getClient(otherUserToken).perform(get(search)) + .andExpect(status().isForbidden()); + + String adminToken = getAuthToken(admin.getEmail(), password); + getClient(adminToken).perform(get(search)) + .andExpect(status().isOk()); + } + + @Test + public void linksTest() throws Exception { + context.turnOffAuthorisationSystem(); + ClarinUserRegistration clarinUserRegistration = ClarinUserRegistrationBuilder + .createClarinUserRegistration(context) + .withEPersonID(eperson.getID()) + .build(); + EPerson otherEPerson = EPersonBuilder.createEPerson(context) + .withEmail("otherEperson@mail.com") + .withPassword(password) + .build(); + context.restoreAuthSystemState(); + + String userToken = getAuthToken(eperson.getEmail(), password); + String otherUserToken = getAuthToken(otherEPerson.getEmail(), password); + for (String link : List.of("userMetadata", "clarinLicenses")) { + String url = "/api/core/clarinuserregistrations/" + clarinUserRegistration.getID() + "/" + link; + + getClient().perform(get(url)) + .andExpect(status().isUnauthorized()); + + getClient(otherUserToken).perform(get(url)) + .andExpect(status().isForbidden()); + + getClient(userToken).perform(get(url)) + .andExpect(status().isOk()); + } + } } From bf1e9a8cfece4e00b05ea9b894f8cfd5c2fe0cdb Mon Sep 17 00:00:00 2001 From: milanmajchrak Date: Thu, 26 Nov 2026 23:22:18 +0100 Subject: [PATCH 2/2] Check that anonymous CLARIN searches without a match get 401 too Without a matching record the services check nothing, so only the endpoint authorization can refuse these searches. Co-Authored-By: Claude Opus 5.5 --- .../ClarinLicenseResourceUserAllowanceRestRepositoryIT.java | 4 ++++ .../dspace/app/rest/ClarinUserMetadataRestRepositoryIT.java | 5 +++++ .../app/rest/ClarinUserRegistrationRestRepositoryIT.java | 4 ++++ 3 files changed, 13 insertions(+) diff --git a/dspace-server-webapp/src/test/java/org/dspace/app/rest/ClarinLicenseResourceUserAllowanceRestRepositoryIT.java b/dspace-server-webapp/src/test/java/org/dspace/app/rest/ClarinLicenseResourceUserAllowanceRestRepositoryIT.java index eb16d8b701e8..7e557973aab0 100644 --- a/dspace-server-webapp/src/test/java/org/dspace/app/rest/ClarinLicenseResourceUserAllowanceRestRepositoryIT.java +++ b/dspace-server-webapp/src/test/java/org/dspace/app/rest/ClarinLicenseResourceUserAllowanceRestRepositoryIT.java @@ -150,6 +150,10 @@ public void findByBitstreamAndUserTest() throws Exception { getClient().perform(get(search)) .andExpect(status().isUnauthorized()); + // a search that matches nothing is refused too + getClient().perform(get("/api/core/clarinlruallowances/search/byBitstreamAndUser?bitstreamUUID=" + + bitstream.getID() + "&userUUID=" + otherEPerson.getID())) + .andExpect(status().isUnauthorized()); String userToken = getAuthToken(eperson.getEmail(), password); getClient(userToken).perform(get(search)) diff --git a/dspace-server-webapp/src/test/java/org/dspace/app/rest/ClarinUserMetadataRestRepositoryIT.java b/dspace-server-webapp/src/test/java/org/dspace/app/rest/ClarinUserMetadataRestRepositoryIT.java index 71f4fd3f1e65..462472bbf7b5 100644 --- a/dspace-server-webapp/src/test/java/org/dspace/app/rest/ClarinUserMetadataRestRepositoryIT.java +++ b/dspace-server-webapp/src/test/java/org/dspace/app/rest/ClarinUserMetadataRestRepositoryIT.java @@ -13,6 +13,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import java.nio.charset.StandardCharsets; +import java.util.UUID; import org.apache.commons.io.IOUtils; import org.dspace.app.rest.test.AbstractControllerIntegrationTest; @@ -194,6 +195,10 @@ public void findByUserRegistrationAndBitstreamTest() throws Exception { getClient().perform(get(search)) .andExpect(status().isUnauthorized()); + // a search that matches nothing is refused too + getClient().perform(get("/api/core/clarinusermetadatas/search/byUserRegistrationAndBitstream?userRegUUID=" + + clarinUserRegistration.getID() + "&bitstreamUUID=" + UUID.randomUUID())) + .andExpect(status().isUnauthorized()); String userToken = getAuthToken(eperson.getEmail(), password); getClient(userToken).perform(get(search)) diff --git a/dspace-server-webapp/src/test/java/org/dspace/app/rest/ClarinUserRegistrationRestRepositoryIT.java b/dspace-server-webapp/src/test/java/org/dspace/app/rest/ClarinUserRegistrationRestRepositoryIT.java index 016e89cf558f..b02cba17e079 100644 --- a/dspace-server-webapp/src/test/java/org/dspace/app/rest/ClarinUserRegistrationRestRepositoryIT.java +++ b/dspace-server-webapp/src/test/java/org/dspace/app/rest/ClarinUserRegistrationRestRepositoryIT.java @@ -135,6 +135,10 @@ public void findByEPersonTest() throws Exception { getClient().perform(get(search)) .andExpect(status().isUnauthorized()); + // a search that matches nothing is refused too + getClient().perform(get("/api/core/clarinuserregistrations/search/byEPerson?userUUID=" + + otherEPerson.getID())) + .andExpect(status().isUnauthorized()); String userToken = getAuthToken(eperson.getEmail(), password); getClient(userToken).perform(get(search))