Commit 7e0a7327 authored by Sonia Zorba's avatar Sonia Zorba
Browse files

Fixed special characters issue on pullFromVoSpace

parent a80fd0ac
Pipeline #7878 passed with stages
in 2 minutes and 34 seconds
...@@ -28,7 +28,6 @@ import org.springframework.http.HttpMethod; ...@@ -28,7 +28,6 @@ import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import static org.springframework.web.servlet.mvc.method.RequestMappingInfo.paths;
@Component @Component
public class FileServiceClient { public class FileServiceClient {
......
...@@ -26,6 +26,7 @@ import it.inaf.oats.vospace.persistence.model.Location; ...@@ -26,6 +26,7 @@ import it.inaf.oats.vospace.persistence.model.Location;
import it.inaf.oats.vospace.persistence.model.LocationType; import it.inaf.oats.vospace.persistence.model.LocationType;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
...@@ -41,6 +42,7 @@ import net.ivoa.xml.vospace.v2.Transfer; ...@@ -41,6 +42,7 @@ import net.ivoa.xml.vospace.v2.Transfer;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
@Service @Service
public class UriService { public class UriService {
...@@ -179,7 +181,8 @@ public class UriService { ...@@ -179,7 +181,8 @@ public class UriService {
private String getEndpoint(JobSummary job, Transfer transfer) { private String getEndpoint(JobSummary job, Transfer transfer) {
String relativePath = URIUtils.returnVosPathFromNodeURI(transfer.getTarget(), authority); String relativePath = StringUtils.uriDecode(URIUtils
.returnVosPathFromNodeURI(transfer.getTarget(), authority), StandardCharsets.UTF_8);
User user = (User) servletRequest.getUserPrincipal(); User user = (User) servletRequest.getUserPrincipal();
String creator = user.getName(); String creator = user.getName();
...@@ -201,6 +204,7 @@ public class UriService { ...@@ -201,6 +204,7 @@ public class UriService {
case pullFromVoSpace: case pullFromVoSpace:
// Refresh relative path: it can differ in case of links followed // Refresh relative path: it can differ in case of links followed
relativePath = NodeUtils.getVosPath(node); relativePath = NodeUtils.getVosPath(node);
relativePath = StringUtils.uriDecode(relativePath, StandardCharsets.UTF_8);
if (!NodeUtils.checkIfReadable(node, creator, groups)) { if (!NodeUtils.checkIfReadable(node, creator, groups)) {
throw PermissionDeniedException.forPath(relativePath); throw PermissionDeniedException.forPath(relativePath);
} }
......
...@@ -560,6 +560,38 @@ public class UriServiceTest { ...@@ -560,6 +560,38 @@ public class UriServiceTest {
assertTrue(ex.getMessage().contains("no protocol")); assertTrue(ex.getMessage().contains("no protocol"));
} }
@Test
public void testPullFileWithSpecialChars() {
DataNode node = new DataNode();
node.setUri("vos://example.com!vospace/(%20+%20).txt");
Property publicProperty = new Property();
publicProperty.setUri(NodeProperties.PUBLIC_READ_URI);
publicProperty.setValue(String.valueOf(true));
node.getProperties().add(publicProperty);
when(nodeDAO.listNode(eq("/( + ).txt"))).thenReturn(Optional.of(node));
Transfer transfer = new Transfer();
transfer.setDirection("pullFromVoSpace");
transfer.setTarget("vos://example.com!vospace/(%20+%20).txt");
Protocol protocol = new Protocol();
protocol.setUri("ivo://ivoa.net/vospace/core#httpget");
transfer.getProtocols().add(protocol);
JobSummary job = new JobSummary();
JobSummary.JobInfo jobInfo = new JobSummary.JobInfo();
jobInfo.getAny().add(transfer);
job.setJobInfo(jobInfo);
Transfer negotiatedTransfer = uriService.getNegotiatedTransfer(job, transfer);
assertEquals(1, negotiatedTransfer.getProtocols().size());
assertTrue(negotiatedTransfer.getProtocols().get(0).getEndpoint().contains("/%28%20%2B%20%29.txt"));
}
private void testArchiveViewEndpoint(String viewUri) { private void testArchiveViewEndpoint(String viewUri) {
Transfer transfer = new Transfer(); Transfer transfer = new Transfer();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment