예제 #1
0
def test_insert_user(db_conn):
    data = {
        'name': 'test',
        'email': '*****@*****.**',
        'password': '******',
    }
    user, errors = insert_user(db_conn, data)
    assert errors
    assert not user
    data['password'] = '******'
    user, errors = insert_user(db_conn, data)
    assert not errors
    assert user
예제 #2
0
def test_user_no_password(db_conn, users_table):
    """
    Ensure an password isn't provided ever.
    """
    user, errors = insert_user({"name": "test", "email": "*****@*****.**", "password": "******"}, db_conn)
    json = deliver_user(user, access="private")
    assert "password" not in json
예제 #3
0
def test_user_password_required(db_conn):
    """
    Ensure a password is required.
    """
    user = {}
    user, errors = insert_user(user, db_conn)
    assert len(errors) > 0
    assert 'password' in [e['name'] for e in errors]
예제 #4
0
def test_user_password_required(db_conn):
    """
    Ensure a password is required.
    """
    user = {}
    user, errors = insert_user(user, db_conn)
    assert len(errors) > 0
    assert "password" in [e["name"] for e in errors]
예제 #5
0
def test_user_password_minlength(db_conn):
    """
    Ensure an password is long enough.
    """
    user = {'password': '******'}
    user, errors = insert_user(user, db_conn)
    assert 'password' in [e['name'] for e in errors]
    assert 'Must have minimum length of 8.' in [e['message'] for e in errors]
예제 #6
0
def test_user_name_required(db_conn):
    """
    Ensure a name is required.
    """
    user = {}
    user, errors = insert_user(user, db_conn)
    assert len(errors) > 0
    assert 'name' in [e['name'] for e in errors]
예제 #7
0
def test_user_email_format(db_conn):
    """
    Ensure an email is formatted.
    """
    user = {'email': 'other'}
    user, errors = insert_user(user, db_conn)
    assert 'email' in [e['name'] for e in errors]
    assert 'Must be an email.' in [e['message'] for e in errors]
예제 #8
0
def test_user_password_minlength(db_conn):
    """
    Ensure an password is long enough.
    """
    user = {"password": "******"}
    user, errors = insert_user(user, db_conn)
    assert "password" in [e["name"] for e in errors]
    assert "Must have minimum length of 8." in [e["message"] for e in errors]
예제 #9
0
def test_user_email_format(db_conn):
    """
    Ensure an email is formatted.
    """
    user = {"email": "other"}
    user, errors = insert_user(user, db_conn)
    assert "email" in [e["name"] for e in errors]
    assert "Must be an email." in [e["message"] for e in errors]
예제 #10
0
def test_user_email_required(db_conn):
    """
    Ensure an email is required.
    """
    user = {}
    user, errors = insert_user(user, db_conn)
    assert len(errors) > 0
    assert "email" in [e["name"] for e in errors]
예제 #11
0
def test_user_email_current(db_conn, users_table):
    """
    Ensure an email is only provided when current user.
    """
    user, errors = insert_user({"name": "test", "email": "*****@*****.**", "password": "******"}, db_conn)
    json = deliver_user(user)
    assert "email" not in json
    json = deliver_user(user, access="private")
    assert "email" in json
예제 #12
0
def test_user_password_validate(db_conn, users_table):
    """
    Ensure a password can be validated.
    """
    user, errors = insert_user(
        {"id": "abcd1234", "name": "test", "email": "*****@*****.**", "password": "******"}, db_conn
    )
    assert not is_password_valid(user["password"], "1234abcd")
    assert is_password_valid(user["password"], "abcd1234")
예제 #13
0
def test_user_email_unique(db_conn, users_table):
    """
    Ensure an email is unique.
    """
    users_table.insert({"id": "abcd1234", "email": "*****@*****.**"}).run(db_conn)
    user, errors = insert_user({"name": "test", "email": "*****@*****.**", "password": "******"}, db_conn)
    assert len(errors) > 0
    assert "email" in [e["name"] for e in errors]
    assert "Must be unique." in [e["message"] for e in errors]
예제 #14
0
def test_update_password(db_conn, users_table):
    """
    Expect to update a user's password.
    """

    user, errors = insert_user({"name": "Dalton", "email": "*****@*****.**", "password": "******"}, db_conn)
    pw1 = user["password"]
    user, errors = update_user_password(user, {"password": "******"}, db_conn)
    assert pw1 != user["password"]
예제 #15
0
def create_user_route(request):
    """
    Create user.
    """

    db_conn = request["db_conn"]
    user, errors = insert_user(request["params"], db_conn)
    if len(errors):
        return 400, {"errors": errors, "ref": "YEcBnqf4vyA2pckIy70R789B"}
    return _log_in(user)
