Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions extensions-contrib/cassandra-storage/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,6 @@
<scope>provided</scope>
</dependency>

<!-- Tests -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
20 changes: 15 additions & 5 deletions extensions-contrib/consul-extensions/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,21 @@
</properties>

<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.druid</groupId>
<artifactId>druid-server</artifactId>
Expand Down Expand Up @@ -112,11 +127,6 @@
</dependency>

<!-- Test dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
package org.apache.druid.consul.discovery;

import com.ecwid.consul.v1.ConsulClient;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

/**
* Tests for Consul client security validation, especially around basic auth over HTTP.
Expand All @@ -38,22 +38,22 @@ public void testBasicAuthOverHttpFailsFastByDefault()
// No TLS configured
.build();

IllegalStateException exception = Assert.assertThrows(
IllegalStateException exception = Assertions.assertThrows(
IllegalStateException.class,
() -> ConsulClients.create(config)
);

Assert.assertTrue(
"Exception should mention TLS not enabled",
exception.getMessage().contains("TLS is not enabled")
Assertions.assertTrue(
exception.getMessage().contains("TLS is not enabled"),
"Exception should mention TLS not enabled"
);
Assert.assertTrue(
"Exception should mention cleartext transmission",
exception.getMessage().contains("cleartext")
Assertions.assertTrue(
exception.getMessage().contains("cleartext"),
"Exception should mention cleartext transmission"
);
Assert.assertTrue(
"Exception should mention allowBasicAuthOverHttp flag",
exception.getMessage().contains("allowBasicAuthOverHttp")
Assertions.assertTrue(
exception.getMessage().contains("allowBasicAuthOverHttp"),
"Exception should mention allowBasicAuthOverHttp flag"
);
}

Expand All @@ -70,7 +70,7 @@ public void testBasicAuthOverHttpSucceedsWithExplicitFlag()

// Should not throw with the flag enabled
ConsulClient client = ConsulClients.create(config);
Assert.assertNotNull(client);
Assertions.assertNotNull(client);
}

@Test
Expand All @@ -84,14 +84,14 @@ public void testBasicAuthOverHttpFailsWhenExplicitlyDisabled()
// No TLS configured
.build();

IllegalStateException exception = Assert.assertThrows(
IllegalStateException exception = Assertions.assertThrows(
IllegalStateException.class,
() -> ConsulClients.create(config)
);

Assert.assertTrue(
"Exception should mention TLS not enabled",
exception.getMessage().contains("TLS is not enabled")
Assertions.assertTrue(
exception.getMessage().contains("TLS is not enabled"),
"Exception should mention TLS not enabled"
);
}

Expand All @@ -105,7 +105,7 @@ public void testNoBasicAuthOverHttpSucceeds()

// Should succeed without basic auth even without TLS
ConsulClient client = ConsulClients.create(config);
Assert.assertNotNull(client);
Assertions.assertNotNull(client);
}

@Test
Expand All @@ -119,7 +119,7 @@ public void testBasicAuthUserWithoutPasswordDoesNotTriggerValidation()

// Should succeed - validation only applies when both user and password are set
ConsulClient client = ConsulClients.create(config);
Assert.assertNotNull(client);
Assertions.assertNotNull(client);
}

@Test
Expand All @@ -133,7 +133,7 @@ public void testBasicAuthPasswordWithoutUserDoesNotTriggerValidation()

// Should succeed - validation only applies when both user and password are set
ConsulClient client = ConsulClients.create(config);
Assert.assertNotNull(client);
Assertions.assertNotNull(client);
}

@Test
Expand All @@ -143,9 +143,9 @@ public void testAllowBasicAuthOverHttpDefaultsToFalse()
.servicePrefix("druid")
.build();

Assert.assertFalse(
"allowBasicAuthOverHttp should default to false",
config.getAuth().getAllowBasicAuthOverHttp()
Assertions.assertFalse(
config.getAuth().getAllowBasicAuthOverHttp(),
"allowBasicAuthOverHttp should default to false"
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.druid.jackson.DefaultObjectMapper;
import org.joda.time.Duration;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertThrows;

public class ConsulDiscoveryConfigTest
{
Expand Down Expand Up @@ -80,7 +82,7 @@ public void testAllowBasicAuthOverHttpDefaultsToFalse() throws Exception
+ " \"service\": { \"servicePrefix\": \"druid\" }\n"
+ "}\n"
);
Assert.assertFalse(config.getAuth().getAllowBasicAuthOverHttp());
Assertions.assertFalse(config.getAuth().getAllowBasicAuthOverHttp());
}

@Test
Expand All @@ -92,7 +94,7 @@ public void testAllowBasicAuthOverHttpExplicitlySet() throws Exception
+ " \"service\": { \"servicePrefix\": \"druid\" }\n"
+ "}\n"
);
Assert.assertTrue(config.getAuth().getAllowBasicAuthOverHttp());
Assertions.assertTrue(config.getAuth().getAllowBasicAuthOverHttp());
}

@Test
Expand All @@ -104,19 +106,21 @@ public void testNegativeMaxWatchRetriesMeansUnlimited() throws Exception
+ " \"watch\": { \"maxWatchRetries\": -1 }\n"
+ "}\n"
);
Assert.assertEquals(Long.MAX_VALUE, config.getWatch().getMaxWatchRetries());
Assertions.assertEquals(Long.MAX_VALUE, config.getWatch().getMaxWatchRetries());
}

@Test(expected = IllegalArgumentException.class)
@Test
public void testNullServicePrefixThrows()
{
TestUtils.builder().servicePrefix(null).build();
assertThrows(IllegalArgumentException.class, () ->
TestUtils.builder().servicePrefix(null).build());
}

@Test(expected = IllegalArgumentException.class)
@Test
public void testEmptyServicePrefixThrows()
{
TestUtils.builder().servicePrefix("").build();
assertThrows(IllegalArgumentException.class, () ->
TestUtils.builder().servicePrefix("").build());
}

@Test
Expand All @@ -128,8 +132,8 @@ public void testLeaderRetryOverrides() throws Exception
+ " \"leader\": { \"leaderMaxErrorRetries\": 5, \"leaderRetryBackoffMax\": \"PT30S\" }\n"
+ "}\n"
);
Assert.assertEquals(5L, config.getLeader().getLeaderMaxErrorRetries());
Assert.assertEquals(Duration.millis(30000), config.getLeader().getLeaderRetryBackoffMax());
Assertions.assertEquals(5L, config.getLeader().getLeaderMaxErrorRetries());
Assertions.assertEquals(Duration.millis(30000), config.getLeader().getLeaderRetryBackoffMax());
}

@Test
Expand All @@ -141,7 +145,7 @@ public void testSocketTimeoutMustExceedWatchSeconds()
.socketTimeout(Duration.millis(5000))
.watchSeconds(Duration.millis(60000))
.build();
Assert.fail("Expected IllegalArgumentException for socketTimeout <= watchSeconds");
Assertions.fail("Expected IllegalArgumentException for socketTimeout <= watchSeconds");
}
catch (IllegalArgumentException expected) {
// expected
Expand All @@ -156,7 +160,7 @@ public void testDefaultSocketTimeoutGreaterThanWatchSeconds()
.watchSeconds(Duration.millis(60000))
.build();

Assert.assertTrue(config.getConnection().getSocketTimeout().isLongerThan(config.getWatch().getWatchSeconds()));
Assertions.assertTrue(config.getConnection().getSocketTimeout().isLongerThan(config.getWatch().getWatchSeconds()));
}

@Test
Expand All @@ -175,12 +179,12 @@ public void testToStringMasksSensitiveData()

String toString = config.toString();

Assert.assertFalse(toString.contains("secret-acl-token"));
Assert.assertFalse(toString.contains("password"));
Assert.assertFalse(toString.contains("admin"));
Assert.assertTrue(toString.contains("*****"));
Assert.assertTrue(toString.contains("localhost"));
Assert.assertTrue(toString.contains("druid"));
Assertions.assertFalse(toString.contains("secret-acl-token"));
Assertions.assertFalse(toString.contains("password"));
Assertions.assertFalse(toString.contains("admin"));
Assertions.assertTrue(toString.contains("*****"));
Assertions.assertTrue(toString.contains("localhost"));
Assertions.assertTrue(toString.contains("druid"));
}

@Test
Expand All @@ -192,7 +196,7 @@ public void testLeaderSessionTtlDefault() throws Exception
.build();

// Default should be max(45s, 3 * healthCheckInterval)
Assert.assertEquals(Duration.standardSeconds(45), config.getLeader().getLeaderSessionTtl());
Assertions.assertEquals(Duration.standardSeconds(45), config.getLeader().getLeaderSessionTtl());
}

@Test
Expand All @@ -205,16 +209,17 @@ public void testLeaderSessionTtlCustom() throws Exception
+ "}\n"
);

Assert.assertEquals(Duration.standardSeconds(60), config.getLeader().getLeaderSessionTtl());
Assertions.assertEquals(Duration.standardSeconds(60), config.getLeader().getLeaderSessionTtl());
}

@Test(expected = IllegalArgumentException.class)
@Test
public void testLeaderSessionTtlTooLow()
{
TestUtils.builder()
.servicePrefix("druid")
.leaderSessionTtl(Duration.standardSeconds(5))
.build();
assertThrows(IllegalArgumentException.class, () ->
TestUtils.builder()
.servicePrefix("druid")
.leaderSessionTtl(Duration.standardSeconds(5))
.build());
}

@Test
Expand All @@ -238,7 +243,7 @@ public void testLeaderSessionTtlDependsOnHealthCheckInterval() throws Exception
.build();

// Should be 3 * healthCheckInterval = 60s (greater than minimum 45s)
Assert.assertEquals(Duration.standardSeconds(60), config.getLeader().getLeaderSessionTtl());
Assertions.assertEquals(Duration.standardSeconds(60), config.getLeader().getLeaderSessionTtl());
}

@Test
Expand All @@ -258,11 +263,11 @@ public void testServiceTagsDefensiveCopyAndUnmodifiable()
// Original map modifications should not affect stored map
originalTags.put("key1", "mutated");

Assert.assertEquals("value1", serviceConfig.getServiceTags().get("key1"));
Assertions.assertEquals("value1", serviceConfig.getServiceTags().get("key1"));

try {
serviceConfig.getServiceTags().put("key2", "value2");
Assert.fail("Expected UnsupportedOperationException when mutating serviceTags");
Assertions.fail("Expected UnsupportedOperationException when mutating serviceTags");
}
catch (UnsupportedOperationException expected) {
// expected
Expand All @@ -276,7 +281,7 @@ private void testSerde(String jsonStr) throws Exception
jsonMapper.writeValueAsString(config),
ConsulDiscoveryConfig.class
);
Assert.assertEquals(config, roundTrip);
Assertions.assertEquals(config, roundTrip);
}

private ConsulDiscoveryConfig testSerdeAndReturn(String jsonStr) throws Exception
Expand All @@ -286,7 +291,7 @@ private ConsulDiscoveryConfig testSerdeAndReturn(String jsonStr) throws Exceptio
jsonMapper.writeValueAsString(config),
ConsulDiscoveryConfig.class
);
Assert.assertEquals(config, roundTrip);
Assertions.assertEquals(config, roundTrip);
return config;
}
}
Loading
Loading