def test_group_many_members(client, logged_in_dummy_user, dummy_group, make_users): """Make sure the group page is paginated with all its members""" users = [f"testuser-{i}" for i in range(1, 50)] make_users(users) ipa_admin.group_add_member(a_cn="dummy-group", o_user=users) result = client.get('/group/dummy-group/') assert result.status_code == 200 page = BeautifulSoup(result.data, 'html.parser') # Only the first page is displayed members = page.select("div[data-section='members'] ul li div.card") assert len(members) == 48 # But the total should be right total = page.select_one("div[data-section='members'] div.h4 span.badge") assert total.get_text(strip=True) == str(len(users)) # The pagination bar should be present pagination_bar = page.select_one("ul.pagination") assert pagination_bar is not None page_items = pagination_bar.select("li.page-item") pages_bar_list = [ p.select(".page-link:last-child")[0].get_text(strip=True) for p in page_items ] assert pages_bar_list == ['1(current)', '2', 'Next']
def test_group_remove_self(client, logged_in_dummy_user, dummy_group): """Test a non-sponsor user removing themselves from a group""" ipa_admin.group_add_member("dummy-group", o_user="******") result = client.get('/group/dummy-group/') assert result.status_code == 200 page = BeautifulSoup(result.data, 'html.parser') leave_btn = page.select_one("#leave-group-btn") assert leave_btn.get_text(strip=True) == "Leave group" result = client.post('/group/dummy-group/members/remove', data={"username": "******"}) expected_message = """You got it! dummy has been removed from dummy-group. <span class='ml-auto' id="flashed-undo-button"> <form action="/group/dummy-group/members/" method="post"> <input id="username" name="username" required type="hidden" value="dummy"> <button type="submit" class="btn btn-outline-success btn-sm" name="new_member_username" value="dummy"> Undo </button> </form> </span>""" assert_redirects_with_flash( result, expected_url="/group/dummy-group/", expected_message=expected_message, expected_category="success", )
def test_user_with_indirect_groups(client, logged_in_dummy_user, dummy_group, make_group): make_group("parent-group") ipa_admin.group_add_member("parent-group", o_group="dummy-group") ipa_admin.group_add_member("dummy-group", o_user="******") result = client.get('/user/dummy/') page = BeautifulSoup(result.data, 'html.parser') assert (page.select_one('.list-group-item.text-right.bg-light strong'). get_text(strip=True) == '2 Group Memberships') assert len(page.select('.list-group .list-group-item span.title')) == 2
def test_group_many_members(client, logged_in_dummy_user, dummy_group, make_users): """Make sure all members are displayed on the group page""" users = [f"testuser-{i}" for i in range(1, 120)] make_users(users) ipa_admin.group_add_member(a_cn="dummy-group", o_user=users) result = client.get('/group/dummy-group/') assert result.status_code == 200 page = BeautifulSoup(result.data, 'html.parser') members = page.select("div[data-section='members'] ul li") assert len(members) == len(users)
def test_group(client, dummy_user_as_group_manager, make_user): """Test the group detail page: /group/<groupname>""" test_users = ["testuser1", "testuser2", "testuser3"] # Add members to the group for username in test_users: make_user(username) ipa_admin.group_add_member(a_cn="dummy-group", o_user=test_users) # Add another user, but only as a membermanager make_user("testuser4") ipa_admin.group_add_member_manager(a_cn="dummy-group", o_user=["testuser4"]) result = client.get('/group/dummy-group/') assert result.status_code == 200 page = BeautifulSoup(result.data, 'html.parser') assert page.title assert page.title.string == 'dummy-group Group - noggin' title = page.select_one("div[data-section='identity'] > .col > h3") assert title.get_text(strip=True) == "dummy-group" assert title.find_next_sibling("div").get_text( strip=True) == "A dummy group" # Check the sponsors list sponsors = page.select( "div[data-section='sponsors'] .list-unstyled.row .col-lg-3.col-md-4.col-sm-6" ) assert len(sponsors) == 2, str(sponsors) assert sponsors[0].find("a")["href"] == "/user/dummy/" assert sponsors[0].find("a").get_text(strip=True) == "dummy" assert sponsors[1].find("a")["href"] == "/user/testuser4/" assert sponsors[1].find("a").get_text(strip=True) == "testuser4" # Check the members list members = page.select("div[data-section='members'] ul li") assert len(members) == len(test_users) + 1 for index, username in enumerate(["dummy"] + test_users): assert members[index].find("a")["href"] == f"/user/{username}/" assert members[index].find("a").get_text(strip=True) == username # Current user is a sponsor, there must be the corresponding add form assert len(page.select("form[action='/group/dummy-group/members/']")) == 1 assert (page.select_one("#group-mailinglist a").get_text( strip=True) == "*****@*****.**") assert (page.select_one("#group-ircchannel a").get_text( strip=True) == "irc:///freenode.net/#dummy-group") assert (page.select_one("#group-urls a").get_text( strip=True) == "http://dummygroup.org")
def test_time_sensitive_password_policy(client, dummy_user, password_min_time): """Verify that new password policies are upheld""" ipa_admin.group_add_member(a_cn="dummy-group", o_user="******") result = client.post( '/password-reset?username=dummy', data={ "current_password": "******", "password": "******", "password_confirm": "somesupersecretpassword", }, ) # the dummy user is created and has its password immediately changed, # so this next attempt should fail with a constraint error. assert_form_field_error( result, field_name="password", expected_message="Constraint violation: Too soon to change password", )
def test_group_remove_member(client, dummy_user_as_group_manager, make_user): """Test removing a member from a group""" make_user("testuser") ipa_admin.group_add_member(a_cn="dummy-group", o_user="******") result = client.post('/group/dummy-group/members/remove', data={"username": "******"}) expected_message = """You got it! testuser has been removed from dummy-group. <span class='ml-auto' id="flashed-undo-button"> <form action="/group/dummy-group/members/" method="post"> <input id="username" name="username" required type="hidden" value="testuser"> <button type="submit" class="btn btn-outline-success btn-sm" name="new_member_username" value="testuser"> Undo </button> </form> </span>""" assert_redirects_with_flash( result, expected_url="/group/dummy-group/", expected_message=expected_message, expected_category="success", )
def dummy_user_as_group_manager(logged_in_dummy_user, dummy_group): """Make the dummy user a manager of the dummy-group group.""" ipa_admin.group_add_member(a_cn="dummy-group", o_user="******") ipa_admin.group_add_member_manager(a_cn="dummy-group", o_user="******") yield