import static org.sonar.api.PropertyType.BOOLEAN;
import static org.sonar.api.PropertyType.PASSWORD;
import static org.sonar.api.PropertyType.STRING;
+import static org.sonar.api.utils.Preconditions.checkState;
public class GitHubSettings {
public static final String WEB_URL = "sonar.auth.github.webUrl";
public static final String ORGANIZATIONS = "sonar.auth.github.organizations";
@VisibleForTesting
- static final String PROVISIONING = "provisioning.github"; //TODO
+ static final String PROVISIONING = "provisioning.github.enabled";
private static final String CATEGORY = "authentication";
private static final String SUBCATEGORY = "github";
return configuration.get(PRIVATE_KEY).orElse("");
}
- boolean isEnabled() {
+ public boolean isEnabled() {
return configuration.getBoolean(ENABLED).orElse(false) && !clientId().isEmpty() && !clientSecret().isEmpty();
}
}
public void setProvisioning(boolean enableProvisioning) {
+ if (enableProvisioning) {
+ checkState(isEnabled(), "GitHub authentication must be enabled to enable GitHub provisioning.");
+ }
internalProperties.write(PROVISIONING, String.valueOf(enableProvisioning));
}
import org.sonar.server.property.InternalProperties;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
assertThat(underTest.isProvisioningEnabled()).isTrue();
}
+ @Test
+ public void setProvisioning_whenGitHubAuthDisabled_shouldThrow() {
+ assertThatIllegalStateException()
+ .isThrownBy(() -> underTest.setProvisioning(true))
+ .withMessage("GitHub authentication must be enabled to enable GitHub provisioning.");
+ }
+
@Test
public void setProvisioning_whenPassedTrue_delegatesToInternalPropertiesWrite() {
+ enableGithubAuthentication();
underTest.setProvisioning(true);
verify(internalProperties).write(GitHubSettings.PROVISIONING, Boolean.TRUE.toString());
}