Search in sources :

Example 1 with SecurityRealm

use of org.sonar.api.security.SecurityRealm in project sonarqube by SonarSource.

the class SonarQubeMonitorTest method get_realm.

@Test
public void get_realm() throws Exception {
    SecurityRealm realm = mock(SecurityRealm.class);
    when(realm.getName()).thenReturn("LDAP");
    when(securityRealmFactory.getRealm()).thenReturn(realm);
    Map<String, Object> attributes = underTest.attributes();
    assertThat(attributes).containsEntry("External User Authentication", "LDAP");
}
Also used : SecurityRealm(org.sonar.api.security.SecurityRealm) Test(org.junit.Test)

Example 2 with SecurityRealm

use of org.sonar.api.security.SecurityRealm in project sonarqube by SonarSource.

the class SecurityRealmFactoryTest method ignore_startup_failure.

@Test
public void ignore_startup_failure() {
    SecurityRealm realm = spy(new AlwaysFailsRealm());
    settings.setProperty(CoreProperties.CORE_AUTHENTICATOR_REALM, realm.getName());
    settings.setProperty(CoreProperties.CORE_AUTHENTICATOR_IGNORE_STARTUP_FAILURE, true);
    new SecurityRealmFactory(settings, new SecurityRealm[] { realm }).start();
    verify(realm).init();
}
Also used : SecurityRealm(org.sonar.api.security.SecurityRealm) Test(org.junit.Test)

Example 3 with SecurityRealm

use of org.sonar.api.security.SecurityRealm in project sonarqube by SonarSource.

the class SecurityRealmFactoryTest method should_fail.

@Test
public void should_fail() {
    SecurityRealm realm = spy(new AlwaysFailsRealm());
    settings.setProperty(CoreProperties.CORE_AUTHENTICATOR_REALM, realm.getName());
    try {
        new SecurityRealmFactory(settings, new SecurityRealm[] { realm }).start();
        fail();
    } catch (SonarException e) {
        assertThat(e.getCause()).isInstanceOf(IllegalStateException.class);
        assertThat(e.getMessage()).contains("Security realm fails to start");
    }
}
Also used : SecurityRealm(org.sonar.api.security.SecurityRealm) SonarException(org.sonar.api.utils.SonarException) Test(org.junit.Test)

Example 4 with SecurityRealm

use of org.sonar.api.security.SecurityRealm in project sonarqube by SonarSource.

the class SecurityRealmFactoryTest method should_select_realm_and_start.

/**
   * Typical usage.
   */
@Test
public void should_select_realm_and_start() {
    SecurityRealm realm = spy(new FakeRealm());
    settings.setProperty(CoreProperties.CORE_AUTHENTICATOR_REALM, realm.getName());
    SecurityRealmFactory factory = new SecurityRealmFactory(settings, new SecurityRealm[] { realm });
    factory.start();
    assertThat(factory.getRealm()).isSameAs(realm);
    assertThat(factory.hasExternalAuthentication()).isTrue();
    verify(realm).init();
    factory.stop();
}
Also used : SecurityRealm(org.sonar.api.security.SecurityRealm) Test(org.junit.Test)

Example 5 with SecurityRealm

use of org.sonar.api.security.SecurityRealm in project sonarqube by SonarSource.

the class SecurityRealmFactoryTest method should_provide_compatibility_for_authenticator.

@Test
public void should_provide_compatibility_for_authenticator() {
    settings.setProperty(CoreProperties.CORE_AUTHENTICATOR_CLASS, FakeAuthenticator.class.getName());
    LoginPasswordAuthenticator authenticator = new FakeAuthenticator();
    SecurityRealmFactory factory = new SecurityRealmFactory(settings, new LoginPasswordAuthenticator[] { authenticator });
    SecurityRealm realm = factory.getRealm();
    assertThat(realm).isInstanceOf(CompatibilityRealm.class);
}
Also used : SecurityRealm(org.sonar.api.security.SecurityRealm) LoginPasswordAuthenticator(org.sonar.api.security.LoginPasswordAuthenticator) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)6 SecurityRealm (org.sonar.api.security.SecurityRealm)6 LoginPasswordAuthenticator (org.sonar.api.security.LoginPasswordAuthenticator)2 SonarException (org.sonar.api.utils.SonarException)1