Skip to content

Commit 3ad0982

Browse files
abr-egnisabelatkinson
authored andcommitted
RUST-1387 Execute CSFLE unified spec tests (mongodb#770)
1 parent ca50433 commit 3ad0982

File tree

153 files changed

+34830
-124
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

153 files changed

+34830
-124
lines changed

.evergreen/run-csfle-tests.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ cargo_test() {
3232

3333
set +o errexit
3434

35-
cargo_test test::csfle > results.xml
35+
cargo_test test::csfle > prose.xml
36+
cargo_test test::spec::client_side_encryption > spec.xml
37+
38+
junit-report-merger results.xml prose.xml spec.xml
3639

3740
exit ${CARGO_RESULT}

src/client/csfle/client_encryption.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use mongocrypt::{
1616
ctx::{Algorithm, Ctx, KmsProvider},
1717
Crypt,
1818
};
19-
use serde::Serialize;
19+
use serde::{Deserialize, Serialize};
2020
use typed_builder::TypedBuilder;
2121

2222
use super::{
@@ -273,7 +273,7 @@ pub struct DataKeyOptions {
273273

274274
/// A KMS-specific key used to encrypt data keys.
275275
#[serde_with::skip_serializing_none]
276-
#[derive(Debug, Clone, Serialize)]
276+
#[derive(Debug, Clone, Serialize, Deserialize)]
277277
#[serde(untagged)]
278278
#[non_exhaustive]
279279
#[allow(missing_docs)]

src/test/csfle.rs

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ use crate::{
4646
CommandSucceededEvent,
4747
},
4848
options::{IndexOptions, ReadConcern, WriteConcern},
49-
test::{Event, EventHandler, SdamEvent},
49+
test::{Event, EventHandler, SdamEvent, KMIP_TLS_OPTIONS, KMS_PROVIDERS},
5050
Client,
5151
Collection,
5252
IndexModel,
@@ -87,30 +87,16 @@ async fn init_client() -> Result<(EventClient, Collection<Document>)> {
8787
}
8888

8989
lazy_static! {
90-
static ref KMS_PROVIDERS: KmsProviders = serde_json::from_str(&std::env::var("KMS_PROVIDERS").unwrap()).unwrap();
9190
static ref LOCAL_KMS: KmsProviders = {
9291
let mut out = KMS_PROVIDERS.clone();
9392
out.retain(|k, _| *k == KmsProvider::Local);
9493
out
9594
};
96-
static ref EXTRA_OPTIONS: Document = doc! { "cryptSharedLibPath": std::env::var("CSFLE_SHARED_LIB_PATH").unwrap() };
95+
static ref EXTRA_OPTIONS: Document =
96+
doc! { "cryptSharedLibPath": std::env::var("CSFLE_SHARED_LIB_PATH").unwrap() };
9797
static ref KV_NAMESPACE: Namespace = Namespace::from_str("keyvault.datakeys").unwrap();
98-
static ref KMIP_TLS_OPTIONS: KmsProvidersTlsOptions = {
99-
/* If these options are used, the test will need a running KMIP server:
100-
pip3 install pykmip
101-
# in drivers-evergreen-tools/.evergreen
102-
python3 ./csfle/kms_kmip_server.py
103-
*/
104-
let cert_dir = PathBuf::from(std::env::var("CSFLE_TLS_CERT_DIR").unwrap());
105-
let kmip_opts = TlsOptions::builder()
106-
.ca_file_path(cert_dir.join("ca.pem"))
107-
.cert_key_file_path(cert_dir.join("client.pem"))
108-
.build();
109-
let tls_options: KmsProvidersTlsOptions = [(KmsProvider::Kmip, kmip_opts)].into_iter().collect();
110-
tls_options
111-
};
112-
static ref DISABLE_CRYPT_SHARED: bool = std::env::var("DISABLE_CRYPT_SHARED")
113-
.map_or(false, |s| s == "true");
98+
static ref DISABLE_CRYPT_SHARED: bool =
99+
std::env::var("DISABLE_CRYPT_SHARED").map_or(false, |s| s == "true");
114100
}
115101

116102
fn check_env(name: &str, kmip: bool) -> bool {
@@ -496,7 +482,7 @@ async fn external_key_vault() -> Result<()> {
496482
fn load_testdata_raw(name: &str) -> Result<String> {
497483
let path: PathBuf = [
498484
env!("CARGO_MANIFEST_DIR"),
499-
"src/test/spec/json/client-side-encryption/testdata",
485+
"src/test/spec/json/testdata/client-side-encryption",
500486
name,
501487
]
502488
.iter()

src/test/mod.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,22 @@ lazy_static! {
8989
std::env::var("SERVERLESS_ATLAS_PASSWORD").ok();
9090
}
9191

92+
#[cfg(feature = "csfle")]
93+
lazy_static! {
94+
pub(crate) static ref KMS_PROVIDERS: crate::client::csfle::options::KmsProviders =
95+
serde_json::from_str(&std::env::var("KMS_PROVIDERS").unwrap()).unwrap();
96+
pub(crate) static ref KMIP_TLS_OPTIONS: crate::client::csfle::options::KmsProvidersTlsOptions = {
97+
let cert_dir = std::path::PathBuf::from(std::env::var("CSFLE_TLS_CERT_DIR").unwrap());
98+
let kmip_opts = crate::client::options::TlsOptions::builder()
99+
.ca_file_path(cert_dir.join("ca.pem"))
100+
.cert_key_file_path(cert_dir.join("client.pem"))
101+
.build();
102+
[(mongocrypt::ctx::KmsProvider::Kmip, kmip_opts)]
103+
.into_iter()
104+
.collect()
105+
};
106+
}
107+
92108
// conditional definitions do not work within the lazy_static! macro, so this
93109
// needs to be defined separately.
94110
#[cfg(feature = "tracing-unstable")]
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
use tokio::sync::RwLockWriteGuard;
2+
3+
use crate::test::LOCK;
4+
5+
use super::{run_spec_test_with_path, run_unified_format_test};
6+
7+
#[cfg_attr(feature = "tokio-runtime", tokio::test(flavor = "multi_thread"))]
8+
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
9+
async fn run() {
10+
let _guard: RwLockWriteGuard<()> = LOCK.run_exclusively().await;
11+
run_spec_test_with_path(
12+
&["client-side-encryption", "unified"],
13+
run_unified_format_test,
14+
)
15+
.await;
16+
}

0 commit comments

Comments
 (0)