-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53527 from callstack-internal/feat/mask-emails-wi…
…th-random-email refactor: mask emails with random strings instead of ***
- Loading branch information
Showing
4 changed files
with
112 additions
and
12 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
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,4 @@ | ||
import ExportOnyxState from '@libs/ExportOnyxState/common'; | ||
import * as ExportOnyxState from '@libs/ExportOnyxState/common'; | ||
import type * as OnyxTypes from '@src/types/onyx'; | ||
|
||
type ExampleOnyxState = { | ||
|
@@ -40,6 +40,49 @@ describe('maskOnyxState', () => { | |
|
||
expect(result.session.authToken).toBe('***'); | ||
expect(result.session.encryptedAuthToken).toBe('***'); | ||
expect(result.session.email).toBe('***'); | ||
}); | ||
|
||
it('should mask emails as a string value in property with a random email', () => { | ||
const input = { | ||
session: mockSession, | ||
}; | ||
|
||
const result = ExportOnyxState.maskOnyxState(input) as ExampleOnyxState; | ||
|
||
expect(result.session.email).toMatch(ExportOnyxState.emailRegex); | ||
}); | ||
|
||
it('should mask array of emails with random emails', () => { | ||
const input = { | ||
session: mockSession, | ||
emails: ['[email protected]', '[email protected]'], | ||
}; | ||
|
||
const result = ExportOnyxState.maskOnyxState(input, true) as Record<string, string[]>; | ||
|
||
expect(result.emails.at(0)).toMatch(ExportOnyxState.emailRegex); | ||
expect(result.emails.at(1)).toMatch(ExportOnyxState.emailRegex); | ||
}); | ||
|
||
it('should mask emails in keys of objects', () => { | ||
const input = { | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
'[email protected]': 'value', | ||
session: mockSession, | ||
}; | ||
|
||
const result = ExportOnyxState.maskOnyxState(input, true) as Record<string, string>; | ||
|
||
expect(Object.keys(result).at(0)).toMatch(ExportOnyxState.emailRegex); | ||
}); | ||
|
||
it('should mask emails that are part of a string', () => { | ||
const input = { | ||
session: mockSession, | ||
emailString: '[email protected] is a test string', | ||
}; | ||
|
||
const result = ExportOnyxState.maskOnyxState(input, true) as Record<string, string>; | ||
expect(result.emailString).not.toContain('[email protected]'); | ||
}); | ||
}); |