You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

LogMessageIfSonarScimEnabledPresentPropertyTest.java 3.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2023 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. package org.sonar.server.platform.db.migration.version.v100;
  21. import java.sql.SQLException;
  22. import org.junit.Before;
  23. import org.junit.Rule;
  24. import org.junit.Test;
  25. import org.slf4j.event.Level;
  26. import org.sonar.api.testfixtures.log.LogTester;
  27. import org.sonar.db.CoreDbTester;
  28. import org.sonar.server.platform.db.migration.step.DataChange;
  29. import static org.assertj.core.api.Assertions.assertThat;
  30. import static org.sonar.server.platform.db.migration.version.v100.LogMessageIfSonarScimEnabledPresentProperty.SONAR_SCIM_ENABLED;
  31. public class LogMessageIfSonarScimEnabledPresentPropertyTest {
  32. @Rule
  33. public LogTester logger = new LogTester();
  34. @Rule
  35. public final CoreDbTester db = CoreDbTester.createForSchema(LogMessageIfSonarScimEnabledPresentPropertyTest.class, "schema.sql");
  36. private final DataChange underTest = new LogMessageIfSonarScimEnabledPresentProperty(db.database());
  37. @Before
  38. public void before() {
  39. logger.clear();
  40. }
  41. @Test
  42. public void migration_should_log_message_when_scim_property() throws SQLException {
  43. db.executeInsert("properties ",
  44. "prop_key", "sonar.scim.enabled",
  45. "is_empty", false,
  46. "text_value", "true",
  47. "created_at", 100_000L,
  48. "uuid", "some-random-uuid"
  49. );
  50. underTest.execute();
  51. assertThat(logger.logs(Level.WARN))
  52. .hasSize(1)
  53. .containsExactly("'" + SONAR_SCIM_ENABLED + "' property is defined but not read anymore. Please read the upgrade notes" +
  54. " for the instruction to upgrade. User provisioning is deactivated until reactivated from the SonarQube" +
  55. " Administration Interface (\"General->Authentication\"). "
  56. + "See documentation: https://docs.sonarsource.com/sonarqube/10.1/instance-administration/authentication/saml/scim/overview/");
  57. }
  58. @Test
  59. public void migration_should_not_log_if_no_scim_property() throws SQLException {
  60. underTest.execute();
  61. assertThat(logger.logs(Level.WARN)).isEmpty();
  62. }
  63. @Test
  64. public void migration_is_reentrant() throws SQLException {
  65. db.executeInsert("properties ",
  66. "prop_key", "sonar.scim.enabled",
  67. "is_empty", false,
  68. "text_value", "true",
  69. "created_at", 100_000L,
  70. "uuid", "some-random-uuid"
  71. );
  72. underTest.execute();
  73. underTest.execute();
  74. assertThat(logger.logs(Level.WARN)).hasSize(2);
  75. }
  76. }