Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,34 @@

public class PlainTextAuthProviderIT {

private static final String USERNAME = "cassandra";
private static final String PASSWORD = "cassandra";
private static final Version SCYLLA_CUSTOM_SUPERUSER_VERSION = Version.parse("2026.2.0");
private static final String SCYLLA_SALTED_PASSWORD =
"$6$java-driver-test$2JXL/pXZTuamSsYNH/kE9UUSQETMmKIcdP8Xgdu/fiHsTHSN.EhjmLrMHPVuQ3.4w0h8CDsP/f1trG0kujylG0";

@ClassRule public static final CustomCcmRule CCM_RULE = getCCMRule();

private static CustomCcmRule getCCMRule() {
CustomCcmRule.Builder builder =
CustomCcmRule.builder()
.withCassandraConfiguration("authenticator", "PasswordAuthenticator");
if (!CcmBridge.isDistributionOf(BackendType.SCYLLA)) {
if (requiresExplicitScyllaSuperuser()) {
builder =
builder
.withCassandraConfiguration("auth_superuser_name", USERNAME)
.withCassandraConfiguration("auth_superuser_salted_password", SCYLLA_SALTED_PASSWORD);
} else if (!CcmBridge.isDistributionOf(BackendType.SCYLLA)) {
builder = builder.withJvmArgs("-Dcassandra.superuser_setup_delay_ms=0");
}
return builder.build();
}

private static boolean requiresExplicitScyllaSuperuser() {
return CcmBridge.isDistributionOf(BackendType.SCYLLA)
&& CcmBridge.getDistributionVersion().compareTo(SCYLLA_CUSTOM_SUPERUSER_VERSION) >= 0;
}

@BeforeClass
public static void sleepForAuth() {
if (CCM_RULE.getCassandraVersion().compareTo(Version.V2_2_0) < 0) {
Expand All @@ -69,8 +85,8 @@ public void should_connect_with_credentials() {
DriverConfigLoader loader =
SessionUtils.configLoaderBuilder()
.withClass(DefaultDriverOption.AUTH_PROVIDER_CLASS, PlainTextAuthProvider.class)
.withString(DefaultDriverOption.AUTH_PROVIDER_USER_NAME, "cassandra")
.withString(DefaultDriverOption.AUTH_PROVIDER_PASSWORD, "cassandra")
.withString(DefaultDriverOption.AUTH_PROVIDER_USER_NAME, USERNAME)
.withString(DefaultDriverOption.AUTH_PROVIDER_PASSWORD, PASSWORD)
.build();
try (CqlSession session = SessionUtils.newSession(CCM_RULE, loader)) {
session.execute("select * from system.local where key='local'");
Expand All @@ -83,7 +99,7 @@ public void should_connect_with_programmatic_credentials() {
SessionBuilder<?, ?> builder =
SessionUtils.baseBuilder()
.addContactEndPoints(CCM_RULE.getContactPoints())
.withAuthCredentials("cassandra", "cassandra");
.withAuthCredentials(USERNAME, PASSWORD);

try (CqlSession session = (CqlSession) builder.build()) {
session.execute("select * from system.local where key='local'");
Expand All @@ -93,7 +109,7 @@ public void should_connect_with_programmatic_credentials() {
@Test
public void should_connect_with_programmatic_provider() {

AuthProvider authProvider = new ProgrammaticPlainTextAuthProvider("cassandra", "cassandra");
AuthProvider authProvider = new ProgrammaticPlainTextAuthProvider(USERNAME, PASSWORD);
SessionBuilder<?, ?> builder =
SessionUtils.baseBuilder()
.addContactEndPoints(CCM_RULE.getContactPoints())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import com.datastax.oss.driver.api.core.CqlIdentifier;
import com.datastax.oss.driver.api.core.CqlSession;
import com.datastax.oss.driver.api.core.Version;
import com.datastax.oss.driver.api.core.config.DefaultDriverOption;
import com.datastax.oss.driver.api.core.config.DriverConfigLoader;
import com.datastax.oss.driver.api.core.config.DriverExecutionProfile;
Expand All @@ -31,6 +32,8 @@
import com.datastax.oss.driver.api.core.session.Session;
import com.datastax.oss.driver.api.core.session.SessionBuilder;
import com.datastax.oss.driver.api.testinfra.CassandraResourceRule;
import com.datastax.oss.driver.api.testinfra.ccm.CcmBridge;
import com.datastax.oss.driver.api.testinfra.requirement.BackendType;
import com.datastax.oss.driver.internal.core.loadbalancing.helper.NodeFilterToDistanceEvaluatorAdapter;
import java.lang.reflect.Method;
import java.util.concurrent.atomic.AtomicInteger;
Expand Down Expand Up @@ -69,6 +72,10 @@ public class SessionUtils {
private static final Logger LOG = LoggerFactory.getLogger(SessionUtils.class);
private static final AtomicInteger keyspaceId = new AtomicInteger();
private static final String DEFAULT_SESSION_CLASS_NAME = CqlSession.class.getName();
private static final String DEFAULT_CCM_DATACENTER = "dc1";
private static final Version SCYLLA_ENTERPRISE_TABLETS_DEFAULT_VERSION =
Version.parse("2024.2.0");
private static final Version SCYLLA_OSS_TABLETS_DEFAULT_VERSION = Version.parse("6.1.0");

private static String getSessionBuilderClass() {
return System.getProperty(SESSION_BUILDER_CLASS_PROPERTY, DEFAULT_SESSION_CLASS_NAME);
Expand Down Expand Up @@ -195,16 +202,31 @@ public static CqlIdentifier uniqueKeyspaceId() {
/** Creates a keyspace through the given session instance, with the given profile. */
public static void createKeyspace(
Session session, CqlIdentifier keyspace, DriverExecutionProfile profile) {
String keyspaceOptions =
shouldUseScyllaTabletsWorkaroundForTestKeyspaces()
? String.format(
"WITH REPLICATION = { 'class' : 'NetworkTopologyStrategy', '%s' : 1 } "
+ "AND tablets = { 'enabled' : false }",
DEFAULT_CCM_DATACENTER)
: "WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 }";
SimpleStatement createKeyspace =
SimpleStatement.builder(
String.format(
"CREATE KEYSPACE %s WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };",
keyspace.asCql(false)))
String.format("CREATE KEYSPACE %s %s;", keyspace.asCql(false), keyspaceOptions))
.setExecutionProfile(profile)
.build();
session.execute(createKeyspace, Statement.SYNC);
}

private static boolean shouldUseScyllaTabletsWorkaroundForTestKeyspaces() {
if (!CcmBridge.isDistributionOf(BackendType.SCYLLA)) {
return false;
}
Version version = CcmBridge.getDistributionVersion();
return CcmBridge.SCYLLA_ENTERPRISE
? version.compareTo(SCYLLA_ENTERPRISE_TABLETS_DEFAULT_VERSION) >= 0
: version.compareTo(SCYLLA_OSS_TABLETS_DEFAULT_VERSION) >= 0;
}

/**
* Calls {@link #createKeyspace(Session, CqlIdentifier, DriverExecutionProfile)} with {@link
* #slowProfile(Session)} as the third argument.
Expand Down
Loading