Skip to content

Commit 8d3f53b

Browse files
committed
RSCBC-147: Fix http tests when running against cluster_run
Fix test_json_block_read in tests/http.rs to use the http port, not just assume 8091.
1 parent 0613074 commit 8d3f53b

File tree

4 files changed

+40
-24
lines changed

4 files changed

+40
-24
lines changed

sdk/couchbase-core/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ mod scram;
4949
pub mod searchcomponent;
5050
pub mod searchx;
5151
pub mod service_type;
52-
mod tls_config;
52+
pub mod tls_config;
5353
mod util;
5454
mod vbucketmap;
5555
mod vbucketrouter;

sdk/couchbase-core/tests/common/default_agent_options.rs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::common::test_config::TestSetupConfig;
22
use couchbase_core::authenticator::{Authenticator, PasswordAuthenticator};
33
use couchbase_core::options::agent::{AgentOptions, SeedConfig};
4+
use couchbase_core::tls_config::TlsConfig;
45
#[cfg(feature = "rustls-tls")]
56
use {
67
couchbase_core::insecure_certverfier::InsecureCertVerifier, std::sync::Arc,
@@ -9,18 +10,7 @@ use {
910
};
1011

1112
pub async fn create_default_options(config: TestSetupConfig) -> AgentOptions {
12-
let tls_config = if config.use_ssl {
13-
#[cfg(feature = "native-tls")]
14-
{
15-
let mut builder = tokio_native_tls::native_tls::TlsConnector::builder();
16-
builder.danger_accept_invalid_certs(true);
17-
Some(builder.build().unwrap())
18-
}
19-
#[cfg(all(feature = "rustls-tls", not(feature = "native-tls")))]
20-
Some(get_rustls_config())
21-
} else {
22-
None
23-
};
13+
let tls_config = create_tls_config(&config);
2414

2515
AgentOptions::new(
2616
SeedConfig::new()
@@ -35,6 +25,21 @@ pub async fn create_default_options(config: TestSetupConfig) -> AgentOptions {
3525
.bucket_name(config.bucket.clone())
3626
}
3727

28+
pub fn create_tls_config(config: &TestSetupConfig) -> Option<TlsConfig> {
29+
if config.use_ssl {
30+
#[cfg(feature = "native-tls")]
31+
{
32+
let mut builder = tokio_native_tls::native_tls::TlsConnector::builder();
33+
builder.danger_accept_invalid_certs(true);
34+
Some(builder.build().unwrap())
35+
}
36+
#[cfg(all(feature = "rustls-tls", not(feature = "native-tls")))]
37+
Some(get_rustls_config())
38+
} else {
39+
None
40+
}
41+
}
42+
3843
pub async fn create_options_without_bucket(config: TestSetupConfig) -> AgentOptions {
3944
let tls_config = if config.use_ssl {
4045
#[cfg(feature = "native-tls")]

sdk/couchbase-core/tests/common/test_config.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ pub struct TestSetupConfig {
4848
pub username: String,
4949
pub password: String,
5050
pub memd_addrs: Vec<Address>,
51+
pub http_addrs: Vec<Address>,
5152
pub data_timeout: String,
5253
pub use_ssl: bool,
5354
pub bucket: String,
@@ -166,6 +167,7 @@ pub async fn create_test_config(test_config: &EnvTestConfig) -> TestSetupConfig
166167
username: test_config.username.clone(),
167168
password: test_config.password.clone(),
168169
memd_addrs: resolved_conn_spec.memd_hosts.clone(),
170+
http_addrs: resolved_conn_spec.http_hosts.clone(),
169171
data_timeout: test_config.data_timeout.clone(),
170172
use_ssl: resolved_conn_spec.use_ssl,
171173
bucket: test_config.default_bucket.clone(),

sdk/couchbase-core/tests/http.rs

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
use crate::common::default_agent_options::create_tls_config;
12
use crate::common::test_config::setup_test;
23
use bytes::Bytes;
3-
use couchbase_core::httpx::client::{Client, ClientConfig, ReqwestClient};
4+
use couchbase_core::httpx::client::{self, Client, ClientConfig, ReqwestClient};
45
use couchbase_core::httpx::decoder::Decoder;
56
use couchbase_core::httpx::raw_json_row_streamer::{RawJsonRowItem, RawJsonRowStreamer};
67
use couchbase_core::httpx::request::{Auth, BasicAuth, Request};
@@ -47,22 +48,26 @@ pub struct QueryMetrics {
4748
#[test]
4849
fn test_row_streamer() {
4950
setup_test(async |config| {
50-
let addrs = config.memd_addrs;
51+
let scheme = if config.use_ssl { "https" } else { "http" };
52+
let addrs = &config.http_addrs;
5153

52-
let host = addrs.first().unwrap().host.clone();
54+
let addr = addrs.first().unwrap();
55+
let host = &addr.host;
56+
let port = addr.port;
5357

54-
let basic_auth = BasicAuth::new(config.username, config.password);
58+
let basic_auth = BasicAuth::new(&config.username, &config.password);
5559

5660
let request_body = json!({"statement": "select i from array_range(1, 10000) AS i;"});
57-
let uri = format!("http://{host}:8093/query/service");
61+
let uri = format!("{scheme}://{host}:{port}/_p/query/query/service");
5862

5963
let request = Request::new(Method::POST, uri)
6064
.user_agent("rscbcorex".to_string())
6165
.auth(Auth::BasicAuth(basic_auth))
6266
.content_type("application/json".to_string())
6367
.body(Bytes::from(serde_json::to_vec(&request_body).unwrap()));
6468

65-
let client = ReqwestClient::new(ClientConfig::default()).unwrap();
69+
let client_config = ClientConfig::default().tls_config(create_tls_config(&config));
70+
let client = ReqwestClient::new(client_config).unwrap();
6671

6772
let resp = timeout(Duration::from_secs(10), client.execute(request))
6873
.await
@@ -116,19 +121,23 @@ fn test_row_streamer() {
116121
#[test]
117122
fn test_json_block_read() {
118123
setup_test(async |config| {
119-
let addrs = config.memd_addrs;
124+
let scheme = if config.use_ssl { "https" } else { "http" };
125+
let addrs = &config.http_addrs;
120126

121-
let host = addrs.first().unwrap().host.clone();
127+
let addr = addrs.first().unwrap();
128+
let host = &addr.host;
129+
let port = addr.port;
122130

123-
let basic_auth = BasicAuth::new(config.username, config.password);
124-
let uri = format!("http://{host}:8091/pools/default/terseClusterInfo");
131+
let basic_auth = BasicAuth::new(&config.username, &config.password);
132+
let uri = format!("{scheme}://{host}:{port}/pools/default/terseClusterInfo");
125133

126134
let request = Request::new(Method::GET, uri)
127135
.user_agent("rscbcorex".to_string())
128136
.auth(Auth::BasicAuth(basic_auth))
129137
.content_type("application/json".to_string());
130138

131-
let client = ReqwestClient::new(ClientConfig::default()).expect("could not create client");
139+
let client_config = ClientConfig::default().tls_config(create_tls_config(&config));
140+
let client = ReqwestClient::new(client_config).expect("could not create client");
132141

133142
let res = timeout(Duration::from_secs(10), client.execute(request))
134143
.await

0 commit comments

Comments
 (0)