Skip to content
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

feat: Add support for filtering encrypted field by list of values #120

Open
wants to merge 2 commits into
base: next
Choose a base branch
from

Conversation

SteveKekacs
Copy link

@SteveKekacs SteveKekacs commented Aug 8, 2024

Took a stab at implementing a fix for #119.

@coveralls
Copy link

coveralls commented Aug 8, 2024

Pull Request Test Coverage Report for Build 10309403851

Details

  • 10 of 12 (83.33%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.5%) to 78.754%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/encryption.ts 10 12 83.33%
Totals Coverage Status
Change from base Build 10298732511: -0.5%
Covered Lines: 274
Relevant Lines: 327

💛 - Coveralls

@SteveKekacs SteveKekacs marked this pull request as ready for review August 8, 2024 20:57
@SteveKekacs SteveKekacs changed the title feat: Add support for filtering encrypted field in list of values feat: Add support for filtering encrypted field by list of values Aug 8, 2024
Copy link
Member

@franky47 franky47 left a comment

Choose a reason for hiding this comment

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

Thanks for this feature!

A couple of things could do with some changes (field naming and checking for arrays), otherwise it looks good.

@@ -67,7 +67,7 @@ export function encryptOnWrite<Models extends string, Actions extends string>(
models,
function encryptFieldValue({
fieldConfig,
value: clearText,
value: unHashedValue,
Copy link
Member

Choose a reason for hiding this comment

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

suggestion: Keep the original clearText name, as the value is not only used for hashing, but also for encryption in most (writing) cases.

Comment on lines 88 to 89
if (typeof unHashedValue === 'object') {
hash = (unHashedValue as string[]).map((value) => hashString(value, fieldConfigHash));
Copy link
Member

Choose a reason for hiding this comment

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

suggestion: Use the Array.isArray function, to make the intent clearer. It also removes the need for the as string[] type casting.


// Encrypting list values is not yet supported
if (typeof unHashedValue !== 'string') {
return;
Copy link
Member

Choose a reason for hiding this comment

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

suggestion: Could we add a log point to this code path, for debugging? It's unlikely we'll hit it with Prisma's current API AFAIK, but it would make it easier to catch issues in the future.

(
// Used for where: { field: in: []} queries
typeof (node as any)?.[specialSubField] === 'string' ||
typeof (node as any)?.[specialSubField] === 'object'
Copy link
Member

Choose a reason for hiding this comment

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

suggestion: Same test here, using Array.isArray.

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