diff --git a/providers/dns/inwx/inwx.go b/providers/dns/inwx/inwx.go index ee569c9295..dc26362f9a 100644 --- a/providers/dns/inwx/inwx.go +++ b/providers/dns/inwx/inwx.go @@ -211,19 +211,21 @@ func (d *DNSProvider) twoFactorAuth(info *goinwx.LoginResponse) error { time.Sleep(sleep) } - tan, err := totp.GenerateCode(d.config.SharedSecret, time.Now()) + now := time.Now() + + tan, err := totp.GenerateCode(d.config.SharedSecret, now) if err != nil { return err } - d.previousUnlock = time.Now() + d.previousUnlock = now.Truncate(30 * time.Second) return d.client.Account.Unlock(tan) } func (d *DNSProvider) computeSleep(now time.Time) time.Duration { if d.previousUnlock.IsZero() { - return 0 * time.Second + return 0 } endPeriod := d.previousUnlock.Add(30 * time.Second) @@ -231,5 +233,5 @@ func (d *DNSProvider) computeSleep(now time.Time) time.Duration { return endPeriod.Sub(now) } - return 0 * time.Second + return 0 } diff --git a/providers/dns/inwx/inwx_test.go b/providers/dns/inwx/inwx_test.go index 8053c87919..f0c8f36706 100644 --- a/providers/dns/inwx/inwx_test.go +++ b/providers/dns/inwx/inwx_test.go @@ -147,27 +147,27 @@ func TestLivePresentAndCleanup(t *testing.T) { func Test_computeSleep(t *testing.T) { testCases := []struct { desc string - previous string + now string expected time.Duration }{ { desc: "after 30s", - previous: "2024-01-01T06:29:20Z", + now: "2024-01-01T06:30:30Z", expected: 0 * time.Second, }, { desc: "0s", - previous: "2024-01-01T06:29:30Z", + now: "2024-01-01T06:30:00Z", expected: 0 * time.Second, }, { desc: "before 30s", - previous: "2024-01-01T06:29:50Z", // 10 s + now: "2024-01-01T06:29:40Z", // 10 s expected: 20 * time.Second, }, } - now, err := time.Parse(time.RFC3339, "2024-01-01T06:30:00Z") + previous, err := time.Parse(time.RFC3339, "2024-01-01T06:29:30Z") require.NoError(t, err) for _, test := range testCases { @@ -175,7 +175,7 @@ func Test_computeSleep(t *testing.T) { t.Run(test.desc, func(t *testing.T) { t.Parallel() - previous, err := time.Parse(time.RFC3339, test.previous) + now, err := time.Parse(time.RFC3339, test.now) require.NoError(t, err) d := &DNSProvider{previousUnlock: previous}