-
-
Notifications
You must be signed in to change notification settings - Fork 420
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added new UnrestrectedFileUpload vulnerability with unrestricted file…
… size. #351
- Loading branch information
Showing
7 changed files
with
119 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/test/java/org/sasanlabs/service/vulnerability/fileupload/UnrestrictedFileUploadTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package org.sasanlabs.service.vulnerability.fileupload; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.io.IOException; | ||
import java.net.URISyntaxException; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
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; | ||
|
||
public class UnrestrictedFileUploadTest { | ||
private UnrestrictedFileUpload unrestrictedFileUpload; | ||
|
||
@BeforeEach | ||
void setUp() throws IOException, URISyntaxException { | ||
unrestrictedFileUpload = new UnrestrictedFileUpload(); | ||
} | ||
|
||
@Test | ||
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); | ||
ResponseEntity<GenericVulnerabilityResponseBean<String>> result = | ||
unrestrictedFileUpload.getVulnerablePayloadLevel10(m); | ||
assertEquals(HttpStatus.OK, result.getStatusCode()); | ||
|
||
assertEquals( | ||
1, | ||
unrestrictedFileUpload.getStoredFiles().size(), | ||
"Uploaded file with unrestricted size is not found."); | ||
assertEquals( | ||
fileContent, | ||
unrestrictedFileUpload.getStoredFiles().get(0), | ||
"The content of uploaded file with unrestricted size is unexpected."); | ||
} | ||
} |