Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interval is not working #151

Closed
dsifat opened this issue Apr 30, 2023 · 3 comments
Closed

Interval is not working #151

dsifat opened this issue Apr 30, 2023 · 3 comments

Comments

@dsifat
Copy link

dsifat commented Apr 30, 2023

Interval remains 30 seconds in TOTP if we provide more than 30 like 60, 120 or 240

@kislyuk
Copy link
Member

kislyuk commented Apr 30, 2023

Thanks for your report. I am unable to reproduce this issue. Can you please provide a full reproduction, including the code you used, the expected outcome, and the observed outcome?

@vladimir-poghosyan
Copy link

I have also encountered issues related to interval. I have written the following test, which fails, although the interval is set to 120 seconds (greater than tested waiting times):

from time import sleep

import pyotp
import pytest


@pytest.mark.parametrize('wait', (25, 55, 85, 105, 115))
def test_totp(wait: int) -> None:
    totp = pyotp.TOTP(pyotp.random_base32(), interval=120)
    code = totp.now()
    sleep(wait)
    assert totp.verify(code)

And here are the results:

============================================ short test summary info =============================================
FAILED test-totp-interval.py::test_totp[55] - AssertionError: assert False
FAILED test-totp-interval.py::test_totp[105] - AssertionError: assert False
FAILED test-totp-interval.py::test_totp[115] - AssertionError: assert False
==================================== 3 failed, 2 passed in 385.04s (0:06:25) =====================================

Testing environment:

  • Python 3.11.3
  • pyotp 2.8.0
  • pytest 7.3.2

@kislyuk
Copy link
Member

kislyuk commented Jun 16, 2023

@vladimir-poghosyan that is a misunderstanding of how TOTP works. The interval doesn't start when your test starts, it starts when the time since the epoch modulo the interval is zero.

I am going to close this issue now, since neither report has a valid reproduction.

@kislyuk kislyuk closed this as completed Jun 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants