|
1 | 1 | 'use strict'; |
2 | 2 |
|
3 | 3 | // This tests that tls.getCACertificates('default') includes certificates from |
4 | | -// OpenSSL's default certificate file when --use-openssl-ca is enabled. |
| 4 | +// OpenSSL's default certificate file and directories when --use-openssl-ca is |
| 5 | +// enabled. |
5 | 6 |
|
6 | 7 | const common = require('../common'); |
7 | 8 | if (!common.hasCrypto) common.skip('missing crypto'); |
8 | 9 |
|
| 10 | +const fs = require('fs'); |
| 11 | +const path = require('path'); |
9 | 12 | const { spawnSyncAndExitWithoutError } = require('../common/child_process'); |
10 | 13 | const fixtures = require('../common/fixtures'); |
| 14 | +const tmpdir = require('../common/tmpdir'); |
| 15 | + |
| 16 | +tmpdir.refresh(); |
| 17 | + |
| 18 | +const firstCertDir = tmpdir.resolve('openssl-certs-1'); |
| 19 | +const secondCertDir = tmpdir.resolve('openssl-certs-2'); |
| 20 | +fs.mkdirSync(firstCertDir); |
| 21 | +fs.mkdirSync(secondCertDir); |
| 22 | + |
| 23 | +const expectedCertFiles = [ |
| 24 | + fixtures.path('keys', 'ca1-cert.pem'), |
| 25 | + fixtures.path('keys', 'ca2-cert.pem'), |
| 26 | + fixtures.path('keys', 'ca3-cert.pem'), |
| 27 | +]; |
| 28 | +fs.copyFileSync(expectedCertFiles[1], path.join(firstCertDir, 'ca2-cert.pem')); |
| 29 | +fs.copyFileSync(expectedCertFiles[2], path.join(secondCertDir, 'ca3-cert.pem')); |
11 | 30 |
|
12 | 31 | spawnSyncAndExitWithoutError( |
13 | 32 | process.execPath, |
14 | 33 | ['--use-openssl-ca', fixtures.path('tls-check-openssl-ca-certificates.js')], |
15 | 34 | { |
16 | 35 | env: { |
17 | 36 | ...process.env, |
| 37 | + EXPECTED_CERT_FILES: JSON.stringify(expectedCertFiles), |
18 | 38 | NODE_EXTRA_CA_CERTS: undefined, |
19 | | - SSL_CERT_FILE: fixtures.path('keys', 'ca1-cert.pem'), |
20 | | - SSL_CERT_DIR: '', |
| 39 | + SSL_CERT_FILE: expectedCertFiles[0], |
| 40 | + SSL_CERT_DIR: [firstCertDir, secondCertDir].join(path.delimiter), |
21 | 41 | }, |
22 | 42 | }, |
23 | 43 | ); |
0 commit comments