@@ -2,6 +2,7 @@ package uphold
2
2
3
3
import (
4
4
"context"
5
+ "crypto/tls"
5
6
"encoding/hex"
6
7
"errors"
7
8
"net/http"
@@ -307,28 +308,53 @@ func TestFingerprintCheck(t *testing.T) {
307
308
var proxy func (* http.Request ) (* url.URL , error )
308
309
wrongFingerprint := "IYSLsapSKlkofKfi6M2hmS4gzXbQKGIX/DHBWIgstw3="
309
310
311
+ w := requireDonorWallet (t )
312
+
313
+ req , err := w .signRegistration ("randomlabel" )
314
+ if err != nil {
315
+ t .Error (err )
316
+ }
317
+
318
+ // Check fingerprint error case
310
319
client := & http.Client {
311
320
Timeout : time .Second * 60 ,
312
321
// remove middleware calls
313
322
Transport : & http.Transport {
314
- Proxy : proxy ,
315
- DialTLSContext : pindialer .MakeContextDialer (wrongFingerprint ),
323
+ Proxy : proxy ,
324
+ TLSClientConfig : pindialer .GetTLSConfig (wrongFingerprint ),
316
325
},
317
326
}
318
327
319
- w := requireDonorWallet (t )
328
+ _ , err = client .Do (req )
329
+ assert .ErrorContains (t , err , "the server certificate was not valid" )
320
330
321
- req , err := w .signRegistration ("randomlabel" )
322
- if err != nil {
323
- t .Error (err )
331
+ // Check the fingerprint success case.
332
+ tlsConfig := pindialer .GetTLSConfig (upholdCertFingerprint )
333
+
334
+ // VerifyConnection callback is only called after
335
+ // tlsConfig.VerifyPeerCertificate returns success.
336
+ verifyConnectionCalled := false
337
+ if tlsConfig .VerifyConnection != nil {
338
+ t .Fatalf ("tlsConfig.VerifyConnection must be unset" )
339
+ }
340
+ tlsConfig .VerifyConnection = func (tls.ConnectionState ) error {
341
+ if verifyConnectionCalled {
342
+ t .Fatalf ("Unexpected extra call to VerifyConnection" )
343
+ }
344
+ verifyConnectionCalled = true
345
+ return nil
324
346
}
325
347
326
- _ , err = client .Do (req )
327
- // should fail here
328
- if err == nil {
329
- t .Error ("unable to fail with bad cert" )
348
+ client = & http.Client {
349
+ Timeout : time .Second * 60 ,
350
+ Transport : & http.Transport {
351
+ Proxy : proxy ,
352
+ TLSClientConfig : tlsConfig ,
353
+ },
330
354
}
331
- assert .Equal (t , errors .Unwrap (err ).Error (), "failed to validate certificate chain: the server certificate was not valid" )
355
+
356
+ _ , _ = client .Do (req )
357
+ assert .Equal (t , true , verifyConnectionCalled )
332
358
}
333
359
334
360
func requireDonorWallet (t * testing.T ) * Wallet {
0 commit comments