-
Notifications
You must be signed in to change notification settings - Fork 3.8k
[WebCryptoAPI] Add tests for argument read order #57614
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
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 |
|---|---|---|
|
|
@@ -171,26 +171,42 @@ Object.keys(digestedData).forEach(function (alg) { | |
| }); | ||
| }, alg + ' with ' + length + ' bit output and ' + size + ' source data'); | ||
|
|
||
| promise_test(function (test) { | ||
| var buffer = new Uint8Array(sourceData[size]); | ||
| return crypto.subtle | ||
| .digest({ name: alg, length: length }, buffer) | ||
| .then(function (result) { | ||
| // Alter the buffer after calling digest | ||
| if (buffer.length > 0) { | ||
| if (sourceData[size].length > 0) { | ||
| promise_test(function (test) { | ||
| var buffer = new Uint8Array(sourceData[size]); | ||
|
Member
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. const |
||
| // Alter the buffer before calling digest | ||
| buffer[0] = ~buffer[0]; | ||
| return crypto.subtle | ||
| .digest({ | ||
| get name() { | ||
| // Alter the buffer back while calling digest | ||
| buffer[0] = sourceData[size][0]; | ||
| return alg; | ||
| }, | ||
|
Comment on lines
+181
to
+185
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. Shouldn't this and all the others using the same pattern truly alter the buffer back instead of continuously switching it back and forth? Otherwise it's dependant on that the
Member
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. Ah, interesting question. It's true that it wasn't my intention for this test to check that Then again, it might make it harder to debug what's the cause of this test failing if it does, and of course this is not quite a proper test of the property being accessed once as it would also pass if it's accessed three times :D So, we could also split that up, if we think the latter is worth testing.
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.
Exactly where i'm coming from. I'm not interested in testing that algorithm properties are only accessed once. Nor in the order itself FWIW but here we are. Optimizations that we have in Node.js rule out this proposed test pattern.
Member
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. Well we might need a separate test then because it sounds like Node.js might not have a conforming bindings implementation?
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. All i'm asking is that the getter "switches back" instead of "switching back and forth".
Member
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. OK, I've updated the tests. We can separately add more tests for the bindings / argument normalization later.
Member
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 understand what you're asking for, but since you're supposed to only call these once and in order, we'd be hiding a bug of sorts by removing coverage for that. |
||
| length | ||
| }, buffer) | ||
| .then(function (result) { | ||
| assert_true( | ||
| equalBuffers(result, digestedData[alg][length][size]), | ||
| 'digest matches expected' | ||
| ); | ||
| }); | ||
| }, alg + ' with ' + length + ' bit output and ' + size + ' source data and altered buffer during call'); | ||
|
|
||
| promise_test(function (test) { | ||
| var buffer = new Uint8Array(sourceData[size]); | ||
| return crypto.subtle | ||
| .digest({ name: alg, length: length }, buffer) | ||
| .then(function (result) { | ||
| // Alter the buffer after calling digest | ||
| buffer[0] = ~buffer[0]; | ||
|
Member
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. We should also alter it immediately after calling digest. In fact, that would be the superior test as this would be redundant with that.
Member
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. Yeah this test is wrong, I fixed that in #57616. |
||
| } | ||
| assert_true( | ||
| equalBuffers(result, digestedData[alg][length][size]), | ||
| 'digest matches expected' | ||
| ); | ||
| }); | ||
| }, alg + | ||
| ' with ' + | ||
| length + | ||
| ' bit output and ' + | ||
| size + | ||
| ' source data and altered buffer after call'); | ||
| assert_true( | ||
| equalBuffers(result, digestedData[alg][length][size]), | ||
| 'digest matches expected' | ||
| ); | ||
| }); | ||
| }, alg + ' with ' + length + ' bit output and ' + size + ' source data and altered buffer after call'); | ||
| } | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
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 we are going to reformat anyway, might as well adopt async/await?
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 didn't really reformat anything here, I just added an
ifaround it. I can refactor this and other tests in a followup.