-
Notifications
You must be signed in to change notification settings - Fork 532
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
AES256GCM decrypt: replace Observable with Promise #778
Merged
Merged
Changes from 7 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
c961275
AES256GCM decrypt: replace Observable with Promise
bangtoven 6107ab1
WalletSDKRelay
bangtoven acebeca
fix linter
bangtoven 349616e
prettier
bangtoven d242915
hmmmmm
bangtoven bdf1b16
rejects.toThrowError
bangtoven 4190870
rejects.toThrow
bangtoven 0d0ceae
update comment
bangtoven c41d68c
return promise
bangtoven 23ed8a5
use async / await instead
bangtoven 72ee522
prettier
bangtoven 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 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 |
---|---|---|
|
@@ -12,11 +12,12 @@ describe("aes256gcm", () => { | |
expect(encrypted.length).toEqual(90); | ||
|
||
// decrypted output matches original input | ||
decrypt(encrypted, randSecret).subscribe({ | ||
next: decrypted => { | ||
decrypt(encrypted, randSecret).then( | ||
decrypted => { | ||
expect(decrypted).toBe("plain text string"); | ||
}, | ||
}); | ||
() => {}, | ||
); | ||
}); | ||
|
||
test("decrypt", () => { | ||
|
@@ -31,11 +32,12 @@ describe("aes256gcm", () => { | |
}, | ||
}; | ||
|
||
decrypt(cipherText, secret).subscribe({ | ||
next: value => { | ||
expect(sampleDataResult).toEqual(value); | ||
decrypt(cipherText, secret).then( | ||
value => { | ||
expect(sampleDataResult).toEqual(JSON.parse(value)); | ||
}, | ||
}); | ||
() => {}, | ||
); | ||
}); | ||
|
||
test("errors", async () => { | ||
|
@@ -47,15 +49,6 @@ describe("aes256gcm", () => { | |
"secret must be 256 bits", | ||
); | ||
|
||
await expect( | ||
decrypt("text", secret).subscribe( | ||
() => { | ||
fail("expected error"); | ||
}, | ||
error => { | ||
expect(error).toBe("expected error"); | ||
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. not sure how this worked before as well. 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. |
||
}, | ||
), | ||
); | ||
await expect(decrypt("text", secret)).rejects.toThrow(); | ||
}); | ||
}); |
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
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.
wonder how this has been working
![image](https://user-images.githubusercontent.com/966662/211397944-b538af3a-e4d1-4253-aadc-34113d9f77ee.png)
decrypt returns Promise (or used to be Observable) of string, so
value
(string) andsampleDataResult
(object) couldn't be equal, right?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.
did the observable resolve to the string or was it an object?
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.
it was string as well. i haven't changed the internal data type.
![image](https://user-images.githubusercontent.com/966662/211399445-6dc51c70-89bd-49a0-9fc3-3ce9bf90ac06.png)
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.
I just logged out what the old test returns when run and it seems like it actually returns an object. Incorrect typing on the decrypt function?
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.
@vishnumad i am getting a string with old code
![image](https://user-images.githubusercontent.com/966662/211417988-a45c8339-38ad-4cff-8d77-b646a4c63044.png)
![image](https://user-images.githubusercontent.com/966662/211418098-82ac11b2-45dd-41ae-983b-889eeae8ef12.png)
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.
@bangtoven Yup, you're correct it is a string. This test is just broken and will pass no matter what you do in the subscribe function because it's an observable. You can test this by replacing the current expect with
expect(true).toEqual(false);
. We need to actually block until the observable emits the value.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.
@bangtoven You'll run into a similar issue with the promises in the current test. The test won't actually get marked as failed currently since you're not awaiting the result of the promise.
![image](https://user-images.githubusercontent.com/3137711/211421754-0514806f-8a7d-463b-afc7-4e8229e3db3f.png)
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.
@vishnumad hmm. actually i was able to find type error since the test failed.
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.
@bangtoven It does print the error to console, but doesn't mark the test as failed. See the orange
![image](https://user-images.githubusercontent.com/3137711/211423180-0e78ac93-6c1f-46ee-8b61-fa7d10c38a29.png)
RUNS
next to the last line in the screenshot above vs redFAIL
below when using awaitThere 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.
oh, gotcha. i just made change to the test code to return the promise.then block.