]> source.dussan.org Git - sonarqube.git/commitdiff
NO-JIRA Remove new code issues resulting from the update of the deprecated methods.
authorMatteo Mara <matteo.mara@sonarsource.com>
Tue, 8 Oct 2024 08:31:31 +0000 (10:31 +0200)
committersonartech <sonartech@sonarsource.com>
Mon, 14 Oct 2024 20:03:04 +0000 (20:03 +0000)
18 files changed:
server/sonar-alm-client/src/test/java/org/sonar/alm/client/github/security/GithubAppSecurityImplTest.java
server/sonar-db-dao/src/it/java/org/sonar/db/component/ComponentDaoIT.java
server/sonar-db-dao/src/test/java/org/sonar/db/ce/CeActivityDtoTest.java
server/sonar-db-dao/src/test/java/org/sonar/db/ce/UpdateIfTest.java
server/sonar-process/src/test/java/org/sonar/process/logging/LogLevelConfigTest.java
server/sonar-server-common/src/test/java/org/sonar/server/es/newindex/FieldAwareTest.java
server/sonar-server-common/src/test/java/org/sonar/server/es/newindex/NewIndexTest.java
server/sonar-server-common/src/test/java/org/sonar/server/es/searchrequest/AllFiltersTest.java
server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/ChangesOnMyIssuesNotificationTest.java
server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/FpPrAcceptedEmailTemplateTest.java
server/sonar-server-common/src/test/java/org/sonar/server/permission/index/AuthorizationDocTest.java
server/sonar-webserver-api/src/test/java/org/sonar/server/util/GlobalLockManagerImplTest.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/hotspot/ws/SearchActionIT.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/HealthActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/SafeModeHealthActionTest.java
sonar-plugin-api-impl/src/test/java/org/sonar/api/config/internal/MultivaluePropertyTest.java
sonar-ws/build.gradle
sonar-ws/src/test/java/org/sonarqube/ws/client/HttpConnectorTest.java

