@@ -504,25 +504,27 @@ func TestLibp2pACMEE2E(t *testing.T) {
504
504
isValidShortForgeAddr := func (addr string ) bool {
505
505
return strings .Contains (addr , "libp2p.direct/tcp/" ) && strings .Contains (addr , "/tls/ws" )
506
506
}
507
+ defaultAddrCheck := isValidResolvedForgeAddr
507
508
508
509
tests := []struct {
509
- name string
510
- clientOpts []client.P2PForgeCertMgrOptions
511
- isValidForgeAddr func (addr string ) bool
512
- caCertValidityPeriod uint64 // 0 means default from letsencrypt/pebble/ca/v2#defaultValidityPeriod will be used
513
- awaitOnCertRenewed bool // include renewal test
510
+ name string
511
+ clientOpts []client.P2PForgeCertMgrOptions
512
+ isValidForgeAddr func (addr string ) bool
513
+ caCertValidityPeriod uint64 // 0 means default from letsencrypt/pebble/ca/v2#defaultValidityPeriod will be used
514
+ awaitOnCertRenewed bool // include renewal test
515
+ expectRegistrationDelay time.Duration // include delayed registration test that fails if registration occured sooner
514
516
}{
515
517
{
516
518
name : "default opts" ,
517
519
clientOpts : []client.P2PForgeCertMgrOptions {},
518
- isValidForgeAddr : isValidResolvedForgeAddr ,
520
+ isValidForgeAddr : defaultAddrCheck ,
519
521
},
520
522
{
521
523
name : "expired cert gets renewed and triggers OnCertRenewed" ,
522
524
clientOpts : []client.P2PForgeCertMgrOptions {
523
525
client .WithRenewCheckInterval (5 * time .Second ),
524
526
},
525
- isValidForgeAddr : isValidResolvedForgeAddr ,
527
+ isValidForgeAddr : defaultAddrCheck ,
526
528
caCertValidityPeriod : 30 , // letsencrypt/pebble/v2/ca uses int as seconds
527
529
awaitOnCertRenewed : true ,
528
530
},
@@ -536,6 +538,12 @@ func TestLibp2pACMEE2E(t *testing.T) {
536
538
clientOpts : []client.P2PForgeCertMgrOptions {client .WithShortForgeAddrs (false )},
537
539
isValidForgeAddr : isValidResolvedForgeAddr ,
538
540
},
541
+ {
542
+ name : "WithRegistrationDelay() produces a delay" ,
543
+ clientOpts : []client.P2PForgeCertMgrOptions {client .WithRegistrationDelay (15 * time .Second )},
544
+ isValidForgeAddr : defaultAddrCheck ,
545
+ expectRegistrationDelay : 15 * time .Second ,
546
+ },
539
547
}
540
548
541
549
for _ , tt := range tests {
@@ -624,6 +632,7 @@ func TestLibp2pACMEE2E(t *testing.T) {
624
632
if err != nil {
625
633
t .Fatal (err )
626
634
}
635
+ start := time .Now ()
627
636
certMgr .Start ()
628
637
defer certMgr .Stop ()
629
638
@@ -667,10 +676,19 @@ func TestLibp2pACMEE2E(t *testing.T) {
667
676
668
677
select {
669
678
case <- certLoaded :
670
- case <- time .After (time .Second * 30 ):
679
+ case <- time .After (time .Second * 30 + tt . expectRegistrationDelay ):
671
680
t .Fatal ("timed out waiting for certificate" )
672
681
}
673
682
683
+ // optional WithRegistrationDelay test
684
+ // confirms registration took longer than the delay defined
685
+ if tt .expectRegistrationDelay != 0 {
686
+ remainingDelay := tt .expectRegistrationDelay - time .Since (start )
687
+ if remainingDelay > 0 {
688
+ t .Fatalf ("WithRegistrationDelay was expected to delay registration by %s" , tt .expectRegistrationDelay )
689
+ }
690
+ }
691
+
674
692
var dialAddr multiaddr.Multiaddr
675
693
hAddrs := h .Addrs ()
676
694
for _ , addr := range hAddrs {
0 commit comments