1/* eslint-disable no-proto */ 2'use strict'; 3 4const common = require('../common'); 5if (!common.hasCrypto) 6 common.skip('missing crypto'); 7 8const { 9 hijackStderr, 10 restoreStderr 11} = require('../common/hijackstdio'); 12const assert = require('assert'); 13// Flags: --expose-internals 14const internalTLS = require('internal/tls'); 15const tls = require('tls'); 16 17const noOutput = common.mustNotCall(); 18hijackStderr(noOutput); 19 20{ 21 const singles = 'C=US\nST=CA\nL=SF\nO=Node.js Foundation\nOU=Node.js\n' + 22 'CN=ca1\nemailAddress=ry@clouds.org'; 23 const singlesOut = internalTLS.parseCertString(singles); 24 assert.deepStrictEqual(singlesOut, { 25 __proto__: null, 26 C: 'US', 27 ST: 'CA', 28 L: 'SF', 29 O: 'Node.js Foundation', 30 OU: 'Node.js', 31 CN: 'ca1', 32 emailAddress: 'ry@clouds.org' 33 }); 34} 35 36{ 37 const doubles = 'OU=Domain Control Validated\nOU=PositiveSSL Wildcard\n' + 38 'CN=*.nodejs.org'; 39 const doublesOut = internalTLS.parseCertString(doubles); 40 assert.deepStrictEqual(doublesOut, { 41 __proto__: null, 42 OU: [ 'Domain Control Validated', 'PositiveSSL Wildcard' ], 43 CN: '*.nodejs.org' 44 }); 45} 46 47{ 48 const invalid = 'fhqwhgads'; 49 const invalidOut = internalTLS.parseCertString(invalid); 50 assert.deepStrictEqual(invalidOut, { __proto__: null }); 51} 52 53{ 54 const input = '__proto__=mostly harmless\nhasOwnProperty=not a function'; 55 const expected = Object.create(null); 56 expected.__proto__ = 'mostly harmless'; 57 expected.hasOwnProperty = 'not a function'; 58 assert.deepStrictEqual(internalTLS.parseCertString(input), expected); 59} 60 61restoreStderr(); 62 63{ 64 common.expectWarning('DeprecationWarning', 65 'tls.parseCertString() is deprecated. ' + 66 'Please use querystring.parse() instead.', 67 'DEP0076'); 68 69 const ret = tls.parseCertString('foo=bar'); 70 assert.deepStrictEqual(ret, { __proto__: null, foo: 'bar' }); 71} 72