@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/TMa6BosF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iKlhh0
+ YS2Vz+yuTDpE54CFW4M8wZKnXNbWJDBdd6KjIu42kKrA/zTJ5Ox92u1BJXFsk9fk
+ xcX++qp5iBGepXZgHEiBMQLcdgY1m3jQl6XXOGSFog0+c4NIE/f1A8PrwI7gAdSt
+ 56SVAoGBAJp214Fo0oheMTTYKVtXuGiH/v3JNG1jKFgsmHqndf4wy7U6bbNctEzc
+ ZXNIacuhWmko6YejMrWNhE57sX812MhXGZq6y0sYZGKtp7oDv8G3rWD6bpZywpcV
+ kTtMJxm8J64u6bAkpWG3BocJP9qbXeAbILo1wuXgYqABBrpA9nnc""";
GithubAppConfiguration githubAppConfiguration = createAppConfigurationForPrivateKey(incompletePrivateKey);
assertThatThrownBy(() -> underTest.createAppToken(githubAppConfiguration.getId(), githubAppConfiguration.getPrivateKey()))
@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/Jq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mHqndf4wy7U6bbNctEzc\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()))
}
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) {
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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DpE54CFW4M8wZKnXNbWJDBdd6KjIu42kKrA/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-----""";
}
.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();
@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();
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");
}
*/
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;
@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))
*/
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;
@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)
@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
*/
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;
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 -> {
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")
@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
@DataProvider
public static Object[][] indexWithAndWithoutRelations() {
return new Object[][] {
- {Index.simple(someIndexName)},
- {Index.withRelations(someIndexName)}
+ {Index.simple(SOME_INDEX_NAME)},
+ {Index.withRelations(SOME_INDEX_NAME)}
};
}
@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
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;
@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");
@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));
@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));
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;
@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));
@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());
@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());
@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();
@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},
@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},
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();
}
}
@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);
}
@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));
}
}
@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);
}
@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);
}
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());
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)
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() {
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;
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");
}
@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();
}
@Test
- public void verify_response_example() {
+ void verify_response_example() {
authenticateWithPasscode();
when(healthChecker.checkNode())
.thenReturn(Health.builder()
.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);
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)}
};
}
return new Object[][] {
{randomTrimmedChars(1, random)},
{randomTrimmedChars(2, random)},
- {randomTrimmedChars(3 + random.nextInt(5), random)}
+ {randomTrimmedChars(3, random)},
+ {randomTrimmedChars(5, random)},
+ {randomTrimmedChars(8, random)}
};
}
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
*/
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;
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;
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;
import static org.mockito.Mockito.mock;
import static org.sonarqube.ws.client.HttpConnector.newBuilder;
+@RunWith(DataProviderRunner.class)
public class HttpConnectorTest {
@Rule
}
@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)
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"));
}