diff --git a/src/test/java/org/sasanlabs/service/vulnerability/sqlInjection/UnionBasedSQLInjectionVulnerabilityTest.java b/src/test/java/org/sasanlabs/service/vulnerability/sqlInjection/UnionBasedSQLInjectionVulnerabilityTest.java index 8bc984d3..fc24740b 100644 --- a/src/test/java/org/sasanlabs/service/vulnerability/sqlInjection/UnionBasedSQLInjectionVulnerabilityTest.java +++ b/src/test/java/org/sasanlabs/service/vulnerability/sqlInjection/UnionBasedSQLInjectionVulnerabilityTest.java @@ -45,7 +45,7 @@ void getCarInformationLevel1_ExpectParamInjected() throws IOException { @Test void getCarInformationLevel2_ExpectParamInjected() throws IOException { // Act - Map params = new HashMap(); + final Map params = new HashMap<>(); params.put("id", "1' UNION SELECT * FROM cars; --"); unionBasedSQLInjectionVulnerability.getCarInformationLevel2(params); @@ -56,7 +56,7 @@ void getCarInformationLevel2_ExpectParamInjected() throws IOException { @Test void getCarInformationLevel3_ExpectParamEscaped() throws IOException { // Act - Map params = new HashMap(); + final Map params = new HashMap<>(); params.put("id", "1' UNION SELECT * FROM cars; --"); unionBasedSQLInjectionVulnerability.getCarInformationLevel3(params); @@ -66,10 +66,9 @@ void getCarInformationLevel3_ExpectParamEscaped() throws IOException { } @Test - void getCarInformationLevel4_ExpectParamEscaped() throws IOException { + void getCarInformationLevel4_ExpecParamEscaped() throws IOException { // Setup template = Mockito.spy(new JdbcTemplate()); - PreparedStatementSetter setter = (ps) -> {}; doReturn(null) .when(template) .query(anyString(), (PreparedStatementSetter) any(), (ResultSetExtractor) any()); @@ -77,7 +76,7 @@ void getCarInformationLevel4_ExpectParamEscaped() throws IOException { unionBasedSQLInjectionVulnerability = Mockito.spy(new UnionBasedSQLInjectionVulnerability(template)); // Act - Map params = new HashMap(); + final Map params = new HashMap<>(); params.put("id", "1' UNION SELECT * FROM cars; --"); unionBasedSQLInjectionVulnerability.getCarInformationLevel4(params); @@ -85,106 +84,4 @@ void getCarInformationLevel4_ExpectParamEscaped() throws IOException { verify(template).query(eq("select * from cars where id=?"), (PreparedStatementSetter) any(), (ResultSetExtractor) any()); } - -// private JdbcTemplate applicationJdbcTemplate; -// -// public UnionBasedSQLInjectionVulnerabilityTest( -// @Qualifier("applicationJdbcTemplate") JdbcTemplate applicationJdbcTemplate) { -// this.applicationJdbcTemplate = applicationJdbcTemplate; -// } -// -// @AttackVector( -// vulnerabilityExposed = VulnerabilityType.UNION_BASED_SQL_INJECTION, -// description = "UNION_SQL_INJECTION_URL_PARAM_APPENDED_DIRECTLY_TO_QUERY", -// payload = "UNION_BASED_SQL_INJECTION_PAYLOAD_LEVEL_1") -// @VulnerableAppRequestMapping( -// value = LevelConstants.LEVEL_1, -// htmlTemplate = "LEVEL_1/SQLInjection_Level1") -// public ResponseEntity getCarInformationLevel1( -// @RequestParam Map queryParams) { -// String id = queryParams.get("id"); -// return applicationJdbcTemplate.query( -// "select * from cars where id=" + id, -// (rs) -> { -// CarInformation carInformation = new CarInformation(); -// if (rs.next()) { -// carInformation.setId(rs.getInt(1)); -// carInformation.setName(rs.getString(2)); -// carInformation.setImagePath(rs.getString(3)); -// } -// return new ResponseEntity(carInformation, HttpStatus.OK); -// }); -// } -// -// @AttackVector( -// vulnerabilityExposed = VulnerabilityType.UNION_BASED_SQL_INJECTION, -// description = -// "UNION_SQL_INJECTION_URL_PARAM_WRAPPED_WITH_SINGLE_QUOTE_APPENDED_TO_QUERY", -// payload = "UNION_BASED_SQL_INJECTION_PAYLOAD_LEVEL_2") -// @VulnerableAppRequestMapping( -// value = LevelConstants.LEVEL_2, -// htmlTemplate = "LEVEL_1/SQLInjection_Level1") -// public ResponseEntity getCarInformationLevel2( -// @RequestParam Map queryParams) { -// String id = queryParams.get("id"); -// CarInformation carInformation = new CarInformation(); -// return applicationJdbcTemplate.query( -// "select * from cars where id='" + id + "'", -// (rs) -> { -// if (rs.next()) { -// carInformation.setId(rs.getInt(1)); -// carInformation.setName(rs.getString(2)); -// carInformation.setImagePath(rs.getString(3)); -// } -// return new ResponseEntity(carInformation, HttpStatus.OK); -// }); -// } -// -// @AttackVector( -// vulnerabilityExposed = VulnerabilityType.UNION_BASED_SQL_INJECTION, -// description = -// "UNION_SQL_INJECTION_URL_PARAM_REMOVES_SINGLE_QUOTE_WITH_SINGLE_QUOTE_APPENDED_TO_QUERY") -// @VulnerableAppRequestMapping( -// value = LevelConstants.LEVEL_3, -// variant = Variant.SECURE, -// htmlTemplate = "LEVEL_1/SQLInjection_Level1") -// public ResponseEntity getCarInformationLevel3( -// @RequestParam Map queryParams) { -// String id = queryParams.get("id").replaceAll("'", ""); -// return applicationJdbcTemplate.query( -// "select * from cars where id='" + id + "'", -// (rs) -> { -// CarInformation carInformation = new CarInformation(); -// if (rs.next()) { -// carInformation.setId(rs.getInt(1)); -// carInformation.setName(rs.getString(2)); -// carInformation.setImagePath(rs.getString(3)); -// } -// return new ResponseEntity(carInformation, HttpStatus.OK); -// }); -// } -// -// @VulnerableAppRequestMapping( -// value = LevelConstants.LEVEL_4, -// variant = Variant.SECURE, -// htmlTemplate = "LEVEL_1/SQLInjection_Level1") -// public ResponseEntity getCarInformationLevel4( -// @RequestParam Map queryParams) { -// String id = queryParams.get("id"); -// -// return applicationJdbcTemplate.query( -// "select * from cars where id=?", -// (prepareStatement) -> { -// prepareStatement.setString(1, id); -// }, -// (rs) -> { -// CarInformation carInformation = new CarInformation(); -// if (rs.next()) { -// carInformation.setId(rs.getInt(1)); -// carInformation.setName(rs.getString(2)); -// carInformation.setImagePath(rs.getString(3)); -// } -// return new ResponseEntity(carInformation, HttpStatus.OK); -// }); -// } }