aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-auth-github/src
diff options
context:
space:
mode:
Diffstat (limited to 'server/sonar-auth-github/src')
-rw-r--r--server/sonar-auth-github/src/main/java/org/sonar/auth/github/GitHubSettings.java8
-rw-r--r--server/sonar-auth-github/src/test/java/org/sonar/auth/github/GitHubSettingsTest.java9
2 files changed, 15 insertions, 2 deletions
diff --git a/server/sonar-auth-github/src/main/java/org/sonar/auth/github/GitHubSettings.java b/server/sonar-auth-github/src/main/java/org/sonar/auth/github/GitHubSettings.java
index b7a1eec45d8..477ba26b84c 100644
--- a/server/sonar-auth-github/src/main/java/org/sonar/auth/github/GitHubSettings.java
+++ b/server/sonar-auth-github/src/main/java/org/sonar/auth/github/GitHubSettings.java
@@ -33,6 +33,7 @@ import static java.lang.String.valueOf;
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 {
@@ -47,7 +48,7 @@ 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";
@@ -78,7 +79,7 @@ public class GitHubSettings {
return configuration.get(PRIVATE_KEY).orElse("");
}
- boolean isEnabled() {
+ public boolean isEnabled() {
return configuration.getBoolean(ENABLED).orElse(false) && !clientId().isEmpty() && !clientSecret().isEmpty();
}
@@ -113,6 +114,9 @@ public class GitHubSettings {
}
public void setProvisioning(boolean enableProvisioning) {
+ if (enableProvisioning) {
+ checkState(isEnabled(), "GitHub authentication must be enabled to enable GitHub provisioning.");
+ }
internalProperties.write(PROVISIONING, String.valueOf(enableProvisioning));
}
diff --git a/server/sonar-auth-github/src/test/java/org/sonar/auth/github/GitHubSettingsTest.java b/server/sonar-auth-github/src/test/java/org/sonar/auth/github/GitHubSettingsTest.java
index 870a2a90973..3f28bad4305 100644
--- a/server/sonar-auth-github/src/test/java/org/sonar/auth/github/GitHubSettingsTest.java
+++ b/server/sonar-auth-github/src/test/java/org/sonar/auth/github/GitHubSettingsTest.java
@@ -28,6 +28,7 @@ import org.sonar.api.utils.System2;
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;
@@ -95,7 +96,15 @@ public class GitHubSettingsTest {
}
@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());
}