Beispiel #1
0
def test_graph_disable(
        session,
        graph,
        users,
        groups,
        user_admin_perm_to_auditors,
        http_client,
        base_url  # noqa: F811
):
    graph.update_from_db(session)
    old_users = graph.users
    assert sorted(old_users) == sorted(list(users.keys()) + ["*****@*****.**"])

    # disable a user
    username = u"*****@*****.**"
    fe_url = url(base_url, "/users/{}/disable".format(username))
    resp = yield http_client.fetch(fe_url,
                                   method="POST",
                                   headers={"X-Grouper-User": "******"},
                                   body=urlencode({}))
    assert resp.code == 200

    graph.update_from_db(session)
    assert len(graph.users) == (len(old_users) -
                                1), "disabled user removed from graph"
    assert username not in graph.users
Beispiel #2
0
def test_multi_users(users, http_client, base_url):  # noqa: F811
    def make_url(*usernames):
        query_args = urlencode({"username": usernames}, doseq=True)

        return url(base_url, "/multi/users?{}".format(query_args))

    # Test case when no usernames are provided
    api_url = make_url()
    resp = yield http_client.fetch(api_url)
    body = json.loads(resp.body)

    assert resp.code == 200
    assert body["status"] == "ok"
    # Service Accounts should be included
    assert sorted(list(
        body["data"].keys())) == sorted(list(users.keys()) + ["*****@*****.**"])

    # Test case when only valid usernames are provided
    api_url = make_url("*****@*****.**", "*****@*****.**", "*****@*****.**")
    resp = yield http_client.fetch(api_url)
    body = json.loads(resp.body)

    assert resp.code == 200
    assert body["status"] == "ok"
    # Service Accounts should be included
    assert sorted(list(body["data"].keys())) == [
        "*****@*****.**", "*****@*****.**", "*****@*****.**"
    ]
    # Verify that we return the same data as the single user endpoint
    for username, data in iteritems(body["data"]):
        r = yield http_client.fetch(url(base_url,
                                        "/users/{}".format(username)))
        rbody = json.loads(r.body)
        assert data == rbody["data"]

    # Ensure that nonexistent usernames are ignored
    api_url = make_url("*****@*****.**", "*****@*****.**", "*****@*****.**")
    resp = yield http_client.fetch(api_url)
    body = json.loads(resp.body)

    assert resp.code == 200
    assert body["status"] == "ok"
    assert sorted(list(
        body["data"].keys())) == ["*****@*****.**", "*****@*****.**"]

    # Test when only nonexistent usernames are given
    api_url = make_url("*****@*****.**", "*****@*****.**")
    resp = yield http_client.fetch(api_url)
    body = json.loads(resp.body)

    assert resp.code == 200
    assert body["status"] == "ok"
    assert sorted(list(body["data"].keys())) == []
Beispiel #3
0
def test_multi_users(users, http_client, base_url):  # noqa: F811
    def make_url(*usernames):
        query_args = urlencode({"username": usernames}, doseq=True)

        return url(base_url, "/multi/users?{}".format(query_args))

    # Test case when no usernames are provided
    api_url = make_url()
    resp = yield http_client.fetch(api_url)
    body = json.loads(resp.body)

    assert resp.code == 200
    assert body["status"] == "ok"
    # Service Accounts should be included
    assert sorted(list(body["data"].keys())) == sorted(list(users.keys()) + ["*****@*****.**"])

    # Test case when only valid usernames are provided
    api_url = make_url("*****@*****.**", "*****@*****.**", "*****@*****.**")
    resp = yield http_client.fetch(api_url)
    body = json.loads(resp.body)

    assert resp.code == 200
    assert body["status"] == "ok"
    # Service Accounts should be included
    assert sorted(list(body["data"].keys())) == ["*****@*****.**", "*****@*****.**", "*****@*****.**"]
    # Verify that we return the same data as the single user endpoint
    for username, data in iteritems(body["data"]):
        r = yield http_client.fetch(url(base_url, "/users/{}".format(username)))
        rbody = json.loads(r.body)
        assert data == rbody["data"]

    # Ensure that nonexistent usernames are ignored
    api_url = make_url("*****@*****.**", "*****@*****.**", "*****@*****.**")
    resp = yield http_client.fetch(api_url)
    body = json.loads(resp.body)

    assert resp.code == 200
    assert body["status"] == "ok"
    assert sorted(list(body["data"].keys())) == ["*****@*****.**", "*****@*****.**"]

    # Test when only nonexistent usernames are given
    api_url = make_url("*****@*****.**", "*****@*****.**")
    resp = yield http_client.fetch(api_url)
    body = json.loads(resp.body)

    assert resp.code == 200
    assert body["status"] == "ok"
    assert sorted(list(body["data"].keys())) == []
Beispiel #4
0
def test_users(users, http_client, base_url):  # noqa: F811
    all_users = sorted(list(users.keys()) + ["*****@*****.**"])
    users_wo_role = sorted([u for u in users if u != u"*****@*****.**"])

    api_url = url(base_url, "/users")
    resp = yield http_client.fetch(api_url)
    body = json.loads(resp.body)
    assert resp.code == 200
    assert body["status"] == "ok"
    assert sorted(body["data"]["users"]) == users_wo_role

    api_url = url(base_url, "/users?include_role_users=yes")
    resp = yield http_client.fetch(api_url)
    body = json.loads(resp.body)
    assert resp.code == 200
    assert body["status"] == "ok"
    assert sorted(body["data"]["users"]) == all_users
Beispiel #5
0
def test_users(users, http_client, base_url):  # noqa: F811
    all_users = sorted(list(users.keys()) + ["*****@*****.**"])
    users_wo_role = sorted([u for u in users if u != u"*****@*****.**"])

    api_url = url(base_url, "/users")
    resp = yield http_client.fetch(api_url)
    body = json.loads(resp.body)
    assert resp.code == 200
    assert body["status"] == "ok"
    assert sorted(body["data"]["users"]) == users_wo_role

    api_url = url(base_url, "/users?include_role_users=yes")
    resp = yield http_client.fetch(api_url)
    body = json.loads(resp.body)
    assert resp.code == 200
    assert body["status"] == "ok"
    assert sorted(body["data"]["users"]) == all_users
Beispiel #6
0
def test_graph_disable(
    session, graph, users, groups, user_admin_perm_to_auditors, http_client, base_url  # noqa: F811
):
    graph.update_from_db(session)
    old_users = graph.users
    assert sorted(old_users) == sorted(list(users.keys()) + ["*****@*****.**"])

    # disable a user
    username = u"*****@*****.**"
    fe_url = url(base_url, "/users/{}/disable".format(username))
    resp = yield http_client.fetch(
        fe_url, method="POST", headers={"X-Grouper-User": "******"}, body=urlencode({})
    )
    assert resp.code == 200

    graph.update_from_db(session)
    assert len(graph.users) == (len(old_users) - 1), "disabled user removed from graph"
    assert username not in graph.users