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.

GitLabSettingsTest.java 3.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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.gitlab;
  21. import org.junit.Before;
  22. import org.junit.Test;
  23. import org.sonar.api.config.PropertyDefinitions;
  24. import org.sonar.api.config.internal.MapSettings;
  25. import org.sonar.api.utils.System2;
  26. import static org.assertj.core.api.Assertions.assertThat;
  27. import static org.sonar.auth.gitlab.GitLabSettings.GITLAB_AUTH_ALLOW_USERS_TO_SIGNUP;
  28. import static org.sonar.auth.gitlab.GitLabSettings.GITLAB_AUTH_APPLICATION_ID;
  29. import static org.sonar.auth.gitlab.GitLabSettings.GITLAB_AUTH_ENABLED;
  30. import static org.sonar.auth.gitlab.GitLabSettings.GITLAB_AUTH_SECRET;
  31. import static org.sonar.auth.gitlab.GitLabSettings.GITLAB_AUTH_SYNC_USER_GROUPS;
  32. import static org.sonar.auth.gitlab.GitLabSettings.GITLAB_AUTH_URL;
  33. public class GitLabSettingsTest {
  34. private MapSettings settings;
  35. private GitLabSettings config;
  36. @Before
  37. public void prepare() {
  38. settings = new MapSettings(new PropertyDefinitions(System2.INSTANCE, GitLabSettings.definitions()));
  39. config = new GitLabSettings(settings.asConfig());
  40. }
  41. @Test
  42. public void test_settings() {
  43. assertThat(config.url()).isEqualTo("https://gitlab.com");
  44. settings.setProperty(GITLAB_AUTH_URL, "https://gitlab.com/api/");
  45. assertThat(config.url()).isEqualTo("https://gitlab.com/api");
  46. settings.setProperty(GITLAB_AUTH_URL, "https://gitlab.com/api");
  47. assertThat(config.url()).isEqualTo("https://gitlab.com/api");
  48. assertThat(config.isEnabled()).isFalse();
  49. settings.setProperty(GITLAB_AUTH_ENABLED, "true");
  50. assertThat(config.isEnabled()).isFalse();
  51. settings.setProperty(GITLAB_AUTH_APPLICATION_ID, "1234");
  52. assertThat(config.isEnabled()).isFalse();
  53. settings.setProperty(GITLAB_AUTH_SECRET, "5678");
  54. assertThat(config.isEnabled()).isTrue();
  55. assertThat(config.applicationId()).isEqualTo("1234");
  56. assertThat(config.secret()).isEqualTo("5678");
  57. assertThat(config.allowUsersToSignUp()).isTrue();
  58. settings.setProperty(GITLAB_AUTH_ALLOW_USERS_TO_SIGNUP, "false");
  59. assertThat(config.allowUsersToSignUp()).isFalse();
  60. assertThat(config.syncUserGroups()).isFalse();
  61. settings.setProperty(GITLAB_AUTH_SYNC_USER_GROUPS, true);
  62. assertThat(config.syncUserGroups()).isTrue();
  63. }
  64. }