Skip to content

Refactor crypto_test.go to use Web Platform Tests #4979

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

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

Conversation

paulnegz
Copy link

@paulnegz paulnegz commented Jul 29, 2025

What?

This PR aligns crypto_test.go with the Web Platform Tests (WPT) approach, following the successful pattern established in subtle_crypto_test.go. Specifically:

  1. Removed Static Tests:

    • static test code from crypto_test.go
    • Removed maintenance burden of manually syncing with spec changes
  2. Added WPT Integration:

    • Integrated official test files for core Crypto interface methods:
      • getRandomValues.any.js for testing random value generation
      • randomUUID.https.any.js for UUID functionality testing
    • Tests now run directly against the official W3C test suite
  3. Runtime Compatibility:

    • Created WebCryptoAPI__getRandomValues.any.js.patch for Float16Array handling
    • Implemented graceful feature detection for k6-specific runtime constraints

Why?

This refactoring addresses issue 4268:

  1. Maintainability:

    • Eliminates the challenge of tracking differences between our implementation and the spec
    • Makes deviations from the standard explicit through patch files
    • Follows the successful pattern from grafana/xk6-webcrypto#87
  2. Standards Compliance:

    • Directly tests against WebPlatform test suite
    • Guarantees alignment with WebCrypto API specifications
    • Makes any k6-specific differences transparent to customers through patches
  3. Future-Proofing:

    • Tests automatically stay in sync with web standards evolution
    • Reduces maintenance burden for the k6 team
    • Provides clearer path for future WebCrypto API updates

Implementation Details

The implementation follows the same successful approach used in grafana/xk6-webcrypto#90, ensuring consistency across the WebCrypto API testing suite.

All tests are passing, and the changes maintain full backward compatibility while improving test coverage and maintainability.

Closes 4268

- Replace static hardcoded tests with official WPT tests
- Add getRandomValues.any.js and randomUUID.https.any.js to test suite
- Create WebCryptoAPI__getRandomValues.any.js.patch for Float16Array compatibility
- Remove crypto_test.go with 268 lines of static test code
- Improve maintainability by using standards-compliant WPT tests
- Ensure automatic updates as web standards evolve

Closes grafana#4268
@paulnegz paulnegz requested a review from a team as a code owner July 29, 2025 07:37
@paulnegz paulnegz requested review from inancgumus and ankur22 and removed request for a team July 29, 2025 07:37
@CLAassistant
Copy link

CLAassistant commented Jul 29, 2025

CLA assistant check
All committers have signed the CLA.

@mstoykov mstoykov added this to the v1.3.0 milestone Jul 30, 2025
paulnegz and others added 3 commits July 30, 2025 09:55
…cPushInterval from 1ms to 10ms to ensure flusher gets called\n- Increase test timeout from 1s to 5s to avoid flaky tests\n- Update both TestOutputFlushWorkersStop and TestOutputFlushWorkersAbort
Copy link
Contributor

@ankur22 ankur22 left a comment

Choose a reason for hiding this comment

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

LGTM 🚀

Copy link
Contributor

@inancgumus inancgumus left a comment

Choose a reason for hiding this comment

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

Please fix the linter errors.

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.

Refactor crypto_test.go
5 participants