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.
|
Bound Connection object to an LDAP server.
|
||||||
group_dn : str
|
group_dn : str
|
||||||
DN of a group entry (cn) directly below the LDAP_GROUPS_OU entry.
|
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)
|
_assert_is_valid_connection(connection)
|
||||||
|
@ -263,38 +263,89 @@ def test_get_users(app, connection):
|
|||||||
for user in ll.get_users(connection):
|
for user in ll.get_users(connection):
|
||||||
assert user.username in ["alice", "bobbuilder"]
|
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):
|
def test_group_exists(app, connection):
|
||||||
with app.app_context():
|
with app.app_context():
|
||||||
# TODO implement
|
assert ll.group_exists(
|
||||||
pass
|
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):
|
def test_create_group(app, connection):
|
||||||
with app.app_context():
|
with app.app_context():
|
||||||
# TODO implement
|
alice = ll.get_user(connection, "alice")
|
||||||
pass
|
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):
|
def test_delete_group(app, connection):
|
||||||
with app.app_context():
|
with app.app_context():
|
||||||
# TODO implement
|
assert ll.group_exists(connection, "cn=employees,ou=groups,dc=example,dc=com")
|
||||||
pass
|
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):
|
def test_get_group(app, connection):
|
||||||
with app.app_context():
|
with app.app_context():
|
||||||
# TODO implement
|
employees = ll.get_group(connection, "employees")
|
||||||
pass
|
assert len(employees.members) == 2
|
||||||
|
|
||||||
|
with pytest.raises(ll.EntryNotFoundException):
|
||||||
|
ll.get_group(connection, "nonexistent")
|
||||||
|
|
||||||
|
|
||||||
def test_get_groups(app, connection):
|
def test_get_groups(app, connection):
|
||||||
with app.app_context():
|
with app.app_context():
|
||||||
# TODO implement
|
groups = ll.get_groups(connection)
|
||||||
pass
|
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):
|
def test_get_groups_of_user(app, connection):
|
||||||
with app.app_context():
|
with app.app_context():
|
||||||
# TODO implement
|
alice = ll.get_user(connection, "alice")
|
||||||
pass
|
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…
x
Reference in New Issue
Block a user