Skip to content

crypto: allow inspecting a crypto key prototype #57890

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 1 commit into
base: main
Choose a base branch
from

Conversation

BridgeAR
Copy link
Member

This would fail so far due to accessing a undefined property.

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/crypto

@nodejs-github-bot nodejs-github-bot added crypto Issues and PRs related to the crypto subsystem. needs-ci PRs that need a full CI run. labels Apr 15, 2025
@BridgeAR BridgeAR changed the title crypto: allow inspecting a crypto key constructor crypto: allow inspecting a crypto key prototype Apr 15, 2025
This would fail so far due to accessing a undefined property.
@BridgeAR BridgeAR force-pushed the fix-crypto-inspect branch from 18d0465 to 25242b2 Compare April 15, 2025 12:31
Copy link
Member

Choose a reason for hiding this comment

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

test/parallel/test-crypto-key-objects.js is possibly a better place to put this test in

Copy link
Member Author

Choose a reason for hiding this comment

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

I had a look at the file but I could not find a CryptoKey in there.
I understand that this test is not ideal but I believe it is not as crucial for the specific case.
Or would you have another spot where to place it?

Copy link
Member

Choose a reason for hiding this comment

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

I had a look at the file but I could not find a CryptoKey in there.

You are correct, apologies.

I understand that this test is not ideal but I believe it is not as crucial for the specific case.

Any generic enough place is fitting, this one here however tests a regression. If there isn't one (such as import/key gen tests that assert resulting instances), feel free to create a new one.

Copy link
Member

@jasnell jasnell Apr 16, 2025

Choose a reason for hiding this comment

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

I'd prefer it go into a separate test file on its own.

'use strict';
const common = require('../common');
const { subtle } = require('crypto');
const { strictEqual } = require('assert');

const promise = subtle.importKey('raw', Buffer.from([1,2,3]), {
  name:'HMAC', hash: 'SHA-256'
}, true, ['sign','verify']);

promise.then(common.mustCall((key) => {
  const inspected = inspect(Object.getPrototypeOf(key));
  strictEqual(
    inspected,
    'CryptoKey {\n' +
    '  type: undefined,\n' +
    '  extractable: undefined,\n' +
    '  algorithm: undefined,\n' +
    '  usages: undefined\n' +
    '}'
  );
}));

Copy link

codecov bot commented Apr 15, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.24%. Comparing base (f89baf2) to head (25242b2).
Report is 7 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #57890      +/-   ##
==========================================
- Coverage   90.24%   90.24%   -0.01%     
==========================================
  Files         630      630              
  Lines      185670   185687      +17     
  Branches    36401    36406       +5     
==========================================
+ Hits       167567   167581      +14     
- Misses      10992    10997       +5     
+ Partials     7111     7109       -2     
Files with missing lines Coverage Δ
lib/internal/crypto/keys.js 95.40% <100.00%> (ø)

... and 31 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crypto Issues and PRs related to the crypto subsystem. needs-ci PRs that need a full CI run.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants