@@ -495,25 +495,27 @@ func TestLibp2pACMEE2E(t *testing.T) {
495
495
isValidShortForgeAddr := func (addr string ) bool {
496
496
return strings .Contains (addr , "libp2p.direct/tcp/" ) && strings .Contains (addr , "/tls/ws" )
497
497
}
498
+ defaultAddrCheck := isValidResolvedForgeAddr
498
499
499
500
tests := []struct {
500
- name string
501
- clientOpts []client.P2PForgeCertMgrOptions
502
- isValidForgeAddr func (addr string ) bool
503
- caCertValidityPeriod uint64 // 0 means default from letsencrypt/pebble/ca/v2#defaultValidityPeriod will be used
504
- awaitOnCertRenewed bool // include renewal test
501
+ name string
502
+ clientOpts []client.P2PForgeCertMgrOptions
503
+ isValidForgeAddr func (addr string ) bool
504
+ caCertValidityPeriod uint64 // 0 means default from letsencrypt/pebble/ca/v2#defaultValidityPeriod will be used
505
+ awaitOnCertRenewed bool // include renewal test
506
+ expectRegistrationDelay time.Duration // include delayed registration test that fails if registration occured sooner
505
507
}{
506
508
{
507
509
name : "default opts" ,
508
510
clientOpts : []client.P2PForgeCertMgrOptions {},
509
- isValidForgeAddr : isValidResolvedForgeAddr ,
511
+ isValidForgeAddr : defaultAddrCheck ,
510
512
},
511
513
{
512
514
name : "expired cert gets renewed and triggers OnCertRenewed" ,
513
515
clientOpts : []client.P2PForgeCertMgrOptions {
514
516
client .WithRenewCheckInterval (5 * time .Second ),
515
517
},
516
- isValidForgeAddr : isValidResolvedForgeAddr ,
518
+ isValidForgeAddr : defaultAddrCheck ,
517
519
caCertValidityPeriod : 30 , // letsencrypt/pebble/v2/ca uses int as seconds
518
520
awaitOnCertRenewed : true ,
519
521
},
@@ -527,6 +529,12 @@ func TestLibp2pACMEE2E(t *testing.T) {
527
529
clientOpts : []client.P2PForgeCertMgrOptions {client .WithShortForgeAddrs (false )},
528
530
isValidForgeAddr : isValidResolvedForgeAddr ,
529
531
},
532
+ {
533
+ name : "WithRegistrationDelay() produces a delay" ,
534
+ clientOpts : []client.P2PForgeCertMgrOptions {client .WithRegistrationDelay (15 * time .Second )},
535
+ isValidForgeAddr : defaultAddrCheck ,
536
+ expectRegistrationDelay : 15 * time .Second ,
537
+ },
530
538
}
531
539
532
540
for _ , tt := range tests {
@@ -602,6 +610,7 @@ func TestLibp2pACMEE2E(t *testing.T) {
602
610
if err != nil {
603
611
t .Fatal (err )
604
612
}
613
+ start := time .Now ()
605
614
certMgr .Start ()
606
615
defer certMgr .Stop ()
607
616
@@ -652,10 +661,19 @@ func TestLibp2pACMEE2E(t *testing.T) {
652
661
653
662
select {
654
663
case <- certLoaded :
655
- case <- time .After (time .Second * 30 ):
664
+ case <- time .After (time .Second * 30 + tt . expectRegistrationDelay ):
656
665
t .Fatal ("timed out waiting for certificate" )
657
666
}
658
667
668
+ // optional WithRegistrationDelay test
669
+ // confirms registration took longer than the delay defined
670
+ if tt .expectRegistrationDelay != 0 {
671
+ remainingDelay := tt .expectRegistrationDelay - time .Since (start )
672
+ if remainingDelay > 0 {
673
+ t .Fatalf ("WithRegistrationDelay was expected to delay registration by %s" , tt .expectRegistrationDelay )
674
+ }
675
+ }
676
+
659
677
var dialAddr multiaddr.Multiaddr
660
678
hAddrs := h .Addrs ()
661
679
for _ , addr := range hAddrs {
0 commit comments