|
| 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