generated from 47ng/typescript-library-starter
-
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: support decrypting strings larger than 4 MiB (#123)
The `cloakedStringRegex` regex fails on ciphertexts larger than 4 MiB. The new `parseCloakedString` in [`@47ng/[email protected]`][1] doesn't have this limitation. [1]: https://github.com/47ng/cloak/releases/tag/v1.2.0 Fixes: #122
- Loading branch information
1 parent
c17354c
commit 8380200
Showing
4 changed files
with
40 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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 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 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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import { cloakedStringRegex } from '@47ng/cloak' | ||
import { createHash } from 'node:crypto' | ||
import fs from 'node:fs/promises' | ||
import path from 'node:path' | ||
import { errors } from '../errors' | ||
|
@@ -453,4 +454,36 @@ describe.each(clients)('integration ($type)', ({ client }) => { | |
expect(received!.name).toEqual(' François') // clear text in returned value | ||
expect(received!.email).toEqual(normalizeTestEmail) | ||
}) | ||
|
||
test('query field with 4 MiB+ data', async () => { | ||
const longNameUser = { | ||
name: 'a'.repeat(4_194_304), | ||
email: '[email protected]' | ||
} as const | ||
await client.user.upsert({ | ||
where: { | ||
email: longNameUser.email | ||
}, | ||
create: longNameUser, | ||
update: longNameUser | ||
}) | ||
const savedUser = await client.user.findUniqueOrThrow({ | ||
where: { | ||
email: longNameUser.email | ||
} | ||
}) | ||
expect(savedUser.email).toStrictEqual(longNameUser.email) | ||
// The encrypted field is larger than the unencrypted field, so just comparing | ||
// the lengths is fine. | ||
expect(savedUser.name?.length).toStrictEqual(longNameUser.name.length) | ||
// Don't test for equality, otherwise we'd fill up the jest log with | ||
// a massive error message if something goes wrong. | ||
expect( | ||
createHash('sha256') | ||
.update(savedUser.name ?? '') | ||
.digest('hex') | ||
).toStrictEqual( | ||
createHash('sha256').update(longNameUser.name).digest('hex') | ||
) | ||
}, 15_000) // storing 4 MiB into the DB is a bit slow | ||
}) |
This file contains 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