@@ -16,6 +16,7 @@ package server
16
16
17
17
import (
18
18
"context"
19
+ "crypto/tls"
19
20
"crypto/x509"
20
21
"os"
21
22
"path/filepath"
@@ -33,6 +34,26 @@ import (
33
34
"github.com/stretchr/testify/require"
34
35
)
35
36
37
+ // isTLSExpiredError checks error is caused by TLS expired.
38
+ func isTLSExpiredError (err error ) bool {
39
+ err = errors .Cause (err )
40
+ switch inval := err .(type ) {
41
+ case x509.CertificateInvalidError :
42
+ if inval .Reason != x509 .Expired {
43
+ return false
44
+ }
45
+ case * tls.CertificateVerificationError :
46
+ invalid , ok := inval .Err .(x509.CertificateInvalidError )
47
+ if ! ok || invalid .Reason != x509 .Expired {
48
+ return false
49
+ }
50
+ return true
51
+ default :
52
+ return false
53
+ }
54
+ return true
55
+ }
56
+
36
57
// this test will change `kv.TxnTotalSizeLimit` which may affect other test suites,
37
58
// so we must make it running in serial.
38
59
func TestLoadData1 (t * testing.T ) {
@@ -263,9 +284,9 @@ func TestTLSVerify(t *testing.T) {
263
284
require .NoError (t , err )
264
285
cli .runTestRegression (t , connOverrider , "TLSRegression" )
265
286
266
- require .False (t , util . IsTLSExpiredError (errors .New ("unknown test" )))
267
- require .False (t , util . IsTLSExpiredError (x509.CertificateInvalidError {Reason : x509 .CANotAuthorizedForThisName }))
268
- require .True (t , util . IsTLSExpiredError (x509.CertificateInvalidError {Reason : x509 .Expired }))
287
+ require .False (t , isTLSExpiredError (errors .New ("unknown test" )))
288
+ require .False (t , isTLSExpiredError (x509.CertificateInvalidError {Reason : x509 .CANotAuthorizedForThisName }))
289
+ require .True (t , isTLSExpiredError (x509.CertificateInvalidError {Reason : x509 .Expired }))
269
290
270
291
_ , _ , err = util .LoadTLSCertificates ("" , "wrong key" , "wrong cert" , true , 528 )
271
292
require .Error (t , err )
@@ -553,6 +574,6 @@ func TestReloadTLS(t *testing.T) {
553
574
}
554
575
err = cli .runTestTLSConnection (t , connOverrider )
555
576
require .NotNil (t , err )
556
- require .Truef (t , util . IsTLSExpiredError (err ), "real error is %+v" , err )
577
+ require .Truef (t , isTLSExpiredError (err ), "real error is %+v" , err )
557
578
server .Close ()
558
579
}
0 commit comments