forked from authlib/otpauth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_otpauth.py
48 lines (34 loc) · 1.17 KB
/
test_otpauth.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# -*- coding: utf-8 -*-
from otpauth import OtpAuth
from nose.tools import raises
def test_hotp():
auth = OtpAuth('python')
code = auth.hotp(4)
assert auth.valid_hotp(code) == 4
# false
assert auth.valid_hotp(1234567) is False
assert auth.valid_hotp(123456) is False
assert auth.valid_hotp('123456') is False
def test_totp():
auth = OtpAuth('python')
code = auth.totp()
assert auth.valid_totp(code)
# false
assert auth.valid_totp(1234567) is False
assert auth.valid_totp(123456) is False
@raises(ValueError)
def test_to_google_raise():
auth = OtpAuth('python')
auth.to_google('invalid', 'python', 'python')
@raises(ValueError)
def test_to_google_hotp_raise():
auth = OtpAuth('python')
auth.to_google('hotp', 'python', 'python')
def test_to_google_hotp():
auth = OtpAuth('python')
expect = 'otpauth://hotp/python?secret=OB4XI2DPNY&issuer=python&counter=4'
assert auth.to_google('hotp', 'python', 'python', 4) == expect
def test_to_google_totp():
auth = OtpAuth('python')
expect = 'otpauth://totp/python?secret=OB4XI2DPNY&issuer=python'
assert auth.to_google('totp', 'python', 'python') == expect