@@ -309,6 +309,56 @@ func TestClientSetRootCertificateFromStringErrorTls(t *testing.T) {
309
309
assertNil (t , transport )
310
310
}
311
311
312
+ func TestClientSetClientRootCertificate (t * testing.T ) {
313
+ client := dc ()
314
+ client .SetClientRootCertificate (filepath .Join (getTestDataPath (), "sample-root.pem" ))
315
+
316
+ transport , err := client .Transport ()
317
+
318
+ assertNil (t , err )
319
+ assertNotNil (t , transport .TLSClientConfig .ClientCAs )
320
+ }
321
+
322
+ func TestClientSetClientRootCertificateNotExists (t * testing.T ) {
323
+ client := dc ()
324
+ client .SetClientRootCertificate (filepath .Join (getTestDataPath (), "not-exists-sample-root.pem" ))
325
+
326
+ transport , err := client .Transport ()
327
+
328
+ assertNil (t , err )
329
+ assertNil (t , transport .TLSClientConfig )
330
+ }
331
+
332
+ func TestClientSetClientRootCertificateFromString (t * testing.T ) {
333
+ client := dc ()
334
+ rootPemData , err := os .ReadFile (filepath .Join (getTestDataPath (), "sample-root.pem" ))
335
+ assertNil (t , err )
336
+
337
+ client .SetClientRootCertificateFromString (string (rootPemData ))
338
+
339
+ transport , err := client .Transport ()
340
+
341
+ assertNil (t , err )
342
+ assertNotNil (t , transport .TLSClientConfig .ClientCAs )
343
+ }
344
+
345
+ func TestClientSetClientRootCertificateFromStringErrorTls (t * testing.T ) {
346
+ client := NewWithClient (& http.Client {})
347
+ client .outputLogTo (io .Discard )
348
+
349
+ rootPemData , err := os .ReadFile (filepath .Join (getTestDataPath (), "sample-root.pem" ))
350
+ assertNil (t , err )
351
+ rt := & CustomRoundTripper {}
352
+ client .SetTransport (rt )
353
+ transport , err := client .Transport ()
354
+
355
+ client .SetClientRootCertificateFromString (string (rootPemData ))
356
+
357
+ assertNotNil (t , rt )
358
+ assertNotNil (t , err )
359
+ assertNil (t , transport )
360
+ }
361
+
312
362
func TestClientOnBeforeRequestModification (t * testing.T ) {
313
363
tc := dc ()
314
364
tc .OnBeforeRequest (func (c * Client , r * Request ) error {
0 commit comments