aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2020-03-16 14:46:26 -0500
committersonartech <sonartech@sonarsource.com>2020-03-19 20:03:53 +0000
commit54e6a6e76a41d6ab96bbec5a5ed1febba96e3a35 (patch)
tree50f81eae00cbf75b0b2966f59f71ffebb3313d17 /server
parent73d64c882358ffb81cfdba5f402e92a3f37bf34e (diff)
downloadsonarqube-54e6a6e76a41d6ab96bbec5a5ed1febba96e3a35.tar.gz
sonarqube-54e6a6e76a41d6ab96bbec5a5ed1febba96e3a35.zip
SONAR-13205 Default QG should fail if Security Hotspots Reviewed on New Code is < 100%
Diffstat (limited to 'server')
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/RegisterQualityGates.java4
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/RegisterQualityGatesTest.java11
2 files changed, 12 insertions, 3 deletions
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/RegisterQualityGates.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/RegisterQualityGates.java
index f5550a2adc7..8bd2f6c2d50 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/RegisterQualityGates.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/RegisterQualityGates.java
@@ -46,6 +46,7 @@ import static org.sonar.api.measures.CoreMetrics.NEW_COVERAGE_KEY;
import static org.sonar.api.measures.CoreMetrics.NEW_DUPLICATED_LINES_DENSITY_KEY;
import static org.sonar.api.measures.CoreMetrics.NEW_MAINTAINABILITY_RATING_KEY;
import static org.sonar.api.measures.CoreMetrics.NEW_RELIABILITY_RATING_KEY;
+import static org.sonar.api.measures.CoreMetrics.NEW_SECURITY_HOTSPOTS_REVIEWED_KEY;
import static org.sonar.api.measures.CoreMetrics.NEW_SECURITY_RATING_KEY;
import static org.sonar.db.qualitygate.QualityGateConditionDto.OPERATOR_GREATER_THAN;
import static org.sonar.db.qualitygate.QualityGateConditionDto.OPERATOR_LESS_THAN;
@@ -62,7 +63,8 @@ public class RegisterQualityGates implements Startable {
new QualityGateCondition().setMetricKey(NEW_RELIABILITY_RATING_KEY).setOperator(OPERATOR_GREATER_THAN).setErrorThreshold(A_RATING),
new QualityGateCondition().setMetricKey(NEW_MAINTAINABILITY_RATING_KEY).setOperator(OPERATOR_GREATER_THAN).setErrorThreshold(A_RATING),
new QualityGateCondition().setMetricKey(NEW_COVERAGE_KEY).setOperator(OPERATOR_LESS_THAN).setErrorThreshold("80"),
- new QualityGateCondition().setMetricKey(NEW_DUPLICATED_LINES_DENSITY_KEY).setOperator(OPERATOR_GREATER_THAN).setErrorThreshold("3"));
+ new QualityGateCondition().setMetricKey(NEW_DUPLICATED_LINES_DENSITY_KEY).setOperator(OPERATOR_GREATER_THAN).setErrorThreshold("3"),
+ new QualityGateCondition().setMetricKey(NEW_SECURITY_HOTSPOTS_REVIEWED_KEY).setOperator(OPERATOR_LESS_THAN).setErrorThreshold("100"));
private final DbClient dbClient;
private final QualityGateConditionsUpdater qualityGateConditionsUpdater;
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/RegisterQualityGatesTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/RegisterQualityGatesTest.java
index 4c0e1896372..98b37354d97 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/RegisterQualityGatesTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/RegisterQualityGatesTest.java
@@ -46,6 +46,7 @@ import static org.sonar.api.measures.CoreMetrics.NEW_COVERAGE_KEY;
import static org.sonar.api.measures.CoreMetrics.NEW_DUPLICATED_LINES_DENSITY_KEY;
import static org.sonar.api.measures.CoreMetrics.NEW_MAINTAINABILITY_RATING_KEY;
import static org.sonar.api.measures.CoreMetrics.NEW_RELIABILITY_RATING_KEY;
+import static org.sonar.api.measures.CoreMetrics.NEW_SECURITY_HOTSPOTS_REVIEWED_KEY;
import static org.sonar.api.measures.CoreMetrics.NEW_SECURITY_RATING_KEY;
import static org.sonar.api.measures.CoreMetrics.NEW_SECURITY_REMEDIATION_EFFORT_KEY;
import static org.sonar.api.measures.Metric.ValueType.INT;
@@ -234,6 +235,7 @@ public class RegisterQualityGatesTest {
dbClient.metricDao().insert(dbSession, newMetricDto().setKey(NEW_MAINTAINABILITY_RATING_KEY).setValueType(PERCENT.name()).setHidden(false).setDirection(0));
dbClient.metricDao().insert(dbSession, newMetricDto().setKey(NEW_COVERAGE_KEY).setValueType(PERCENT.name()).setHidden(false).setDirection(0));
dbClient.metricDao().insert(dbSession, newMetricDto().setKey(NEW_DUPLICATED_LINES_DENSITY_KEY).setValueType(PERCENT.name()).setHidden(false).setDirection(0));
+ dbClient.metricDao().insert(dbSession, newMetricDto().setKey(NEW_SECURITY_HOTSPOTS_REVIEWED_KEY).setValueType(PERCENT.name()).setHidden(false).setDirection(0));
dbSession.commit();
}
@@ -243,6 +245,8 @@ public class RegisterQualityGatesTest {
MetricDto newMaintainability = metricDao.selectByKey(dbSession, NEW_MAINTAINABILITY_RATING_KEY);
MetricDto newCoverage = metricDao.selectByKey(dbSession, NEW_COVERAGE_KEY);
MetricDto newDuplication = metricDao.selectByKey(dbSession, NEW_DUPLICATED_LINES_DENSITY_KEY);
+ MetricDto newSecurityHotspots = metricDao.selectByKey(dbSession, NEW_SECURITY_HOTSPOTS_REVIEWED_KEY);
+
QualityGateDto qualityGateDto = qualityGateDao.selectByName(dbSession, BUILT_IN_NAME);
assertThat(qualityGateDto).isNotNull();
@@ -251,12 +255,13 @@ public class RegisterQualityGatesTest {
assertThat(gateConditionDao.selectForQualityGate(dbSession, qualityGateDto.getId()))
.extracting(QualityGateConditionDto::getMetricId, QualityGateConditionDto::getOperator,
QualityGateConditionDto::getErrorThreshold)
- .containsOnly(
+ .containsExactlyInAnyOrder(
tuple(newReliability.getId().longValue(), OPERATOR_GREATER_THAN, "1"),
tuple(newSecurity.getId().longValue(), OPERATOR_GREATER_THAN, "1"),
tuple(newMaintainability.getId().longValue(), OPERATOR_GREATER_THAN, "1"),
tuple(newCoverage.getId().longValue(), OPERATOR_LESS_THAN, "80"),
- tuple(newDuplication.getId().longValue(), OPERATOR_GREATER_THAN, "3"));
+ tuple(newDuplication.getId().longValue(), OPERATOR_GREATER_THAN, "3"),
+ tuple(newSecurityHotspots.getId().longValue(), OPERATOR_LESS_THAN, "100"));
}
private List<QualityGateConditionDto> createBuiltInConditions(QualityGateDto qg) {
@@ -272,6 +277,8 @@ public class RegisterQualityGatesTest {
NEW_COVERAGE_KEY, OPERATOR_LESS_THAN, "80"));
conditions.add(qualityGateConditionsUpdater.createCondition(dbSession, qg,
NEW_DUPLICATED_LINES_DENSITY_KEY, OPERATOR_GREATER_THAN, "3"));
+ conditions.add(qualityGateConditionsUpdater.createCondition(dbSession, qg,
+ NEW_SECURITY_HOTSPOTS_REVIEWED_KEY, OPERATOR_LESS_THAN, "100"));
return conditions;
}