aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-auth-ldap
diff options
context:
space:
mode:
authorDejan Milisavljevic <130993898+dejan-milisavljevic-sonarsource@users.noreply.github.com>2024-02-26 10:27:42 +0100
committersonartech <sonartech@sonarsource.com>2024-02-26 20:02:36 +0000
commit990606438b5fb472915f244a5ea68386abb63c1d (patch)
tree6f5c0dcbc0781da0921ab8670f09c7d252644842 /server/sonar-auth-ldap
parente2e4ca5594431f7ed596d7da93dfc21656c02ddb (diff)
downloadsonarqube-990606438b5fb472915f244a5ea68386abb63c1d.tar.gz
sonarqube-990606438b5fb472915f244a5ea68386abb63c1d.zip
SONAR-21643 Make rule compatible with JUnit5 (#10700)
Diffstat (limited to 'server/sonar-auth-ldap')
-rw-r--r--server/sonar-auth-ldap/build.gradle8
-rw-r--r--server/sonar-auth-ldap/src/it/java/org/sonar/auth/ldap/DefaultLdapAuthenticatorIT.java29
-rw-r--r--server/sonar-auth-ldap/src/it/java/org/sonar/auth/ldap/server/LdapServer.java17
3 files changed, 38 insertions, 16 deletions
diff --git a/server/sonar-auth-ldap/build.gradle b/server/sonar-auth-ldap/build.gradle
index ff21ffe4a90..77692decb3e 100644
--- a/server/sonar-auth-ldap/build.gradle
+++ b/server/sonar-auth-ldap/build.gradle
@@ -17,7 +17,15 @@ dependencies {
testImplementation 'com.tngtech.java:junit-dataprovider'
testImplementation 'junit:junit'
testImplementation 'org.assertj:assertj-core'
+ testImplementation 'org.junit.jupiter:junit-jupiter-api'
testImplementation 'org.mockito:mockito-core'
testImplementation project(":sonar-testing-ldap")
+ testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
+ testRuntimeOnly 'org.junit.vintage:junit-vintage-engine'
+}
+
+test {
+ // Enabling the JUnit Platform (see https://github.com/junit-team/junit5-samples/tree/master/junit5-migration-gradle)
+ useJUnitPlatform()
}
diff --git a/server/sonar-auth-ldap/src/it/java/org/sonar/auth/ldap/DefaultLdapAuthenticatorIT.java b/server/sonar-auth-ldap/src/it/java/org/sonar/auth/ldap/DefaultLdapAuthenticatorIT.java
index 1bcd99e9377..a0c2f5a5d6f 100644
--- a/server/sonar-auth-ldap/src/it/java/org/sonar/auth/ldap/DefaultLdapAuthenticatorIT.java
+++ b/server/sonar-auth-ldap/src/it/java/org/sonar/auth/ldap/DefaultLdapAuthenticatorIT.java
@@ -19,8 +19,8 @@
*/
package org.sonar.auth.ldap;
-import org.junit.ClassRule;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.server.http.HttpRequest;
import org.sonar.auth.ldap.server.LdapServer;
@@ -28,23 +28,24 @@ import org.sonar.auth.ldap.server.LdapServer;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
-public class DefaultLdapAuthenticatorIT {
+class DefaultLdapAuthenticatorIT {
/**
* A reference to the original ldif file
*/
- public static final String USERS_EXAMPLE_ORG_LDIF = "/users.example.org.ldif";
+ private static final String USERS_EXAMPLE_ORG_LDIF = "/users.example.org.ldif";
/**
* A reference to an additional ldif file.
*/
- public static final String USERS_INFOSUPPORT_COM_LDIF = "/users.infosupport.com.ldif";
- @ClassRule
- public static LdapServer exampleServer = new LdapServer(USERS_EXAMPLE_ORG_LDIF);
- @ClassRule
- public static LdapServer infosupportServer = new LdapServer(USERS_INFOSUPPORT_COM_LDIF, "infosupport.com", "dc=infosupport,dc=com");
+ private static final String USERS_INFOSUPPORT_COM_LDIF = "/users.infosupport.com.ldif";
+ @RegisterExtension
+ private static final LdapServer exampleServer = new LdapServer(USERS_EXAMPLE_ORG_LDIF);
+ @RegisterExtension
+ private static final LdapServer infosupportServer = new LdapServer(USERS_INFOSUPPORT_COM_LDIF, "infosupport.com", "dc=infosupport," +
+ "dc=com");
@Test
- public void testNoConnection() {
+ void testNoConnection() {
exampleServer.disableAnonymousAccess();
try {
LdapSettingsManager settingsManager = new LdapSettingsManager(
@@ -58,7 +59,7 @@ public class DefaultLdapAuthenticatorIT {
}
@Test
- public void testSimple() {
+ void testSimple() {
LdapSettingsManager settingsManager = new LdapSettingsManager(
LdapSettingsFactory.generateAuthenticationSettings(exampleServer, null, LdapContextFactory.AUTH_METHOD_SIMPLE).asConfig());
DefaultLdapAuthenticator authenticator = new DefaultLdapAuthenticator(settingsManager.getContextFactories(), settingsManager.getUserMappings());
@@ -82,7 +83,7 @@ public class DefaultLdapAuthenticatorIT {
}
@Test
- public void testSimpleMultiLdap() {
+ void testSimpleMultiLdap() {
LdapSettingsManager settingsManager = new LdapSettingsManager(
LdapSettingsFactory.generateAuthenticationSettings(exampleServer, infosupportServer, LdapContextFactory.AUTH_METHOD_SIMPLE).asConfig());
DefaultLdapAuthenticator authenticator = new DefaultLdapAuthenticator(settingsManager.getContextFactories(), settingsManager.getUserMappings());
@@ -115,7 +116,7 @@ public class DefaultLdapAuthenticatorIT {
}
@Test
- public void testSasl() {
+ void testSasl() {
MapSettings mapSettings = LdapSettingsFactory.generateAuthenticationSettings(exampleServer, null, LdapContextFactory.AUTH_METHOD_DIGEST_MD5);
//set sasl QoP properties as per https://docs.oracle.com/javase/jndi/tutorial/ldap/security/digest.html
mapSettings.setProperty("ldap.saslQop", "auth")
@@ -140,7 +141,7 @@ public class DefaultLdapAuthenticatorIT {
}
@Test
- public void testSaslMultipleLdap() {
+ void testSaslMultipleLdap() {
LdapSettingsManager settingsManager = new LdapSettingsManager(
LdapSettingsFactory.generateAuthenticationSettings(exampleServer, infosupportServer, LdapContextFactory.AUTH_METHOD_CRAM_MD5).asConfig());
DefaultLdapAuthenticator authenticator = new DefaultLdapAuthenticator(settingsManager.getContextFactories(), settingsManager.getUserMappings());
diff --git a/server/sonar-auth-ldap/src/it/java/org/sonar/auth/ldap/server/LdapServer.java b/server/sonar-auth-ldap/src/it/java/org/sonar/auth/ldap/server/LdapServer.java
index a259c24ba96..9b19e956899 100644
--- a/server/sonar-auth-ldap/src/it/java/org/sonar/auth/ldap/server/LdapServer.java
+++ b/server/sonar-auth-ldap/src/it/java/org/sonar/auth/ldap/server/LdapServer.java
@@ -19,10 +19,13 @@
*/
package org.sonar.auth.ldap.server;
+import org.junit.jupiter.api.extension.AfterAllCallback;
+import org.junit.jupiter.api.extension.BeforeAllCallback;
+import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.rules.ExternalResource;
import org.sonar.ldap.ApacheDS;
-public class LdapServer extends ExternalResource {
+public class LdapServer extends ExternalResource implements BeforeAllCallback, AfterAllCallback {
private ApacheDS server;
private String ldif;
@@ -40,12 +43,22 @@ public class LdapServer extends ExternalResource {
}
@Override
- protected void before() throws Throwable {
+ public void beforeAll(ExtensionContext extensionContext) throws Exception {
+ before();
+ }
+
+ @Override
+ protected void before() throws Exception {
server = ApacheDS.start(realm, baseDn);
server.importLdif(LdapServer.class.getResourceAsStream(ldif));
}
@Override
+ public void afterAll(ExtensionContext extensionContext) throws Exception {
+ after();
+ }
+
+ @Override
protected void after() {
try {
server.stop();