From 0a4354287f3b95c32d117e1510ec4fc937e77872 Mon Sep 17 00:00:00 2001 From: Jacek Date: Thu, 2 Jan 2020 13:12:38 +0100 Subject: SONAR-12723 remove 'newsbox.dismiss.hotspots' user property --- .../container/ComputeEngineContainerImplTest.java | 2 +- .../db/migration/MigrationConfigurationModule.java | 2 + .../db/migration/version/v81/DbVersion81.java | 4 +- .../v81/DropSecurityHotSpotsInReviewStatus.java | 58 --------- ...ateManualVulnerabilitiesToSecurityHotSpots.java | 68 ---------- .../v81/RemoveNewsboxDismissHotspotsProperty.java | 38 ++++++ .../db/migration/version/v82/DbVersion82.java | 33 +++++ .../v82/DropSecurityHotSpotsInReviewStatus.java | 58 +++++++++ ...ateManualVulnerabilitiesToSecurityHotSpots.java | 68 ++++++++++ .../v82/RemoveNewsboxDismissHotspotsProperty.java | 38 ++++++ .../MigrationConfigurationModuleTest.java | 2 +- .../db/migration/version/v81/DbVersion81Test.java | 2 +- .../DropSecurityHotSpotsInReviewStatusTest.java | 118 ----------------- ...anualVulnerabilitiesToSecurityHotSpotsTest.java | 140 --------------------- .../RemoveNewsboxDismissHotspotsPropertyTest.java | 93 ++++++++++++++ .../db/migration/version/v82/DbVersion82Test.java | 42 +++++++ .../DropSecurityHotSpotsInReviewStatusTest.java | 118 +++++++++++++++++ ...anualVulnerabilitiesToSecurityHotSpotsTest.java | 140 +++++++++++++++++++++ .../RemoveNewsboxDismissHotspotsPropertyTest.java | 93 ++++++++++++++ .../schema.sql | 54 -------- .../schema.sql | 54 -------- .../schema.sql | 11 ++ .../schema.sql | 54 ++++++++ .../schema.sql | 54 ++++++++ .../schema.sql | 11 ++ .../org/sonar/server/user/ws/SetSettingAction.java | 2 +- .../sonar/server/user/ws/SetSettingActionTest.java | 11 +- 27 files changed, 860 insertions(+), 508 deletions(-) delete mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v81/DropSecurityHotSpotsInReviewStatus.java delete mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v81/MigrateManualVulnerabilitiesToSecurityHotSpots.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v81/RemoveNewsboxDismissHotspotsProperty.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v82/DbVersion82.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v82/DropSecurityHotSpotsInReviewStatus.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v82/MigrateManualVulnerabilitiesToSecurityHotSpots.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v82/RemoveNewsboxDismissHotspotsProperty.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v81/DropSecurityHotSpotsInReviewStatusTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v81/MigrateManualVulnerabilitiesToSecurityHotSpotsTest.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v81/RemoveNewsboxDismissHotspotsPropertyTest.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v82/DbVersion82Test.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v82/DropSecurityHotSpotsInReviewStatusTest.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v82/MigrateManualVulnerabilitiesToSecurityHotSpotsTest.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v82/RemoveNewsboxDismissHotspotsPropertyTest.java delete mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v81/DropSecurityHotSpotsInReviewStatusTest/schema.sql delete mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v81/MigrateManualVulnerabilitiesToSecurityHotSpotsTest/schema.sql create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v81/RemoveNewsboxDismissHotspotsPropertyTest/schema.sql create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v82/DropSecurityHotSpotsInReviewStatusTest/schema.sql create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v82/MigrateManualVulnerabilitiesToSecurityHotSpotsTest/schema.sql create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v82/RemoveNewsboxDismissHotspotsPropertyTest/schema.sql (limited to 'server') diff --git a/server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java b/server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java index 839e2c6aae4..b99e0c4b47d 100644 --- a/server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java +++ b/server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java @@ -122,7 +122,7 @@ public class ComputeEngineContainerImplTest { ); assertThat(picoContainer.getParent().getParent().getComponentAdapters()).hasSize( CONTAINER_ITSELF - + 6 // MigrationConfigurationModule + + 7 // MigrationConfigurationModule + 16 // level 2 ); assertThat(picoContainer.getParent().getParent().getParent().getComponentAdapters()).hasSize( diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/MigrationConfigurationModule.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/MigrationConfigurationModule.java index e724ff44940..1d3754e6f39 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/MigrationConfigurationModule.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/MigrationConfigurationModule.java @@ -27,6 +27,7 @@ import org.sonar.server.platform.db.migration.step.MigrationStepsProvider; import org.sonar.server.platform.db.migration.version.v00.DbVersion00; import org.sonar.server.platform.db.migration.version.v80.DbVersion80; import org.sonar.server.platform.db.migration.version.v81.DbVersion81; +import org.sonar.server.platform.db.migration.version.v82.DbVersion82; public class MigrationConfigurationModule extends Module { @Override @@ -36,6 +37,7 @@ public class MigrationConfigurationModule extends Module { DbVersion00.class, DbVersion80.class, DbVersion81.class, + DbVersion82.class, // migration steps MigrationStepRegistryImpl.class, diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v81/DbVersion81.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v81/DbVersion81.java index f09d1c15fa7..997f9362c41 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v81/DbVersion81.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v81/DbVersion81.java @@ -42,8 +42,6 @@ public class DbVersion81 implements DbVersion { RenameDaysBeforeDeletingInactiveSLBSetting.class) .add(3112, "Migrate short and long living branches types to common BRANCH type", MigrateSlbsAndLlbsToCommonType.class) .add(3113, "Migrate short and long living branches types to common BRANCH type in ce tasks table", - MigrateSlbsAndLlbsToCommonTypeInCeTasks.class) - .add(3114, "Drop 'In Review' Security Hotspots status ", DropSecurityHotSpotsInReviewStatus.class) - .add(3115, "Migrate Manual Vulnerabilities to Security Hotspots ", MigrateManualVulnerabilitiesToSecurityHotSpots.class); + MigrateSlbsAndLlbsToCommonTypeInCeTasks.class); } } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v81/DropSecurityHotSpotsInReviewStatus.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v81/DropSecurityHotSpotsInReviewStatus.java deleted file mode 100644 index 7b1248d2c19..00000000000 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v81/DropSecurityHotSpotsInReviewStatus.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2020 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.v81; - -import java.sql.SQLException; -import org.sonar.api.utils.System2; -import org.sonar.db.Database; -import org.sonar.server.platform.db.migration.step.DataChange; -import org.sonar.server.platform.db.migration.step.MassUpdate; - -public class DropSecurityHotSpotsInReviewStatus extends DataChange { - - private System2 system; - - public DropSecurityHotSpotsInReviewStatus(Database db, System2 system) { - super(db); - this.system = system; - } - - @Override - protected void execute(Context context) throws SQLException { - MassUpdate massUpdate = context.prepareMassUpdate(); - massUpdate.select("select id,kee from issues where status = 'IN_REVIEW'"); - massUpdate.update("update issues set status = 'TO_REVIEW' where id = ? and status = 'IN_REVIEW'"); - massUpdate.update("insert into issue_changes(issue_key, change_type, change_data, created_at, updated_at, issue_change_creation_date) " + - "VALUES(?, 'diff', 'status=IN_REVIEW|TO_REVIEW', ?, ?, ?)"); - massUpdate.execute((row, update, updateIndex) -> { - - if (updateIndex == 0) { - update.setLong(1, row.getLong(1)); - } else if (updateIndex == 1) { - long currentTime = system.now(); - update.setString(1, row.getString(2)) - .setLong(2, currentTime) - .setLong(3, currentTime) - .setLong(4, currentTime); - } - return true; - }); - } -} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v81/MigrateManualVulnerabilitiesToSecurityHotSpots.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v81/MigrateManualVulnerabilitiesToSecurityHotSpots.java deleted file mode 100644 index 8c3e16a33f5..00000000000 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v81/MigrateManualVulnerabilitiesToSecurityHotSpots.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2020 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.v81; - -import java.sql.SQLException; -import org.sonar.api.utils.System2; -import org.sonar.db.Database; -import org.sonar.server.platform.db.migration.step.DataChange; -import org.sonar.server.platform.db.migration.step.MassUpdate; - -import static org.sonar.api.issue.Issue.STATUS_TO_REVIEW; -import static org.sonar.api.rules.RuleType.VULNERABILITY; - -public class MigrateManualVulnerabilitiesToSecurityHotSpots extends DataChange { - private System2 system; - - public MigrateManualVulnerabilitiesToSecurityHotSpots(Database db, System2 system) { - super(db); - this.system = system; - } - - @Override - protected void execute(Context context) throws SQLException { - MassUpdate updateIssues = context.prepareMassUpdate(); - updateIssues.select("select id, kee, project_uuid, component_uuid from issues where from_hotspot = ? and issue_type = ?") - .setBoolean(1, true) - .setInt(2, 3); - updateIssues.update("update issues set issue_type = ?, status = ? where id = ? and from_hotspot = ? and issue_type = ?"); - updateIssues.update("insert into issue_changes(issue_key, change_type, change_data, created_at, updated_at, issue_change_creation_date) " + - "VALUES(?, ?, ?, ?, ?, ?)"); - - updateIssues.execute((row, update, updateIndex) -> { - if (updateIndex == 0) { - update.setInt(1, 4) - .setString(2, STATUS_TO_REVIEW) - .setLong(3, row.getLong(1)) - .setBoolean(4, true) - .setInt(5, VULNERABILITY.getDbConstant()); - } else if (updateIndex == 1) { - long currentTime = system.now(); - update.setString(1, row.getString(2)) - .setString(2, "diff") - .setString(3, "type=VULNERABILITY|SECURITY_HOTSPOT,status=OPEN|TO_REVIEW") - .setLong(4, currentTime) - .setLong(5, currentTime) - .setLong(6, currentTime); - } - return true; - }); - } -} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v81/RemoveNewsboxDismissHotspotsProperty.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v81/RemoveNewsboxDismissHotspotsProperty.java new file mode 100644 index 00000000000..d46e7ca508a --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v81/RemoveNewsboxDismissHotspotsProperty.java @@ -0,0 +1,38 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 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.v81; + +import java.sql.SQLException; +import org.sonar.db.Database; +import org.sonar.server.platform.db.migration.step.DataChange; + +public class RemoveNewsboxDismissHotspotsProperty extends DataChange { + + public RemoveNewsboxDismissHotspotsProperty(Database db) { + super(db); + } + + @Override + protected void execute(Context context) throws SQLException { + context.prepareUpsert("delete from user_properties where kee='newsbox.dismiss.hotspots'") + .execute() + .commit(); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v82/DbVersion82.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v82/DbVersion82.java new file mode 100644 index 00000000000..ccaa809ef80 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v82/DbVersion82.java @@ -0,0 +1,33 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 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.v82; + +import org.sonar.server.platform.db.migration.step.MigrationStepRegistry; +import org.sonar.server.platform.db.migration.version.DbVersion; + +public class DbVersion82 implements DbVersion { + @Override + public void addSteps(MigrationStepRegistry registry) { + registry + .add(3200, "Drop 'In Review' Security Hotspots status ", DropSecurityHotSpotsInReviewStatus.class) + .add(3201, "Migrate Manual Vulnerabilities to Security Hotspots ", MigrateManualVulnerabilitiesToSecurityHotSpots.class) + .add(3202, "Remove 'newsbox.dismiss.hotspots' user property", RemoveNewsboxDismissHotspotsProperty.class); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v82/DropSecurityHotSpotsInReviewStatus.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v82/DropSecurityHotSpotsInReviewStatus.java new file mode 100644 index 00000000000..44601a38c09 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v82/DropSecurityHotSpotsInReviewStatus.java @@ -0,0 +1,58 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 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.v82; + +import java.sql.SQLException; +import org.sonar.api.utils.System2; +import org.sonar.db.Database; +import org.sonar.server.platform.db.migration.step.DataChange; +import org.sonar.server.platform.db.migration.step.MassUpdate; + +public class DropSecurityHotSpotsInReviewStatus extends DataChange { + + private System2 system; + + public DropSecurityHotSpotsInReviewStatus(Database db, System2 system) { + super(db); + this.system = system; + } + + @Override + protected void execute(Context context) throws SQLException { + MassUpdate massUpdate = context.prepareMassUpdate(); + massUpdate.select("select id,kee from issues where status = 'IN_REVIEW'"); + massUpdate.update("update issues set status = 'TO_REVIEW' where id = ? and status = 'IN_REVIEW'"); + massUpdate.update("insert into issue_changes(issue_key, change_type, change_data, created_at, updated_at, issue_change_creation_date) " + + "VALUES(?, 'diff', 'status=IN_REVIEW|TO_REVIEW', ?, ?, ?)"); + massUpdate.execute((row, update, updateIndex) -> { + + if (updateIndex == 0) { + update.setLong(1, row.getLong(1)); + } else if (updateIndex == 1) { + long currentTime = system.now(); + update.setString(1, row.getString(2)) + .setLong(2, currentTime) + .setLong(3, currentTime) + .setLong(4, currentTime); + } + return true; + }); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v82/MigrateManualVulnerabilitiesToSecurityHotSpots.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v82/MigrateManualVulnerabilitiesToSecurityHotSpots.java new file mode 100644 index 00000000000..a170484888e --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v82/MigrateManualVulnerabilitiesToSecurityHotSpots.java @@ -0,0 +1,68 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 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.v82; + +import java.sql.SQLException; +import org.sonar.api.utils.System2; +import org.sonar.db.Database; +import org.sonar.server.platform.db.migration.step.DataChange; +import org.sonar.server.platform.db.migration.step.MassUpdate; + +import static org.sonar.api.issue.Issue.STATUS_TO_REVIEW; +import static org.sonar.api.rules.RuleType.VULNERABILITY; + +public class MigrateManualVulnerabilitiesToSecurityHotSpots extends DataChange { + private System2 system; + + public MigrateManualVulnerabilitiesToSecurityHotSpots(Database db, System2 system) { + super(db); + this.system = system; + } + + @Override + protected void execute(Context context) throws SQLException { + MassUpdate updateIssues = context.prepareMassUpdate(); + updateIssues.select("select id, kee, project_uuid, component_uuid from issues where from_hotspot = ? and issue_type = ?") + .setBoolean(1, true) + .setInt(2, 3); + updateIssues.update("update issues set issue_type = ?, status = ? where id = ? and from_hotspot = ? and issue_type = ?"); + updateIssues.update("insert into issue_changes(issue_key, change_type, change_data, created_at, updated_at, issue_change_creation_date) " + + "VALUES(?, ?, ?, ?, ?, ?)"); + + updateIssues.execute((row, update, updateIndex) -> { + if (updateIndex == 0) { + update.setInt(1, 4) + .setString(2, STATUS_TO_REVIEW) + .setLong(3, row.getLong(1)) + .setBoolean(4, true) + .setInt(5, VULNERABILITY.getDbConstant()); + } else if (updateIndex == 1) { + long currentTime = system.now(); + update.setString(1, row.getString(2)) + .setString(2, "diff") + .setString(3, "type=VULNERABILITY|SECURITY_HOTSPOT,status=OPEN|TO_REVIEW") + .setLong(4, currentTime) + .setLong(5, currentTime) + .setLong(6, currentTime); + } + return true; + }); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v82/RemoveNewsboxDismissHotspotsProperty.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v82/RemoveNewsboxDismissHotspotsProperty.java new file mode 100644 index 00000000000..1acb60826a5 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v82/RemoveNewsboxDismissHotspotsProperty.java @@ -0,0 +1,38 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 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.v82; + +import java.sql.SQLException; +import org.sonar.db.Database; +import org.sonar.server.platform.db.migration.step.DataChange; + +public class RemoveNewsboxDismissHotspotsProperty extends DataChange { + + public RemoveNewsboxDismissHotspotsProperty(Database db) { + super(db); + } + + @Override + protected void execute(Context context) throws SQLException { + context.prepareUpsert("delete from user_properties where kee='newsbox.dismiss.hotspots'") + .execute() + .commit(); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/MigrationConfigurationModuleTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/MigrationConfigurationModuleTest.java index 615d0ebd933..17f0012f50f 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/MigrationConfigurationModuleTest.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/MigrationConfigurationModuleTest.java @@ -37,7 +37,7 @@ public class MigrationConfigurationModuleTest { assertThat(container.getPicoContainer().getComponentAdapters()) .hasSize(COMPONENTS_IN_EMPTY_COMPONENT_CONTAINER // DbVersion classes - + 3 + + 4 // Others + 4); } diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v81/DbVersion81Test.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v81/DbVersion81Test.java index 1bbfa86ae55..46c2f39dfd8 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v81/DbVersion81Test.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v81/DbVersion81Test.java @@ -36,7 +36,7 @@ public class DbVersion81Test { @Test public void verify_migration_count() { - verifyMigrationCount(underTest, 16); + verifyMigrationCount(underTest, 14); } } diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v81/DropSecurityHotSpotsInReviewStatusTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v81/DropSecurityHotSpotsInReviewStatusTest.java deleted file mode 100644 index 33272ea586a..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v81/DropSecurityHotSpotsInReviewStatusTest.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2020 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.v81; - -import java.sql.SQLException; -import java.util.List; -import java.util.Map; -import java.util.function.Function; -import java.util.stream.Collectors; -import java.util.stream.IntStream; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.sonar.api.utils.System2; -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.api.issue.Issue.STATUSES; - -public class DropSecurityHotSpotsInReviewStatusTest { - - private final static String ISSUES_TABLE_NAME = "issues"; - private final static int NUMBER_OF_ISSUES_IN_REVIEW = 3; - - @Rule - public CoreDbTester db = CoreDbTester.createForSchema(DropSecurityHotSpotsInReviewStatusTest.class, "schema.sql"); - @Rule - public ExpectedException expectedException = ExpectedException.none(); - - private System2 system2 = System2.INSTANCE; - - private DataChange underTest = new DropSecurityHotSpotsInReviewStatus(db.database(), system2); - - @Test - public void should_change_IN_REVIEW_statuses_only() throws SQLException { - - Map statuses = IntStream.range(0, STATUSES.size()) - .boxed() - .collect(Collectors.toMap(Function.identity(), STATUSES::get)); - - statuses.forEach(this::insertIssue); - - int startIndex = STATUSES.size(); - int endIndex = startIndex + NUMBER_OF_ISSUES_IN_REVIEW; - IntStream.range(startIndex, endIndex).forEach(value -> insertIssue(value, "IN_REVIEW")); - - underTest.execute(); - - IntStream.range(startIndex, endIndex).forEach(this::assertIssueChanged); - - statuses.forEach(this::assertIssueNotChanged); - - // should not fail if executed twice - underTest.execute(); - } - - @Test - public void should_not_fail_if_no_issues() throws SQLException { - underTest.execute(); - assertThat(db.countRowsOfTable("issues")).isEqualTo(0); - } - - private void assertIssueChanged(int issueId) { - List> row = db.select(String.format("select status from issues where kee = '%s'", "issue-key-" + issueId)); - assertThat(row).hasSize(1); - assertThat(row.get(0).get("STATUS")) - .isEqualTo("TO_REVIEW"); - - List> changelogRows = db.select(String.format("select change_type, change_data, created_at, updated_at, issue_change_creation_date" + - " from issue_changes where issue_key = '%s'", "issue-key-" + issueId)); - assertThat(changelogRows).hasSize(1); - - Map changelogRow = changelogRows.get(0); - assertThat(changelogRow.get("CHANGE_TYPE")).isEqualTo("diff"); - assertThat(changelogRow.get("CHANGE_DATA")).isEqualTo("status=IN_REVIEW|TO_REVIEW"); - - assertThat(changelogRow.get("CREATED_AT")).isNotNull(); - assertThat(changelogRow.get("UPDATED_AT")).isNotNull(); - assertThat(changelogRow.get("ISSUE_CHANGE_CREATION_DATE")).isNotNull(); - } - - private void assertIssueNotChanged(int issueId, String expectedStatus) { - List> row = db.select(String.format("select status from issues where kee = '%s'", "issue-key-" + issueId)); - assertThat(row).hasSize(1); - assertThat(row.get(0).get("STATUS")) - .isEqualTo(expectedStatus); - - List> changelogRows = db.select(String.format("select change_type, change_data, created_at, updated_at, issue_change_creation_date" + - " from issue_changes where issue_key = '%s'", "issue-key-" + issueId)); - assertThat(changelogRows).isEmpty(); - } - - private void insertIssue(int issueId, String status) { - db.executeInsert(ISSUES_TABLE_NAME, - "kee", "issue-key-" + issueId, - "status", status, - "manual_severity", false); - } - -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v81/MigrateManualVulnerabilitiesToSecurityHotSpotsTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v81/MigrateManualVulnerabilitiesToSecurityHotSpotsTest.java deleted file mode 100644 index 975e3eaa3a1..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v81/MigrateManualVulnerabilitiesToSecurityHotSpotsTest.java +++ /dev/null @@ -1,140 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2020 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.v81; - -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.Random; -import java.util.stream.Collectors; -import java.util.stream.IntStream; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.sonar.api.utils.System2; -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.api.rules.RuleType.BUG; -import static org.sonar.api.rules.RuleType.CODE_SMELL; -import static org.sonar.api.rules.RuleType.SECURITY_HOTSPOT; -import static org.sonar.api.rules.RuleType.VULNERABILITY; - -public class MigrateManualVulnerabilitiesToSecurityHotSpotsTest { - - private final static String ISSUES_TABLE_NAME = "issues"; - private final static int TOTAL_NUMBER_OF_ISSUES = 9; - - @Rule - public CoreDbTester db = CoreDbTester.createForSchema(MigrateManualVulnerabilitiesToSecurityHotSpotsTest.class, "schema.sql"); - @Rule - public ExpectedException expectedException = ExpectedException.none(); - - private System2 system2 = System2.INSTANCE; - - private DataChange underTest = new MigrateManualVulnerabilitiesToSecurityHotSpots(db.database(), system2); - - @Test - public void should_migrate_manual_vulnerabilities_only() throws SQLException { - Random random = new Random(); - List range = IntStream.range(0, TOTAL_NUMBER_OF_ISSUES).boxed() - .collect(Collectors.toCollection(ArrayList::new)); - Collections.shuffle(range); - - insertIssue(range.get(0), CODE_SMELL.getDbConstant(), random.nextBoolean()); - insertIssue(range.get(1), BUG.getDbConstant(), random.nextBoolean()); - insertIssue(range.get(2), VULNERABILITY.getDbConstant(), false); - insertIssue(range.get(3), SECURITY_HOTSPOT.getDbConstant(), random.nextBoolean()); - insertIssue(range.get(4), -1, random.nextBoolean()); - - insertIssue(range.get(5), VULNERABILITY.getDbConstant(), true); - insertIssue(range.get(6), VULNERABILITY.getDbConstant(), true); - insertIssue(range.get(7), VULNERABILITY.getDbConstant(), true); - insertIssue(range.get(8), VULNERABILITY.getDbConstant(), true); - - underTest.execute(); - - assertIssueNotChanged(range.get(0), CODE_SMELL.getDbConstant()); - assertIssueNotChanged(range.get(1), BUG.getDbConstant()); - assertIssueNotChanged(range.get(2), VULNERABILITY.getDbConstant()); - assertIssueNotChanged(range.get(3), SECURITY_HOTSPOT.getDbConstant()); - assertIssueNotChanged(range.get(4), -1); - - assertIssueChanged(range.get(5)); - assertIssueChanged(range.get(6)); - assertIssueChanged(range.get(7)); - assertIssueChanged(range.get(8)); - - // should not fail if executed twice - underTest.execute(); - } - - @Test - public void should_not_fail_if_no_issues() throws SQLException { - underTest.execute(); - assertThat(db.countRowsOfTable("issues")).isEqualTo(0); - } - - private void assertIssueChanged(int issueId) { - List> row = db.select(String.format("select status from issues where kee = '%s'", "issue-key-" + issueId)); - assertThat(row).hasSize(1); - assertThat(row.get(0).get("STATUS")) - .isEqualTo("TO_REVIEW"); - - List> changelogRows = db.select(String.format("select change_type, change_data, created_at, updated_at, issue_change_creation_date" + - " from issue_changes where issue_key = '%s'", "issue-key-" + issueId)); - assertThat(changelogRows).hasSize(1); - - Map changelogRow = changelogRows.get(0); - assertThat(changelogRow.get("CHANGE_TYPE")).isEqualTo("diff"); - assertThat(changelogRow.get("CHANGE_DATA")).isEqualTo("type=VULNERABILITY|SECURITY_HOTSPOT,status=OPEN|TO_REVIEW"); - - assertThat(changelogRow.get("CREATED_AT")).isNotNull(); - assertThat(changelogRow.get("UPDATED_AT")).isNotNull(); - assertThat(changelogRow.get("ISSUE_CHANGE_CREATION_DATE")).isNotNull(); - } - - private void assertIssueNotChanged(int issueId, int expectedType) { - List> row = db.select(String.format("select issue_type, status from issues where kee = '%s'", "issue-key-" + issueId)); - assertThat(row).hasSize(1); - - Map issueData = row.get(0); - assertThat(issueData.get("STATUS")) - .isNull(); - assertThat(issueData.get("ISSUE_TYPE")) - .isEqualTo(expectedType); - - List> changelogRows = db.select(String.format("select change_type, change_data, created_at, updated_at, issue_change_creation_date" + - " from issue_changes where issue_key = '%s'", "issue-key-" + issueId)); - assertThat(changelogRows).isEmpty(); - } - - private void insertIssue(int issueId, int issueType, boolean fromHotspot) { - db.executeInsert(ISSUES_TABLE_NAME, - "kee", "issue-key-" + issueId, - "issue_type", issueType, - "from_hotspot", fromHotspot, - "manual_severity", false); - } - -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v81/RemoveNewsboxDismissHotspotsPropertyTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v81/RemoveNewsboxDismissHotspotsPropertyTest.java new file mode 100644 index 00000000000..284e5c308c6 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v81/RemoveNewsboxDismissHotspotsPropertyTest.java @@ -0,0 +1,93 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 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.v81; + +import java.sql.SQLException; +import java.time.Instant; +import java.util.Random; +import java.util.UUID; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.sonar.db.CoreDbTester; + +import static java.lang.String.format; +import static org.junit.Assert.assertEquals; + +public class RemoveNewsboxDismissHotspotsPropertyTest { + + private static final String USER_PROPERTIES_TABLE_NAME = "user_properties"; + private static final int TOTAL_NUMBER_OF_HOTSPOTS_DISMISS_USER_PROPERTIES = 10; + + @Rule + public CoreDbTester dbTester = CoreDbTester.createForSchema(RemoveNewsboxDismissHotspotsPropertyTest.class, "schema.sql"); + + @Rule + public ExpectedException expectedException = ExpectedException.none(); + + private Random random = new Random(); + + private RemoveNewsboxDismissHotspotsProperty underTest = new RemoveNewsboxDismissHotspotsProperty(dbTester.database()); + + @Before + public void setup() { + insertUserProperty("some-user-uuid", "some-property", random.nextBoolean()); + + for (int i = 1; i <= TOTAL_NUMBER_OF_HOTSPOTS_DISMISS_USER_PROPERTIES; i++) { + insertUserProperty(format("user-uuid-%s", i), "newsbox.dismiss.hotspots", random.nextBoolean()); + } + + int propertiesCount = dbTester.countRowsOfTable(USER_PROPERTIES_TABLE_NAME); + assertEquals(TOTAL_NUMBER_OF_HOTSPOTS_DISMISS_USER_PROPERTIES + 1, propertiesCount); + } + + @Test + public void remove_newsbox_dismiss_hotspot_property() throws SQLException { + underTest.execute(); + + verifyResult(); + } + + @Test + public void migration_is_re_entrant() throws SQLException { + underTest.execute(); + underTest.execute(); + + verifyResult(); + } + + private void verifyResult() { + int hotspotDismissPropertiesCount = dbTester.countSql("select count(uuid) from user_properties where kee = 'newsbox.dismiss.hotspots'"); + assertEquals(0, hotspotDismissPropertiesCount); + int otherPropertiesCount = dbTester.countSql("select count(uuid) from user_properties where kee != 'newsbox.dismiss.hotspots'"); + assertEquals(1, otherPropertiesCount); + } + + private void insertUserProperty(String userUuid, String key, boolean value) { + dbTester.executeInsert(USER_PROPERTIES_TABLE_NAME, + "uuid", UUID.randomUUID().toString(), + "kee", key, + "user_uuid", userUuid, + "text_value", value, + "created_at", Instant.now().toEpochMilli(), + "updated_at", Instant.now().toEpochMilli()); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v82/DbVersion82Test.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v82/DbVersion82Test.java new file mode 100644 index 00000000000..0776c6275e6 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v82/DbVersion82Test.java @@ -0,0 +1,42 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 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.v82; + +import org.junit.Test; +import org.sonar.server.platform.db.migration.version.DbVersion; + +import static org.sonar.server.platform.db.migration.version.DbVersionTestUtils.verifyMigrationCount; +import static org.sonar.server.platform.db.migration.version.DbVersionTestUtils.verifyMinimumMigrationNumber; + +public class DbVersion82Test { + + private DbVersion underTest = new DbVersion82(); + + @Test + public void migrationNumber_starts_at_3000() { + verifyMinimumMigrationNumber(underTest, 3200); + } + + @Test + public void verify_migration_count() { + verifyMigrationCount(underTest, 3); + } + +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v82/DropSecurityHotSpotsInReviewStatusTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v82/DropSecurityHotSpotsInReviewStatusTest.java new file mode 100644 index 00000000000..9ede542c649 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v82/DropSecurityHotSpotsInReviewStatusTest.java @@ -0,0 +1,118 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 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.v82; + +import java.sql.SQLException; +import java.util.List; +import java.util.Map; +import java.util.function.Function; +import java.util.stream.Collectors; +import java.util.stream.IntStream; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.sonar.api.utils.System2; +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.api.issue.Issue.STATUSES; + +public class DropSecurityHotSpotsInReviewStatusTest { + + private final static String ISSUES_TABLE_NAME = "issues"; + private final static int NUMBER_OF_ISSUES_IN_REVIEW = 3; + + @Rule + public CoreDbTester db = CoreDbTester.createForSchema(DropSecurityHotSpotsInReviewStatusTest.class, "schema.sql"); + @Rule + public ExpectedException expectedException = ExpectedException.none(); + + private System2 system2 = System2.INSTANCE; + + private DataChange underTest = new DropSecurityHotSpotsInReviewStatus(db.database(), system2); + + @Test + public void should_change_IN_REVIEW_statuses_only() throws SQLException { + + Map statuses = IntStream.range(0, STATUSES.size()) + .boxed() + .collect(Collectors.toMap(Function.identity(), STATUSES::get)); + + statuses.forEach(this::insertIssue); + + int startIndex = STATUSES.size(); + int endIndex = startIndex + NUMBER_OF_ISSUES_IN_REVIEW; + IntStream.range(startIndex, endIndex).forEach(value -> insertIssue(value, "IN_REVIEW")); + + underTest.execute(); + + IntStream.range(startIndex, endIndex).forEach(this::assertIssueChanged); + + statuses.forEach(this::assertIssueNotChanged); + + // should not fail if executed twice + underTest.execute(); + } + + @Test + public void should_not_fail_if_no_issues() throws SQLException { + underTest.execute(); + assertThat(db.countRowsOfTable("issues")).isEqualTo(0); + } + + private void assertIssueChanged(int issueId) { + List> row = db.select(String.format("select status from issues where kee = '%s'", "issue-key-" + issueId)); + assertThat(row).hasSize(1); + assertThat(row.get(0).get("STATUS")) + .isEqualTo("TO_REVIEW"); + + List> changelogRows = db.select(String.format("select change_type, change_data, created_at, updated_at, issue_change_creation_date" + + " from issue_changes where issue_key = '%s'", "issue-key-" + issueId)); + assertThat(changelogRows).hasSize(1); + + Map changelogRow = changelogRows.get(0); + assertThat(changelogRow.get("CHANGE_TYPE")).isEqualTo("diff"); + assertThat(changelogRow.get("CHANGE_DATA")).isEqualTo("status=IN_REVIEW|TO_REVIEW"); + + assertThat(changelogRow.get("CREATED_AT")).isNotNull(); + assertThat(changelogRow.get("UPDATED_AT")).isNotNull(); + assertThat(changelogRow.get("ISSUE_CHANGE_CREATION_DATE")).isNotNull(); + } + + private void assertIssueNotChanged(int issueId, String expectedStatus) { + List> row = db.select(String.format("select status from issues where kee = '%s'", "issue-key-" + issueId)); + assertThat(row).hasSize(1); + assertThat(row.get(0).get("STATUS")) + .isEqualTo(expectedStatus); + + List> changelogRows = db.select(String.format("select change_type, change_data, created_at, updated_at, issue_change_creation_date" + + " from issue_changes where issue_key = '%s'", "issue-key-" + issueId)); + assertThat(changelogRows).isEmpty(); + } + + private void insertIssue(int issueId, String status) { + db.executeInsert(ISSUES_TABLE_NAME, + "kee", "issue-key-" + issueId, + "status", status, + "manual_severity", false); + } + +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v82/MigrateManualVulnerabilitiesToSecurityHotSpotsTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v82/MigrateManualVulnerabilitiesToSecurityHotSpotsTest.java new file mode 100644 index 00000000000..50cba019e05 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v82/MigrateManualVulnerabilitiesToSecurityHotSpotsTest.java @@ -0,0 +1,140 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 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.v82; + +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Random; +import java.util.stream.Collectors; +import java.util.stream.IntStream; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.sonar.api.utils.System2; +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.api.rules.RuleType.BUG; +import static org.sonar.api.rules.RuleType.CODE_SMELL; +import static org.sonar.api.rules.RuleType.SECURITY_HOTSPOT; +import static org.sonar.api.rules.RuleType.VULNERABILITY; + +public class MigrateManualVulnerabilitiesToSecurityHotSpotsTest { + + private final static String ISSUES_TABLE_NAME = "issues"; + private final static int TOTAL_NUMBER_OF_ISSUES = 9; + + @Rule + public CoreDbTester db = CoreDbTester.createForSchema(MigrateManualVulnerabilitiesToSecurityHotSpotsTest.class, "schema.sql"); + @Rule + public ExpectedException expectedException = ExpectedException.none(); + + private System2 system2 = System2.INSTANCE; + + private DataChange underTest = new MigrateManualVulnerabilitiesToSecurityHotSpots(db.database(), system2); + + @Test + public void should_migrate_manual_vulnerabilities_only() throws SQLException { + Random random = new Random(); + List range = IntStream.range(0, TOTAL_NUMBER_OF_ISSUES).boxed() + .collect(Collectors.toCollection(ArrayList::new)); + Collections.shuffle(range); + + insertIssue(range.get(0), CODE_SMELL.getDbConstant(), random.nextBoolean()); + insertIssue(range.get(1), BUG.getDbConstant(), random.nextBoolean()); + insertIssue(range.get(2), VULNERABILITY.getDbConstant(), false); + insertIssue(range.get(3), SECURITY_HOTSPOT.getDbConstant(), random.nextBoolean()); + insertIssue(range.get(4), -1, random.nextBoolean()); + + insertIssue(range.get(5), VULNERABILITY.getDbConstant(), true); + insertIssue(range.get(6), VULNERABILITY.getDbConstant(), true); + insertIssue(range.get(7), VULNERABILITY.getDbConstant(), true); + insertIssue(range.get(8), VULNERABILITY.getDbConstant(), true); + + underTest.execute(); + + assertIssueNotChanged(range.get(0), CODE_SMELL.getDbConstant()); + assertIssueNotChanged(range.get(1), BUG.getDbConstant()); + assertIssueNotChanged(range.get(2), VULNERABILITY.getDbConstant()); + assertIssueNotChanged(range.get(3), SECURITY_HOTSPOT.getDbConstant()); + assertIssueNotChanged(range.get(4), -1); + + assertIssueChanged(range.get(5)); + assertIssueChanged(range.get(6)); + assertIssueChanged(range.get(7)); + assertIssueChanged(range.get(8)); + + // should not fail if executed twice + underTest.execute(); + } + + @Test + public void should_not_fail_if_no_issues() throws SQLException { + underTest.execute(); + assertThat(db.countRowsOfTable("issues")).isEqualTo(0); + } + + private void assertIssueChanged(int issueId) { + List> row = db.select(String.format("select status from issues where kee = '%s'", "issue-key-" + issueId)); + assertThat(row).hasSize(1); + assertThat(row.get(0).get("STATUS")) + .isEqualTo("TO_REVIEW"); + + List> changelogRows = db.select(String.format("select change_type, change_data, created_at, updated_at, issue_change_creation_date" + + " from issue_changes where issue_key = '%s'", "issue-key-" + issueId)); + assertThat(changelogRows).hasSize(1); + + Map changelogRow = changelogRows.get(0); + assertThat(changelogRow.get("CHANGE_TYPE")).isEqualTo("diff"); + assertThat(changelogRow.get("CHANGE_DATA")).isEqualTo("type=VULNERABILITY|SECURITY_HOTSPOT,status=OPEN|TO_REVIEW"); + + assertThat(changelogRow.get("CREATED_AT")).isNotNull(); + assertThat(changelogRow.get("UPDATED_AT")).isNotNull(); + assertThat(changelogRow.get("ISSUE_CHANGE_CREATION_DATE")).isNotNull(); + } + + private void assertIssueNotChanged(int issueId, int expectedType) { + List> row = db.select(String.format("select issue_type, status from issues where kee = '%s'", "issue-key-" + issueId)); + assertThat(row).hasSize(1); + + Map issueData = row.get(0); + assertThat(issueData.get("STATUS")) + .isNull(); + assertThat(issueData.get("ISSUE_TYPE")) + .isEqualTo(expectedType); + + List> changelogRows = db.select(String.format("select change_type, change_data, created_at, updated_at, issue_change_creation_date" + + " from issue_changes where issue_key = '%s'", "issue-key-" + issueId)); + assertThat(changelogRows).isEmpty(); + } + + private void insertIssue(int issueId, int issueType, boolean fromHotspot) { + db.executeInsert(ISSUES_TABLE_NAME, + "kee", "issue-key-" + issueId, + "issue_type", issueType, + "from_hotspot", fromHotspot, + "manual_severity", false); + } + +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v82/RemoveNewsboxDismissHotspotsPropertyTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v82/RemoveNewsboxDismissHotspotsPropertyTest.java new file mode 100644 index 00000000000..c087c18c646 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v82/RemoveNewsboxDismissHotspotsPropertyTest.java @@ -0,0 +1,93 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 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.v82; + +import java.sql.SQLException; +import java.time.Instant; +import java.util.Random; +import java.util.UUID; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.sonar.db.CoreDbTester; + +import static java.lang.String.format; +import static org.junit.Assert.assertEquals; + +public class RemoveNewsboxDismissHotspotsPropertyTest { + + private static final String USER_PROPERTIES_TABLE_NAME = "user_properties"; + private static final int TOTAL_NUMBER_OF_HOTSPOTS_DISMISS_USER_PROPERTIES = 10; + + @Rule + public CoreDbTester dbTester = CoreDbTester.createForSchema(RemoveNewsboxDismissHotspotsPropertyTest.class, "schema.sql"); + + @Rule + public ExpectedException expectedException = ExpectedException.none(); + + private Random random = new Random(); + + private RemoveNewsboxDismissHotspotsProperty underTest = new RemoveNewsboxDismissHotspotsProperty(dbTester.database()); + + @Before + public void setup() { + insertUserProperty("some-user-uuid", "some-property", random.nextBoolean()); + + for (int i = 1; i <= TOTAL_NUMBER_OF_HOTSPOTS_DISMISS_USER_PROPERTIES; i++) { + insertUserProperty(format("user-uuid-%s", i), "newsbox.dismiss.hotspots", random.nextBoolean()); + } + + int propertiesCount = dbTester.countRowsOfTable(USER_PROPERTIES_TABLE_NAME); + assertEquals(TOTAL_NUMBER_OF_HOTSPOTS_DISMISS_USER_PROPERTIES + 1, propertiesCount); + } + + @Test + public void remove_newsbox_dismiss_hotspot_property() throws SQLException { + underTest.execute(); + + verifyResult(); + } + + @Test + public void migration_is_re_entrant() throws SQLException { + underTest.execute(); + underTest.execute(); + + verifyResult(); + } + + private void verifyResult() { + int hotspotDismissPropertiesCount = dbTester.countSql("select count(uuid) from user_properties where kee = 'newsbox.dismiss.hotspots'"); + assertEquals(0, hotspotDismissPropertiesCount); + int otherPropertiesCount = dbTester.countSql("select count(uuid) from user_properties where kee != 'newsbox.dismiss.hotspots'"); + assertEquals(1, otherPropertiesCount); + } + + private void insertUserProperty(String userUuid, String key, boolean value) { + dbTester.executeInsert(USER_PROPERTIES_TABLE_NAME, + "uuid", UUID.randomUUID().toString(), + "kee", key, + "user_uuid", userUuid, + "text_value", value, + "created_at", Instant.now().toEpochMilli(), + "updated_at", Instant.now().toEpochMilli()); + } +} diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v81/DropSecurityHotSpotsInReviewStatusTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v81/DropSecurityHotSpotsInReviewStatusTest/schema.sql deleted file mode 100644 index d8f2d4316ab..00000000000 --- a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v81/DropSecurityHotSpotsInReviewStatusTest/schema.sql +++ /dev/null @@ -1,54 +0,0 @@ -CREATE TABLE "ISSUES"( - "ID" BIGINT NOT NULL AUTO_INCREMENT (1,1), - "KEE" VARCHAR(50) NOT NULL, - "RULE_ID" INTEGER, - "SEVERITY" VARCHAR(10), - "MANUAL_SEVERITY" BOOLEAN NOT NULL, - "MESSAGE" VARCHAR(4000), - "LINE" INTEGER, - "GAP" DOUBLE, - "STATUS" VARCHAR(20), - "RESOLUTION" VARCHAR(20), - "CHECKSUM" VARCHAR(1000), - "REPORTER" VARCHAR(255), - "ASSIGNEE" VARCHAR(255), - "AUTHOR_LOGIN" VARCHAR(255), - "ACTION_PLAN_KEY" VARCHAR(50), - "ISSUE_ATTRIBUTES" VARCHAR(4000), - "EFFORT" INTEGER, - "CREATED_AT" BIGINT, - "UPDATED_AT" BIGINT, - "ISSUE_CREATION_DATE" BIGINT, - "ISSUE_UPDATE_DATE" BIGINT, - "ISSUE_CLOSE_DATE" BIGINT, - "TAGS" VARCHAR(4000), - "COMPONENT_UUID" VARCHAR(50), - "PROJECT_UUID" VARCHAR(50), - "LOCATIONS" BLOB, - "ISSUE_TYPE" TINYINT, - "FROM_HOTSPOT" BOOLEAN -); -ALTER TABLE "ISSUES" ADD CONSTRAINT "PK_ISSUES" PRIMARY KEY("ID"); -CREATE INDEX "ISSUES_ASSIGNEE" ON "ISSUES"("ASSIGNEE"); -CREATE INDEX "ISSUES_COMPONENT_UUID" ON "ISSUES"("COMPONENT_UUID"); -CREATE INDEX "ISSUES_CREATION_DATE" ON "ISSUES"("ISSUE_CREATION_DATE"); -CREATE UNIQUE INDEX "ISSUES_KEE" ON "ISSUES"("KEE"); -CREATE INDEX "ISSUES_PROJECT_UUID" ON "ISSUES"("PROJECT_UUID"); -CREATE INDEX "ISSUES_RESOLUTION" ON "ISSUES"("RESOLUTION"); -CREATE INDEX "ISSUES_RULE_ID" ON "ISSUES"("RULE_ID"); -CREATE INDEX "ISSUES_UPDATED_AT" ON "ISSUES"("UPDATED_AT"); - -CREATE TABLE "ISSUE_CHANGES"( - "ID" BIGINT NOT NULL AUTO_INCREMENT (1,1), - "KEE" VARCHAR(50), - "ISSUE_KEY" VARCHAR(50) NOT NULL, - "USER_LOGIN" VARCHAR(255), - "CHANGE_TYPE" VARCHAR(20), - "CHANGE_DATA" CLOB(2147483647), - "CREATED_AT" BIGINT, - "UPDATED_AT" BIGINT, - "ISSUE_CHANGE_CREATION_DATE" BIGINT -); -ALTER TABLE "ISSUE_CHANGES" ADD CONSTRAINT "PK_ISSUE_CHANGES" PRIMARY KEY("ID"); -CREATE INDEX "ISSUE_CHANGES_ISSUE_KEY" ON "ISSUE_CHANGES"("ISSUE_KEY"); -CREATE INDEX "ISSUE_CHANGES_KEE" ON "ISSUE_CHANGES"("KEE"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v81/MigrateManualVulnerabilitiesToSecurityHotSpotsTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v81/MigrateManualVulnerabilitiesToSecurityHotSpotsTest/schema.sql deleted file mode 100644 index d8f2d4316ab..00000000000 --- a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v81/MigrateManualVulnerabilitiesToSecurityHotSpotsTest/schema.sql +++ /dev/null @@ -1,54 +0,0 @@ -CREATE TABLE "ISSUES"( - "ID" BIGINT NOT NULL AUTO_INCREMENT (1,1), - "KEE" VARCHAR(50) NOT NULL, - "RULE_ID" INTEGER, - "SEVERITY" VARCHAR(10), - "MANUAL_SEVERITY" BOOLEAN NOT NULL, - "MESSAGE" VARCHAR(4000), - "LINE" INTEGER, - "GAP" DOUBLE, - "STATUS" VARCHAR(20), - "RESOLUTION" VARCHAR(20), - "CHECKSUM" VARCHAR(1000), - "REPORTER" VARCHAR(255), - "ASSIGNEE" VARCHAR(255), - "AUTHOR_LOGIN" VARCHAR(255), - "ACTION_PLAN_KEY" VARCHAR(50), - "ISSUE_ATTRIBUTES" VARCHAR(4000), - "EFFORT" INTEGER, - "CREATED_AT" BIGINT, - "UPDATED_AT" BIGINT, - "ISSUE_CREATION_DATE" BIGINT, - "ISSUE_UPDATE_DATE" BIGINT, - "ISSUE_CLOSE_DATE" BIGINT, - "TAGS" VARCHAR(4000), - "COMPONENT_UUID" VARCHAR(50), - "PROJECT_UUID" VARCHAR(50), - "LOCATIONS" BLOB, - "ISSUE_TYPE" TINYINT, - "FROM_HOTSPOT" BOOLEAN -); -ALTER TABLE "ISSUES" ADD CONSTRAINT "PK_ISSUES" PRIMARY KEY("ID"); -CREATE INDEX "ISSUES_ASSIGNEE" ON "ISSUES"("ASSIGNEE"); -CREATE INDEX "ISSUES_COMPONENT_UUID" ON "ISSUES"("COMPONENT_UUID"); -CREATE INDEX "ISSUES_CREATION_DATE" ON "ISSUES"("ISSUE_CREATION_DATE"); -CREATE UNIQUE INDEX "ISSUES_KEE" ON "ISSUES"("KEE"); -CREATE INDEX "ISSUES_PROJECT_UUID" ON "ISSUES"("PROJECT_UUID"); -CREATE INDEX "ISSUES_RESOLUTION" ON "ISSUES"("RESOLUTION"); -CREATE INDEX "ISSUES_RULE_ID" ON "ISSUES"("RULE_ID"); -CREATE INDEX "ISSUES_UPDATED_AT" ON "ISSUES"("UPDATED_AT"); - -CREATE TABLE "ISSUE_CHANGES"( - "ID" BIGINT NOT NULL AUTO_INCREMENT (1,1), - "KEE" VARCHAR(50), - "ISSUE_KEY" VARCHAR(50) NOT NULL, - "USER_LOGIN" VARCHAR(255), - "CHANGE_TYPE" VARCHAR(20), - "CHANGE_DATA" CLOB(2147483647), - "CREATED_AT" BIGINT, - "UPDATED_AT" BIGINT, - "ISSUE_CHANGE_CREATION_DATE" BIGINT -); -ALTER TABLE "ISSUE_CHANGES" ADD CONSTRAINT "PK_ISSUE_CHANGES" PRIMARY KEY("ID"); -CREATE INDEX "ISSUE_CHANGES_ISSUE_KEY" ON "ISSUE_CHANGES"("ISSUE_KEY"); -CREATE INDEX "ISSUE_CHANGES_KEE" ON "ISSUE_CHANGES"("KEE"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v81/RemoveNewsboxDismissHotspotsPropertyTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v81/RemoveNewsboxDismissHotspotsPropertyTest/schema.sql new file mode 100644 index 00000000000..8ce5b03c093 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v81/RemoveNewsboxDismissHotspotsPropertyTest/schema.sql @@ -0,0 +1,11 @@ +CREATE TABLE "USER_PROPERTIES" ( + "UUID" VARCHAR(40) NOT NULL, + "USER_UUID" VARCHAR(255) NOT NULL, + "KEE" VARCHAR(100) NOT NULL, + "TEXT_VALUE" VARCHAR(4000) NOT NULL, + "CREATED_AT" BIGINT NOT NULL, + "UPDATED_AT" BIGINT NOT NULL, + + CONSTRAINT "PK_USER_PROPERTIES" PRIMARY KEY ("UUID") +); +CREATE UNIQUE INDEX "USER_PROPERTIES_USER_UUID_KEE" ON "USER_PROPERTIES" ("USER_UUID", "KEE"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v82/DropSecurityHotSpotsInReviewStatusTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v82/DropSecurityHotSpotsInReviewStatusTest/schema.sql new file mode 100644 index 00000000000..d8f2d4316ab --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v82/DropSecurityHotSpotsInReviewStatusTest/schema.sql @@ -0,0 +1,54 @@ +CREATE TABLE "ISSUES"( + "ID" BIGINT NOT NULL AUTO_INCREMENT (1,1), + "KEE" VARCHAR(50) NOT NULL, + "RULE_ID" INTEGER, + "SEVERITY" VARCHAR(10), + "MANUAL_SEVERITY" BOOLEAN NOT NULL, + "MESSAGE" VARCHAR(4000), + "LINE" INTEGER, + "GAP" DOUBLE, + "STATUS" VARCHAR(20), + "RESOLUTION" VARCHAR(20), + "CHECKSUM" VARCHAR(1000), + "REPORTER" VARCHAR(255), + "ASSIGNEE" VARCHAR(255), + "AUTHOR_LOGIN" VARCHAR(255), + "ACTION_PLAN_KEY" VARCHAR(50), + "ISSUE_ATTRIBUTES" VARCHAR(4000), + "EFFORT" INTEGER, + "CREATED_AT" BIGINT, + "UPDATED_AT" BIGINT, + "ISSUE_CREATION_DATE" BIGINT, + "ISSUE_UPDATE_DATE" BIGINT, + "ISSUE_CLOSE_DATE" BIGINT, + "TAGS" VARCHAR(4000), + "COMPONENT_UUID" VARCHAR(50), + "PROJECT_UUID" VARCHAR(50), + "LOCATIONS" BLOB, + "ISSUE_TYPE" TINYINT, + "FROM_HOTSPOT" BOOLEAN +); +ALTER TABLE "ISSUES" ADD CONSTRAINT "PK_ISSUES" PRIMARY KEY("ID"); +CREATE INDEX "ISSUES_ASSIGNEE" ON "ISSUES"("ASSIGNEE"); +CREATE INDEX "ISSUES_COMPONENT_UUID" ON "ISSUES"("COMPONENT_UUID"); +CREATE INDEX "ISSUES_CREATION_DATE" ON "ISSUES"("ISSUE_CREATION_DATE"); +CREATE UNIQUE INDEX "ISSUES_KEE" ON "ISSUES"("KEE"); +CREATE INDEX "ISSUES_PROJECT_UUID" ON "ISSUES"("PROJECT_UUID"); +CREATE INDEX "ISSUES_RESOLUTION" ON "ISSUES"("RESOLUTION"); +CREATE INDEX "ISSUES_RULE_ID" ON "ISSUES"("RULE_ID"); +CREATE INDEX "ISSUES_UPDATED_AT" ON "ISSUES"("UPDATED_AT"); + +CREATE TABLE "ISSUE_CHANGES"( + "ID" BIGINT NOT NULL AUTO_INCREMENT (1,1), + "KEE" VARCHAR(50), + "ISSUE_KEY" VARCHAR(50) NOT NULL, + "USER_LOGIN" VARCHAR(255), + "CHANGE_TYPE" VARCHAR(20), + "CHANGE_DATA" CLOB(2147483647), + "CREATED_AT" BIGINT, + "UPDATED_AT" BIGINT, + "ISSUE_CHANGE_CREATION_DATE" BIGINT +); +ALTER TABLE "ISSUE_CHANGES" ADD CONSTRAINT "PK_ISSUE_CHANGES" PRIMARY KEY("ID"); +CREATE INDEX "ISSUE_CHANGES_ISSUE_KEY" ON "ISSUE_CHANGES"("ISSUE_KEY"); +CREATE INDEX "ISSUE_CHANGES_KEE" ON "ISSUE_CHANGES"("KEE"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v82/MigrateManualVulnerabilitiesToSecurityHotSpotsTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v82/MigrateManualVulnerabilitiesToSecurityHotSpotsTest/schema.sql new file mode 100644 index 00000000000..d8f2d4316ab --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v82/MigrateManualVulnerabilitiesToSecurityHotSpotsTest/schema.sql @@ -0,0 +1,54 @@ +CREATE TABLE "ISSUES"( + "ID" BIGINT NOT NULL AUTO_INCREMENT (1,1), + "KEE" VARCHAR(50) NOT NULL, + "RULE_ID" INTEGER, + "SEVERITY" VARCHAR(10), + "MANUAL_SEVERITY" BOOLEAN NOT NULL, + "MESSAGE" VARCHAR(4000), + "LINE" INTEGER, + "GAP" DOUBLE, + "STATUS" VARCHAR(20), + "RESOLUTION" VARCHAR(20), + "CHECKSUM" VARCHAR(1000), + "REPORTER" VARCHAR(255), + "ASSIGNEE" VARCHAR(255), + "AUTHOR_LOGIN" VARCHAR(255), + "ACTION_PLAN_KEY" VARCHAR(50), + "ISSUE_ATTRIBUTES" VARCHAR(4000), + "EFFORT" INTEGER, + "CREATED_AT" BIGINT, + "UPDATED_AT" BIGINT, + "ISSUE_CREATION_DATE" BIGINT, + "ISSUE_UPDATE_DATE" BIGINT, + "ISSUE_CLOSE_DATE" BIGINT, + "TAGS" VARCHAR(4000), + "COMPONENT_UUID" VARCHAR(50), + "PROJECT_UUID" VARCHAR(50), + "LOCATIONS" BLOB, + "ISSUE_TYPE" TINYINT, + "FROM_HOTSPOT" BOOLEAN +); +ALTER TABLE "ISSUES" ADD CONSTRAINT "PK_ISSUES" PRIMARY KEY("ID"); +CREATE INDEX "ISSUES_ASSIGNEE" ON "ISSUES"("ASSIGNEE"); +CREATE INDEX "ISSUES_COMPONENT_UUID" ON "ISSUES"("COMPONENT_UUID"); +CREATE INDEX "ISSUES_CREATION_DATE" ON "ISSUES"("ISSUE_CREATION_DATE"); +CREATE UNIQUE INDEX "ISSUES_KEE" ON "ISSUES"("KEE"); +CREATE INDEX "ISSUES_PROJECT_UUID" ON "ISSUES"("PROJECT_UUID"); +CREATE INDEX "ISSUES_RESOLUTION" ON "ISSUES"("RESOLUTION"); +CREATE INDEX "ISSUES_RULE_ID" ON "ISSUES"("RULE_ID"); +CREATE INDEX "ISSUES_UPDATED_AT" ON "ISSUES"("UPDATED_AT"); + +CREATE TABLE "ISSUE_CHANGES"( + "ID" BIGINT NOT NULL AUTO_INCREMENT (1,1), + "KEE" VARCHAR(50), + "ISSUE_KEY" VARCHAR(50) NOT NULL, + "USER_LOGIN" VARCHAR(255), + "CHANGE_TYPE" VARCHAR(20), + "CHANGE_DATA" CLOB(2147483647), + "CREATED_AT" BIGINT, + "UPDATED_AT" BIGINT, + "ISSUE_CHANGE_CREATION_DATE" BIGINT +); +ALTER TABLE "ISSUE_CHANGES" ADD CONSTRAINT "PK_ISSUE_CHANGES" PRIMARY KEY("ID"); +CREATE INDEX "ISSUE_CHANGES_ISSUE_KEY" ON "ISSUE_CHANGES"("ISSUE_KEY"); +CREATE INDEX "ISSUE_CHANGES_KEE" ON "ISSUE_CHANGES"("KEE"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v82/RemoveNewsboxDismissHotspotsPropertyTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v82/RemoveNewsboxDismissHotspotsPropertyTest/schema.sql new file mode 100644 index 00000000000..8ce5b03c093 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v82/RemoveNewsboxDismissHotspotsPropertyTest/schema.sql @@ -0,0 +1,11 @@ +CREATE TABLE "USER_PROPERTIES" ( + "UUID" VARCHAR(40) NOT NULL, + "USER_UUID" VARCHAR(255) NOT NULL, + "KEE" VARCHAR(100) NOT NULL, + "TEXT_VALUE" VARCHAR(4000) NOT NULL, + "CREATED_AT" BIGINT NOT NULL, + "UPDATED_AT" BIGINT NOT NULL, + + CONSTRAINT "PK_USER_PROPERTIES" PRIMARY KEY ("UUID") +); +CREATE UNIQUE INDEX "USER_PROPERTIES_USER_UUID_KEE" ON "USER_PROPERTIES" ("USER_UUID", "KEE"); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/user/ws/SetSettingAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/user/ws/SetSettingAction.java index 8acbcf797b1..4b208c7ca2d 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/user/ws/SetSettingAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/user/ws/SetSettingAction.java @@ -57,7 +57,7 @@ public class SetSettingAction implements UsersWsAction { .setRequired(true) .setMaximumLength(100) .setDescription("Setting key") - .setPossibleValues("notifications.optOut", UserUpdater.NOTIFICATIONS_READ_DATE, "newsbox.dismiss.hotspots"); + .setPossibleValues("notifications.optOut", UserUpdater.NOTIFICATIONS_READ_DATE); action.createParam(PARAM_VALUE) .setRequired(true) diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/SetSettingActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/SetSettingActionTest.java index 96030c5eaa2..2dd0af8b413 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/SetSettingActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/SetSettingActionTest.java @@ -91,17 +91,11 @@ public class SetSettingActionTest { .setParam("value", "true") .execute(); - ws.newRequest() - .setParam("key", "newsbox.dismiss.hotspots") - .setParam("value", "true") - .execute(); - assertThat(db.getDbClient().userPropertiesDao().selectByUser(db.getSession(), user)) .extracting(UserPropertyDto::getKey, UserPropertyDto::getValue) .containsExactlyInAnyOrder( tuple("notifications.readDate", "1234"), - tuple("notifications.optOut", "true"), - tuple("newsbox.dismiss.hotspots", "true")); + tuple("notifications.optOut", "true")); } @Test @@ -131,8 +125,7 @@ public class SetSettingActionTest { assertThat(definition.param("key").possibleValues()).containsExactlyInAnyOrder( "notifications.optOut", - "notifications.readDate", - "newsbox.dismiss.hotspots"); + "notifications.readDate"); } } -- cgit v1.2.3