Skip to content

Commit

Permalink
Test and lint config updates
Browse files Browse the repository at this point in the history
  • Loading branch information
kislyuk committed Oct 25, 2019
1 parent 18c0352 commit b650e35
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
universal=1
[flake8]
max-line-length=120
ignore: E301, E302, W504
ignore: E401, W504
2 changes: 2 additions & 0 deletions src/pyotp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from pyotp.totp import TOTP # noqa
from . import utils # noqa


def random_base32(length=16, random=None,
chars=list('ABCDEFGHIJKLMNOPQRSTUVWXYZ234567')):
if length < 16:
Expand All @@ -23,6 +24,7 @@ def random_base32(length=16, random=None,
for _ in range(length)
)


def random_hex(length=32, random=None,
chars=list('ABCDEF0123456789')):
if length < 32:
Expand Down
1 change: 1 addition & 0 deletions src/pyotp/hotp.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from .otp import OTP
from .compat import str


class HOTP(OTP):
"""
Handler for HMAC-based OTP counters.
Expand Down
1 change: 1 addition & 0 deletions src/pyotp/otp.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import hmac
from .compat import str


class OTP(object):
"""
Base class for OTP handlers.
Expand Down
1 change: 1 addition & 0 deletions src/pyotp/totp.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from .otp import OTP
from .compat import str


class TOTP(OTP):
"""
Handler for time-based OTP counters.
Expand Down
8 changes: 8 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src'))
import pyotp # noqa


class HOTPExampleValuesFromTheRFC(unittest.TestCase):
def test_match_rfc(self):
# 12345678901234567890 in Bas32
Expand Down Expand Up @@ -236,6 +237,12 @@ def test_provisioning_uri(self):
def test_random_key_generation(self):
self.assertEqual(len(pyotp.random_base32()), 16)
self.assertEqual(len(pyotp.random_base32(length=20)), 20)
self.assertEqual(len(pyotp.random_hex()), 32)
self.assertEqual(len(pyotp.random_hex(length=64)), 64)
with self.assertRaises(Exception):
pyotp.random_base32(length=15)
with self.assertRaises(Exception):
pyotp.random_hex(length=24)


class CompareDigestTest(unittest.TestCase):
Expand Down Expand Up @@ -305,5 +312,6 @@ def now(cls, **kwargs):
timecop = self
return FrozenDateTime


if __name__ == '__main__':
unittest.main()

0 comments on commit b650e35

Please sign in to comment.