GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — test: check tls server verification with addCACert · nodejs/node@4207bce

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • test/internet
    • test-tls-add-ca-cert.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎test/internet/test-tls-add-ca-cert.js‎

Copy file name to clipboard
+55Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
'use strict';
2+
const common = require('../common');
3+
4+
if (!common.hasCrypto) {
5+
common.skip('missing crypto');
6+
return;
7+
}
8+
9+
// Test interaction of compiled-in CAs with user-provided CAs.
10+
11+
const assert = require('assert');
12+
const fs = require('fs');
13+
const tls = require('tls');
14+
15+
function filenamePEM(n) {
16+
return require('path').join(common.fixturesDir, 'keys', n + '.pem');
17+
}
18+
19+
function loadPEM(n) {
20+
return fs.readFileSync(filenamePEM(n));
21+
}
22+
23+
const caCert = loadPEM('ca1-cert');
24+
25+
const opts = {
26+
host: 'www.nodejs.org',
27+
port: 443,
28+
rejectUnauthorized: true
29+
};
30+
31+
// Success relies on the compiled in well-known root CAs
32+
tls.connect(opts, common.mustCall(end));
33+
34+
// The .ca option replaces the well-known roots, so connection fails.
35+
opts.ca = caCert;
36+
tls.connect(opts, fail).on('error', common.mustCall((err) => {
37+
assert.strictEqual(err.message, 'unable to get local issuer certificate');
38+
}));
39+
40+
function fail() {
41+
assert(false, 'should fail to connect');
42+
}
43+
44+
// New secure contexts have the well-known root CAs.
45+
opts.secureContext = tls.createSecureContext();
46+
tls.connect(opts, common.mustCall(end));
47+
48+
// Explicit calls to addCACert() add to the default well-known roots, instead
49+
// of replacing, so connection still succeeds.
50+
opts.secureContext.context.addCACert(caCert);
51+
tls.connect(opts, common.mustCall(end));
52+
53+
function end() {
54+
this.end();
55+
}

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.