Skip to content

Commit 544a615

Browse files
Lorak-mmkmuzarski
andcommitted
IT: Move authenticate tests to CCM
Co-authored-by: Mikołaj Uzarski <mikolaj.uzarski@scylladb.com>
1 parent 186d20e commit 544a615

File tree

4 files changed

+135
-85
lines changed

4 files changed

+135
-85
lines changed
Lines changed: 134 additions & 0 deletions
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::lib::cluster::{Cluster, ClusterOptions};
10+
use crate::ccm::lib::{run_ccm_test_with_configuration, CLUSTER_VERSION};
11+
use crate::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+
|mut 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/integration/ccm/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
mod lib;
22

3+
mod authenticate;
34
mod example;

scylla/tests/integration/session/authenticate.rs

Lines changed: 0 additions & 84 deletions
This file was deleted.

scylla/tests/integration/session/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
mod authenticate;
21
mod history;
32
mod new_session;
43
mod retries;

0 commit comments

Comments
 (0)