示例#1
0
def test_is_valid_token(db_conn):
    assert not is_valid_token({'id': uuid.uuid4()}, '')
    create_test_users(db_conn)
    user = get_user_by_id(db_conn, {'id': user_a_uuid})
    token = get_email_token(user)
    assert not is_valid_token(user, 'qyzjosinmal1234')
    token = get_email_token(user)
    assert is_valid_token(user, token)
示例#2
0
def create_token_route(request):
  """
  Create an email token for the user.
  """

  db_conn = request['db_conn']
  user = get_user(db_conn, {'email': request['params'].get('email')})
  if not user:
    return abort(404, 'AyuDktXTTJqNOp6TV5A3yA')
  get_email_token(user)
  return 200, {}  # NB do not output token
示例#3
0
def create_token_route(request):
    """
    Create an email token for the user.
    """

    db_conn = request["db_conn"]
    user = get_user({"email": request["params"].get("email")}, db_conn)
    if not user:
        return abort(404)
    get_email_token(user)
    return 200, {}
示例#4
0
文件: user.py 项目: m3rryqold/sagefy
def create_token_route(request):
    """
    Create an email token for the user.
    """

    db_conn = request['db_conn']
    user = get_user({'email': request['params'].get('email')}, db_conn)
    if not user:
        return abort(404)
    get_email_token(user)
    return 200, {}
示例#5
0
def test_user_create_password_fail(db_conn, users_table):
    """
    Expect a user to be able to reset their password.
    """

    create_user_in_db(users_table, db_conn)
    user = get_user({'id': 'abcd1234'}, db_conn)
    pw1 = user['password']
    get_email_token(user, send_email=False)

    request = {
        'params': {
            'token': 'qza',
            'password': '******'
        },
        'db_conn': db_conn
    }
    code, response = routes.user.create_password_route(request, 'abcd1234')
    assert code == 403
    user = get_user({'id': 'abcd1234'}, db_conn)
    assert user['password'] == pw1
示例#6
0
def test_get_email_token(db_conn, users_table):
    """
    Expect an email token created so a user can reset their password.
    """

    users_table.insert({"id": "abcd1234", "name": "Dalton", "email": "*****@*****.**", "password": "******"}).run(
        db_conn
    )
    user = get_user({"id": "abcd1234"}, db_conn)
    token = get_email_token(user, send_email=False)
    assert redis.get("user_password_token_abcd1234")
    assert token
示例#7
0
def test_user_create_password_fail(db_conn, users_table):
    """
    Expect a user to be able to reset their password.
    """

    create_user_in_db(users_table, db_conn)
    user = get_user({'id': 'abcd1234'}, db_conn)
    pw1 = user['password']
    get_email_token(user, send_email=False)

    request = {
        'params': {
            'token': 'qza',
            'password': '******'
        },
        'db_conn': db_conn
    }
    code, response = routes.user.create_password_route(request, 'abcd1234')
    assert code == 403
    user = get_user({'id': 'abcd1234'}, db_conn)
    assert user['password'] == pw1
def test_user_create_password_fail(db_conn):
    """
  Expect a user to be able to reset their password.
  """

    create_user_in_db(db_conn)
    user = get_user(db_conn, {'id': user_id})
    pw1 = user['password']
    get_email_token(user)

    request = {
        'params': {
            'token': 'qza',
            'password': '******'
        },
        'db_conn': db_conn
    }
    code, _ = routes.user.create_password_route(request, user_id)
    assert code == 403
    user = get_user(db_conn, {'id': user_id})
    assert user['password'] == pw1
示例#9
0
def test_is_valid_token(db_conn, users_table):
    """
    Expect a valid token to be approved.
    Expect an invalid token to not be approved.
    """

    users_table.insert({"id": "abcd1234", "name": "Dalton", "email": "*****@*****.**", "password": "******"}).run(
        db_conn
    )
    user = get_user({"id": "abcd1234"}, db_conn)
    token = get_email_token(user, send_email=False)
    assert is_valid_token(user, token)
    assert not is_valid_token(user, "abcd1234")
示例#10
0
def test_get_email_token(db_conn, users_table):
    """
    Expect an email token created so a user can reset their password.
    """

    users_table.insert({
        'id': 'abcd1234',
        'name': 'Dalton',
        'email': '*****@*****.**',
        'password': '******',
    }).run(db_conn)
    user = get_user({'id': 'abcd1234'}, db_conn)
    token = get_email_token(user, send_email=False)
    assert redis.get('user_password_token_abcd1234')
    assert token
示例#11
0
def test_is_valid_token(db_conn, users_table):
    """
    Expect a valid token to be approved.
    Expect an invalid token to not be approved.
    """

    users_table.insert({
        'id': 'abcd1234',
        'name': 'Dalton',
        'email': '*****@*****.**',
        'password': '******',
    }).run(db_conn)
    user = get_user({'id': 'abcd1234'}, db_conn)
    token = get_email_token(user, send_email=False)
    assert is_valid_token(user, token)
    assert not is_valid_token(user, 'abcd1234')
示例#12
0
def test_get_email_token(db_conn):
    create_test_users(db_conn)
    user = get_user_by_id(db_conn, {'id': user_a_uuid})
    token = get_email_token(user)
    assert token