@@ -29,46 +29,60 @@ describe('MongoOptions', function () {
29
29
expect ( options . prototype ) . to . not . exist ;
30
30
} ) ;
31
31
32
- it ( 'should rename tls options correctly' , function ( ) {
33
- const filename = `${ os . tmpdir ( ) } /tmp.pem` ;
34
- fs . closeSync ( fs . openSync ( filename , 'w' ) ) ;
35
- const options = parseOptions ( 'mongodb://localhost:27017/?ssl=true' , {
36
- tlsCertificateKeyFile : filename ,
37
- tlsCertificateFile : filename ,
38
- tlsCAFile : filename ,
39
- sslCRL : filename ,
40
- tlsCertificateKeyFilePassword : 'tlsCertificateKeyFilePassword' ,
41
- sslValidate : false
42
- } ) ;
43
- fs . unlinkSync ( filename ) ;
44
-
45
- /*
46
- * If set TLS enabled, equivalent to setting the ssl option.
47
- *
48
- * ### Additional options:
49
- *
50
- * | nodejs option | MongoDB equivalent | type |
51
- * |:---------------------|----------------------------------------------------|:---------------------------------------|
52
- * | `ca` | sslCA, tlsCAFile | `string \| Buffer \| Buffer[]` |
53
- * | `crl` | sslCRL | `string \| Buffer \| Buffer[]` |
54
- * | `cert` | sslCert, tlsCertificateFile | `string \| Buffer \| Buffer[]` |
55
- * | `key` | sslKey, tlsCertificateKeyFile | `string \| Buffer \| KeyObject[]` |
56
- * | `passphrase` | sslPass, tlsCertificateKeyFilePassword | `string` |
57
- * | `rejectUnauthorized` | sslValidate | `boolean` |
58
- *
59
- */
60
- expect ( options ) . to . not . have . property ( 'tlsCertificateKeyFile' ) ;
61
- expect ( options ) . to . not . have . property ( 'tlsCAFile' ) ;
62
- expect ( options ) . to . not . have . property ( 'sslCRL' ) ;
63
- expect ( options ) . to . not . have . property ( 'tlsCertificateKeyFilePassword' ) ;
64
- expect ( options ) . has . property ( 'ca' , '' ) ;
65
- expect ( options ) . has . property ( 'crl' , '' ) ;
66
- expect ( options ) . has . property ( 'cert' , '' ) ;
67
- expect ( options ) . has . property ( 'key' ) ;
68
- expect ( options . key ) . has . length ( 0 ) ;
69
- expect ( options ) . has . property ( 'passphrase' , 'tlsCertificateKeyFilePassword' ) ;
70
- expect ( options ) . has . property ( 'rejectUnauthorized' , false ) ;
71
- expect ( options ) . has . property ( 'tls' , true ) ;
32
+ describe ( 'tls options' , ( ) => {
33
+ let filename ;
34
+ before ( ( ) => {
35
+ filename = `${ os . tmpdir ( ) } /tmp.pem` ;
36
+ fs . closeSync ( fs . openSync ( filename , 'w' ) ) ;
37
+ } ) ;
38
+ after ( ( ) => {
39
+ fs . unlinkSync ( filename ) ;
40
+ } ) ;
41
+ it ( 'should rename tls options correctly' , function ( ) {
42
+ const options = parseOptions ( 'mongodb://localhost:27017/?ssl=true' , {
43
+ tlsCertificateKeyFile : filename ,
44
+ tlsCertificateFile : filename ,
45
+ tlsCAFile : filename ,
46
+ sslCRL : filename ,
47
+ tlsCertificateKeyFilePassword : 'tlsCertificateKeyFilePassword' ,
48
+ sslValidate : false
49
+ } ) ;
50
+
51
+ /*
52
+ * If set TLS enabled, equivalent to setting the ssl option.
53
+ *
54
+ * ### Additional options:
55
+ *
56
+ * | nodejs option | MongoDB equivalent | type |
57
+ * |:---------------------|----------------------------------------------------|:---------------------------------------|
58
+ * | `ca` | sslCA, tlsCAFile | `string \| Buffer \| Buffer[]` |
59
+ * | `crl` | sslCRL | `string \| Buffer \| Buffer[]` |
60
+ * | `cert` | sslCert, tlsCertificateFile | `string \| Buffer \| Buffer[]` |
61
+ * | `key` | sslKey, tlsCertificateKeyFile | `string \| Buffer \| KeyObject[]` |
62
+ * | `passphrase` | sslPass, tlsCertificateKeyFilePassword | `string` |
63
+ * | `rejectUnauthorized` | sslValidate | `boolean` |
64
+ *
65
+ */
66
+ expect ( options ) . to . not . have . property ( 'tlsCertificateKeyFile' ) ;
67
+ expect ( options ) . to . not . have . property ( 'tlsCAFile' ) ;
68
+ expect ( options ) . to . not . have . property ( 'sslCRL' ) ;
69
+ expect ( options ) . to . not . have . property ( 'tlsCertificateKeyFilePassword' ) ;
70
+ expect ( options ) . has . property ( 'ca' , '' ) ;
71
+ expect ( options ) . has . property ( 'crl' , '' ) ;
72
+ expect ( options ) . has . property ( 'cert' , '' ) ;
73
+ expect ( options ) . has . property ( 'key' ) ;
74
+ expect ( options . key ) . has . length ( 0 ) ;
75
+ expect ( options ) . has . property ( 'passphrase' , 'tlsCertificateKeyFilePassword' ) ;
76
+ expect ( options ) . has . property ( 'rejectUnauthorized' , false ) ;
77
+ expect ( options ) . has . property ( 'tls' , true ) ;
78
+ } ) ;
79
+
80
+ it ( 'should not emit a deprecation warning for `tlsCertificateKeyFile` when `tlsCaFile` is specified' , ( ) => {
81
+ const promiseSpy = sinon . spy ( process , 'emitWarning' ) ;
82
+ new MongoClient ( `mongodb://localhost:27017/my_db?tlsCertificateKeyFile=${ filename } ` ) ;
83
+
84
+ expect ( promiseSpy ) . not . to . have . been . called ;
85
+ } ) ;
72
86
} ) ;
73
87
74
88
const ALL_OPTIONS = {
0 commit comments