From 69a3c36db9f206297ce606f7d1f0e6c48e9d69e6 Mon Sep 17 00:00:00 2001 From: Soby Chacko Date: Wed, 23 Jun 2021 17:48:19 -0400 Subject: [PATCH] GH-1094: Fix JAAS initializer tests on CI Before running the JAAS initilizer security tests, remove reference to JAAS related config files created previously in other tests. This is done through clearing a system property (java.security.auth.login.config) in the tests. Without clearing this property, these tests run into a race condition. Fixes https://github.com/spring-cloud/spring-cloud-stream-binder-kafka/issues/1094 --- .../bootstrap/KafkaStreamsBinderBootstrapTest.java | 9 +++++++-- .../KafkaBinderJaasInitializerListenerTest.java | 12 ++++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/spring-cloud-stream-binder-kafka-streams/src/test/java/org/springframework/cloud/stream/binder/kafka/streams/bootstrap/KafkaStreamsBinderBootstrapTest.java b/spring-cloud-stream-binder-kafka-streams/src/test/java/org/springframework/cloud/stream/binder/kafka/streams/bootstrap/KafkaStreamsBinderBootstrapTest.java index 3a6813579..1427c2b09 100644 --- a/spring-cloud-stream-binder-kafka-streams/src/test/java/org/springframework/cloud/stream/binder/kafka/streams/bootstrap/KafkaStreamsBinderBootstrapTest.java +++ b/spring-cloud-stream-binder-kafka-streams/src/test/java/org/springframework/cloud/stream/binder/kafka/streams/bootstrap/KafkaStreamsBinderBootstrapTest.java @@ -18,11 +18,12 @@ package org.springframework.cloud.stream.binder.kafka.streams.bootstrap; import javax.security.auth.login.AppConfigurationEntry; +import org.apache.kafka.common.security.JaasUtils; import org.apache.kafka.streams.kstream.GlobalKTable; import org.apache.kafka.streams.kstream.KStream; import org.apache.kafka.streams.kstream.KTable; +import org.junit.Before; import org.junit.ClassRule; -import org.junit.Ignore; import org.junit.Test; import org.springframework.boot.WebApplicationType; @@ -44,6 +45,11 @@ public class KafkaStreamsBinderBootstrapTest { @ClassRule public static EmbeddedKafkaRule embeddedKafka = new EmbeddedKafkaRule(1, true, 10); + @Before + public void before() { + System.clearProperty(JaasUtils.JAVA_LOGIN_CONFIG_PARAM); + } + @Test public void testKStreamBinderWithCustomEnvironmentCanStart() { ConfigurableApplicationContext applicationContext = new SpringApplicationBuilder( @@ -93,7 +99,6 @@ public class KafkaStreamsBinderBootstrapTest { } @Test - @Ignore("Need to investigate why this test fails on CI") public void testKafkaStreamsBinderJaasInitialization() { ConfigurableApplicationContext applicationContext = new SpringApplicationBuilder( SimpleKafkaStreamsApplication.class).web(WebApplicationType.NONE).run( diff --git a/spring-cloud-stream-binder-kafka/src/test/java/org/springframework/cloud/stream/binder/kafka/KafkaBinderJaasInitializerListenerTest.java b/spring-cloud-stream-binder-kafka/src/test/java/org/springframework/cloud/stream/binder/kafka/KafkaBinderJaasInitializerListenerTest.java index c6d63d9b1..d0ebd76be 100644 --- a/spring-cloud-stream-binder-kafka/src/test/java/org/springframework/cloud/stream/binder/kafka/KafkaBinderJaasInitializerListenerTest.java +++ b/spring-cloud-stream-binder-kafka/src/test/java/org/springframework/cloud/stream/binder/kafka/KafkaBinderJaasInitializerListenerTest.java @@ -19,9 +19,12 @@ package org.springframework.cloud.stream.binder.kafka; import javax.security.auth.login.AppConfigurationEntry; import com.sun.security.auth.login.ConfigFile; +import org.apache.kafka.common.security.JaasUtils; import org.junit.AfterClass; +import org.junit.Before; import org.junit.BeforeClass; import org.junit.ClassRule; +import org.junit.Test; import org.springframework.boot.autoconfigure.kafka.KafkaAutoConfiguration; import org.springframework.boot.test.context.runner.ApplicationContextRunner; @@ -57,7 +60,12 @@ public class KafkaBinderJaasInitializerListenerTest { System.clearProperty(KAFKA_BROKERS_PROPERTY); } -// @Test + @Before + public void before() { + System.clearProperty(JaasUtils.JAVA_LOGIN_CONFIG_PARAM); + } + + @Test public void testConfigurationParsedCorrectlyWithKafkaClientAndDefaultControlFlag() throws Exception { ConfigFile configFile = new ConfigFile( @@ -86,7 +94,7 @@ public class KafkaBinderJaasInitializerListenerTest { }); } -// @Test + @Test public void testConfigurationParsedCorrectlyWithKafkaClientAndNonDefaultControlFlag() throws Exception { ConfigFile configFile = new ConfigFile(