Skip to content

Commit 4d706dc

Browse files
committed
test: set keyset erro if default configured
1 parent 944c74f commit 4d706dc

File tree

5 files changed

+82
-1
lines changed

5 files changed

+82
-1
lines changed

docs/errors.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ Unknown keyset name or id '{keyset}'
368368
### How to Fix
369369

370370
1. Check that the active `keyset_name` or `keyset_id` is associated with a keyset in the configured workspace.
371-
2. Check that the configured client credentials have access to the keyset and workspace.
371+
2. Check that the configured `client` has been granted access to the keyset via the dashboard.
372372
3. Keyset names are case sensitive. If setting the active keyset by name, check that the `keyset_name` is an exact match.
373373

374374

packages/cipherstash-proxy-integration/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ mod passthrough;
1818
mod pipeline;
1919
mod schema_change;
2020
mod select;
21+
mod set_keyset_error;
2122
mod simple_protocol;
2223
mod support;
2324
mod update;

packages/cipherstash-proxy-integration/src/multitenant/set_keyset_id.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
/// IMPORTANT
2+
/// IMPORTANT
3+
///
4+
/// These test assumes that `CS_DEFAULT_KEYSET_ID` has not been set
5+
///
6+
/// The mise integration task splits the `multitenant` tests so that the config can be changed
7+
///
18
#[cfg(test)]
29
mod tests {
310
use crate::common::{

packages/cipherstash-proxy-integration/src/multitenant/set_keyset_name.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
/// IMPORTANT
2+
/// IMPORTANT
3+
///
4+
/// These test assumes that `CS_DEFAULT_KEYSET_ID` has not been set
5+
///
6+
/// The mise integration task splits the `multitenant` tests so that the config can be changed
7+
///
18
#[cfg(test)]
29
mod tests {
310
use crate::common::{
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/// IMPORTANT
2+
/// IMPORTANT
3+
///
4+
/// This test assumes that `CS_DEFAULT_KEYSET_ID`` has been set
5+
///
6+
/// Do not move into the multitenant module,
7+
///
8+
/// The mise integration task splits the `multitenant` tests out so that the config can be changed
9+
///
10+
#[cfg(test)]
11+
mod tests {
12+
use tracing::info;
13+
14+
use crate::common::{connect_with_tls, trace, PROXY};
15+
16+
/// Helper function to assert that a result contains the expected "Cannot SET CIPHERSTASH.KEYSET" error
17+
fn assert_keyset_error<T>(result: Result<T, tokio_postgres::Error>) {
18+
if let Err(err) = result {
19+
let msg = err.to_string();
20+
assert_eq!(msg, "db error: FATAL: Cannot SET CIPHERSTASH.KEYSET if a default keyset has been configured. For help visit https://github.com/cipherstash/proxy/blob/main/docs/errors.md#encrypt-unexpected-set-keyset");
21+
} else {
22+
unreachable!();
23+
}
24+
}
25+
26+
/// Tests error handling of unknown keyset id
27+
#[tokio::test]
28+
async fn set_keyset_id_with_default_config_error() {
29+
trace();
30+
31+
let client = connect_with_tls(PROXY).await;
32+
33+
let sql = "SET CIPHERSTASH.KEYSET_ID = '2cace9db-3a2a-4b46-a184-ba412b3e0730'";
34+
35+
let result = client.query(sql, &[]).await;
36+
info!(?result);
37+
assert!(result.is_err());
38+
39+
assert_keyset_error(result);
40+
41+
let result = client.simple_query(sql).await;
42+
assert!(result.is_err());
43+
44+
assert_keyset_error(result);
45+
}
46+
47+
/// Tests error handling of unknown keyset id
48+
#[tokio::test]
49+
async fn set_keyset_name_with_default_config_error() {
50+
trace();
51+
52+
let client = connect_with_tls(PROXY).await;
53+
54+
let sql = "SET CIPHERSTASH.KEYSET_NAME = 'tenant-1'";
55+
56+
let result = client.query(sql, &[]).await;
57+
assert!(result.is_err());
58+
59+
assert_keyset_error(result);
60+
61+
let result = client.simple_query(sql).await;
62+
assert!(result.is_err());
63+
64+
assert_keyset_error(result);
65+
}
66+
}

0 commit comments

Comments
 (0)