]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-18797 warn log message and truncate scim_users during upgrade
authorPierre <pierre.guillot@sonarsource.com>
Fri, 17 Mar 2023 14:08:43 +0000 (15:08 +0100)
committersonartech <sonartech@sonarsource.com>
Wed, 22 Mar 2023 20:04:08 +0000 (20:04 +0000)
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v100/DbVersion100.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v100/DropScimUserProvisioning.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v100/DropSonarScimEnabledProperty.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v100/LogMessageIfSonarScimEnabledPresentProperty.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v100/DropScimUserProvisioningTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v100/DropSonarScimEnabledPropertyTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v100/LogMessageIfSonarScimEnabledPresentPropertyTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v100/DropScimUserProvisioningTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v100/DropSonarScimEnabledPropertyTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v100/LogMessageIfSonarScimEnabledPresentPropertyTest/schema.sql [new file with mode: 0644]

index 331d3b25b240da59a763c4178b24d16ae63e37fd..1217495bcc28344f8254dc6aad3aaeb85d5c80f8 100644 (file)
@@ -53,6 +53,9 @@ public class DbVersion100 implements DbVersion {
       .add(10_0_009, "Make column 'user_local' not nullable in the 'users' table", MakeColumnUserLocalNotNullableInUsers.class)
       .add(10_0_010, "Create 'scim_groups' table", CreateScimGroupsTable.class)
       .add(10_0_011, "Create unique index on scim_groups.group_uuid", CreateUniqueIndexForScimGroupsUuid.class)
+      .add(10_0_012, "Log a warning message if 'sonar.scim.enabled' is used", LogMessageIfSonarScimEnabledPresentProperty.class)
+      .add(10_0_013, "Drop 'sonar.scim.enabled' property", DropSonarScimEnabledProperty.class)
+      .add(10_0_014, "Drop any SCIM User provisioning, turning all users local", DropScimUserProvisioning.class)
     ;
   }
 }
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v100/DropScimUserProvisioning.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v100/DropScimUserProvisioning.java
new file mode 100644 (file)
index 0000000..f4cb12b
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v100;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.step.DataChange;
+
+public class DropScimUserProvisioning extends DataChange {
+
+  public DropScimUserProvisioning(Database db) {
+    super(db);
+  }
+
+  @Override
+  protected void execute(Context context) throws SQLException {
+    context.prepareUpsert("delete from scim_users").execute().commit();
+  }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v100/DropSonarScimEnabledProperty.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v100/DropSonarScimEnabledProperty.java
new file mode 100644 (file)
index 0000000..6df2a3e
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v100;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.step.DataChange;
+
+public class DropSonarScimEnabledProperty extends DataChange {
+
+  public DropSonarScimEnabledProperty(Database db) {
+    super(db);
+  }
+
+  @Override
+  protected void execute(Context context) throws SQLException {
+    context.prepareUpsert("delete from properties where prop_key = ?")
+      .setString(1, "sonar.scim.enabled")
+      .execute()
+      .commit();
+  }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v100/LogMessageIfSonarScimEnabledPresentProperty.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v100/LogMessageIfSonarScimEnabledPresentProperty.java
new file mode 100644 (file)
index 0000000..2888982
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v100;
+
+import java.sql.SQLException;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.step.DataChange;
+
+public class LogMessageIfSonarScimEnabledPresentProperty extends DataChange {
+
+  private static final Logger LOG = Loggers.get(LogMessageIfSonarScimEnabledPresentProperty.class);
+  public static final String SONAR_SCIM_ENABLED = "sonar.scim.enabled";
+
+  public LogMessageIfSonarScimEnabledPresentProperty(Database db) {
+    super(db);
+  }
+
+  @Override
+  protected void execute(Context context) throws SQLException {
+    context.prepareSelect("select * from properties where prop_key = ?")
+      .setString(1, SONAR_SCIM_ENABLED)
+      .scroll(row -> LOG.warn("'{}' property is defined but not read anymore." +
+        " Please read the upgrade notes for the instruction to upgrade. User provisioning is deactivated until reactivated" +
+        " from the SonarQube Administration Interface (\"General->Authentication\").", SONAR_SCIM_ENABLED));
+  }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v100/DropScimUserProvisioningTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v100/DropScimUserProvisioningTest.java
new file mode 100644 (file)
index 0000000..cd3d1ae
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v100;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DataChange;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class DropScimUserProvisioningTest {
+
+  @Rule
+  public final CoreDbTester db = CoreDbTester.createForSchema(DropScimUserProvisioningTest.class, "schema.sql");
+  private final DataChange underTest = new DropScimUserProvisioning(db.database());
+
+  @Test
+  public void migration_should_truncate_scim_users_table() throws SQLException {
+    insertScimUser(1);
+    insertScimUser(2);
+
+    underTest.execute();
+
+    assertThat(db.select("select * from scim_users")).isEmpty();
+  }
+
+  private void insertScimUser(long id) {
+    db.executeInsert("scim_users",
+      "scim_uuid", "any-scim-uuid-" + id,
+      "user_uuid", "any-user-uuid-" + id
+    );
+  }
+
+  @Test
+  public void migration_is_reentrant() throws SQLException {
+    insertScimUser(1);
+    insertScimUser(2);
+
+    underTest.execute();
+    underTest.execute();
+    assertThat(db.select("select * from scim_users")).isEmpty();
+  }
+
+}
\ No newline at end of file
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v100/DropSonarScimEnabledPropertyTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v100/DropSonarScimEnabledPropertyTest.java
new file mode 100644 (file)
index 0000000..c2bba8a
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v100;
+
+import java.sql.SQLException;
+import org.assertj.core.api.Assertions;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DataChange;
+
+public class DropSonarScimEnabledPropertyTest {
+
+  @Rule
+  public final CoreDbTester db = CoreDbTester.createForSchema(DropSonarScimEnabledPropertyTest.class, "schema.sql");
+  private final DataChange underTest = new DropSonarScimEnabledProperty(db.database());
+
+  @Test
+  public void migration_should_remove_scim_property() throws SQLException {
+    insertScimProperty(db);
+
+    underTest.execute();
+
+    Assertions.assertThat(db.select("select * from properties")).isEmpty();
+  }
+
+  @Test
+  public void migration_is_reentrant() throws SQLException {
+    insertScimProperty(db);
+
+    underTest.execute();
+    underTest.execute();
+
+    Assertions.assertThat(db.select("select * from properties")).isEmpty();
+  }
+
+  private void insertScimProperty(CoreDbTester db) {
+    db.executeInsert("properties ",
+      "prop_key", "sonar.scim.enabled",
+      "is_empty", false,
+      "text_value", "true",
+      "created_at", 100_000L,
+      "uuid", "some-random-uuid"
+    );
+  }
+}
\ No newline at end of file
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v100/LogMessageIfSonarScimEnabledPresentPropertyTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v100/LogMessageIfSonarScimEnabledPresentPropertyTest.java
new file mode 100644 (file)
index 0000000..cf71c21
--- /dev/null
@@ -0,0 +1,90 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v100;
+
+import java.sql.SQLException;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.api.utils.log.LogTester;
+import org.sonar.api.utils.log.LoggerLevel;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DataChange;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.sonar.server.platform.db.migration.version.v100.LogMessageIfSonarScimEnabledPresentProperty.SONAR_SCIM_ENABLED;
+
+public class LogMessageIfSonarScimEnabledPresentPropertyTest {
+
+  @Rule
+  public LogTester logger = new LogTester();
+
+  @Rule
+  public final CoreDbTester db = CoreDbTester.createForSchema(LogMessageIfSonarScimEnabledPresentPropertyTest.class, "schema.sql");
+  private final DataChange underTest = new LogMessageIfSonarScimEnabledPresentProperty(db.database());
+
+  @Before
+  public void before() {
+    logger.clear();
+  }
+
+  @Test
+  public void migration_should_log_message_when_scim_property() throws SQLException {
+    db.executeInsert("properties ",
+      "prop_key", "sonar.scim.enabled",
+      "is_empty", false,
+      "text_value", "true",
+      "created_at", 100_000L,
+      "uuid", "some-random-uuid"
+    );
+
+    underTest.execute();
+
+    assertThat(logger.logs(LoggerLevel.WARN))
+      .hasSize(1)
+      .containsExactly("'" + SONAR_SCIM_ENABLED + "' property is defined but not read anymore. Please read the upgrade notes" +
+        " for the instruction to upgrade. User provisioning is deactivated until reactivated from the SonarQube" +
+        " Administration Interface (\"General->Authentication\").");
+  }
+
+  @Test
+  public void migration_should_not_log_if_no_scim_property() throws SQLException {
+
+    underTest.execute();
+
+    assertThat(logger.logs(LoggerLevel.WARN)).isEmpty();
+  }
+
+  @Test
+  public void migration_is_reentrant() throws SQLException {
+    db.executeInsert("properties ",
+      "prop_key", "sonar.scim.enabled",
+      "is_empty", false,
+      "text_value", "true",
+      "created_at", 100_000L,
+      "uuid", "some-random-uuid"
+    );
+
+    underTest.execute();
+    underTest.execute();
+
+    assertThat(logger.logs(LoggerLevel.WARN)).hasSize(2);
+  }
+}
\ No newline at end of file
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v100/DropScimUserProvisioningTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v100/DropScimUserProvisioningTest/schema.sql
new file mode 100644 (file)
index 0000000..aa6b750
--- /dev/null
@@ -0,0 +1,6 @@
+CREATE TABLE "SCIM_USERS"(
+    "SCIM_UUID" CHARACTER VARYING(40) NOT NULL,
+    "USER_UUID" CHARACTER VARYING(40) NOT NULL
+);
+ALTER TABLE "SCIM_USERS" ADD CONSTRAINT "PK_SCIM_USERS" PRIMARY KEY("SCIM_UUID");
+CREATE UNIQUE INDEX "UNIQ_SCIM_USERS_USER_UUID" ON "SCIM_USERS"("USER_UUID" NULLS FIRST);
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v100/DropSonarScimEnabledPropertyTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v100/DropSonarScimEnabledPropertyTest/schema.sql
new file mode 100644 (file)
index 0000000..7aef2dc
--- /dev/null
@@ -0,0 +1,12 @@
+CREATE TABLE "PROPERTIES"(
+    "UUID" CHARACTER VARYING(40) NOT NULL,
+    "PROP_KEY" CHARACTER VARYING(512) NOT NULL,
+    "IS_EMPTY" BOOLEAN NOT NULL,
+    "TEXT_VALUE" CHARACTER VARYING(4000),
+    "CLOB_VALUE" CHARACTER LARGE OBJECT,
+    "CREATED_AT" BIGINT NOT NULL,
+    "COMPONENT_UUID" CHARACTER VARYING(40),
+    "USER_UUID" CHARACTER VARYING(255)
+);
+ALTER TABLE "PROPERTIES" ADD CONSTRAINT "PK_PROPERTIES" PRIMARY KEY("UUID");
+CREATE INDEX "PROPERTIES_KEY" ON "PROPERTIES"("PROP_KEY" NULLS FIRST);
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v100/LogMessageIfSonarScimEnabledPresentPropertyTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v100/LogMessageIfSonarScimEnabledPresentPropertyTest/schema.sql
new file mode 100644 (file)
index 0000000..7aef2dc
--- /dev/null
@@ -0,0 +1,12 @@
+CREATE TABLE "PROPERTIES"(
+    "UUID" CHARACTER VARYING(40) NOT NULL,
+    "PROP_KEY" CHARACTER VARYING(512) NOT NULL,
+    "IS_EMPTY" BOOLEAN NOT NULL,
+    "TEXT_VALUE" CHARACTER VARYING(4000),
+    "CLOB_VALUE" CHARACTER LARGE OBJECT,
+    "CREATED_AT" BIGINT NOT NULL,
+    "COMPONENT_UUID" CHARACTER VARYING(40),
+    "USER_UUID" CHARACTER VARYING(255)
+);
+ALTER TABLE "PROPERTIES" ADD CONSTRAINT "PK_PROPERTIES" PRIMARY KEY("UUID");
+CREATE INDEX "PROPERTIES_KEY" ON "PROPERTIES"("PROP_KEY" NULLS FIRST);