Skip to content

Commit e0fced0

Browse files
committed
test: use heapdump test for SecureContext memory tracking
Signed-off-by: Mert Can Altin <mertgold60@gmail.com>
1 parent 4ee2117 commit e0fced0

2 files changed

Lines changed: 37 additions & 27 deletions

File tree

test/cctest/test_node_crypto.cc

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -25,33 +25,6 @@ TEST(NodeCrypto, NewRootCertStore) {
2525
X509_STORE_free(store);
2626
}
2727

28-
/*
29-
* This test verifies that OpenSSL memory tracking constants are properly
30-
* defined.
31-
*/
32-
TEST(NodeCrypto, MemoryTrackingConstants) {
33-
// Verify that our memory tracking constants are defined and reasonable
34-
EXPECT_GT(node::crypto::kSizeOf_SSL_CTX, static_cast<size_t>(0))
35-
<< "SSL_CTX size constant should be positive";
36-
EXPECT_GT(node::crypto::kSizeOf_X509, static_cast<size_t>(0))
37-
<< "X509 size constant should be positive";
38-
EXPECT_GT(node::crypto::kSizeOf_EVP_MD_CTX, static_cast<size_t>(0))
39-
<< "EVP_MD_CTX size constant should be positive";
40-
41-
// Verify reasonable size ranges (basic sanity check)
42-
EXPECT_LT(node::crypto::kSizeOf_SSL_CTX, static_cast<size_t>(10000))
43-
<< "SSL_CTX size should be reasonable";
44-
EXPECT_LT(node::crypto::kSizeOf_X509, static_cast<size_t>(10000))
45-
<< "X509 size should be reasonable";
46-
EXPECT_LT(node::crypto::kSizeOf_EVP_MD_CTX, static_cast<size_t>(1000))
47-
<< "EVP_MD_CTX size should be reasonable";
48-
49-
// Specific values we expect based on our implementation
50-
EXPECT_EQ(node::crypto::kSizeOf_SSL_CTX, static_cast<size_t>(240));
51-
EXPECT_EQ(node::crypto::kSizeOf_X509, static_cast<size_t>(128));
52-
EXPECT_EQ(node::crypto::kSizeOf_EVP_MD_CTX, static_cast<size_t>(48));
53-
}
54-
5528
TEST(NodeCrypto, TryGetIntCipherOutputLength) {
5629
int output_len = 0;
5730

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
'use strict';
2+
// This tests heap snapshot integration of SecureContext.
3+
4+
const common = require('../common');
5+
6+
if (!common.hasCrypto) common.skip('missing crypto');
7+
8+
const fixtures = require('../common/fixtures');
9+
const assert = require('assert');
10+
const {
11+
createJSHeapSnapshot,
12+
validateByRetainingPathFromNodes,
13+
} = require('../common/heap');
14+
const tls = require('tls');
15+
16+
{
17+
const nodes = createJSHeapSnapshot();
18+
const matches = nodes.filter(
19+
(n) => n.name === 'Node / SecureContext' && n.type !== 'string');
20+
assert.strictEqual(matches.length, 0);
21+
}
22+
23+
// eslint-disable-next-line no-unused-vars
24+
const ctx = tls.createSecureContext({
25+
cert: fixtures.readKey('agent1-cert.pem'),
26+
key: fixtures.readKey('agent1-key.pem'),
27+
});
28+
29+
{
30+
const nodes = createJSHeapSnapshot();
31+
validateByRetainingPathFromNodes(nodes, 'Node / SecureContext', [
32+
{ edge_name: 'ctx', node_name: 'Node / ctx' },
33+
]);
34+
validateByRetainingPathFromNodes(nodes, 'Node / SecureContext', [
35+
{ edge_name: 'cert', node_name: 'Node / cert' },
36+
]);
37+
}

0 commit comments

Comments
 (0)