]> source.dussan.org Git - sonarqube.git/commitdiff
NO-JIRA Fix the Quality Gate
authorMatteo Mara <matteo.mara@sonarsource.com>
Mon, 14 Oct 2024 14:21:50 +0000 (16:21 +0200)
committersonartech <sonartech@sonarsource.com>
Tue, 15 Oct 2024 20:03:06 +0000 (20:03 +0000)
server/sonar-alm-client/src/test/java/org/sonar/alm/client/github/security/GithubAppSecurityImplTest.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/metric/Metric.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/SendAnalysisTelemetryStep.java
server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectDao.java
server/sonar-server-common/src/test/java/org/sonar/server/notification/email/EmailNotificationChannelTest.java
server/sonar-telemetry/src/main/java/org/sonar/telemetry/legacy/TelemetryDataLoaderImpl.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/SafeModeHealthActionTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/PluginFilesTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectReactorValidatorTest.java
sonar-scanner-engine/src/test/java/org/sonar/scm/git/ChangedFileTest.java

index 08ad4f1a87d0634586451a853c44ade1bba3a097..872dc19513d84f9be7e3a3c96c85afb36c4ca42e 100644 (file)
@@ -25,7 +25,6 @@ import java.security.spec.InvalidKeySpecException;
 import java.time.Clock;
 import java.time.Instant;
 import java.time.ZoneId;
-import java.util.Random;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.sonar.auth.github.GithubAppConfiguration;
@@ -144,7 +143,7 @@ public class GithubAppSecurityImplTest {
   }
 
   private GithubAppConfiguration createAppConfigurationForPrivateKey(String privateKey) {
-    long applicationId = new Random().nextInt(654);
+    long applicationId = 1L;
     return new GithubAppConfiguration(applicationId, privateKey, secure().nextAlphabetic(8));
   }
 
index 65910eb79f0674509a3940a8bc1c6f33dedb21ca..0a3397eb1552780428e02800a900e90e71ecffc7 100644 (file)
@@ -20,7 +20,7 @@
 package org.sonar.ce.task.projectanalysis.metric;
 
 import javax.annotation.CheckForNull;
