public class GitHubIdentityProvider implements OAuth2IdentityProvider {
- static final String KEY = "github";
+ public static final String KEY = "github";
private final GitHubSettings settings;
private final UserIdentityFactory userIdentityFactory;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
+import static org.sonar.db.property.InternalPropertiesDao.LOCK_NAME_MAX_LENGTH;
public class InternalPropertiesDaoIT {
private static final String EMPTY_STRING = "";
private static final String A_KEY = "a_key";
private static final String ANOTHER_KEY = "another_key";
- private static final String VALUE_1 = "one";
- private static final String VALUE_2 = "two";
private static final long DATE_1 = 1_500_000_000_000L;
private static final long DATE_2 = 1_600_000_000_000L;
private static final String VALUE_SMALL = "some small value";
.flatMap(s -> s)
.collect(Collectors.toSet());
- expectKeyNullOrEmptyIAE(() -> underTest.selectByKeys(dbSession, keysIncludingAnEmptyString));
+ expectKeyNullOrEmptyIAE(() -> underTest.selectByKeys(dbSession, keysIncludingAnEmptyString));
}
@Test
}
@Test
- public void tryLock_throws_IAE_if_lock_name_length_is_16_or_more() {
- String tooLongName = randomAlphabetic(16 + new Random().nextInt(30));
+ public void tryLock_throws_IAE_if_lock_name_length_is_too_long() {
+ String tooLongName = randomAlphabetic(LOCK_NAME_MAX_LENGTH + new Random().nextInt(30));
assertThatThrownBy(() -> underTest.tryLock(dbSession, tooLongName, 60))
.isInstanceOf(IllegalArgumentException.class)
*/
private static final String LOCK_PREFIX = "lock.";
- private static final int KEY_MAX_LENGTH = 20;
+ private static final int KEY_MAX_LENGTH = 40;
public static final int LOCK_NAME_MAX_LENGTH = KEY_MAX_LENGTH - LOCK_PREFIX.length();
private static final int TEXT_VALUE_MAX_LENGTH = 4000;
import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatNoException;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
+import static org.sonar.db.property.InternalPropertiesDao.LOCK_NAME_MAX_LENGTH;
import static org.sonar.server.util.GlobalLockManager.DEFAULT_LOCK_DURATION_SECONDS;
@RunWith(DataProviderRunner.class)
public class GlobalLockManagerImplTest {
- private static final int LOCK_NAME_MAX_LENGTH = 15;
private final DbClient dbClient = mock(DbClient.class);
private final InternalPropertiesDao internalPropertiesDao = mock(InternalPropertiesDao.class);
private final DbSession dbSession = mock(DbSession.class);
}
@Test
- public void tryLock_fails_with_IAE_if_name_length_is_16_or_more() {
+ 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));
expectBadLockNameIAE(() -> underTest.tryLock(badLockName), badLockName);
}
@Test
- public void tryLock_accepts_name_with_length_15_or_less() {
+ public void tryLock_accepts_name_with_allowed_length() {
for (int i = 1; i <= LOCK_NAME_MAX_LENGTH; i++) {
- underTest.tryLock(RandomStringUtils.random(i));
+ String lockName = RandomStringUtils.random(i);
+ assertThatNoException().isThrownBy(() -> underTest.tryLock(lockName));
}
}
@Test
@UseDataProvider("randomValidDuration")
- public void tryLock_with_duration_fails_with_IAE_if_name_length_is_16_or_more(int 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));
expectBadLockNameIAE(() -> underTest.tryLock(badLockName, randomValidDuration), badLockName);
@Test
@UseDataProvider("randomValidLockName")
public void tryLock_with_duration_fails_with_IAE_if_duration_is_0(String randomValidLockName) {
- expectBadDuration(() -> underTest.tryLock(randomValidLockName, 0),0);
+ expectBadDuration(() -> underTest.tryLock(randomValidLockName, 0), 0);
}
@Test
@DataProvider
public static Object[][] randomValidDuration() {
return new Object[][] {
- {1+ new Random().nextInt(2_00)}
+ {1 + new Random().nextInt(2_00)}
};
}
private final DbClient dbClient = db.getDbClient();
private final DbSession dbSession = db.getSession();
private final UserAnonymizer userAnonymizer = new UserAnonymizer(db.getDbClient(), () -> "anonymized");
- private final UserDeactivator userDeactivator = new UserDeactivator(dbClient, userSession, userAnonymizer);
+ private final UserDeactivator userDeactivator = new UserDeactivator(dbClient, userAnonymizer);
private final ManagedInstanceChecker managedInstanceChecker = mock(ManagedInstanceChecker.class);
private final WsActionTester ws = new WsActionTester(new DeactivateAction(dbClient, userSession, new UserJsonWriter(userSession), userDeactivator, managedInstanceChecker));
@Override
public void handle(Request request, Response response) throws Exception {
- String login;
userSession.checkLoggedIn().checkIsSystemAdministrator();
- login = request.mandatoryParam(PARAM_LOGIN);
+ String login = request.mandatoryParam(PARAM_LOGIN);
checkRequest(!login.equals(userSession.getLogin()), "Self-deactivation is not possible");
try (DbSession dbSession = dbClient.openSession(false)) {
preventManagedUserDeactivationIfManagedInstance(dbSession, login);
import org.sonar.db.DbSession;
import org.sonar.db.property.PropertyQuery;
import org.sonar.db.user.UserDto;
-import org.sonar.server.user.UserSession;
import static org.sonar.api.CoreProperties.DEFAULT_ISSUE_ASSIGNEE;
import static org.sonar.db.permission.GlobalPermission.ADMINISTER;
public class UserDeactivator {
private final DbClient dbClient;
- private final UserSession userSession;
private final UserAnonymizer userAnonymizer;
- public UserDeactivator(DbClient dbClient, UserSession userSession, UserAnonymizer userAnonymizer) {
+ public UserDeactivator(DbClient dbClient, UserAnonymizer userAnonymizer) {
this.dbClient = dbClient;
- this.userSession = userSession;
this.userAnonymizer = userAnonymizer;
}
}
private UserDto doBeforeDeactivation(DbSession dbSession, String login) {
- checkRequest(!login.equals(userSession.getLogin()), "Self-deactivation is not possible");
UserDto user = getUserOrThrow(dbSession, login);
ensureNotLastAdministrator(dbSession, user);
deleteRelatedData(dbSession, user);