-
Notifications
You must be signed in to change notification settings - Fork 11
refactor(crypto): minor refactor of decryptWithAttachments #65
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
Changes from all commits
cf7d5f9
f86ccbb
c129846
0b320d1
5350bae
637f9ec
5ae3cba
9c67a89
b16fa1f
9802e3e
0eedc38
9cce879
0d7817b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import { areAttachmentFieldIdsValid } from '../src/util/crypto' | ||
| describe('utils', () => { | ||
| describe('areAttachmentFieldIdsValid', () => { | ||
| it('should return true when all the fieldIds are within the filenames', () => { | ||
| // Arrange | ||
| const MOCK_FILENAMES = { | ||
| mock: 'file', | ||
| alsomock: 'file2', | ||
| } | ||
| const MOCK_FIELD_IDS = Object.keys(MOCK_FILENAMES) | ||
|
|
||
| // Act | ||
| const actual = areAttachmentFieldIdsValid(MOCK_FIELD_IDS, MOCK_FILENAMES) | ||
|
|
||
| // Assert | ||
| expect(actual).toBe(true) | ||
| }) | ||
|
|
||
| it('should return false when some fieldIds are not within the filenames', () => { | ||
| // Arrange | ||
| const MOCK_FILENAMES = { | ||
| mock: 'file', | ||
| alsomock: 'file2', | ||
| } | ||
| const MOCK_FIELD_IDS = Object.keys(MOCK_FILENAMES).concat('missingField') | ||
|
|
||
| // Act | ||
| const actual = areAttachmentFieldIdsValid(MOCK_FIELD_IDS, MOCK_FILENAMES) | ||
|
|
||
| // Assert | ||
| expect(actual).toBe(false) | ||
| }) | ||
| }) | ||
| }) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,8 +33,16 @@ class WebhookAuthenticateError extends Error { | |
| } | ||
| } | ||
|
|
||
| class AttachmentDecryptionError extends Error { | ||
| constructor(message = 'Attachment decryption with the given nonce failed.') { | ||
| super(message) | ||
| this.name = this.constructor.name | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. out of curiosity, why is this line necessary?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it isn't! i actually left it in because i thought it was convention @__@ i'll remove it!
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i went to investigate more and it was q enlightening for me! the reason why this is done is because it's an error. when js (and by extension, ts) throws an error, the error printed to the output is done using |
||
| } | ||
| } | ||
|
|
||
| export { | ||
| MissingSecretKeyError, | ||
| MissingPublicKeyError, | ||
| WebhookAuthenticateError, | ||
| AttachmentDecryptionError, | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.