예제 #1
0
def test_create_user():
    email = random_lower_string()
    password = random_lower_string()
    user = create_or_get_user(email, password)
    keys = ["_id", "_rev", "name", "roles", "type"]
    for key in keys:
        assert key in user
예제 #2
0
def test_not_create_db_for_user():
    email = random_lower_string()
    password = random_lower_string()
    user = create_or_get_user(email, password)  # noqa
    db_id = get_database_id_for_user(email)
    client = get_client()
    assert db_id not in client
예제 #3
0
def test_get_user_different_usernames():
    email = random_lower_string()
    password = random_lower_string()
    username = random_lower_string()
    user = create_or_get_user(email, password)
    user_2 = get_user(username)
    assert user != user_2
예제 #4
0
def test_check_if_username_is_active_inactive():
    email = random_lower_string()
    password = random_lower_string()
    user = create_or_get_user(email, password)
    user["roles"].remove("active")
    user.save()
    is_active = check_if_username_is_active(email)
    assert is_active is False
예제 #5
0
def test_authenticate_user():
    email = random_lower_string()
    password = random_lower_string()
    user = create_or_get_user(email, password)  # noqa
    db_user = authenticate_user(email, password)
    keys = ["_id", "_rev", "name", "roles", "type"]
    assert db_user
    for key in keys:
        assert key in db_user
예제 #6
0
def test_add_user_to_db_admins():
    client = get_client()
    db = client.create_database(random_lower_string())
    email = random_lower_string()
    password = random_lower_string()
    user = create_or_get_user(email, password)  # noqa
    add_user_to_db_admins(email, db)
    sd = db.get_security_document()
    assert "admins" in sd
    assert "members" not in sd
    assert email in sd["admins"]["names"]
예제 #7
0
def init_db():
    # Secure main DB access by adding a single dummy user 'app'
    client = get_client()
    db_app = get_db_app(client)
    add_user_to_db_admins("app", db_app)
    add_user_to_db_members("app", db_app)
    # Create first superuser
    db_users = get_db_users(client)
    create_or_get_user(
        config.FIRST_SUPERUSER,
        config.FIRST_SUPERUSER_PASSWORD,
        is_superuser=True,
        db_users=db_users,
        client=client,
    )
    create_user_with_default_db(config.FIRST_SUPERUSER, config.FIRST_SUPERUSER_PASSWORD)
    db_app.create_query_index(fields=["type", "username"])
    db_users.create_query_index(fields=["type"])
    enable_cors()
    setup_cookie()
예제 #8
0
def test_create_db_for_user():
    email = random_lower_string()
    password = random_lower_string()
    user = create_or_get_user(email, password)  # noqa
    db_id = get_database_id_for_user(email)
    db = get_database_for_user(email)
    sd = db.get_security_document()
    client = get_client()
    assert db_id in client.keys(remote=True)
    assert "members" not in sd
    assert "admins" not in sd
예제 #9
0
def test_check_if_username_is_active():
    email = random_lower_string()
    password = random_lower_string()
    user = create_or_get_user(email, password)  # noqa
    is_active = check_if_username_is_active(email)
    assert is_active is True
예제 #10
0
def test_not_create_user_if_exists():
    email = random_lower_string()
    password = random_lower_string()
    user = create_or_get_user(email, password)
    same_user = create_or_get_user(email, password)
    assert user == same_user
예제 #11
0
def test_get_user():
    password = random_lower_string()
    username = random_lower_string()
    user = create_or_get_user(username, password)
    user_2 = get_user(username)
    assert user == user_2
예제 #12
0
def test_check_if_user_is_superuser_normal_user():
    username = random_lower_string()
    password = random_lower_string()
    user = create_or_get_user(username, password)
    is_superuser = check_if_user_is_superuser(user)
    assert is_superuser is False
예제 #13
0
def test_check_if_user_is_superuser():
    email = random_lower_string()
    password = random_lower_string()
    user = create_or_get_user(email, password, is_superuser=True)
    is_superuser = check_if_user_is_superuser(user)
    assert is_superuser is True