def test_default_provision_user(): user_id = '10' auth.provision_user(user_id) auth_user = auth.load_user(user_id) assert auth_user.user_id == '10' assert len(auth_user.secret) == auth.SECRET_KEY_BYTES assert auth_user.key_length == 6 assert auth_user.hash_algorithm == 'SHA256'
def test_default_provision_user(): user_id = "10" auth.provision_user(user_id) auth_user = auth.load_user(user_id) assert auth_user.user_id == "10" assert len(auth_user.secret) == auth.SECRET_KEY_BYTES assert auth_user.key_length == 6 assert auth_user.hash_algorithm == "SHA256"
def user_auth_code(): try: validate(request.args, USER_AUTH_CODE_SCHEMA) except ValidationError as e: return jsonify(error_message=str(e), error_code='INVALID_PARAMS'), 400 user = auth.load_user(request.args['user_id']) if not user: return user_not_provisioned_response(request.args['user_id']) return jsonify({'code': auth.get_auth_code_for_user(user)})
def user_regenerate_recovery_codes(): data = request.get_json(force=True) try: validate(data, USER_RECOVERY_CODE_REGENERATE_SCHEMA) except ValidationError as e: return jsonify(error_message=str(e), error_code='INVALID_PARAMS'), 400 auth_user = auth.load_user(data['user_id']) if not auth_user: return user_not_provisioned_response(data['user_id']) auth_user = auth.regenerate_user_recovery_codes(auth_user.user_id) return format_auth_user_response(auth_user)
def user_auth_code(): try: validate(request.args, USER_AUTH_CODE_SCHEMA) except ValidationError as e: return jsonify(error_message=str(e), error_code='INVALID_PARAMS'), 400 user = auth.load_user(request.args['user_id']) if not user: return user_not_provisioned_response(request.args['user_id']) return jsonify({ 'code': auth.get_auth_code_for_user(user) })
def user_validate_recovery_code(): data = request.get_json(force=True) try: validate(data, USER_RECOVERY_CODE_AUTHENTICATE_SCHEMA) except ValidationError as e: return jsonify(error_message=str(e), error_code='INVALID_PARAMS'), 400 auth_user = auth.load_user(data['user_id']) if not auth_user: return user_not_provisioned_response(data['user_id']) try: auth.consume_recovery_code(auth_user.user_id, data['recovery_code']) except auth.RecoveryCodeConsumptionError as e: return jsonify(error_message= 'The recovery code supplied is not valid for this user', error_code='INVALID_RECOVERY_CODE'), 400 return jsonify()
def user_validate_recovery_code(): data = request.get_json(force=True) try: validate(data, USER_RECOVERY_CODE_AUTHENTICATE_SCHEMA) except ValidationError as e: return jsonify(error_message=str(e), error_code='INVALID_PARAMS'), 400 auth_user = auth.load_user(data['user_id']) if not auth_user: return user_not_provisioned_response(data['user_id']) try: auth.consume_recovery_code(auth_user.user_id, data['recovery_code']) except auth.RecoveryCodeConsumptionError as e: return jsonify( error_message='The recovery code supplied is not valid for this user', error_code='INVALID_RECOVERY_CODE' ), 400 return jsonify()
def healthcheck(): # Make sure the DB connection is dandy load_user(1) return jsonify({})
def test_provision_user_alternate_algorithm(): user_id = '12' auth.provision_user(user_id, hash_algorithm='SHA1') auth_user = auth.load_user(user_id) assert auth_user.hash_algorithm == 'SHA1'
def test_provision_user_alternate_key_length(): user_id = '11' auth.provision_user(user_id, key_length=8) auth_user = auth.load_user(user_id) assert auth_user.key_length == 8
def test_provision_user_alternate_algorithm(): user_id = "12" auth.provision_user(user_id, hash_algorithm="SHA1") auth_user = auth.load_user(user_id) assert auth_user.hash_algorithm == "SHA1"
def test_provision_user_alternate_key_length(): user_id = "11" auth.provision_user(user_id, key_length=8) auth_user = auth.load_user(user_id) assert auth_user.key_length == 8