Skip to content

Commit ee98512

Browse files
authored
Merge pull request #1236 from muzarski/ccm-auth
tests: port AUTH tests to ccm
2 parents a253772 + f37c98e commit ee98512

File tree

7 files changed

+144
-153
lines changed

7 files changed

+144
-153
lines changed

.github/workflows/authenticate_test.yml

-40
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
use std::sync::Arc;
2+
3+
use async_trait::async_trait;
4+
use bytes::{BufMut, BytesMut};
5+
use scylla::authentication::{AuthenticatorProvider, AuthenticatorSession};
6+
use scylla::errors::AuthError;
7+
use tokio::sync::Mutex;
8+
9+
use crate::ccm::cluster::{Cluster, ClusterOptions};
10+
use crate::ccm::{run_ccm_test_with_configuration, CLUSTER_VERSION};
11+
use crate::common::utils::{setup_tracing, unique_keyspace_name, PerformDDL};
12+
13+
fn cluster_1_node() -> ClusterOptions {
14+
ClusterOptions {
15+
name: "cluster_auth_1_node".to_string(),
16+
version: CLUSTER_VERSION.clone(),
17+
nodes: vec![1],
18+
..ClusterOptions::default()
19+
}
20+
}
21+
22+
async fn run_ccm_auth_test_cluster_one_node<T, TFut>(test: T)
23+
where
24+
T: FnOnce(Arc<Mutex<Cluster>>) -> TFut,
25+
TFut: std::future::Future<Output = ()>,
26+
{
27+
run_ccm_test_with_configuration(
28+
cluster_1_node,
29+
|cluster| async move {
30+
cluster
31+
.enable_password_authentication()
32+
.await
33+
.expect("Failed to enable password authenticator");
34+
cluster
35+
},
36+
test,
37+
)
38+
.await
39+
}
40+
41+
#[tokio::test]
42+
#[cfg_attr(not(ccm_tests), ignore)]
43+
async fn authenticate_superuser_cluster_one_node() {
44+
setup_tracing();
45+
async fn test(cluster: Arc<Mutex<Cluster>>) {
46+
let cluster = cluster.lock().await;
47+
48+
tracing::info!(
49+
"Connecting to {:?} with cassandra superuser...",
50+
cluster.nodes().get_contact_endpoints().await
51+
);
52+
53+
let session = cluster
54+
.make_session_builder()
55+
.await
56+
.user("cassandra", "cassandra")
57+
.build()
58+
.await
59+
.unwrap();
60+
let ks = unique_keyspace_name();
61+
62+
session.ddl(format!("CREATE KEYSPACE IF NOT EXISTS {} WITH REPLICATION = {{'class' : 'NetworkTopologyStrategy', 'replication_factor' : 1}}", ks)).await.unwrap();
63+
session.use_keyspace(ks, false).await.unwrap();
64+
session.ddl("DROP TABLE IF EXISTS t;").await.unwrap();
65+
66+
tracing::info!("Ok.");
67+
}
68+
69+
run_ccm_auth_test_cluster_one_node(test).await
70+
}
71+
72+
struct CustomAuthenticator;
73+
74+
#[async_trait]
75+
impl AuthenticatorSession for CustomAuthenticator {
76+
async fn evaluate_challenge(
77+
&mut self,
78+
_token: Option<&[u8]>,
79+
) -> Result<Option<Vec<u8>>, AuthError> {
80+
Err("Challenges are not expected".to_string())
81+
}
82+
83+
async fn success(&mut self, _token: Option<&[u8]>) -> Result<(), AuthError> {
84+
Ok(())
85+
}
86+
}
87+
88+
struct CustomAuthenticatorProvider;
89+
90+
#[async_trait]
91+
impl AuthenticatorProvider for CustomAuthenticatorProvider {
92+
async fn start_authentication_session(
93+
&self,
94+
_authenticator_name: &str,
95+
) -> Result<(Option<Vec<u8>>, Box<dyn AuthenticatorSession>), AuthError> {
96+
let mut response = BytesMut::new();
97+
let cred = "\0cassandra\0cassandra";
98+
99+
response.put_slice(cred.as_bytes());
100+
101+
Ok((Some(response.to_vec()), Box::new(CustomAuthenticator)))
102+
}
103+
}
104+
105+
#[tokio::test]
106+
#[cfg_attr(not(ccm_tests), ignore)]
107+
async fn custom_authentication_cluster_one_node() {
108+
setup_tracing();
109+
async fn test(cluster: Arc<Mutex<Cluster>>) {
110+
let cluster = cluster.lock().await;
111+
112+
tracing::info!(
113+
"Connecting to {:?} with custom authenticator as cassandra superuser...",
114+
cluster.nodes().get_contact_endpoints().await
115+
);
116+
117+
let session = cluster
118+
.make_session_builder()
119+
.await
120+
.authenticator_provider(Arc::new(CustomAuthenticatorProvider))
121+
.build()
122+
.await
123+
.unwrap();
124+
let ks = unique_keyspace_name();
125+
126+
session.ddl(format!("CREATE KEYSPACE IF NOT EXISTS {} WITH REPLICATION = {{'class' : 'NetworkTopologyStrategy', 'replication_factor' : 1}}", ks)).await.unwrap();
127+
session.use_keyspace(ks, false).await.unwrap();
128+
session.ddl("DROP TABLE IF EXISTS t;").await.unwrap();
129+
130+
tracing::info!("Ok.");
131+
}
132+
133+
run_ccm_auth_test_cluster_one_node(test).await
134+
}

scylla/tests/ccm_integration/ccm/cluster.rs

+9
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,15 @@ impl Cluster {
705705
self.updateconf(args).await
706706
}
707707

708+
/// Enables the `PasswordAuthenticator` for the cluster.
709+
// Consider making it accept an enum in the future. Supported authenticators:
710+
// https://github.com/scylladb/scylladb/blob/529ff3efa57553eef6b0239b03b81581b70fb9ed/db/config.cc#L1045-L1051.
711+
pub(crate) async fn enable_password_authentication(&self) -> Result<(), Error> {
712+
let args = [("authenticator", "PasswordAuthenticator")];
713+
714+
self.updateconf(args).await
715+
}
716+
708717
fn get_ccm_env(&self) -> HashMap<String, String> {
709718
let mut env: HashMap<String, String> = HashMap::new();
710719
env.insert(

scylla/tests/ccm_integration/main.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#[path = "../common/mod.rs"]
22
mod common;
33

4+
mod authenticate;
45
pub(crate) mod ccm;
56
mod test_example;
67
#[cfg(feature = "ssl")]

scylla/tests/integration/authenticate.rs

-84
This file was deleted.

scylla/tests/integration/main.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
mod authenticate;
21
mod batch;
32
mod consistency;
43
mod cql_collections;

test/cluster/docker-compose-passauth.yml

-28
This file was deleted.

0 commit comments

Comments
 (0)