aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--server/sonar-alm-client/src/test/java/org/sonar/alm/client/github/security/GithubAppSecurityImplTest.java158
-rw-r--r--server/sonar-db-dao/src/it/java/org/sonar/db/component/ComponentDaoIT.java7
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/ce/CeActivityDtoTest.java3
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/ce/UpdateIfTest.java3
-rw-r--r--server/sonar-process/src/test/java/org/sonar/process/logging/LogLevelConfigTest.java6
-rw-r--r--server/sonar-server-common/src/test/java/org/sonar/server/es/newindex/FieldAwareTest.java4
-rw-r--r--server/sonar-server-common/src/test/java/org/sonar/server/es/newindex/NewIndexTest.java14
-rw-r--r--server/sonar-server-common/src/test/java/org/sonar/server/es/searchrequest/AllFiltersTest.java11
-rw-r--r--server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/ChangesOnMyIssuesNotificationTest.java7
-rw-r--r--server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/FpPrAcceptedEmailTemplateTest.java23
-rw-r--r--server/sonar-server-common/src/test/java/org/sonar/server/permission/index/AuthorizationDocTest.java10
-rw-r--r--server/sonar-webserver-api/src/test/java/org/sonar/server/util/GlobalLockManagerImplTest.java14
-rw-r--r--server/sonar-webserver-webapi/src/it/java/org/sonar/server/hotspot/ws/SearchActionIT.java11
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/HealthActionTest.java8
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/SafeModeHealthActionTest.java46
-rw-r--r--sonar-plugin-api-impl/src/test/java/org/sonar/api/config/internal/MultivaluePropertyTest.java8
-rw-r--r--sonar-ws/build.gradle31
-rw-r--r--sonar-ws/src/test/java/org/sonarqube/ws/client/HttpConnectorTest.java18
18 files changed, 202 insertions, 180 deletions
diff --git a/server/sonar-alm-client/src/test/java/org/sonar/alm/client/github/security/GithubAppSecurityImplTest.java b/server/sonar-alm-client/src/test/java/org/sonar/alm/client/github/security/GithubAppSecurityImplTest.java
index 65224ce6adb..08ad4f1a87d 100644
--- a/server/sonar-alm-client/src/test/java/org/sonar/alm/client/github/security/GithubAppSecurityImplTest.java
+++ b/server/sonar-alm-client/src/test/java/org/sonar/alm/client/github/security/GithubAppSecurityImplTest.java
@@ -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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hzG0CgYAEN011MAyTqFSvAwN9kjhb
+ 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" +
- "oeg0A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eP8b3JW70LkC+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" +
- "MIIEowIBAAKCAQEA6C29ZdvrwHOu7Eew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lIU4oDu/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+M5AXVj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ZgHEiBMQLcdgY1m3jQl6XXOGSFog0+c4NIE/f1A8PrwI7gAdSt
+ 56SVAoGBAJp214Fo0oheMTTYKVtXuGiH/v3JNG1jKFgsmHqndf4wy7U6bbNctEzc
+ ZXNIacuhWmko6YejMrWNhE57sX812MhXGZq6y0sYZGKtp7oDv8G3rWD6bpZywpcV
+ kTtMJxm8J64u6bAkpWG3BocJP9qbXeAbILo1wuXgYqABBrpA9nnc
+ -----END RSA PRIVATE KEY-----""";
}
diff --git a/server/sonar-db-dao/src/it/java/org/sonar/db/component/ComponentDaoIT.java b/server/sonar-db-dao/src/it/java/org/sonar/db/component/ComponentDaoIT.java
index a5288b236bf..3d43a6e6810 100644
--- a/server/sonar-db-dao/src/it/java/org/sonar/db/component/ComponentDaoIT.java
+++ b/server/sonar-db-dao/src/it/java/org/sonar/db/component/ComponentDaoIT.java
@@ -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");
}
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/ce/CeActivityDtoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/ce/CeActivityDtoTest.java
index 6724092155d..94ad2337c07 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/ce/CeActivityDtoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/ce/CeActivityDtoTest.java
@@ -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))
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/ce/UpdateIfTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/ce/UpdateIfTest.java
index ce3ab177108..928d7e73c08 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/ce/UpdateIfTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/ce/UpdateIfTest.java
@@ -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)
diff --git a/server/sonar-process/src/test/java/org/sonar/process/logging/LogLevelConfigTest.java b/server/sonar-process/src/test/java/org/sonar/process/logging/LogLevelConfigTest.java
index 4f1a23c04e7..9e72c2a53d0 100644
--- a/server/sonar-process/src/test/java/org/sonar/process/logging/LogLevelConfigTest.java
+++ b/server/sonar-process/src/test/java/org/sonar/process/logging/LogLevelConfigTest.java
@@ -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
diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/es/newindex/FieldAwareTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/es/newindex/FieldAwareTest.java
index 59eef06c822..d1bc06593c4 100644
--- a/server/sonar-server-common/src/test/java/org/sonar/server/es/newindex/FieldAwareTest.java
+++ b/server/sonar-server-common/src/test/java/org/sonar/server/es/newindex/FieldAwareTest.java
@@ -19,12 +19,10 @@
*/
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 -> {
diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/es/newindex/NewIndexTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/es/newindex/NewIndexTest.java
index 8e33bbc620e..e8a2ee572b0 100644
--- a/server/sonar-server-common/src/test/java/org/sonar/server/es/newindex/NewIndexTest.java
+++ b/server/sonar-server-common/src/test/java/org/sonar/server/es/newindex/NewIndexTest.java
@@ -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)}
};
}
diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/es/searchrequest/AllFiltersTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/es/searchrequest/AllFiltersTest.java
index b6ec64e6e4f..d3ea1974056 100644
--- a/server/sonar-server-common/src/test/java/org/sonar/server/es/searchrequest/AllFiltersTest.java
+++ b/server/sonar-server-common/src/test/java/org/sonar/server/es/searchrequest/AllFiltersTest.java
@@ -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
diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/ChangesOnMyIssuesNotificationTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/ChangesOnMyIssuesNotificationTest.java
index ff9847b368a..42c29365318 100644
--- a/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/ChangesOnMyIssuesNotificationTest.java
+++ b/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/ChangesOnMyIssuesNotificationTest.java
@@ -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));
diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/FpPrAcceptedEmailTemplateTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/FpPrAcceptedEmailTemplateTest.java
index 7a0d96b10ca..967e5955cd8 100644
--- a/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/FpPrAcceptedEmailTemplateTest.java
+++ b/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/FpPrAcceptedEmailTemplateTest.java
@@ -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},
diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/permission/index/AuthorizationDocTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/permission/index/AuthorizationDocTest.java
index 23e47a79507..2614352fdd5 100644
--- a/server/sonar-server-common/src/test/java/org/sonar/server/permission/index/AuthorizationDocTest.java
+++ b/server/sonar-server-common/src/test/java/org/sonar/server/permission/index/AuthorizationDocTest.java
@@ -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();
}
diff --git a/server/sonar-webserver-api/src/test/java/org/sonar/server/util/GlobalLockManagerImplTest.java b/server/sonar-webserver-api/src/test/java/org/sonar/server/util/GlobalLockManagerImplTest.java
index 92f556e19cf..d1010b128d1 100644
--- a/server/sonar-webserver-api/src/test/java/org/sonar/server/util/GlobalLockManagerImplTest.java
+++ b/server/sonar-webserver-api/src/test/java/org/sonar/server/util/GlobalLockManagerImplTest.java
@@ -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);
}
diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/hotspot/ws/SearchActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/hotspot/ws/SearchActionIT.java
index 6c636202e6e..4a739cad218 100644
--- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/hotspot/ws/SearchActionIT.java
+++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/hotspot/ws/SearchActionIT.java
@@ -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)
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/HealthActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/HealthActionTest.java
index f085045ffd3..e9d4a57c786 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/HealthActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/HealthActionTest.java
@@ -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() {
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/SafeModeHealthActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/SafeModeHealthActionTest.java
index 63645093980..283dd04fb5c 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/SafeModeHealthActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/SafeModeHealthActionTest.java
@@ -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);
diff --git a/sonar-plugin-api-impl/src/test/java/org/sonar/api/config/internal/MultivaluePropertyTest.java b/sonar-plugin-api-impl/src/test/java/org/sonar/api/config/internal/MultivaluePropertyTest.java
index 1452e78d673..d28c74fd946 100644
--- a/sonar-plugin-api-impl/src/test/java/org/sonar/api/config/internal/MultivaluePropertyTest.java
+++ b/sonar-plugin-api-impl/src/test/java/org/sonar/api/config/internal/MultivaluePropertyTest.java
@@ -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)}
};
}
diff --git a/sonar-ws/build.gradle b/sonar-ws/build.gradle
index 4c8f23c9e5d..e33277140ef 100644
--- a/sonar-ws/build.gradle
+++ b/sonar-ws/build.gradle
@@ -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
diff --git a/sonar-ws/src/test/java/org/sonarqube/ws/client/HttpConnectorTest.java b/sonar-ws/src/test/java/org/sonarqube/ws/client/HttpConnectorTest.java
index 411dd9b9bbc..c0320cbde02 100644
--- a/sonar-ws/src/test/java/org/sonarqube/ws/client/HttpConnectorTest.java
+++ b/sonar-ws/src/test/java/org/sonarqube/ws/client/HttpConnectorTest.java
@@ -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"));
}