index 65224ce6adb0b798fb43ec5217b4fc2cd70f7847..08ad4f1a87d0634586451a853c44ade1bba3a097 100644 (file)
@@ -52,32 +52,33 @@ public class GithubAppSecurityImplTest {
 
   @Test
   public void createAppToken_fails_with_IAE_if_privateKey_PKCS8_content_is_missing_end_comment() {
-    String incompletePrivateKey = "-----BEGIN RSA PRIVATE KEY-----\n" +
-      "MIIEowIBAAKCAQEA6C29ZdvrwHOu7Eewv+xvUd4inCnACTzAHukHKTSY4R16+lRI\n" +
-      "YC5qZ8Xo304J7lLhN4/d4Xnof3lDXZOHthVbJKik4fOuEGbTXTIcuFs3hdJtrJsb\n" +
-      "antv8SOl5iR4fYRAf2AILMdtZI4iMSicBLIIttR+wVXo6NJYMjpj1OuAU3uN8eET\n" +
-      "Gge09oJT3QOUBem7N8uaYi/p5uAfsf2/SVNsoMPV624X4kgNcyj/TMa6BosFJ8Y3\n" +
-      "oeg0Aguk2yuHhAnixDVGoz6N7Go0QjEipVNix2JOOJwpFH4k2iZfM6n+8sJTLilq\n" +
-      "yzT53JW/XI+M5AXVj4OjBJ/2yMPi3RFMNTdgRwIDAQABAoIBACcYBIsRI7oNAIgi\n" +
-      "bh1y1y+mwpce5Inpo8PQovcKNy+4gguCg4lGZ34/sb1f64YoiGmNnOOpXj+QkIpC\n" +
-      "HBjJscYTa2fsWwPB/Jb1qCZWnZu32eW1XEFqtWeaBAYjX/JqgV2xMs8vaTkEQbeb\n" +
-      "SeH0hEkcsJcnOwdw247hjAu+96WWlyt10ZGgQaWPfXsdtelbaoaturNAVAJHdl9e\n" +
-      "TIknCIbtLlbz/FtzjtCtdeiWr8gbKdVkshGtA8SKVhXGQwDwENjUkAUtSJ0aXR1t\n" +
-      "+UjQcTISk7LiiYs0MrJ/CKoJ7mShwx7+YF3hgyqQ0qaqHwt9Yyd7wzWdCgdM5Eha\n" +
-      "ccioIskCgYEA+EDJmcM5NGu5AYpZ1ogmG6jzsefAlr2NG1PQ/U03twal/B+ygAQb\n" +
-      "5dholrq+aF+45Hrzfxije3Zrvpb08vxzKAs20lOlJsKftx2zkLR+mNvWTAORuO16\n" +
-      "lG0c0cgYAKA1ld4R8KB8NmbuNb1w4LYZuyuFIEVmm2B3ca141WNHBwMCgYEA72yK\n" +
-      "B4+xxomZn6dtbCGQZxziaI9WH/KEfDemKO5cfPlynQjmmMkiDpcyHa7mvdU+PGh3\n" +
-      "g+OmQxORXMmBkHEnYS1fl3ac3U5sLiHAQBmTKKcLuVQlIU4oDu/K6WEGL9DdPtaK\n" +
-      "gyOOWtSnfHTbT0bZ4IMm+gzdc4bCuEjvYyUhzG0CgYAEN011MAyTqFSvAwN9kjhb\n" +
-      "deYVmmL57GQuF6FP+/S7RgChpIQqimdS4vb7wFYlfaKtNq1V9jwoh51S0kt8qO7n\n" +
-      "ujEHJ2aBnwKJYJbBGV+hBvK/vbvG0TmotaWspmJJ+G6QigHx/Te+0Maw4PO+zTjo\n" +
-      "pdeP8b3JW70LkC+iKBp3swKBgFL/nm32m1tHEjFtehpVHFkSg05Z+jJDATiKlhh0\n" +
-      "YS2Vz+yuTDpE54CFW4M8wZKnXNbWJDBdd6KjIu42kKrA/zTJ5Ox92u1BJXFsk9fk\n" +
-      "xcX++qp5iBGepXZgHEiBMQLcdgY1m3jQl6XXOGSFog0+c4NIE/f1A8PrwI7gAdSt\n" +
-      "56SVAoGBAJp214Fo0oheMTTYKVtXuGiH/v3JNG1jKFgsmHqndf4wy7U6bbNctEzc\n" +
-      "ZXNIacuhWmko6YejMrWNhE57sX812MhXGZq6y0sYZGKtp7oDv8G3rWD6bpZywpcV\n" +
-      "kTtMJxm8J64u6bAkpWG3BocJP9qbXeAbILo1wuXgYqABBrpA9nnc";
+    String incompletePrivateKey = """
+      -----BEGIN RSA PRIVATE KEY-----
+      MIIEowIBAAKCAQEA6C29ZdvrwHOu7Eewv+xvUd4inCnACTzAHukHKTSY4R16+lRI
+      YC5qZ8Xo304J7lLhN4/d4Xnof3lDXZOHthVbJKik4fOuEGbTXTIcuFs3hdJtrJsb
+      antv8SOl5iR4fYRAf2AILMdtZI4iMSicBLIIttR+wVXo6NJYMjpj1OuAU3uN8eET
+      Gge09oJT3QOUBem7N8uaYi/p5uAfsf2/SVNsoMPV624X4kgNcyj/TMa6BosFJ8Y3
+      oeg0Aguk2yuHhAnixDVGoz6N7Go0QjEipVNix2JOOJwpFH4k2iZfM6n+8sJTLilq
+      yzT53JW/XI+M5AXVj4OjBJ/2yMPi3RFMNTdgRwIDAQABAoIBACcYBIsRI7oNAIgi
+      bh1y1y+mwpce5Inpo8PQovcKNy+4gguCg4lGZ34/sb1f64YoiGmNnOOpXj+QkIpC
+      HBjJscYTa2fsWwPB/Jb1qCZWnZu32eW1XEFqtWeaBAYjX/JqgV2xMs8vaTkEQbeb
+      SeH0hEkcsJcnOwdw247hjAu+96WWlyt10ZGgQaWPfXsdtelbaoaturNAVAJHdl9e
+      TIknCIbtLlbz/FtzjtCtdeiWr8gbKdVkshGtA8SKVhXGQwDwENjUkAUtSJ0aXR1t
+      +UjQcTISk7LiiYs0MrJ/CKoJ7mShwx7+YF3hgyqQ0qaqHwt9Yyd7wzWdCgdM5Eha
+      ccioIskCgYEA+EDJmcM5NGu5AYpZ1ogmG6jzsefAlr2NG1PQ/U03twal/B+ygAQb
+      5dholrq+aF+45Hrzfxije3Zrvpb08vxzKAs20lOlJsKftx2zkLR+mNvWTAORuO16
+      lG0c0cgYAKA1ld4R8KB8NmbuNb1w4LYZuyuFIEVmm2B3ca141WNHBwMCgYEA72yK
+      B4+xxomZn6dtbCGQZxziaI9WH/KEfDemKO5cfPlynQjmmMkiDpcyHa7mvdU+PGh3
+      g+OmQxORXMmBkHEnYS1fl3ac3U5sLiHAQBmTKKcLuVQlIU4oDu/K6WEGL9DdPtaK
+      gyOOWtSnfHTbT0bZ4IMm+gzdc4bCuEjvYyUhzG0CgYAEN011MAyTqFSvAwN9kjhb
+      deYVmmL57GQuF6FP+/S7RgChpIQqimdS4vb7wFYlfaKtNq1V9jwoh51S0kt8qO7n
+      ujEHJ2aBnwKJYJbBGV+hBvK/vbvG0TmotaWspmJJ+G6QigHx/Te+0Maw4PO+zTjo
+      pdeP8b3JW70LkC+iKBp3swKBgFL/nm32m1tHEjFtehpVHFkSg05Z+jJDATiKlhh0
+      YS2Vz+yuTDpE54CFW4M8wZKnXNbWJDBdd6KjIu42kKrA/zTJ5Ox92u1BJXFsk9fk
+      xcX++qp5iBGepXZgHEiBMQLcdgY1m3jQl6XXOGSFog0+c4NIE/f1A8PrwI7gAdSt
+      56SVAoGBAJp214Fo0oheMTTYKVtXuGiH/v3JNG1jKFgsmHqndf4wy7U6bbNctEzc
+      ZXNIacuhWmko6YejMrWNhE57sX812MhXGZq6y0sYZGKtp7oDv8G3rWD6bpZywpcV
+      kTtMJxm8J64u6bAkpWG3BocJP9qbXeAbILo1wuXgYqABBrpA9nnc""";
     GithubAppConfiguration githubAppConfiguration = createAppConfigurationForPrivateKey(incompletePrivateKey);
 
     assertThatThrownBy(() -> underTest.createAppToken(githubAppConfiguration.getId(), githubAppConfiguration.getPrivateKey()))
@@ -88,33 +89,27 @@ public class GithubAppSecurityImplTest {
 
   @Test
   public void createAppToken_fails_with_IAE_if_privateKey_PKCS8_content_is_corrupted() {
-    String corruptedPrivateKey = "-----BEGIN RSA PRIVATE KEY-----\n" +
-      "MIIEowIBAAKCAQEA6C29ZdvrwHOu7Eewv+xvUd4inCnACTzAHukHKTSY4R16+lRI\n" +
-      "YC5qZ8Xo304J7lLhN4/d4Xnof3lDXZOHthVbJKik4fOuEGbTXTIcuFs3hdJtrJsb\n" +
-      "antv8SOl5iR4fYRAf2AILMdtZI4iMSicBLIIttR+wVXo6NJYMjpj1OuAU3uN8eET\n" +
-      "Gge09oJT3QOUBem7N8uaYi/p5uAfsf2/SVNsoMPV624X4kgNcyj/TMa6BosFJ8Y3\n" +
-      "oeg0Aguk2yuHhAnixDVGoz6N7Go0QjEipVNix2JOOJwpFH4k2iZfM6n+8sJTLilq\n" +
-      "yzT53JW/XI+M5AXVj4OjBJ/2yMPi3RFMNTdgRwIDAQABAoIBACcYBIsRI7oNAIgi\n" +
-      "bh1y1y+mwpce5Inpo8PQovcKNy+4gguCg4lGZ34/sb1f64YoiGmNnOOpXj+QkIpC\n" +
-      "HBjJscYTa2fsWwPB/Jb1qCZWnZu32eW1XEFqtWeaBAYjX/JqgV2xMs8vaTkEQbeb\n" +
-      // "SeH0hEkcsJcnOwdw247hjAu+96WWlyt10ZGgQaWPfXsdtelbaoaturNAVAJHdl9e\n" +
-      // "TIknCIbtLlbz/FtzjtCtdeiWr8gbKdVkshGtA8SKVhXGQwDwENjUkAUtSJ0aXR1t\n" +
-      // "+UjQcTISk7LiiYs0MrJ/CKoJ7mShwx7+YF3hgyqQ0qaqHwt9Yyd7wzWdCgdM5Eha\n" +
-      // "ccioIskCgYEA+EDJmcM5NGu5AYpZ1ogmG6jzsefAlr2NG1PQ/U03twal/B+ygAQb\n" +
-      // "5dholrq+aF+45Hrzfxije3Zrvpb08vxzKAs20lOlJsKftx2zkLR+mNvWTAORuO16\n" +
-      // "lG0c0cgYAKA1ld4R8KB8NmbuNb1w4LYZuyuFIEVmm2B3ca141WNHBwMCgYEA72yK\n" +
-      // "B4+xxomZn6dtbCGQZxziaI9WH/KEfDemKO5cfPlynQjmmMkiDpcyHa7mvdU+PGh3\n" +
-      "g+OmQxORXMmBkHEnYS1fl3ac3U5sLiHAQBmTKKcLuVQlIU4oDu/K6WEGL9DdPtaK\n" +
-      "gyOOWtSnfHTbT0bZ4IMm+gzdc4bCuEjvYyUhzG0CgYAEN011MAyTqFSvAwN9kjhb\n" +
-      "deYVmmL57GQuF6FP+/S7RgChpIQqimdS4vb7wFYlfaKtNq1V9jwoh51S0kt8qO7n\n" +
-      "ujEHJ2aBnwKJYJbBGV+hBvK/vbvG0TmotaWspmJJ+G6QigHx/Te+0Maw4PO+zTjo\n" +
-      "pdeP8b3JW70LkC+iKBp3swKBgFL/nm32m1tHEjFtehpVHFkSg05Z+jJDATiKlhh0\n" +
-      "YS2Vz+yuTDpE54CFW4M8wZKnXNbWJDBdd6KjIu42kKrA/zTJ5Ox92u1BJXFsk9fk\n" +
-      "xcX++qp5iBGepXZgHEiBMQLcdgY1m3jQl6XXOGSFog0+c4NIE/f1A8PrwI7gAdSt\n" +
-      "56SVAoGBAJp214Fo0oheMTTYKVtXuGiH/v3JNG1jKFgsmHqndf4wy7U6bbNctEzc\n" +
-      "ZXNIacuhWmko6YejMrWNhE57sX812MhXGZq6y0sYZGKtp7oDv8G3rWD6bpZywpcV\n" +
-      "kTtMJxm8J64u6bAkpWG3BocJP9qbXeAbILo1wuXgYqABBrpA9nnc\n" +
-      "-----END RSA PRIVATE KEY-----";
+    String corruptedPrivateKey = """
+      -----BEGIN RSA PRIVATE KEY-----
+      //This+Key+Is+Corrupted+Gets+Decoded+But+It+Is+Invalid+pXj+QkIpC
+      MIIEowIBAAKCAQEA6C29ZdvrwHOu7Eewv+xvUd4inCnACTzAHukHKTSY4R16+lRI
+      YC5qZ8Xo304J7lLhN4/d4Xnof3lDXZOHthVbJKik4fOuEGbTXTIcuFs3hdJtrJsb
+      antv8SOl5iR4fYRAf2AILMdtZI4iMSicBLIIttR+wVXo6NJYMjpj1OuAU3uN8eET
+      Gge09oJT3QOUBem7N8uaYi/p5uAfsf2/SVNsoMPV624X4kgNcyj/TMa6BosFJ8Y3
+      oeg0Aguk2yuHhAnixDVGoz6N7Go0QjEipVNix2JOOJwpFH4k2iZfM6n+8sJTLilq
+      yzT53JW/XI+M5AXVj4OjBJ/2yMPi3RFMNTdgRwIDAQABAoIBACcYBIsRI7oNAIgi
+      HBjJscYTa2fsWwPB/Jb1qCZWnZu32eW1XEFqtWeaBAYjX/JqgV2xMs8vaTkEQbeb
+      g+OmQxORXMmBkHEnYS1fl3ac3U5sLiHAQBmTKKcLuVQlIU4oDu/K6WEGL9DdPtaK
+      gyOOWtSnfHTbT0bZ4IMm+gzdc4bCuEjvYyUhzG0CgYAEN011MAyTqFSvAwN9kjhb
+      deYVmmL57GQuF6FP+/S7RgChpIQqimdS4vb7wFYlfaKtNq1V9jwoh51S0kt8qO7n
+      ujEHJ2aBnwKJYJbBGV+hBvK/vbvG0TmotaWspmJJ+G6QigHx/Te+0Maw4PO+zTjo
+      pdeP8b3JW70LkC+iKBp3swKBgFL/nm32m1tHEjFtehpVHFkSg05Z+jJDATiKlhh0
+      YS2Vz+yuTDpE54CFW4M8wZKnXNbWJDBdd6KjIu42kKrA/zTJ5Ox92u1BJXFsk9fk
+      xcX++qp5iBGepXZgHEiBMQLcdgY1m3jQl6XXOGSFog0+c4NIE/f1A8PrwI7gAdSt
+      56SVAoGBAJp214Fo0oheMTTYKVtXuGiH/v3JNG1jKFgsmHqndf4wy7U6bbNctEzc
+      ZXNIacuhWmko6YejMrWNhE57sX812MhXGZq6y0sYZGKtp7oDv8G3rWD6bpZywpcV
+      kTtMJxm8J64u6bAkpWG3BocJP9qbXeAbILo1wuXgYqABBrpA9nnc
+      -----END RSA PRIVATE KEY-----""";
     GithubAppConfiguration githubAppConfiguration = createAppConfigurationForPrivateKey(corruptedPrivateKey);
 
     assertThatThrownBy(() -> underTest.createAppToken(githubAppConfiguration.getId(), githubAppConfiguration.getPrivateKey()))
@@ -145,7 +140,7 @@ public class GithubAppSecurityImplTest {
   }
 
   private GithubAppConfiguration createAppConfiguration() {
-    return new GithubAppConfiguration(new Random().nextLong(), REAL_PRIVATE_KEY, secure().nextAlphanumeric(5));
+    return new GithubAppConfiguration(1L, REAL_PRIVATE_KEY, secure().nextAlphanumeric(5));
   }
 
   private GithubAppConfiguration createAppConfigurationForPrivateKey(String privateKey) {
@@ -153,31 +148,32 @@ public class GithubAppSecurityImplTest {
     return new GithubAppConfiguration(applicationId, privateKey, secure().nextAlphabetic(8));
   }
 
-  private static final String REAL_PRIVATE_KEY = "-----BEGIN RSA PRIVATE KEY-----\n" +
-    "MIIEowIBAAKCAQEA6C29ZdvrwHOu7Eewv+xvUd4inCnACTzAHukHKTSY4R16+lRI\n" +
-    "YC5qZ8Xo304J7lLhN4/d4Xnof3lDXZOHthVbJKik4fOuEGbTXTIcuFs3hdJtrJsb\n" +
-    "antv8SOl5iR4fYRAf2AILMdtZI4iMSicBLIIttR+wVXo6NJYMjpj1OuAU3uN8eET\n" +
-    "Gge09oJT3QOUBem7N8uaYi/p5uAfsf2/SVNsoMPV624X4kgNcyj/TMa6BosFJ8Y3\n" +
-    "oeg0Aguk2yuHhAnixDVGoz6N7Go0QjEipVNix2JOOJwpFH4k2iZfM6n+8sJTLilq\n" +
-    "yzT53JW/XI+M5AXVj4OjBJ/2yMPi3RFMNTdgRwIDAQABAoIBACcYBIsRI7oNAIgi\n" +
-    "bh1y1y+mwpce5Inpo8PQovcKNy+4gguCg4lGZ34/sb1f64YoiGmNnOOpXj+QkIpC\n" +
-    "HBjJscYTa2fsWwPB/Jb1qCZWnZu32eW1XEFqtWeaBAYjX/JqgV2xMs8vaTkEQbeb\n" +
-    "SeH0hEkcsJcnOwdw247hjAu+96WWlyt10ZGgQaWPfXsdtelbaoaturNAVAJHdl9e\n" +
-    "TIknCIbtLlbz/FtzjtCtdeiWr8gbKdVkshGtA8SKVhXGQwDwENjUkAUtSJ0aXR1t\n" +
-    "+UjQcTISk7LiiYs0MrJ/CKoJ7mShwx7+YF3hgyqQ0qaqHwt9Yyd7wzWdCgdM5Eha\n" +
-    "ccioIskCgYEA+EDJmcM5NGu5AYpZ1ogmG6jzsefAlr2NG1PQ/U03twal/B+ygAQb\n" +
-    "5dholrq+aF+45Hrzfxije3Zrvpb08vxzKAs20lOlJsKftx2zkLR+mNvWTAORuO16\n" +
-    "lG0c0cgYAKA1ld4R8KB8NmbuNb1w4LYZuyuFIEVmm2B3ca141WNHBwMCgYEA72yK\n" +
-    "B4+xxomZn6dtbCGQZxziaI9WH/KEfDemKO5cfPlynQjmmMkiDpcyHa7mvdU+PGh3\n" +
-    "g+OmQxORXMmBkHEnYS1fl3ac3U5sLiHAQBmTKKcLuVQlIU4oDu/K6WEGL9DdPtaK\n" +
-    "gyOOWtSnfHTbT0bZ4IMm+gzdc4bCuEjvYyUhzG0CgYAEN011MAyTqFSvAwN9kjhb\n" +
-    "deYVmmL57GQuF6FP+/S7RgChpIQqimdS4vb7wFYlfaKtNq1V9jwoh51S0kt8qO7n\n" +
-    "ujEHJ2aBnwKJYJbBGV+hBvK/vbvG0TmotaWspmJJ+G6QigHx/Te+0Maw4PO+zTjo\n" +
-    "pdeP8b3JW70LkC+iKBp3swKBgFL/nm32m1tHEjFtehpVHFkSg05Z+jJDATiKlhh0\n" +
-    "YS2Vz+yuTDpE54CFW4M8wZKnXNbWJDBdd6KjIu42kKrA/zTJ5Ox92u1BJXFsk9fk\n" +
-    "xcX++qp5iBGepXZgHEiBMQLcdgY1m3jQl6XXOGSFog0+c4NIE/f1A8PrwI7gAdSt\n" +
-    "56SVAoGBAJp214Fo0oheMTTYKVtXuGiH/v3JNG1jKFgsmHqndf4wy7U6bbNctEzc\n" +
-    "ZXNIacuhWmko6YejMrWNhE57sX812MhXGZq6y0sYZGKtp7oDv8G3rWD6bpZywpcV\n" +
-    "kTtMJxm8J64u6bAkpWG3BocJP9qbXeAbILo1wuXgYqABBrpA9nnc\n" +
-    "-----END RSA PRIVATE KEY-----";
+  private static final String REAL_PRIVATE_KEY = """
+    -----BEGIN RSA PRIVATE KEY-----
+    MIIEowIBAAKCAQEA6C29ZdvrwHOu7Eewv+xvUd4inCnACTzAHukHKTSY4R16+lRI
+    YC5qZ8Xo304J7lLhN4/d4Xnof3lDXZOHthVbJKik4fOuEGbTXTIcuFs3hdJtrJsb
+    antv8SOl5iR4fYRAf2AILMdtZI4iMSicBLIIttR+wVXo6NJYMjpj1OuAU3uN8eET
+    Gge09oJT3QOUBem7N8uaYi/p5uAfsf2/SVNsoMPV624X4kgNcyj/TMa6BosFJ8Y3
+    oeg0Aguk2yuHhAnixDVGoz6N7Go0QjEipVNix2JOOJwpFH4k2iZfM6n+8sJTLilq
+    yzT53JW/XI+M5AXVj4OjBJ/2yMPi3RFMNTdgRwIDAQABAoIBACcYBIsRI7oNAIgi
+    bh1y1y+mwpce5Inpo8PQovcKNy+4gguCg4lGZ34/sb1f64YoiGmNnOOpXj+QkIpC
+    HBjJscYTa2fsWwPB/Jb1qCZWnZu32eW1XEFqtWeaBAYjX/JqgV2xMs8vaTkEQbeb
+    SeH0hEkcsJcnOwdw247hjAu+96WWlyt10ZGgQaWPfXsdtelbaoaturNAVAJHdl9e
+    TIknCIbtLlbz/FtzjtCtdeiWr8gbKdVkshGtA8SKVhXGQwDwENjUkAUtSJ0aXR1t
+    +UjQcTISk7LiiYs0MrJ/CKoJ7mShwx7+YF3hgyqQ0qaqHwt9Yyd7wzWdCgdM5Eha
+    ccioIskCgYEA+EDJmcM5NGu5AYpZ1ogmG6jzsefAlr2NG1PQ/U03twal/B+ygAQb
+    5dholrq+aF+45Hrzfxije3Zrvpb08vxzKAs20lOlJsKftx2zkLR+mNvWTAORuO16
+    lG0c0cgYAKA1ld4R8KB8NmbuNb1w4LYZuyuFIEVmm2B3ca141WNHBwMCgYEA72yK
+    B4+xxomZn6dtbCGQZxziaI9WH/KEfDemKO5cfPlynQjmmMkiDpcyHa7mvdU+PGh3
+    g+OmQxORXMmBkHEnYS1fl3ac3U5sLiHAQBmTKKcLuVQlIU4oDu/K6WEGL9DdPtaK
+    gyOOWtSnfHTbT0bZ4IMm+gzdc4bCuEjvYyUhzG0CgYAEN011MAyTqFSvAwN9kjhb
+    deYVmmL57GQuF6FP+/S7RgChpIQqimdS4vb7wFYlfaKtNq1V9jwoh51S0kt8qO7n
+    ujEHJ2aBnwKJYJbBGV+hBvK/vbvG0TmotaWspmJJ+G6QigHx/Te+0Maw4PO+zTjo
+    pdeP8b3JW70LkC+iKBp3swKBgFL/nm32m1tHEjFtehpVHFkSg05Z+jJDATiKlhh0
+    YS2Vz+yuTDpE54CFW4M8wZKnXNbWJDBdd6KjIu42kKrA/zTJ5Ox92u1BJXFsk9fk
+    xcX++qp5iBGepXZgHEiBMQLcdgY1m3jQl6XXOGSFog0+c4NIE/f1A8PrwI7gAdSt
+    56SVAoGBAJp214Fo0oheMTTYKVtXuGiH/v3JNG1jKFgsmHqndf4wy7U6bbNctEzc
+    ZXNIacuhWmko6YejMrWNhE57sX812MhXGZq6y0sYZGKtp7oDv8G3rWD6bpZywpcV
+    kTtMJxm8J64u6bAkpWG3BocJP9qbXeAbILo1wuXgYqABBrpA9nnc
+    -----END RSA PRIVATE KEY-----""";
 }
index a5288b236bfb130b9a5eb20d152bc7a4ba2f27e4..3d43a6e681069c6f039f338760a6025612b1f712 100644 (file)
@@ -127,7 +127,7 @@ class ComponentDaoIT {
       .setKey("org.struts:struts")
       .setName("Struts")
       .setLongName("Apache Struts")).getMainBranchComponent();
-    ComponentDto anotherProject = db.components().insertPrivateProject().getMainBranchComponent();
+    db.components().insertPrivateProject().getMainBranchComponent();
 
     ComponentDto result = underTest.selectByUuid(dbSession, project.uuid()).get();
     assertThat(result).isNotNull();
@@ -174,7 +174,6 @@ class ComponentDaoIT {
 
   @Test
   void selectByUuid_on_disabled_component() {
-    ComponentDto enabledProject = db.components().insertPublicProject(p -> p.setEnabled(true)).getMainBranchComponent();
     ComponentDto disabledProject = db.components().insertPublicProject(p -> p.setEnabled(false)).getMainBranchComponent();
 
     ComponentDto result = underTest.selectByUuid(dbSession, disabledProject.uuid()).get();
@@ -1402,11 +1401,11 @@ class ComponentDaoIT {
     db.components().insertPublicProject(p -> p.setKey("-key")).getMainBranchComponent();
 
     ComponentQuery privateProjectsQuery = ComponentQuery.builder().setPrivate(true).setQualifiers(PROJECT).build();
-    ComponentQuery ProjectsQuery = ComponentQuery.builder().setPrivate(false).setQualifiers(PROJECT).build();
+    ComponentQuery projectsQuery = ComponentQuery.builder().setPrivate(false).setQualifiers(PROJECT).build();
     ComponentQuery allProjectsQuery = ComponentQuery.builder().setPrivate(null).setQualifiers(PROJECT).build();
 
     assertThat(underTest.selectByQuery(dbSession, privateProjectsQuery, forPage(1).andSize(10))).extracting(ComponentDto::getKey).containsExactly("private-key");
-    assertThat(underTest.selectByQuery(dbSession, ProjectsQuery, forPage(1).andSize(10))).extracting(ComponentDto::getKey).containsExactly("-key");
+    assertThat(underTest.selectByQuery(dbSession, projectsQuery, forPage(1).andSize(10))).extracting(ComponentDto::getKey).containsExactly("-key");
     assertThat(underTest.selectByQuery(dbSession, allProjectsQuery, forPage(1).andSize(10))).extracting(ComponentDto::getKey).containsOnly("-key", "private-key");
   }
 
index 6724092155d3de371a10d131beb2c0971b7af9ec..94ad2337c072fa273f6e1757fb1f315f393c2de6 100644 (file)
@@ -19,6 +19,7 @@
  */
 package org.sonar.db.ce;
 
+import java.time.Instant;
 import java.util.Random;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.params.ParameterizedTest;
@@ -36,7 +37,7 @@ class CeActivityDtoTest {
 
   @Test
   void constructor_from_CeQueueDto_populates_fields() {
-    long now = new Random().nextLong();
+    long now = Instant.now().toEpochMilli();
     CeQueueDto ceQueueDto = new CeQueueDto()
       .setUuid(secure().nextAlphanumeric(10))
       .setTaskType(secure().nextAlphanumeric(11))
index ce3ab1771086ac406c51a82fcbd15ee63af6aff6..928d7e73c08ebfc387d19e51c7dc6e90199e97ab 100644 (file)
@@ -19,7 +19,6 @@
  */
 package org.sonar.db.ce;
 
-import java.util.Random;
 import org.apache.commons.lang3.RandomStringUtils;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.params.ParameterizedTest;
@@ -48,7 +47,7 @@ class UpdateIfTest {
 
   @Test
   void newProperties_constructor_fails_with_IAE_if_workerUuid_is_41_or_more() {
-    String workerUuid = RandomStringUtils.secure().nextAlphanumeric(41 + new Random().nextInt(5));
+    String workerUuid = RandomStringUtils.secure().nextAlphanumeric(41);
 
     assertThatThrownBy(() -> new UpdateIf.NewProperties(CeQueueDto.Status.PENDING, workerUuid, 123, 456))
       .isInstanceOf(IllegalArgumentException.class)
index 4f1a23c04e7f26bcf50916fcb60c685705757986..9e72c2a53d0aa47e230642ad858514b9acdc3195 100644 (file)
@@ -44,11 +44,11 @@ public class LogLevelConfigTest {
 
   @Test
   public void getLoggerName_returns_name_passed_to_builder() {
-    String rootLoggerName = RandomStringUtils.secure().nextAlphabetic(32);
+    String loggerName = RandomStringUtils.secure().nextAlphabetic(32);
 
-    LogLevelConfig logLevelConfig = newBuilder(rootLoggerName).build();
+    LogLevelConfig logLevelConfig = newBuilder(loggerName).build();
 
-    assertThat(logLevelConfig.getRootLoggerName()).isEqualTo(rootLoggerName);
+    assertThat(logLevelConfig.getRootLoggerName()).isEqualTo(loggerName);
   }
 
   @Test
index 59eef06c822ed1a4a115af8d9ffb7c744299a3a3..d1bc06593c4c5d2535fe456fe6a9410e2880674b 100644 (file)
  */
 package org.sonar.server.es.newindex;
 
-import java.util.Random;
 import java.util.function.BiConsumer;
 import java.util.stream.Stream;
 import org.junit.Test;
 
-import static org.apache.commons.lang3.RandomStringUtils.secure;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Fail.fail;
 
@@ -47,7 +45,7 @@ public class FieldAwareTest {
     fieldSetters.forEach(c -> {
       TestFieldAware underTest = new TestFieldAware();
       // should not fail for other field name
-      c.accept(underTest, secure().nextAlphabetic(1 + new Random().nextInt(10)));
+      c.accept(underTest, "notIndexType");
       // fails whatever the case
       Stream.of("indexType", "indextype", "InDexType", "INDEXTYPE")
         .forEach(illegalFieldName -> {
index 8e33bbc620ecd5bf4e7b45225b50e2ace9991f48..e8a2ee572b06beea4db7410f0959171dfefd7f19 100644 (file)
@@ -45,9 +45,9 @@ import static org.sonar.server.es.newindex.SettingsConfiguration.newBuilder;
 public class NewIndexTest {
 
 
-  private static final String someIndexName = secure().nextAlphabetic(5).toLowerCase();
-  private MapSettings settings = new MapSettings();
-  private SettingsConfiguration defaultSettingsConfiguration = newBuilder(settings.asConfig()).build();
+  private static final String SOME_INDEX_NAME = secure().nextAlphabetic(5).toLowerCase();
+  private final MapSettings settings = new MapSettings();
+  private final SettingsConfiguration defaultSettingsConfiguration = newBuilder(settings.asConfig()).build();
 
   @Test
   @UseDataProvider("indexWithAndWithoutRelations")
@@ -353,9 +353,9 @@ public class NewIndexTest {
 
   @Test
   public void createTypeMapping_with_IndexRelationType_fails_with_ISE_if_index_does_not_allow_relations() {
-    IndexType.IndexRelationType indexRelationType = IndexType.relation(IndexType.main(Index.withRelations(someIndexName), "bar"), "bar");
+    IndexType.IndexRelationType indexRelationType = IndexType.relation(IndexType.main(Index.withRelations(SOME_INDEX_NAME), "bar"), "bar");
 
-    Index index = Index.simple(someIndexName);
+    Index index = Index.simple(SOME_INDEX_NAME);
     IndexMainType mainType = IndexType.main(index, "foo");
     NewIndex underTest = new NewIndex(index, defaultSettingsConfiguration) {
       @Override
@@ -377,8 +377,8 @@ public class NewIndexTest {
   @DataProvider
   public static Object[][] indexWithAndWithoutRelations() {
     return new Object[][] {
-      {Index.simple(someIndexName)},
-      {Index.withRelations(someIndexName)}
+      {Index.simple(SOME_INDEX_NAME)},
+      {Index.withRelations(SOME_INDEX_NAME)}
     };
   }
 
index b6ec64e6e4f6bf1b8a01330798a6b2dca159a67f..d3ea1974056c016b282d01d83dd0b23172d5e7a9 100644 (file)
@@ -70,21 +70,20 @@ public class AllFiltersTest {
 
   @Test
   public void addFilter_fails_if_field_with_name_already_exists() {
-    String name1 = secure().nextAlphabetic(12);
-    String name2 = secure().nextAlphabetic(15);
+    String name = secure().nextAlphabetic(15);
     FilterScope filterScope1 = mock(FilterScope.class);
     FilterScope filterScope2 = mock(FilterScope.class);
     RequestFiltersComputer.AllFilters allFilters = RequestFiltersComputer.newAllFilters();
-    allFilters.addFilter(name2, filterScope1, boolQuery());
+    allFilters.addFilter(name, filterScope1, boolQuery());
 
     Stream.<ThrowingCallable>of(
       // exact same call
-      () -> allFilters.addFilter(name2, filterScope1, boolQuery()),
+      () -> allFilters.addFilter(name, filterScope1, boolQuery()),
       // call with a different fieldName
-      () -> allFilters.addFilter(name2, filterScope2, boolQuery()))
+      () -> allFilters.addFilter(name, filterScope2, boolQuery()))
       .forEach(t -> assertThatThrownBy(t)
         .isInstanceOf(IllegalArgumentException.class)
-        .hasMessage("A filter with name " + name2 + " has already been added"));
+        .hasMessage("A filter with name " + name + " has already been added"));
   }
 
   @Test
index ff9847b368a7667f4b43db29096f052b678a4cd2..42c29365318f3a128b84b129c7bb243a9cf7a2a6 100644 (file)
@@ -20,7 +20,6 @@
 package org.sonar.server.issue.notification;
 
 import com.google.common.collect.ImmutableSet;
-import java.util.Random;
 import org.junit.Test;
 import org.sonar.api.notifications.Notification;
 import org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.AnalysisChange;
@@ -37,7 +36,7 @@ public class ChangesOnMyIssuesNotificationTest {
   @Test
   public void key_is_ChangesOnMyIssues() {
     ChangesOnMyIssuesNotification underTest = new ChangesOnMyIssuesNotification(
-      new UserChange(new Random().nextLong(), new User(secure().nextAlphabetic(2), secure().nextAlphabetic(3), secure().nextAlphabetic(4))),
+      new UserChange(1L, new User(secure().nextAlphabetic(2), secure().nextAlphabetic(3), secure().nextAlphabetic(4))),
       ImmutableSet.of());
 
     assertThat(underTest.getType()).isEqualTo("ChangesOnMyIssues");
@@ -45,7 +44,7 @@ public class ChangesOnMyIssuesNotificationTest {
 
   @Test
   public void equals_is_based_on_change_and_issues() {
-    AnalysisChange analysisChange = new AnalysisChange(new Random().nextLong());
+    AnalysisChange analysisChange = new AnalysisChange(1L);
     ChangedIssue changedIssue = IssuesChangesNotificationBuilderTesting.newChangedIssue("doo", IssuesChangesNotificationBuilderTesting.newProject("prj"),
       newRandomNotAHotspotRule("rul"));
     ChangesOnMyIssuesNotification underTest = new ChangesOnMyIssuesNotification(analysisChange, ImmutableSet.of(changedIssue));
@@ -60,7 +59,7 @@ public class ChangesOnMyIssuesNotificationTest {
 
   @Test
   public void hashcode_is_based_on_change_and_issues() {
-    AnalysisChange analysisChange = new AnalysisChange(new Random().nextLong());
+    AnalysisChange analysisChange = new AnalysisChange(1L);
     ChangedIssue changedIssue = IssuesChangesNotificationBuilderTesting.newChangedIssue("doo", IssuesChangesNotificationBuilderTesting.newProject("prj"),
       newRandomNotAHotspotRule("rul"));
     ChangesOnMyIssuesNotification underTest = new ChangesOnMyIssuesNotification(analysisChange, ImmutableSet.of(changedIssue));
index 7a0d96b10cad0dafa26e5b9359e9e86024b3258b..967e5955cd89c00d23c0f5b0be25147efb7337ad 100644 (file)
@@ -23,6 +23,7 @@ import com.google.common.collect.ImmutableSet;
 import com.tngtech.java.junit.dataprovider.DataProvider;
 import com.tngtech.java.junit.dataprovider.DataProviderRunner;
 import com.tngtech.java.junit.dataprovider.UseDataProvider;
+import java.time.Instant;
 import java.util.Collections;
 import java.util.List;
 import java.util.Locale;
@@ -61,10 +62,12 @@ import static org.sonar.server.issue.notification.IssuesChangesNotificationBuild
 
 @RunWith(DataProviderRunner.class)
 public class FpPrAcceptedEmailTemplateTest {
-  private I18n i18n = mock(I18n.class);
-  private EmailSettings emailSettings = mock(EmailSettings.class);
-  private FpOrAcceptedEmailTemplate underTest = new FpOrAcceptedEmailTemplate(i18n, emailSettings);
+  private final I18n i18n = mock(I18n.class);
+  private final EmailSettings emailSettings = mock(EmailSettings.class);
+  private final FpOrAcceptedEmailTemplate underTest = new FpOrAcceptedEmailTemplate(i18n, emailSettings);
 
+  private static final long DATE_LONG = Instant.now().toEpochMilli();
+  
   @Test
   public void format_returns_null_on_Notification() {
     EmailMessage emailMessage = underTest.format(mock(Notification.class));
@@ -102,7 +105,7 @@ public class FpPrAcceptedEmailTemplateTest {
 
   @Test
   public void format_sets_from_to_name_of_author_change_when_available() {
-    UserChange change = new UserChange(new Random().nextLong(), new User(secure().nextAlphabetic(5), secure().nextAlphabetic(6), secure().nextAlphabetic(7)));
+    UserChange change = new UserChange(DATE_LONG, new User(secure().nextAlphabetic(5), secure().nextAlphabetic(6), secure().nextAlphabetic(7)));
     EmailMessage emailMessage = underTest.format(new FPOrAcceptedNotification(change, Collections.emptySet(), ACCEPTED));
 
     assertThat(emailMessage.getFrom()).isEqualTo(change.getUser().getName().get());
@@ -110,7 +113,7 @@ public class FpPrAcceptedEmailTemplateTest {
 
   @Test
   public void format_sets_from_to_login_of_author_change_when_name_is_not_available() {
-    UserChange change = new UserChange(new Random().nextLong(), new User(secure().nextAlphabetic(5), secure().nextAlphabetic(6), null));
+    UserChange change = new UserChange(DATE_LONG, new User(secure().nextAlphabetic(5), secure().nextAlphabetic(6), null));
     EmailMessage emailMessage = underTest.format(new FPOrAcceptedNotification(change, Collections.emptySet(), ACCEPTED));
 
     assertThat(emailMessage.getFrom()).isEqualTo(change.getUser().getLogin());
@@ -118,7 +121,7 @@ public class FpPrAcceptedEmailTemplateTest {
 
   @Test
   public void format_sets_from_to_null_when_analysisChange() {
-    AnalysisChange change = new AnalysisChange(new Random().nextLong());
+    AnalysisChange change = new AnalysisChange(DATE_LONG);
     EmailMessage emailMessage = underTest.format(new FPOrAcceptedNotification(change, Collections.emptySet(), ACCEPTED));
 
     assertThat(emailMessage.getFrom()).isNull();
@@ -472,8 +475,8 @@ public class FpPrAcceptedEmailTemplateTest {
 
   @DataProvider
   public static Object[][] userOrAnalysisChange() {
-    AnalysisChange analysisChange = new AnalysisChange(new Random().nextLong());
-    UserChange userChange = new UserChange(new Random().nextLong(), new User(secure().nextAlphabetic(5), secure().nextAlphabetic(6),
+    AnalysisChange analysisChange = new AnalysisChange(DATE_LONG);
+    UserChange userChange = new UserChange(DATE_LONG, new User(secure().nextAlphabetic(5), secure().nextAlphabetic(6),
       new Random().nextBoolean() ? null : secure().nextAlphabetic(7)));
     return new Object[][] {
       {analysisChange},
@@ -483,8 +486,8 @@ public class FpPrAcceptedEmailTemplateTest {
 
   @DataProvider
   public static Object[][] fpOrWontFixValuesByUserOrAnalysisChange() {
-    AnalysisChange analysisChange = new AnalysisChange(new Random().nextLong());
-    UserChange userChange = new UserChange(new Random().nextLong(), new User(secure().nextAlphabetic(5), secure().nextAlphabetic(6),
+    AnalysisChange analysisChange = new AnalysisChange(DATE_LONG);
+    UserChange userChange = new UserChange(DATE_LONG, new User(secure().nextAlphabetic(5), secure().nextAlphabetic(6),
       new Random().nextBoolean() ? null : secure().nextAlphabetic(7)));
     return new Object[][] {
       {analysisChange, FP},
index 23e47a79507f485a634399b9b37eb442aad5ffd1..2614352fdd521c7428518dad3066ad404367d5f9 100644 (file)
@@ -62,13 +62,19 @@ public class AuthorizationDocTest {
   public void projectUuidOf_returns_substring_if_starts_with_id_prefix() {
     assertThat(AuthorizationDoc.entityUuidOf("auth_")).isEmpty();
 
-    String id = secure().nextAlphabetic(1 + new Random().nextInt(10));
+    String id = "u";
+    assertThat(AuthorizationDoc.entityUuidOf("auth_" + id)).isEqualTo(id);
+
+    id = "uuid";
+    assertThat(AuthorizationDoc.entityUuidOf("auth_" + id)).isEqualTo(id);
+
+    id = "aMuchLongerUuid";
     assertThat(AuthorizationDoc.entityUuidOf("auth_" + id)).isEqualTo(id);
   }
 
   @Test
   public void projectUuidOf_returns_argument_if_does_not_starts_with_id_prefix() {
-    String id = secure().nextAlphabetic(1 + new Random().nextInt(10));
+    String id = "uuid";
     assertThat(AuthorizationDoc.entityUuidOf(id)).isEqualTo(id);
     assertThat(AuthorizationDoc.entityUuidOf("")).isEmpty();
   }
index 92f556e19cf1e77d91473c2fa8797df20118a8ad..d1010b128d15528c8a8dd6c287147ea46800a663 100644 (file)
@@ -65,8 +65,8 @@ public class GlobalLockManagerImplTest {
   }
 
   @Test
-  public void tryLock_fails_with_IAE_if_name_length_is_more_than_max_or_more() {
-    String badLockName = RandomStringUtils.random(LOCK_NAME_MAX_LENGTH + 1 + new Random().nextInt(96));
+  public void tryLock_fails_with_IAE_if_name_length_is_more_than_max() {
+    String badLockName = RandomStringUtils.secure().next(LOCK_NAME_MAX_LENGTH + 1);
 
     expectBadLockNameIAE(() -> underTest.tryLock(badLockName), badLockName);
   }
@@ -74,7 +74,7 @@ public class GlobalLockManagerImplTest {
   @Test
   public void tryLock_accepts_name_with_allowed_length() {
     for (int i = 1; i <= LOCK_NAME_MAX_LENGTH; i++) {
-      String lockName = RandomStringUtils.random(i);
+      String lockName = RandomStringUtils.secure().next(i);
       assertThatNoException().isThrownBy(() -> underTest.tryLock(lockName));
     }
   }
@@ -106,14 +106,14 @@ public class GlobalLockManagerImplTest {
   @UseDataProvider("randomValidDuration")
   public void tryLock_with_duration_accepts_name_with_length_15_or_less(int randomValidDuration) {
     for (int i = 1; i <= 15; i++) {
-      underTest.tryLock(RandomStringUtils.random(i), randomValidDuration);
+      underTest.tryLock(RandomStringUtils.secure().next(i), randomValidDuration);
     }
   }
 
   @Test
   @UseDataProvider("randomValidDuration")
-  public void tryLock_with_duration_fails_with_IAE_if_name_length_is_36_or_more(int randomValidDuration) {
-    String badLockName = RandomStringUtils.random(LOCK_NAME_MAX_LENGTH + 1 + new Random().nextInt(65));
+  public void tryLock_with_duration_fails_with_IAE_if_name_length_is_more_than_36(int randomValidDuration) {
+    String badLockName = RandomStringUtils.secure().next(LOCK_NAME_MAX_LENGTH + 1);
 
     expectBadLockNameIAE(() -> underTest.tryLock(badLockName, randomValidDuration), badLockName);
   }
@@ -127,7 +127,7 @@ public class GlobalLockManagerImplTest {
   @Test
   @UseDataProvider("randomValidLockName")
   public void tryLock_with_duration_fails_with_IAE_if_duration_is_less_than_0(String randomValidLockName) {
-    int negativeDuration = -1 - new Random().nextInt(100);
+    int negativeDuration = -1;
 
     expectBadDuration(() -> underTest.tryLock(randomValidLockName, negativeDuration), negativeDuration);
   }
index 6c636202e6edf3f5aab0062bb6980253139bf37e..4a739cad2180d6670e81790d82ba38c702630ca3 100644 (file)
@@ -579,7 +579,7 @@ public class SearchActionIT {
 
     assertThat(responseProject1.getHotspotsList())
       .extracting(SearchWsResponse.Hotspot::getKey)
-      .doesNotContainAnyElementsOf(Arrays.stream(hotspots2).map(IssueDto::getKey).collect(toList()));
+      .doesNotContainAnyElementsOf(Arrays.stream(hotspots2).map(IssueDto::getKey).toList());
     assertThat(responseProject1.getComponentsList())
       .extracting(Component::getKey)
       .containsOnly(project1.getKey(), file1.getKey());
@@ -936,9 +936,12 @@ public class SearchActionIT {
     RuleDto rule = newRule(SECURITY_HOTSPOT);
     IssueDto unresolvedHotspot = insertHotspot(rule, project, file, t -> t.setResolution(null));
     // unrealistic case since a resolution must be set, but shows a limit of current implementation (resolution is enough)
-    IssueDto badlyResolved = insertHotspot(rule, project, file, t -> t.setStatus(STATUS_TO_REVIEW).setResolution(secure().nextAlphabetic(5)));
-    IssueDto badlyReviewed = insertHotspot(rule, project, file, t -> t.setStatus(STATUS_REVIEWED).setResolution(null));
-    IssueDto badlyClosedHotspot = insertHotspot(rule, project, file, t -> t.setStatus(STATUS_CLOSED).setResolution(null));
+    //Badly Resolved
+    insertHotspot(rule, project, file, t -> t.setStatus(STATUS_TO_REVIEW).setResolution("Resolution"));
+    //Badly Reviewed
+    insertHotspot(rule, project, file, t -> t.setStatus(STATUS_REVIEWED).setResolution(null));
+    //Badly Closed
+    insertHotspot(rule, project, file, t -> t.setStatus(STATUS_CLOSED).setResolution(null));
     indexIssues();
 
     SearchWsResponse response = newRequest(project, STATUS_TO_REVIEW, null, null, null)
index f085045ffd353dfe815b1a3279fe872b6ac36d0f..e9d4a57c786015e9513d53a961615b65f2ecd804 100644 (file)
@@ -67,10 +67,10 @@ public class HealthActionTest {
   public UserSessionRule userSessionRule = UserSessionRule.standalone();
 
   private final Random random = new Random();
-  private HealthChecker healthChecker = mock(HealthChecker.class);
-  private NodeInformation nodeInformation = mock(NodeInformation.class);
-  private SystemPasscode systemPasscode = mock(SystemPasscode.class);
-  private WsActionTester underTest = new WsActionTester(new HealthAction(nodeInformation, new HealthActionSupport(healthChecker), systemPasscode, userSessionRule));
+  private final HealthChecker healthChecker = mock(HealthChecker.class);
+  private final NodeInformation nodeInformation = mock(NodeInformation.class);
+  private final SystemPasscode systemPasscode = mock(SystemPasscode.class);
+  private final WsActionTester underTest = new WsActionTester(new HealthAction(nodeInformation, new HealthActionSupport(healthChecker), systemPasscode, userSessionRule));
 
   @Test
   public void verify_definition() {
index 63645093980bfdbc5abd1c23a0f55731e1e52f70..283dd04fb5c62647adfd69485a373743ea943b15 100644 (file)
@@ -24,7 +24,9 @@ import java.util.Random;
 import java.util.stream.IntStream;
 import org.apache.commons.lang3.RandomStringUtils;
 import org.assertj.core.api.ThrowableAssert.ThrowingCallable;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.EnumSource;
 import org.sonar.api.server.ws.WebService;
 import org.sonar.server.exceptions.ForbiddenException;
 import org.sonar.server.health.Health;
@@ -45,13 +47,12 @@ import static org.sonar.test.JsonAssert.assertJson;
 
 public class SafeModeHealthActionTest {
 
-  private final Random random = new Random();
-  private HealthChecker healthChecker = mock(HealthChecker.class);
-  private SystemPasscode systemPasscode = mock(SystemPasscode.class);
-  private WsActionTester underTest = new WsActionTester(new SafeModeHealthAction(new HealthActionSupport(healthChecker), systemPasscode));
+  private final HealthChecker healthChecker = mock(HealthChecker.class);
+  private final SystemPasscode systemPasscode = mock(SystemPasscode.class);
+  private final WsActionTester underTest = new WsActionTester(new SafeModeHealthAction(new HealthActionSupport(healthChecker), systemPasscode));
 
   @Test
-  public void verify_definition() {
+  void verify_definition() {
     WebService.Action definition = underTest.getDef();
 
     assertThat(definition.key()).isEqualTo("health");
@@ -64,19 +65,20 @@ public class SafeModeHealthActionTest {
   }
 
   @Test
-  public void request_fails_with_ForbiddenException_when_PassCode_disabled_or_incorrect() {
+  void request_fails_with_ForbiddenException_when_PassCode_disabled_or_incorrect() {
     when(systemPasscode.isValid(any())).thenReturn(false);
     TestRequest request = underTest.newRequest();
 
     expectForbiddenException(() -> request.execute());
   }
 
-  @Test
-  public void request_succeeds_when_valid_passcode() {
+  @ParameterizedTest
+  @EnumSource(Health.Status.class)
+  void request_succeeds_when_valid_passcode(Health.Status healthStatus) {
     authenticateWithPasscode();
     when(healthChecker.checkNode())
       .thenReturn(Health.builder()
-        .setStatus(Health.Status.values()[random.nextInt(Health.Status.values().length)])
+        .setStatus(healthStatus)
         .build());
     TestRequest request = underTest.newRequest();
 
@@ -84,7 +86,7 @@ public class SafeModeHealthActionTest {
   }
 
   @Test
-  public void verify_response_example() {
+  void verify_response_example() {
     authenticateWithPasscode();
     when(healthChecker.checkNode())
       .thenReturn(Health.builder()
@@ -99,34 +101,34 @@ public class SafeModeHealthActionTest {
       .isSimilarTo(underTest.getDef().responseExampleAsString());
   }
 
-  @Test
-  public void request_returns_status_and_causes_from_HealthChecker_checkNode_method() {
+  @ParameterizedTest
+  @EnumSource(Health.Status.class)
+  void request_returns_status_and_causes_from_HealthChecker_checkNode_method(Health.Status healthStatus) {
     authenticateWithPasscode();
-    Health.Status randomStatus = Health.Status.values()[new Random().nextInt(Health.Status.values().length)];
     Health.Builder builder = Health.builder()
-      .setStatus(randomStatus);
+      .setStatus(healthStatus);
     IntStream.range(0, new Random().nextInt(5)).mapToObj(i -> RandomStringUtils.secure().nextAlphanumeric(3)).forEach(builder::addCause);
     Health health = builder.build();
     when(healthChecker.checkNode()).thenReturn(health);
     TestRequest request = underTest.newRequest();
 
     System.HealthResponse healthResponse = request.executeProtobuf(System.HealthResponse.class);
-    assertThat(healthResponse.getHealth().name()).isEqualTo(randomStatus.name());
+    assertThat(healthResponse.getHealth().name()).isEqualTo(healthStatus.name());
     assertThat(health.getCauses()).isEqualTo(health.getCauses());
   }
 
-  @Test
-  public void response_contains_status_and_causes_from_HealthChecker_checkCluster() {
+  @ParameterizedTest
+  @EnumSource(Health.Status.class)
+  void response_contains_status_and_causes_from_HealthChecker_checkCluster(Health.Status healthStatus) {
     authenticateWithPasscode();
-    Health.Status randomStatus = Health.Status.values()[random.nextInt(Health.Status.values().length)];
-    String[] causes = IntStream.range(0, random.nextInt(33)).mapToObj(i -> secure().nextAlphanumeric(4)).toArray(String[]::new);
+    String[] causes = IntStream.range(0, new Random().nextInt(33)).mapToObj(i -> secure().nextAlphanumeric(4)).toArray(String[]::new);
     Health.Builder healthBuilder = Health.builder()
-      .setStatus(randomStatus);
+      .setStatus(healthStatus);
     Arrays.stream(causes).forEach(healthBuilder::addCause);
     when(healthChecker.checkNode()).thenReturn(healthBuilder.build());
 
     System.HealthResponse clusterHealthResponse = underTest.newRequest().executeProtobuf(System.HealthResponse.class);
-    assertThat(clusterHealthResponse.getHealth().name()).isEqualTo(randomStatus.name());
+    assertThat(clusterHealthResponse.getHealth().name()).isEqualTo(healthStatus.name());
     assertThat(clusterHealthResponse.getCausesList())
       .extracting(System.Cause::getMessage)
       .containsOnly(causes);
index 1452e78d6735cd0a22472afd207ec1fc74c6ddba..d28c74fd9469d6c5834f277b91050c1a2c2645d7 100644 (file)
@@ -116,7 +116,9 @@ public class MultivaluePropertyTest {
     return new Object[][] {
       {secure().nextAlphanumeric(1)},
       {secure().nextAlphanumeric(2)},
-      {secure().nextAlphanumeric(3 + new Random().nextInt(5))}
+      {secure().nextAlphanumeric(3)},
+      {secure().nextAlphanumeric(5)},
+      {secure().nextAlphanumeric(8)}
     };
   }
 
@@ -215,7 +217,9 @@ public class MultivaluePropertyTest {
     return new Object[][] {
       {randomTrimmedChars(1, random)},
       {randomTrimmedChars(2, random)},
-      {randomTrimmedChars(3 + random.nextInt(5), random)}
+      {randomTrimmedChars(3, random)},
+      {randomTrimmedChars(5, random)},
+      {randomTrimmedChars(8, random)}
     };
   }
 
index 4c8f23c9e5d1eee5062c33b75f60265972c466fb..e33277140ef89d7a0c1989803f50df86b764f42e 100644 (file)
@@ -21,21 +21,22 @@ dependencies {
   compileOnlyApi 'com.github.spotbugs:spotbugs-annotations'
   compileOnlyApi 'javax.annotation:javax.annotation-api'
 
-    testImplementation 'com.squareup.okhttp3:mockwebserver'
-    testImplementation 'commons-io:commons-io'
-    testImplementation 'org.apache.commons:commons-lang3'
-    testImplementation 'junit:junit'
-    testImplementation 'org.assertj:assertj-core'
-    testImplementation 'org.hamcrest:hamcrest'
-    testImplementation 'org.mockito:mockito-core'
-    testImplementation project(':sonar-testing-harness')
-
-    testFixturesApi 'junit:junit'
-    testFixturesApi 'com.google.guava:guava'
-    testFixturesApi 'org.assertj:assertj-core'
-    testFixturesApi 'org.junit.jupiter:junit-jupiter-api'
-    testFixturesApi 'org.sonarsource.orchestrator:sonar-orchestrator-junit4'
-    testFixturesApi 'commons-io:commons-io'
+  testImplementation 'com.squareup.okhttp3:mockwebserver'
+  testImplementation 'com.tngtech.java:junit-dataprovider'
+  testImplementation 'commons-io:commons-io'
+  testImplementation 'org.apache.commons:commons-lang3'
+  testImplementation 'junit:junit'
+  testImplementation 'org.assertj:assertj-core'
+  testImplementation 'org.hamcrest:hamcrest'
+  testImplementation 'org.mockito:mockito-core'
+  testImplementation project(':sonar-testing-harness')
+
+  testFixturesApi 'junit:junit'
+  testFixturesApi 'com.google.guava:guava'
+  testFixturesApi 'org.assertj:assertj-core'
+  testFixturesApi 'org.junit.jupiter:junit-jupiter-api'
+  testFixturesApi 'org.sonarsource.orchestrator:sonar-orchestrator-junit4'
+  testFixturesApi 'commons-io:commons-io'
 }
 
 artifactoryPublish.skip = false
index 411dd9b9bbca29934086de615ae57c65255f34e3..c0320cbde0259e475ff4291d08478f746e85f0c5 100644 (file)
@@ -19,6 +19,9 @@
  */
 package org.sonarqube.ws.client;
 
+import com.tngtech.java.junit.dataprovider.DataProvider;
+import com.tngtech.java.junit.dataprovider.DataProviderRunner;
+import com.tngtech.java.junit.dataprovider.UseDataProvider;
 import java.io.File;
 import java.io.IOException;
 import java.net.InetSocketAddress;
@@ -26,7 +29,6 @@ import java.net.Proxy;
 import java.net.SocketTimeoutException;
 import java.util.Base64;
 import java.util.List;
-import java.util.Random;
 import java.util.concurrent.TimeUnit;
 import java.util.zip.GZIPOutputStream;
 import javax.net.ssl.SSLSocketFactory;
@@ -45,6 +47,7 @@ import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
+import org.junit.runner.RunWith;
 import org.sonarqube.ws.MediaTypes;
 
 import static java.nio.charset.StandardCharsets.UTF_8;
@@ -56,6 +59,7 @@ import static org.junit.Assert.fail;
 import static org.mockito.Mockito.mock;
 import static org.sonarqube.ws.client.HttpConnector.newBuilder;
 
+@RunWith(DataProviderRunner.class)
 public class HttpConnectorTest {
 
   @Rule
@@ -249,9 +253,9 @@ public class HttpConnectorTest {
   }
 
   @Test
-  public void systemPassCode_sets_header_when_value_is_not_null() throws InterruptedException {
+  @UseDataProvider("nonNullPasswords")
+  public void systemPassCode_sets_header_when_value_is_not_null(String systemPassCode) throws InterruptedException {
     answerHelloWorld();
-    String systemPassCode = new Random().nextBoolean() ? "" : RandomStringUtils.secure().nextAlphanumeric(21);
     underTest = HttpConnector.newBuilder()
       .url(serverUrl)
       .systemPassCode(systemPassCode)
@@ -557,6 +561,14 @@ public class HttpConnectorTest {
     assertThat(connectionSpecs.get(1).isTls()).isFalse();
   }
 
+  @DataProvider()
+  public static Object[][] nonNullPasswords() {
+    return new Object[][] {
+      {""},
+      {RandomStringUtils.secure().nextAlphanumeric(21)}
+    };
+  }
+
   private void answerHelloWorld() {
     server.enqueue(new MockResponse().setBody("hello, world!").setHeader("header", "value"));
   }