-
-
Notifications
You must be signed in to change notification settings - Fork 417
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add test for PathTraversal class #456
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
306 changes: 306 additions & 0 deletions
306
src/test/java/org/sasanlabs/service/vulnerability/pathTraversal/PathTraversalTest.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,306 @@ | ||
package org.sasanlabs.service.vulnerability.pathTraversal; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.mockito.InjectMocks; | ||
import org.sasanlabs.service.vulnerability.bean.GenericVulnerabilityResponseBean; | ||
import org.springframework.http.HttpMethod; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.http.RequestEntity; | ||
|
||
|
||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
|
||
class PathTraversalVulnerabilityTest { | ||
@InjectMocks | ||
private PathTraversalVulnerability pathTraversalVulnerability = new PathTraversalVulnerability(); | ||
@Test | ||
void testGetVulnerablePayloadLevel1WithNullFileName() { | ||
Map<String, String> queryParams = new HashMap<>(); | ||
queryParams.put("fileName", null); | ||
ResponseEntity<GenericVulnerabilityResponseBean<String>> response = | ||
pathTraversalVulnerability.getVulnerablePayloadLevel1(queryParams); | ||
assertEquals(HttpStatus.OK, response.getStatusCode()); | ||
assertNotNull(response.getBody()); | ||
assertFalse(response.getBody().getIsValid()); | ||
assertNull(response.getBody().getContent()); | ||
} | ||
@Test | ||
void testGetVulnerablePayloadLevel1() { | ||
Map<String, String> queryParams = new HashMap<>(); | ||
queryParams.put("fileName", "UserInfo.json"); | ||
ResponseEntity<GenericVulnerabilityResponseBean<String>> response = | ||
pathTraversalVulnerability.getVulnerablePayloadLevel1(queryParams); | ||
assertEquals(HttpStatus.OK, response.getStatusCode()); | ||
} | ||
@Test | ||
void testGetVulnerablePayloadLevel2WithNullFileName() throws URISyntaxException { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @richard66033 can you please use other conditions for test instead of just Null like |
||
Map<String, String> queryParams = new HashMap<>(); | ||
queryParams.put("fileName", null); | ||
RequestEntity<String> requestEntity = | ||
new RequestEntity<>( | ||
HttpMethod.GET, new URI("localhost")); | ||
ResponseEntity<GenericVulnerabilityResponseBean<String>> response = | ||
pathTraversalVulnerability.getVulnerablePayloadLevel2(requestEntity,queryParams); | ||
assertEquals(HttpStatus.OK, response.getStatusCode()); | ||
assertNotNull(response.getBody()); | ||
assertFalse(response.getBody().getIsValid()); | ||
assertNull(response.getBody().getContent()); | ||
} | ||
@Test | ||
void testGetVulnerablePayloadLevel2() throws URISyntaxException { | ||
Map<String, String> queryParams = new HashMap<>(); | ||
queryParams.put("fileName", "UserInfo.json"); | ||
RequestEntity<String> requestEntity = | ||
new RequestEntity<>( | ||
HttpMethod.GET, new URI("localhost")); | ||
ResponseEntity<GenericVulnerabilityResponseBean<String>> response = | ||
pathTraversalVulnerability.getVulnerablePayloadLevel2(requestEntity,queryParams); | ||
assertEquals(HttpStatus.OK, response.getStatusCode()); | ||
} | ||
@Test | ||
void testGetVulnerablePayloadLevel3WithNullFileName() throws URISyntaxException { | ||
Map<String, String> queryParams = new HashMap<>(); | ||
queryParams.put("fileName", null); | ||
RequestEntity<String> requestEntity = | ||
new RequestEntity<>( | ||
HttpMethod.GET, new URI("localhost")); | ||
ResponseEntity<GenericVulnerabilityResponseBean<String>> response = | ||
pathTraversalVulnerability.getVulnerablePayloadLevel3(requestEntity,queryParams); | ||
assertEquals(HttpStatus.OK, response.getStatusCode()); | ||
assertNotNull(response.getBody()); | ||
assertFalse(response.getBody().getIsValid()); | ||
assertNull(response.getBody().getContent()); | ||
} | ||
|
||
@Test | ||
void testGetVulnerablePayloadLevel3() throws URISyntaxException { | ||
Map<String, String> queryParams = new HashMap<>(); | ||
queryParams.put("fileName", "UserInfo.json"); | ||
RequestEntity<String> requestEntity = | ||
new RequestEntity<>( | ||
HttpMethod.GET, new URI("localhost")); | ||
ResponseEntity<GenericVulnerabilityResponseBean<String>> response = | ||
pathTraversalVulnerability.getVulnerablePayloadLevel3(requestEntity,queryParams); | ||
assertEquals(HttpStatus.OK, response.getStatusCode()); | ||
} | ||
@Test | ||
void testGetVulnerablePayloadLevel4WithNullFileName() throws URISyntaxException { | ||
Map<String, String> queryParams = new HashMap<>(); | ||
queryParams.put("fileName", null); | ||
RequestEntity<String> requestEntity = | ||
new RequestEntity<>( | ||
HttpMethod.GET, new URI("localhost")); | ||
ResponseEntity<GenericVulnerabilityResponseBean<String>> response = | ||
pathTraversalVulnerability.getVulnerablePayloadLevel4(requestEntity,queryParams); | ||
assertEquals(HttpStatus.OK, response.getStatusCode()); | ||
assertNotNull(response.getBody()); | ||
assertFalse(response.getBody().getIsValid()); | ||
assertNull(response.getBody().getContent()); | ||
} | ||
@Test | ||
void testGetVulnerablePayloadLevel4() throws URISyntaxException { | ||
Map<String, String> queryParams = new HashMap<>(); | ||
queryParams.put("fileName", "UserInfo.json"); | ||
RequestEntity<String> requestEntity = | ||
new RequestEntity<>( | ||
HttpMethod.GET, new URI("localhost")); | ||
ResponseEntity<GenericVulnerabilityResponseBean<String>> response = | ||
pathTraversalVulnerability.getVulnerablePayloadLevel4(requestEntity,queryParams); | ||
assertEquals(HttpStatus.OK, response.getStatusCode()); | ||
} | ||
@Test | ||
void testGetVulnerablePayloadLevel5WithNullFileName() throws URISyntaxException { | ||
Map<String, String> queryParams = new HashMap<>(); | ||
queryParams.put("fileName", null); | ||
RequestEntity<String> requestEntity = | ||
new RequestEntity<>( | ||
HttpMethod.GET, new URI("localhost")); | ||
ResponseEntity<GenericVulnerabilityResponseBean<String>> response = | ||
pathTraversalVulnerability.getVulnerablePayloadLevel5(requestEntity,queryParams); | ||
assertEquals(HttpStatus.OK, response.getStatusCode()); | ||
assertNotNull(response.getBody()); | ||
assertFalse(response.getBody().getIsValid()); | ||
assertNull(response.getBody().getContent()); | ||
} | ||
@Test | ||
void testGetVulnerablePayloadLevel5() throws URISyntaxException { | ||
Map<String, String> queryParams = new HashMap<>(); | ||
queryParams.put("fileName", "UserInfo.json"); | ||
RequestEntity<String> requestEntity = | ||
new RequestEntity<>( | ||
HttpMethod.GET, new URI("localhost")); | ||
ResponseEntity<GenericVulnerabilityResponseBean<String>> response = | ||
pathTraversalVulnerability.getVulnerablePayloadLevel5(requestEntity,queryParams); | ||
assertEquals(HttpStatus.OK, response.getStatusCode()); | ||
} | ||
@Test | ||
void testGetVulnerablePayloadLevel6WithNullFileName() { | ||
Map<String, String> queryParams = new HashMap<>(); | ||
queryParams.put("fileName", null); | ||
ResponseEntity<GenericVulnerabilityResponseBean<String>> response = | ||
pathTraversalVulnerability.getVulnerablePayloadLevel6(queryParams); | ||
assertEquals(HttpStatus.OK, response.getStatusCode()); | ||
assertNotNull(response.getBody()); | ||
assertFalse(response.getBody().getIsValid()); | ||
assertNull(response.getBody().getContent()); | ||
} | ||
@Test | ||
void testGetVulnerablePayloadLevel6() { | ||
Map<String, String> queryParams = new HashMap<>(); | ||
queryParams.put("fileName", "UserInfo.json"); | ||
ResponseEntity<GenericVulnerabilityResponseBean<String>> response = | ||
pathTraversalVulnerability.getVulnerablePayloadLevel6(queryParams); | ||
assertEquals(HttpStatus.OK, response.getStatusCode()); | ||
} | ||
@Test | ||
void testGetVulnerablePayloadLevel7WithNullFileName() throws URISyntaxException { | ||
Map<String, String> queryParams = new HashMap<>(); | ||
queryParams.put("fileName", null); | ||
RequestEntity<String> requestEntity = | ||
new RequestEntity<>( | ||
HttpMethod.GET, new URI("localhost")); | ||
ResponseEntity<GenericVulnerabilityResponseBean<String>> response = | ||
pathTraversalVulnerability.getVulnerablePayloadLevel7(requestEntity,queryParams); | ||
assertEquals(HttpStatus.OK, response.getStatusCode()); | ||
assertNotNull(response.getBody()); | ||
assertFalse(response.getBody().getIsValid()); | ||
assertNull(response.getBody().getContent()); | ||
} | ||
@Test | ||
void testGetVulnerablePayloadLevel7() throws URISyntaxException { | ||
Map<String, String> queryParams = new HashMap<>(); | ||
queryParams.put("fileName", "UserInfo.json"); | ||
RequestEntity<String> requestEntity = | ||
new RequestEntity<>( | ||
HttpMethod.GET, new URI("localhost")); | ||
ResponseEntity<GenericVulnerabilityResponseBean<String>> response = | ||
pathTraversalVulnerability.getVulnerablePayloadLevel7(requestEntity,queryParams); | ||
assertEquals(HttpStatus.OK, response.getStatusCode()); | ||
} | ||
@Test | ||
void testGetVulnerablePayloadLevel8WithNullFileName() throws URISyntaxException { | ||
Map<String, String> queryParams = new HashMap<>(); | ||
queryParams.put("fileName", null); | ||
RequestEntity<String> requestEntity = | ||
new RequestEntity<>( | ||
HttpMethod.GET, new URI("localhost")); | ||
ResponseEntity<GenericVulnerabilityResponseBean<String>> response = | ||
pathTraversalVulnerability.getVulnerablePayloadLevel8(requestEntity,queryParams); | ||
assertEquals(HttpStatus.OK, response.getStatusCode()); | ||
assertNotNull(response.getBody()); | ||
assertFalse(response.getBody().getIsValid()); | ||
assertNull(response.getBody().getContent()); | ||
} | ||
@Test | ||
void testGetVulnerablePayloadLevel8() throws URISyntaxException { | ||
Map<String, String> queryParams = new HashMap<>(); | ||
queryParams.put("fileName", "UserInfo.json"); | ||
RequestEntity<String> requestEntity = | ||
new RequestEntity<>( | ||
HttpMethod.GET, new URI("localhost")); | ||
ResponseEntity<GenericVulnerabilityResponseBean<String>> response = | ||
pathTraversalVulnerability.getVulnerablePayloadLevel8(requestEntity,queryParams); | ||
assertEquals(HttpStatus.OK, response.getStatusCode()); | ||
} | ||
@Test | ||
void testGetVulnerablePayloadLevel9WithNullFileName() throws URISyntaxException { | ||
Map<String, String> queryParams = new HashMap<>(); | ||
queryParams.put("fileName", null); | ||
RequestEntity<String> requestEntity = | ||
new RequestEntity<>( | ||
HttpMethod.GET, new URI("localhost")); | ||
ResponseEntity<GenericVulnerabilityResponseBean<String>> response = | ||
pathTraversalVulnerability.getVulnerablePayloadLevel9(requestEntity,queryParams); | ||
assertEquals(HttpStatus.OK, response.getStatusCode()); | ||
assertNotNull(response.getBody()); | ||
assertFalse(response.getBody().getIsValid()); | ||
assertNull(response.getBody().getContent()); | ||
} | ||
@Test | ||
void testGetVulnerablePayloadLevel9() throws URISyntaxException { | ||
Map<String, String> queryParams = new HashMap<>(); | ||
queryParams.put("fileName", "UserInfo.json"); | ||
RequestEntity<String> requestEntity = | ||
new RequestEntity<>( | ||
HttpMethod.GET, new URI("localhost")); | ||
ResponseEntity<GenericVulnerabilityResponseBean<String>> response = | ||
pathTraversalVulnerability.getVulnerablePayloadLevel9(requestEntity,queryParams); | ||
assertEquals(HttpStatus.OK, response.getStatusCode()); | ||
} | ||
@Test | ||
void testGetVulnerablePayloadLevel10WithNullFileName() throws URISyntaxException { | ||
Map<String, String> queryParams = new HashMap<>(); | ||
queryParams.put("fileName", null); | ||
RequestEntity<String> requestEntity = | ||
new RequestEntity<>( | ||
HttpMethod.GET, new URI("localhost")); | ||
ResponseEntity<GenericVulnerabilityResponseBean<String>> response = | ||
pathTraversalVulnerability.getVulnerablePayloadLevel10(requestEntity,queryParams); | ||
assertEquals(HttpStatus.OK, response.getStatusCode()); | ||
assertNotNull(response.getBody()); | ||
assertFalse(response.getBody().getIsValid()); | ||
assertNull(response.getBody().getContent()); | ||
} | ||
@Test | ||
void testGetVulnerablePayloadLevel10() throws URISyntaxException { | ||
Map<String, String> queryParams = new HashMap<>(); | ||
queryParams.put("fileName", "UserInfo.json"); | ||
RequestEntity<String> requestEntity = | ||
new RequestEntity<>( | ||
HttpMethod.GET, new URI("localhost")); | ||
ResponseEntity<GenericVulnerabilityResponseBean<String>> response = | ||
pathTraversalVulnerability.getVulnerablePayloadLevel10(requestEntity,queryParams); | ||
assertEquals(HttpStatus.OK, response.getStatusCode()); | ||
} | ||
@Test | ||
void testGetVulnerablePayloadLevel11WithNullFileName() throws URISyntaxException { | ||
Map<String, String> queryParams = new HashMap<>(); | ||
queryParams.put("fileName", null); | ||
RequestEntity<String> requestEntity = | ||
new RequestEntity<>( | ||
HttpMethod.GET, new URI("localhost")); | ||
ResponseEntity<GenericVulnerabilityResponseBean<String>> response = | ||
pathTraversalVulnerability.getVulnerablePayloadLevel11(requestEntity,queryParams); | ||
assertEquals(HttpStatus.OK, response.getStatusCode()); | ||
assertNotNull(response.getBody()); | ||
assertFalse(response.getBody().getIsValid()); | ||
assertNull(response.getBody().getContent()); | ||
} | ||
@Test | ||
void testGetVulnerablePayloadLevel11() throws URISyntaxException { | ||
Map<String, String> queryParams = new HashMap<>(); | ||
queryParams.put("fileName", "UserInfo.json"); | ||
RequestEntity<String> requestEntity = | ||
new RequestEntity<>( | ||
HttpMethod.GET, new URI("localhost")); | ||
ResponseEntity<GenericVulnerabilityResponseBean<String>> response = | ||
pathTraversalVulnerability.getVulnerablePayloadLevel11(requestEntity,queryParams); | ||
assertEquals(HttpStatus.OK, response.getStatusCode()); | ||
} | ||
@Test | ||
void testGetVulnerablePayloadLevel12WithNullFileName() throws URISyntaxException { | ||
Map<String, String> queryParams = new HashMap<>(); | ||
queryParams.put("fileName", null); | ||
ResponseEntity<GenericVulnerabilityResponseBean<String>> response = | ||
pathTraversalVulnerability.getVulnerablePayloadLevel12(queryParams); | ||
assertEquals(HttpStatus.OK, response.getStatusCode()); | ||
assertNotNull(response.getBody()); | ||
assertFalse(response.getBody().getIsValid()); | ||
assertNull(response.getBody().getContent()); | ||
} | ||
@Test | ||
void testGetVulnerablePayloadLevel12() throws URISyntaxException { | ||
Map<String, String> queryParams = new HashMap<>(); | ||
queryParams.put("fileName", "UserInfo.json"); | ||
ResponseEntity<GenericVulnerabilityResponseBean<String>> response = | ||
pathTraversalVulnerability.getVulnerablePayloadLevel12(queryParams); | ||
assertEquals(HttpStatus.OK, response.getStatusCode()); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please run
./gradlew spotlessApply
this will fix the indentation and will pass the CI/CD pipeline.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.