Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial support for Capella testing #332

Merged
merged 1 commit into from
Jul 16, 2024
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
29 changes: 12 additions & 17 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
workspace = { members = ["utilities"] }
[package]
name = "couchbase-shell"
version = "0.95.0"
Expand Down Expand Up @@ -55,8 +56,8 @@ tokio = { version = "1.38.0", features = ["full"] }
tokio-util = { version = "0.7.11", features = ["codec"] }
tokio-rustls = { version = "0.26.0" }
toml = "0.8.14"
trust-dns-resolver = { version = "0.23.2", features = ["dns-over-rustls"] }
uuid = { version = "1.9.1", features = ["v4"] }
utilities = { path = "utilities" }
webpki-roots = "0.26.3"

[target.'cfg(not(any(target_os = "macos", target_os = "windows")))'.dependencies]
Expand All @@ -83,14 +84,16 @@ static-link-openssl = ["dep:openssl"]
# We use a list of supported features to determine which tests we want to run, the defaults will always be run, then we
# define any additional features using the specific server versions we test against
default = ["key_value", "query", "query_index", "query_index_definitions", "query_index_advise"]
"7.1.1" = ["collections"]
"7.0.3" = ["collections"]
"7.1.1" = ["collections", "import_sample"]
"7.0.3" = ["collections", "import_sample"]
"capella" = ["collections"]
key_value = []
query = []
collections = []
query_index = []
query_index_definitions = []
query_index_advise = []
import_sample = []

[[bin]]
name = "cbsh"
Expand Down
49 changes: 8 additions & 41 deletions src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ use std::sync::atomic::AtomicBool;
use std::sync::Arc;
use tokio::time::Instant;

use trust_dns_resolver::config::{ResolverConfig, ResolverOpts};
use trust_dns_resolver::Resolver;
extern crate utilities;

