Beispiel #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
Beispiel #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
Beispiel #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]
Beispiel #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]
Beispiel #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]
Beispiel #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]
Beispiel #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]
Beispiel #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]
Beispiel #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]
Beispiel #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]
Beispiel #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
Beispiel #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")
Beispiel #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]
Beispiel #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"]
Beispiel #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)
Beispiel #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$")
Beispiel #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"]
Beispiel #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
Beispiel #19
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)
Beispiel #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')
Beispiel #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)
Beispiel #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
Beispiel #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$')
Beispiel #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]
Beispiel #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']
Beispiel #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']
Beispiel #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))