Skip to content

Commit ca4c58b

Browse files
committed
fix(tests): proxy jsonb integration tests
1 parent ccdec51 commit ca4c58b

File tree

3 files changed

+37
-10
lines changed

3 files changed

+37
-10
lines changed

packages/cipherstash-proxy-integration/src/insert/insert_with_literal.rs

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ mod tests {
99

1010
macro_rules! test_insert_with_literal {
1111
($name: ident, $type: ident, $pg_type: ident) => {
12+
test_insert_with_literal!($name, $type, $pg_type, false);
13+
};
14+
15+
($name: ident, $type: ident, $pg_type: ident, $cast: expr) => {
1216
#[tokio::test]
1317
pub async fn $name() {
1418
trace();
@@ -22,8 +26,14 @@ mod tests {
2226

2327
let expected = vec![encrypted_val.clone()];
2428

25-
let insert_sql = format!("INSERT INTO encrypted (id, {encrypted_col}) VALUES ($1, '{encrypted_val}')");
26-
let select_sql = format!("SELECT {encrypted_col} FROM encrypted WHERE id = $1");
29+
let cast_to_type: &str = if $cast {
30+
&format!("::{}", stringify!($pg_type))
31+
} else {
32+
""
33+
};
34+
35+
let insert_sql = format!("INSERT INTO encrypted (id, {encrypted_col}) VALUES ($1, '{encrypted_val}'{cast_to_type})");
36+
let select_sql = format!("SELECT {encrypted_col}{cast_to_type} FROM encrypted WHERE id = $1");
2737

2838
execute_query(&insert_sql, &[&id]).await;
2939
let actual = query_by::<$type>(&select_sql, &id).await;
@@ -36,6 +46,10 @@ mod tests {
3646

3747
macro_rules! test_insert_simple_query_with_literal {
3848
($name: ident, $type: ident, $pg_type: ident) => {
49+
test_insert_simple_query_with_literal!($name, $type, $pg_type, false);
50+
};
51+
52+
($name: ident, $type: ident, $pg_type: ident, $cast: expr) => {
3953
#[tokio::test]
4054
pub async fn $name() {
4155
trace();
@@ -48,8 +62,14 @@ mod tests {
4862
let encrypted_col = format!("encrypted_{}", stringify!($pg_type));
4963
let encrypted_val = crate::value_for_type!($type, random_limited());
5064

51-
let insert_sql = format!("INSERT INTO encrypted (id, {encrypted_col}) VALUES ({id}, '{encrypted_val}')");
52-
let select_sql = format!("SELECT {encrypted_col} FROM encrypted WHERE id = {id}");
65+
let cast_to_type: &str = if $cast {
66+
&format!("::{}", stringify!($pg_type))
67+
} else {
68+
""
69+
};
70+
71+
let insert_sql = format!("INSERT INTO encrypted (id, {encrypted_col}) VALUES ({id}, '{encrypted_val}'{cast_to_type})");
72+
let select_sql = format!("SELECT {encrypted_col}{cast_to_type} FROM encrypted WHERE id = {id}");
5373

5474

5575
let expected = vec![encrypted_val];
@@ -69,7 +89,7 @@ mod tests {
6989
test_insert_with_literal!(insert_with_literal_bool, bool, bool);
7090
test_insert_with_literal!(insert_with_literal_text, String, text);
7191
test_insert_with_literal!(insert_with_literal_date, NaiveDate, date);
72-
test_insert_with_literal!(insert_with_literal_jsonb, Value, jsonb);
92+
test_insert_with_literal!(insert_with_literal_jsonb, Value, jsonb, true);
7393

7494
test_insert_simple_query_with_literal!(insert_simple_query_with_literal_int2, i16, int2);
7595
test_insert_simple_query_with_literal!(insert_simple_query_with_literal_int4, i32, int4);
@@ -78,7 +98,12 @@ mod tests {
7898
test_insert_simple_query_with_literal!(insert_simple_query_with_literal_bool, bool, bool);
7999
test_insert_simple_query_with_literal!(insert_simple_query_with_literal_text, String, text);
80100
test_insert_simple_query_with_literal!(insert_simple_query_with_literal_date, NaiveDate, date);
81-
test_insert_simple_query_with_literal!(insert_simple_query_with_literal_jsonb, Value, jsonb);
101+
test_insert_simple_query_with_literal!(
102+
insert_simple_query_with_literal_jsonb,
103+
Value,
104+
jsonb,
105+
true
106+
);
82107

83108
// -----------------------------------------------------------------
84109

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@ mod tests {
5555
let encrypted_jsonb = serde_json::json!({"key": "value"});
5656

5757
let sql = format!(
58-
"INSERT INTO encrypted (id, encrypted_jsonb) VALUES ($1, '{encrypted_jsonb}')",
58+
"INSERT INTO encrypted (id, encrypted_jsonb) VALUES ($1, '{encrypted_jsonb}'::jsonb)",
5959
);
6060

6161
client.query(&sql, &[&id]).await.unwrap();
6262

63-
let sql = "SELECT id, encrypted_jsonb FROM encrypted WHERE id = $1";
63+
let sql = "SELECT id, encrypted_jsonb::jsonb FROM encrypted WHERE id = $1";
6464
let rows = client.query(sql, &[&id]).await.unwrap();
6565

6666
assert_eq!(rows.len(), 1);

tests/benchmark/sql/benchmark-schema.sql

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ SELECT eql_v2.add_column(
1919
'email'
2020
);
2121

22-
SELECT eql_v2.encrypt();
23-
SELECT eql_v2.activate();
22+
-- SELECT eql_v2.encrypt();
23+
-- SELECT eql_v2.activate();
2424

25+
SELECT eql_v2.migrate_config();
26+
SELECT eql_v2.activate_config();

0 commit comments

Comments
 (0)