Skip to content

Conversation

@tobyhede
Copy link
Contributor

Add comprehensive Rust/SQLx tests for encrypted data equality operations.

HMAC Index Equality

  • Operator tests with matching encrypted values
  • Operator tests with non-matching encrypted values
  • Plain JSONB comparison validation

Blake3 Index Equality

  • Operator tests with matching encrypted values
  • Operator tests with non-matching encrypted values
  • eq() function tests for exact equality
  • JSONB payload structure preservation (including 'ob' field)

Key Differences Tested

  • HMAC removes 'ob' field during equality comparison
  • Blake3 preserves 'ob' field for complete payload equality
  • Both support operator and function-based equality checks

Migration Status

Like-for-Like Migration: Complete (40/40 SQL assertions ported)

  • Equality operators: 16/16 (HMAC + Blake3, operators + functions + JSONB)
  • JSONB functions: 24/24 (arrays, paths, structure validation, encrypted selectors)

Test Count: 35 tests (34 functional + 1 helper)

These tests ensure encrypted data can be reliably compared for equality using both index-based operators and explicit eq() function calls, maintaining SQL parity across all supported PostgreSQL versions.


Depends on: #139 (JSONB tests)
Completes: SQLx test migration

Add Rust/SQLx tests covering JSONB functionality in encrypted payloads:

**JSONB Array Tests:**
- jsonb_array_elements_text - array element extraction
- jsonb_array_length - array size validation

**JSONB Path Query Tests:**
- jsonb_path_query - complex path expressions
- jsonb_path_query_first - single result queries
- jsonb_path_exists - path existence checks
- Array-specific path operations

**JSONB Structure Tests:**
- Encrypted selector validation (ct, k, i, p, ob fields)
- JSONB field type verification
- Payload structure correctness

**Test Helpers:**
- Function call tracking verification
- Test framework meta-tests

These tests migrate all JSONB-related assertions from the original SQL
test suite to the new Rust/SQLx framework, ensuring consistent behavior
across PostgreSQL versions 14-17.
@tobyhede tobyhede force-pushed the feature/sqlx-jsonb-tests branch from fe685f5 to 28a0eb9 Compare October 27, 2025 00:44
Add comprehensive Rust/SQLx tests for encrypted data equality:

**HMAC Index Equality:**
- Operator tests with matching encrypted values
- Operator tests with non-matching encrypted values
- Plain JSONB comparison validation

**Blake3 Index Equality:**
- Operator tests with matching encrypted values
- Operator tests with non-matching encrypted values
- eq() function tests for exact equality
- JSONB payload structure preservation (including 'ob' field)

**Key Differences Tested:**
- HMAC removes 'ob' field during equality comparison
- Blake3 preserves 'ob' field for complete payload equality
- Both support operator and function-based equality checks

These tests ensure encrypted data can be reliably compared for equality
using both index-based operators and explicit eq() function calls,
maintaining SQL parity across all supported PostgreSQL versions.
@tobyhede tobyhede force-pushed the feature/sqlx-equality-tests branch from 23fd39d to b213d55 Compare October 27, 2025 00:45
@tobyhede tobyhede changed the base branch from feature/sqlx-jsonb-tests to main October 27, 2025 03:18
- Fix assertion count: 513 total (was incorrectly 558)
- Fix migrated count: 56 assertions (equality + JSONB, not 40)
- Recalculate all coverage percentages with correct totals
- Split Task 15 into 8 incremental sub-tasks (15.1-15.9)
- Add index type constants module (tests/sqlx/src/index_types.rs)
- Add fixture schema documentation (tests/sqlx/fixtures/FIXTURE_SCHEMA.md)
- Update success criteria and performance expectations
- Remaining: 457/513 assertions (89.1%) to migrate
Copy link
Contributor

@freshtonic freshtonic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Powering through - LGTM

Fixes 4 HIGH severity issues identified in plan review:

1. Remove duplicate ore table creation
   - Deleted ore_data.sql fixture creation (Task 2, Step 2-3)
   - ore table already exists from migrations/002_install_ore_data.sql
   - Tests now use #[sqlx::test] without fixtures

2. Fix ORE helper function calls
   - Replace create_encrypted_json_with_index(&pool, 42, "ore64")
   - With get_ore_encrypted(&pool, 42) to select from pre-seeded table
   - Applied across Tasks 2-6, 8-9, 12 (all ORE tests)
   - ore table has 'ob' key (ORE_BLOCK), not ore64 index

3. Fix invalid test IDs
   - Replace id=91347 with id=4 for "different record" tests
   - 91347 * 10 = 913470 outside ore range (1-99) → NULL → panic
   - 4 * 10 = 40 is within ore range → valid data
   - Applied in Task 1 (inequality tests)

4. Remove ore_data fixture references
   - Removed all scripts("ore_data") fixture attributes
   - Updated tests to use migrations instead
   - Added comments explaining ore table source

Updated documentation:
- FIXTURE_SCHEMA.md: Document ore from migrations (NOT fixture)
- Added helper function documentation (get_ore_encrypted)
- Added valid id range explanation (1-9 → lookups 10-90)

Coverage: All ORE-related tests now use correct patterns
@tobyhede tobyhede merged commit ac6a360 into main Oct 27, 2025
4 checks passed
@tobyhede tobyhede deleted the feature/sqlx-equality-tests branch October 27, 2025 05:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants