Exemple #1
0
def test_totp_verify_60_second_window():
    secret = os.urandom(20)
    key_length = 6
    current_time = 400
    hash_algorithm = 'SHA256'
    totp = auth.get_totp(secret, key_length, hash_algorithm, 60)

    value = totp.generate(current_time)
    previous_window_value = totp.generate(340)
    next_window_value = totp.generate(460)

    assert auth.totp_verify(secret, key_length, hash_algorithm, 60, value,
                            current_time, 0)
    with pytest.raises(auth.ValidationException):
        auth.totp_verify(secret, key_length, hash_algorithm, 60,
                         previous_window_value, current_time, 0)
    with pytest.raises(auth.ValidationException):
        auth.totp_verify(secret, key_length, hash_algorithm, 60,
                         next_window_value, current_time, 0)

    assert auth.totp_verify(secret, key_length, hash_algorithm, 60, value,
                            current_time, 1)
    assert auth.totp_verify(secret, key_length, hash_algorithm, 60,
                            previous_window_value, current_time, 1)
    assert auth.totp_verify(secret, key_length, hash_algorithm, 60,
                            next_window_value, current_time, 1)

    with pytest.raises(auth.ValidationException):
        auth.totp_verify(secret, key_length, hash_algorithm, 60, b'999999',
                         current_time, 0)
    with pytest.raises(auth.ValidationException):
        auth.totp_verify(secret, key_length, hash_algorithm, 30, value,
                         current_time, 0)
Exemple #2
0
def test_totp_verify_60_second_window():
    secret = os.urandom(20)
    key_length = 6
    current_time = 400
    hash_algorithm = "SHA256"
    totp = auth.get_totp(secret, key_length, hash_algorithm, 60)

    value = totp.generate(current_time)
    previous_window_value = totp.generate(340)
    next_window_value = totp.generate(460)

    assert auth.totp_verify(secret, key_length, hash_algorithm, 60, value, current_time, 0)
    with pytest.raises(auth.ValidationException):
        auth.totp_verify(secret, key_length, hash_algorithm, 60, previous_window_value, current_time, 0)
    with pytest.raises(auth.ValidationException):
        auth.totp_verify(secret, key_length, hash_algorithm, 60, next_window_value, current_time, 0)

    assert auth.totp_verify(secret, key_length, hash_algorithm, 60, value, current_time, 1)
    assert auth.totp_verify(secret, key_length, hash_algorithm, 60, previous_window_value, current_time, 1)
    assert auth.totp_verify(secret, key_length, hash_algorithm, 60, next_window_value, current_time, 1)

    with pytest.raises(auth.ValidationException):
        auth.totp_verify(secret, key_length, hash_algorithm, 60, b"999999", current_time, 0)
    with pytest.raises(auth.ValidationException):
        auth.totp_verify(secret, key_length, hash_algorithm, 30, value, current_time, 0)
Exemple #3
0
def test_authorize_user():
    user_id = '14'
    user = auth.provision_user(user_id)

    totp = auth.get_totp(user.secret, user.key_length, user.hash_algorithm, 30)
    code_to_validate = totp.generate(time.time())

    assert auth.authorize_user(user_id, code_to_validate)
Exemple #4
0
def test_authorize_user():
    user_id = "14"
    user = auth.provision_user(user_id)

    totp = auth.get_totp(user.secret, user.key_length, user.hash_algorithm, 30)
    code_to_validate = totp.generate(time.time())

    assert auth.authorize_user(user_id, code_to_validate)
Exemple #5
0
def test_totp_verify():
    secret = os.urandom(20)
    key_length = 6
    current_time = 400
    hash_algorithm = "SHA256"
    totp = auth.get_totp(secret, key_length, hash_algorithm, 30)
    value = totp.generate(current_time)

    assert auth.totp_verify(secret, key_length, hash_algorithm, 30, value, current_time, 0)
    assert auth.totp_verify(secret, key_length, hash_algorithm, 30, value, current_time, 1)
    with pytest.raises(auth.ValidationException):
        auth.totp_verify(secret, key_length, hash_algorithm, 60, value, current_time, 0)
    with pytest.raises(auth.ValidationException):
        auth.totp_verify(secret, key_length, hash_algorithm, 30, b"999999", current_time, 0)
Exemple #6
0
def test_totp_verify():
    secret = os.urandom(20)
    key_length = 6
    current_time = 400
    hash_algorithm = 'SHA256'
    totp = auth.get_totp(secret, key_length, hash_algorithm, 30)
    value = totp.generate(current_time)

    assert auth.totp_verify(secret, key_length, hash_algorithm, 30, value,
                            current_time, 0)
    assert auth.totp_verify(secret, key_length, hash_algorithm, 30, value,
                            current_time, 1)
    with pytest.raises(auth.ValidationException):
        auth.totp_verify(secret, key_length, hash_algorithm, 60, value,
                         current_time, 0)
    with pytest.raises(auth.ValidationException):
        auth.totp_verify(secret, key_length, hash_algorithm, 30, b'999999',
                         current_time, 0)