Skip to content

RUST-1387 Execute CSFLE unified spec tests #770

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

Merged
merged 10 commits into from
Nov 10, 2022
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
5 changes: 4 additions & 1 deletion .evergreen/run-csfle-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ cargo_test() {

set +o errexit

cargo_test test::csfle > results.xml
cargo_test test::csfle > prose.xml
cargo_test test::spec::client_side_encryption > spec.xml

junit-report-merger results.xml prose.xml spec.xml

exit ${CARGO_RESULT}
4 changes: 2 additions & 2 deletions src/client/csfle/client_encryption.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use mongocrypt::{
ctx::{Algorithm, Ctx, KmsProvider},
Crypt,
};
use serde::Serialize;
use serde::{Deserialize, Serialize};
use typed_builder::TypedBuilder;

use super::{
Expand Down Expand Up @@ -273,7 +273,7 @@ pub struct DataKeyOptions {

/// A KMS-specific key used to encrypt data keys.
#[serde_with::skip_serializing_none]
#[derive(Debug, Clone, Serialize)]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
#[non_exhaustive]
#[allow(missing_docs)]
Expand Down
26 changes: 6 additions & 20 deletions src/test/csfle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ use crate::{
CommandSucceededEvent,
},
options::{IndexOptions, ReadConcern, WriteConcern},
test::{Event, EventHandler, SdamEvent},
test::{Event, EventHandler, SdamEvent, KMIP_TLS_OPTIONS, KMS_PROVIDERS},
Client,
Collection,
IndexModel,
Expand Down Expand Up @@ -87,30 +87,16 @@ async fn init_client() -> Result<(EventClient, Collection<Document>)> {
}

lazy_static! {
static ref KMS_PROVIDERS: KmsProviders = serde_json::from_str(&std::env::var("KMS_PROVIDERS").unwrap()).unwrap();
static ref LOCAL_KMS: KmsProviders = {
let mut out = KMS_PROVIDERS.clone();
out.retain(|k, _| *k == KmsProvider::Local);
out
};
static ref EXTRA_OPTIONS: Document = doc! { "cryptSharedLibPath": std::env::var("CSFLE_SHARED_LIB_PATH").unwrap() };
static ref EXTRA_OPTIONS: Document =
doc! { "cryptSharedLibPath": std::env::var("CSFLE_SHARED_LIB_PATH").unwrap() };
static ref KV_NAMESPACE: Namespace = Namespace::from_str("keyvault.datakeys").unwrap();
static ref KMIP_TLS_OPTIONS: KmsProvidersTlsOptions = {
/* If these options are used, the test will need a running KMIP server:
pip3 install pykmip
# in drivers-evergreen-tools/.evergreen
python3 ./csfle/kms_kmip_server.py
*/
let cert_dir = PathBuf::from(std::env::var("CSFLE_TLS_CERT_DIR").unwrap());
let kmip_opts = TlsOptions::builder()
.ca_file_path(cert_dir.join("ca.pem"))
.cert_key_file_path(cert_dir.join("client.pem"))
.build();
let tls_options: KmsProvidersTlsOptions = [(KmsProvider::Kmip, kmip_opts)].into_iter().collect();
tls_options
};
static ref DISABLE_CRYPT_SHARED: bool = std::env::var("DISABLE_CRYPT_SHARED")
.map_or(false, |s| s == "true");
static ref DISABLE_CRYPT_SHARED: bool =
std::env::var("DISABLE_CRYPT_SHARED").map_or(false, |s| s == "true");
}

fn check_env(name: &str, kmip: bool) -> bool {
Expand Down Expand Up @@ -496,7 +482,7 @@ async fn external_key_vault() -> Result<()> {
fn load_testdata_raw(name: &str) -> Result<String> {
let path: PathBuf = [
env!("CARGO_MANIFEST_DIR"),
"src/test/spec/json/client-side-encryption/testdata",
"src/test/spec/json/testdata/client-side-encryption",
name,
]
.iter()
Expand Down
16 changes: 16 additions & 0 deletions src/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,22 @@ lazy_static! {
std::env::var("SERVERLESS_ATLAS_PASSWORD").ok();
}

#[cfg(feature = "csfle")]
lazy_static! {
pub(crate) static ref KMS_PROVIDERS: crate::client::csfle::options::KmsProviders =
serde_json::from_str(&std::env::var("KMS_PROVIDERS").unwrap()).unwrap();
pub(crate) static ref KMIP_TLS_OPTIONS: crate::client::csfle::options::KmsProvidersTlsOptions = {
let cert_dir = std::path::PathBuf::from(std::env::var("CSFLE_TLS_CERT_DIR").unwrap());
let kmip_opts = crate::client::options::TlsOptions::builder()
.ca_file_path(cert_dir.join("ca.pem"))
.cert_key_file_path(cert_dir.join("client.pem"))
.build();
[(mongocrypt::ctx::KmsProvider::Kmip, kmip_opts)]
.into_iter()
.collect()
};
}

// conditional definitions do not work within the lazy_static! macro, so this
// needs to be defined separately.
#[cfg(feature = "tracing-unstable")]
Expand Down
16 changes: 16 additions & 0 deletions src/test/spec/client_side_encryption.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use tokio::sync::RwLockWriteGuard;

use crate::test::LOCK;

use super::{run_spec_test_with_path, run_unified_format_test};

#[cfg_attr(feature = "tokio-runtime", tokio::test(flavor = "multi_thread"))]
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
async fn run() {
let _guard: RwLockWriteGuard<()> = LOCK.run_exclusively().await;
run_spec_test_with_path(
&["client-side-encryption", "unified"],
run_unified_format_test,
)
.await;
}
Loading