Skip to content
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

Use better asserts in WebCryptoAPI #25083

Open
gsnedders opened this issue Aug 18, 2020 · 2 comments
Open

Use better asserts in WebCryptoAPI #25083

gsnedders opened this issue Aug 18, 2020 · 2 comments

Comments

@gsnedders
Copy link
Member

Currently WebCryptoAPI has a lot of assert_true(equalBuffers(…)) and a bunch of assert_true(equalJwk(…)). Specifically:

   3 assert_false(equalBuffers(
  27 assert_true(equalBuffers(
   1 assert_true(equalExport(
   3 assert_true(equalJwk(

All of these are a bit of an anti-pattern; they mean that the error messages are little more descriptive than "assert_true: Post-wrap export matches original export expected true got false". This is rather little information to go on!

Note that in Safari some of these tests are flaky (see these results) and it's hard to debug what's going on when all I know is true != false.

It would be good to replace equalBuffers with something like the built-in assert_array_equals (and perhaps we should add something built-in to do this, perhaps for typed arrays and data views too, cc @jgraham @stephenmcgruer in case you have views on whether we should have those built-in).

Is there any reason why equalJwk can't use assert_object_equals?

@stephenmcgruer
Copy link
Contributor

I would be happy to see some convenience methods in testharness.js for this; whilst it would increase the API space it seems like they would be fairly clear in their usage.

cc @annevk who put a lot of good thought into assert_array_equals when they reworked it, as it turns out producing useful output for differing array-like objects is tricky.

Is there any reason why equalJwk can't use assert_object_equals?

For a start, we're trying to get rid of (well, at least fix) assert_object_equals (#2033), so I would try to avoid introducing more uses till we do that.

@annevk
Copy link
Member

annevk commented Sep 11, 2020

assert_array_equals([].slice.call(encoded), bytes) is something https://github.com/web-platform-tests/wpt/blob/master/encoding/api-basics.any.js does and it seems reasonable to have assert_view/buffer_equals that does that for you. Or make assert_array_equals also accept a buffer/view on either side, maybe that's even better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants