-
Notifications
You must be signed in to change notification settings - Fork 1
feat(proxy): support OPE index type #390
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3825daf
feat(ope): add ope index type alongside ore
freshtonic 3931e9c
test(integration): give each ORE/OPE test its own fixture table
freshtonic 470e560
docs(ope): document ope index type and add parse unit test
freshtonic 97eeba1
chore: fmt
freshtonic 951fba2
test(ope): vary text fixture lengths; tidy changelog and assertions
freshtonic b7a297e
refactor(test): dedup ORE/OPE fixtures and ordering test helpers
freshtonic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
146 changes: 146 additions & 0 deletions
146
packages/cipherstash-proxy-integration/src/map_ope_index_order.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,146 @@ | ||
| #[cfg(test)] | ||
| mod tests { | ||
| use crate::common::{ | ||
| clear_table, connect_with_tls, interleaved_indices, random_id, trace, PROXY, | ||
| }; | ||
| use std::fmt::Debug; | ||
| use tokio_postgres::types::{FromSql, ToSql}; | ||
|
|
||
| #[tokio::test] | ||
| async fn map_ope_order_text_asc() { | ||
| run_order_test( | ||
| "encrypted_ope_order_text_asc", | ||
| "encrypted_text", | ||
| text_values(), | ||
| false, | ||
| ) | ||
| .await; | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn map_ope_order_text_desc() { | ||
| run_order_test( | ||
| "encrypted_ope_order_text_desc", | ||
| "encrypted_text", | ||
| text_values(), | ||
| true, | ||
| ) | ||
| .await; | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn map_ope_order_int4_asc() { | ||
| run_order_test( | ||
| "encrypted_ope_order_int4_asc", | ||
| "encrypted_int4", | ||
| vec![-100i32, -1, 0, 1, 42, 1000, i32::MAX], | ||
| false, | ||
| ) | ||
| .await; | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn map_ope_order_int4_desc() { | ||
| run_order_test( | ||
| "encrypted_ope_order_int4_desc", | ||
| "encrypted_int4", | ||
| vec![-100i32, -1, 0, 1, 42, 1000, i32::MAX], | ||
| true, | ||
| ) | ||
| .await; | ||
| } | ||
|
|
||
| fn text_values() -> Vec<String> { | ||
| ["aardvark", "aplomb", "chimera", "chrysalis", "zephyr"] | ||
| .iter() | ||
| .map(|s| s.to_string()) | ||
| .collect() | ||
| } | ||
|
|
||
| /// Inserts `values` (given in ascending order) in interleaved order, then | ||
| /// verifies `ORDER BY {col_name}` returns them sorted in the requested | ||
| /// direction. | ||
| async fn run_order_test<T>(table: &str, col_name: &str, values: Vec<T>, descending: bool) | ||
| where | ||
| for<'a> T: PartialEq + ToSql + Sync + FromSql<'a> + Debug, | ||
| { | ||
| trace(); | ||
| clear_table(table).await; | ||
| let client = connect_with_tls(PROXY).await; | ||
|
|
||
| let insert = format!("INSERT INTO {table} (id, {col_name}) VALUES ($1, $2)"); | ||
| for idx in interleaved_indices(values.len()) { | ||
| client | ||
| .query(&insert, &[&random_id(), &values[idx]]) | ||
| .await | ||
| .unwrap(); | ||
| } | ||
|
|
||
| let dir = if descending { "DESC" } else { "ASC" }; | ||
| let select = format!("SELECT {col_name} FROM {table} ORDER BY {col_name} {dir}"); | ||
| let rows = client.query(&select, &[]).await.unwrap(); | ||
|
|
||
| let actual: Vec<T> = rows.iter().map(|r| r.get(0)).collect(); | ||
| let expected: Vec<T> = if descending { | ||
| values.into_iter().rev().collect() | ||
| } else { | ||
| values | ||
| }; | ||
| assert_eq!(actual, expected); | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn map_ope_order_nulls_last_by_default() { | ||
| trace(); | ||
| let table = "encrypted_ope_order_nulls_last"; | ||
| clear_table(table).await; | ||
| let client = connect_with_tls(PROXY).await; | ||
|
|
||
| let null_insert = format!("INSERT INTO {table} (id) VALUES ($1)"); | ||
| client.query(&null_insert, &[&random_id()]).await.unwrap(); | ||
|
|
||
| let insert = format!("INSERT INTO {table} (id, encrypted_text) VALUES ($1, $2), ($3, $4)"); | ||
| client | ||
| .query(&insert, &[&random_id(), &"a", &random_id(), &"b"]) | ||
| .await | ||
| .unwrap(); | ||
|
|
||
| let select = format!("SELECT encrypted_text FROM {table} ORDER BY encrypted_text"); | ||
| let rows = client.query(&select, &[]).await.unwrap(); | ||
|
|
||
| let actual: Vec<Option<String>> = rows.iter().map(|r| r.get(0)).collect(); | ||
| assert_eq!( | ||
| actual, | ||
| vec![Some("a".into()), Some("b".into()), None], | ||
| "NULLs should sort last by default" | ||
| ); | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn map_ope_order_nulls_first() { | ||
| trace(); | ||
| let table = "encrypted_ope_order_nulls_first"; | ||
| clear_table(table).await; | ||
| let client = connect_with_tls(PROXY).await; | ||
|
|
||
| let insert = format!("INSERT INTO {table} (id, encrypted_text) VALUES ($1, $2), ($3, $4)"); | ||
| client | ||
| .query(&insert, &[&random_id(), &"a", &random_id(), &"b"]) | ||
| .await | ||
| .unwrap(); | ||
|
|
||
| let null_insert = format!("INSERT INTO {table} (id) VALUES ($1)"); | ||
| client.query(&null_insert, &[&random_id()]).await.unwrap(); | ||
|
|
||
| let select = | ||
| format!("SELECT encrypted_text FROM {table} ORDER BY encrypted_text NULLS FIRST"); | ||
| let rows = client.query(&select, &[]).await.unwrap(); | ||
|
|
||
| let actual: Vec<Option<String>> = rows.iter().map(|r| r.get(0)).collect(); | ||
| assert_eq!( | ||
| actual, | ||
| vec![None, Some("a".into()), Some("b".into())], | ||
| "NULLS FIRST should explicitly sort NULLs first" | ||
| ); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Guard table names before building
TRUNCATESQL.Line 95 interpolates
tabledirectly into SQL. Even in tests, this helper ispuband can execute unintended SQL if passed unexpected input. Constrain fixture table names before formatting.Suggested hardening
pub async fn clear_table_with_client(client: &Client, table: &str) { + assert!( + table + .chars() + .all(|c| c.is_ascii_lowercase() || c.is_ascii_digit() || c == '_'), + "invalid fixture table name: {table}" + ); let sql = format!("TRUNCATE {}", table); client.simple_query(&sql).await.unwrap(); }📝 Committable suggestion
🤖 Prompt for AI Agents