[WebCryptoAPI] Add tests for argument read order#57614
[WebCryptoAPI] Add tests for argument read order#57614twiss merged 2 commits intoweb-platform-tests:masterfrom
Conversation
f880c2d to
56594eb
Compare
| get name() { | ||
| // Alter the buffer back while calling digest | ||
| buffer[0] = ~buffer[0]; | ||
| return alg; | ||
| }, |
There was a problem hiding this comment.
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 name is only accessed once.
There was a problem hiding this comment.
Ah, interesting question. It's true that it wasn't my intention for this test to check that name is accessed only once, however, I do think WebIDL and WebCrypto are defined as such, because the property is accessed once in step 4 of normalizing an algorithm, and then never thereafter. So I think it should be fine to rely on this?
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.
There was a problem hiding this comment.
it might make it harder to debug what's the cause of this test failing if it does
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.
There was a problem hiding this comment.
Well we might need a separate test then because it sounds like Node.js might not have a conforming bindings implementation?
There was a problem hiding this comment.
All i'm asking is that the getter "switches back" instead of "switching back and forth".
There was a problem hiding this comment.
OK, I've updated the tests. We can separately add more tests for the bindings / argument normalization later.
There was a problem hiding this comment.
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.
Rather than flipping the data on each call to the argument name getter function, restore it to the original value. This makes it easier to distinguish the cause of test failures if the argument name getter is called multiple times.
annevk
left a comment
There was a problem hiding this comment.
By-and-large this seems good, though not sure we needed this many tests. Quality of JS could be improved a bit while here, but I suppose that's largely up to you all.
| get name() { | ||
| // Alter the buffer back while calling digest | ||
| buffer[0] = ~buffer[0]; | ||
| return alg; | ||
| }, |
There was a problem hiding this comment.
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.
| if (buffer.length > 0) { | ||
| if (sourceData[size].length > 0) { | ||
| promise_test(function (test) { | ||
| var buffer = new Uint8Array(sourceData[size]); |
| // Alter the buffer after calling digest | ||
| if (buffer.length > 0) { | ||
| if (sourceData[size].length > 0) { | ||
| promise_test(function (test) { |
There was a problem hiding this comment.
If we are going to reformat anyway, might as well adopt async/await?
There was a problem hiding this comment.
I didn't really reformat anything here, I just added an if around it. I can refactor this and other tests in a followup.
| .digest({ name: alg, length: length }, buffer) | ||
| .then(function (result) { | ||
| // Alter the buffer after calling digest | ||
| buffer[0] = ~buffer[0]; |
There was a problem hiding this comment.
We should also alter it immediately after calling digest. In fact, that would be the superior test as this would be redundant with that.
There was a problem hiding this comment.
Yeah this test is wrong, I fixed that in #57616.
|
Fair enough :D I mostly just copy+pasted all the instances of the "modify the buffer after the call" tests and modified them mechanically. I also thought having all the algorithms at least might be useful since some implementations implement some of them synchronously and others not, but it seems the implementations are consistent between algorithms at least, indeed. |
|
There are no reviewers for this pull request besides its author. Please reach out on the chat room to get help with this. Thank you! |
The specification of WebCrypto and Modern Algorithms in WebCrypto has updated to reorder reading algorithm and data arguments in "encrypt", "decrypt", "sign", "verify", "digest", "importKey", "unwrapKey", "decapsulateKey" and "decapsulateBits" methods. WebCrypto: w3c/webcrypto@5b57233 Modern Algorithms in WebCrypto: WICG/webcrypto-modern-algos@ae72ee6 This patch updates our implementation accordingly. Testing: Pass new WPT tests added in web-platform-tests/wpt#57614 and servo#42925 Signed-off-by: Kingsley Yung <[email protected]>
…2927) The specification of WebCrypto and Modern Algorithms in WebCrypto has updated to reorder reading algorithm and data arguments in "encrypt", "decrypt", "sign", "verify", "digest", "importKey", "unwrapKey", "decapsulateKey" and "decapsulateBits" methods. This patch updates our implementation accordingly. The relevant commits in specification repositories: - WebCrypto: w3c/webcrypto@5b57233 - Modern Algorithms in WebCrypto: WICG/webcrypto-modern-algos@ae72ee6 Testing: Pass new WPT tests added in web-platform-tests/wpt#57614 and #42925 Signed-off-by: Kingsley Yung <[email protected]>
…2927) The specification of WebCrypto and Modern Algorithms in WebCrypto has updated to reorder reading algorithm and data arguments in "encrypt", "decrypt", "sign", "verify", "digest", "importKey", "unwrapKey", "decapsulateKey" and "decapsulateBits" methods. This patch updates our implementation accordingly. The relevant commits in specification repositories: - WebCrypto: w3c/webcrypto@5b57233 - Modern Algorithms in WebCrypto: WICG/webcrypto-modern-algos@ae72ee6 Testing: Pass new WPT tests added in web-platform-tests/wpt#57614 and #42925 Signed-off-by: Kingsley Yung <[email protected]>
…rvo#42927) The specification of WebCrypto and Modern Algorithms in WebCrypto has updated to reorder reading algorithm and data arguments in "encrypt", "decrypt", "sign", "verify", "digest", "importKey", "unwrapKey", "decapsulateKey" and "decapsulateBits" methods. This patch updates our implementation accordingly. The relevant commits in specification repositories: - WebCrypto: w3c/webcrypto@5b57233 - Modern Algorithms in WebCrypto: WICG/webcrypto-modern-algos@ae72ee6 Testing: Pass new WPT tests added in web-platform-tests/wpt#57614 and servo#42925 Signed-off-by: Kingsley Yung <[email protected]>
Add tests for the reading order of arguments in Web Crypto, updated in w3c/webcrypto#426 to match the majority of implementations.
To be merged after w3c/webcrypto#426.