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
Loading
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -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());                       
+0 −3
Original line number Diff line number Diff line
@@ -35,9 +35,6 @@ public class CopyControllerTest {
    @Autowired
    private MockMvc mockMvc;
    
    @MockBean
    private FileCopyService fileCopyService;
    
    private static String jobId;
    private static String sourceVosRootPath;
    private static String destVosRootPath;
+16 −0
Original line number Diff line number Diff line
@@ -99,6 +99,22 @@ 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 {