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;
import it.inaf.ia2.transfer.persistence.FileDAO;
import it.inaf.ia2.transfer.persistence.model.FileInfo;
import it.inaf.oats.vospace.exception.InvalidArgumentException;
import it.inaf.oats.vospace.exception.QuotaExceededException;
import java.io.File;
import java.io.IOException;
......@@ -96,9 +97,12 @@ public class PutFileService {
// the first upload (fsPath not null)
if(destinationFileInfo.getActualBasePath() != null) {
if(destinationFileInfo.getFsPath() != null) {
LOG.warn("Node {} fsPath is not null: {}. Overwriting.",
LOG.error("Node {} fsPath is not null: {}. Overwriting.",
destinationFileInfo.getVirtualPath(),
destinationFileInfo.getFsPath());
throw new InvalidArgumentException("Node " +
destinationFileInfo.getVirtualPath() +
" is already populated. Overwriting not allowed.");
}
destinationFileInfo.setFsPath(this.generateFsPath().toString());
......
......@@ -34,9 +34,6 @@ public class CopyControllerTest {
@Autowired
private MockMvc mockMvc;
@MockBean
private FileCopyService fileCopyService;
private static String jobId;
private static String sourceVosRootPath;
......
......@@ -98,7 +98,23 @@ public class PutFileControllerTest {
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
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