Skip to content

Commit 124db7c

Browse files
authored
Merge pull request #284 from cipherstash/jsonb-array-functions
Integration tests for jsonb array functions
2 parents 034b660 + f4ec4ab commit 124db7c

File tree

15 files changed

+366
-194
lines changed

15 files changed

+366
-194
lines changed

Cargo.lock

Lines changed: 195 additions & 180 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ debug = true
4343

4444
[workspace.dependencies]
4545
sqltk = { version = "0.10.0" }
46-
cipherstash-client = "0.23.0"
46+
cipherstash-client = "0.25.0"
47+
cts-common = { version = "0.3.0" }
4748
thiserror = "2.0.9"
4849
tokio = { version = "1.44.2", features = ["full"] }
4950
tracing = "0.1"

mise.toml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ CS_PROXY__HOST = "proxy"
3131
# Misc
3232
DOCKER_CLI_HINTS = "false" # Please don't show us What's Next.
3333

34-
CS_EQL_VERSION = "eql-2.1.4"
34+
CS_EQL_VERSION = "eql-2.1.5"
3535

3636

3737
[tools]
@@ -92,7 +92,12 @@ if [ "${CS_DATABASE__HOST}" == "localhost" ]; then
9292
fi
9393
9494
# run the container
95-
echo docker compose up {{arg(name="service",default="proxy")}} {{option(name="extra-args",default="")}} | bash
95+
if ! echo docker compose up {{arg(name="service",default="proxy")}} {{option(name="extra-args",default="")}} | bash; then
96+
echo "Error occurred during docker compose up, showing container logs:"
97+
docker logs --timestamps --follow proxy
98+
exit 1
99+
fi
100+
96101
"""
97102

98103
[tasks."proxy:psql"]
@@ -478,10 +483,6 @@ done
478483
alias = 'e'
479484
description = "Download latest EQL release or use local copy"
480485
dir = "{{config_root}}/tests"
481-
outputs = [
482-
"{{config_root}}/cipherstash-encrypt.sql",
483-
"{{config_root}}/cipherstash-encrypt-uninstall.sql",
484-
]
485486
run = """
486487
# install script
487488
if [ -z "$CS_EQL_PATH" ]; then

packages/cipherstash-proxy-integration/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ version = "0.1.0"
44
edition = "2021"
55

66
[dependencies]
7+
aws-lc-rs = "1.13.3"
78
bytes = "1.10.1"
89
cipherstash-client = { workspace = true, features = ["tokio"] }
910
cipherstash-config = "0.2.3"
1011
cipherstash-proxy = { path = "../cipherstash-proxy/" }
1112
chrono = { version = "0.4.39", features = ["clock"] }
1213
clap = "4.5.32"
1314
fake = { version = "4", features = ["chrono", "derive"] }
14-
1515
hex = "0.4.3"
1616
postgres-types = { version = "0.2.9", features = ["derive"] }
1717
rand = "0.9"

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,8 @@ pub async fn insert_jsonb_for_search() {
268268
///
269269
/// This is because the test database uses a self-signed certificate.
270270
pub fn configure_test_client() -> ClientConfig {
271+
let _ = rustls::crypto::aws_lc_rs::default_provider().install_default();
272+
271273
let verifier = DangerousTestCertVerifier;
272274
rustls::ClientConfig::builder()
273275
.dangerous()
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#[cfg(test)]
2+
mod tests {
3+
use crate::common::{clear, insert_jsonb, query_by, simple_query, trace};
4+
use crate::support::assert::assert_expected;
5+
use crate::support::json_path::JsonPath;
6+
use serde_json::Value;
7+
8+
async fn select_jsonb(selector: &str, expected: &[Value]) {
9+
let selector = JsonPath::new(selector);
10+
11+
let sql =
12+
"SELECT jsonb_array_elements(jsonb_path_query(encrypted_jsonb, $1)) FROM encrypted";
13+
let actual = query_by::<Value>(sql, &selector).await;
14+
15+
assert_expected(expected, &actual);
16+
17+
let sql = format!("SELECT jsonb_array_elements(jsonb_path_query(encrypted_jsonb, '{selector}')) FROM encrypted");
18+
let actual = simple_query::<Value>(&sql).await;
19+
20+
assert_expected(expected, &actual);
21+
}
22+
23+
#[tokio::test]
24+
async fn select_jsonb_array_elements_with_string() {
25+
trace();
26+
27+
clear().await;
28+
insert_jsonb().await;
29+
30+
let expected = vec![Value::from("hello"), Value::from("world")];
31+
select_jsonb("$.array_string[@]", &expected).await;
32+
}
33+
34+
#[tokio::test]
35+
async fn select_jsonb_array_elements_with_numeric() {
36+
trace();
37+
38+
clear().await;
39+
insert_jsonb().await;
40+
41+
let expected = vec![Value::from(42), Value::from(84)];
42+
select_jsonb("$.array_number[@]", &expected).await;
43+
}
44+
45+
#[tokio::test]
46+
async fn select_jsonb_array_elements_with_unknown_field() {
47+
trace();
48+
49+
clear().await;
50+
insert_jsonb().await;
51+
52+
let expected = vec![];
53+
select_jsonb("$.blah", &expected).await;
54+
}
55+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#[cfg(test)]
2+
mod tests {
3+
use crate::common::{clear, insert_jsonb, query_by, simple_query, trace};
4+
use crate::support::assert::assert_expected;
5+
use crate::support::json_path::JsonPath;
6+
7+
async fn select_jsonb(selector: &str, expected: i32) {
8+
let selector = JsonPath::new(selector);
9+
10+
let sql = "SELECT jsonb_array_length(jsonb_path_query(encrypted_jsonb, $1)) FROM encrypted";
11+
let actual = query_by::<i32>(sql, &selector).await;
12+
13+
if expected == 0 {
14+
assert!(actual.is_empty());
15+
} else {
16+
let expected = vec![expected];
17+
assert_expected(&expected, &actual);
18+
}
19+
20+
let sql = format!("SELECT jsonb_array_length(jsonb_path_query(encrypted_jsonb, '{selector}')) FROM encrypted");
21+
let actual = simple_query::<i32>(&sql).await;
22+
23+
if expected == 0 {
24+
assert!(actual.is_empty());
25+
} else {
26+
let expected = vec![expected];
27+
assert_expected(&expected, &actual);
28+
}
29+
}
30+
31+
#[tokio::test]
32+
async fn select_jsonb_array_length_with_string() {
33+
trace();
34+
35+
clear().await;
36+
insert_jsonb().await;
37+
38+
select_jsonb("$.array_string[@]", 2).await;
39+
}
40+
41+
#[tokio::test]
42+
async fn select_jsonb_array_length_with_numeric() {
43+
trace();
44+
45+
clear().await;
46+
47+
insert_jsonb().await;
48+
49+
select_jsonb("$.array_number[@]", 2).await;
50+
}
51+
52+
#[tokio::test]
53+
async fn select_jsonb_array_length_with_unknown_field() {
54+
trace();
55+
56+
clear().await;
57+
insert_jsonb().await;
58+
59+
select_jsonb("$.blah", 0).await;
60+
}
61+
}

packages/cipherstash-proxy-integration/src/select/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
mod group_by;
2+
mod jsonb_array_elements;
3+
mod jsonb_array_length;
24
mod jsonb_contained_by;
35
mod jsonb_contains;
46
mod jsonb_get_field;
@@ -10,6 +12,7 @@ mod order_by;
1012
mod order_by_with_null;
1113
mod pg_catalog;
1214
mod regression;
15+
mod select_domain_type;
1316
mod select_where_jsonb_eq;
1417
mod select_where_jsonb_gt;
1518
mod select_where_jsonb_gte;

packages/cipherstash-proxy/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ version = "2.0.0"
44
edition = "2021"
55

66
[dependencies]
7+
aws-lc-rs = "1.13.3"
78
bigdecimal = { version = "0.4.6", features = ["serde-json"] }
89
arc-swap = "1.7.1"
910
bytes = { version = "1.9", default-features = false }
@@ -16,7 +17,7 @@ config = { version = "0.15", features = [
1617
"json",
1718
"toml",
1819
], default-features = false }
19-
cts-common = { version = "0.3.0" }
20+
cts-common = { workspace = true }
2021
eql-mapper = { path = "../eql-mapper" }
2122
exitcode = "1.1.2"
2223
hex = "0.4.3"
@@ -30,7 +31,6 @@ postgres-protocol = "0.6.7"
3031
postgres-types = { version = "0.2.8", features = ["with-serde_json-1"] }
3132
rand = "0.9"
3233
regex = "1.11.1"
33-
ring = { version = "0.17", default-features = false }
3434
rust_decimal = { version = "1.36.0", default-features = false, features = [
3535
"db-postgres",
3636
] }
@@ -56,6 +56,7 @@ uuid = { version = "1.11.0", features = ["serde", "v4"] }
5656
x509-parser = "0.17.0"
5757
vitaminc-protected = "0.1.0-pre2"
5858

59+
5960
[dev-dependencies]
6061
recipher = "0.1.3"
6162
temp-env = "0.3.6"

packages/cipherstash-proxy/src/connect/async_stream.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
use super::{configure, connect_with_retry};
22
use crate::{error::Error, log::AUTHENTICATION};
3+
use aws_lc_rs::digest;
34
use core::str;
45
use oid_registry::{
56
Oid, OID_HASH_SHA1, OID_NIST_HASH_SHA256, OID_NIST_HASH_SHA384, OID_NIST_HASH_SHA512,
67
OID_PKCS1_SHA1WITHRSA, OID_PKCS1_SHA256WITHRSA, OID_PKCS1_SHA384WITHRSA,
78
OID_PKCS1_SHA512WITHRSA, OID_SIG_ECDSA_WITH_SHA256, OID_SIG_ECDSA_WITH_SHA384, OID_SIG_ED25519,
89
};
910
use postgres_protocol::authentication::sasl::ChannelBinding;
10-
use ring::digest;
11+
1112
use std::{
1213
pin::Pin,
1314
task::{Context, Poll},

0 commit comments

Comments
 (0)