mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 01:54:22 +00:00
#9668: Ensure proper handling of non-subpath URLs in link tokens
(cherry picked from commit 6eb3271fa3
)
This commit is contained in:

committed by
github-actions[bot]
![github-actions[bot]](/assets/img/avatar_default.png)
parent
083f7b45e0
commit
6f1bc3bb6a
@@ -297,8 +297,9 @@ public class RequestItemRepository
|
||||
final String base = configurationService.getProperty("dspace.ui.url");
|
||||
URIBuilder uriBuilder = new URIBuilder(base);
|
||||
// Add request-a-copy/token to the existing path (without breaking /sub/dir dspace URLs)
|
||||
URI uri = uriBuilder.setPath(StringUtils.stripEnd(uriBuilder.getPath(), "")
|
||||
+ "/request-a-copy/" + token).build();
|
||||
URI uri = uriBuilder.setPath(
|
||||
(uriBuilder.getPath() == null ? "" : StringUtils.stripEnd(uriBuilder.getPath(), ""))
|
||||
+ "/request-a-copy/" + token).build();
|
||||
return uri.toURL().toExternalForm();
|
||||
}
|
||||
}
|
||||
|
@@ -606,10 +606,10 @@ public class RequestItemRepositoryIT
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that generated links include the correct base URL, even if it has extra URL segments
|
||||
* Test that generated links include the correct base URL, where the UI URL has a subpath like /subdir
|
||||
*/
|
||||
@Test
|
||||
public void testGetLinkTokenEmail() throws MalformedURLException, URISyntaxException {
|
||||
public void testGetLinkTokenEmailWithSubPath() throws MalformedURLException, URISyntaxException {
|
||||
RequestItemRepository instance = applicationContext.getBean(
|
||||
RequestItemRest.CATEGORY + '.' + RequestItemRest.PLURAL_NAME,
|
||||
RequestItemRepository.class);
|
||||
@@ -623,4 +623,20 @@ public class RequestItemRepositoryIT
|
||||
assertEquals(expectedUrl, generatedLink);
|
||||
configurationService.reloadConfig();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that generated links include the correct base URL, with NO subpath elements
|
||||
*/
|
||||
@Test
|
||||
public void testGetLinkTokenEmailWithoutSubPath() throws MalformedURLException, URISyntaxException {
|
||||
RequestItemRepository instance = applicationContext.getBean(
|
||||
RequestItemRest.CATEGORY + '.' + RequestItemRest.PLURAL_NAME,
|
||||
RequestItemRepository.class);
|
||||
String currentDspaceUrl = configurationService.getProperty("dspace.ui.url");
|
||||
String expectedUrl = currentDspaceUrl + "/request-a-copy/token";
|
||||
String generatedLink = instance.getLinkTokenEmail("token");
|
||||
// The URLs should match
|
||||
assertEquals(expectedUrl, generatedLink);
|
||||
configurationService.reloadConfig();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user