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

refactor crypto_test.go againts web platform tests #4274

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

aniqaqill
Copy link

@aniqaqill aniqaqill commented Jan 23, 2025

What?

This PR adds Web Platform Tests (WPT) for the Crypto interface in the k6 WebCrypto API implementation.

The tests are integrated into the existing WPT framework, and any necessary patches are applied to ensure compatibility with the k6 runtime.


Why?

These changes ensure that the k6 implementation of the WebCrypto API is compliant with the WebCrypto specification. By running the WPT suite, we can:

  1. Improve Maintainability:

    • Use the WPT suite to catch regressions and ensure consistency with the specification.
  2. Increase Transparency:

    • Make it easier for contributors and users to understand how the k6 implementation aligns with the WebCrypto API.

Checklist

  • I have performed a self-review of my code.
  • I have added tests for my changes.
  • I have run linter locally (make lint) and all checks pass.
  • I have run tests locally (make tests) and all tests pass.
  • I have commented on my code, particularly in hard-to-understand areas.

Related PR(s)/Issue(s)


Changes Made

  1. Updated crypto_test.go:

    • Integrated the WPT test files into the test suite.
  2. Applied Patches:

    • Generated and applied patches to ensure the WPT tests are compatible with the k6 runtime.
  3. Verified Tests:

    • Ran the tests locally to ensure they pass and cover the implemented functionality.

Thanks for your contribution! 🙏🏼

@aniqaqill aniqaqill requested a review from a team as a code owner January 23, 2025 15:51
@aniqaqill aniqaqill requested review from mstoykov and joanlopez and removed request for a team January 23, 2025 15:51
@CLAassistant
Copy link

CLAassistant commented Jan 23, 2025

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

@olegbespalov olegbespalov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @aniqaqill !

Thanks for the opening the pull-request, however I'm not sure if it addresses the need of #4268.

So the predominant point of the #4268 is to migrate from the hardcoded tests (JavaScript code) to running the tests that are part of the web platform test suite.

For instance, TestGetRandomValuesSupportedTypedArrays has a comment that it was based on the https://github.com/web-platform-tests/wpt/blob/75db68b05454e7f3a81e063373defd094c176a16/WebCryptoAPI/getRandomValues.any.js (not I've replaced the master reference to a precise commit that we use for checking out the test).

So the desired state is that instead of current hardcoded logic:

...
_, gotErr := ts.RunOnEventLoop(fmt.Sprintf(`
				var buf = new %s(10);
				crypto.getRandomValues(buf);
				if (buf.length != 10) {
					throw new Error("buf.length != 10");
				}
			`, tc.typedArray))
...

We run the test against the files of web platform tests.

Furthermore, it seems like crypto_test.go just duplicates what is presented in the subtle_crypto_test.go.

Please let me know if you have more questions.

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

Successfully merging this pull request may close these issues.

3 participants