Skip to content

Searchable json tests #232

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions packages/cipherstash-proxy-integration/src/jsonb/compare.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#[cfg(test)]
mod tests {
use std::collections::HashMap;

use tracing::info;

use crate::common::{clear, connect_with_tls, id, reset_schema, trace, PROXY};

async fn seed_jsonb_data() {
let mut map: HashMap<i64, &str> = HashMap::new();

for (num, word) in (10..=100).step_by(10).zip([
"Alpha", "Bravo", "Charlie", "Delta", "Echo", "Foxtrot", "Golf", "Hotel", "India",
"Juliet",
]) {
map.insert(num, word);
}

let client = connect_with_tls(PROXY).await;
for i in (10..=100).step_by(10) {
// let key = format!()

let id: i64 = i;

let s = map.get(&i).unwrap();

let encrypted_jsonb = serde_json::json!({
"string": s,
"number": i,
"nested": {
"number": i,
"string": s,
}
});

// info!("{encrypted_jsonb:?}");

let sql = "INSERT INTO encrypted (id, encrypted_jsonb) VALUES ($1, $2)";
client.query(sql, &[&id, &encrypted_jsonb]).await.unwrap();
}
}

#[tokio::test]
async fn lt_with_jsonb_path_query() {
trace();

clear().await;

seed_jsonb_data().await;

let client = connect_with_tls(PROXY).await;

let sql = "SELECT encrypted_jsonb FROM encrypted WHERE encrypted_jsonb->'number' < $1";
// let sql = "SELECT encrypted_jsonb FROM encrypted WHERE eql_v1.jsonb_path_query_first(encrypted_jsonb, '$.number') < $1";

// let rows = client.query(sql, &[&n]).await.unwrap();
let rows = client.query(sql, &[]).await.unwrap();

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

for row in rows {
let result: String = row.get("encrypted_jsonb");
info!("{result}");
// assert_eq!(encrypted_text, result);
}
}
}
56 changes: 56 additions & 0 deletions packages/cipherstash-proxy-integration/src/jsonb/map_params.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#[cfg(test)]
mod tests {
use crate::common::{connect_with_tls, id, reset_schema, trace, PROXY};

#[tokio::test]
async fn with_number() {
trace();

let client = connect_with_tls(PROXY).await;

let id = id();
let encrypted_jsonb = serde_json::json!({"key": 42});

let sql = "INSERT INTO encrypted (id, encrypted_jsonb) VALUES ($1, $2)";
client.query(sql, &[&id, &encrypted_jsonb]).await.unwrap();

let sql = "SELECT id, encrypted_jsonb FROM encrypted WHERE id = $1";
let rows = client.query(sql, &[&id]).await.unwrap();

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

for row in rows {
let result_id: i64 = row.get("id");
let result: serde_json::Value = row.get("encrypted_jsonb");

assert_eq!(id, result_id);
assert_eq!(encrypted_jsonb, result);
}
}

#[tokio::test]
async fn with_array() {
trace();

let client = connect_with_tls(PROXY).await;

let id = id();
let encrypted_jsonb = serde_json::json!({"a": [1, 2, 4, 42]});

let sql = "INSERT INTO encrypted (id, encrypted_jsonb) VALUES ($1, $2)";
client.query(sql, &[&id, &encrypted_jsonb]).await.unwrap();

let sql = "SELECT id, encrypted_jsonb FROM encrypted WHERE id = $1";
let rows = client.query(sql, &[&id]).await.unwrap();

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

for row in rows {
let result_id: i64 = row.get("id");
let result: serde_json::Value = row.get("encrypted_jsonb");

assert_eq!(id, result_id);
assert_eq!(encrypted_jsonb, result);
}
}
}
2 changes: 2 additions & 0 deletions packages/cipherstash-proxy-integration/src/jsonb/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mod compare;
mod map_params;
1 change: 1 addition & 0 deletions packages/cipherstash-proxy-integration/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
mod common;
mod empty_result;
mod extended_protocol_error_messages;
mod jsonb;
mod map_concat;
mod map_literals;
mod map_match_index;
Expand Down