Skip to content

Commit

Permalink
Merge pull request #1236 from muzarski/ccm-auth
Browse files Browse the repository at this point in the history
tests: port AUTH tests to ccm
  • Loading branch information
wprzytula authored Feb 13, 2025
2 parents a253772 + f37c98e commit ee98512
Show file tree
Hide file tree
Showing 7 changed files with 144 additions and 153 deletions.
40 changes: 0 additions & 40 deletions .github/workflows/authenticate_test.yml

This file was deleted.

134 changes: 134 additions & 0 deletions scylla/tests/ccm_integration/authenticate.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
use std::sync::Arc;

use async_trait::async_trait;
use bytes::{BufMut, BytesMut};
use scylla::authentication::{AuthenticatorProvider, AuthenticatorSession};
use scylla::errors::AuthError;
use tokio::sync::Mutex;

use crate::ccm::cluster::{Cluster, ClusterOptions};
use crate::ccm::{run_ccm_test_with_configuration, CLUSTER_VERSION};
use crate::common::utils::{setup_tracing, unique_keyspace_name, PerformDDL};

fn cluster_1_node() -> ClusterOptions {
ClusterOptions {
name: "cluster_auth_1_node".to_string(),
version: CLUSTER_VERSION.clone(),
nodes: vec![1],
..ClusterOptions::default()
}
}

async fn run_ccm_auth_test_cluster_one_node<T, TFut>(test: T)
where
T: FnOnce(Arc<Mutex<Cluster>>) -> TFut,
TFut: std::future::Future<Output = ()>,
{
run_ccm_test_with_configuration(
cluster_1_node,
|cluster| async move {
cluster
.enable_password_authentication()
.await
.expect("Failed to enable password authenticator");
cluster
},
test,
)
.await
}

#[tokio::test]
#[cfg_attr(not(ccm_tests), ignore)]
async fn authenticate_superuser_cluster_one_node() {
setup_tracing();
async fn test(cluster: Arc<Mutex<Cluster>>) {
let cluster = cluster.lock().await;

tracing::info!(
"Connecting to {:?} with cassandra superuser...",
cluster.nodes().get_contact_endpoints().await
);

let session = cluster
.make_session_builder()
.await
.user("cassandra", "cassandra")
.build()
.await
.unwrap();
let ks = unique_keyspace_name();

session.ddl(format!("CREATE KEYSPACE IF NOT EXISTS {} WITH REPLICATION = {{'class' : 'NetworkTopologyStrategy', 'replication_factor' : 1}}", ks)).await.unwrap();
session.use_keyspace(ks, false).await.unwrap();
session.ddl("DROP TABLE IF EXISTS t;").await.unwrap();

tracing::info!("Ok.");
}

run_ccm_auth_test_cluster_one_node(test).await
}

struct CustomAuthenticator;

#[async_trait]
impl AuthenticatorSession for CustomAuthenticator {
async fn evaluate_challenge(
&mut self,
_token: Option<&[u8]>,
) -> Result<Option<Vec<u8>>, AuthError> {
Err("Challenges are not expected".to_string())
}

async fn success(&mut self, _token: Option<&[u8]>) -> Result<(), AuthError> {
Ok(())
}
}

struct CustomAuthenticatorProvider;

#[async_trait]
impl AuthenticatorProvider for CustomAuthenticatorProvider {
async fn start_authentication_session(
&self,
_authenticator_name: &str,
) -> Result<(Option<Vec<u8>>, Box<dyn AuthenticatorSession>), AuthError> {
let mut response = BytesMut::new();
let cred = "\0cassandra\0cassandra";

response.put_slice(cred.as_bytes());

Ok((Some(response.to_vec()), Box::new(CustomAuthenticator)))
}
}

#[tokio::test]
#[cfg_attr(not(ccm_tests), ignore)]
async fn custom_authentication_cluster_one_node() {
setup_tracing();
async fn test(cluster: Arc<Mutex<Cluster>>) {
let cluster = cluster.lock().await;

tracing::info!(
"Connecting to {:?} with custom authenticator as cassandra superuser...",
cluster.nodes().get_contact_endpoints().await
);

let session = cluster
.make_session_builder()
.await
.authenticator_provider(Arc::new(CustomAuthenticatorProvider))
.build()
.await
.unwrap();
let ks = unique_keyspace_name();

session.ddl(format!("CREATE KEYSPACE IF NOT EXISTS {} WITH REPLICATION = {{'class' : 'NetworkTopologyStrategy', 'replication_factor' : 1}}", ks)).await.unwrap();
session.use_keyspace(ks, false).await.unwrap();
session.ddl("DROP TABLE IF EXISTS t;").await.unwrap();

tracing::info!("Ok.");
}

run_ccm_auth_test_cluster_one_node(test).await
}
9 changes: 9 additions & 0 deletions scylla/tests/ccm_integration/ccm/cluster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,15 @@ impl Cluster {
self.updateconf(args).await
}

/// Enables the `PasswordAuthenticator` for the cluster.
// Consider making it accept an enum in the future. Supported authenticators:
// https://github.com/scylladb/scylladb/blob/529ff3efa57553eef6b0239b03b81581b70fb9ed/db/config.cc#L1045-L1051.
pub(crate) async fn enable_password_authentication(&self) -> Result<(), Error> {
let args = [("authenticator", "PasswordAuthenticator")];

self.updateconf(args).await
}

fn get_ccm_env(&self) -> HashMap<String, String> {
let mut env: HashMap<String, String> = HashMap::new();
env.insert(
Expand Down
1 change: 1 addition & 0 deletions scylla/tests/ccm_integration/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#[path = "../common/mod.rs"]
mod common;

mod authenticate;
pub(crate) mod ccm;
mod test_example;
#[cfg(feature = "ssl")]
Expand Down
84 changes: 0 additions & 84 deletions scylla/tests/integration/authenticate.rs

This file was deleted.

1 change: 0 additions & 1 deletion scylla/tests/integration/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
mod authenticate;
mod batch;
mod consistency;
mod cql_collections;
Expand Down
28 changes: 0 additions & 28 deletions test/cluster/docker-compose-passauth.yml

This file was deleted.

0 comments on commit ee98512

Please sign in to comment.