예제 #16
0
def test_user_password_encrypt(db_conn, users_table):
    """
    Ensure a password is encrypted before going into db.
    """
    user, errors = insert_user(
        {"id": "abcd1234", "name": "test", "email": "*****@*****.**", "password": "******"}, db_conn
    )
    assert len(errors) == 0
    assert user["password"] != "abcd1234"
    assert user["password"].startswith("$2a$")
예제 #17
0
def test_update_user(db_conn, users_table):
    """
    Expect to update a user's data.
    """

    user, errors = insert_user({"name": "Dalton", "email": "*****@*****.**", "password": "******"}, db_conn)
    user2, errors2 = update_user(user, {"email": "*****@*****.**"}, db_conn)
    assert len(errors2) == 0
    assert user["name"] == user2["name"]
    assert user["email"] != user2["email"]
예제 #18
0
def test_user_no_password(db_conn, users_table):
    """
    Ensure an password isn't provided ever.
    """
    user, errors = insert_user(
        {
            'name': 'test',
            'email': '*****@*****.**',
            'password': '******'
        }, db_conn)
    json = deliver_user(user, access='private')
    assert 'password' not in json
예제 #19
0
파일: user.py 프로젝트: m3rryqold/sagefy
def create_user_route(request):
    """
    Create user.
    """

    db_conn = request['db_conn']
    user, errors = insert_user(request['params'], db_conn)
    if len(errors):
        return 400, {
            'errors': errors,
            'ref': 'YEcBnqf4vyA2pckIy70R789B',
        }
    return _log_in(user)
예제 #20
0
def test_user_password_validate(db_conn, users_table):
    """
    Ensure a password can be validated.
    """
    user, errors = insert_user(
        {
            'id': 'abcd1234',
            'name': 'test',
            'email': '*****@*****.**',
            'password': '******'
        }, db_conn)
    assert not is_password_valid(user['password'], '1234abcd')
    assert is_password_valid(user['password'], 'abcd1234')
예제 #21
0
def create_user_route(request):
  """
  Create user.
  """

  db_conn = request['db_conn']
  user, errors = insert_user(db_conn, request['params'])
  if errors:
    return 400, {
      'errors': errors,
      'ref': 'zy5VJ9zlQ-qWRUi9rETenw',
    }
  return _log_in(user)
예제 #22
0
def test_user_email_current(db_conn, users_table):
    """
    Ensure an email is only provided when current user.
    """
    user, errors = insert_user(
        {
            'name': 'test',
            'email': '*****@*****.**',
            'password': '******'
        }, db_conn)
    json = deliver_user(user)
    assert 'email' not in json
    json = deliver_user(user, access='private')
    assert 'email' in json
예제 #23
0
def test_user_password_encrypt(db_conn, users_table):
    """
    Ensure a password is encrypted before going into db.
    """
    user, errors = insert_user(
        {
            'id': 'abcd1234',
            'name': 'test',
            'email': '*****@*****.**',
            'password': '******'
        }, db_conn)
    assert len(errors) == 0
    assert user['password'] != 'abcd1234'
    assert user['password'].startswith('$2a$')
예제 #24
0
def test_user_name_unique(db_conn, users_table):
    """
    Ensure a name is unique.
    """
    users_table.insert({'name': 'test'}).run(db_conn)
    user = {
        'name': 'test',
        'email': '*****@*****.**',
        'password': '******'
    }
    user, errors = insert_user(user, db_conn)
    assert len(errors) > 0
    assert 'name' in [e['name'] for e in errors]
    assert 'Must be unique.' in [e['message'] for e in errors]
예제 #25
0
def test_update_password(db_conn, users_table):
    """
    Expect to update a user's password.
    """

    user, errors = insert_user(
        {
            'name': 'Dalton',
            'email': '*****@*****.**',
            'password': '******',
        }, db_conn)
    pw1 = user['password']
    user, errors = update_user_password(user, {'password': '******'},
                                        db_conn)
    assert pw1 != user['password']
예제 #26
0
def test_update_user(db_conn, users_table):
    """
    Expect to update a user's data.
    """

    user, errors = insert_user(
        {
            'name': 'Dalton',
            'email': '*****@*****.**',
            'password': '******',
        }, db_conn)
    user2, errors2 = update_user(user, {'email': '*****@*****.**'}, db_conn)
    assert len(errors2) == 0
    assert user['name'] == user2['name']
    assert user['email'] != user2['email']
예제 #27
0
def create_user(user: UserModel) -> Dict[str, Union[UUID4, dict]]:
    if find_user(user):
        return error_response("Email or Username has been registered", 409)
    user.password = hash_helper.encrypt(user.password)
    return insert_user(jsonable_encoder(user))