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) {
869
869
}
870
870
871
871
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
+
873
881
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
+
875
891
if ( options . ca ) this . ca = options . ca ;
876
892
if ( options . secureProtocol ) this . secureProtocol = options . secureProtocol ;
877
893
if ( options . crl ) this . crl = options . crl ;
Original file line number Diff line number Diff line change @@ -21,13 +21,28 @@ var options = {
21
21
rejectUnauthorized : false
22
22
} ;
23
23
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
+
24
33
var server = https . createServer ( options , function ( req , res ) {
25
34
assert . equal ( req . socket . authorized , false ) ; // not a client cert
26
35
assert . equal ( req . socket . authorizationError , 'DEPTH_ZERO_SELF_SIGNED_CERT' ) ;
27
36
res . writeHead ( 200 ) ;
28
37
res . end ( 'OK' ) ;
29
38
} ) ;
30
39
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
+
31
46
server . listen ( options . port , options . host , function ( ) {
32
47
var data = '' ;
33
48
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