Skip to content
Snippets Groups Projects
Commit ab66d88b authored by Nicola Fulvio Calabria's avatar Nicola Fulvio Calabria
Browse files

Added BAD_REQUEST exception in case of file overwrite attempt

parent fb93a17f
No related branches found
No related tags found
No related merge requests found
Pipeline #2438 passed
...@@ -7,6 +7,7 @@ package it.inaf.ia2.transfer.service; ...@@ -7,6 +7,7 @@ package it.inaf.ia2.transfer.service;
import it.inaf.ia2.transfer.persistence.FileDAO; import it.inaf.ia2.transfer.persistence.FileDAO;
import it.inaf.ia2.transfer.persistence.model.FileInfo; import it.inaf.ia2.transfer.persistence.model.FileInfo;
import it.inaf.oats.vospace.exception.InvalidArgumentException;
import it.inaf.oats.vospace.exception.QuotaExceededException; import it.inaf.oats.vospace.exception.QuotaExceededException;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
...@@ -96,9 +97,12 @@ public class PutFileService { ...@@ -96,9 +97,12 @@ public class PutFileService {
// the first upload (fsPath not null) // the first upload (fsPath not null)
if(destinationFileInfo.getActualBasePath() != null) { if(destinationFileInfo.getActualBasePath() != null) {
if(destinationFileInfo.getFsPath() != null) { if(destinationFileInfo.getFsPath() != null) {
LOG.warn("Node {} fsPath is not null: {}. Overwriting.", LOG.error("Node {} fsPath is not null: {}. Overwriting.",
destinationFileInfo.getVirtualPath(), destinationFileInfo.getVirtualPath(),
destinationFileInfo.getFsPath()); destinationFileInfo.getFsPath());
throw new InvalidArgumentException("Node " +
destinationFileInfo.getVirtualPath() +
" is already populated. Overwriting not allowed.");
} }
destinationFileInfo.setFsPath(this.generateFsPath().toString()); destinationFileInfo.setFsPath(this.generateFsPath().toString());
......
...@@ -35,9 +35,6 @@ public class CopyControllerTest { ...@@ -35,9 +35,6 @@ public class CopyControllerTest {
@Autowired @Autowired
private MockMvc mockMvc; private MockMvc mockMvc;
@MockBean
private FileCopyService fileCopyService;
private static String jobId; private static String jobId;
private static String sourceVosRootPath; private static String sourceVosRootPath;
private static String destVosRootPath; private static String destVosRootPath;
......
...@@ -99,6 +99,22 @@ public class PutFileControllerTest { ...@@ -99,6 +99,22 @@ public class PutFileControllerTest {
assertTrue(file.delete()); assertTrue(file.delete());
} }
@Test
public void putGenericFileOverwriteDenied() throws Exception {
when(fileDao.getRemainingQuota(any())).thenReturn(null);
String randomFileName = UUID.randomUUID().toString();
FileInfo fileInfo = createBaseFileInfo(randomFileName);
fileInfo.setFsPath("year/month/date/UUID-whatever");
MockMultipartFile fakeFile = new MockMultipartFile("file", "test.txt", "text/plain", "content".getBytes());
mockMvc.perform(putMultipart("/path/to/test.txt")
.file(fakeFile))
.andDo(print())
.andExpect(status().isBadRequest());
}
@Test @Test
public void putGenericFileWithJobId() throws Exception { public void putGenericFileWithJobId() throws Exception {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment