Skip to content

Commit 6c0206e

Browse files
committed
Expanded multi-dataset tests
1 parent 93bc212 commit 6c0206e

File tree

6 files changed

+248
-125
lines changed

6 files changed

+248
-125
lines changed

src/encrypted_table/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,9 +288,7 @@ impl<D> EncryptedTable<D> {
288288
delete: PreparedDelete,
289289
dataset_id: Option<Uuid>,
290290
) -> Result<DynamoRecordPatch, DeleteError> {
291-
let scoped_cipher = ScopedZeroKmsCipher::init(self.cipher.clone(), dataset_id)
292-
.await
293-
.unwrap();
291+
let scoped_cipher = ScopedZeroKmsCipher::init(self.cipher.clone(), dataset_id).await?;
294292

295293
let PrimaryKeyParts { pk, sk } =
296294
encrypt_primary_key_parts(&scoped_cipher, delete.primary_key)?;

src/encrypted_table/query.rs

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use super::{Dynamo, EncryptedTable, QueryError, ScopedZeroKmsCipher, SealError};
2020
pub struct QueryBuilder<S, B = ()> {
2121
parts: Vec<(String, SingleIndex, Plaintext)>,
2222
storage: B,
23+
dataset_id: Option<Uuid>,
2324
__searchable: PhantomData<S>,
2425
}
2526

@@ -93,6 +94,7 @@ impl<S> Default for QueryBuilder<S> {
9394
Self {
9495
parts: vec![],
9596
storage: Default::default(),
97+
dataset_id: None,
9698
__searchable: Default::default(),
9799
}
98100
}
@@ -103,10 +105,17 @@ impl<S, B> QueryBuilder<S, B> {
103105
Self {
104106
parts: vec![],
105107
storage: backend,
108+
dataset_id: None,
106109
__searchable: Default::default(),
107110
}
108111
}
109112

113+
/// Specify the dataset to query against.
114+
pub fn via(mut self, dataset_id: Uuid) -> Self {
115+
self.dataset_id = Some(dataset_id);
116+
self
117+
}
118+
110119
pub fn eq(mut self, name: impl Into<String>, plaintext: impl Into<Plaintext>) -> Self {
111120
self.parts
112121
.push((name.into(), SingleIndex::Exact, plaintext.into()));
@@ -138,27 +147,12 @@ where
138147
///
139148
/// While a client can decrypt records from any dataset it has access to,
140149
/// queries are always scoped to a single dataset.
141-
pub async fn load<T>(self) -> Result<Vec<T>, QueryError>
142-
where
143-
T: Decryptable + Identifiable,
144-
{
145-
self.load_inner(None).await
146-
}
147-
148-
/// Similar to `load`, but the query is scoped to a specific dataset.
149-
pub async fn load_via<T>(self, dataset_id: Uuid) -> Result<Vec<T>, QueryError>
150-
where
151-
T: Decryptable + Identifiable,
152-
{
153-
self.load_inner(Some(dataset_id)).await
154-
}
155-
156-
async fn load_inner<T>(self, dataset_id: Option<Uuid>) -> Result<Vec<T>, QueryError>
150+
pub(crate) async fn load<T>(self) -> Result<Vec<T>, QueryError>
157151
where
158152
T: Decryptable + Identifiable,
159153
{
160154
let scoped_cipher =
161-
ScopedZeroKmsCipher::init(self.storage.cipher.clone(), dataset_id).await?;
155+
ScopedZeroKmsCipher::init(self.storage.cipher.clone(), self.dataset_id).await?;
162156

163157
let storage = self.storage;
164158
let query = self.build()?;

src/errors/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ pub enum DeleteError {
6464
AwsBuildError(#[from] BuildError),
6565
#[error("AwsError: {0}")]
6666
Aws(String),
67+
68+
#[error("ZeroKMS Error: {0}")]
69+
ZeroKMS(#[from] zerokms::Error),
6770
}
6871

6972
/// Error returned by `EncryptedTable::query` when indexing, retrieving and decrypting records from DynamoDB

tests/common.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ pub fn fail_not_found() -> CheckFailed {
6464
/// The name is used as a prefix in case its helpful to distinguish between tests.
6565
/// A random is appended to the name to ensure uniqueness for async tests.
6666
#[allow(dead_code)]
67-
pub async fn with_encrypted_table<F: Future<Output = miette::Result<()>>>(
67+
pub async fn with_encrypted_table<O, F: Future<Output = miette::Result<O>>>(
6868
table_name: &str,
6969
mut f: impl FnMut(EncryptedTable) -> F,
70-
) -> Result<(), Box<dyn std::error::Error>> {
70+
) -> Result<O, Box<dyn std::error::Error>> {
7171
let config = aws_config::from_env()
7272
.endpoint_url("http://localhost:8000")
7373
.load()

0 commit comments

Comments
 (0)