3 * Copyright (C) 2009-2019 SonarSource SA
4 * mailto:info AT sonarsource DOT com
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.
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.
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.
20 package org.sonar.server.platform.monitoring.cluster;
22 import org.junit.Rule;
23 import org.junit.Test;
24 import org.sonar.api.impl.config.MapSettings;
25 import org.sonar.api.platform.Server;
26 import org.sonar.api.security.SecurityRealm;
27 import org.sonar.process.systeminfo.protobuf.ProtobufSystemInfo;
28 import org.sonar.server.authentication.IdentityProviderRepositoryRule;
29 import org.sonar.server.authentication.TestIdentityProvider;
30 import org.sonar.server.user.SecurityRealmFactory;
32 import static org.assertj.core.api.Assertions.assertThat;
33 import static org.mockito.Mockito.mock;
34 import static org.mockito.Mockito.when;
35 import static org.sonar.process.systeminfo.SystemInfoUtils.attribute;
36 import static org.sonar.server.platform.monitoring.SystemInfoTesting.assertThatAttributeIs;
38 public class GlobalSystemSectionTest {
41 public IdentityProviderRepositoryRule identityProviderRepository = new IdentityProviderRepositoryRule();
43 private MapSettings settings = new MapSettings();
44 private Server server = mock(Server.class);
45 private SecurityRealmFactory securityRealmFactory = mock(SecurityRealmFactory.class);
47 private GlobalSystemSection underTest = new GlobalSystemSection(settings.asConfig(),
48 server, securityRealmFactory, identityProviderRepository);
51 public void name_is_not_empty() {
52 assertThat(underTest.toProtobuf().getName()).isEqualTo("System");
56 public void get_realm() {
57 SecurityRealm realm = mock(SecurityRealm.class);
58 when(realm.getName()).thenReturn("LDAP");
59 when(securityRealmFactory.getRealm()).thenReturn(realm);
61 ProtobufSystemInfo.Section protobuf = underTest.toProtobuf();
62 assertThatAttributeIs(protobuf, "External User Authentication", "LDAP");
66 public void no_realm() {
67 when(securityRealmFactory.getRealm()).thenReturn(null);
69 ProtobufSystemInfo.Section protobuf = underTest.toProtobuf();
70 assertThat(attribute(protobuf, "External User Authentication")).isNull();
74 public void get_enabled_identity_providers() {
75 identityProviderRepository.addIdentityProvider(new TestIdentityProvider()
79 identityProviderRepository.addIdentityProvider(new TestIdentityProvider()
83 identityProviderRepository.addIdentityProvider(new TestIdentityProvider()
88 ProtobufSystemInfo.Section protobuf = underTest.toProtobuf();
89 assertThatAttributeIs(protobuf, "Accepted external identity providers", "Bitbucket, GitHub");
93 public void get_enabled_identity_providers_allowing_users_to_signup() {
94 identityProviderRepository.addIdentityProvider(new TestIdentityProvider()
98 .setAllowsUsersToSignUp(true));
99 identityProviderRepository.addIdentityProvider(new TestIdentityProvider()
101 .setName("Bitbucket")
103 .setAllowsUsersToSignUp(false));
104 identityProviderRepository.addIdentityProvider(new TestIdentityProvider()
108 .setAllowsUsersToSignUp(true));
110 ProtobufSystemInfo.Section protobuf = underTest.toProtobuf();
111 assertThatAttributeIs(protobuf, "External identity providers whose users are allowed to sign themselves up", "GitHub");