@@ -24,6 +24,7 @@ import (
24
24
"github.com/mongodb/mongo-go-driver/x/mongo/driver/topology"
25
25
"github.com/mongodb/mongo-go-driver/x/network/connstring"
26
26
"github.com/stretchr/testify/require"
27
+ "reflect"
27
28
)
28
29
29
30
func TestClientOptions_simple (t * testing.T ) {
@@ -144,7 +145,7 @@ func TestClientOptions_chainAll(t *testing.T) {
144
145
SSLClientCertificateKeyFile : "client.pem" ,
145
146
SSLClientCertificateKeyFileSet : true ,
146
147
SSLClientCertificateKeyPassword : nil ,
147
- SSLClientCertificateKeyPasswordSet : true ,
148
+ SSLClientCertificateKeyPasswordSet : false , // will not be set if it's nil
148
149
SSLInsecure : false ,
149
150
SSLInsecureSet : true ,
150
151
SSLCaFile : "ca.pem" ,
@@ -159,6 +160,44 @@ func TestClientOptions_chainAll(t *testing.T) {
159
160
require .Equal (t , expectedClient , opts )
160
161
}
161
162
163
+ func TestClientOptions_sslOptions (t * testing.T ) {
164
+ t .Parallel ()
165
+
166
+ t .Run ("TestEmptyOptionsNotSet" , func (t * testing.T ) {
167
+ ssl := & options.SSLOpt {}
168
+ c , err := NewClientWithOptions ("mongodb://localhost" , options .Client ().SetSSL (ssl ))
169
+ require .NoError (t , err )
170
+
171
+ require .Equal (t , c .connString .SSLClientCertificateKeyFile , "" )
172
+ require .Equal (t , c .connString .SSLClientCertificateKeyFileSet , false )
173
+ require .Nil (t , c .connString .SSLClientCertificateKeyPassword )
174
+ require .Equal (t , c .connString .SSLClientCertificateKeyPasswordSet , false )
175
+ require .Equal (t , c .connString .SSLCaFile , "" )
176
+ require .Equal (t , c .connString .SSLCaFileSet , false )
177
+ })
178
+
179
+ t .Run ("TestNonEmptyOptionsSet" , func (t * testing.T ) {
180
+ f := func () string {
181
+ return "KeyPassword"
182
+ }
183
+
184
+ ssl := & options.SSLOpt {
185
+ ClientCertificateKeyFile : "KeyFile" ,
186
+ ClientCertificateKeyPassword : f ,
187
+ CaFile : "CaFile" ,
188
+ }
189
+ c , err := NewClientWithOptions ("mongodb://localhost" , options .Client ().SetSSL (ssl ))
190
+ require .NoError (t , err )
191
+
192
+ require .Equal (t , c .connString .SSLClientCertificateKeyFile , "KeyFile" )
193
+ require .Equal (t , c .connString .SSLClientCertificateKeyFileSet , true )
194
+ require .Equal (t , reflect .ValueOf (c .connString .SSLClientCertificateKeyPassword ).Pointer (), reflect .ValueOf (f ).Pointer ())
195
+ require .Equal (t , c .connString .SSLClientCertificateKeyPasswordSet , true )
196
+ require .Equal (t , c .connString .SSLCaFile , "CaFile" )
197
+ require .Equal (t , c .connString .SSLCaFileSet , true )
198
+ })
199
+ }
200
+
162
201
func TestClientOptions_CustomDialer (t * testing.T ) {
163
202
td := & testDialer {d : & net.Dialer {}}
164
203
opts := options .Client ().SetDialer (td )
0 commit comments