Example #1
0
def user_authenticate():
    data = request.get_json(force=True)
    try:
        validate(data, USER_AUTHENTICATE_SCHEMA)
    except ValidationError as e:
        return jsonify(error_message=str(e), error_code='INVALID_PARAMS'), 400

    try:
        auth.authorize_user(data['user_id'], data['auth_code'].encode('ASCII'))
    except auth.ValidationException as e:
        return jsonify(error_message=e.args[0],
                       error_code='VALIDATION_FAILURE'), 400

    return jsonify({}), 200
Example #2
0
def user_authenticate():
    data = request.get_json(force=True)
    try:
        validate(data, USER_AUTHENTICATE_SCHEMA)
    except ValidationError as e:
        return jsonify(error_message=str(e), error_code='INVALID_PARAMS'), 400

    try:
        auth.authorize_user(data['user_id'], data['auth_code'].encode('ASCII'))
    except auth.ValidationException as e:
        return jsonify(
            error_message=e.args[0],
            error_code='VALIDATION_FAILURE'
        ), 400

    return jsonify({}), 200
Example #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)
Example #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)
Example #5
0
def test_authorize_user_not_found():
    user_id = '15'
    with pytest.raises(auth.ValidationException):
        auth.authorize_user(user_id, 'foo')
Example #6
0
def test_authorize_user_not_found():
    user_id = "15"
    with pytest.raises(auth.ValidationException):
        auth.authorize_user(user_id, "foo")