Skip to content

Commit f25bf53

Browse files
committed
fix(protect): fix flaky escaped-containment test comparing non-deterministic ciphertexts
The test encrypted the same plaintext twice and compared ciphertexts directly, which fails because encryption is non-deterministic. Instead, verify the escaped format structurally and use the unwrapped value directly for the PG query.
1 parent 2d9d397 commit f25bf53

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

packages/protect/__tests__/searchable-json-pg.test.ts

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -687,14 +687,6 @@ describe('searchableJson postgres integration', () => {
687687
RETURNING id
688688
`
689689

690-
const compositeResult = await protectClient.encryptQuery({ role: 'escaped-containment-test' }, {
691-
column: table.metadata,
692-
table: table,
693-
queryType: 'steVecTerm',
694-
returnType: 'composite-literal',
695-
})
696-
if (compositeResult.failure) throw new Error(compositeResult.failure.message)
697-
698690
const escapedResult = await protectClient.encryptQuery({ role: 'escaped-containment-test' }, {
699691
column: table.metadata,
700692
table: table,
@@ -709,14 +701,15 @@ describe('searchableJson postgres integration', () => {
709701
expect(escapedData).toMatch(/^"\(.*\)"$/)
710702
const unwrapped = JSON.parse(escapedData)
711703

712-
const compositeData = compositeResult.data as string
713-
expect(unwrapped).toBe(compositeData)
704+
// Unwrapped escaped format should be a valid composite-literal
705+
expect(typeof unwrapped).toBe('string')
706+
expect(unwrapped).toMatch(/^\(.*\)$/)
714707

715-
// Use composite-literal form to query PG
708+
// Use unwrapped composite-literal form to query PG
716709
const rows = await sql`
717710
SELECT id, (metadata).data as metadata
718711
FROM "protect-ci-jsonb"
719-
WHERE metadata @> ${compositeData}::eql_v2_encrypted
712+
WHERE metadata @> ${unwrapped}::eql_v2_encrypted
720713
AND test_run_id = ${TEST_RUN_ID}
721714
`
722715

0 commit comments

Comments
 (0)