aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-auth-github/src
diff options
context:
space:
mode:
authorWojtek Wajerowicz <115081248+wojciech-wajerowicz-sonarsource@users.noreply.github.com>2023-12-21 11:15:22 +0100
committersonartech <sonartech@sonarsource.com>2023-12-22 20:03:03 +0000
commit7453617939eff3e8d3f5cc4c84f21b38c5c50701 (patch)
treea12357e847faf3d2aecaf24c0558bf0d6892b5c2 /server/sonar-auth-github/src
parentf7b41e437a2b9a1a8f51e59e24d0979480db66ad (diff)
downloadsonarqube-7453617939eff3e8d3f5cc4c84f21b38c5c50701.tar.gz
sonarqube-7453617939eff3e8d3f5cc4c84f21b38c5c50701.zip
SONAR-21244 Clean github_orgs_groups table when disabling GitHub auto provisioning.
Diffstat (limited to 'server/sonar-auth-github/src')
-rw-r--r--server/sonar-auth-github/src/it/java/org/sonar/auth/github/GitHubSettingsIT.java (renamed from server/sonar-auth-github/src/test/java/org/sonar/auth/github/GitHubSettingsTest.java)20
-rw-r--r--server/sonar-auth-github/src/main/java/org/sonar/auth/github/GitHubSettings.java1
2 files changed, 15 insertions, 6 deletions
diff --git a/server/sonar-auth-github/src/test/java/org/sonar/auth/github/GitHubSettingsTest.java b/server/sonar-auth-github/src/it/java/org/sonar/auth/github/GitHubSettingsIT.java
index 5641897330f..b88b8929fa7 100644
--- a/server/sonar-auth-github/src/test/java/org/sonar/auth/github/GitHubSettingsTest.java
+++ b/server/sonar-auth-github/src/it/java/org/sonar/auth/github/GitHubSettingsIT.java
@@ -28,6 +28,7 @@ import org.sonar.api.config.PropertyDefinitions;
import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.utils.System2;
import org.sonar.db.DbTester;
+import org.sonar.db.provisioning.GithubOrganizationGroupDto;
import org.sonar.db.user.GroupDto;
import org.sonar.server.property.InternalProperties;
@@ -36,10 +37,10 @@ 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;
-import static org.sonar.auth.github.GitHubSettings.USER_CONSENT_FOR_PERMISSIONS_REQUIRED_AFTER_UPGRADE;
import static org.sonar.auth.github.GitHubSettings.PROVISION_VISIBILITY;
+import static org.sonar.auth.github.GitHubSettings.USER_CONSENT_FOR_PERMISSIONS_REQUIRED_AFTER_UPGRADE;
-public class GitHubSettingsTest {
+public class GitHubSettingsIT {
@Rule
public DbTester db = DbTester.create(System2.INSTANCE);
@@ -124,6 +125,7 @@ public class GitHubSettingsTest {
settings.setProperty(PROVISION_VISIBILITY, "false");
assertThat(underTest.isProjectVisibilitySynchronizationActivated()).isFalse();
}
+
@Test
public void isProjectVisibilitySynchronizationActivated_whenPropertyIsSetToTrue_returnsTrue() {
settings.setProperty(PROVISION_VISIBILITY, "true");
@@ -169,20 +171,26 @@ public class GitHubSettingsTest {
@Test
public void setProvisioning_whenPassedFalse_delegatesToInternalPropertiesWriteAndCleansUpExternalGroups() {
- GroupDto groupDto = createGithubManagedGroup();
+ createGithubManagedGroup();
+ createGitHubOrganizationGroup();
underTest.setProvisioning(false);
verify(internalProperties).write(GitHubSettings.PROVISIONING, Boolean.FALSE.toString());
- assertThat(db.getDbClient().externalGroupDao().selectByGroupUuid(db.getSession(), groupDto.getUuid())).isEmpty();
+ assertThat(db.getDbClient().externalGroupDao().selectByIdentityProvider(db.getSession(), GitHubIdentityProvider.KEY)).isEmpty();
+ assertThat(db.getDbClient().githubOrganizationGroupDao().findAll(db.getSession())).isEmpty();
}
- private GroupDto createGithubManagedGroup() {
+ private void createGithubManagedGroup() {
GroupDto groupDto = db.users().insertGroup();
db.users().markGroupAsGithubManaged(groupDto.getUuid());
- return groupDto;
}
+ private void createGitHubOrganizationGroup() {
+ GroupDto groupDto = db.users().insertGroup();
+ db.getDbClient().githubOrganizationGroupDao().insert(db.getSession(), new GithubOrganizationGroupDto(groupDto.getUuid(), "org1"));
+ db.commit();
+ }
@Test
public void return_client_id() {
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 5a50ee8980d..03093f98104 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
@@ -147,6 +147,7 @@ public class GitHubSettings implements DevOpsPlatformSettings {
private void removeExternalGroupsForGithub() {
try (DbSession dbSession = dbClient.openSession(false)) {
dbClient.externalGroupDao().deleteByExternalIdentityProvider(dbSession, GitHubIdentityProvider.KEY);
+ dbClient.githubOrganizationGroupDao().deleteAll(dbSession);
dbSession.commit();
}
}