mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-15 22:13:08 +00:00
DURACOM-136 improve handling and testing of invalid mimetype
This commit is contained in:
@@ -19,9 +19,12 @@ import org.dspace.app.rest.model.hateoas.ProcessResource;
|
|||||||
import org.dspace.app.rest.repository.ScriptRestRepository;
|
import org.dspace.app.rest.repository.ScriptRestRepository;
|
||||||
import org.dspace.app.rest.utils.ContextUtil;
|
import org.dspace.app.rest.utils.ContextUtil;
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
|
import org.dspace.scripts.configuration.ScriptConfiguration;
|
||||||
|
import org.dspace.scripts.service.ScriptService;
|
||||||
import org.dspace.services.RequestService;
|
import org.dspace.services.RequestService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.rest.webmvc.ControllerUtils;
|
import org.springframework.data.rest.webmvc.ControllerUtils;
|
||||||
|
import org.springframework.data.rest.webmvc.ResourceNotFoundException;
|
||||||
import org.springframework.hateoas.RepresentationModel;
|
import org.springframework.hateoas.RepresentationModel;
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
@@ -50,6 +53,9 @@ public class ScriptProcessesController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private ScriptRestRepository scriptRestRepository;
|
private ScriptRestRepository scriptRestRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ScriptService scriptService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private RequestService requestService;
|
private RequestService requestService;
|
||||||
|
|
||||||
@@ -80,9 +86,17 @@ public class ScriptProcessesController {
|
|||||||
@RequestMapping(method = RequestMethod.POST, consumes = "!" + MediaType.MULTIPART_FORM_DATA_VALUE)
|
@RequestMapping(method = RequestMethod.POST, consumes = "!" + MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||||
@PreAuthorize("hasAuthority('AUTHENTICATED')")
|
@PreAuthorize("hasAuthority('AUTHENTICATED')")
|
||||||
public ResponseEntity<RepresentationModel<?>> startProcessInvalidMimeType(
|
public ResponseEntity<RepresentationModel<?>> startProcessInvalidMimeType(
|
||||||
@PathVariable(name = "name") String scriptName,
|
@PathVariable(name = "name") String scriptName)
|
||||||
@RequestParam(name = "file", required = false) List<MultipartFile> files)
|
|
||||||
throws Exception {
|
throws Exception {
|
||||||
|
if (log.isTraceEnabled()) {
|
||||||
|
log.trace("Starting Process for Script with name: " + scriptName);
|
||||||
|
}
|
||||||
|
Context context = ContextUtil.obtainContext(requestService.getCurrentRequest().getHttpServletRequest());
|
||||||
|
ScriptConfiguration scriptToExecute = scriptService.getScriptConfiguration(scriptName);
|
||||||
|
|
||||||
|
if (scriptToExecute == null) {
|
||||||
|
throw new ResourceNotFoundException("The script for name: " + scriptName + " wasn't found");
|
||||||
|
}
|
||||||
throw new DSpaceBadRequestException("Invalid mimetype");
|
throw new DSpaceBadRequestException("Invalid mimetype");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -134,6 +134,13 @@ public class ScriptRestRepositoryIT extends AbstractControllerIntegrationTest {
|
|||||||
.andExpect(jsonPath("$.page.totalElements", is(0)));
|
.andExpect(jsonPath("$.page.totalElements", is(0)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void findAllScriptsAnonymousUserTest() throws Exception {
|
||||||
|
getClient().perform(get("/api/system/scripts"))
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(jsonPath("$.page.totalElements", is(0)));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void findAllScriptsLocalAdminsTest() throws Exception {
|
public void findAllScriptsLocalAdminsTest() throws Exception {
|
||||||
context.turnOffAuthorisationSystem();
|
context.turnOffAuthorisationSystem();
|
||||||
@@ -543,8 +550,13 @@ public class ScriptRestRepositoryIT extends AbstractControllerIntegrationTest {
|
|||||||
public void postProcessAdminWithWrongContentTypeBadRequestException() throws Exception {
|
public void postProcessAdminWithWrongContentTypeBadRequestException() throws Exception {
|
||||||
|
|
||||||
String token = getAuthToken(admin.getEmail(), password);
|
String token = getAuthToken(admin.getEmail(), password);
|
||||||
|
|
||||||
|
getClient(token)
|
||||||
|
.perform(post("/api/system/scripts/mock-script/processes"))
|
||||||
|
.andExpect(status().isBadRequest());
|
||||||
|
|
||||||
getClient(token).perform(post("/api/system/scripts/mock-script-invalid/processes"))
|
getClient(token).perform(post("/api/system/scripts/mock-script-invalid/processes"))
|
||||||
.andExpect(status().isBadRequest());
|
.andExpect(status().isNotFound());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Reference in New Issue
Block a user