tests(ldap): add missing unit tests
This commit is contained in:
parent
031fe2b4bd
commit
26d5e36529
@ -832,11 +832,6 @@ def group_exists(connection: Connection, group_dn: str) -> bool:
|
||||
Bound Connection object to an LDAP server.
|
||||
group_dn : str
|
||||
DN of a group entry (cn) directly below the LDAP_GROUPS_OU entry.
|
||||
|
||||
Raises
|
||||
------
|
||||
MissingParentEntryException
|
||||
If the specified group DN's direct parent entry is not present in the DIT.
|
||||
"""
|
||||
|
||||
_assert_is_valid_connection(connection)
|
||||
|
@ -263,38 +263,89 @@ def test_get_users(app, connection):
|
||||
for user in ll.get_users(connection):
|
||||
assert user.username in ["alice", "bobbuilder"]
|
||||
|
||||
ll.create_user(
|
||||
connection,
|
||||
lu.User(
|
||||
username="user0",
|
||||
password_hash=lu.User.generate_password_hash("password"),
|
||||
email="valid@example.com",
|
||||
first_name="Test",
|
||||
last_name="User",
|
||||
),
|
||||
)
|
||||
|
||||
assert len(ll.get_users(connection)) == 3
|
||||
for user in ll.get_users(connection):
|
||||
assert user.username in ["alice", "bobbuilder", "user0"]
|
||||
|
||||
|
||||
def test_group_exists(app, connection):
|
||||
with app.app_context():
|
||||
# TODO implement
|
||||
pass
|
||||
assert ll.group_exists(
|
||||
connection, "cn=employees,ou=groups,dc=example,dc=com"
|
||||
)
|
||||
assert not ll.group_exists(
|
||||
connection, "cn=nonexistent,ou=groups,dc=example,dc=com"
|
||||
)
|
||||
|
||||
|
||||
def test_create_group(app, connection):
|
||||
with app.app_context():
|
||||
# TODO implement
|
||||
pass
|
||||
alice = ll.get_user(connection, "alice")
|
||||
testgroup = lu.Group("testgroup", {alice})
|
||||
|
||||
ll.create_group(connection, testgroup)
|
||||
assert ll.group_exists(connection, "cn=testgroup,ou=groups,dc=example,dc=com")
|
||||
|
||||
with pytest.raises(ll.EntryExistsException):
|
||||
ll.create_group(connection, testgroup)
|
||||
|
||||
user0 = lu.User(
|
||||
username="user0",
|
||||
password_hash=lu.User.generate_password_hash("password"),
|
||||
email="valid@example.com",
|
||||
first_name="Test",
|
||||
last_name="User",
|
||||
)
|
||||
with pytest.raises(ll.EntryNotFoundException):
|
||||
ll.create_group(connection, lu.Group("invalidgroup", {user0}))
|
||||
|
||||
|
||||
|
||||
def test_delete_group(app, connection):
|
||||
with app.app_context():
|
||||
# TODO implement
|
||||
pass
|
||||
assert ll.group_exists(connection, "cn=employees,ou=groups,dc=example,dc=com")
|
||||
ll.delete_group(connection, "employees")
|
||||
assert not ll.group_exists(connection, "cn=employees,ou=groups,dc=example,dc=com")
|
||||
|
||||
with pytest.raises(ll.EntryNotFoundException):
|
||||
ll.delete_group(connection, "employees")
|
||||
|
||||
|
||||
|
||||
def test_get_group(app, connection):
|
||||
with app.app_context():
|
||||
# TODO implement
|
||||
pass
|
||||
employees = ll.get_group(connection, "employees")
|
||||
assert len(employees.members) == 2
|
||||
|
||||
with pytest.raises(ll.EntryNotFoundException):
|
||||
ll.get_group(connection, "nonexistent")
|
||||
|
||||
|
||||
def test_get_groups(app, connection):
|
||||
with app.app_context():
|
||||
# TODO implement
|
||||
pass
|
||||
groups = ll.get_groups(connection)
|
||||
assert len(groups) == 2
|
||||
|
||||
for group in groups:
|
||||
ll.delete_group(connection, group.groupname)
|
||||
assert len(ll.get_groups(connection)) == 0
|
||||
|
||||
|
||||
def test_get_groups_of_user(app, connection):
|
||||
with app.app_context():
|
||||
# TODO implement
|
||||
pass
|
||||
alice = ll.get_user(connection, "alice")
|
||||
bobbuilder = ll.get_user(connection, "bobbuilder")
|
||||
|
||||
assert len(ll.get_groups_of_user(connection, alice)) == 2
|
||||
assert len(ll.get_groups_of_user(connection, bobbuilder)) == 1
|
||||
|
Loading…
Reference in New Issue
Block a user