-import org.sonar.ce.task.projectanalysis.measure.Measure;
+import org.sonar.ce.task.projectanalysis.measure.Measure.ValueType;
 
 public interface Metric {
   /**
@@ -51,32 +51,32 @@ public interface Metric {
 
   /**
    * The decimal scale of float measures. Returned value is greater than or equal zero.
-   * @throws IllegalStateException if the value type is not decimal (see {@link org.sonar.ce.task.projectanalysis.measure.Measure.ValueType}
+   * @throws IllegalStateException if the value type is not decimal (see {@link ValueType}
    */
   int getDecimalScale();
 
   boolean isDeleteHistoricalData();
 
   enum MetricType {
-    INT(Measure.ValueType.INT),
-    MILLISEC(Measure.ValueType.LONG),
-    RATING(Measure.ValueType.INT),
-    WORK_DUR(Measure.ValueType.LONG),
-    FLOAT(Measure.ValueType.DOUBLE),
-    PERCENT(Measure.ValueType.DOUBLE),
-    BOOL(Measure.ValueType.BOOLEAN),
-    STRING(Measure.ValueType.STRING),
-    DISTRIB(Measure.ValueType.STRING),
-    DATA(Measure.ValueType.STRING),
-    LEVEL(Measure.ValueType.LEVEL);
+    INT(ValueType.INT),
+    MILLISEC(ValueType.LONG),
+    RATING(ValueType.INT),
+    WORK_DUR(ValueType.LONG),
+    FLOAT(ValueType.DOUBLE),
+    PERCENT(ValueType.DOUBLE),
+    BOOL(ValueType.BOOLEAN),
+    STRING(ValueType.STRING),
+    DISTRIB(ValueType.STRING),
+    DATA(ValueType.STRING),
+    LEVEL(ValueType.LEVEL);
 
-    private final Measure.ValueType valueType;
+    private final ValueType valueType;
 
-    MetricType(Measure.ValueType valueType) {
+    MetricType(ValueType valueType) {
       this.valueType = valueType;
     }
 
-    public Measure.ValueType getValueType() {
+    public ValueType getValueType() {
       return valueType;
     }
   }
index 62700fad8005f1fc3662e5f9abbd97c19de871d9..112c846da43922cf10d53fe0fa9f2e5752bf860f 100644 (file)
@@ -89,4 +89,4 @@ public class SendAnalysisTelemetryStep implements ComputationStep {
   public String getDescription() {
     return "This step pushes telemetry data from the Sonar analyzers to Telemetry V2 server in case telemetry is enabled.";
   }
-}
\ No newline at end of file
+}
index 49f305100e71a2e564a6bf2f894ba9b524766530..74849bf4f0476b6417893011fd4742248eadf796 100644 (file)
@@ -23,7 +23,6 @@ import java.util.Collection;
 import java.util.List;
 import java.util.Optional;
 import java.util.Set;
-import java.util.function.Function;
 import javax.annotation.Nullable;
 import org.sonar.api.utils.System2;
 import org.sonar.db.Dao;
@@ -39,8 +38,6 @@ public class ProjectDao implements Dao {
   private final System2 system2;
   private final AuditPersister auditPersister;
 
-  private final Function<String, Set<String>> languageFilters = language -> Set.of(language + "=%", "%;" + language + "=%");
-
   public ProjectDao(System2 system2, AuditPersister auditPersister) {
     this.system2 = system2;
     this.auditPersister = auditPersister;
index efff8f1b796b93c00e13ed96f3043b1b029d806f..750fdff9f10c2b4801a2f064d29f820d7afa5801 100644 (file)
@@ -53,7 +53,7 @@ import org.subethamail.wiser.WiserMessage;
 import static java.util.stream.Collectors.toMap;
 import static java.util.stream.Collectors.toSet;
 import static junit.framework.Assert.fail;
-import static org.apache.commons.lang3.RandomStringUtils.random;
+import static org.apache.commons.lang3.RandomStringUtils.secure;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
@@ -93,7 +93,7 @@ public class EmailNotificationChannelTest {
 
   @Test
   public void isActivated_returns_true_if_smpt_host_is_not_empty() {
-    when(configuration.getSmtpHost()).thenReturn(random(5));
+    when(configuration.getSmtpHost()).thenReturn(secure().next(5));
 
     assertThat(underTest.isActivated()).isTrue();
   }
index 9bfffe45fc09db38f9d9c81ef7b7d5e445e9e232..c133c57afb095fe4b622dfdf54b70f5d0173644e 100644 (file)
@@ -76,8 +76,6 @@ import static java.util.stream.Collectors.toMap;
 import static org.apache.commons.lang3.StringUtils.startsWithIgnoreCase;
 import static org.sonar.api.measures.CoreMetrics.BUGS_KEY;
 import static org.sonar.api.measures.CoreMetrics.DEVELOPMENT_COST_KEY;
-import static org.sonar.api.measures.CoreMetrics.NCLOC_KEY;
-import static org.sonar.api.measures.CoreMetrics.NCLOC_LANGUAGE_DISTRIBUTION_KEY;
 import static org.sonar.api.measures.CoreMetrics.SECURITY_HOTSPOTS_KEY;
 import static org.sonar.api.measures.CoreMetrics.TECHNICAL_DEBT_KEY;
 import static org.sonar.api.measures.CoreMetrics.VULNERABILITIES_KEY;
@@ -394,12 +392,6 @@ public class TelemetryDataLoaderImpl implements TelemetryDataLoader {
     return this.defaultQualityProfileByLanguage.get(language);
   }
 
-  private Map<String, String> getNclocMetricUuidMap(DbSession dbSession) {
-    return dbClient.metricDao().selectByKeys(dbSession, asList(NCLOC_KEY, NCLOC_LANGUAGE_DISTRIBUTION_KEY))
-      .stream()
-      .collect(toMap(MetricDto::getKey, MetricDto::getUuid));
-  }
-
   private void resolveQualityGates(TelemetryData.Builder data, DbSession dbSession) {
     List<TelemetryData.QualityGate> qualityGates = new ArrayList<>();
     Collection<QualityGateDto> qualityGateDtos = dbClient.qualityGateDao().selectAll(dbSession);
index 283dd04fb5c62647adfd69485a373743ea943b15..e750f8ea2d7e3cd9b460251e395bf85cdb8a1823 100644 (file)
@@ -45,7 +45,7 @@ import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 import static org.sonar.test.JsonAssert.assertJson;
 
-public class SafeModeHealthActionTest {
+class SafeModeHealthActionTest {
 
   private final HealthChecker healthChecker = mock(HealthChecker.class);
   private final SystemPasscode systemPasscode = mock(SystemPasscode.class);
index 97d33f200fa93b07d0f87e1105a6e34d3cd6845e..30472694f711f4400e60bc7f903068dad3a74149 100644 (file)
@@ -276,7 +276,7 @@ class PluginFilesTest {
 
     FileAndMd5() throws IOException {
       this.file = Files.createTempFile(tempDir, "jar", null);
-      Files.write(this.file, RandomStringUtils.random(3).getBytes());
+      Files.write(this.file, RandomStringUtils.secure().next(3).getBytes());
       try (InputStream fis = Files.newInputStream(this.file)) {
         this.md5 = DigestUtils.md5Hex(fis);
       } catch (IOException e) {
index 3be0fda2132cc2773d539507ffc1a751970d27c4..40d785b4c51f8b8031222f3d9dba6efc4c592ef8 100644 (file)
@@ -38,7 +38,7 @@ import org.sonar.scanner.ProjectInfo;
 import org.sonar.scanner.bootstrap.GlobalConfiguration;
 
 import static java.lang.String.format;
-import static org.apache.commons.lang3.RandomStringUtils.randomAscii;
+import static org.apache.commons.lang3.RandomStringUtils.secure;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.mockito.ArgumentMatchers.anyString;
 import static org.mockito.Mockito.mock;
@@ -181,7 +181,7 @@ class ProjectReactorValidatorTest {
       null,
       "1.0",
       "2017-10-16",
-      randomAscii(100)
+      secure().nextAscii(100)
     );
   }
 
@@ -199,7 +199,7 @@ class ProjectReactorValidatorTest {
       null,
       "1.0",
       "2017-10-16",
-      randomAscii(100)
+      secure().nextAscii(100)
     );
   }
 
index 20ee5a69035e0703a718f6037953fc248fab7707..d6e7fef0d5e7d8eea77531cf5ab0d09919e74245 100644 (file)
@@ -26,7 +26,6 @@ import org.sonar.api.batch.fs.internal.DefaultIndexedFile;
 import org.sonar.api.batch.fs.internal.DefaultInputFile;
 import org.sonar.api.batch.fs.internal.SensorStrategy;
 
-import static org.apache.commons.lang3.RandomStringUtils.random;
 import static org.apache.commons.lang3.RandomStringUtils.secure;
 import static org.assertj.core.api.Assertions.assertThat;
 
@@ -82,11 +81,11 @@ public class ChangedFileTest {
   private DefaultIndexedFile composeDefaultIndexFile(Path path, String oldRelativePath) {
     return new DefaultIndexedFile(
       path,
-      random(5),
-      random(5),
-      random(5),
+      secure().next(5),
+      secure().next(5),
+      secure().next(5),
       InputFile.Type.MAIN,
-      random(5),
+      secure().next(5),
       Integer.parseInt(secure().nextNumeric(5)),
       new SensorStrategy(),
       oldRelativePath);