Skip to content

Commit

Permalink
Block user from starting queued downloads with set status #42
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick-austin committed Nov 22, 2024
1 parent 26649e1 commit 4c3b281
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,9 @@ public Response setDownloadStatus(
if (!download.getUserName().equals(cartUserName)) {
throw new ForbiddenException("you do not have permission to delete this download");
}
if (download.getPreparedId() == null && download.getStatus().equals(DownloadStatus.PAUSED)) {
throw new ForbiddenException("Cannot modify status of a queued download");
}

download.setStatus(DownloadStatus.valueOf(value));
if(value.equals("COMPLETE")){
Expand Down
27 changes: 27 additions & 0 deletions src/test/java/org/icatproject/topcat/UserResourceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

import org.icatproject.topcat.httpclient.HttpClient;
import org.icatproject.topcat.domain.*;
import org.icatproject.topcat.exceptions.ForbiddenException;

import java.net.URLEncoder;

import org.icatproject.topcat.repository.CacheRepository;
Expand Down Expand Up @@ -255,6 +257,31 @@ public void testSubmitCart() throws Exception {
assertTrue(newDownload.getIsDeleted());
}

@Test
public void testSetDownloadStatus() throws Exception {
Download testDownload = new Download();
String facilityName = "LILS";
testDownload.setFacilityName(facilityName);
testDownload.setSessionId(sessionId);
testDownload.setStatus(DownloadStatus.PAUSED);
testDownload.setIsDeleted(false);
testDownload.setUserName("simple/root");
testDownload.setFileName("testFile.txt");
testDownload.setTransport("http");
downloadRepository.save(testDownload);

assertThrows("Cannot modify status of a queued download", ForbiddenException.class, () -> {
userResource.setDownloadStatus(testDownload.getId(), facilityName, sessionId, DownloadStatus.RESTORING.toString());
});

Response response = userResource.getDownloads(facilityName, sessionId, "1 = 1");
assertEquals(200, response.getStatus());
List<Download> downloads = (List<Download>) response.getEntity();

Download unmodifiedDownload = findDownload(downloads, testDownload.getId());
assertEquals(DownloadStatus.PAUSED, unmodifiedDownload.getStatus());
}

@Test
public void testGetDownloadTypeStatus() throws Exception {

Expand Down

0 comments on commit 4c3b281

Please sign in to comment.