Skip to content

Commit

Permalink
PR feedback updates: renamed custom MultipartResolver class name, rem…
Browse files Browse the repository at this point in the history
…oved spring-test dependency.
  • Loading branch information
tkomlodi committed Nov 27, 2023
1 parent daa993c commit d1db58f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
2 changes: 0 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,6 @@ dependencies {
// https://mvnrepository.com/artifact/org.assertj/assertj-core
testImplementation group: 'org.assertj', name: 'assertj-core', version: '3.17.2'

testImplementation group: 'org.springframework', name: 'spring-test'

// https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-data-jpa
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: '2.3.1.RELEASE'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public JdbcTemplate applicationJdbcTemplate(
@Bean
@Order(0)
public MultipartFilter multipartFilter() {
class CustomMF extends MultipartFilter {
class MaxUploadSizeOverrideMultipartFilter extends MultipartFilter {
@Override
protected MultipartResolver lookupMultipartResolver(HttpServletRequest request) {
if (MAX_FILE_UPLOAD_SIZE_OVERRIDE_PATHS.contains(request.getServletPath())) {
Expand All @@ -158,6 +158,6 @@ protected MultipartResolver lookupMultipartResolver(HttpServletRequest request)
}
}
};
return new CustomMF();
return new MaxUploadSizeOverrideMultipartFilter();
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package org.sasanlabs.service.vulnerability.fileupload;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.when;

import java.io.IOException;
import java.net.URISyntaxException;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.sasanlabs.service.vulnerability.bean.GenericVulnerabilityResponseBean;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.web.multipart.MultipartFile;

public class UnrestrictedFileUploadTest {
private UnrestrictedFileUpload unrestrictedFileUpload;
Expand All @@ -24,10 +25,13 @@ void setUp() throws IOException, URISyntaxException {
void unrestrictedFileSizeUploadLevel10_OverLimitFileSize_FileContentSavedInMemory()
throws Exception {
final byte[] fileContent = "Test file content".getBytes();
MockMultipartFile m =
new MockMultipartFile("file", "file.txt", MediaType.TEXT_PLAIN_VALUE, fileContent);

MultipartFile multiplartFile = Mockito.mock(MultipartFile.class);
when(multiplartFile.getBytes()).thenReturn(fileContent);

ResponseEntity<GenericVulnerabilityResponseBean<String>> result =
unrestrictedFileUpload.getVulnerablePayloadLevel10(m);
unrestrictedFileUpload.getVulnerablePayloadLevel10(multiplartFile);

assertEquals(HttpStatus.OK, result.getStatusCode());

assertEquals(
Expand Down

0 comments on commit d1db58f

Please sign in to comment.