-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(service-desk): WebApiCrypto encryption (#14768)
* Create encrypt and decrypt actions to cypher text using the Web Api Crypto library * merged with main * fix test * fix code so test will run on node rather then jsdom * fix build after nullable unmask/mask * fix pr comments * chore: nx format:write update dirty files * fix encryption to be url friendly * chore: nx format:write update dirty files --------- Co-authored-by: Sævar Már Atlason <[email protected]> Co-authored-by: andes-it <[email protected]> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
- Loading branch information
1 parent
a831ebe
commit af29933
Showing
9 changed files
with
216 additions
and
89 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
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,29 +1,34 @@ | ||
/** | ||
* @jest-environment node | ||
*/ | ||
|
||
import { maskString, unmaskString } from './simpleEncryption' | ||
|
||
const originalText = 'Original Jest Text!' | ||
const secretKey = 'not-really-secret-key' | ||
|
||
describe('Encryption and Decryption Functions', () => { | ||
test('Encrypt and decrypt a string successfully', () => { | ||
const encrypted = maskString(originalText, secretKey) | ||
test('Encrypt and decrypt a string successfully', async () => { | ||
const encrypted = await maskString(originalText, secretKey) | ||
|
||
// Check for successful encryption | ||
expect(encrypted).not.toBe(originalText) | ||
expect(encrypted).not.toBeNull() | ||
|
||
// If null check succeeds, we can safely cast to string for the unmasking test | ||
const textToDecrypt = encrypted as string | ||
|
||
// Check for successful decryption | ||
if (encrypted !== null) { | ||
const decrypted = unmaskString(encrypted, secretKey) | ||
expect(decrypted).toBe(originalText) | ||
expect(encrypted).not.toBe(originalText) | ||
} else { | ||
// Fail the test explicitly if encryption failed | ||
fail('Encryption failed') | ||
} | ||
const decrypted = await unmaskString(textToDecrypt, secretKey) | ||
expect(decrypted).toBe(originalText) | ||
expect(encrypted).not.toBe(originalText) | ||
}) | ||
|
||
test('Return null in case of decryption failure', () => { | ||
test('Return null in case of decryption failure', async () => { | ||
// Example: testing decryption failure | ||
const decryptedFailure = unmaskString('invalid-encrypted-text', secretKey) | ||
const decryptedFailure = await unmaskString( | ||
'invalid-encrypted-text', | ||
secretKey, | ||
) | ||
expect(decryptedFailure).toBeNull() | ||
}) | ||
}) |
Oops, something went wrong.