-
Notifications
You must be signed in to change notification settings - Fork 34
[PB-5655] feat(recovery): send backup public keys for validation during account #1805
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
59f430b
feat(recovery): send backup public keys for validation during account…
Dougama f8f3af2
Merge branch 'master' into feat/send-public-keys-on-recovery
douglas-xt 933b69d
fix(backup): only export publicKeys when both ecc and kyber are present
Dougama 6d990bd
Merge branch 'master' into feat/send-public-keys-on-recovery
douglas-xt f025d73
fix(auth): send privateKeys even when publicKeys are missing for back…
Dougama b17b890
Merge branch 'master' into feat/send-public-keys-on-recovery
Dougama 4e22e03
Merge branch 'master' into feat/send-public-keys-on-recovery
douglas-xt 7ff7273
Merge branch 'master' into feat/send-public-keys-on-recovery
CandelR df1f44c
Merge branch 'master' into feat/send-public-keys-on-recovery
CandelR 2ca6625
Merge branch 'master' into feat/send-public-keys-on-recovery
xabg2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -65,17 +65,19 @@ describe('backupKeyUtils', () => { | |
| }); | ||
|
|
||
| describe('handleExportBackupKey', () => { | ||
| it('should export backup key successfully', () => { | ||
| it('When user has valid public keys, then backup should include publicKeys', async () => { | ||
| const mockMnemonic = | ||
| 'whip pipe sphere rail witness sting hawk project east return unhappy focus shop dry midnight frog critic lion horror slide luxury consider vibrant timber'; | ||
| const mockUser = { | ||
| privateKey: 'test-private-key', | ||
| keys: { | ||
| ecc: { | ||
| privateKey: 'test-ecc-private-key', | ||
| publicKey: 'test-ecc-public-key', | ||
| }, | ||
| kyber: { | ||
| privateKey: 'test-kyber-private-key', | ||
| publicKey: 'test-kyber-public-key', | ||
| }, | ||
| }, | ||
| userId: 'test-user-id', | ||
|
|
@@ -107,20 +109,129 @@ describe('backupKeyUtils', () => { | |
|
|
||
| handleExportBackupKey(mockTranslate); | ||
|
|
||
| expect(localStorageService.get).toHaveBeenCalledWith('xMnemonic'); | ||
| expect(localStorageService.getUser).toHaveBeenCalled(); | ||
| expect(saveAs).toHaveBeenCalledWith(expect.any(Blob), 'INTERNXT-BACKUP-KEY.txt'); | ||
|
|
||
| const blobCall = vi.mocked(saveAs).mock.calls[0][0] as Blob; | ||
| const blobContent = await blobCall.text(); | ||
| const parsedBackup = JSON.parse(blobContent); | ||
|
|
||
| expect(parsedBackup.publicKeys).toEqual({ | ||
| ecc: 'test-ecc-public-key', | ||
| kyber: 'test-kyber-public-key', | ||
| }); | ||
|
|
||
| expect(notificationsService.show).toHaveBeenCalledWith({ | ||
| text: mockTranslate('views.account.tabs.security.backupKey.success'), | ||
| type: ToastType.Success, | ||
| }); | ||
| }); | ||
|
|
||
| it('When user has no public keys, then backup should not include publicKeys', async () => { | ||
| const mockMnemonic = | ||
| 'whip pipe sphere rail witness sting hawk project east return unhappy focus shop dry midnight frog critic lion horror slide luxury consider vibrant timber'; | ||
| const mockUser = { | ||
| privateKey: 'test-private-key', | ||
| keys: { | ||
| ecc: { | ||
| privateKey: 'test-ecc-private-key', | ||
| }, | ||
| kyber: { | ||
| privateKey: 'test-kyber-private-key', | ||
| }, | ||
| }, | ||
| userId: 'test-user-id', | ||
| uuid: 'test-uuid', | ||
| email: '[email protected]', | ||
| name: 'Test User', | ||
| lastname: 'User', | ||
| username: 'testuser', | ||
| bridgeUser: 'test-bridge-user', | ||
| bucket: 'test-bucket', | ||
| backupsBucket: null, | ||
| root_folder_id: 0, | ||
| rootFolderId: 'test-root-folder-id', | ||
| rootFolderUuid: 'test-root-folder-uuid', | ||
| sharedWorkspace: false, | ||
| credit: 0, | ||
| publicKey: 'test-public-key', | ||
| revocationKey: 'test-revocation-key', | ||
| appSumoDetails: null, | ||
| registerCompleted: false, | ||
| hasReferralsProgram: false, | ||
| createdAt: new Date(), | ||
| avatar: null, | ||
| emailVerified: false, | ||
| } as UserSettings; | ||
|
|
||
| vi.mocked(localStorageService.get).mockReturnValue(mockMnemonic); | ||
| vi.mocked(localStorageService.getUser).mockReturnValue(mockUser); | ||
|
|
||
| handleExportBackupKey(mockTranslate); | ||
|
|
||
| expect(saveAs).toHaveBeenCalledWith(expect.any(Blob), 'INTERNXT-BACKUP-KEY.txt'); | ||
|
|
||
| const blobCall = vi.mocked(saveAs).mock.calls[0][0] as Blob; | ||
| expect(blobCall.type).toBe('text/plain'); | ||
| const blobContent = await blobCall.text(); | ||
| const parsedBackup = JSON.parse(blobContent); | ||
|
|
||
| expect(parsedBackup.publicKeys).toBeUndefined(); | ||
|
|
||
| expect(notificationsService.show).toHaveBeenCalledWith({ | ||
| text: mockTranslate('views.account.tabs.security.backupKey.success'), | ||
| type: ToastType.Success, | ||
| }); | ||
| }); | ||
|
|
||
| it('When user has only ecc public key, then backup should not include publicKeys', async () => { | ||
| const mockMnemonic = | ||
| 'whip pipe sphere rail witness sting hawk project east return unhappy focus shop dry midnight frog critic lion horror slide luxury consider vibrant timber'; | ||
| const mockUser = { | ||
| privateKey: 'test-private-key', | ||
| keys: { | ||
| ecc: { | ||
| privateKey: 'test-ecc-private-key', | ||
| publicKey: 'test-ecc-public-key', | ||
| }, | ||
| kyber: { | ||
| privateKey: 'test-kyber-private-key', | ||
| }, | ||
| }, | ||
| userId: 'test-user-id', | ||
| uuid: 'test-uuid', | ||
| email: '[email protected]', | ||
| name: 'Test User', | ||
| lastname: 'User', | ||
| username: 'testuser', | ||
| bridgeUser: 'test-bridge-user', | ||
| bucket: 'test-bucket', | ||
| backupsBucket: null, | ||
| root_folder_id: 0, | ||
| rootFolderId: 'test-root-folder-id', | ||
| rootFolderUuid: 'test-root-folder-uuid', | ||
| sharedWorkspace: false, | ||
| credit: 0, | ||
| publicKey: 'test-public-key', | ||
| revocationKey: 'test-revocation-key', | ||
| appSumoDetails: null, | ||
| registerCompleted: false, | ||
| hasReferralsProgram: false, | ||
| createdAt: new Date(), | ||
| avatar: null, | ||
| emailVerified: false, | ||
| } as UserSettings; | ||
|
|
||
| vi.mocked(localStorageService.get).mockReturnValue(mockMnemonic); | ||
| vi.mocked(localStorageService.getUser).mockReturnValue(mockUser); | ||
|
|
||
| handleExportBackupKey(mockTranslate); | ||
|
|
||
| const blobCall = vi.mocked(saveAs).mock.calls[0][0] as Blob; | ||
| const blobContent = await blobCall.text(); | ||
| const parsedBackup = JSON.parse(blobContent); | ||
|
|
||
| expect(parsedBackup.publicKeys).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('should handle missing mnemonic', () => { | ||
| vi.mocked(localStorageService.get).mockReturnValue(null); | ||
| vi.mocked(localStorageService.getUser).mockReturnValue({} as any); | ||
|
|
@@ -192,6 +303,88 @@ describe('backupKeyUtils', () => { | |
| }); | ||
|
|
||
| describe('detectBackupKeyFormat', () => { | ||
| it('When backup has valid publicKeys, then result should include publicKeys', () => { | ||
| const mockBackupData = { | ||
| mnemonic: 'test mnemonic', | ||
| privateKey: 'test-private-key', | ||
| keys: { | ||
| ecc: 'test-ecc-key', | ||
| kyber: 'test-kyber-key', | ||
| }, | ||
| publicKeys: { | ||
| ecc: 'test-ecc-public-key', | ||
| kyber: 'test-kyber-public-key', | ||
| }, | ||
| }; | ||
|
|
||
| const backupKeyContent = JSON.stringify(mockBackupData); | ||
|
|
||
| const result = detectBackupKeyFormat(backupKeyContent); | ||
|
|
||
| expect(result.backupData?.publicKeys).toEqual({ | ||
| ecc: 'test-ecc-public-key', | ||
| kyber: 'test-kyber-public-key', | ||
| }); | ||
| }); | ||
|
|
||
| it('When backup has no publicKeys, then result should not include publicKeys', () => { | ||
| const mockBackupData: BackupData = { | ||
| mnemonic: 'test mnemonic', | ||
| privateKey: 'test-private-key', | ||
| keys: { | ||
| ecc: 'test-ecc-key', | ||
| kyber: 'test-kyber-key', | ||
| }, | ||
| }; | ||
|
|
||
| const backupKeyContent = JSON.stringify(mockBackupData); | ||
|
|
||
| const result = detectBackupKeyFormat(backupKeyContent); | ||
|
|
||
| expect(result.backupData?.publicKeys).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('When backup has only ecc publicKey, then result should not include publicKeys', () => { | ||
| const mockBackupData = { | ||
| mnemonic: 'test mnemonic', | ||
| privateKey: 'test-private-key', | ||
| keys: { | ||
| ecc: 'test-ecc-key', | ||
| kyber: 'test-kyber-key', | ||
| }, | ||
| publicKeys: { | ||
| ecc: 'test-ecc-public-key', | ||
| }, | ||
| }; | ||
|
|
||
| const backupKeyContent = JSON.stringify(mockBackupData); | ||
|
|
||
| const result = detectBackupKeyFormat(backupKeyContent); | ||
|
|
||
| expect(result.backupData?.publicKeys).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('When backup has empty publicKeys, then result should not include publicKeys', () => { | ||
| const mockBackupData = { | ||
| mnemonic: 'test mnemonic', | ||
| privateKey: 'test-private-key', | ||
| keys: { | ||
| ecc: 'test-ecc-key', | ||
| kyber: 'test-kyber-key', | ||
| }, | ||
| publicKeys: { | ||
| ecc: '', | ||
| kyber: '', | ||
| }, | ||
| }; | ||
|
|
||
| const backupKeyContent = JSON.stringify(mockBackupData); | ||
|
|
||
| const result = detectBackupKeyFormat(backupKeyContent); | ||
|
|
||
| expect(result.backupData?.publicKeys).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('should detect new backup key format with full data', () => { | ||
| const mockBackupData: BackupData = { | ||
| mnemonic: 'test mnemonic', | ||
|
|
||
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if doesn't mind, change the test that are modifying to "when X, then Y" format