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.

BitbucketSettingsTest.java 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2021 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.auth.bitbucket;
  21. import org.junit.Test;
  22. import org.sonar.api.config.internal.MapSettings;
  23. import static org.assertj.core.api.Assertions.assertThat;
  24. public class BitbucketSettingsTest {
  25. private MapSettings settings = new MapSettings();
  26. private BitbucketSettings underTest = new BitbucketSettings(settings.asConfig());
  27. @Test
  28. public void is_enabled() {
  29. settings.setProperty("sonar.auth.bitbucket.clientId.secured", "id");
  30. settings.setProperty("sonar.auth.bitbucket.clientSecret.secured", "secret");
  31. settings.setProperty("sonar.auth.bitbucket.enabled", true);
  32. assertThat(underTest.isEnabled()).isTrue();
  33. settings.setProperty("sonar.auth.bitbucket.enabled", false);
  34. assertThat(underTest.isEnabled()).isFalse();
  35. }
  36. @Test
  37. public void is_enabled_always_return_false_when_client_id_is_null() {
  38. settings.setProperty("sonar.auth.bitbucket.enabled", true);
  39. settings.setProperty("sonar.auth.bitbucket.clientId.secured", (String) null);
  40. settings.setProperty("sonar.auth.bitbucket.clientSecret.secured", "secret");
  41. assertThat(underTest.isEnabled()).isFalse();
  42. }
  43. @Test
  44. public void is_enabled_always_return_false_when_client_secret_is_null() {
  45. settings.setProperty("sonar.auth.bitbucket.enabled", true);
  46. settings.setProperty("sonar.auth.bitbucket.clientId.secured", "id");
  47. settings.setProperty("sonar.auth.bitbucket.clientSecret.secured", (String) null);
  48. assertThat(underTest.isEnabled()).isFalse();
  49. }
  50. @Test
  51. public void return_client_id() {
  52. settings.setProperty("sonar.auth.bitbucket.clientId.secured", "id");
  53. assertThat(underTest.clientId()).isEqualTo("id");
  54. }
  55. @Test
  56. public void return_client_secret() {
  57. settings.setProperty("sonar.auth.bitbucket.clientSecret.secured", "secret");
  58. assertThat(underTest.clientSecret()).isEqualTo("secret");
  59. }
  60. @Test
  61. public void allow_users_to_sign_up() {
  62. settings.setProperty("sonar.auth.bitbucket.allowUsersToSignUp", "true");
  63. assertThat(underTest.allowUsersToSignUp()).isTrue();
  64. settings.setProperty("sonar.auth.bitbucket.allowUsersToSignUp", "false");
  65. assertThat(underTest.allowUsersToSignUp()).isFalse();
  66. }
  67. @Test
  68. public void default_apiUrl() {
  69. assertThat(underTest.apiURL()).isEqualTo("https://api.bitbucket.org/");
  70. }
  71. @Test
  72. public void default_webUrl() {
  73. assertThat(underTest.webURL()).isEqualTo("https://bitbucket.org/");
  74. }
  75. @Test
  76. public void definitions() {
  77. assertThat(BitbucketSettings.definitions()).hasSize(5);
  78. }
  79. }