File tree Expand file tree Collapse file tree 3 files changed +54
-2
lines changed
Expand file tree Collapse file tree 3 files changed +54
-2
lines changed Original file line number Diff line number Diff line change @@ -869,9 +869,25 @@ Server.prototype.setOptions = function(options) {
869869 }
870870
871871 if ( options . pfx ) this . pfx = options . pfx ;
872- if ( options . key ) this . key = options . key ;
872+ var defaultCiphers = options . ciphers === tls . DEFAULT_CIPHERS ;
873+ if ( ! options . key ) {
874+ if ( ( options . ciphers === undefined || defaultCiphers ) && ! options . pfx ) {
875+ throw new Error ( 'key is a required parameter for Server.createServer' ) ;
876+ }
877+ } else {
878+ this . key = options . key ;
879+ }
880+
873881 if ( options . passphrase ) this . passphrase = options . passphrase ;
874- if ( options . cert ) this . cert = options . cert ;
882+
883+ if ( ! options . cert ) {
884+ if ( ( options . ciphers === undefined || defaultCiphers ) && ! options . pfx ) {
885+ throw new Error ( 'cert is a required parameter for Server.createServer' ) ;
886+ }
887+ } else {
888+ this . cert = options . cert ;
889+ }
890+
875891 if ( options . ca ) this . ca = options . ca ;
876892 if ( options . secureProtocol ) this . secureProtocol = options . secureProtocol ;
877893 if ( options . crl ) this . crl = options . crl ;
Original file line number Diff line number Diff line change @@ -21,13 +21,28 @@ var options = {
2121 rejectUnauthorized : false
2222} ;
2323
24+ var options1 = {
25+ host : '127.0.0.1' ,
26+ port : common . PORT ,
27+ path : '/' ,
28+ pfx : pfx ,
29+ passphrase : 'sample' ,
30+ requestCert : true
31+ } ;
32+
2433var server = https . createServer ( options , function ( req , res ) {
2534 assert . equal ( req . socket . authorized , false ) ; // not a client cert
2635 assert . equal ( req . socket . authorizationError , 'DEPTH_ZERO_SELF_SIGNED_CERT' ) ;
2736 res . writeHead ( 200 ) ;
2837 res . end ( 'OK' ) ;
2938} ) ;
3039
40+ assert . doesNotThrow ( ( ) => https . createServer ( options1 , assert . fail ) ,
41+ 'cert is a required parameter for Server.createServer' ) ;
42+
43+ assert . doesNotThrow ( ( ) => https . createServer ( options1 , assert . fail ) ,
44+ 'key is a required parameter for Server.createServer' ) ;
45+
3146server . listen ( options . port , options . host , function ( ) {
3247 var data = '' ;
3348
Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+ const common = require ( '../common' ) ;
3+ const assert = require ( 'assert' ) ;
4+ const https = require ( 'https' ) ;
5+ const fs = require ( 'fs' ) ;
6+
7+ const options1 = {
8+ key : fs . readFileSync ( common . fixturesDir + '/keys/agent1-key.pem' , 'ascii' ) ,
9+ crt : fs . readFileSync ( common . fixturesDir + '/keys/agent1-cert.pem' , 'ascii' )
10+ } ;
11+
12+ const options2 = {
13+ ky : fs . readFileSync ( common . fixturesDir + '/keys/agent1-key.pem' , 'ascii' ) ,
14+ cert : fs . readFileSync ( common . fixturesDir + '/keys/agent1-cert.pem' , 'ascii' )
15+ } ;
16+
17+ assert . throws ( ( ) => https . createServer ( options1 , assert . fail ) ,
18+ 'cert is a required parameter for Server.createServer' ) ;
19+
20+ assert . throws ( ( ) => https . createServer ( options2 , assert . fail ) ,
21+ 'key is a required parameter for Server.createServer' ) ;
You can’t perform that action at this time.
0 commit comments