mod bedrock_client;
mod capella_ca;
Expand Down Expand Up @@ -51,7 +50,13 @@ impl Client {
tls_config: Option<RustTlsConfig>,
) -> Self {
let seeds = if Client::might_be_srv(&seeds) {
Client::try_lookup_srv(seeds[0].clone()).unwrap_or(seeds)
match utilities::try_lookup_srv(seeds[0].clone()) {
Ok(s) => s,
Err(e) => {
debug!("Server lookup failed, falling back to hostnames: {}", e);
seeds
}
}
} else {
seeds
};
Expand Down Expand Up @@ -91,44 +96,6 @@ impl Client {
.await
}

fn try_lookup_srv(addr: String) -> Result<Vec<String>, ClientError> {
// NOTE: resolver is going to build its own runtime, which is a pain...
let resolver =
Resolver::new(ResolverConfig::default(), ResolverOpts::default()).map_err(|e| {
ClientError::RequestFailed {
reason: Some(e.to_string()),
key: None,
}
})?;
let mut address = addr;
if !address.starts_with("_couchbases._tcp.") {
address = format!("_couchbases._tcp.{}", address);
}

let response = match resolver.srv_lookup(address) {
Ok(k) => k,
Err(e) => {
return Err(ClientError::RequestFailed {
reason: Some(e.to_string()),
key: None,
})
}
};

let mut addresses: Vec<String> = Vec::new();
for a in response.iter() {
// The addresses get suffixed with a . so we have to remove this to later match the address
// with the addresses in the alternate addresses in the config.
let mut host = a.target().to_string();
if let Some(prefix) = host.strip_suffix('.') {
host = prefix.to_string();
}
addresses.push(host);
}

Ok(addresses)
}

// This broadly mirrors the srv logic from the connstr package within gocbcore.
fn might_be_srv(seeds: &[String]) -> bool {
if seeds.len() > 1 {
Expand Down
64 changes: 3 additions & 61 deletions src/client/tls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,70 +4,12 @@ use crate::ClusterTlsConfig;
use log::{debug, error};
use rustls_pemfile::{read_all, Item};
use std::convert::TryFrom;
use std::fmt::Debug;
use std::fs;
use std::io::BufReader;
use std::sync::Arc;
use tokio_rustls::rustls::client::danger::{
HandshakeSignatureValid, ServerCertVerified, ServerCertVerifier,
};
use tokio_rustls::rustls::crypto::{aws_lc_rs::default_provider, CryptoProvider};
use tokio_rustls::rustls::pki_types::{CertificateDer, ServerName, UnixTime};
use tokio_rustls::rustls::{
ClientConfig, DigitallySignedStruct, Error, RootCertStore, SignatureScheme,
};

#[derive(Debug)]
struct InsecureCertVerifier {}

impl ServerCertVerifier for InsecureCertVerifier {
fn verify_server_cert(
&self,
_end_entity: &CertificateDer,
_intermediates: &[CertificateDer],
_server_name: &ServerName,
_ocsp_response: &[u8],
_now: UnixTime,
) -> Result<ServerCertVerified, Error> {
Ok(ServerCertVerified::assertion())
}

fn verify_tls12_signature(
&self,
_message: &[u8],
_cert: &CertificateDer<'_>,
_dss: &DigitallySignedStruct,
) -> Result<HandshakeSignatureValid, Error> {
Ok(HandshakeSignatureValid::assertion())
}

fn verify_tls13_signature(
&self,
_message: &[u8],
_cert: &CertificateDer<'_>,
_dss: &DigitallySignedStruct,
) -> Result<HandshakeSignatureValid, Error> {
Ok(HandshakeSignatureValid::assertion())
}

fn supported_verify_schemes(&self) -> Vec<SignatureScheme> {
vec![
SignatureScheme::RSA_PKCS1_SHA1,
SignatureScheme::ECDSA_SHA1_Legacy,
SignatureScheme::RSA_PKCS1_SHA256,
SignatureScheme::ECDSA_NISTP256_SHA256,
SignatureScheme::RSA_PKCS1_SHA384,
SignatureScheme::ECDSA_NISTP384_SHA384,
SignatureScheme::RSA_PKCS1_SHA512,
SignatureScheme::ECDSA_NISTP521_SHA512,
SignatureScheme::RSA_PSS_SHA256,
SignatureScheme::RSA_PSS_SHA384,
SignatureScheme::RSA_PSS_SHA512,
SignatureScheme::ED25519,
SignatureScheme::ED448,
]
}
}
use tokio_rustls::rustls::{ClientConfig, RootCertStore};
use utilities;

#[derive(Clone)]
pub struct RustTlsConfig {
Expand All @@ -87,7 +29,7 @@ impl RustTlsConfig {
if accept_all_certs {
let config = builder
.dangerous()
.with_custom_certificate_verifier(Arc::new(InsecureCertVerifier {}))
.with_custom_certificate_verifier(Arc::new(utilities::InsecureCertVerifier {}))
.with_no_client_auth();

return Ok(RustTlsConfig {
Expand Down
2 changes: 2 additions & 0 deletions tests/buckets_sample.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use nu_test_support::pipeline;
use std::{thread, time};

#[test]
#[cfg_attr(not(feature = "import_sample"), ignore)]
fn import_sample() {
CBPlayground::setup("import_sample", None, None, |dirs, sandbox| {
let out =
Expand Down Expand Up @@ -47,6 +48,7 @@ fn import_sample() {
}

#[test]
#[cfg_attr(not(feature = "import_sample"), ignore)]
fn import_sample_invalid_sample() {
CBPlayground::setup("import_sample", None, None, |dirs, sandbox| {
let out =
Expand Down
1 change: 1 addition & 0 deletions tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub mod utils;

use crate::common::error::TestError;
use uuid::Uuid;
extern crate utilities;

pub type TestResult<T> = Result<T, TestError>;

Expand Down
Loading
Loading